1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.ui.outline;
19
20 import org.eclipse.draw2d.Label;
21 import org.eclipse.draw2d.LightweightSystem;
22 import org.eclipse.draw2d.parts.ScrollableThumbnail;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Canvas;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.IEditorPart;
27 import org.eclipse.ui.IPartListener;
28 import org.eclipse.ui.IWorkbenchPart;
29
30 import pl.edu.agh.cast.editor.AbstractEditor;
31 import pl.edu.agh.cast.editor.input.DiagramEditorInput;
32 import pl.edu.agh.cast.ui.AbstractConfigurableView;
33 import pl.edu.agh.cast.util.Messages;
34
35
36
37
38
39
40 public class OutlineMiniatureView extends AbstractConfigurableView implements IPartListener {
41
42
43
44
45 public OutlineMiniatureView() {
46
47 }
48
49
50
51
52 public static final String ID = "pl.edu.agh.cast.view.miniature";
53
54 private LightweightSystem lightweightSystem;
55
56 private ScrollableThumbnail scrollableThumbnail;
57
58 private Object currentDiagram;
59
60
61
62
63
64
65 @Override
66 protected void activate() {
67 getSite().getPage().addPartListener(this);
68 }
69
70
71
72
73
74
75 @Override
76 public void dispose() {
77 super.dispose();
78 getSite().getPage().removePartListener(this);
79 }
80
81
82
83
84
85
86
87 public void partActivated(IWorkbenchPart part) {
88 updateActiveEditor();
89 }
90
91
92
93
94
95
96
97 public void partBroughtToTop(IWorkbenchPart part) {
98 updateActiveEditor();
99 }
100
101
102
103
104
105
106
107 public void partClosed(IWorkbenchPart part) {
108 updateActiveEditor();
109 }
110
111
112
113
114
115
116
117 public void partDeactivated(IWorkbenchPart part) {
118 updateActiveEditor();
119 }
120
121
122
123
124
125
126
127 public void partOpened(IWorkbenchPart part) {
128 updateActiveEditor();
129 }
130
131
132
133
134
135
136
137 @Override
138 protected void contributeToActionBars() {
139
140
141 }
142
143
144
145
146
147
148
149 @Override
150 protected void hookContextMenu() {
151
152
153 }
154
155
156
157
158
159
160
161 @Override
162 protected void hookDoubleClickAction() {
163
164
165 }
166
167
168
169
170
171
172
173 @Override
174 protected void makeActions() {
175
176
177 }
178
179
180
181
182
183
184
185 @Override
186 public void createPartControl(Composite parent) {
187 activate();
188
189 Canvas canvas = new Canvas(parent, SWT.BORDER);
190 this.lightweightSystem = new LightweightSystem(canvas);
191 }
192
193
194
195
196
197
198
199 @Override
200 public void setFocus() {
201
202
203 }
204
205
206
207
208 @SuppressWarnings("unchecked")
209 private void updateActiveEditor() {
210 IEditorPart activeEditor = getSite().getPage().getActiveEditor();
211 if (activeEditor instanceof AbstractEditor) {
212 AbstractEditor editor = (AbstractEditor)activeEditor;
213 DiagramEditorInput input = (DiagramEditorInput)editor.getEditorInput();
214 Object diagram = input.getDiagram();
215 if (!diagram.equals(currentDiagram)) {
216 currentDiagram = diagram;
217
218
219 scrollableThumbnail = new ScrollableThumbnail(editor.getEditorViewport());
220 scrollableThumbnail.setSource(editor.getPrintableLayer());
221 lightweightSystem.setContents(scrollableThumbnail);
222 }
223 } else {
224 currentDiagram = null;
225
226
227 lightweightSystem.setContents(new Label(Messages.OutlineMiniatureView_0));
228 }
229 }
230 }