use of com.centurylink.mdw.plugin.designer.model.Note in project mdw-designer by CenturyLinkCloud.
the class ProcessCanvasWrapper method eventDispatched.
/**
* Handles Swing events (running on the AWT UI thread).
*/
public void eventDispatched(AWTEvent event) {
// check for relevance and consistency
if (isInstance()) {
if (getProcessInstancePage() == null || !event.getSource().equals(getProcessInstancePage().canvas) || getProcessInstancePage().getProcess() == null)
return;
} else {
if (!event.getSource().equals(getFlowchartPage().canvas) || getFlowchartPage().getProcess() == null)
return;
}
if (event.getID() == MouseEvent.MOUSE_RELEASED) {
final MouseEvent mouseEvent = (MouseEvent) event;
if (mouseEvent.isPopupTrigger() || (PluginUtil.isMac() && mouseEvent.getButton() == 3)) {
getDisplay().asyncExec(new Runnable() {
public void run() {
final Menu menu = buildPopupMenu(mouseEvent.getX(), mouseEvent.getY());
if (menu != null) {
getEmbeddedSwingComposite().setMenu(menu);
menu.setVisible(true);
}
}
});
mouseEvent.consume();
}
if (!isInstance() && (getFlowchartPage().canvas.getAnchor() == -2 || designerCanvasSelection instanceof Note))
// no in-place editing unless specified
mouseEvent.consume();
} else if (event.getID() == MouseEvent.MOUSE_CLICKED) {
// don't propagate double-click events
MouseEvent mouseEvent = (MouseEvent) event;
if (mouseEvent.getClickCount() > 1)
mouseEvent.consume();
} else if (event.getID() == MouseEvent.MOUSE_DRAGGED) {
MouseEvent mouseEvent = (MouseEvent) event;
// ignore drag events for instances and read-only
if (isInstance() || (process.isReadOnly() && flowchartPage.canvas.getMarquee() == null))
mouseEvent.consume();
} else if (event.getID() == MouseEvent.MOUSE_PRESSED) {
// set the current selection
MouseEvent mouseEvent = (MouseEvent) event;
final boolean doubleClick = mouseEvent.getClickCount() > 1;
if (doubleClick)
// don't select twice
mouseEvent.consume();
else
handleSelection(mouseEvent);
if (!isInstance() && getFlowchartPage().canvas.getAnchor() == -2)
// no in-place editing
mouseEvent.consume();
final boolean isSubProcessActivity = designerCanvasSelection instanceof Activity && ((Activity) designerCanvasSelection).isSubProcessInvoke();
final boolean isScriptActivity = designerCanvasSelection instanceof Activity && ((Activity) designerCanvasSelection).isScript();
getDisplay().asyncExec(new Runnable() {
public void run() {
setEditorFocus();
getSelectionProvider().setSelection(designerCanvasSelection);
if (doubleClick) {
showPropertiesView();
if (!isInstance() && MdwPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREFS_DOUBLE_CLICK_OPENS_SUBPROCESSES_AND_SCRIPTS)) {
if (isSubProcessActivity) {
Activity subProcessActivity = (Activity) designerCanvasSelection;
openSubProcess(subProcessActivity);
} else if (isScriptActivity) {
Activity scriptActivity = (Activity) designerCanvasSelection;
openScript(scriptActivity);
}
}
}
}
});
} else if (event.getID() == KeyEvent.KEY_PRESSED) {
KeyEvent keyEvent = (KeyEvent) event;
int keycode = keyEvent.getKeyCode();
if (keycode != KeyEvent.VK_DELETE && keycode != KeyEvent.VK_UP && keycode != KeyEvent.VK_DOWN && keycode != KeyEvent.VK_LEFT && keycode != KeyEvent.VK_RIGHT) {
keyEvent.consume();
}
} else if (event.getID() == KeyEvent.KEY_RELEASED) {
KeyEvent keyEvent = (KeyEvent) event;
// override ctrl-x since canvas uses non-standard mnemonics
if (keyEvent.isControlDown() && keyEvent.getKeyCode() == KeyEvent.VK_X) {
cutSelection();
keyEvent.consume();
}
}
if (!isInstance()) {
// check for effect on dirtiness
boolean newDirty = getFlowchartPage().getProcess().dirtyLevel > 0;
if (newDirty != dirty) {
dirty = newDirty;
getDisplay().asyncExec(new Runnable() {
public void run() {
fireDirtyStateChanged(dirty);
}
});
}
}
}
use of com.centurylink.mdw.plugin.designer.model.Note in project mdw-designer by CenturyLinkCloud.
the class ProcessCanvasWrapper method handleSelection.
private void handleSelection(MouseEvent mouseEvent) {
Graph lProcess = null;
if (isInstance())
lProcess = getProcessInstancePage().getProcess();
else
lProcess = getFlowchartPage().getProcess();
int mouseX = mouseEvent.getX();
int mouseY = mouseEvent.getY();
if (lProcess.zoom != 100) {
mouseX = mouseX * 100 / lProcess.zoom;
mouseY = mouseY * 100 / lProcess.zoom;
}
Object obj = null;
if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
if (isInstance())
obj = getProcessInstancePage().canvas.objectAt(lProcess, mouseX, mouseY, getProcessInstancePage().canvas.getGraphics());
else
obj = getFlowchartPage().canvas.objectAt(lProcess, mouseX, mouseY, getFlowchartPage().canvas.getGraphics());
} else {
obj = lProcess.objectAt(mouseX, mouseY, isInstance() ? getProcessInstancePage().canvas.getGraphics() : getFlowchartPage().canvas.getGraphics());
}
if (obj != null) {
DesignerProxy designerProxy = getProcess().getProject().getDesignerProxy();
// create the appropriate DesignerCanvasSelection
if (obj instanceof Node) {
ActivityImpl actImpl = getProcess().getProject().getActivityImpl(((Node) obj).nodet.getImplementorClassName());
Activity activity = new Activity((Node) obj, getProcess(), actImpl);
if (isInstance()) {
activity.setProcessInstance(getProcess().getProcessInstance());
List<ActivityInstanceVO> activityInstances = getProcess().getProcessInstance().getActivityInstances(activity.getId());
if (activityInstances.isEmpty() && getProcess().getEmbeddedSubProcessInstances() != null) {
// try embedded subprocess instances
for (ProcessInstanceVO embeddedSubProcessInstance : getProcess().getEmbeddedSubProcessInstances()) activityInstances.addAll(embeddedSubProcessInstance.getActivityInstances(activity.getId()));
}
activity.setInstances(activityInstances);
if (activity.isManualTask()) {
activity.setTaskInstances(getProcess().getMainTaskInstances(activity.getId()));
activity.setSubTaskInstances(getProcess().getSubTaskInstances(activity.getId()));
}
if (activity.isSubProcessInvoke()) {
// TODO: load subprocess instances when process instance
// id loaded (like manual task instances above)
List<ProcessInstanceVO> subProcessInstances = designerProxy.getSubProcessInstances(getProcess(), activity);
if (subProcessInstances.isEmpty() && getProcess().getEmbeddedSubProcessInstances() != null) {
for (ProcessInstanceVO embeddedSubProcessInstance : getProcess().getEmbeddedSubProcessInstances()) subProcessInstances.addAll(designerProxy.getSubProcessInstances(embeddedSubProcessInstance, activity));
}
activity.setSubProcessInstances(subProcessInstances);
}
} else {
if (activity.getLogicalId() == null)
activity.setLogicalId(lProcess.generateLogicalId("A"));
if (Node.ID_SEQUENCE.equals(getNodeIdType()) && activity.getSequenceId() == 0)
lProcess.assignSequenceIds();
}
designerCanvasSelection = activity;
} else if (obj instanceof Link) {
Transition transition = new Transition((Link) obj, getProcess());
if (isInstance())
transition.setInstances(getProcess().getProcessInstance().getTransitionInstances(transition.getId()));
designerCanvasSelection = transition;
} else if (obj instanceof SubGraph) {
EmbeddedSubProcess embeddedSubProcess = new EmbeddedSubProcess((SubGraph) obj, getProcess());
if (isInstance()) {
embeddedSubProcess.setSubProcessInstances(((SubGraph) obj).getInstances());
}
designerCanvasSelection = embeddedSubProcess;
} else if (obj instanceof TextNote) {
TextNote textNote = (TextNote) obj;
Note note = new Note(textNote, getProcess());
designerCanvasSelection = note;
} else {
designerCanvasSelection = getProcess();
}
} else {
designerCanvasSelection = getProcess();
}
designerCanvasSelection.addDirtyStateListener(this);
}
Aggregations