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.gef.Request;
|
14
|
import org.eclipse.gef.commands.Command;
|
15
|
import org.eclipse.gef.requests.GroupRequest;
|
16
|
|
17
|
/**
|
18
|
* A model-based EditPolicy for <i>components within a </i>container</i>. A
|
19
|
* model-based EditPolicy only knows about the host's model and the basic
|
20
|
* operations it supports. A <i>component</i> is anything that is inside a
|
21
|
* container. By default, ComponentEditPolicy understands being DELETEd from its
|
22
|
* container, and being ORPHANed from its container. Subclasses can add support
|
23
|
* to handle additional behavior specific to the model.
|
24
|
* <P>
|
25
|
* ORPHAN is forwarded to the <i>parent</i> EditPart for it to handle.
|
26
|
* <P>
|
27
|
* DELETE is also forwarded to the <i>parent</i> EditPart, but subclasses may
|
28
|
* also contribute to the delete by overriding
|
29
|
* {@link #createDeleteCommand(GroupRequest)}.
|
30
|
* <P>
|
31
|
* This EditPolicy is not a
|
32
|
* {@link org.eclipse.gef.editpolicies.GraphicalEditPolicy}, and should not be
|
33
|
* used to show feedback or interact with the host's visuals in any way.
|
34
|
* <P>
|
35
|
* This EditPolicy should not be used with
|
36
|
* {@link org.eclipse.gef.ConnectionEditPart}. Connections do not really have a
|
37
|
* parent; use {@link ConnectionEditPolicy}.
|
38
|
*
|
39
|
* @since 2.0
|
40
|
*/
|
41
|
public abstract class ComponentEditPolicy extends AbstractEditPolicy {
|
42
|
|
43
|
/**
|
44
|
* Override to contribute to the component's being deleted.
|
45
|
*
|
46
|
* @param deleteRequest
|
47
|
* the DeleteRequest
|
48
|
* @return Command <code>null</code> or a contribution to the delete
|
49
|
*/
|
50
|
protected Command createDeleteCommand(GroupRequest deleteRequest) {
|
51
|
return null;
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Factors the incoming Request into ORPHANs and DELETEs.
|
56
|
*
|
57
|
* @see org.eclipse.gef.EditPolicy#getCommand(Request)
|
58
|
*/
|
59
|
public Command getCommand(Request request) {
|
60
|
if (REQ_ORPHAN.equals(request.getType()))
|
61
|
return getOrphanCommand();
|
62
|
if (REQ_DELETE.equals(request.getType()))
|
63
|
return getDeleteCommand((GroupRequest) request);
|
64
|
return null;
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Calls and returns {@link #createDeleteCommand(GroupRequest)}. This method
|
69
|
* is here for historical reasons and used to perform additional function.
|
70
|
*
|
71
|
* @param request
|
72
|
* the DeleteRequest
|
73
|
* @return a delete command
|
74
|
*/
|
75
|
protected Command getDeleteCommand(GroupRequest request) {
|
76
|
return createDeleteCommand(request);
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Returns the command contribution for orphaning this component from its
|
81
|
* container. By default, ORPHAN is redispatched to the host's parent as an
|
82
|
* ORPHAN_CHILDREN Request. The parents contribution is then returned.
|
83
|
*
|
84
|
* @return the contribution obtained from the host's parent.
|
85
|
*/
|
86
|
protected Command getOrphanCommand() {
|
87
|
GroupRequest req = new GroupRequest(REQ_ORPHAN_CHILDREN);
|
88
|
req.setEditParts(getHost());
|
89
|
return getHost().getParent().getCommand(req);
|
90
|
}
|
91
|
|
92
|
}
|