MenuItem formatItem = new MenuItem(FORMAT_ITEM_NAME);
actionsMenu.add(formatItem);
PopupMenu orderSubMenu = new PopupMenu(ORDER_SUB_POP_MENU_NAME);
ModelGraph modelGraph = state.getSelected();
newSubMenu.setEnabled(modelGraph == null
|| modelGraph.getModel().isParentType());
deleteItem.setEnabled(modelGraph != null);
formatItem.setEnabled(true);
if (modelGraph != null) {
viewReferrencedWorkflow.setEnabled(modelGraph.getModel().isRef());
taskItem.setEnabled(!modelGraph.isCondition());
condItem.setEnabled(modelGraph.isCondition());
orderSubMenu.setEnabled(modelGraph.getParent() != null
&& !(modelGraph.isCondition() && !modelGraph.getParent()
.isCondition()));
} else {
boolean isCondition = false;
if (state.getGraphs().size() > 0)
isCondition = state.getGraphs().get(0).isCondition();
viewReferrencedWorkflow.setEnabled(false);
taskItem.setEnabled(!isCondition);
condItem.setEnabled(isCondition);
}
actionsMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(DELETE_ITEM_NAME)) {
GuiUtils.removeNode(state.getGraphs(), state.getSelected().getModel());
state.setSelected(null);
GraphView.this.notifyListeners();
} else if (e.getActionCommand().equals(FORMAT_ITEM_NAME)) {
GraphView.this.refreshView(state);
} else if (e.getActionCommand().equals(VIEW_REF_WORKFLOW)) {
scrollSelectedToVisible = true;
GraphView.this.notifyListeners(new ViewChange.VIEW_MODEL(state
.getSelected().getModel().getModelId(), GraphView.this));
}
}
});
PopupMenu edgesSubMenu = new PopupMenu(EDGES_SUB_POP_MENU_NAME);
edgesSubMenu.add(new MenuItem(TASK_LEVEL));
edgesSubMenu.add(new MenuItem(WORKFLOW_LEVEL));
actionsMenu.add(edgesSubMenu);
edgesSubMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(TASK_LEVEL)) {
state.setProperty(EDGE_DISPLAY_MODE, TASK_MODE);
} else if (e.getActionCommand().equals(WORKFLOW_LEVEL)) {
state.setProperty(EDGE_DISPLAY_MODE, WORKFLOW_MODE);
}
GraphView.this.refreshView(state);
}
});
actionsMenu.add(orderSubMenu);
orderSubMenu.add(new MenuItem(TO_FRONT_ITEM_NAME));
orderSubMenu.add(new MenuItem(TO_BACK_ITEM_NAME));
orderSubMenu.add(new MenuItem(FORWARD_ITEM_NAME));
orderSubMenu.add(new MenuItem(BACKWARDS_ITEM_NAME));
orderSubMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ModelGraph graph = state.getSelected();
ModelGraph parent = graph.getParent();
if (e.getActionCommand().equals(TO_FRONT_ITEM_NAME)) {
if (parent.getChildren().remove(graph))
parent.getChildren().add(0, graph);
} else if (e.getActionCommand().equals(TO_BACK_ITEM_NAME)) {
if (parent.getChildren().remove(graph))
parent.getChildren().add(graph);
} else if (e.getActionCommand().equals(FORWARD_ITEM_NAME)) {
int index = parent.getChildren().indexOf(graph);
if (index != -1) {
parent.getChildren().remove(index);
parent.getChildren().add(
Math.min(parent.getChildren().size(), index + 1), graph);
}
} else if (e.getActionCommand().equals(BACKWARDS_ITEM_NAME)) {
int index = parent.getChildren().indexOf(graph);
if (index != -1) {
parent.getChildren().remove(index);
parent.getChildren().add(Math.max(0, index - 1), graph);
}
}
GraphView.this.notifyListeners();
}