| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GraphChangeAdapter |
|
| 2.4545454545454546;2.455 |
| 1 | /* $Id: GraphChangeAdapter.java 17850 2010-01-12 19:53:35Z linus $ | |
| 2 | ***************************************************************************** | |
| 3 | * Copyright (c) 2009 Contributors - see below | |
| 4 | * All rights reserved. This program and the accompanying materials | |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 6 | * which accompanies this distribution, and is available at | |
| 7 | * http://www.eclipse.org/legal/epl-v10.html | |
| 8 | * | |
| 9 | * Contributors: | |
| 10 | * mvw | |
| 11 | ***************************************************************************** | |
| 12 | * | |
| 13 | * Some portions of this file was previously release using the BSD License: | |
| 14 | */ | |
| 15 | ||
| 16 | // Copyright (c) 1996-2006 The Regents of the University of California. All | |
| 17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
| 18 | // software and its documentation without fee, and without a written | |
| 19 | // agreement is hereby granted, provided that the above copyright notice | |
| 20 | // and this paragraph appear in all copies. This software program and | |
| 21 | // documentation are copyrighted by The Regents of the University of | |
| 22 | // California. The software program and documentation are supplied "AS | |
| 23 | // IS", without any accompanying services from The Regents. The Regents | |
| 24 | // does not warrant that the operation of the program will be | |
| 25 | // uninterrupted or error-free. The end-user understands that the program | |
| 26 | // was developed for research purposes and is advised not to rely | |
| 27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
| 28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
| 29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
| 30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
| 31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
| 32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
| 33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
| 35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
| 36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
| 37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
| 38 | ||
| 39 | package org.argouml.uml.diagram; | |
| 40 | ||
| 41 | import org.argouml.model.DiDiagram; | |
| 42 | import org.argouml.model.DiElement; | |
| 43 | import org.argouml.model.Model; | |
| 44 | import org.tigris.gef.graph.GraphEvent; | |
| 45 | import org.tigris.gef.graph.GraphListener; | |
| 46 | import org.tigris.gef.graph.GraphModel; | |
| 47 | import org.tigris.gef.presentation.Fig; | |
| 48 | ||
| 49 | /** | |
| 50 | * Adapts changes in the Diagram subsystem (the graph presentation layer) | |
| 51 | * to changes in the Model subsyetm (diagram interchange model). | |
| 52 | * The curent implementaion does this by listening to graph events and | |
| 53 | * forwarding those as specific calls to the DiagramInterchangeModel. | |
| 54 | * This should be changed to a more standard Adapter architecture that | |
| 55 | * provides an interface for Figs and GraphModels to call only when required. | |
| 56 | * | |
| 57 | * @author Bob Tarling | |
| 58 | * @stereotype singleton | |
| 59 | */ | |
| 60 | public final class GraphChangeAdapter implements GraphListener { | |
| 61 | /** | |
| 62 | * The instance. | |
| 63 | */ | |
| 64 | 0 | private static final GraphChangeAdapter INSTANCE = |
| 65 | new GraphChangeAdapter(); | |
| 66 | ||
| 67 | /** | |
| 68 | * The getter for the instance. | |
| 69 | * | |
| 70 | * @return The instance. | |
| 71 | */ | |
| 72 | public static GraphChangeAdapter getInstance() { | |
| 73 | 0 | return INSTANCE; |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * The constructor of a singleton is private. | |
| 78 | */ | |
| 79 | 0 | private GraphChangeAdapter() { |
| 80 | // singleton, no instantiation | |
| 81 | 0 | } |
| 82 | ||
| 83 | public DiDiagram createDiagram(Class type, Object owner) { | |
| 84 | 0 | if (Model.getDiagramInterchangeModel() != null) { |
| 85 | 0 | return Model.getDiagramInterchangeModel() |
| 86 | .createDiagram(type, owner); | |
| 87 | } | |
| 88 | 0 | return null; |
| 89 | } | |
| 90 | ||
| 91 | ||
| 92 | public void removeDiagram(DiDiagram dd) { | |
| 93 | 0 | if (Model.getDiagramInterchangeModel() != null) { |
| 94 | 0 | Model.getDiagramInterchangeModel().deleteDiagram(dd); |
| 95 | } | |
| 96 | 0 | } |
| 97 | ||
| 98 | public DiElement createElement(GraphModel gm, Object node) { | |
| 99 | 0 | if (Model.getDiagramInterchangeModel() != null) { |
| 100 | 0 | return Model.getDiagramInterchangeModel().createElement( |
| 101 | ((UMLMutableGraphSupport) gm).getDiDiagram(), node); | |
| 102 | } | |
| 103 | 0 | return null; |
| 104 | } | |
| 105 | ||
| 106 | public void removeElement(DiElement element) { | |
| 107 | 0 | if (Model.getDiagramInterchangeModel() != null) { |
| 108 | 0 | Model.getDiagramInterchangeModel().deleteElement(element); |
| 109 | } | |
| 110 | 0 | } |
| 111 | ||
| 112 | /* | |
| 113 | * @see org.tigris.gef.graph.GraphListener#nodeAdded(org.tigris.gef.graph.GraphEvent) | |
| 114 | */ | |
| 115 | public void nodeAdded(GraphEvent e) { | |
| 116 | 0 | Object source = e.getSource(); |
| 117 | 0 | Object arg = e.getArg(); |
| 118 | 0 | if (source instanceof Fig) { |
| 119 | 0 | source = ((Fig) source).getOwner(); |
| 120 | } | |
| 121 | 0 | if (arg instanceof Fig) { |
| 122 | 0 | arg = ((Fig) arg).getOwner(); |
| 123 | } | |
| 124 | 0 | Model.getDiagramInterchangeModel().nodeAdded(source, arg); |
| 125 | 0 | } |
| 126 | ||
| 127 | /* | |
| 128 | * @see org.tigris.gef.graph.GraphListener#edgeAdded(org.tigris.gef.graph.GraphEvent) | |
| 129 | */ | |
| 130 | public void edgeAdded(GraphEvent e) { | |
| 131 | 0 | Object source = e.getSource(); |
| 132 | 0 | Object arg = e.getArg(); |
| 133 | 0 | if (source instanceof Fig) { |
| 134 | 0 | source = ((Fig) source).getOwner(); |
| 135 | } | |
| 136 | 0 | if (arg instanceof Fig) { |
| 137 | 0 | arg = ((Fig) arg).getOwner(); |
| 138 | } | |
| 139 | 0 | Model.getDiagramInterchangeModel().edgeAdded(source, arg); |
| 140 | 0 | } |
| 141 | ||
| 142 | /* | |
| 143 | * @see org.tigris.gef.graph.GraphListener#nodeRemoved(org.tigris.gef.graph.GraphEvent) | |
| 144 | */ | |
| 145 | public void nodeRemoved(GraphEvent e) { | |
| 146 | 0 | Object source = e.getSource(); |
| 147 | 0 | Object arg = e.getArg(); |
| 148 | 0 | if (source instanceof Fig) { |
| 149 | 0 | source = ((Fig) source).getOwner(); |
| 150 | } | |
| 151 | 0 | if (arg instanceof Fig) { |
| 152 | 0 | arg = ((Fig) arg).getOwner(); |
| 153 | } | |
| 154 | 0 | Model.getDiagramInterchangeModel().nodeRemoved(source, arg); |
| 155 | 0 | } |
| 156 | ||
| 157 | /* | |
| 158 | * @see org.tigris.gef.graph.GraphListener#edgeRemoved(org.tigris.gef.graph.GraphEvent) | |
| 159 | */ | |
| 160 | public void edgeRemoved(GraphEvent e) { | |
| 161 | 0 | Object source = e.getSource(); |
| 162 | 0 | Object arg = e.getArg(); |
| 163 | 0 | if (source instanceof Fig) { |
| 164 | 0 | source = ((Fig) source).getOwner(); |
| 165 | } | |
| 166 | 0 | if (arg instanceof Fig) { |
| 167 | 0 | arg = ((Fig) arg).getOwner(); |
| 168 | } | |
| 169 | 0 | Model.getDiagramInterchangeModel().edgeRemoved(source, arg); |
| 170 | 0 | } |
| 171 | ||
| 172 | /* | |
| 173 | * @see org.tigris.gef.graph.GraphListener#graphChanged(org.tigris.gef.graph.GraphEvent) | |
| 174 | */ | |
| 175 | public void graphChanged(GraphEvent e) { | |
| 176 | 0 | Object source = e.getSource(); |
| 177 | 0 | Object arg = e.getArg(); |
| 178 | 0 | if (source instanceof Fig) { |
| 179 | 0 | source = ((Fig) source).getOwner(); |
| 180 | } | |
| 181 | 0 | if (arg instanceof Fig) { |
| 182 | 0 | arg = ((Fig) arg).getOwner(); |
| 183 | } | |
| 184 | 0 | Model.getDiagramInterchangeModel().graphChanged(source, arg); |
| 185 | 0 | } |
| 186 | } |