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.ChangeBoundsRequest;
|
16
|
import org.eclipse.gef.requests.CreateRequest;
|
17
|
import org.eclipse.gef.requests.GroupRequest;
|
18
|
|
19
|
/**
|
20
|
* An EditPolicy for use with container editparts. This policy can be used to
|
21
|
* contribute commands to add, create, and orphan requests.
|
22
|
*
|
23
|
* @author hudsonr
|
24
|
*/
|
25
|
public abstract class ContainerEditPolicy extends AbstractEditPolicy {
|
26
|
|
27
|
/**
|
28
|
* Override to contribute to add requests.
|
29
|
*
|
30
|
* @param request
|
31
|
* the add request
|
32
|
* @return the command contribution to the add
|
33
|
*/
|
34
|
protected Command getAddCommand(GroupRequest request) {
|
35
|
return null;
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Override to contribute to clone requests.
|
40
|
*
|
41
|
* @param request
|
42
|
* the clone request
|
43
|
* @return the command contribution to the clone
|
44
|
*/
|
45
|
protected Command getCloneCommand(ChangeBoundsRequest request) {
|
46
|
return null;
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Overridden to check for add, create, and orphan.
|
51
|
*
|
52
|
* @see org.eclipse.gef.EditPolicy#getCommand(org.eclipse.gef.Request)
|
53
|
*/
|
54
|
public Command getCommand(Request request) {
|
55
|
if (REQ_CREATE.equals(request.getType()))
|
56
|
return getCreateCommand((CreateRequest) request);
|
57
|
if (REQ_ADD.equals(request.getType()))
|
58
|
return getAddCommand((GroupRequest) request);
|
59
|
if (REQ_CLONE.equals(request.getType()))
|
60
|
return getCloneCommand((ChangeBoundsRequest) request);
|
61
|
if (REQ_ORPHAN_CHILDREN.equals(request.getType()))
|
62
|
return getOrphanChildrenCommand((GroupRequest) request);
|
63
|
return null;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Clients must implement to contribute to create requests.
|
68
|
*
|
69
|
* @param request
|
70
|
* the create request
|
71
|
* @return <code>null</code> or a command contribution
|
72
|
*/
|
73
|
protected abstract Command getCreateCommand(CreateRequest request);
|
74
|
|
75
|
/**
|
76
|
* Override to contribute to orphan requests.
|
77
|
*
|
78
|
* @param request
|
79
|
* the orphan request
|
80
|
* @return a command contribution for the orphan
|
81
|
*/
|
82
|
protected Command getOrphanChildrenCommand(GroupRequest request) {
|
83
|
return null;
|
84
|
}
|
85
|
|
86
|
}
|