1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2010 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.editpolicies;
|
12
|
|
13
|
import org.eclipse.draw2d.IFigure;
|
14
|
|
15
|
import org.eclipse.gef.GraphicalEditPart;
|
16
|
import org.eclipse.gef.LayerConstants;
|
17
|
import org.eclipse.gef.editparts.LayerManager;
|
18
|
|
19
|
/**
|
20
|
* A <code>GraphicalEditPolicy</code> is used with a {@link GraphicalEditPart}.
|
21
|
* All GraphicalEditPolicies are involved with the Figure in some way. They
|
22
|
* might use the Figure to interpret Requests, or they might simply decorate the
|
23
|
* Figure with graphical Feedback, such as selection handles.
|
24
|
* <P>
|
25
|
* This class provides convenience methods for accessing the host's Figure, and
|
26
|
* for adding <i>feedback</i> to the GraphicalViewer. This class does not handle
|
27
|
* any Request types directly.
|
28
|
*/
|
29
|
public abstract class GraphicalEditPolicy extends AbstractEditPolicy {
|
30
|
|
31
|
/**
|
32
|
* Adds the specified <code>Figure</code> to the
|
33
|
* {@link LayerConstants#FEEDBACK_LAYER}.
|
34
|
*
|
35
|
* @param figure
|
36
|
* the feedback to add
|
37
|
*/
|
38
|
protected void addFeedback(IFigure figure) {
|
39
|
getFeedbackLayer().add(figure);
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Returns the layer used for displaying feedback.
|
44
|
*
|
45
|
* @return the feedback layer
|
46
|
*/
|
47
|
protected IFigure getFeedbackLayer() {
|
48
|
return getLayer(LayerConstants.FEEDBACK_LAYER);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Convenience method to return the host's Figure.
|
53
|
*
|
54
|
* @return The host GraphicalEditPart's Figure
|
55
|
*/
|
56
|
protected IFigure getHostFigure() {
|
57
|
return ((GraphicalEditPart) getHost()).getFigure();
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Obtains the specified layer.
|
62
|
*
|
63
|
* @param layer
|
64
|
* the key identifying the layer
|
65
|
* @return the requested layer
|
66
|
*/
|
67
|
protected IFigure getLayer(Object layer) {
|
68
|
return LayerManager.Helper.find(getHost()).getLayer(layer);
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Removes the specified <code>Figure</code> from the
|
73
|
* {@link LayerConstants#FEEDBACK_LAYER}.
|
74
|
*
|
75
|
* @param figure
|
76
|
* the feedback to remove
|
77
|
*/
|
78
|
protected void removeFeedback(IFigure figure) {
|
79
|
getFeedbackLayer().remove(figure);
|
80
|
}
|
81
|
|
82
|
}
|