/**
* Check what elements are selected and changes the status accordingly.
*/
protected void checkSelection()
{
IEditor editor = am.getUi().getEditorFocus();
AbstractGraph graph = null;
Object selectedCell = null, mainCell = null;
if (isActive())
{
graph = null;
selectedCell = null;
if (editor != null)
{
graph = editor.getGraph();
selectedCell = graph.getSelectionCell();
mainCell = selectedCell;
}
boolean noSelection = (selectedCell == null && !arcpointSelected);
boolean routedArcSelected = false;
boolean xorArcSelected = false;
boolean unroutedArcSelected = false;
boolean transitionSelected = false;
boolean triggeredTransitionSelected = false;
boolean noTimeTriggerSelected = false;
boolean noMessageTriggerSelected = false;
boolean noResourceTriggerSelected = false;
boolean placeSelected = false;
boolean tokenPlaceSelected = false;
boolean subprocessSelected = false;
boolean arcSelected = false;
boolean nameSelected = false;
boolean operatorSelected = false;
boolean groupSelected = false;
boolean multipleSelected = false;
int triggerType = TriggerModel.TRIGGER_NONE;
while (selectedCell instanceof GroupModel)
{
selectedCell = ((GroupModel) selectedCell).getMainElement();
}
if (graph != null && graph.isGroup(mainCell) && ((GroupModel)mainCell).isUngroupable())
{
groupSelected = true;
}
else if (graph != null && graph.getSelectionCount() > 1)
{
multipleSelected = true;
}
else if (selectedCell instanceof ArcModel)
{
arcSelected = true;
ArcModel a = (ArcModel)selectedCell;
if (a.isXORsplit(editor.getModelProcessor()))
{
xorArcSelected = true;
}
if (((ArcModel) selectedCell).isRoute())
{
routedArcSelected = true;
}
else
{
unroutedArcSelected = true;
}
}
else if (selectedCell instanceof SubProcessModel)
{
subprocessSelected = true;
}
else if (selectedCell instanceof OperatorTransitionModel)
{
transitionSelected = true;
operatorSelected = true;
if (((OperatorTransitionModel) selectedCell).hasTrigger()) {
triggerType = ((OperatorTransitionModel)selectedCell).getTriggerType();
triggeredTransitionSelected = true;
}
if (triggerType != TriggerModel.TRIGGER_MESSAGE)
noMessageTriggerSelected = true;
if (triggerType != TriggerModel.TRIGGER_TIME)
noTimeTriggerSelected = true;
if (triggerType != TriggerModel.TRIGGER_RESOURCE)
noResourceTriggerSelected = true;
}
else if (selectedCell instanceof TransitionModel)
{
transitionSelected = true;
if (((TransitionModel)selectedCell).hasTrigger()) {
triggerType = ((TransitionModel)selectedCell).getTriggerType();
triggeredTransitionSelected = true;
}
if (triggerType != TriggerModel.TRIGGER_MESSAGE)
noMessageTriggerSelected = true;
if (triggerType != TriggerModel.TRIGGER_TIME)
noTimeTriggerSelected = true;
if (triggerType != TriggerModel.TRIGGER_RESOURCE)
noResourceTriggerSelected = true;
}
else if (selectedCell instanceof PlaceModel)
{
placeSelected = true;
if (((PlaceModel) selectedCell).hasTokens())
{
tokenPlaceSelected = true;
}
}
else if (selectedCell instanceof TriggerModel)
{
transitionSelected = true;
triggeredTransitionSelected = true;
triggerType = ((TriggerModel)selectedCell).getTriggertype();
if (triggerType != TriggerModel.TRIGGER_MESSAGE)
noMessageTriggerSelected = true;
if (triggerType != TriggerModel.TRIGGER_TIME)
noTimeTriggerSelected = true;
if (triggerType != TriggerModel.TRIGGER_RESOURCE)
noResourceTriggerSelected = true;
}
else if (selectedCell instanceof NameModel)
{
nameSelected = true;
}
setStatus(NO_SELECTION, noSelection);
setStatus(ANY_SELECTION, !noSelection && !nameSelected && !arcpointSelected);
setStatus(SUBPROCESS_SELECTION, subprocessSelected);
setStatus(PLACE_SELECTION, placeSelected);
setStatus(TOKEN_PLACE_SELECTION, tokenPlaceSelected);
setStatus(ROUTED_ARC_SELECTION, routedArcSelected);
setStatus(NODE_OR_XORARC_SELECTION, (transitionSelected | placeSelected | xorArcSelected) && !arcpointSelected);
setStatus(UNROUTED_ARC_SELECTION, unroutedArcSelected);
setStatus(TRANSITION_SELECTION, transitionSelected);
setStatus(NODE_SELECTION, transitionSelected | placeSelected | subprocessSelected);
setStatus(TRIGGERED_TRANSITION_SELECTION, triggeredTransitionSelected);
setStatus(TIME_TRIGGER_SELECTION, noTimeTriggerSelected);
setStatus(RESOURCE_TRIGGER_SELECTION, noResourceTriggerSelected);
setStatus(MESSAGE_TRIGGER_SELECTION, noMessageTriggerSelected);
setStatus(TRIGGERED_TRANSITION_SELECTION, triggeredTransitionSelected);
setStatus(ARC_SELECTION, arcSelected && !arcpointSelected);
setStatus(ARCPOINT_SELECTION, arcpointSelected);
setStatus(OPERATOR_SELECTION, operatorSelected);
setStatus(GROUP_SELECTION, groupSelected);
setStatus(MULTIPLE_SELECTION, multipleSelected);
setStatus(CAN_CUTCOPY, transitionSelected | placeSelected | multipleSelected | groupSelected | subprocessSelected);
setStatus(CAN_PASTE, editor == null ? false : !editor.isClipboardEmpty());
setStatus(CAN_RENAME, subprocessSelected);
};
}