airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samin...@apache.org
Subject [57/90] [abbrv] AIRAVATA-1124
Date Mon, 14 Apr 2014 18:30:59 GMT
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/RunMenuItem.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/RunMenuItem.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/RunMenuItem.java
new file mode 100644
index 0000000..ab8f102
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/RunMenuItem.java
@@ -0,0 +1,412 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.menues;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.wf.WorkflowExecutionState;
+import org.apache.airavata.ws.monitor.Monitor;
+import org.apache.airavata.ws.monitor.MonitorConfiguration;
+import org.apache.airavata.ws.monitor.MonitorException;
+import org.apache.airavata.ws.monitor.event.Event;
+import org.apache.airavata.ws.monitor.event.Event.Type;
+import org.apache.airavata.ws.monitor.event.EventListener;
+import org.apache.airavata.xbaya.XBayaConfiguration;
+import org.apache.airavata.xbaya.XBayaConfiguration.XBayaExecutionMode;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.core.ide.XBayaExecutionModeListener;
+import org.apache.airavata.xbaya.ui.dialogs.graph.dynamic.DynamicWorkflowRunnerWindow;
+import org.apache.airavata.xbaya.ui.dialogs.monitor.MonitorConfigurationWindow;
+import org.apache.airavata.xbaya.ui.experiment.WorkflowInterpreterLaunchWindow;
+import org.apache.airavata.xbaya.ui.monitor.MonitorStarter;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.apache.airavata.xbaya.ui.widgets.ToolbarButton;
+import org.apache.airavata.xbaya.ui.widgets.XBayaToolBar;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RunMenuItem  implements EventListener, XBayaExecutionModeListener{
+
+    private XBayaEngine engine;
+
+    private JMenu runMenu;
+    
+//    private JMenuItem launchDynamicWorkflowItem;
+
+    private JMenuItem launchXBayaInterpreterItem;
+
+    private JMenuItem configMonitorItem;
+
+    private JMenuItem resumeMonitoringItem;
+
+    private JMenuItem pauseMonitoringItem;
+
+    private JMenuItem resetMonitoringItem;
+
+    private static final Logger logger = LoggerFactory.getLogger(RunMenuItem.class);
+
+	private static final String EXECUTE_ACTIONS = "run_actions";
+	private static final String EXECUTE_MONITOR_ACTIONS = "monitor_actions";
+
+    private XBayaToolBar toolBar;
+
+	private ToolbarButton toolbarButtonRunWorkflow;
+
+	private ToolbarButton toolbarButtonPauseMonitor;
+
+	private ToolbarButton toolbarButtonResumeMonitor;
+
+	private JMenuItem stopWorkflowItem;
+
+	private ToolbarButton toolbarButtonStopWorkflow;
+    
+    /**
+     * Constructs a WorkflowMenu.
+     * 
+     * @param engine
+     */
+    public RunMenuItem(XBayaEngine engine, XBayaToolBar toolBar) {
+        this.engine = engine;
+        setToolBar(toolBar);
+        createWorkflowMenu();
+        Monitor monitor = this.engine.getMonitor();
+        monitor.addEventListener(this);
+        monitor.getConfiguration().addEventListener(this);
+        engine.getConfiguration().registerExecutionModeChangeListener(this);
+        XBayaToolBar.setGroupOrder(EXECUTE_ACTIONS, 5);
+        XBayaToolBar.setGroupOrder(EXECUTE_MONITOR_ACTIONS, 6);
+    }
+
+    /**
+     * @return The workflow menu.
+     */
+    public JMenu getMenu() {
+        return this.runMenu;
+    }
+
+    /**
+     * Creates workflow menu.
+     */
+    private void createWorkflowMenu() {
+//        this.launchDynamicWorkflowItem = createLaunchDynamicWorkflowItem();
+        createLaunchXBayaInterpreterItem();
+        this.configMonitorItem = createConfigMonitoring();
+        this.resumeMonitoringItem = createResumeMonitoring();
+        this.pauseMonitoringItem = createPauseMonitoring();
+        this.resetMonitoringItem = createResetMonitoring();
+        stopWorkflowItem = createStopWorkflow();
+        
+        runMenu = new JMenu("Run");
+        runMenu.setMnemonic(KeyEvent.VK_R);
+
+        runMenu.add(launchXBayaInterpreterItem);
+//        runMenu.add(launchDynamicWorkflowItem);
+        
+        runMenu.addSeparator();
+        runMenu.add(stopWorkflowItem);
+
+        runMenu.addSeparator();
+        
+        runMenu.add(this.resumeMonitoringItem);
+        runMenu.add(this.pauseMonitoringItem);
+        runMenu.add(this.resetMonitoringItem);
+        runMenu.add(this.configMonitorItem);
+        
+        runMenu.addMenuListener(new MenuListener(){
+			@Override
+			public void menuCanceled(MenuEvent e) {}
+			@Override
+			public void menuDeselected(MenuEvent e) {}
+			@Override
+			public void menuSelected(MenuEvent e) {
+				stopWorkflowItem.setEnabled(isWorkflowRunning());
+			}
+        });
+        
+        setupMonitors();
+        startStopButtonStateUpdater();
+        executionModeChanged(engine.getConfiguration());
+    }
+
+	private void setupMonitors() {
+		SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+            	while(engine.getGUI()==null){
+            		Thread.yield();
+            	}
+                engine.getGUI().addWorkflowTabChangeListener(new ChangeListener(){
+					@Override
+					public void stateChanged(ChangeEvent event) {
+						boolean runShouldBeActive = isRunShouldBeActive();
+						toolbarButtonRunWorkflow.setEnabled(runShouldBeActive);	
+//						launchDynamicWorkflowItem.setEnabled(runShouldBeActive);
+						launchXBayaInterpreterItem.setEnabled(runShouldBeActive);
+					}
+                });
+            }
+        });
+	}
+    
+    private JMenuItem createConfigMonitoring() {
+        JMenuItem item = new JMenuItem("Configure Monitoring...");
+        item.setMnemonic(KeyEvent.VK_C);
+        item.addActionListener(new AbstractAction() {
+            private MonitorConfigurationWindow window;
+
+            public void actionPerformed(ActionEvent e) {
+                if (this.window == null) {
+                    this.window = new MonitorConfigurationWindow(engine);
+                }
+                this.window.show();
+            }
+        });
+        return item;
+    }
+
+    private JMenuItem createResumeMonitoring() {
+        JMenuItem item = new JMenuItem("Resume monitoring",MenuIcons.MONITOR_RESUME_ICON);
+        item.setMnemonic(KeyEvent.VK_S);
+        AbstractAction action = new AbstractAction() {
+            private MonitorStarter starter;
+
+            public void actionPerformed(ActionEvent event) {
+                if (this.starter == null) {
+                    this.starter = new MonitorStarter(engine);
+                }
+                this.starter.start();
+            }
+        };
+		item.addActionListener(action);
+        boolean valid = this.engine.getMonitor().getConfiguration().isValid();
+        item.setVisible(valid);
+        toolbarButtonResumeMonitor = getToolBar().addToolbarButton(EXECUTE_MONITOR_ACTIONS,item.getText(), MenuIcons.MONITOR_RESUME_ICON, "Resume monitoring", action,4);
+        toolbarButtonResumeMonitor.setEnabled(false);
+        return item;
+    }
+
+    private JMenuItem createPauseMonitoring() {
+        JMenuItem item = new JMenuItem("Pause monitoring", MenuIcons.MONITOR_PAUSE_ICON);
+        item.setMnemonic(KeyEvent.VK_T);
+        AbstractAction action = new AbstractAction() {
+            public void actionPerformed(ActionEvent event) {
+                try {
+                    engine.getMonitor().stopMonitoring();
+                } catch (RuntimeException e) {
+                    engine.getGUI().getErrorWindow().error(ErrorMessages.MONITOR_ERROR, e);
+                } catch (Error e) {
+                    engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+                }
+            }
+        };
+		item.addActionListener(action);
+        item.setVisible(false);
+        toolbarButtonPauseMonitor = getToolBar().addToolbarButton(EXECUTE_MONITOR_ACTIONS,item.getText(), MenuIcons.MONITOR_PAUSE_ICON, "Pause monitoring", action,3);
+        toolbarButtonPauseMonitor.setEnabled(false);
+        return item;
+    }
+
+    private JMenuItem createResetMonitoring() {
+        JMenuItem item = new JMenuItem("Reset monitoring");
+        item.setMnemonic(KeyEvent.VK_R);
+        item.addActionListener(new AbstractAction() {
+            public void actionPerformed(ActionEvent event) {
+                engine.getMonitor().resetEventData();
+            }
+        });
+        item.setVisible(false);
+        return item;
+    }
+
+    private JMenuItem createStopWorkflow() {
+        JMenuItem item = new JMenuItem("Stop running workflow",MenuIcons.STOP_ICON);
+        item.setMnemonic(KeyEvent.VK_S);
+        AbstractAction action = new AbstractAction() {
+            public void actionPerformed(ActionEvent event) {
+                cleanup();
+            }
+        };
+		item.addActionListener(action);
+        item.setEnabled(false);
+        toolbarButtonStopWorkflow = getToolBar().addToolbarButton(EXECUTE_ACTIONS,item.getText(), MenuIcons.STOP_ICON, "Stop workflow", action,2);
+        toolbarButtonStopWorkflow.setEnabled(item.isEnabled());
+        return item;
+    }
+
+    private JMenuItem createLaunchDynamicWorkflowItem() {
+        JMenuItem menuItem = new JMenuItem("Run workflow...");
+        menuItem.setMnemonic(KeyEvent.VK_D);
+        AbstractAction action = new AbstractAction() {
+            private DynamicWorkflowRunnerWindow window;
+
+            public void actionPerformed(ActionEvent event) {
+            	if (isWorkflowRunning()){
+            		if (JOptionPane.showConfirmDialog(null, "A previous workflow excution data needs to be cleared before launching another workflow. Do you wish to continue?", "Run Dynamic Workflow", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
+            			cleanup();
+                    }else{
+            			return;
+            		}
+            	}
+                if (this.window == null) {
+                    int count = 0;
+                    //there is a possibility the ealier run is not yet cleanedup yet.. so wait until it finishes
+                    // and sets the execution state to NONE as the last task of scheduleDynamically
+                    while(engine.getGUI().getWorkflow().getExecutionState() != WorkflowExecutionState.NONE){
+                        try {
+                            Thread.sleep(500);
+                        } catch (InterruptedException e) {
+                            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                        }
+                        count++;
+                        if(count > 20){
+                            throw new WorkflowRuntimeException("Error stopping previous workflow Execution");
+                        }
+                    }
+                    
+                }
+                this.window = new DynamicWorkflowRunnerWindow(engine);
+                this.window.show();
+            }
+        };
+		menuItem.addActionListener(action);
+		menuItem.setEnabled(false);
+        return menuItem;
+    }
+    
+    private boolean isRunShouldBeActive() {
+		return engine.getGUI().getGraphCanvas() !=null;
+	}
+    
+    private void createLaunchXBayaInterpreterItem() {
+        this.launchXBayaInterpreterItem = new JMenuItem("Run on Interpreter Server...", MenuIcons.RUN_ICON);
+        AbstractAction action = new AbstractAction() {
+            private WorkflowInterpreterLaunchWindow window;
+            public void actionPerformed(ActionEvent e) {
+                if(!engine.getMonitor().hasCurrentExecutionTerminatedNotificationReceived() && engine.getMonitor().isMonitoring()){
+                    if (JOptionPane.showConfirmDialog(null,
+                            "A previous workflow execution data needs to be cleared before launching another workflow. Do you wish to continue?",
+                            "Run Workflow", JOptionPane.YES_NO_OPTION)!=JOptionPane.YES_OPTION){
+                        return;
+                    }
+                }
+//                if (this.window == null) {
+                this.window = new WorkflowInterpreterLaunchWindow(engine);
+//                }
+                try {
+                    this.window.show();
+                } catch (Exception e1) {
+                    engine.getGUI().getErrorWindow().error(e1);
+                }
+            }
+        };
+        launchXBayaInterpreterItem.addActionListener(action);
+        toolbarButtonRunWorkflow = getToolBar().addToolbarButton(EXECUTE_ACTIONS, launchXBayaInterpreterItem.getText(), MenuIcons.RUN_ICON, "Run workflow", action,1);
+        toolbarButtonRunWorkflow.setEnabled(launchXBayaInterpreterItem.isEnabled());
+        launchXBayaInterpreterItem.setEnabled(false);
+    }
+    
+    /**
+     * @see org.apache.airavata.ws.monitor.event.EventListener#eventReceived(org.apache.airavata.ws.monitor.event.Event)
+     */
+    public void eventReceived(Event event) {
+        Type type = event.getType();
+        if (type.equals(Type.MONITOR_CONFIGURATION_CHANGED)) {
+            MonitorConfiguration configuration = this.engine.getMonitor().getConfiguration();
+            boolean valid = configuration.isValid();
+            resumeMonitoringItem.setVisible(valid);
+            pauseMonitoringItem.setVisible(false);
+            resetMonitoringItem.setVisible(false);
+        } else if (type.equals(Type.MONITOR_STARTED)) {
+            resumeMonitoringItem.setVisible(false);
+            pauseMonitoringItem.setVisible(true);
+            resetMonitoringItem.setVisible(true);
+        } else if (type.equals(Type.MONITOR_STOPED)) {
+            resumeMonitoringItem.setVisible(true);
+            pauseMonitoringItem.setVisible(false);
+            resetMonitoringItem.setVisible(false);
+        }
+        toolbarButtonPauseMonitor.setEnabled(pauseMonitoringItem.isVisible());
+        toolbarButtonResumeMonitor.setEnabled(resumeMonitoringItem.isVisible());
+    }
+
+	public XBayaToolBar getToolBar() {
+		return toolBar;
+	}
+
+	public void setToolBar(XBayaToolBar toolBar) {
+		this.toolBar = toolBar;
+	}
+	
+	private void cleanup() {
+		try {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            }
+            engine.getWorkflowInterpreter().cleanup();
+		} catch (MonitorException e) {
+			this.engine.getGUI().getErrorWindow().error(e);
+		}
+	}
+
+	private boolean isWorkflowRunning() {
+		return engine.getWorkflowInterpreter()!=null;
+	}
+
+	@Override
+	public void executionModeChanged(XBayaConfiguration config) {
+		toolbarButtonRunWorkflow.setVisible(config.getXbayaExecutionMode()==XBayaExecutionMode.IDE);
+		toolbarButtonStopWorkflow.setVisible(config.getXbayaExecutionMode()==XBayaExecutionMode.IDE);
+	}
+	
+	private void startStopButtonStateUpdater() {
+		Thread t=new Thread(){
+			@Override
+			public void run() {
+				while(true){
+					toolbarButtonStopWorkflow.setEnabled(isWorkflowRunning());
+//					if (!isWorkflowRunning()){
+//						pauseMonitorButton.setEnabled(false);
+//						resumeMonitorButton.setEnabled(false);
+//					}
+					try {
+						Thread.sleep(1000);
+					} catch (InterruptedException e) {
+					}
+				}
+			}
+		};
+		t.start();
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/ViewMenuItem.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/ViewMenuItem.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/ViewMenuItem.java
new file mode 100644
index 0000000..ab12e13
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/ViewMenuItem.java
@@ -0,0 +1,140 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.menues;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.net.URI;
+import java.util.List;
+
+import javax.swing.AbstractAction;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ViewMenuItem {
+
+	private XBayaEngine engine;
+
+	private JMenu viewMenu;
+
+	private JMenuItem jcrRegistryView;
+
+	private JMenuItem componentsView;
+
+	private JMenuItem monitoringView;
+
+	private JMenuItem parametersView;
+
+	private static final Logger logger = LoggerFactory
+			.getLogger(ViewMenuItem.class);
+
+	/**
+	 * Constructs a WorkflowMenu.
+	 * 
+	 * @param engine
+	 */
+	public ViewMenuItem(XBayaEngine engine) {
+		this.engine = engine;
+		createWorkflowMenu();
+	}
+
+	/**
+	 * @return The workflow menu.
+	 */
+	public JMenu getMenu() {
+		return this.viewMenu;
+	}
+
+	/**
+	 * Creates workflow menu.
+	 */
+	private void createWorkflowMenu() {
+		this.jcrRegistryView = createShpwJCRRegistryView();
+		this.componentsView = createShowComponentsView();
+
+		monitoringView = createShowMonitoringView();
+		parametersView = createShowParameterView();
+
+		viewMenu = new JMenu("View");
+		viewMenu.setMnemonic(KeyEvent.VK_V);
+
+		viewMenu.add(this.jcrRegistryView);
+
+		viewMenu.addSeparator();
+
+		viewMenu.add(this.componentsView);
+
+		viewMenu.addSeparator();
+
+		viewMenu.add(monitoringView);
+		viewMenu.add(parametersView);
+	}
+
+	private JMenuItem createShpwJCRRegistryView() {
+		JMenuItem menuItem = new JMenuItem("Airavata Registry");
+		menuItem.addActionListener(new AbstractAction() {
+			public void actionPerformed(ActionEvent e) {
+				engine.getGUI().viewJCRBrowserPanel();
+			}
+		});
+		return menuItem;
+	}
+
+	private JMenuItem createShowComponentsView() {
+		JMenuItem menuItem = new JMenuItem("Components");
+		menuItem.addActionListener(new AbstractAction() {
+			public void actionPerformed(ActionEvent e) {
+				engine.getGUI().viewComponentTree();
+			}
+		});
+		return menuItem;
+	}
+
+	private JMenuItem createShowMonitoringView() {
+		JMenuItem menuItem = new JMenuItem("Monitoring");
+		menuItem.addActionListener(new AbstractAction() {
+			public void actionPerformed(ActionEvent e) {
+				// TODO
+			}
+		});
+		// FIXME remove this once save all functionality is fixed
+		menuItem.setEnabled(false);
+		return menuItem;
+	}
+
+	private JMenuItem createShowParameterView() {
+		JMenuItem menuItem = new JMenuItem("Parameters");
+		menuItem.addActionListener(new AbstractAction() {
+			public void actionPerformed(ActionEvent e) {
+				// TODO
+			}
+		});
+		// FIXME remove this once save all functionality is fixed
+		menuItem.setEnabled(false);
+		return menuItem;
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenu.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenu.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenu.java
new file mode 100644
index 0000000..5b472ed
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenu.java
@@ -0,0 +1,158 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.menues;
+
+import org.apache.airavata.xbaya.XBayaConfiguration;
+import org.apache.airavata.xbaya.XBayaConfiguration.XBayaExecutionMode;
+import org.apache.airavata.xbaya.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.core.ide.XBayaExecutionModeListener;
+//import org.apache.airavata.xbaya.menues.tools.ToolsMenuItem;
+import org.apache.airavata.xbaya.ui.XBayaGUI;
+import org.apache.airavata.xbaya.ui.dialogs.AboutWindow;
+import org.apache.airavata.xbaya.ui.widgets.XBayaComponent;
+import org.apache.airavata.xbaya.ui.widgets.XBayaToolBar;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+public class XBayaMenu implements XBayaComponent,XBayaExecutionModeListener{
+
+    private XBayaEngine engine;
+
+    private JMenuBar menuBar;
+
+	private XBayaMenuItem xBayaMenuItem;
+
+	private EditMenuItem editMenuItem;
+
+	private ViewMenuItem viewMenuItem;
+
+	private RunMenuItem runMenuItem;
+
+	private RegistryMenuItem registryMenuItem;
+
+    private AmazonEC2MenuItem amazonEC2MenuItem;
+
+//	private ToolsMenuItem toolsMenuItem;
+
+	private XBayaGUI gui;
+
+	private XBayaToolBar toolBar;
+	
+    /**
+     * Constructs an XwfMenu.
+     * 
+     * @param engine
+     */
+    public XBayaMenu(XBayaEngine engine, XBayaToolBar toolBar) {
+        this.setEngine(engine);
+        setToolBar(toolBar);
+        initMenu();
+		engine.getConfiguration().registerExecutionModeChangeListener(this);
+    }
+    
+	private void initMenu() {
+		xBayaMenuItem = new XBayaMenuItem(getEngine(),getToolBar());
+		editMenuItem = new EditMenuItem(getEngine());
+        amazonEC2MenuItem = new AmazonEC2MenuItem(getEngine());
+		viewMenuItem = new ViewMenuItem(getEngine());
+		runMenuItem = new RunMenuItem(getEngine(), getToolBar());
+		registryMenuItem = new RegistryMenuItem(getEngine(),getToolBar());
+//		toolsMenuItem = new ToolsMenuItem(getEngine());
+
+		createMenuBar();
+		executionModeChanged(getEngine().getConfiguration());
+	}
+
+    /**
+     * Returns the menu bar.
+     * 
+     * @return The menu bar.
+     */
+    public JMenuBar getSwingComponent() {
+        return this.menuBar;
+    }
+
+    /**
+     * Creates the menu bar.
+     */
+    private void createMenuBar() {
+        this.menuBar = new JMenuBar();
+        menuBar.add(xBayaMenuItem.getMenu());
+        menuBar.add(editMenuItem.getMenu());
+        menuBar.add(viewMenuItem.getMenu());
+        menuBar.add(runMenuItem.getMenu());
+//        menuBar.add(toolsMenuItem.getMenu());
+        menuBar.add(registryMenuItem.getMenu());
+        menuBar.add(amazonEC2MenuItem.getMenu());
+        // Space before Help
+        this.menuBar.add(Box.createHorizontalGlue());
+
+        this.menuBar.add(createHelpMenu());
+    }
+
+    private JMenu createHelpMenu() {
+        // Help
+        JMenu helpMenu = new JMenu("Help");
+        helpMenu.setMnemonic(KeyEvent.VK_H);
+
+        JMenuItem aboutItem = new JMenuItem("About " + XBayaConstants.APPLICATION_SHORT_NAME);
+        aboutItem.setMnemonic(KeyEvent.VK_A);
+        aboutItem.addActionListener(new AbstractAction() {
+            private AboutWindow window;
+
+            public void actionPerformed(ActionEvent event) {
+                if (this.window == null) {
+                    this.window = new AboutWindow(XBayaMenu.this.getEngine());
+                }
+                this.window.show();
+            }
+        });
+        helpMenu.add(aboutItem);
+
+        return helpMenu;
+    }
+
+	public XBayaEngine getEngine() {
+		return engine;
+	}
+
+	public void setEngine(XBayaEngine engine) {
+		this.engine = engine;
+	}
+
+	public XBayaToolBar getToolBar() {
+		return toolBar;
+	}
+
+	public void setToolBar(XBayaToolBar toolBar) {
+		this.toolBar = toolBar;
+	}
+
+	@Override
+	public void executionModeChanged(XBayaConfiguration config) {
+		this.menuBar.setVisible(config.getXbayaExecutionMode()==XBayaExecutionMode.IDE);	
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
new file mode 100644
index 0000000..98dad2b
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
@@ -0,0 +1,610 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.menues;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+
+import org.apache.airavata.xbaya.XBayaConfiguration;
+import org.apache.airavata.xbaya.XBayaConfiguration.XBayaExecutionMode;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.component.registry.ComponentRegistryLoader;
+import org.apache.airavata.xbaya.core.generators.BPELFiler;
+import org.apache.airavata.xbaya.core.generators.ImageFiler;
+import org.apache.airavata.xbaya.core.generators.JythonFiler;
+import org.apache.airavata.xbaya.core.generators.ODEScriptFiler;
+import org.apache.airavata.xbaya.core.generators.WorkflowFiler;
+import org.apache.airavata.xbaya.core.ide.XBayaExecutionModeListener;
+import org.apache.airavata.xbaya.registry.RegistryAccesser;
+import org.apache.airavata.xbaya.ui.dialogs.component.URLRegistryWindow;
+import org.apache.airavata.xbaya.ui.dialogs.descriptors.ApplicationDescriptionDialog;
+import org.apache.airavata.xbaya.ui.dialogs.descriptors.DeploymentDescriptionDialog;
+import org.apache.airavata.xbaya.ui.dialogs.descriptors.HostDescriptionDialog;
+import org.apache.airavata.xbaya.ui.experiment.RegistryLoaderWindow;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
+import org.apache.airavata.xbaya.ui.widgets.ToolbarButton;
+import org.apache.airavata.xbaya.ui.widgets.XBayaToolBar;
+import org.apache.airavata.xbaya.util.RegistryConstants;
+import org.apache.airavata.xbaya.util.XBayaUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class XBayaMenuItem implements XBayaExecutionModeListener {
+
+    private static final Logger logger = LoggerFactory.getLogger(XBayaMenuItem.class);
+
+    private JMenu xbayaMenuItem;
+
+    private WorkflowFiler graphFiler;
+
+    private JythonFiler jythonFiler;
+
+    private ImageFiler imageFiler;
+
+    private BPELFiler bpelFiler;
+
+//    private ScuflFiler scuflFiler;
+    
+    private JMenuItem urlItem;
+
+//    private ODEDeploymentDescriptor odeDeploymentDescription;
+
+    private JMenuItem openWorkflowItem;
+
+    private JMenuItem saveWorkflowItem;
+
+    private JMenuItem exportJythonItem;
+
+    private JMenuItem exportBpelItem;
+
+    private JMenuItem saveImageItem;
+
+    private JMenuItem importWorkflowItemFromFileSystem;
+
+    private JMenuItem exportODEScriptsItem;
+    
+    private JMenuItem clearWorkflowItem;
+
+    private JMenuItem newWorkflowTabItem;
+
+    private JMenuItem closeWorkflowItem;
+
+    private JMenuItem nextWorkflowTabItem;
+    
+    private JMenuItem exitItem;
+
+    private XBayaEngine engine;
+    
+    private JMenuItem registerServiceDesc;
+
+    private JMenuItem registerApplicationDesc;
+
+    private JMenuItem registerHostDesc;
+
+	private JMenuItem closeAllWorkflowItem;
+
+	private JMenuItem saveAsWorkflowItem;
+
+	private JMenuItem saveAllWorkflowItem;
+
+    private JMenuItem saveWorkflowtoRegistryItem;
+
+	private JMenuItem importWorkflowItemFromRegistry;
+
+	private RegistryAccesser registryAccesser;
+
+	private XBayaToolBar toolBar;
+
+	private ToolbarButton toolbarButtonSave;
+
+	private ToolbarButton toolbarButtonOpen;
+
+	private ToolbarButton toolbarButtonNew;
+	
+	private static final String FILE_ACTIONS="file";
+	
+    /**
+     * Constructs a FileMenu.
+     * 
+     * @param engine
+     * 
+     */
+    public XBayaMenuItem(XBayaEngine engine, XBayaToolBar toolBar) {
+        this.engine = engine;
+        this.toolBar=toolBar;
+        this.registryAccesser = new RegistryAccesser(engine);
+
+        this.graphFiler = new WorkflowFiler(engine);
+        this.jythonFiler = new JythonFiler(engine);
+        this.imageFiler = new ImageFiler(engine);
+        this.bpelFiler = new BPELFiler(engine);
+//        this.scuflFiler = new ScuflFiler(engine);
+//        this.odeDeploymentDescription = new ODEDeploymentDescriptor();
+
+        this.exitItem = createExitItem();
+
+        createFileMenu();
+        engine.getConfiguration().registerExecutionModeChangeListener(this);
+        XBayaToolBar.setGroupOrder(FILE_ACTIONS, 1);
+    }
+
+    private void createFileMenu() {
+
+        createOpenWorkflowMenuItem();
+        createSaveWorkflowItem();
+        createSaveAsWorkflowItem();
+        createSaveAllWorkflowItem();
+        createSaveWorkflowtoRegistryItem();
+
+        createImportWorkflowItemFromFileSystem();
+        createImportWorkflowItemFromRegistry();
+        createExportJythonScriptItem();
+        createExportBpelScriptItem();
+        createSaveWorkflowImageItem();
+        createExportODEScriptsItem();
+        
+        clearWorkflowItem = createClearWorkflowItem();
+        newWorkflowTabItem = createNewWorkflowTabMenuItem();
+        closeWorkflowItem = createCloseWorkflowTabItem();
+        closeAllWorkflowItem = createCloseAllWorkflowTabItem();
+        nextWorkflowTabItem = createNextWorkflowTabItem();
+        urlItem = createURLRegistryItem();
+        
+        createRegisterHostDesc();
+        createRegisterServiceDesc();
+        createRegisterApplicationDesc();
+        
+        xbayaMenuItem = new JMenu("XBaya");
+        xbayaMenuItem.setMnemonic(KeyEvent.VK_X);
+//        JMenu newMenu = new JMenu("New");
+//	        newMenu.add(newWorkflowTabItem);
+//	        newMenu.addSeparator();
+//	        
+//	        newMenu.add(this.registerApplicationDesc);
+//	        newMenu.addSeparator();
+//	        JMenu regAddSubMenuItem = new JMenu("Registry additions");
+//	        newMenu.add(regAddSubMenuItem);
+//	        regAddSubMenuItem.add(this.registerHostDesc);
+//	        regAddSubMenuItem.add(this.registerServiceDesc);
+//	        
+//        xbayaMenuItem.add(newMenu);
+        xbayaMenuItem.add(newWorkflowTabItem);
+        xbayaMenuItem.add(registerHostDesc);
+        xbayaMenuItem.add(this.registerServiceDesc);
+//        xbayaMenuItem.add(registerApplicationDesc);
+        xbayaMenuItem.add(this.openWorkflowItem);
+
+        xbayaMenuItem.addSeparator();
+        
+        xbayaMenuItem.add(clearWorkflowItem);
+        xbayaMenuItem.add(closeWorkflowItem);
+        xbayaMenuItem.add(closeAllWorkflowItem);
+        
+        //This menu item did not seem useful at all
+//        xbayaMenuItem.add(this.nextWorkflowTabItem);
+
+        xbayaMenuItem.addSeparator();
+
+        xbayaMenuItem.add(this.saveWorkflowItem);
+
+        xbayaMenuItem.add(this.saveAsWorkflowItem);
+        xbayaMenuItem.add(this.saveAllWorkflowItem);
+        
+        xbayaMenuItem.addSeparator();
+        JMenu importMenu = new JMenu("Import");
+        	importMenu.add(importWorkflowItemFromFileSystem);
+        	importMenu.add(importWorkflowItemFromRegistry);
+        	importMenu.addSeparator();
+        	importMenu.add(urlItem);	
+        	
+        JMenu exportMenu = new JMenu("Export");
+        	exportMenu.add(saveWorkflowtoRegistryItem);
+        	exportMenu.addSeparator();
+	        exportMenu.add(exportJythonItem);
+	        exportMenu.add(exportBpelItem);
+	        exportMenu.add(exportODEScriptsItem);
+	        exportMenu.addSeparator();
+	        exportMenu.add(saveImageItem);
+        
+        xbayaMenuItem.add(importMenu);
+        xbayaMenuItem.add(exportMenu);
+        
+        xbayaMenuItem.addSeparator();
+        
+        xbayaMenuItem.add(exitItem);
+        
+        xbayaMenuItem.addMenuListener(new MenuListener() {
+			
+			@Override
+			public void menuSelected(MenuEvent e) {
+				GraphCanvas graphCanvas = engine.getGUI().getGraphCanvas();
+				saveAsWorkflowItem.setEnabled(isWorkflowTabPresent() && graphCanvas.getWorkflowFile()!=null);
+				saveWorkflowItem.setEnabled(isSaveShouldBeActive());
+				saveAllWorkflowItem.setEnabled(engine.getGUI().getGraphCanvases().size()>0);
+				saveWorkflowtoRegistryItem.setEnabled(isWorkflowTabPresent());
+				exportJythonItem.setEnabled(isWorkflowTabPresent());
+				exportBpelItem.setEnabled(isWorkflowTabPresent());
+				exportODEScriptsItem.setEnabled(isWorkflowTabPresent());
+				saveImageItem.setEnabled(isWorkflowTabPresent());
+			}
+			@Override
+			public void menuDeselected(MenuEvent e) {}
+			@Override
+			public void menuCanceled(MenuEvent e) {}
+		});
+        executionModeChanged(engine.getConfiguration());
+    }
+
+    /**
+     * @return The file menu.
+     */
+    public JMenu getMenu() {
+        return this.xbayaMenuItem;
+    }
+
+    private void createSaveWorkflowtoRegistryItem() {
+        this.saveWorkflowtoRegistryItem = new JMenuItem("Workflow To Registry...");
+        this.saveWorkflowtoRegistryItem.setMnemonic(KeyEvent.VK_C);
+        this.saveWorkflowtoRegistryItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                if (registryAccesser.saveWorkflow()){
+                	if (engine.getGUI().getGraphCanvas().getWorkflowFile()==null){
+                		engine.getGUI().getGraphCanvas().workflowSaved();
+                	}
+                }
+            }
+        });
+    }
+    
+    private JMenuItem createURLRegistryItem() {
+        JMenuItem item = new JMenuItem("WSDL From URL...");
+        item.setMnemonic(KeyEvent.VK_U);
+        item.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            private URLRegistryWindow window;
+            public void actionPerformed(ActionEvent e) {
+                if (this.window == null) {
+                    this.window = new URLRegistryWindow(engine);
+                }
+                this.window.show();
+            }
+        });
+        return item;
+    }
+    
+    private void createRegisterServiceDesc() {
+        this.registerServiceDesc = new JMenuItem("Register Application...");
+
+        this.registerServiceDesc.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                if (XBayaUtil.acquireJCRRegistry(engine)) {
+                    try {
+                        DeploymentDescriptionDialog serviceDescriptionDialog = new DeploymentDescriptionDialog(XBayaMenuItem.this.engine.getGUI().getFrame(), engine.getConfiguration()
+                                        .getAiravataAPI());
+                    	serviceDescriptionDialog.open();
+//                        ServiceDescriptionDialog serviceDescriptionDialog = new ServiceDescriptionDialog(
+//                                engine.getConfiguration().getJcrComponentRegistry()
+//                                        .getRegistry());
+//                        serviceDescriptionDialog.open();
+                    	if (serviceDescriptionDialog.isServiceCreated()){
+//                    		engine.reloadRegistry();
+                    		ComponentRegistryLoader loader = ComponentRegistryLoader.getLoader(engine, RegistryConstants.REGISTRY_TYPE_JCR);
+                    		loader.load(engine.getConfiguration().getJcrComponentRegistry());
+                    	}
+                    } catch (Exception e1) {
+                        engine.getGUI().getErrorWindow().error(e1);
+                    }
+                }
+            }
+        });
+
+    }
+
+    private void createRegisterApplicationDesc() {
+        this.registerApplicationDesc = new JMenuItem("Register Application...");
+
+        this.registerApplicationDesc.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                if (XBayaUtil.acquireJCRRegistry(engine)) {
+                    try {
+                        ApplicationDescriptionDialog applicationDescriptionDialog = new ApplicationDescriptionDialog(
+                                engine);
+        	    		applicationDescriptionDialog.setLocationRelativeTo(engine.getGUI().getFrame());
+                        applicationDescriptionDialog.open();
+                    } catch (Exception e1) {
+                        engine.getGUI().getErrorWindow().error(e1);
+                    }
+                }
+            }
+        });
+
+    }
+
+    private void createRegisterHostDesc() {
+        this.registerHostDesc = new JMenuItem("Add Host...");
+
+        this.registerHostDesc.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                if (XBayaUtil.acquireJCRRegistry(engine)) {
+                    try {
+                        HostDescriptionDialog hostDescriptionDialog = new HostDescriptionDialog(
+                        		engine.getConfiguration().getAiravataAPI(),XBayaMenuItem.this.engine.getGUI().getFrame() );
+                        hostDescriptionDialog.open();
+                    } catch (Exception e1) {
+                        engine.getGUI().getErrorWindow().error(e1);
+                    }
+                }
+            }
+        });
+
+    }
+    private JMenuItem createClearWorkflowItem() {
+        JMenuItem menuItem = new JMenuItem("Clear Workflow");
+        menuItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+			public void actionPerformed(ActionEvent e) {
+                engine.getGUI().getGraphCanvas().newWorkflow();
+            }
+        });
+        return menuItem;
+    }
+
+    private JMenuItem createNewWorkflowTabMenuItem() {
+        
+		JMenuItem menuItem = new JMenuItem("New Workflow", MenuIcons.NEW_ICON);
+        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
+        AbstractAction action = new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                engine.getGUI().newGraphCanvas(true, true);
+            }
+        };
+		menuItem.addActionListener(action);
+		toolbarButtonNew=getToolBar().addToolbarButton(FILE_ACTIONS,menuItem.getText(), MenuIcons.NEW_ICON, "Create new workflow", action,1);
+        return menuItem;
+    }
+
+    private JMenuItem createCloseWorkflowTabItem() {
+        JMenuItem menuItem = new JMenuItem("Close Tab");
+        menuItem.setMnemonic(KeyEvent.VK_C);
+        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.CTRL_MASK));
+        menuItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                engine.getGUI().closeGraphCanvas();
+            }
+        });
+        return menuItem;
+    }
+
+    private JMenuItem createCloseAllWorkflowTabItem() {
+        JMenuItem menuItem = new JMenuItem("Close All Tabs");
+        menuItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                engine.getGUI().closeAllGraphCanvas();
+            }
+        });
+        return menuItem;
+    }
+    
+    private JMenuItem createNextWorkflowTabItem() {
+        JMenuItem menuItem = new JMenuItem("Select Next Workflow Tab");
+        menuItem.setMnemonic(KeyEvent.VK_S);
+        // XXX VK_TAB doesn't work...
+        // menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
+        // ActionEvent.CTRL_MASK));
+        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, ActionEvent.CTRL_MASK));
+        menuItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                engine.getGUI().selectNextGraphCanvas();
+            }
+        });
+        return menuItem;
+    }
+    
+    private void createOpenWorkflowMenuItem() {
+		this.openWorkflowItem = new JMenuItem("Open Workflow...", MenuIcons.OPEN_ICON);
+        this.openWorkflowItem.setMnemonic(KeyEvent.VK_O);
+        openWorkflowItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
+        AbstractAction action = new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent event) {
+                XBayaMenuItem.this.graphFiler.openWorkflow();
+            }
+        };
+		this.openWorkflowItem.addActionListener(action);
+		toolbarButtonOpen=getToolBar().addToolbarButton(FILE_ACTIONS,openWorkflowItem.getText(), MenuIcons.OPEN_ICON, "Open workflow", action,2);
+    }
+
+    private void createSaveWorkflowItem() {
+		saveWorkflowItem = new JMenuItem("Save", MenuIcons.SAVE_ICON);
+        saveWorkflowItem.setMnemonic(KeyEvent.VK_S);
+        saveWorkflowItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
+        AbstractAction action = new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                XBayaMenuItem.this.graphFiler.saveWorkflow();
+                toolbarButtonSave.setEnabled(isSaveShouldBeActive());
+            }
+        };
+		saveWorkflowItem.addActionListener(action);
+        toolbarButtonSave = getToolBar().addToolbarButton(FILE_ACTIONS,saveWorkflowItem.getText(), MenuIcons.SAVE_ICON, "Save workflow", action,3);
+        toolbarButtonSave.setEnabled(false);
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+            	while(engine.getGUI()==null){
+            		Thread.yield();
+            	}
+                engine.getGUI().addWorkflowTabChangeListener(new ChangeListener(){
+					@Override
+					public void stateChanged(ChangeEvent event) {
+						toolbarButtonSave.setEnabled(isSaveShouldBeActive());						
+					}
+                });
+            }
+        });
+    }
+    
+    private void createSaveAsWorkflowItem() {
+        saveAsWorkflowItem = new JMenuItem("Save as...");
+        saveAsWorkflowItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                XBayaMenuItem.this.graphFiler.saveAsWorkflow();
+            }
+        });
+    }
+    
+    private void createSaveAllWorkflowItem() {
+        saveAllWorkflowItem = new JMenuItem("Save all");
+        saveAllWorkflowItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                XBayaMenuItem.this.graphFiler.saveAllWorkflows();
+            }
+        });
+        saveAllWorkflowItem.setEnabled(false);
+    }
+
+    private void createImportWorkflowItemFromFileSystem() {
+        importWorkflowItemFromFileSystem = new JMenuItem("Workflow From File System...");
+        importWorkflowItemFromFileSystem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                XBayaMenuItem.this.graphFiler.importWorkflow();
+            }
+        });
+    }
+    
+    private void createImportWorkflowItemFromRegistry() {
+        importWorkflowItemFromRegistry = new JMenuItem("Workflow From Registry...");
+        importWorkflowItemFromRegistry.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                new RegistryLoaderWindow(engine).show();
+            }
+        });
+    }
+    
+    private void createExportJythonScriptItem() {
+        this.exportJythonItem = new JMenuItem("Workflow To Jython Script...");
+        this.exportJythonItem.setMnemonic(KeyEvent.VK_J);
+        this.exportJythonItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                XBayaMenuItem.this.jythonFiler.exportJythonScript();
+            }
+        });
+    }
+
+    private void createExportBpelScriptItem() {
+        this.exportBpelItem = new JMenuItem("Workflow To BPEL2 Script...");
+        this.exportBpelItem.setMnemonic(KeyEvent.VK_B);
+        this.exportBpelItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                XBayaMenuItem.this.bpelFiler.exportBPEL();
+            }
+        });
+    }
+
+    private void createSaveWorkflowImageItem() {
+        this.saveImageItem = new JMenuItem("Workflow To Image...");
+        this.saveImageItem.setMnemonic(KeyEvent.VK_I);
+        this.saveImageItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                XBayaMenuItem.this.imageFiler.saveWorkflowImage();
+            }
+        });
+    }
+
+    private void createExportODEScriptsItem() {
+        this.exportODEScriptsItem = new JMenuItem("Workflow To ODE Scripts...");
+        this.exportODEScriptsItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent e) {
+                new ODEScriptFiler(XBayaMenuItem.this.engine).save();
+
+            }
+        });
+    }
+
+    private JMenuItem createExitItem() {
+        JMenuItem menuItem = new JMenuItem("Exit");
+        menuItem.setMnemonic(KeyEvent.VK_X);
+        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
+        menuItem.addActionListener(new AbstractAction() {
+			private static final long serialVersionUID = 1L;
+            public void actionPerformed(ActionEvent event) {
+            	JFrame frame = XBayaMenuItem.this.engine.getGUI().getFrame();
+				frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); 
+            }
+        });
+        return menuItem;
+    }
+
+	public XBayaToolBar getToolBar() {
+		return toolBar;
+	}
+
+	public void setToolBar(XBayaToolBar toolBar) {
+		this.toolBar = toolBar;
+	}
+
+	private boolean isSaveShouldBeActive() {
+		GraphCanvas graphCanvas = engine.getGUI().getGraphCanvas();
+		return isWorkflowTabPresent() && (graphCanvas.getWorkflowFile()==null || graphCanvas.isWorkflowChanged());
+	}
+
+	private boolean isWorkflowTabPresent() {
+		return engine.getGUI().getGraphCanvas() !=null;
+	}
+
+	@Override
+	public void executionModeChanged(XBayaConfiguration config) {
+		toolbarButtonNew.setVisible(config.getXbayaExecutionMode()==XBayaExecutionMode.IDE);
+		toolbarButtonSave.setVisible(config.getXbayaExecutionMode()==XBayaExecutionMode.IDE);
+		toolbarButtonOpen.setVisible(config.getXbayaExecutionMode()==XBayaExecutionMode.IDE);
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorEventHandler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorEventHandler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorEventHandler.java
new file mode 100644
index 0000000..2b89082
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorEventHandler.java
@@ -0,0 +1,547 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.monitor;
+
+import java.awt.Color;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.apache.airavata.workflow.model.graph.ControlPort;
+import org.apache.airavata.workflow.model.graph.EPRPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.Node;
+import org.apache.airavata.workflow.model.graph.Node.NodeExecutionState;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.amazon.InstanceNode;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.system.InputNode;
+import org.apache.airavata.workflow.model.graph.system.OutputNode;
+import org.apache.airavata.workflow.model.graph.util.GraphUtil;
+import org.apache.airavata.workflow.model.graph.ws.WSGraph;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.ws.monitor.EventData;
+import org.apache.airavata.ws.monitor.EventDataRepository;
+import org.apache.airavata.ws.monitor.MonitorUtil;
+import org.apache.airavata.ws.monitor.MonitorUtil.EventType;
+import org.apache.airavata.xbaya.graph.controller.NodeController;
+import org.apache.airavata.xbaya.ui.XBayaGUI;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
+import org.apache.airavata.xbaya.ui.graph.NodeGUI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.infoset.XmlElement;
+
+public class MonitorEventHandler implements ChangeListener {
+
+    /**
+     * The state of a node
+     */
+    public static enum NodeState {
+
+        /**
+         * FINISHED
+         */
+        FINISHED(Color.GRAY),
+
+        /**
+         * EXECUTING
+         */
+        EXECUTING(Color.GREEN),
+
+        /**
+         * FAILED
+         */
+        FAILED(Color.RED),
+
+        /**
+         * DEFAULT COLOR
+         */
+        DEFAULT(NodeGUI.DEFAULT_BODY_COLOR);
+
+
+        /**
+         * color
+         */
+        final public Color color;
+
+        private NodeState(Color color) {
+            this.color = color;
+        }
+    }
+
+    private static Logger logger = LoggerFactory.getLogger(MonitorEventHandler.class);
+
+    private XBayaGUI xbayaGUI;
+
+    private int sliderValue;
+
+    private Collection<URI> incorrectWorkflowIDs;
+
+    private Collection<URI> triedWorkflowIDs;
+
+    private Map<Node, LinkedList<ResourcePaintable>> resourcePaintableMap;
+
+//    private WorkflowStatusUpdater workflowStatusUpdater;
+
+//    private WorkflowNodeStatusUpdater workflowNodeStatusUpdater;
+
+    /**
+     * Model MonitorEventHandler
+     *
+     * @param xbayaGUI
+     */
+    public MonitorEventHandler(XBayaGUI xbayaGUI) {
+        this.xbayaGUI = xbayaGUI;
+        this.incorrectWorkflowIDs = Collections.synchronizedSet(new HashSet<URI>());
+        this.triedWorkflowIDs = Collections.synchronizedSet(new HashSet<URI>());
+        this.resourcePaintableMap = new HashMap<Node, LinkedList<ResourcePaintable>>();
+//        try {
+//            if (this.getClass().getClassLoader().getResource("airavata-server.properties") != null) {
+//                this.workflowNodeStatusUpdater =
+//                        new WorkflowNodeStatusUpdater(XBayaUtil.getRegistry(this.getClass().getClassLoader().getResource("airavata-server.properties")));
+//                this.workflowStatusUpdater =
+//                        new WorkflowStatusUpdater(XBayaUtil.getRegistry(this.getClass().getClassLoader().getResource("airavata-server.properties")));
+//            }
+//        } catch (IOException e) {
+//            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+//        } catch (RepositoryException e) {
+//            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+//        } catch (URISyntaxException e) {
+//            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+//        }
+    }
+
+    /**
+     * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
+     */
+    public void stateChanged(ChangeEvent event) {
+        try {
+            Object source = event.getSource();
+            if (source instanceof EventDataRepository) {
+                handleChange((EventDataRepository) source);
+            }
+        } catch (RuntimeException e) {
+            // Don't want to pop up an error dialog every time XBaya received an
+            // ill-formatted notification.
+            logger.error(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * @param model
+     */
+    private void handleChange(EventDataRepository model) {
+        int newValue = model.getValue();
+
+        if (model.getEventSize() == 0) {
+            // The monitor was reset.
+            resetAll();
+        } else if (newValue > this.sliderValue) {
+            // 3 -> 5
+            // 3, 4
+            for (int i = this.sliderValue; i < newValue; i++) {
+                handleEvent(model.getEvent(i), true);
+            }
+        } else if (newValue < this.sliderValue) {
+            // 5 -> 3
+            // 4, 3
+            for (int i = this.sliderValue - 1; i >= newValue; i--) {
+                handleEvent(model.getEvent(i), false);
+            }
+        }
+        this.sliderValue = newValue;
+
+        // Repaints only the active canvas.
+        this.xbayaGUI.getGraphCanvas().repaint();
+    }
+
+    private void handleEvent(EventData event, boolean forward) {
+        EventType type = event.getType();
+        //todo currrently we do not set the workflowID properly its just node ID
+        URI workflowID = event.getWorkflowID();
+
+        List<GraphCanvas> graphCanvases = this.xbayaGUI.getGraphCanvases();
+        boolean found = false;
+        for (GraphCanvas graphCanvas : graphCanvases) {
+            Workflow workflow = graphCanvas.getWorkflow();
+//            URI instanceID = workflow.getGPELInstanceID();
+//            if (instanceID == null) {
+            // If the workflow doesn't have an instance ID, it's a template.
+            // We handle it so that users can use a workflow template to
+            // monitor a workflow too.
+            // This is also needed in the case of jython workflow.
+            handleEvent(event, forward, workflow.getGraph());
+//            } else if (instanceID.equals(workflowID)) {
+//                This is the regular case.
+//                found = true;
+//                handleEvent(event, forward, workflow.getGraph());
+//            } else if (null != workflowID
+//                    && -1 != WSDLUtil.findWorkflowName(workflowID).indexOf(WSDLUtil.findWorkflowName(instanceID))) {
+//                handleEvent(event, WSDLUtil.findWorkflowName(workflowID), workflow.getGraph());
+//            }
+        }
+
+        // Load a sub-workflow.
+        if (type == MonitorUtil.EventType.WORKFLOW_INITIALIZED) {
+            if (forward) {
+                // Check if the workflow instance is already open.
+                for (GraphCanvas graphCanvas : graphCanvases) {
+                    Workflow workflow = graphCanvas.getWorkflow();
+                    URI instanceID = workflow.getGPELInstanceID();
+                    if (workflowID.equals(instanceID)) {
+                        // The workflow instance is already loaded.
+                        return;
+                    }
+                }
+                loadWorkflow(workflowID);
+            } else {
+                // Don't need to close the workflow when it's opened.
+            }
+        }
+
+        if (found == false && workflowID != null) {
+            // Loads the workflow instance ID in case a user started to monitor
+            // in the middle.
+            loadWorkflow(workflowID);
+        }
+
+        /*
+         * Handle resource mapping message which contains resource from Amazon EC2 Since workflowID (workflowName) from
+         * message and instanceID do not equal, so we have to handle it explicitly
+         */
+        if (type == EventType.RESOURCE_MAPPING && event.getMessage().contains("i-")) {
+            String nodeID = event.getNodeID();
+            for (GraphCanvas graphCanvas : graphCanvases) {
+                Node node = graphCanvas.getWorkflow().getGraph().getNode(nodeID);
+                if (node != null) {
+                    ControlPort control = node.getControlInPort();
+                    if (control != null) {
+                        Node fromNode = control.getFromNode();
+                        if (fromNode instanceof InstanceNode) {
+                            InstanceNode ec2Node = (InstanceNode) fromNode;
+
+                            /*
+                             * parse message and set output to InstanceNode
+                             */
+                            int start = event.getMessage().indexOf("i-");
+                            String instanceId = event.getMessage().substring(start, start + 10);
+                            ec2Node.setOutputInstanceId(instanceId);
+
+                            // make this node to not start a new instance
+                            ec2Node.setStartNewInstance(false);
+                            ec2Node.setInstanceId(instanceId);
+                            ec2Node.setAmiId(null);
+                        }
+                    }
+                }
+            }
+        }
+
+        // TODO There is a possibility that XBaya misses to handle some
+        // notification while a workflow is being loaded. Create a thread for
+        // each workflow ID to handle notifications.
+    }
+
+    /**
+     * @param graph
+     * @return
+     */
+    private LinkedList<InputNode> getInputNodes(WSGraph graph) {
+        List<NodeImpl> nodes = graph.getNodes();
+        LinkedList<InputNode> inputNodes = new LinkedList<InputNode>();
+        for (NodeImpl nodeImpl : nodes) {
+            if (nodeImpl instanceof InputNode) {
+                inputNodes.add((InputNode) nodeImpl);
+            }
+        }
+        return inputNodes;
+    }
+
+    private LinkedList<OutputNode> getOutputNodes(WSGraph graph) {
+        List<NodeImpl> nodes = graph.getNodes();
+        LinkedList<OutputNode> outputNodes = new LinkedList<OutputNode>();
+        for (NodeImpl nodeImpl : nodes) {
+            if (nodeImpl instanceof OutputNode) {
+                outputNodes.add((OutputNode) nodeImpl);
+            }
+        }
+        return outputNodes;
+    }
+
+    /**
+     * @param event
+     * @param forward
+     * @param graph
+     */
+    private void handleEvent(EventData event, boolean forward, Graph graph) {
+        EventType type = event.getType();
+        String nodeID = event.getNodeID();
+        Node node = graph.getNode(nodeID);
+        System.out.println(type);
+        ;
+        // logger.info("type: " + type);
+        if (type == MonitorUtil.EventType.WORKFLOW_INVOKED) {
+            workflowStarted(graph, forward);
+//            workflowStatusUpdater.workflowStarted(event.getExperimentID());
+        } else if (type == MonitorUtil.EventType.WORKFLOW_TERMINATED) {
+            workflowFinished(graph, forward);
+//            workflowStatusUpdater.workflowFinished(event.getExperimentID());
+        } else if (type == EventType.INVOKING_SERVICE
+                // TODO this should be removed when GPEL sends all notification
+                // correctly.
+                || type == EventType.SERVICE_INVOKED) {
+            if (node == null) {
+                logger.warn("There is no node that has ID, " + nodeID);
+            } else {
+                nodeStarted(node, forward);
+//                workflowNodeStatusUpdater.workflowStarted(event.getExperimentID(), event.getNodeID());
+            }
+        } else if (type == MonitorUtil.EventType.RECEIVED_RESULT
+                // TODO this should be removed when GPEL sends all notification
+                // correctly.
+                || type == EventType.SENDING_RESULT) {
+            if (node == null) {
+                logger.warn("There is no node that has ID, " + nodeID);
+            } else {
+                nodeFinished(node, forward);
+//                workflowNodeStatusUpdater.workflowFinished(event.getExperimentID(), event.getNodeID());
+            }
+
+        } else if (type == EventType.INVOKING_SERVICE_FAILED || type == EventType.RECEIVED_FAULT
+                // TODO
+                || type == EventType.SENDING_FAULT || type == EventType.SENDING_RESPONSE_FAILED) {
+            if (node == null) {
+                logger.warn("There is no node that has ID, " + nodeID);
+            } else {
+                nodeFailed(node, forward);
+//                workflowNodeStatusUpdater.workflowFailed(event.getExperimentID(), event.getNodeID());
+            }
+        } else if (type == MonitorUtil.EventType.RESOURCE_MAPPING) {
+            if (node == null) {
+                logger.warn("There is no node that has ID, " + nodeID);
+            } else {
+                nodeResourceMapped(node, event.getEvent(), forward);
+//                workflowNodeStatusUpdater.workflowRunning(event.getExperimentID(), event.getNodeID());
+            }
+        } else {
+            // Ignore the rest.
+        }
+    }
+
+    /**
+     * @param workflowInstanceID
+     */
+    private void loadWorkflow(final URI workflowInstanceID) {
+        // To avoid to load a same workflow twice.
+        if (this.triedWorkflowIDs.contains(workflowInstanceID)) {
+            return;
+        }
+        this.triedWorkflowIDs.add(workflowInstanceID);
+
+        new Thread() {
+            @Override
+            public void run() {
+                loadWorkflowInThread(workflowInstanceID);
+            }
+        }.start();
+    }
+
+    private void loadWorkflowInThread(URI workflowInstanceID) {
+        try {
+            if (this.incorrectWorkflowIDs.contains(workflowInstanceID)) {
+                // Do not try to load a workflow that failed before.
+                return;
+            }
+            //There is not workflow client assigned in the engine. thus the following code is commented
+//            WorkflowClient client = this.engine.getWorkflowClient();
+//            Workflow loadedWorkflow = client.load(workflowInstanceID, WorkflowType.INSTANCE);
+//            GraphCanvas canvas = this.xbayaGUI.newGraphCanvas(true);
+//            canvas.setWorkflow(loadedWorkflow);
+//        } catch (GraphException e) {
+//            this.incorrectWorkflowIDs.add(workflowInstanceID);
+//            logger.error(e.getMessage(), e);
+//        } catch (WorkflowEngineException e) {
+//            this.incorrectWorkflowIDs.add(workflowInstanceID);
+//            logger.error(e.getMessage(), e);
+//        } catch (ComponentException e) {
+//            this.incorrectWorkflowIDs.add(workflowInstanceID);
+//            logger.error(e.getMessage(), e);
+        } catch (RuntimeException e) {
+            this.incorrectWorkflowIDs.add(workflowInstanceID);
+            logger.error(e.getMessage(), e);
+        }
+
+    }
+
+    private void workflowStarted(Graph graph, boolean forward) {
+        for (InputNode node : GraphUtil.getInputNodes(graph)) {
+            if (forward) {
+                finishNode(node);
+            } else {
+                resetNode(node);
+            }
+        }
+    }
+
+    private void workflowFinished(Graph graph, boolean forward) {
+        for (OutputNode node : GraphUtil.getOutputNodes(graph)) {
+            if (forward) {
+                finishNode(node);
+                finishPredecessorNodes(node);
+            } else {
+                resetNode(node);
+            }
+        }
+    }
+
+    private void nodeStarted(Node node, boolean forward) {
+        if (forward) {
+            if (node.getState() != NodeExecutionState.FINISHED) {
+                executeNode(node);
+                finishPredecessorNodes(node);
+            }
+        } else {
+            resetNode(node);
+        }
+    }
+
+    private void nodeFinished(Node node, boolean forward) {
+        if (forward) {
+            finishNode(node);
+            finishPredecessorNodes(node);
+        } else {
+            executeNode(node);
+        }
+    }
+
+    private void nodeFailed(Node node, boolean forward) {
+        if (forward) {
+            failNode(node);
+            finishPredecessorNodes(node);
+        } else {
+            executeNode(node);
+        }
+    }
+
+    private void nodeResourceMapped(Node node, XmlElement event, boolean forward) {
+        String resource = MonitorUtil.getMappedResource(event);
+        String retryCount = MonitorUtil.getRetryCount(event);
+        NodeGUI nodeGUI = NodeController.getGUI(node);
+        if (forward) {
+            LinkedList<ResourcePaintable> paintables = this.resourcePaintableMap.get(node);
+            if (paintables == null) {
+                paintables = new LinkedList<ResourcePaintable>();
+                this.resourcePaintableMap.put(node, paintables);
+            }
+            if (paintables.size() > 0) {
+                // Remove the previous one.
+                ResourcePaintable previousPaintable = paintables.getLast();
+                nodeGUI.removePaintable(previousPaintable);
+            }
+            ResourcePaintable paintable = new ResourcePaintable(resource, retryCount);
+            paintables.addLast(paintable);
+            nodeGUI.addPaintable(paintable);
+        } else {
+            LinkedList<ResourcePaintable> paintables = this.resourcePaintableMap.get(node);
+            if (paintables == null) {
+                paintables = new LinkedList<ResourcePaintable>();
+                this.resourcePaintableMap.put(node, paintables);
+            }
+            if (paintables.size() > 0) {
+                // Remove the last one.
+                ResourcePaintable lastPaintable = paintables.removeLast();
+                nodeGUI.removePaintable(lastPaintable);
+            }
+            if (paintables.size() > 0) {
+                // Add the previous one.
+                ResourcePaintable previousPaintable = paintables.getLast();
+                nodeGUI.addPaintable(previousPaintable);
+            }
+        }
+    }
+
+    private void resetAll() {
+        List<GraphCanvas> graphCanvases = this.xbayaGUI.getGraphCanvases();
+        for (GraphCanvas graphCanvas : graphCanvases) {
+            Graph graph = graphCanvas.getGraph();
+            for (Node node : graph.getNodes()) {
+                resetNode(node);
+            }
+        }
+    }
+
+    private void executeNode(Node node) {
+        node.setState(NodeExecutionState.EXECUTING);
+    }
+
+    private void finishNode(Node node) {
+        if (!NodeExecutionState.FAILED.equals(node.getState())) {
+            node.setState(NodeExecutionState.FINISHED);
+        }
+    }
+
+    private void failNode(Node node) {
+        node.setState(NodeExecutionState.FAILED);
+    }
+
+    private void resetNode(Node node) {
+        node.setState(NodeExecutionState.WAITING);
+        NodeController.getGUI(node).resetTokens();
+    }
+
+    /**
+     * Make preceding nodes done. This helps the monitoring GUI when a user subscribes from the middle of the workflow
+     * execution.
+     *
+     * @param node
+     */
+    private void finishPredecessorNodes(Node node) {
+        for (Port inputPort : node.getInputPorts()) {
+            for (Edge edge : inputPort.getEdges()) {
+                Port fromPort = edge.getFromPort();
+                if (!(fromPort instanceof EPRPort)) {
+                    Node fromNode = fromPort.getNode();
+                    finishNode(fromNode);
+                    finishPredecessorNodes(fromNode);
+                }
+            }
+        }
+        Port controlInPort = node.getControlInPort();
+        if (controlInPort != null) {
+            for (Node fromNode : controlInPort.getFromNodes()) {
+                finishNode(fromNode);
+                finishPredecessorNodes(fromNode);
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorStarter.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorStarter.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorStarter.java
new file mode 100644
index 0000000..94e856c
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/MonitorStarter.java
@@ -0,0 +1,125 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.monitor;
+
+import org.apache.airavata.ws.monitor.MonitorException;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.ui.dialogs.WaitDialog;
+import org.apache.airavata.xbaya.ui.utils.Cancelable;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MonitorStarter implements Cancelable {
+
+    private static final Logger logger = LoggerFactory.getLogger(MonitorStarter.class);
+
+    private XBayaEngine engine;
+
+    private Thread subscribingThread;
+
+    private boolean canceled;
+
+    private WaitDialog startingDialog;
+
+    /**
+     * Constructs a MonitorStarter.
+     * 
+     * @param engine
+     */
+    public MonitorStarter(XBayaEngine engine) {
+        this.engine = engine;
+
+        this.startingDialog = new WaitDialog(this, "Starting Monitoring", "Subscribing to notification.\n"
+                + "Please wait for a moment.", this.engine.getGUI());
+    }
+
+    /**
+     * @see org.apache.airavata.xbaya.ui.utils.Cancelable#cancel()
+     */
+    public void cancel() {
+        this.canceled = true;
+        this.subscribingThread.interrupt();
+    }
+
+    /**
+     * Starts monitoring.
+     */
+    public void start() {
+        // Non blocking
+        start(false);
+    }
+
+    /**
+     * Starts monitoring.
+     * 
+     * @param blocking
+     */
+    public void start(final boolean blocking) {
+        this.canceled = false;
+
+        this.subscribingThread = new Thread() {
+            @Override
+            public void run() {
+                runInThread();
+            }
+
+        };
+        this.subscribingThread.start();
+
+        // This has to be the last because it blocks when the dialog is modal.
+        this.startingDialog.show();
+
+        if (blocking) {
+            try {
+                this.subscribingThread.join();
+            } catch (InterruptedException e) {
+                logger.error(e.getMessage(), e);
+            }
+        }
+    }
+
+    private void runInThread() {
+        try {
+            this.engine.getMonitor().start();
+            this.startingDialog.hide();
+        } catch (MonitorException e) {
+            // Probably canceled by a user.
+            if (this.canceled) {
+                logger.error(e.getMessage(), e);
+            } else {
+                this.engine.getGUI().getErrorWindow().error(ErrorMessages.MONITOR_SUBSCRIPTION_ERROR, e);
+                this.startingDialog.hide();
+            }
+        } catch (RuntimeException e) {
+            if (this.canceled) {
+                logger.error(e.getMessage(), e);
+            } else {
+                this.engine.getGUI().getErrorWindow().error(ErrorMessages.MONITOR_SUBSCRIPTION_ERROR, e);
+                this.startingDialog.hide();
+            }
+        } catch (Error e) {
+            this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+            this.startingDialog.hide();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/ResourcePaintable.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/ResourcePaintable.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/ResourcePaintable.java
new file mode 100644
index 0000000..049edc0
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/monitor/ResourcePaintable.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.monitor;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Point;
+
+import org.apache.airavata.xbaya.ui.graph.Paintable;
+
+public class ResourcePaintable implements Paintable {
+
+    private String resource;
+
+    private String retryCount;
+
+    private String displayText;
+
+    /**
+     * Constructs a ResourcePaintable.
+     * 
+     * @param resource
+     * @param retryCount
+     */
+    public ResourcePaintable(String resource, String retryCount) {
+        this.resource = resource;
+        this.retryCount = retryCount;
+
+        this.displayText = "";
+        if (this.resource != null) {
+            this.displayText += this.resource;
+        }
+        if (this.retryCount != null && this.retryCount.length() > 0 && !"0".equals(this.retryCount)) {
+            this.displayText += "/" + this.retryCount;
+        }
+    }
+
+    /**
+     * @see org.apache.airavata.xbaya.ui.graph.Paintable#paint(java.awt.Graphics2D, java.awt.Point)
+     */
+    public void paint(Graphics2D graphics, Point point) {
+        graphics.setColor(Color.BLACK);
+        graphics.drawString(this.displayText, point.x, point.y - 10);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/Cancelable.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/Cancelable.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/Cancelable.java
new file mode 100644
index 0000000..42658c7
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/Cancelable.java
@@ -0,0 +1,30 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.utils;
+
+public interface Cancelable {
+
+    /**
+     * Cancels a task.
+     */
+    public void cancel();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/DrawUtils.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/DrawUtils.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/DrawUtils.java
new file mode 100644
index 0000000..47e79bc
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/utils/DrawUtils.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.ui.utils;
+
+import java.awt.Color;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
+import java.awt.Polygon;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.RoundRectangle2D;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.python.modules.math;
+
+public class DrawUtils {
+	public static final int ARC_SIZE=10;
+	
+	public static void gradientFillShape(Graphics2D g,Color startColor, Color endColor, Shape shape) {
+		initializeGraphics2D(g);
+		GradientPaint gp = getGradientPaint(startColor, endColor, shape);
+        g.setPaint(gp);
+        g.fill(shape);
+	}
+
+
+	public static GradientPaint getGradientPaint(Color startColor,
+			Color endColor, Shape shape) {
+		GradientPaint gp = new GradientPaint((int)shape.getBounds().getX(), (int)shape.getBounds().getY(),
+				startColor, (int)(shape.getBounds().getX()+shape.getBounds().getWidth()), (int)(shape.getBounds().getY()+shape.getBounds().getHeight()),
+				endColor,false);
+		return gp;
+	}
+	
+
+	public static void initializeGraphics2D(Graphics2D g) {
+		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                RenderingHints.VALUE_ANTIALIAS_ON);
+	}
+	
+	public static Shape getRoundedShape(Rectangle shape) {
+		return new RoundRectangle2D.Double(shape.getX(),shape.getY(),shape.getWidth(),shape.getHeight(),DrawUtils.ARC_SIZE,DrawUtils.ARC_SIZE);
+    }
+	
+	public static GeneralPath getRoundedShape(Polygon polygon) {
+    	GeneralPath generalPath=new GeneralPath();
+    	DrawUtils.setupRoundedGeneralPath(polygon, generalPath);
+    	return generalPath;
+    }
+
+	public static void setupRoundedGeneralPath(Polygon polygon, GeneralPath generalPath) {
+		generalPath.reset();
+		List<int[]> l = new ArrayList<int[]>();
+		for(int i=0; i < polygon.npoints; i++){
+			l.add(new int[]{polygon.xpoints[i],polygon.ypoints[i]});
+		}
+		l.add(l.get(0));
+		l.add(l.get(1));
+		int[][] a=l.toArray(new int[][]{});
+		generalPath.moveTo(a[0][0],a[0][1]);
+		for(int pointIndex=1; pointIndex<a.length-1;pointIndex++){
+			int[] p1=a[pointIndex-1];
+			int[] p2=a[pointIndex];
+			int[] p3=a[pointIndex+1];
+			int[] mPoint = calculatePoint(p1, p2);
+			generalPath.lineTo(mPoint[0], mPoint[1]);
+			mPoint = calculatePoint(p3, p2);
+			generalPath.curveTo(p2[0], p2[1], p2[0], p2[1], mPoint[0], mPoint[1]);
+		}
+	}
+	
+
+    private static int[] calculatePoint(int[] p1, int[] p2) {
+		double d1=math.sqrt(math.pow(p1[0]-p2[0], 2)+math.pow(p1[1]-p2[1], 2));
+		double per=ARC_SIZE/d1;
+		
+		double d_x=(p1[0]-p2[0])*per;
+		double d_y=(p1[1]-p2[1])*per;
+		
+		int xx=(int)(p2[0]+d_x);
+		int yy=(int)(p2[1]+d_y);
+		
+		int[] mPoint={xx,yy};
+		return mPoint;
+	}
+}


Mime
View raw message