|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.gef.handles; |
| 12 |
|
| 13 |
import org.eclipse.core.runtime.Assert; |
| 14 |
|
| 15 |
import org.eclipse.draw2d.ConnectionLocator; |
| 16 |
|
| 17 |
import org.eclipse.gef.ConnectionEditPart; |
| 18 |
import org.eclipse.gef.DragTracker; |
| 19 |
import org.eclipse.gef.RequestConstants; |
| 20 |
import org.eclipse.gef.tools.ConnectionEndpointTracker; |
| 21 |
|
| 22 |
/** |
| 23 |
* A handle used at the start or end of the |
| 24 |
* {@link org.eclipse.draw2d.Connection}. A ConnectionEndpointHandle may be |
| 25 |
* extended rather than using the final {@link ConnectionStartHandle} or |
| 26 |
* {@link ConnectionEndHandle} |
| 27 |
* |
| 28 |
* @author Anthony Hunter |
| 29 |
* @since 3.4 |
| 30 |
*/ |
| 31 |
public class ConnectionEndpointHandle extends ConnectionHandle { |
| 32 |
|
| 33 |
/** |
| 34 |
* Caches whether the handle is for the source or target endpoint. endPoint |
| 35 |
* is either {@link ConnectionLocator#SOURCE} or |
| 36 |
* {@link ConnectionLocator#TARGET}. |
| 37 |
*/ |
| 38 |
private int endPoint; |
| 39 |
|
| 40 |
/** |
| 41 |
* Creates a new ConnectionStartHandle, sets its owner to <code>owner</code>, |
| 42 |
* and sets its locator to a {@link ConnectionLocator}. |
| 43 |
* |
| 44 |
* @param owner |
| 45 |
* the ConnectionEditPart owner |
| 46 |
* @param endPoint |
| 47 |
* one of {@link ConnectionLocator#SOURCE} or |
| 48 |
* {@link ConnectionLocator#TARGET}. |
| 49 |
*/ |
| 50 |
public ConnectionEndpointHandle(ConnectionEditPart owner, int endPoint) { |
| 51 |
setOwner(owner); |
| 52 |
Assert.isTrue(endPoint == ConnectionLocator.SOURCE |
| 53 |
|| endPoint == ConnectionLocator.TARGET); |
| 54 |
this.endPoint = endPoint; |
| 55 |
setLocator(new ConnectionLocator(getConnection(), endPoint)); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Creates a new ConnectionStartHandle and sets its owner to |
| 60 |
* <code>owner</code>. If the handle is fixed, it cannot be dragged. |
| 61 |
* |
| 62 |
* @param owner |
| 63 |
* the ConnectionEditPart owner |
| 64 |
* @param fixed |
| 65 |
* if true, handle cannot be dragged. |
| 66 |
* @param endPoint |
| 67 |
* one of {@link ConnectionLocator#SOURCE} or |
| 68 |
* {@link ConnectionLocator#TARGET}. |
| 69 |
*/ |
| 70 |
public ConnectionEndpointHandle(ConnectionEditPart owner, boolean fixed, |
| 71 |
int endPoint) { |
| 72 |
super(fixed); |
| 73 |
setOwner(owner); |
| 74 |
Assert.isTrue(endPoint == ConnectionLocator.SOURCE |
| 75 |
|| endPoint == ConnectionLocator.TARGET); |
| 76 |
this.endPoint = endPoint; |
| 77 |
setLocator(new ConnectionLocator(getConnection(), endPoint)); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Creates a new ConnectionStartHandle. |
| 82 |
* |
| 83 |
* @param endPoint |
| 84 |
* one of {@link ConnectionLocator#SOURCE} or |
| 85 |
* {@link ConnectionLocator#TARGET}. |
| 86 |
*/ |
| 87 |
public ConnectionEndpointHandle(int endPoint) { |
| 88 |
Assert.isTrue(endPoint == ConnectionLocator.SOURCE |
| 89 |
|| endPoint == ConnectionLocator.TARGET); |
| 90 |
this.endPoint = endPoint; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Creates and returns a new {@link ConnectionEndpointTracker}. |
| 95 |
* |
| 96 |
* @return the new ConnectionEndpointTracker |
| 97 |
*/ |
| 98 |
protected DragTracker createDragTracker() { |
| 99 |
if (isFixed()) |
| 100 |
return null; |
| 101 |
ConnectionEndpointTracker tracker; |
| 102 |
tracker = new ConnectionEndpointTracker((ConnectionEditPart) getOwner()); |
| 103 |
if (endPoint == ConnectionLocator.SOURCE) { |
| 104 |
tracker.setCommandName(RequestConstants.REQ_RECONNECT_SOURCE); |
| 105 |
} else { |
| 106 |
tracker.setCommandName(RequestConstants.REQ_RECONNECT_TARGET); |
| 107 |
} |
| 108 |
tracker.setDefaultCursor(getCursor()); |
| 109 |
return tracker; |
| 110 |
} |
| 111 |
|
| 112 |
} |