1 19 package org.openharmonise.him.dnd; 20 21 import java.awt.*; 22 import java.awt.dnd.*; 23 import java.util.*; 24 25 import org.openharmonise.commons.xml.namespace.*; 26 import org.openharmonise.him.*; 27 import org.openharmonise.him.context.StateHandler; 28 import org.openharmonise.him.swing.resourcetree.*; 29 import org.openharmonise.him.window.messages.*; 30 import org.openharmonise.vfs.*; 31 import org.openharmonise.vfs.context.*; 32 import org.openharmonise.vfs.metadata.*; 33 import org.openharmonise.vfs.metadata.value.*; 34 import org.openharmonise.vfs.servers.ServerList; 35 import org.openharmonise.vfs.status.*; 36 import org.openharmonise.workfloweditor.flowchart.*; 37 import org.openharmonise.workfloweditor.flowchart.shapes.*; 38 import org.openharmonise.workfloweditor.vfs.*; 39 40 41 49 public class WorkflowDropTarget implements DropTargetListener { 50 51 DropTarget m_target; 52 FlowChart m_chart; 53 ResourceTree m_tree; 54 55 private boolean bDisplayErrorMessage = true; 56 57 private StageShape m_stageShape = null; 58 59 65 public WorkflowDropTarget(FlowChart chart, ResourceTree tree) { 66 m_chart = chart; 67 m_tree = tree; 68 m_target = new DropTarget(m_chart, this); 69 } 70 71 74 public void dragEnter(DropTargetDragEvent arg0) { 75 } 76 77 80 public void dragOver(DropTargetDragEvent dtde) { 81 Point pt = dtde.getLocation(); 82 if(this.m_stageShape==null) { 83 VirtualFile vfFile = m_tree.getSelectedResource(); 84 85 VFSWorkflowModel model = (VFSWorkflowModel) m_chart.getModel(); 86 87 boolean bDuplicate = false; 88 89 Iterator itor = model.getWorkflowStages().iterator(); 90 while (itor.hasNext()) { 91 VFSWorkflowStage stage = (VFSWorkflowStage) itor.next(); 92 VirtualFile stageFile = ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(stage.getPath()).getResource(); 93 if(stageFile!=null && stageFile.getFileName().equals(vfFile.getFileName())) { 94 bDuplicate = true; 95 } 96 } 97 98 if(!bDuplicate) { 99 AbstractVirtualFileSystem vfs = vfFile.getVFS(); 100 101 VFSWorkflowStageDefinition stageDefn = new VFSWorkflowStageDefinition(vfFile, (VFSWorkflowModel)this.m_chart.getModel()); 102 VirtualFile vfStagesCollection = model.getStagesCollection(); 103 String sNewPath = vfStagesCollection.getFullPath() + "/" + vfFile.getFileName(); 104 105 VirtualFile vfNewFile = new VirtualFile(sNewPath); 106 vfNewFile.setContent(null); 107 if(vfs.addVirtualFile(sNewPath, vfNewFile)!=null) { 108 VersionedVirtualFile vfStageFile = (VersionedVirtualFile) vfs.getVirtualFile(sNewPath).getResource(); 109 PropertyInstance propInst = vfStageFile.getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_RELN"); 110 ResourceValue value = (ResourceValue) propInst.getNewValueInstance(); 111 value.setValue(stageDefn.getPath()); 112 propInst.addValue(value); 113 114 PropertyInstance propInst2 = vfStageFile.getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_MAND"); 115 BooleanValue value2 = (BooleanValue) propInst2.getNewValueInstance(); 116 value2.setValue(true); 117 propInst2.addValue(value2); 118 119 StatusData status = vfStageFile.sync(); 120 121 122 StateHandler.getInstance().addWait("WORKFLOWSAVE"); 123 try { 124 itor = model.getWorkflowStages().iterator(); 125 126 while (itor.hasNext()) { 127 VFSWorkflowStage stage = (VFSWorkflowStage) itor.next(); 128 VersionedVirtualFile vfFile2 = (VersionedVirtualFile) vfs.getVirtualFile(stage.getPath()).getResource(); 129 if(vfFile2.isChanged()) { 130 StatusData status2 = vfFile2.sync(); 131 status.addStatusData(status2); 132 if( status2.isOK() ) { 133 if(vfFile2.getState()==VirtualFile.STATE_LIVE && vfFile2.getPendingVersionPath()!=null) { 135 VersionedVirtualFile vfPending = (VersionedVirtualFile) vfs.getVirtualFile(vfFile2.getPendingVersionPath()).getResource(); 136 if(vfPending!=null) { 137 vfPending.checkin(); 138 } 139 } else if(vfFile2.getState()==VirtualFile.STATE_PENDING) { 140 vfFile2.checkin(); 141 } 142 } else { 143 } 145 } 146 } 147 } catch(Exception e) { 148 e.printStackTrace(); 149 } finally { 150 StateHandler.getInstance().removeWait("WORKFLOWSAVE"); 151 } 152 153 if(status.isOK()) { 154 vfStageFile = (VersionedVirtualFile) vfs.getVirtualFile(sNewPath).getResource(); 155 StatusData status2 = vfStageFile.checkin(); 156 if( status2.isOK() ) { 157 vfStageFile = (VersionedVirtualFile) vfs.getVirtualFile(sNewPath).getResource(); 158 159 VFSWorkflowStage stage = new VFSWorkflowStage(model, vfStageFile); 160 stage.setDefinition(stageDefn); 161 162 this.m_chart.getModel().addWorkflowStage(stage); 163 164 m_stageShape = new StageShape(100,100, stage); 165 this.m_chart.addShape(m_stageShape); 166 } 167 } 168 169 } 170 this.m_stageShape.setX(pt.x); 171 this.m_stageShape.setY(pt.y); 172 } else { 173 if(bDisplayErrorMessage) { 174 MessageHandler.getInstance().fireMessageEvent("You cannot have two Workflow Stages with the same name in a single Workflow.", MessageHandler.TYPE_ERROR); 175 this.bDisplayErrorMessage=false; 176 } 177 } 178 179 } 180 this.m_chart.repaint(); 181 } 182 183 186 public void dropActionChanged(DropTargetDragEvent arg0) { 187 } 188 189 192 public void drop(DropTargetDropEvent dtde) { 193 this.m_stageShape=null; 194 this.bDisplayErrorMessage=true; 195 } 196 197 200 public void dragExit(DropTargetEvent arg0) { 201 } 202 203 } 204 | Popular Tags |