View Javadoc
1 /* ==================================================================== 2 * The Apache Software License, Version 1.1 3 * 4 * Copyright (c) 2000 The Apache Software Foundation. All rights 5 * reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * 19 * 3. The end-user documentation included with the redistribution, 20 * if any, must include the following acknowledgment: 21 * "This product includes software developed by the 22 * Apache Software Foundation (http://www.apache.org/)." 23 * Alternately, this acknowledgment may appear in the software itself, 24 * if and wherever such third-party acknowledgments normally appear. 25 * 26 * 4. The names "Apache" and "Apache Software Foundation" must 27 * not be used to endorse or promote products derived from this 28 * software without prior written permission. For written 29 * permission, please contact apache@apache.org. 30 * 31 * 5. Products derived from this software may not be called "Apache", 32 * nor may "Apache" appear in their name, without prior written 33 * permission of the Apache Software Foundation. 34 * 35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 46 * SUCH DAMAGE. 47 * ==================================================================== 48 * 49 * This software consists of voluntary contributions made by many 50 * individuals on behalf of the Apache Software Foundation. For more 51 * information on the Apache Software Foundation, please see 52 * <http://www.apache.org/>. 53 * 54 * Portions of this software are based upon public domain software 55 * originally written at the National Center for Supercomputing Applications, 56 * University of Illinois, Urbana-Champaign. 57 */ 58 package com.bonevich.eclipse.cvsgrapher.editors; 59 60 import com.bonevich.eclipse.cvsgrapher.model.ICvsGraphNodeModel; 61 62 import org.eclipse.draw2d.ConnectionAnchor; 63 import org.eclipse.draw2d.geometry.Point; 64 import org.eclipse.draw2d.geometry.Rectangle; 65 import org.eclipse.gef.ConnectionEditPart; 66 import org.eclipse.gef.GraphicalEditPart; 67 import org.eclipse.gef.Request; 68 import org.eclipse.gef.editparts.AbstractGraphicalEditPart; 69 import org.eclipse.swt.SWT; 70 import org.eclipse.swt.graphics.Font; 71 72 import java.beans.PropertyChangeEvent; 73 import java.beans.PropertyChangeListener; 74 import java.util.List; 75 76 /*** 77 * Base class for node (version, branch) controller edit parts. 78 * 79 * @author jbonevic 80 */ 81 public abstract class AbstractCvsGraphNodeEditPart 82 extends AbstractGraphicalEditPart 83 implements ICvsGraphNodeEditPart, PropertyChangeListener 84 { 85 protected static final Font VERSION = new Font(null, "Helvetica", 10, SWT.BOLD); 86 protected static final Font INFO = new Font(null, "Helvetica", 8, SWT.NORMAL); 87 88 /*** The figure's anchor. */ 89 private ConnectionAnchor _anchor; 90 91 /*** 92 * Solely to intercept events in the graph. This way the model objects are 93 * not sullied with view information (location, size). 94 */ 95 private CvsGraphNodeViewHelper _helper; 96 97 /*** 98 * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() 99 */ 100 protected void createEditPolicies() 101 { 102 // For some reasons I do not quite understand, the 103 // CvsGraphXYLayoutEditPolicy.createChildEditPolicy() must be 104 // used instead of a PRIMARY_DRAG_ROLE edit policy here. 105 } 106 107 /*** 108 * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals() 109 */ 110 protected void refreshVisuals() 111 { 112 // System.out.println("[AbstractCvsGraphNodeEditPart] refreshVisuals"); 113 Point loc = _helper.getLocation(); 114 // System.out.println("[AbstractCvsGraphNodeEditPart] refreshVisuals: location = " + loc); 115 if (loc != null) 116 { 117 Rectangle r = new Rectangle(loc, CvsGraphNodeViewHelper.PREFERRED_SIZE); 118 ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), r); 119 } 120 } 121 122 /*** 123 * @see java.beans.PropertyChangeListener#propertyChange(PropertyChangeEvent) 124 */ 125 public void propertyChange(PropertyChangeEvent evt) 126 { 127 String prop = evt.getPropertyName(); 128 if (prop.equals("size") || prop.equals("location")) 129 { 130 refreshVisuals(); 131 } 132 } 133 134 /*** 135 * @see org.eclipse.gef.EditPart#activate() 136 */ 137 public void activate() 138 { 139 if (isActive() == false) 140 { 141 super.activate(); 142 _helper.addPropertyChangeListener(this); 143 } 144 } 145 146 /*** 147 * @see org.eclipse.gef.EditPart#deactivate() 148 */ 149 public void deactivate() 150 { 151 if (isActive()) 152 { 153 super.deactivate(); 154 _helper.removePropertyChangeListener(this); 155 } 156 } 157 158 /*** 159 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelSourceConnections() 160 */ 161 protected List getModelSourceConnections() 162 { 163 return getNodeModel().getSourceConnections(); 164 } 165 166 protected ICvsGraphNodeModel getNodeModel() 167 { 168 return ((ICvsGraphNodeModel) getModel()); 169 } 170 171 /*** 172 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelTargetConnections() 173 */ 174 protected List getModelTargetConnections() 175 { 176 return getNodeModel().getTargetConnections(); 177 } 178 179 /*** 180 * @see org.eclipse.gef.editparts.AbstractEditPart#createConnection(Object) 181 */ 182 protected ConnectionEditPart createConnection(Object iModel) 183 { 184 // The line below is based on Logical Diagram Editor's LogicEditPart.createConnection() 185 // It looks like an EditPart cache mechanism for EditPart connections, but I need 186 // to make sure of that... 187 CvsGraphConnectionEditPart connectPart = 188 (CvsGraphConnectionEditPart) getRoot().getViewer().getEditPartRegistry().get(iModel); 189 if (connectPart == null) 190 { 191 connectPart = new CvsGraphConnectionEditPart(); 192 connectPart.setModel(iModel); 193 } 194 195 return connectPart; 196 } 197 198 /*** 199 * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(ConnectionEditPart) 200 */ 201 public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) 202 { 203 return _anchor; 204 } 205 206 /*** 207 * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(Request) 208 */ 209 public ConnectionAnchor getSourceConnectionAnchor(Request request) 210 { 211 return null; 212 } 213 214 /*** 215 * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(ConnectionEditPart) 216 */ 217 public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) 218 { 219 return _anchor; 220 } 221 222 /*** 223 * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(Request) 224 */ 225 public ConnectionAnchor getTargetConnectionAnchor(Request request) 226 { 227 return null; 228 } 229 230 protected void setViewHelper(CvsGraphNodeViewHelper helper) 231 { 232 _helper = helper; 233 } 234 235 public CvsGraphNodeViewHelper getViewHelper() 236 { 237 return _helper; 238 } 239 240 protected void setAnchor(ConnectionAnchor anchor) 241 { 242 _anchor = anchor; 243 } 244 245 }

This page was automatically generated by Maven