Search in sources :

Example 1 with GraphCanvasListener

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;
}
Also used : ContainerEvent(java.awt.event.ContainerEvent) TabLabelButton(org.apache.airavata.xbaya.ui.widgets.TabLabelButton) ActionEvent(java.awt.event.ActionEvent) Workflow(org.apache.airavata.workflow.model.wf.Workflow) InvocationTargetException(java.lang.reflect.InvocationTargetException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) MonitorException(org.apache.airavata.xbaya.messaging.MonitorException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) ActionListener(java.awt.event.ActionListener) GraphCanvasEventType(org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent.GraphCanvasEventType) GraphCanvasListener(org.apache.airavata.xbaya.ui.graph.GraphCanvasListener) ContainerListener(java.awt.event.ContainerListener) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ChangeListener(javax.swing.event.ChangeListener) GraphCanvasEvent(org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent) GraphCanvas(org.apache.airavata.xbaya.ui.graph.GraphCanvas)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ContainerEvent (java.awt.event.ContainerEvent)1 ContainerListener (java.awt.event.ContainerListener)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ChangeListener (javax.swing.event.ChangeListener)1 WorkflowException (org.apache.airavata.workflow.model.exceptions.WorkflowException)1 WorkflowRuntimeException (org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException)1 Workflow (org.apache.airavata.workflow.model.wf.Workflow)1 MonitorException (org.apache.airavata.xbaya.messaging.MonitorException)1 GraphCanvas (org.apache.airavata.xbaya.ui.graph.GraphCanvas)1 GraphCanvasEvent (org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent)1 GraphCanvasEventType (org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent.GraphCanvasEventType)1 GraphCanvasListener (org.apache.airavata.xbaya.ui.graph.GraphCanvasListener)1 TabLabelButton (org.apache.airavata.xbaya.ui.widgets.TabLabelButton)1