| Line | Hits | Source |
|---|---|---|
| 1 | /******************************************************************************* | |
| 2 | * Demetrix process modelling system | |
| 3 | * | |
| 4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
| 5 | * | |
| 6 | * This file is part of Demetrix. | |
| 7 | * | |
| 8 | * Demetrix is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2.1 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * Demetrix is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with Demetrix; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | * | |
| 22 | * For further information you may | |
| 23 | * | |
| 24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
| 25 | * - look at http://sourceforge.net/projects/demetrix/ | |
| 26 | * - look at http://demetrix.sourceforge.net/ | |
| 27 | * - look at http://members.inode.at/d.pissarenko/ | |
| 28 | * | |
| 29 | *****************************************************************************/ | |
| 30 | package net.sourceforge.demetrix.ui; | |
| 31 | import java.awt.image.BufferedImage; | |
| 32 | import java.io.File; | |
| 33 | import java.io.IOException; | |
| 34 | import java.util.ArrayList; | |
| 35 | import java.util.Date; | |
| 36 | import java.util.Iterator; | |
| 37 | import javax.swing.JDialog; | |
| 38 | import javax.swing.JFileChooser; | |
| 39 | import javax.swing.JOptionPane; | |
| 40 | import javax.swing.tree.DefaultMutableTreeNode; | |
| 41 | ||
| 42 | import org._3pq.jgrapht.Graph; | |
| 43 | import org._3pq.jgrapht.ext.JGraphModelAdapter; | |
| 44 | import org._3pq.jgrapht.graph.ListenableDirectedGraph; | |
| 45 | import org.apache.log4j.Logger; | |
| 46 | import org.jgraph.JGraph; | |
| 47 | import org.jgraph.graph.DefaultGraphCell; | |
| 48 | import net.sourceforge.demetrix.model.*; | |
| 49 | import net.sourceforge.demetrix.properties.DemetrixPropertiesHolder; | |
| 50 | import net.sourceforge.demetrix.ui.balancesheets.*; | |
| 51 | import net.sourceforge.demetrix.util.ExcelFileFilter; | |
| 52 | import net.sourceforge.demetrix.util.GraphVertexPositioningHelper; | |
| 53 | import net.sourceforge.demetrix.util.JGraphExporter; | |
| 54 | import net.sourceforge.demetrix.util.PNGFileFilter; | |
| 55 | import net.sourceforge.demetrix.util.SwingWorker; | |
| 56 | /** | |
| 57 | * @author Dimitri Pissarenko | |
| 58 | * | |
| 59 | */ | |
| 60 | 0 | public class ProcessChainEditorActions { |
| 61 | private Logger logger = Logger.getLogger(getClass()); | |
| 62 | 4 | public ProcessChainEditorActions() { |
| 63 | 4 | } |
| 64 | public void newLinkAction(JGraph jgraph, ListenableDirectedGraph grapht) { | |
| 65 | 0 | Object selectedObject1 = null; |
| 66 | 0 | Object selectedObject2 = null; |
| 67 | 0 | Object[] selectedCells = null; |
| 68 | 0 | Link link = null; |
| 69 | 0 | if (jgraph.getSelectionCount() == 2) { |
| 70 | 0 | selectedCells = jgraph.getSelectionCells(); |
| 71 | 0 | selectedObject1 = |
| 72 | ((DefaultGraphCell) selectedCells[0]).getUserObject(); | |
| 73 | 0 | selectedObject2 = |
| 74 | ((DefaultGraphCell) selectedCells[1]).getUserObject(); | |
| 75 | 0 | if ((selectedObject1 instanceof ProcessChainNode) |
| 76 | && (selectedObject2 instanceof ProcessChainNode)) { | |
| 77 | 0 | if (((selectedObject1 instanceof Task) |
| 78 | && (selectedObject2 instanceof Resource)) | |
| 79 | || ((selectedObject1 instanceof Resource) | |
| 80 | && (selectedObject2 instanceof Task))) { | |
| 81 | 0 | link = |
| 82 | new Link( | |
| 83 | (DemetrixPropertiesHolder) selectedObject1, | |
| 84 | (DemetrixPropertiesHolder) selectedObject2); | |
| 85 | 0 | grapht.addEdge(link); |
| 86 | 0 | ( |
| 87 | (ProcessChain) CurrentProcessChainSingleton | |
| 88 | .getInstance() | |
| 89 | .getCurrentGraphParent() | |
| 90 | .getSubGraph()) | |
| 91 | .addLink( | |
| 92 | link); | |
| 93 | } else { | |
| 94 | this.logger.debug( | |
| 95 | "newLinkAction: either both selected objects are tasks or both are resources, can't create a link between them"); | |
| 96 | } | |
| 97 | } else { | |
| 98 | this.logger.debug( | |
| 99 | "newLinkAction: at least one of the selected objects is not a ProcessChainNode"); | |
| 100 | } | |
| 101 | } else { | |
| 102 | this.logger.debug( | |
| 103 | "newLinkAction: in order to create a link, exactly two objects must be selected"); | |
| 104 | } | |
| 105 | 0 | } |
| 106 | public void balanceSheetAction() { | |
| 107 | 0 | TaskBalanceSheetDialog dialog = null; |
| 108 | 0 | SwixMLTaskBalanceSheetRenderer balanceSheet = null; |
| 109 | 0 | Task task = null; |
| 110 | 0 | task = |
| 111 | (Task) CurrentlySelectedNodeSingleton | |
| 112 | .getInstance() | |
| 113 | .getCurrentlySelectedNode() | |
| 114 | .getUserObject(); | |
| 115 | 0 | balanceSheet = this.createBalanceSheet(task); |
| 116 | 0 | balanceSheet.render(); |
| 117 | 0 | dialog = new TaskBalanceSheetDialog(balanceSheet, task); |
| 118 | 0 | dialog.getDialog().show(); |
| 119 | 0 | } |
| 120 | private SwixMLTaskBalanceSheetRenderer createBalanceSheet(Task task) { | |
| 121 | 1 | SwixMLTaskBalanceSheetRenderer balanceSheet = null; |
| 122 | 1 | ProcessChain processChain = null; |
| 123 | 1 | ArrayList inputs = null; |
| 124 | 1 | ArrayList outputs = null; |
| 125 | 1 | balanceSheet = new SwixMLTaskBalanceSheetRenderer(); |
| 126 | 1 | balanceSheet.setTask(task); |
| 127 | 1 | processChain = |
| 128 | (ProcessChain) CurrentProcessChainSingleton | |
| 129 | .getInstance() | |
| 130 | .getCurrentGraphParent() | |
| 131 | .getSubGraph(); | |
| 132 | 1 | if (processChain != null) { |
| 133 | 1 | inputs = |
| 134 | new ArrayList( | |
| 135 | processChain.getInputs( | |
| 136 | (String) task.getProperty("name").getValue())); | |
| 137 | 1 | outputs = |
| 138 | new ArrayList( | |
| 139 | processChain.getOutputs( | |
| 140 | (String) task.getProperty("name").getValue())); | |
| 141 | 1 | balanceSheet.setInputs(inputs); |
| 142 | 1 | balanceSheet.setOutputs(outputs); |
| 143 | } else { | |
| 144 | this.logger.error( | |
| 145 | "no process chain, couldn't fetch inputs/outputs of the task (CurrentProcessChainSingleton.data==null)"); | |
| 146 | } | |
| 147 | 1 | return balanceSheet; |
| 148 | } | |
| 149 | public void loadProcessChainActionAction() { | |
| 150 | final JFileChooser fileChooser; | |
| 151 | ||
| 152 | 0 | fileChooser = new JFileChooser(); |
| 153 | 0 | fileChooser.setFileFilter(new ExcelFileFilter()); |
| 154 | 0 | if (fileChooser |
| 155 | .showOpenDialog(ProcessChainEditor.getInstance().getFrame()) | |
| 156 | == JFileChooser.APPROVE_OPTION) { | |
| 157 | 0 | SwingWorker worker = new SwingWorker() { |
| 158 | public Object construct() { | |
| 159 | File file = null; | |
| 160 | Task task = null; | |
| 161 | ||
| 162 | ProcessChainExcelReader reader = null; | |
| 163 | ProcessChain processChain = null; | |
| 164 | file = fileChooser.getSelectedFile(); | |
| 165 | CursorManagementSingleton.getInstance().setWaitCursor(); | |
| 166 | reader = new ProcessChainExcelReader(file); | |
| 167 | try { | |
| 168 | processChain = reader.read(); | |
| 169 | } catch (Exception exception) { | |
| 170 | logger.error( | |
| 171 | "an error occured while trying to read a process chain from file \"" | |
| 172 | + file | |
| 173 | + "\"", | |
| 174 | exception); | |
| 175 | CursorManagementSingleton | |
| 176 | .getInstance() | |
| 177 | .setDefaultCursor(); | |
| 178 | JOptionPane.showMessageDialog( | |
| 179 | ProcessChainEditor.getInstance().getFrame(), | |
| 180 | "An error occured while loading the process chain. See console output for details.", | |
| 181 | ProcessChainEditor | |
| 182 | .getInstance() | |
| 183 | .getFrame() | |
| 184 | .getTitle(), | |
| 185 | JOptionPane.OK_OPTION); | |
| 186 | } | |
| 187 | task = new Task(); | |
| 188 | task.setSubGraph(processChain); | |
| 189 | ||
| 190 | CurrentProcessChainSingleton | |
| 191 | .getInstance() | |
| 192 | .setCurrentGraphParent( | |
| 193 | task); | |
| 194 | CurrentProcessChainSingleton | |
| 195 | .getInstance() | |
| 196 | .setSavingLocation( | |
| 197 | file); | |
| 198 | CurrentProcessChainSingleton | |
| 199 | .getInstance() | |
| 200 | .setTopLevelProcessChain( | |
| 201 | true); | |
| 202 | CurrentProcessChainSingleton | |
| 203 | .getInstance() | |
| 204 | .informCurrentGraphParentChanged(); | |
| 205 | ||
| 206 | return ""; | |
| 207 | } | |
| 208 | }; | |
| 209 | 0 | worker.start(); |
| 210 | } | |
| 211 | 0 | } |
| 212 | public void newProcessChainAction() { | |
| 213 | 0 | NewProcessChainActionSwingWorker worker = null; |
| 214 | 0 | worker = new NewProcessChainActionSwingWorker(); |
| 215 | 0 | worker.start(); |
| 216 | 0 | } |
| 217 | public Resource newResourceAction(ListenableDirectedGraph grapht) { | |
| 218 | 1 | Resource resource = null; |
| 219 | 1 | resource = new Resource(); |
| 220 | 1 | resource.getProperty("name").setValue("resource " + (new Date())); |
| 221 | 1 | ( |
| 222 | (ProcessChain) CurrentProcessChainSingleton | |
| 223 | .getInstance() | |
| 224 | .getCurrentGraphParent() | |
| 225 | .getSubGraph()) | |
| 226 | .addResource( | |
| 227 | resource); | |
| 228 | 1 | grapht.addVertex(resource); |
| 229 | 1 | return resource; |
| 230 | } | |
| 231 | public void newResourcePopupAction( | |
| 232 | ListenableDirectedGraph grapht, | |
| 233 | int x, | |
| 234 | int y, | |
| 235 | JGraphModelAdapter jgraphAdapter) { | |
| 236 | 0 | Object vertex = null; |
| 237 | 0 | vertex = this.newResourceAction(grapht); |
| 238 | 0 | GraphVertexPositioningHelper.getInstance().positionVertexAt( |
| 239 | vertex, | |
| 240 | x, | |
| 241 | y, | |
| 242 | jgraphAdapter); | |
| 243 | 0 | } |
| 244 | public Task newTaskAction(ListenableDirectedGraph grapht) { | |
| 245 | 1 | Task task = null; |
| 246 | 1 | task = new Task(); |
| 247 | 1 | task.getProperty("name").setValue("task " + (new Date())); |
| 248 | 1 | ( |
| 249 | (ProcessChain) CurrentProcessChainSingleton | |
| 250 | .getInstance() | |
| 251 | .getCurrentGraphParent() | |
| 252 | .getSubGraph()) | |
| 253 | .addTask( | |
| 254 | task); | |
| 255 | 1 | grapht.addVertex(task); |
| 256 | 1 | return task; |
| 257 | } | |
| 258 | public void newTaskPopupAction( | |
| 259 | ListenableDirectedGraph grapht, | |
| 260 | int x, | |
| 261 | int y, | |
| 262 | JGraphModelAdapter jgraphAdapter) { | |
| 263 | 0 | Object vertex = null; |
| 264 | 0 | vertex = this.newTaskAction(grapht); |
| 265 | 0 | GraphVertexPositioningHelper.getInstance().positionVertexAt( |
| 266 | vertex, | |
| 267 | x, | |
| 268 | y, | |
| 269 | jgraphAdapter); | |
| 270 | 0 | } |
| 271 | public void saveProcessChainAction() { | |
| 272 | 0 | SwingWorker worker = new SwingWorker() { |
| 273 | public Object construct() { | |
| 274 | JFileChooser fileChooser = null; | |
| 275 | ProcessChainExcelWriter writer = null; | |
| 276 | if (CurrentProcessChainSingleton | |
| 277 | .getInstance() | |
| 278 | .getSavingLocation() | |
| 279 | == null) { | |
| 280 | fileChooser = new JFileChooser(); | |
| 281 | fileChooser.setFileFilter(new ExcelFileFilter()); | |
| 282 | if (fileChooser | |
| 283 | .showSaveDialog( | |
| 284 | ProcessChainEditor.getInstance().getFrame()) | |
| 285 | == JFileChooser.APPROVE_OPTION) { | |
| 286 | CurrentProcessChainSingleton | |
| 287 | .getInstance() | |
| 288 | .setSavingLocation( | |
| 289 | fileChooser.getSelectedFile()); | |
| 290 | } | |
| 291 | } | |
| 292 | if (CurrentProcessChainSingleton | |
| 293 | .getInstance() | |
| 294 | .getSavingLocation() | |
| 295 | != null) { | |
| 296 | CursorManagementSingleton.getInstance().setWaitCursor(); | |
| 297 | writer = | |
| 298 | new ProcessChainExcelWriter( | |
| 299 | CurrentProcessChainSingleton | |
| 300 | .getInstance() | |
| 301 | .getSavingLocation(), | |
| 302 | (ProcessChain) CurrentProcessChainSingleton | |
| 303 | .getInstance() | |
| 304 | .getCurrentGraphParent() | |
| 305 | .getSubGraph()); | |
| 306 | try { | |
| 307 | writer.write(); | |
| 308 | CursorManagementSingleton | |
| 309 | .getInstance() | |
| 310 | .setDefaultCursor(); | |
| 311 | } catch (IOException exception) { | |
| 312 | exception.printStackTrace(); | |
| 313 | logger.error( | |
| 314 | "error while saving process chain", | |
| 315 | exception); | |
| 316 | CursorManagementSingleton | |
| 317 | .getInstance() | |
| 318 | .setDefaultCursor(); | |
| 319 | JOptionPane.showMessageDialog( | |
| 320 | ProcessChainEditor.getInstance().getFrame(), | |
| 321 | "An error occured while saving the process chain. Perhaps the file is open in Microsoft(R) Excel(tm). See console output for details.", | |
| 322 | ProcessChainEditor | |
| 323 | .getInstance() | |
| 324 | .getFrame() | |
| 325 | .getTitle(), | |
| 326 | JOptionPane.ERROR_MESSAGE); | |
| 327 | } | |
| 328 | } | |
| 329 | return ""; | |
| 330 | } | |
| 331 | }; | |
| 332 | 0 | worker.start(); |
| 333 | 0 | } |
| 334 | public void systemBalanceSheetAction() { | |
| 335 | 0 | SystemBalanceSheetDialog dialog = null; |
| 336 | 0 | SwixMLBalanceSheetRenderer balanceSheetRenderer = null; |
| 337 | 0 | balanceSheetRenderer = new SwixMLSystemBalanceSheetRenderer(); |
| 338 | 0 | balanceSheetRenderer.render(); |
| 339 | 0 | dialog = new SystemBalanceSheetDialog(balanceSheetRenderer); |
| 340 | 0 | dialog.getDialog().show(); |
| 341 | 0 | } |
| 342 | public void aboutAction() { | |
| 343 | 0 | SwingWorker worker = new SwingWorker() { |
| 344 | public Object construct() { | |
| 345 | JDialog aboutDialog = null; | |
| 346 | CursorManagementSingleton.getInstance().setWaitCursor(); | |
| 347 | aboutDialog = (new AboutDialog()).getDialog(); | |
| 348 | CursorManagementSingleton.getInstance().setDefaultCursor(); | |
| 349 | aboutDialog.show(); | |
| 350 | return ""; | |
| 351 | } | |
| 352 | }; | |
| 353 | 0 | worker.start(); |
| 354 | 0 | } |
| 355 | public void exportToPNGAction(JGraph graph) { | |
| 356 | 0 | BufferedImage img = null; |
| 357 | 0 | String selectedFileName = null; |
| 358 | 0 | JFileChooser fileChooser = null; |
| 359 | 0 | fileChooser = new JFileChooser(); |
| 360 | 0 | fileChooser.setFileFilter(new PNGFileFilter()); |
| 361 | 0 | if (fileChooser |
| 362 | .showSaveDialog(ProcessChainEditor.getInstance().getFrame()) | |
| 363 | == JFileChooser.APPROVE_OPTION) { | |
| 364 | 0 | selectedFileName = fileChooser.getSelectedFile().getAbsolutePath(); |
| 365 | 0 | if (!selectedFileName.toLowerCase().endsWith(".png")) { |
| 366 | 0 | selectedFileName = selectedFileName + ".png"; |
| 367 | } | |
| 368 | 0 | JGraphExporter.getInstance().exportJGraph( |
| 369 | graph, | |
| 370 | JGraphExporter.PNG_FORMAT, | |
| 371 | new File(selectedFileName)); | |
| 372 | }; | |
| 373 | 0 | } |
| 374 | public void createTaskSubGraphAction( | |
| 375 | ListenableDirectedGraph graph, | |
| 376 | JGraph jgraph) { | |
| 377 | 0 | SubGraphCreationHelper.getInstance().createSubGraph( |
| 378 | (ProcessChain) graph, | |
| 379 | jgraph); | |
| 380 | 0 | } |
| 381 | public void descendIntoSubGraphAction() { | |
| 382 | 0 | ProcessChainNode node = null; |
| 383 | 0 | DefaultGraphCell cell = null; |
| 384 | 0 | Object userObject = null; |
| 385 | 0 | Graph subGraph = null; |
| 386 | 0 | cell = |
| 387 | CurrentlySelectedNodeSingleton | |
| 388 | .getInstance() | |
| 389 | .getCurrentlySelectedNode(); | |
| 390 | 0 | if (cell != null) { |
| 391 | 0 | userObject = cell.getUserObject(); |
| 392 | 0 | if ((userObject != null) |
| 393 | && (userObject instanceof ProcessChainNode)) { | |
| 394 | 0 | node = (ProcessChainNode) userObject; |
| 395 | 0 | subGraph = node.getSubGraph(); |
| 396 | 0 | if (subGraph != null) { |
| 397 | 0 | CurrentProcessChainSingleton |
| 398 | .getInstance() | |
| 399 | .setCurrentGraphParent( | |
| 400 | node); | |
| 401 | 0 | CurrentProcessChainSingleton |
| 402 | .getInstance() | |
| 403 | .setTopLevelProcessChain( | |
| 404 | false); | |
| 405 | 0 | CurrentProcessChainSingleton |
| 406 | .getInstance() | |
| 407 | .setSavingLocation( | |
| 408 | null); | |
| 409 | } | |
| 410 | } | |
| 411 | } | |
| 412 | 0 | } |
| 413 | public void deleteAction(JGraph jgraph) { | |
| 414 | 7 | this.deleteSingleCell( |
| 415 | jgraph, | |
| 416 | CurrentlySelectedNodeSingleton | |
| 417 | .getInstance() | |
| 418 | .getCurrentlySelectedNode()); | |
| 419 | 7 | this.deleteSeveralCells(jgraph); |
| 420 | 7 | } |
| 421 | private void deleteSingleCell(JGraph jgraph, DefaultGraphCell cell) { | |
| 422 | 14 | Object[] stuffToDelete = null; |
| 423 | 14 | Object userObject = null; |
| 424 | 14 | ProcessChain processChain = null; |
| 425 | 14 | Iterator edgesIterator = null; |
| 426 | 14 | DefaultMutableTreeNode treeNode=null; |
| 427 | ||
| 428 | 14 | if (cell != null) { |
| 429 | 11 | processChain = |
| 430 | (ProcessChain) CurrentProcessChainSingleton | |
| 431 | .getInstance() | |
| 432 | .getCurrentGraphParent() | |
| 433 | .getSubGraph(); | |
| 434 | ||
| 435 | 11 | userObject = cell.getUserObject(); |
| 436 | 11 | if (userObject != null) { |
| 437 | 11 | if ((userObject instanceof Resource) |
| 438 | || (userObject instanceof Task)) { | |
| 439 | ||
| 440 | 9 | edgesIterator = processChain.edgesOf(userObject).iterator(); |
| 441 | 11 | while (edgesIterator.hasNext()) { |
| 442 | 2 | processChain.removeLink((Link)edgesIterator.next()); |
| 443 | } | |
| 444 | 9 | ((ProcessChainNodeTreeModel)SideBar.getInstance().getGraphStructureTree().getModel()).removeTreeNodeCorrespongingToUserObject(userObject); |
| 445 | ||
| 446 | 9 | processChain.removeTaskOrResource(userObject); |
| 447 | 2 | } else if (userObject instanceof Link) { |
| 448 | 0 | processChain.removeLink((Link) userObject); |
| 449 | } | |
| 450 | ||
| 451 | } | |
| 452 | } | |
| 453 | 14 | } |
| 454 | private void deleteSeveralCells(JGraph jgraph) { | |
| 455 | 7 | Object[] selectedCells = null; |
| 456 | ||
| 457 | 7 | selectedCells = |
| 458 | CurrentlySelectedNodeSingleton | |
| 459 | .getInstance() | |
| 460 | .getCurrentlySelectedCells(); | |
| 461 | 7 | if (selectedCells != null) { |
| 462 | 11 | for (int i = 0; i < selectedCells.length; i++) { |
| 463 | 7 | this.deleteSingleCell( |
| 464 | jgraph, | |
| 465 | (DefaultGraphCell) selectedCells[i]); | |
| 466 | } | |
| 467 | } | |
| 468 | 7 | } |
| 469 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |