KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > actions > NewWorkflow


1 package com.opensymphony.workflow.designer.actions;
2
3 import java.awt.event.ActionEvent JavaDoc;
4 import java.awt.*;
5 import javax.swing.*;
6
7 import com.opensymphony.workflow.designer.event.WorkspaceListener;
8 import com.opensymphony.workflow.designer.event.WorkspaceEvent;
9 import com.opensymphony.workflow.designer.WorkflowDesigner;
10 import com.opensymphony.workflow.designer.ResourceManager;
11 import com.opensymphony.workflow.loader.Workspace;
12 import com.opensymphony.workflow.FactoryException;
13
14 /**
15  * @author Hani Suleiman (hani@formicary.net)
16  * Date: May 21, 2003
17  * Time: 1:14:41 AM
18  */

19 public class NewWorkflow extends AbstractAction implements WorkspaceListener
20 {
21   private Workspace currentWorkspace;
22
23   public NewWorkflow()
24   {
25     setEnabled(false);
26   }
27
28   public void actionPerformed(ActionEvent JavaDoc e)
29   {
30     String JavaDoc name = JOptionPane.showInputDialog(ResourceManager.getString("createflow"), ResourceManager.getString("createflow.long"));
31     if(name==null) return;
32     try
33     {
34       if(currentWorkspace.getWorkflow(name)!=null)
35       {
36         JOptionPane.showMessageDialog((Component)e.getSource(), ResourceManager.getString("createflow.error", new Object JavaDoc[]{name}), ResourceManager.getString("createflow.error"), JOptionPane.ERROR_MESSAGE);
37         return;
38       }
39     }
40     catch(FactoryException ex)
41     {
42       ex.printStackTrace();
43       return;
44     }
45     currentWorkspace.createWorkflow(name);
46     WorkflowDesigner.INSTANCE.newWorkflowCreated(name);
47   }
48
49   public void workspaceChanged(WorkspaceEvent event)
50   {
51     if(event.getId()==WorkspaceEvent.WORKSPACE_OPENED)
52     {
53       setEnabled(true);
54       currentWorkspace = event.getWorkspace();
55     }
56     else
57     {
58       setEnabled(false);
59       currentWorkspace = null;
60     }
61   }
62 }
63
Popular Tags