1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2005, 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
|
|
12
|
package org.eclipse.gef.editparts;
|
13
|
|
14
|
import org.eclipse.draw2d.Figure;
|
15
|
import org.eclipse.draw2d.IFigure;
|
16
|
import org.eclipse.draw2d.StackLayout;
|
17
|
|
18
|
import org.eclipse.gef.EditPart;
|
19
|
import org.eclipse.gef.EditPartViewer;
|
20
|
import org.eclipse.gef.Request;
|
21
|
import org.eclipse.gef.RootEditPart;
|
22
|
import org.eclipse.gef.commands.Command;
|
23
|
import org.eclipse.gef.commands.UnexecutableCommand;
|
24
|
|
25
|
/**
|
26
|
* Default implementation of RootEditPart for GraphicalViewers.
|
27
|
*
|
28
|
* @author Pratik Shah
|
29
|
* @since 3.2
|
30
|
*/
|
31
|
public class SimpleRootEditPart extends AbstractGraphicalEditPart implements
|
32
|
RootEditPart {
|
33
|
|
34
|
private EditPart contents;
|
35
|
private EditPartViewer viewer;
|
36
|
|
37
|
/**
|
38
|
* No editpolicies are installed on a RootEditPart by default.
|
39
|
*
|
40
|
* @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
|
41
|
*/
|
42
|
protected void createEditPolicies() {
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* The default root figure is a figure with a stack layout.
|
47
|
*
|
48
|
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
|
49
|
*/
|
50
|
protected IFigure createFigure() {
|
51
|
Figure figure = new Figure();
|
52
|
figure.setLayoutManager(new StackLayout());
|
53
|
return figure;
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* The RootEditPart should never be asked for a command. This implementation
|
58
|
* returns an unexecutable command.
|
59
|
*
|
60
|
* @see EditPart#getCommand(Request)
|
61
|
*/
|
62
|
public Command getCommand(Request req) {
|
63
|
return UnexecutableCommand.INSTANCE;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* @see RootEditPart#getContents()
|
68
|
*/
|
69
|
public EditPart getContents() {
|
70
|
return contents;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @see EditPart#getRoot()
|
75
|
*/
|
76
|
public RootEditPart getRoot() {
|
77
|
return this;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* @see EditPart#getViewer()
|
82
|
*/
|
83
|
public EditPartViewer getViewer() {
|
84
|
return viewer;
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Overridden to do nothing, child is set using setContents(EditPart)
|
89
|
*
|
90
|
* @see AbstractEditPart#refreshChildren()
|
91
|
*/
|
92
|
protected void refreshChildren() {
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* @see RootEditPart#setContents(EditPart)
|
97
|
*/
|
98
|
public void setContents(EditPart editpart) {
|
99
|
if (contents == editpart)
|
100
|
return;
|
101
|
if (contents != null)
|
102
|
removeChild(contents);
|
103
|
contents = editpart;
|
104
|
if (contents != null)
|
105
|
addChild(contents, 0);
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* @see RootEditPart#setViewer(EditPartViewer)
|
110
|
*/
|
111
|
public void setViewer(EditPartViewer newViewer) {
|
112
|
if (viewer == newViewer)
|
113
|
return;
|
114
|
if (viewer != null)
|
115
|
unregister();
|
116
|
viewer = newViewer;
|
117
|
if (viewer != null)
|
118
|
register();
|
119
|
}
|
120
|
|
121
|
}
|