use of org.apache.airavata.xbaya.ui.graph.GraphCanvasListener in project airavata by apache.
the class XBayaGUI method getNewGraphCanvas.
public GraphCanvas getNewGraphCanvas(String wfName, String wfDescription) {
GraphCanvas newGraphCanvas = new GraphCanvas(this.engine, wfName);
newGraphCanvas.setDescription(wfDescription);
this.graphCanvases.add(newGraphCanvas);
this.graphTabbedPane.addTab(newGraphCanvas.getWorkflow().getName(), newGraphCanvas.getSwingComponent());
final int index = graphTabbedPane.getTabCount() - 1;
TabLabelButton tabLabelButton = new TabLabelButton(graphTabbedPane, "Close this workflow");
graphTabbedPane.setTabComponentAt(index, tabLabelButton);
tabLabelButton.setCloseButtonListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeGraphCanvasFromIndex(index);
}
});
graphTabbedPane.addContainerListener(new ContainerListener() {
@Override
public void componentAdded(ContainerEvent event) {
}
@Override
public void componentRemoved(ContainerEvent event) {
List<GraphCanvas> graphCanvases = engine.getGUI().getGraphCanvases();
for (GraphCanvas graphCanvas : graphCanvases) {
if (graphCanvas.getSwingComponent() == event.getComponent()) {
if (graphCanvas.isWorkflowChanged()) {
setFocus(graphCanvas);
if (JOptionPane.showConfirmDialog(null, "The workflow '" + graphCanvas.getWorkflow().getName() + "' has been modified. Save changes?", "Save Workflow", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
graphFiler.saveWorkflow(graphCanvas);
}
}
break;
}
}
}
});
newGraphCanvas.addGraphCanvasListener(this.componentViewer);
newGraphCanvas.addGraphCanvasListener(this.portViewer);
newGraphCanvas.addGraphCanvasListener(new GraphCanvasListener() {
public void graphCanvasChanged(GraphCanvasEvent event) {
GraphCanvasEventType type = event.getType();
final GraphCanvas graphCanvas = event.getGraphCanvas();
final Workflow workflow = event.getWorkflow();
switch(type) {
case GRAPH_LOADED:
case NAME_CHANGED:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String name = workflow.getName();
// Change the name of the tab.
updateTabTitle(graphCanvas, workflow);
// Change the name of the frame.
setFrameName(name);
}
});
break;
case NODE_SELECTED:
case INPUT_PORT_SELECTED:
case OUTPUT_PORT_SELECTED:
// Do nothing
case WORKFLOW_CHANGED:
updateTabTitle(graphCanvas, graphCanvas.getWorkflow());
setFrameName(workflow.getName());
for (ChangeListener listener : tabChangeListeners) {
try {
listener.stateChanged(null);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
}
private void updateTabTitle(final GraphCanvas graphCanvas, final Workflow workflow) {
int index = XBayaGUI.this.graphTabbedPane.indexOfComponent(graphCanvas.getSwingComponent());
String newTitle = workflow.getName();
if (graphCanvas.isWorkflowChanged()) {
newTitle = "*" + newTitle;
}
XBayaGUI.this.graphTabbedPane.setTitleAt(index, newTitle);
}
});
return newGraphCanvas;
}
Aggregations