001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.workfloweditor;
020:
021: import java.util.*;
022:
023: import org.openharmonise.him.*;
024: import org.openharmonise.him.context.StateHandler;
025: import org.openharmonise.him.window.messages.*;
026: import org.openharmonise.vfs.*;
027: import org.openharmonise.vfs.context.*;
028: import org.openharmonise.vfs.servers.ServerList;
029: import org.openharmonise.vfs.status.*;
030: import org.openharmonise.workfloweditor.flowchart.*;
031: import org.openharmonise.workfloweditor.model.*;
032: import org.openharmonise.workfloweditor.vfs.*;
033:
034: /**
035: * Starting class for workflow editing. On constructing this
036: * class the workflow editor window will open, then a workflow model can
037: * be set which will then be loaded for editing.
038: *
039: * @author Matthew Large
040: * @version $Revision: 1.1 $
041: *
042: */
043: public class WorkflowEditor {
044:
045: /**
046: * The workflow diagram.
047: */
048: private FlowChart m_chart = null;
049:
050: /**
051: * Workflow editor display manager.
052: */
053: private DisplayManager m_display = null;
054:
055: /**
056: *
057: */
058: public WorkflowEditor() {
059: super ();
060: this .setup();
061: }
062:
063: /**
064: * Configures the workflow editor.
065: *
066: */
067: private void setup() {
068: m_display = new DisplayManager(this );
069:
070: m_chart = m_display.getFlowChart();
071: }
072:
073: /**
074: * Sets the model to be edited.
075: *
076: * @param model Workflow model
077: */
078: public void setModel(WorkflowModel model) {
079: this .m_chart.setModel(model);
080: this .m_chart.repaint();
081: }
082:
083: /**
084: * Prepared the workflow editor for shutdown. Saves all current
085: * changes.
086: *
087: */
088: public void shutdown() {
089: StateHandler.getInstance().addWait("WORKFLOWSAVE");
090: try {
091: AbstractVirtualFileSystem vfs = ServerList.getInstance()
092: .getHarmoniseServer().getVFS();
093:
094: VFSWorkflowModel model = (VFSWorkflowModel) m_chart
095: .getModel();
096: Iterator itor = model.getWorkflowStages().iterator();
097:
098: while (itor.hasNext()) {
099: VFSWorkflowStage stage = (VFSWorkflowStage) itor.next();
100: VersionedVirtualFile vfFile = (VersionedVirtualFile) vfs
101: .getVirtualFile(stage.getPath()).getResource();
102: if (vfFile.isChanged()) {
103: StatusData status = vfFile.sync();
104: if (status.isOK()) {
105: if (vfFile.getState() == VirtualFile.STATE_LIVE
106: && vfFile.getPendingVersionPath() != null) {
107: VersionedVirtualFile vfPending = (VersionedVirtualFile) vfs
108: .getVirtualFile(
109: vfFile
110: .getPendingVersionPath())
111: .getResource();
112: if (vfPending != null) {
113: vfPending.checkin();
114: }
115: } else if (vfFile.getState() == VirtualFile.STATE_PENDING) {
116: vfFile.checkin();
117: }
118: } else {
119:
120: }
121: }
122: }
123: } catch (Exception e) {
124: e.printStackTrace();
125: MessageHandler.getInstance().fireMessageEvent(
126: "There were problems saving the workflow changes.",
127: MessageHandler.TYPE_ERROR);
128: } finally {
129: StateHandler.getInstance().removeWait("WORKFLOWSAVE");
130: MessageHandler.getInstance().fireMessageEvent(
131: "Workflow changes saved.",
132: MessageHandler.TYPE_CONFIRM);
133: }
134: }
135:
136: public static void main(String[] args) {
137: WorkflowEditor editor = new WorkflowEditor();
138: }
139: }
|