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;
|
12
|
|
13
|
import org.eclipse.gef.commands.Command;
|
14
|
|
15
|
/**
|
16
|
* A pluggable contribution implementing a portion of an EditPart's behavior.
|
17
|
* EditPolicies contribute to the overall <i>editing behavior</i> of an
|
18
|
* EditPart. Editing behavior is defined as one or more of the following:
|
19
|
* <ul>
|
20
|
* <li><b>Command Creation </b>- Returning a <code>Command</code> in response to
|
21
|
* {@link #getCommand(Request)}
|
22
|
* <li><b>Feedback Management</b> - Showing/erasing source and/or target
|
23
|
* feedback in response to Requests.
|
24
|
* <li><b>Delegation/Forwarding</b> - Collecting contributions from other
|
25
|
* EditParts (and therefore their EditPolicies). In response to a given
|
26
|
* <code>Request</code>, an EditPolicy may create a derived Request and forward
|
27
|
* it to other EditParts. For example, during the deletion of a composite
|
28
|
* EditPart, that composite may consult its children for contributions to the
|
29
|
* delete command. Then, if the children have any additional work to do, they
|
30
|
* will return additional comands to be executed.
|
31
|
* </ul>
|
32
|
* <P>
|
33
|
* EditPolicies should determine an EditPart's editing capabilities. It is
|
34
|
* possible to implement an EditPart such that it handles all editing
|
35
|
* responsibility. However, it is much more flexible and object-oriented to use
|
36
|
* EditPolicies. Using policies, you can pick and choose the editing behavior
|
37
|
* for an EditPart without being bound to its class hierarchy. Code reuse is
|
38
|
* increased, and code management is easier.
|
39
|
* <p>
|
40
|
* IMPORTANT: This interface is <EM>not</EM> intended to be implemented by
|
41
|
* clients. Clients should inherit from
|
42
|
* {@link org.eclipse.gef.editpolicies.AbstractEditPolicy}. New methods may be
|
43
|
* added in the future.
|
44
|
*/
|
45
|
|
46
|
public interface EditPolicy {
|
47
|
|
48
|
/**
|
49
|
* The key used to install a <i>component</i> EditPolicy. A <i>component</i>
|
50
|
* is defined as anything in the model. This EditPolicy should handle the
|
51
|
* fundamental operations that do not fit under any other EditPolicy role.
|
52
|
* For example, delete is a fundamental operation. Generally the component
|
53
|
* EditPolicy knows only about the model, and can be used in any type of
|
54
|
* EditPartViewer.
|
55
|
*/
|
56
|
String COMPONENT_ROLE = "ComponentEditPolicy"; //$NON-NLS-1$
|
57
|
|
58
|
/**
|
59
|
* The key used to install a <i>connection endpoint</i> EditPolicy. A
|
60
|
* <i>connection endpoint</i> EditPolicy is usually a
|
61
|
* {@link org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy} subclass.
|
62
|
* Besides rendering selection by displaying <code>Handle</code>s at then
|
63
|
* ends of the connection, the EditPolicy also understands how to move the
|
64
|
* endpoints of the connection. If the endpoints are moveable, the
|
65
|
* EditPolicy will show feedback and provide <code>Commands</code> to
|
66
|
* perform the move.
|
67
|
*/
|
68
|
String CONNECTION_ENDPOINTS_ROLE = "Connection Endpoint Policy"; //$NON-NLS-1$
|
69
|
|
70
|
/**
|
71
|
* The key used to install a <i>bendpoint</i> EditPolicy. A <i>bendpoint</i>
|
72
|
* EditPolicy is an optional EditPolicy for connections that are visibile.
|
73
|
* As with {@link #CONNECTION_ENDPOINTS_ROLE endpoints}, bendpoint
|
74
|
* EditPolicies are porbably
|
75
|
* {@link org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy}.
|
76
|
*/
|
77
|
String CONNECTION_BENDPOINTS_ROLE = "Connection Bendpoint Policy"; //$NON-NLS-1$
|
78
|
|
79
|
/**
|
80
|
* The key used to install a <i>connection</i> EditPolicy. The behavior of a
|
81
|
* <code>ConnectionEditPart</code> may be implemented in its
|
82
|
* <i>component</i> EditPolicy,
|
83
|
*/
|
84
|
String CONNECTION_ROLE = "ConnectionEditPolicy"; //$NON-NLS-1$
|
85
|
|
86
|
/**
|
87
|
* The key used to install a <i>container</i> EditPolicy.
|
88
|
*/
|
89
|
String CONTAINER_ROLE = "ContainerEditPolicy"; //$NON-NLS-1$
|
90
|
|
91
|
/**
|
92
|
* The key used to install a <i>direct edit</i> EditPolicy.
|
93
|
*/
|
94
|
String DIRECT_EDIT_ROLE = "DirectEditPolicy"; //$NON-NLS-1$
|
95
|
|
96
|
/**
|
97
|
* The key used to install a <i>graphical node</i> EditPolicy.
|
98
|
*/
|
99
|
String GRAPHICAL_NODE_ROLE = "GraphicalNodeEditPolicy"; //$NON-NLS-1$
|
100
|
|
101
|
/**
|
102
|
* The key used to install a <i>layout</i> EditPolicy.
|
103
|
*/
|
104
|
String LAYOUT_ROLE = "LayoutEditPolicy"; //$NON-NLS-1$
|
105
|
|
106
|
/**
|
107
|
* The key used to install a <i>node</i> EditPolicy.
|
108
|
*/
|
109
|
String NODE_ROLE = "NodeEditPolicy"; //$NON-NLS-1$
|
110
|
|
111
|
/**
|
112
|
* The key used to install a <i>primary drag</i> EditPolicy.
|
113
|
*/
|
114
|
String PRIMARY_DRAG_ROLE = "PrimaryDrag Policy"; //$NON-NLS-1$
|
115
|
|
116
|
/**
|
117
|
* The key used to install a <i>selection feedback</i> EditPolicy.
|
118
|
*/
|
119
|
String SELECTION_FEEDBACK_ROLE = "Selection Feedback"; //$NON-NLS-1$
|
120
|
|
121
|
/**
|
122
|
* The key used to install a <i>tree container</i> EditPolicy.
|
123
|
*/
|
124
|
String TREE_CONTAINER_ROLE = "TreeContainerEditPolicy"; //$NON-NLS-1$
|
125
|
|
126
|
/**
|
127
|
* Activates this EditPolicy. The EditPolicy might need to hook listeners.
|
128
|
* These listeners should be unhooked in <code>deactivate()</code>. The
|
129
|
* EditPolicy might also contribute feedback/visuals immediately, such as
|
130
|
* <i>selection handles</i> if the EditPart was selected at the time of
|
131
|
* activation.
|
132
|
* <P>
|
133
|
* Activate is called after the <i>host</i> has been set, and that host has
|
134
|
* been activated.
|
135
|
*
|
136
|
* @see EditPart#activate()
|
137
|
* @see #deactivate()
|
138
|
* @see EditPart#installEditPolicy(Object, EditPolicy)
|
139
|
*/
|
140
|
void activate();
|
141
|
|
142
|
/**
|
143
|
* Deactivates the EditPolicy, the inverse of {@link #activate()}.
|
144
|
* Deactivate is called when the <i>host</i> is deactivated, or when the
|
145
|
* EditPolicy is uninstalled from an active host. Deactivate unhooks any
|
146
|
* listeners, and removes all feedback.
|
147
|
*
|
148
|
* @see EditPart#deactivate()
|
149
|
* @see #activate()
|
150
|
* @see EditPart#removeEditPolicy(Object)
|
151
|
*/
|
152
|
void deactivate();
|
153
|
|
154
|
/**
|
155
|
* Erases source feedback based on the given <code>Request</code>. Does
|
156
|
* nothing if the EditPolicy does not apply to the given Request.
|
157
|
* <P>
|
158
|
* This method is declared on {@link EditPart#eraseSourceFeedback(Request)
|
159
|
* EditPart}, and is redeclared here so that EditPart can delegate its
|
160
|
* implementation to each of its EditPolicies.
|
161
|
*
|
162
|
* @param request
|
163
|
* the Request
|
164
|
*/
|
165
|
void eraseSourceFeedback(Request request);
|
166
|
|
167
|
/**
|
168
|
* Erases target feedback based on the given <code>Request</code>. Does
|
169
|
* nothing if the EditPolicy does not apply to the given Request.
|
170
|
* <P>
|
171
|
* This method is declared on {@link EditPart#eraseTargetFeedback(Request)
|
172
|
* EditPart}, and is redeclared here so that EditPart can delegate its
|
173
|
* implementation to each of its EditPolicies.
|
174
|
*
|
175
|
* @param request
|
176
|
* the Request
|
177
|
* */
|
178
|
void eraseTargetFeedback(Request request);
|
179
|
|
180
|
/**
|
181
|
* Returns the <code>Command</code> contribution for the given
|
182
|
* <code>Request</code>, or <code>null</code>. <code>null</code> is treated
|
183
|
* as a no-op by the caller, or an empty contribution. The EditPolicy must
|
184
|
* return an {@link org.eclipse.gef.commands.UnexecutableCommand} if it
|
185
|
* wishes to disallow the Request.
|
186
|
* <P>
|
187
|
* This method is declared on {@link EditPart#getCommand(Request) EditPart},
|
188
|
* and is redeclared here so that EditPart can delegate its implementation
|
189
|
* to each of its EditPolicies. The EditPart will combine each EditPolicy's
|
190
|
* contribution into a {@link org.eclipse.gef.commands.CompoundCommand}.
|
191
|
*
|
192
|
* @param request
|
193
|
* the Request
|
194
|
* @return <code>null</code> or a Command contribution
|
195
|
*/
|
196
|
Command getCommand(Request request);
|
197
|
|
198
|
/**
|
199
|
* @return the <i>host</i> EditPart on which this policy is installed.
|
200
|
*/
|
201
|
EditPart getHost();
|
202
|
|
203
|
/**
|
204
|
* Returns <code>null</code> or the appropriate <code>EditPart</code> for
|
205
|
* the specified <code>Request</code>. In general, this EditPolicy will
|
206
|
* return its <i>host</i> EditPart if it understands the Request. Otherwise,
|
207
|
* it will return <code>null</code>.
|
208
|
* <P>
|
209
|
* This method is declared on {@link EditPart#getTargetEditPart(Request)
|
210
|
* EditPart}, and is redeclared here so that EditPart can delegate its
|
211
|
* implementation to each of its EditPolicies. The first non-
|
212
|
* <code>null</code> result returned by an EditPolicy is returned by the
|
213
|
* EditPart.
|
214
|
*
|
215
|
* @param request
|
216
|
* the Request
|
217
|
* @return <code>null</code> or the appropriate target <code>EditPart</code>
|
218
|
*/
|
219
|
EditPart getTargetEditPart(Request request);
|
220
|
|
221
|
/**
|
222
|
* Sets the host in which this EditPolicy is installed.
|
223
|
*
|
224
|
* @param editpart
|
225
|
* the host EditPart
|
226
|
*/
|
227
|
void setHost(EditPart editpart);
|
228
|
|
229
|
/**
|
230
|
* Shows or updates <i>source feedback</i> for the specified
|
231
|
* <code>Request</code>. This method may be called repeatedly for the
|
232
|
* purpose of updating feedback based on changes to the Request.
|
233
|
* <P>
|
234
|
* Does nothing if the EditPolicy does not recognize the given Request.
|
235
|
* <P>
|
236
|
* This method is declared on {@link EditPart#showSourceFeedback(Request)
|
237
|
* EditPart}, and is redeclared here so that EditPart can delegate its
|
238
|
* implementation to each of its EditPolicies.
|
239
|
*
|
240
|
* @param request
|
241
|
* the Request
|
242
|
*/
|
243
|
void showSourceFeedback(Request request);
|
244
|
|
245
|
/**
|
246
|
* Shows or updates <i>target feedback</i> for the specified
|
247
|
* <code>Request</code>. This method may be called repeatedly for the
|
248
|
* purpose of updating feedback based on changes to the Request.
|
249
|
* <P>
|
250
|
* Does nothing if the EditPolicy does not recognize the given request.
|
251
|
* <P>
|
252
|
* This method is declared on {@link EditPart#showTargetFeedback(Request)
|
253
|
* EditPart}, and is redeclared here so that EditPart can delegate its
|
254
|
* implementation to each of its EditPolicies.
|
255
|
*
|
256
|
* @param request
|
257
|
* the Request
|
258
|
*/
|
259
|
void showTargetFeedback(Request request);
|
260
|
|
261
|
/**
|
262
|
* Returns <code>true</code> if this EditPolicy understand the specified
|
263
|
* request.
|
264
|
* <P>
|
265
|
* This method is declared on {@link EditPart#understandsRequest(Request)
|
266
|
* EditPart}, and is redeclared here so that EditPart can delegate its
|
267
|
* implementation to each of its EditPolicies. <code>EditPart</code> returns
|
268
|
* <code>true</code> if any of its EditPolicies returns <code>true</code>.
|
269
|
* In other words, it performs a logical OR.
|
270
|
*
|
271
|
* @param request
|
272
|
* the Request
|
273
|
* @return boolean <code>true</code> if the EditPolicy understands the
|
274
|
* specified request
|
275
|
* @see EditPart#understandsRequest(Request)
|
276
|
*/
|
277
|
boolean understandsRequest(Request request);
|
278
|
|
279
|
}
|