Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
First selection of message and signal
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Aug 10, 2015
1 parent ff0e37b commit ea49c4a
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import org.activiti.bpmn.model.Event;
import org.activiti.bpmn.model.Message;
import org.activiti.bpmn.model.MessageEventDefinition;
import org.activiti.designer.util.eclipse.ActivitiUiUtil;
import org.activiti.designer.util.editor.BpmnMemoryModel;
import org.activiti.designer.util.editor.ModelHandler;
import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.platform.IDiagramContainer;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Combo;

Expand All @@ -37,20 +40,31 @@ public static String[] fillMessageCombo(Combo messageCombo, SelectionListener se
}


public static String getMessageValue(Event event, Diagram diagram) {
public static String getMessageValue(final Event event, final Diagram diagram, final IDiagramContainer diagramContainer) {
if (event.getEventDefinitions().get(0) != null) {
MessageEventDefinition messageDefinition = (MessageEventDefinition) event.getEventDefinitions().get(0);
final MessageEventDefinition messageDefinition = (MessageEventDefinition) event.getEventDefinitions().get(0);
final BpmnMemoryModel memoryModel = ModelHandler.getModel(EcoreUtil.getURI(diagram));
final BpmnModel model = memoryModel.getBpmnModel();
if (StringUtils.isNotEmpty(messageDefinition.getMessageRef())) {
BpmnMemoryModel memoryModel = ModelHandler.getModel(EcoreUtil.getURI(diagram));
BpmnModel model = memoryModel.getBpmnModel();
for (Message message : model.getMessages()) {
if (message.getId() != null && message.getId().equals(messageDefinition.getMessageRef())) {
return message.getName() + " (" + message.getId() + ")";
}
}

} else {
return "message";
if (model.getMessages().size() > 0) {
final Runnable runnable = new Runnable() {
public void run() {
Message message = model.getMessages().iterator().next();
messageDefinition.setMessageRef(message.getId());
}
};

TransactionalEditingDomain editingDomain = diagramContainer.getDiagramBehavior().getEditingDomain();
ActivitiUiUtil.runModelChange(runnable, editingDomain, "Model Update");

}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected Object getModelValueForControl(Control control, Object businessObject)
return String.valueOf(event.isCancelActivity());

} else if (control == messageCombo) {
return MessagePropertyUtil.getMessageValue(event, getDiagram());
return MessagePropertyUtil.getMessageValue(event, getDiagram(), getDiagramContainer());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected Object getModelValueForControl(Control control, Object businessObject)
return String.valueOf(event.isCancelActivity());

} else if (control == signalCombo) {
return SignalPropertyUtil.getSignalValue(event, getDiagram());
return SignalPropertyUtil.getSignalValue(event, getDiagram(), getDiagramContainer());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void populateControl(Control control, Object businessObject) {
protected Object getModelValueForControl(Control control, Object businessObject) {
Event event = (Event) businessObject;
if (control == messageCombo) {
return MessagePropertyUtil.getMessageValue(event, getDiagram());
return MessagePropertyUtil.getMessageValue(event, getDiagram(), getDiagramContainer());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void populateControl(Control control, Object businessObject) {
protected Object getModelValueForControl(Control control, Object businessObject) {
Event event = (Event) businessObject;
if (control == signalCombo) {
return SignalPropertyUtil.getSignalValue(event, getDiagram());
return SignalPropertyUtil.getSignalValue(event, getDiagram(), getDiagramContainer());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void populateControl(Control control, Object businessObject) {
protected Object getModelValueForControl(Control control, Object businessObject) {
Event event = (Event) businessObject;
if (control == signalCombo) {
return SignalPropertyUtil.getSignalValue(event, getDiagram());
return SignalPropertyUtil.getSignalValue(event, getDiagram(), getDiagramContainer());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void populateControl(Control control, Object businessObject) {
protected Object getModelValueForControl(Control control, Object businessObject) {
Event event = (Event) businessObject;
if (control == messageCombo) {
return MessagePropertyUtil.getMessageValue(event, getDiagram());
return MessagePropertyUtil.getMessageValue(event, getDiagram(), getDiagramContainer());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void populateControl(Control control, Object businessObject) {
protected Object getModelValueForControl(Control control, Object businessObject) {
Event event = (Event) businessObject;
if (control == signalCombo) {
return SignalPropertyUtil.getSignalValue(event, getDiagram());
return SignalPropertyUtil.getSignalValue(event, getDiagram(), getDiagramContainer());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import org.activiti.bpmn.model.Event;
import org.activiti.bpmn.model.Signal;
import org.activiti.bpmn.model.SignalEventDefinition;
import org.activiti.designer.util.eclipse.ActivitiUiUtil;
import org.activiti.designer.util.editor.BpmnMemoryModel;
import org.activiti.designer.util.editor.ModelHandler;
import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.platform.IDiagramContainer;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Combo;

Expand All @@ -33,20 +36,30 @@ public static String[] fillSignalCombo(Combo signalCombo, SelectionListener sele
}


public static String getSignalValue(Event event, Diagram diagram) {
public static String getSignalValue(final Event event, final Diagram diagram, final IDiagramContainer diagramContainer) {
if (event.getEventDefinitions().get(0) != null) {
SignalEventDefinition signalDefinition = (SignalEventDefinition) event.getEventDefinitions().get(0);
final SignalEventDefinition signalDefinition = (SignalEventDefinition) event.getEventDefinitions().get(0);
final BpmnMemoryModel memoryModel = ModelHandler.getModel(EcoreUtil.getURI(diagram));
final BpmnModel model = memoryModel.getBpmnModel();
if (StringUtils.isNotEmpty(signalDefinition.getSignalRef())) {
BpmnMemoryModel memoryModel = ModelHandler.getModel(EcoreUtil.getURI(diagram));
BpmnModel model = memoryModel.getBpmnModel();
for (Signal signal : model.getSignals()) {
if (signal.getId() != null && signal.getId().equals(signalDefinition.getSignalRef())) {
return signal.getName() + " (" + signal.getId() + ")";
}
}

} else {
return "signal";
if (model.getSignals().size() > 0) {
final Runnable runnable = new Runnable() {
public void run() {
Signal signal = model.getSignals().iterator().next();
signalDefinition.setSignalRef(signal.getId());
}
};

TransactionalEditingDomain editingDomain = diagramContainer.getDiagramBehavior().getEditingDomain();
ActivitiUiUtil.runModelChange(runnable, editingDomain, "Model Update");
}
}
}
return null;
Expand Down
Binary file not shown.

0 comments on commit ea49c4a

Please sign in to comment.