KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > workfloweditor > WorkflowEditor


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.workfloweditor;
20
21 import java.util.*;
22
23 import org.openharmonise.him.*;
24 import org.openharmonise.him.context.StateHandler;
25 import org.openharmonise.him.window.messages.*;
26 import org.openharmonise.vfs.*;
27 import org.openharmonise.vfs.context.*;
28 import org.openharmonise.vfs.servers.ServerList;
29 import org.openharmonise.vfs.status.*;
30 import org.openharmonise.workfloweditor.flowchart.*;
31 import org.openharmonise.workfloweditor.model.*;
32 import org.openharmonise.workfloweditor.vfs.*;
33
34
35 /**
36  * Starting class for workflow editing. On constructing this
37  * class the workflow editor window will open, then a workflow model can
38  * be set which will then be loaded for editing.
39  *
40  * @author Matthew Large
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class WorkflowEditor {
45
46     /**
47      * The workflow diagram.
48      */

49     private FlowChart m_chart = null;
50     
51     /**
52      * Workflow editor display manager.
53      */

54     private DisplayManager m_display = null;
55
56     /**
57      *
58      */

59     public WorkflowEditor() {
60         super();
61         this.setup();
62     }
63     
64     /**
65      * Configures the workflow editor.
66      *
67      */

68     private void setup() {
69         m_display = new DisplayManager(this);
70         
71         m_chart = m_display.getFlowChart();
72     }
73     
74     /**
75      * Sets the model to be edited.
76      *
77      * @param model Workflow model
78      */

79     public void setModel(WorkflowModel model) {
80         this.m_chart.setModel(model);
81         this.m_chart.repaint();
82     }
83     
84     /**
85      * Prepared the workflow editor for shutdown. Saves all current
86      * changes.
87      *
88      */

89     public void shutdown() {
90         StateHandler.getInstance().addWait("WORKFLOWSAVE");
91         try {
92             AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS();
93         
94             VFSWorkflowModel model = (VFSWorkflowModel) m_chart.getModel();
95             Iterator itor = model.getWorkflowStages().iterator();
96             
97             while (itor.hasNext()) {
98                 VFSWorkflowStage stage = (VFSWorkflowStage) itor.next();
99                 VersionedVirtualFile vfFile = (VersionedVirtualFile) vfs.getVirtualFile(stage.getPath()).getResource();
100                 if(vfFile.isChanged()) {
101                     StatusData status = vfFile.sync();
102                     if( status.isOK() ) {
103                         if(vfFile.getState()==VirtualFile.STATE_LIVE && vfFile.getPendingVersionPath()!=null) {
104                             VersionedVirtualFile vfPending = (VersionedVirtualFile) vfs.getVirtualFile(vfFile.getPendingVersionPath()).getResource();
105                             if(vfPending!=null) {
106                                 vfPending.checkin();
107                             }
108                         } else if(vfFile.getState()==VirtualFile.STATE_PENDING) {
109                             vfFile.checkin();
110                         }
111                     } else {
112                         
113                     }
114                 }
115             }
116         } catch(Exception JavaDoc e) {
117             e.printStackTrace();
118             MessageHandler.getInstance().fireMessageEvent("There were problems saving the workflow changes.", MessageHandler.TYPE_ERROR);
119         } finally {
120             StateHandler.getInstance().removeWait("WORKFLOWSAVE");
121             MessageHandler.getInstance().fireMessageEvent("Workflow changes saved.", MessageHandler.TYPE_CONFIRM);
122         }
123     }
124
125     public static void main(String JavaDoc[] args) {
126         WorkflowEditor editor = new WorkflowEditor();
127     }
128 }
129
Popular Tags