1 10 11 package org.enhydra.jawe; 12 13 import org.enhydra.jawe.actions.*; 14 import org.enhydra.jawe.graph.*; 15 import org.enhydra.jawe.xml.*; 16 17 import org.jgraph.*; 18 import org.jgraph.graph.*; 19 import org.jgraph.plaf.basic.*; 20 import java.awt.*; 21 import java.awt.print.*; 22 import java.awt.event.*; 23 import java.util.*; 24 import java.io.*; 25 import javax.swing.*; 26 import javax.swing.border.*; 27 import javax.swing.tree.DefaultMutableTreeNode ; 28 import org.enhydra.jawe.PackageEditor; 29 30 33 public abstract class AbstractGraph extends JGraph implements WorkflowElement { 34 35 protected XMLComplexElement xmlObject=null; 36 37 38 protected transient WorkflowManager workflowManager; 39 40 protected transient AbstractEditor editor; 41 42 44 protected Map xpdlSchemaValidationErrors=null; 45 46 49 protected String basicXpdlSchemaValidationError=null; 50 51 55 protected Map graphConnectionErrors=null; 56 57 60 protected String basicGraphConnectionError=null; 61 62 66 protected Map graphConformanceErrors=null; 67 68 72 protected java.util.List basicGraphConformanceErrors=null; 73 74 78 protected Map logicErrors=null; 79 80 83 protected String basicLogicError=null; 84 85 88 public AbstractGraph(GraphModel model,AbstractEditor editor) { 89 selectionModel = new JaWEGraphSelectionModel(this); 90 setLayout(null); 91 GraphLayoutCache view = new GraphLayoutCache(this); setGraphLayoutCache(view); 95 updateUI(); 96 if (model == null) { 97 model = new JaWEGraphModel(); 98 } 99 setModel(model); 100 101 this.editor=editor; 102 workflowManager=new WorkflowManager(this); 104 setMarqueeHandler(new JaWEMarqueeHandler(this)); 107 108 initGraphBehavior(); 110 111 } 112 113 public AbstractGraph(GraphModel model,GraphLayoutCache view) { 114 super(model,view); 115 } 116 117 public abstract org.enhydra.jawe.xml.elements.Package getXMLPackage (); 118 119 public abstract void setPropertyObject (XMLComplexElement ce); 120 121 public abstract void createWorkflowGraph (Window pFrame); 122 123 139 public abstract String getToolTipText(MouseEvent event); 140 141 protected void initGraphBehavior() { 142 setHandleSize(4); 143 setTolerance(4); 144 setSelectNewCells(true); 145 setSizeable(false); 146 setMoveable(false); 147 148 selectionModel.setSelectionMode(GraphSelectionModel.SINGLE_GRAPH_SELECTION); 149 150 refreshGraphConfiguration(); 151 } 152 153 public void refreshGraphConfiguration () { 154 JaWEConfig jcfg=JaWEConfig.getInstance(); 155 boolean gs=jcfg.getGridStatus(); 156 setGridEnabled(gs); 157 setGridVisible(gs); 158 setGridSize(jcfg.getGridSize()); 159 setBackground(Utils.getColor(jcfg.getBackgroundColor())); 160 setHighlightColor(Utils.getColor(jcfg.getHighlightColor())); 161 setGridColor(Utils.getColor(jcfg.getGridColor())); 162 setHandleColor(Utils.getColor(jcfg.getHandleColor())); 163 setMarqueeColor(Utils.getColor(jcfg.getMarqueeColor())); 164 setFontSize(); 165 ((JaWEMarqueeHandler)getMarqueeHandler()).enableBubblesButtons(JaWEConfig.getInstance().getUseBubblesStatus()); 166 updateStartEndBubbles(); 167 } 168 169 protected void setFontSize () { 170 boolean isModified=JaWE.getInstance().isModified(); 171 Set cellSet=JaWEGraphModel.getAllCellsInModel(getModel()); 172 if (cellSet==null) return; 173 java.util.List list = new ArrayList(); 175 for (Iterator i=cellSet.iterator(); i.hasNext();) { 176 Object cell=i.next(); 177 if (!(cell instanceof Port)) { 178 list.add(cell); 179 } 180 } 181 Object [] cells = list.toArray(); 182 183 Map nested = new Hashtable(); 184 for (int i = 0; i < cells.length; i++) { 185 CellView view = getGraphLayoutCache().getMapping(cells[i], false); 186 if (view != null) { 187 Font font = GraphConstants.getFont(view.getAllAttributes()); 188 if (font.getSize()==JaWEConfig.getInstance().getFontSize()) { 189 return; 190 } 191 Map attr = GraphConstants.createMap(); 192 GraphConstants.setFont(attr, font.deriveFont(JaWEConfig.getInstance().getFontSize())); 193 nested.put(cells[i], attr); 194 } 195 } 196 ((JaWEGraphModel)graphModel).editFonts(nested); 199 if (!isModified) { 200 JaWE.getInstance().setModified(false); 201 } 202 } 203 204 protected void updateStartEndBubbles () { 205 if (!JaWEConfig.getInstance().getUseBubblesStatus()) { 206 Set objectsToRemove=new HashSet(); 207 Set starts=workflowManager.getStarts(); 208 objectsToRemove.addAll(starts); 209 Iterator it=starts.iterator(); 210 while (it.hasNext()) { 211 Start s=(Start)it.next(); 212 objectsToRemove.addAll(s.getOutgoingTransitions()); 213 } 214 Set ends=workflowManager.getEnds(); 215 objectsToRemove.addAll(ends); 216 it=ends.iterator(); 217 while (it.hasNext()) { 218 End e=(End)it.next(); 219 objectsToRemove.addAll(e.getIncomingTransitions()); 220 } 221 if (objectsToRemove.size()>0) { 222 ((JaWEGraphModel)graphModel).removeBubbles(objectsToRemove.toArray(),getEditor()); 223 } 224 } 225 } 226 227 230 public static void addSampleData(GraphModel model) { 231 return; 232 } 233 234 235 public void showPropertyDialog (Window parentWindow,AbstractGraph graph) {} 236 237 238 241 public XMLElement getPropertyObject () { 242 return xmlObject; 243 } 244 245 248 public XMLElement getXPDLObject () { 249 return xmlObject; 250 } 251 252 255 public XMLElement get (String what) { 256 return ((XMLComplexElement)getPropertyObject()).get(what); 257 } 258 259 263 public void set (String what,Object value) { 264 ((XMLComplexElement)getPropertyObject()).set(what,value); 265 } 266 267 270 public String getTooltip () { 271 return ""; 272 } 273 274 277 public AbstractEditor getEditor() { 278 return editor; 279 } 280 281 284 public WorkflowManager getWorkflowManager() { 285 return workflowManager; 286 } 287 288 290 public Map getXPDLSchemaValidationErrorMessages () { 291 return xpdlSchemaValidationErrors; 292 } 293 294 296 public String getBasicXPDLSchemaValidationErrorMessage () { 297 return basicXpdlSchemaValidationError; 298 } 299 300 306 public Map getConnectionErrorMessages () { 307 return graphConnectionErrors; 308 } 309 310 314 public String getBasicConnectionErrorMessage () { 315 return basicGraphConnectionError; 316 } 317 318 public abstract boolean validateAgainsXPDLSchema (); 319 320 331 public abstract boolean checkConnections (boolean fullCheck); 332 333 protected abstract boolean checkStartAndEndsConnections (boolean fullCheck); 334 335 protected abstract void updateXMLObjectsBeforeChecking (); 336 337 343 public Map getGraphConformanceErrorMessages () { 344 return graphConformanceErrors; 345 } 346 347 350 public java.util.List getBasicGraphConformanceErrorMessages () { 351 return basicGraphConformanceErrors; 352 } 353 354 365 public abstract boolean checkGraphConformance (boolean fullCheck); 366 367 370 public Map getLogicErrorMessages () { 371 return logicErrors; 372 } 373 374 377 public String getBasicLogicErrorMessage () { 378 return basicLogicError; 379 } 380 381 385 public abstract boolean checkLogic (boolean fullCheck); 386 387 395 public void updateUI() { 396 setUI(new JaWEGraphUI()); 397 invalidate(); 398 } 399 400 public void setAdditionalKeyboardShortcuts () { 401 getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) 402 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,InputEvent.ALT_DOWN_MASK,false), 403 Utils.getUnqualifiedClassName(EditProperties.class)); 404 getActionMap().put(Utils.getUnqualifiedClassName(EditProperties.class), 405 editor.getAction(Utils.getUnqualifiedClassName(EditProperties.class))); 406 407 editor.setALTCursorKeyboardShortcuts (this); 408 } 409 410 } 411 412 | Popular Tags |