Added
Link Here
|
1 |
/* |
2 |
* Copyright (c) 2006 Borland Software 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 |
* Borland Software Corporation - initial API and implementation |
10 |
*/ |
11 |
package org.eclipse.gmf.graphdef.editor.sheet; |
12 |
|
13 |
public abstract class AbstractCustomPropertySection extends org.eclipse.gmf.runtime.diagram.ui.properties.sections.AbstractModelerPropertySection { |
14 |
|
15 |
public abstract java.util.Collection getSavedSelection(); |
16 |
public abstract org.eclipse.jface.resource.ImageRegistry getImageRegistry(); |
17 |
|
18 |
private static final String KIND_KEY = "kind"; //$NON-NLS-1$ |
19 |
|
20 |
private static final int FILL = 101; |
21 |
|
22 |
private static final int OUTLINE = 102; |
23 |
|
24 |
private static final int XOR_FILL = 103; |
25 |
|
26 |
private static final int XOR_OUTLINE = 104; |
27 |
|
28 |
private static final int CORNER_WIDTH = 201; |
29 |
|
30 |
private static final int CORNER_HEIGHT = 202; |
31 |
|
32 |
private static final int LINE_WIDTH = 203; |
33 |
|
34 |
private LineWidthListener myListener; |
35 |
|
36 |
private org.eclipse.swt.widgets.Group myLineStyleGroup; |
37 |
|
38 |
private org.eclipse.swt.widgets.Group myLineWidthGroup; |
39 |
|
40 |
private org.eclipse.swt.widgets.Group myFillOutlineGroup; |
41 |
|
42 |
private org.eclipse.swt.widgets.Group myCornerGroup; |
43 |
|
44 |
private org.eclipse.swt.widgets.Spinner myLineWidthSpinner; |
45 |
|
46 |
private org.eclipse.swt.widgets.Button myLineStyle_Solid; |
47 |
|
48 |
private org.eclipse.swt.widgets.Button myLineStyle_Dash; |
49 |
|
50 |
private org.eclipse.swt.widgets.Button myLineStyle_Dot; |
51 |
|
52 |
private org.eclipse.swt.widgets.Button myLineStyle_DashDot; |
53 |
|
54 |
private org.eclipse.swt.widgets.Button myLineStyle_DashDotDot; |
55 |
|
56 |
private org.eclipse.swt.widgets.Button myLineStyle_Custom; |
57 |
|
58 |
private org.eclipse.swt.widgets.Button myFillCheckbox; |
59 |
|
60 |
private org.eclipse.swt.widgets.Button myOutlineCheckbox; |
61 |
|
62 |
private org.eclipse.swt.widgets.Button myXorFillCheckbox; |
63 |
|
64 |
private org.eclipse.swt.widgets.Button myXorOutlineCheckbox; |
65 |
|
66 |
private org.eclipse.swt.widgets.Spinner myCornerWidthSpinner; |
67 |
|
68 |
private org.eclipse.swt.widgets.Spinner myCornerHeightSpinner; |
69 |
|
70 |
private org.eclipse.swt.widgets.Composite mySectionComposite; |
71 |
|
72 |
protected org.eclipse.emf.ecore.EObject getEObject() { |
73 |
if (getSavedSelection() != null && !getSavedSelection().isEmpty()) { |
74 |
return (org.eclipse.emf.ecore.EObject) getSavedSelection().iterator().next(); |
75 |
} |
76 |
return super.getEObject(); |
77 |
} |
78 |
|
79 |
public void createControls(org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage tabbedPropertySheetPage) { |
80 |
super.createControls(parent, tabbedPropertySheetPage); |
81 |
mySectionComposite = getWidgetFactory().createFlatFormComposite(parent); |
82 |
|
83 |
myLineStyleGroup = createLineStyleGroup(mySectionComposite, getLineStyleLabel()); |
84 |
myLineStyle_Solid = createLineStyleRadio(myLineStyleGroup, null, false, getImageRegistry().get(org.eclipse.gmf.gmfgraph.LineKind.LINE_SOLID_LITERAL.getLiteral()), org.eclipse.swt.SWT.LINE_SOLID); |
85 |
myLineStyle_Dash = createLineStyleRadio(myLineStyleGroup, myLineStyle_Solid, false, getImageRegistry().get(org.eclipse.gmf.gmfgraph.LineKind.LINE_DASH_LITERAL.getLiteral()), org.eclipse.swt.SWT.LINE_DASH); |
86 |
myLineStyle_Dot = createLineStyleRadio(myLineStyleGroup, myLineStyle_Dash, false, getImageRegistry().get(org.eclipse.gmf.gmfgraph.LineKind.LINE_DOT_LITERAL.getLiteral()), org.eclipse.swt.SWT.LINE_DOT); |
87 |
myLineStyle_DashDot = createLineStyleRadio(myLineStyleGroup, myLineStyle_Dot, false, getImageRegistry().get(org.eclipse.gmf.gmfgraph.LineKind.LINE_DASHDOT_LITERAL.getLiteral()), org.eclipse.swt.SWT.LINE_DASHDOT); |
88 |
myLineStyle_DashDotDot = createLineStyleRadio(myLineStyleGroup, myLineStyle_DashDot, false, getImageRegistry().get(org.eclipse.gmf.gmfgraph.LineKind.LINE_DASHDOTDOT_LITERAL.getLiteral()), org.eclipse.swt.SWT.LINE_DASHDOTDOT); |
89 |
myLineStyle_Custom = createLineStyleRadio(myLineStyleGroup, myLineStyle_DashDotDot, true, getImageRegistry().get(org.eclipse.gmf.gmfgraph.LineKind.LINE_CUSTOM_LITERAL.getLiteral()), org.eclipse.swt.SWT.LINE_CUSTOM); |
90 |
|
91 |
myLineWidthGroup = createLineWidthGroup(mySectionComposite, getLineWidthLabel()); |
92 |
//org.eclipse.swt.custom.CLabel lineWidthLabel = createLabelWidget(myLineWidthGroup, getLineWidthLabel(), null); |
93 |
myLineWidthSpinner = createSpinnerWidget(myLineWidthGroup, null, LINE_WIDTH); |
94 |
|
95 |
myFillOutlineGroup = createFillOutlineGroup(mySectionComposite, getFillOutlineLabel()); |
96 |
myFillCheckbox = createCheckbox(myFillOutlineGroup, getFillPropertyNameLabel(), null, null, FILL); |
97 |
myOutlineCheckbox = createCheckbox(myFillOutlineGroup, getOutlinePropertyNameLabel(), myFillCheckbox, null, OUTLINE); |
98 |
myXorFillCheckbox = createCheckbox(myFillOutlineGroup, getXorFillPropertyNameLabel(), null, myFillCheckbox, XOR_FILL); |
99 |
myXorOutlineCheckbox = createCheckbox(myFillOutlineGroup, getXorOutlinePropertyNameLabel(), myXorFillCheckbox, myOutlineCheckbox, XOR_OUTLINE); |
100 |
|
101 |
myCornerGroup = createCornerGroup(mySectionComposite, getCornerDimensionsLabel()); |
102 |
org.eclipse.swt.custom.CLabel cornerWidthLabel = createLabelWidget(myCornerGroup, getCornerWidthLabel(), null); |
103 |
myCornerWidthSpinner = createSpinnerWidget(myCornerGroup, cornerWidthLabel, CORNER_WIDTH); |
104 |
org.eclipse.swt.custom.CLabel cornerHeigthLabel = createLabelWidget(myCornerGroup, getCornerHeightLabel(), myCornerWidthSpinner); |
105 |
myCornerHeightSpinner = createSpinnerWidget(myCornerGroup, cornerHeigthLabel, CORNER_HEIGHT); |
106 |
|
107 |
getListener().startListeningTo(myLineWidthSpinner); |
108 |
getListener().startListeningTo(myLineStyle_Solid); |
109 |
getListener().startListeningTo(myLineStyle_Dash); |
110 |
getListener().startListeningTo(myLineStyle_Dot); |
111 |
getListener().startListeningTo(myLineStyle_DashDot); |
112 |
getListener().startListeningTo(myLineStyle_DashDotDot); |
113 |
getListener().startListeningTo(myLineStyle_Custom); |
114 |
getListener().startListeningTo(myFillCheckbox); |
115 |
getListener().startListeningTo(myOutlineCheckbox); |
116 |
getListener().startListeningTo(myXorFillCheckbox); |
117 |
getListener().startListeningTo(myXorOutlineCheckbox); |
118 |
getListener().startListeningTo(myCornerWidthSpinner); |
119 |
getListener().startListeningTo(myCornerHeightSpinner); |
120 |
} |
121 |
|
122 |
public void dispose() { |
123 |
getListener().stopListeningTo(myLineWidthSpinner); |
124 |
getListener().stopListeningTo(myLineStyle_Solid); |
125 |
getListener().stopListeningTo(myLineStyle_Dash); |
126 |
getListener().stopListeningTo(myLineStyle_Dot); |
127 |
getListener().stopListeningTo(myLineStyle_DashDot); |
128 |
getListener().stopListeningTo(myLineStyle_DashDotDot); |
129 |
getListener().stopListeningTo(myLineStyle_Custom); |
130 |
getListener().stopListeningTo(myFillCheckbox); |
131 |
getListener().stopListeningTo(myOutlineCheckbox); |
132 |
getListener().stopListeningTo(myXorFillCheckbox); |
133 |
getListener().stopListeningTo(myXorOutlineCheckbox); |
134 |
getListener().stopListeningTo(myCornerWidthSpinner); |
135 |
getListener().stopListeningTo(myCornerHeightSpinner); |
136 |
super.dispose(); |
137 |
} |
138 |
|
139 |
protected org.eclipse.swt.widgets.Button createLineStyleRadio(org.eclipse.swt.widgets.Composite parent, org.eclipse.swt.widgets.Control topControl, boolean last, org.eclipse.swt.graphics.Image image, int kind) { |
140 |
org.eclipse.swt.widgets.Button radio = getWidgetFactory().createButton(parent, "", org.eclipse.swt.SWT.RADIO); |
141 |
radio.setImage(image); |
142 |
radio.setData(KIND_KEY, new Integer(kind)); |
143 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
144 |
if (topControl == null) { |
145 |
data.top = new org.eclipse.swt.layout.FormAttachment(0); |
146 |
} else { |
147 |
data.top = new org.eclipse.swt.layout.FormAttachment(topControl, 5); |
148 |
} |
149 |
data.left = new org.eclipse.swt.layout.FormAttachment(0); |
150 |
if (last) { |
151 |
data.bottom = new org.eclipse.swt.layout.FormAttachment(100); |
152 |
} |
153 |
radio.setLayoutData(data); |
154 |
return radio; |
155 |
} |
156 |
|
157 |
protected org.eclipse.swt.widgets.Group createLineWidthGroup(org.eclipse.swt.widgets.Composite parent, String label) { |
158 |
org.eclipse.swt.widgets.Group group = getWidgetFactory().createGroup(parent, label); |
159 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
160 |
data.top = new org.eclipse.swt.layout.FormAttachment(0, 0); |
161 |
data.left = new org.eclipse.swt.layout.FormAttachment(myLineStyleGroup); |
162 |
group.setLayoutData(data); |
163 |
group.setLayout(createStandardFormLayout()); |
164 |
return group; |
165 |
} |
166 |
|
167 |
protected org.eclipse.swt.widgets.Group createLineStyleGroup(org.eclipse.swt.widgets.Composite parent, String label) { |
168 |
org.eclipse.swt.widgets.Group group = getWidgetFactory().createGroup(parent, label); |
169 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
170 |
data.top = new org.eclipse.swt.layout.FormAttachment(0, 0); |
171 |
data.left = new org.eclipse.swt.layout.FormAttachment(0); |
172 |
group.setLayoutData(data); |
173 |
group.setLayout(createStandardFormLayout()); |
174 |
return group; |
175 |
} |
176 |
|
177 |
protected org.eclipse.swt.widgets.Group createFillOutlineGroup(org.eclipse.swt.widgets.Composite parent, String label) { |
178 |
org.eclipse.swt.widgets.Group group = getWidgetFactory().createGroup(parent, label); |
179 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
180 |
data.top = new org.eclipse.swt.layout.FormAttachment(myLineWidthGroup); |
181 |
data.left = new org.eclipse.swt.layout.FormAttachment(myLineStyleGroup); |
182 |
group.setLayoutData(data); |
183 |
group.setLayout(createStandardFormLayout()); |
184 |
return group; |
185 |
} |
186 |
|
187 |
protected org.eclipse.swt.widgets.Group createCornerGroup(org.eclipse.swt.widgets.Composite parent, String label) { |
188 |
org.eclipse.swt.widgets.Group group = getWidgetFactory().createGroup(parent, label); |
189 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
190 |
data.top = new org.eclipse.swt.layout.FormAttachment(myFillOutlineGroup); |
191 |
data.left = new org.eclipse.swt.layout.FormAttachment(myLineStyleGroup); |
192 |
data.bottom = new org.eclipse.swt.layout.FormAttachment(100); |
193 |
group.setLayoutData(data); |
194 |
group.setLayout(createStandardFormLayout()); |
195 |
return group; |
196 |
} |
197 |
|
198 |
protected org.eclipse.swt.widgets.Layout createStandardFormLayout() { |
199 |
org.eclipse.swt.layout.FormLayout layout = new org.eclipse.swt.layout.FormLayout(); |
200 |
layout.marginWidth = org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants.HSPACE + 2; |
201 |
layout.marginHeight = org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants.VSPACE; |
202 |
layout.spacing = org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants.VMARGIN + 1; |
203 |
return layout; |
204 |
} |
205 |
|
206 |
protected org.eclipse.swt.widgets.Button createCheckbox(org.eclipse.swt.widgets.Group parent, String label, org.eclipse.swt.widgets.Control topControl, org.eclipse.swt.widgets.Control leftControl, int kind) { |
207 |
org.eclipse.swt.widgets.Button checkbox = getWidgetFactory().createButton(parent, label, org.eclipse.swt.SWT.CHECK); |
208 |
checkbox.setData(KIND_KEY, new Integer(kind)); |
209 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
210 |
if (topControl == null) { |
211 |
data.top = new org.eclipse.swt.layout.FormAttachment(0); |
212 |
} else { |
213 |
data.top = new org.eclipse.swt.layout.FormAttachment(topControl); |
214 |
} |
215 |
if (leftControl == null) { |
216 |
data.left = new org.eclipse.swt.layout.FormAttachment(0); |
217 |
} else { |
218 |
data.right = new org.eclipse.swt.layout.FormAttachment(100, -org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants.HSPACE); |
219 |
data.left = new org.eclipse.swt.layout.FormAttachment(50); |
220 |
} |
221 |
checkbox.setLayoutData(data); |
222 |
return checkbox; |
223 |
} |
224 |
|
225 |
private String getCornerDimensionsLabel() { |
226 |
return "Corner Dimensions"; |
227 |
} |
228 |
|
229 |
private String getCornerWidthLabel() { |
230 |
return "Corner Width"; |
231 |
} |
232 |
|
233 |
private String getCornerHeightLabel() { |
234 |
return "Corner Height"; |
235 |
} |
236 |
|
237 |
private String getFillPropertyNameLabel() { |
238 |
return "Fill"; |
239 |
} |
240 |
|
241 |
private String getOutlinePropertyNameLabel() { |
242 |
return "Outline"; |
243 |
} |
244 |
|
245 |
private String getXorFillPropertyNameLabel() { |
246 |
return "XOR Fill"; |
247 |
} |
248 |
|
249 |
private String getXorOutlinePropertyNameLabel() { |
250 |
return "XOR Outline"; |
251 |
} |
252 |
|
253 |
private String getFillOutlineLabel() { |
254 |
return "Mix Styles"; |
255 |
} |
256 |
|
257 |
private String getLineStyleLabel() { |
258 |
return "Line Style"; |
259 |
} |
260 |
|
261 |
private String getLineWidthLabel() { |
262 |
return "Line Width"; |
263 |
} |
264 |
|
265 |
protected void setLineWidth(final int lineWidth) { |
266 |
modifyModel(new RunnableWithShape() { |
267 |
|
268 |
public void run() { |
269 |
getShape().setLineWidth(lineWidth); |
270 |
} |
271 |
}, "Setting line width"); |
272 |
} |
273 |
|
274 |
protected void setLineKind(final int lineKind) { |
275 |
modifyModel(new RunnableWithShape() { |
276 |
|
277 |
public void run() { |
278 |
getShape().setLineKind(org.eclipse.gmf.gmfgraph.LineKind.get(lineKind)); |
279 |
} |
280 |
}, "Setting line style"); |
281 |
} |
282 |
|
283 |
protected void setFill(final boolean value) { |
284 |
modifyModel(new RunnableWithShape() { |
285 |
|
286 |
public void run() { |
287 |
getShape().setFill(value); |
288 |
} |
289 |
}, "Setting shape fill"); |
290 |
} |
291 |
|
292 |
protected void setOutline(final boolean value) { |
293 |
modifyModel(new RunnableWithShape() { |
294 |
|
295 |
public void run() { |
296 |
getShape().setOutline(value); |
297 |
} |
298 |
}, "Setting shape outline"); |
299 |
} |
300 |
|
301 |
protected void setXorFill(final boolean value) { |
302 |
modifyModel(new RunnableWithShape() { |
303 |
|
304 |
public void run() { |
305 |
getShape().setXorFill(value); |
306 |
} |
307 |
}, "Setting shape XOR fill"); |
308 |
} |
309 |
|
310 |
protected void setXorOutline(final boolean value) { |
311 |
modifyModel(new RunnableWithShape() { |
312 |
|
313 |
public void run() { |
314 |
getShape().setXorOutline(value); |
315 |
} |
316 |
}, "Setting shape XOR outline"); |
317 |
} |
318 |
|
319 |
protected void setCornerWidth(final int cornerWidth) { |
320 |
modifyModel(new RunnableWithShape() { |
321 |
|
322 |
public void run() { |
323 |
((org.eclipse.gmf.gmfgraph.RoundedRectangle) getShape()).setCornerWidth(cornerWidth); |
324 |
} |
325 |
}, "Setting corner width"); |
326 |
} |
327 |
|
328 |
protected void setCornerHeight(final int cornerHeight) { |
329 |
modifyModel(new RunnableWithShape() { |
330 |
|
331 |
public void run() { |
332 |
((org.eclipse.gmf.gmfgraph.RoundedRectangle) getShape()).setCornerHeight(cornerHeight); |
333 |
} |
334 |
}, "Setting corner height"); |
335 |
} |
336 |
|
337 |
public static abstract class RunnableWithShape implements Runnable { |
338 |
|
339 |
private org.eclipse.gmf.gmfgraph.Shape myShape; |
340 |
|
341 |
public org.eclipse.gmf.gmfgraph.Shape getShape() { |
342 |
return myShape; |
343 |
} |
344 |
|
345 |
public void setTargetShape(org.eclipse.gmf.gmfgraph.Shape shape) { |
346 |
myShape = shape; |
347 |
} |
348 |
} |
349 |
|
350 |
protected void modifyModel(RunnableWithShape runnable, String commandName) { |
351 |
java.util.ArrayList commands = new java.util.ArrayList(); |
352 |
for (java.util.Iterator it = getSavedSelection().iterator(); it.hasNext();) { |
353 |
final org.eclipse.emf.ecore.EObject next = (org.eclipse.emf.ecore.EObject) it.next(); |
354 |
if (next instanceof org.eclipse.gmf.gmfgraph.Shape) { |
355 |
final org.eclipse.gmf.gmfgraph.Shape shape = (org.eclipse.gmf.gmfgraph.Shape) next; |
356 |
runnable.setTargetShape(shape); |
357 |
commands.add(createCommand(commandName, next, runnable)); |
358 |
} |
359 |
} |
360 |
executeAsCompositeCommand(commandName, commands); |
361 |
refresh(); |
362 |
} |
363 |
|
364 |
private LineWidthListener getListener() { |
365 |
if (myListener == null) { |
366 |
myListener = new LineWidthListener(); |
367 |
} |
368 |
return myListener; |
369 |
} |
370 |
|
371 |
private class LineWidthListener implements org.eclipse.swt.events.ModifyListener, org.eclipse.swt.events.SelectionListener { |
372 |
|
373 |
private boolean nonUserChange; |
374 |
|
375 |
public boolean isNonUserChange() { |
376 |
return nonUserChange; |
377 |
} |
378 |
|
379 |
private void applyChangesFrom(org.eclipse.swt.widgets.Widget widget) { |
380 |
if (!isNonUserChange()) { |
381 |
if (widget instanceof org.eclipse.swt.widgets.Spinner) { |
382 |
Integer kind = (Integer) widget.getData(KIND_KEY); |
383 |
int value = ((org.eclipse.swt.widgets.Spinner) widget).getSelection(); |
384 |
switch (kind.intValue()) { |
385 |
case CORNER_WIDTH: { |
386 |
setCornerWidth(value); |
387 |
break; |
388 |
} |
389 |
case CORNER_HEIGHT: { |
390 |
setCornerHeight(value); |
391 |
break; |
392 |
} |
393 |
case LINE_WIDTH: { |
394 |
setLineWidth(value); |
395 |
break; |
396 |
} |
397 |
} |
398 |
} else if (widget instanceof org.eclipse.swt.widgets.Button) { |
399 |
boolean turnedOn = ((org.eclipse.swt.widgets.Button) widget).getSelection(); |
400 |
Integer kind = (Integer) widget.getData(KIND_KEY); |
401 |
switch (kind.intValue()) { |
402 |
case org.eclipse.swt.SWT.LINE_SOLID: |
403 |
case org.eclipse.swt.SWT.LINE_DASH: |
404 |
case org.eclipse.swt.SWT.LINE_DOT: |
405 |
case org.eclipse.swt.SWT.LINE_DASHDOT: |
406 |
case org.eclipse.swt.SWT.LINE_DASHDOTDOT: |
407 |
case org.eclipse.swt.SWT.LINE_CUSTOM: { |
408 |
setLineKind(kind.intValue()); |
409 |
break; |
410 |
} |
411 |
case FILL: { |
412 |
setFill(turnedOn); |
413 |
break; |
414 |
} |
415 |
case OUTLINE: { |
416 |
setOutline(turnedOn); |
417 |
break; |
418 |
} |
419 |
case XOR_FILL: { |
420 |
setXorFill(turnedOn); |
421 |
break; |
422 |
} |
423 |
case XOR_OUTLINE: { |
424 |
setXorOutline(turnedOn); |
425 |
break; |
426 |
} |
427 |
} |
428 |
} |
429 |
} |
430 |
} |
431 |
|
432 |
public void modifyText(org.eclipse.swt.events.ModifyEvent e) { |
433 |
applyChangesFrom(e.widget); |
434 |
} |
435 |
|
436 |
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { |
437 |
widgetSelected(e); |
438 |
} |
439 |
|
440 |
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { |
441 |
applyChangesFrom(e.widget); |
442 |
} |
443 |
|
444 |
public void startListeningTo(org.eclipse.swt.widgets.Spinner spinner) { |
445 |
spinner.addModifyListener(this); |
446 |
spinner.addSelectionListener(this); |
447 |
} |
448 |
|
449 |
public void stopListeningTo(org.eclipse.swt.widgets.Spinner spinner) { |
450 |
spinner.removeModifyListener(this); |
451 |
spinner.removeSelectionListener(this); |
452 |
} |
453 |
|
454 |
public void startListeningTo(org.eclipse.swt.widgets.Button button) { |
455 |
button.addSelectionListener(this); |
456 |
} |
457 |
|
458 |
public void stopListeningTo(org.eclipse.swt.widgets.Button button) { |
459 |
button.removeSelectionListener(this); |
460 |
} |
461 |
|
462 |
public void startNonUserChange() { |
463 |
nonUserChange = true; |
464 |
} |
465 |
|
466 |
public void finishNonUserChange() { |
467 |
nonUserChange = false; |
468 |
} |
469 |
} |
470 |
|
471 |
protected org.eclipse.swt.custom.CLabel createLabelWidget(org.eclipse.swt.widgets.Composite parent, String labelText, org.eclipse.swt.widgets.Control leftWidget) { |
472 |
org.eclipse.swt.custom.CLabel label = getWidgetFactory().createCLabel(parent, labelText); |
473 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
474 |
data.top = new org.eclipse.swt.layout.FormAttachment(0); |
475 |
if (leftWidget != null) { |
476 |
data.left = new org.eclipse.swt.layout.FormAttachment(leftWidget); |
477 |
} else { |
478 |
data.left = new org.eclipse.swt.layout.FormAttachment(0); |
479 |
} |
480 |
label.setLayoutData(data); |
481 |
return label; |
482 |
} |
483 |
|
484 |
protected org.eclipse.swt.widgets.Spinner createSpinnerWidget(org.eclipse.swt.widgets.Composite parent, org.eclipse.swt.widgets.Control leftWidget, int kind) { |
485 |
org.eclipse.swt.widgets.Spinner spinner = new org.eclipse.swt.widgets.Spinner(parent, org.eclipse.swt.SWT.BORDER); |
486 |
spinner.setMinimum(1); |
487 |
spinner.setMaximum(999); |
488 |
spinner.setSelection(100); |
489 |
spinner.setIncrement(1); |
490 |
spinner.setPageIncrement(100); |
491 |
spinner.setBackground(parent.getBackground()); |
492 |
spinner.setForeground(parent.getForeground()); |
493 |
spinner.setData(KIND_KEY, kind); |
494 |
org.eclipse.swt.layout.FormData data = new org.eclipse.swt.layout.FormData(); |
495 |
if (leftWidget != null) { |
496 |
data.left = new org.eclipse.swt.layout.FormAttachment(leftWidget); |
497 |
} else { |
498 |
data.left = new org.eclipse.swt.layout.FormAttachment(0); |
499 |
} |
500 |
data.top = new org.eclipse.swt.layout.FormAttachment(0); |
501 |
spinner.setLayoutData(data); |
502 |
return spinner; |
503 |
} |
504 |
|
505 |
private int getLineKind(Object object) { |
506 |
if (object instanceof org.eclipse.gmf.gmfgraph.Shape) { |
507 |
org.eclipse.gmf.gmfgraph.Shape shape = (org.eclipse.gmf.gmfgraph.Shape) object; |
508 |
return shape.getLineKind().getValue(); |
509 |
} |
510 |
return -1; |
511 |
} |
512 |
|
513 |
private int getLineWidth(Object object) { |
514 |
if (object instanceof org.eclipse.gmf.gmfgraph.Shape) { |
515 |
org.eclipse.gmf.gmfgraph.Shape shape = (org.eclipse.gmf.gmfgraph.Shape) object; |
516 |
return shape.getLineWidth(); |
517 |
} |
518 |
return -1; |
519 |
} |
520 |
|
521 |
private boolean getFill(Object object) { |
522 |
if (object instanceof org.eclipse.gmf.gmfgraph.Shape) { |
523 |
org.eclipse.gmf.gmfgraph.Shape shape = (org.eclipse.gmf.gmfgraph.Shape) object; |
524 |
return shape.isFill(); |
525 |
} |
526 |
return false; |
527 |
} |
528 |
|
529 |
private boolean getOutline(Object object) { |
530 |
if (object instanceof org.eclipse.gmf.gmfgraph.Shape) { |
531 |
org.eclipse.gmf.gmfgraph.Shape shape = (org.eclipse.gmf.gmfgraph.Shape) object; |
532 |
return shape.isOutline(); |
533 |
} |
534 |
return false; |
535 |
} |
536 |
|
537 |
private boolean getXorFill(Object object) { |
538 |
if (object instanceof org.eclipse.gmf.gmfgraph.Shape) { |
539 |
org.eclipse.gmf.gmfgraph.Shape shape = (org.eclipse.gmf.gmfgraph.Shape) object; |
540 |
return shape.isXorFill(); |
541 |
} |
542 |
return false; |
543 |
} |
544 |
|
545 |
private boolean getXorOutline(Object object) { |
546 |
if (object instanceof org.eclipse.gmf.gmfgraph.Shape) { |
547 |
org.eclipse.gmf.gmfgraph.Shape shape = (org.eclipse.gmf.gmfgraph.Shape) object; |
548 |
return shape.isXorOutline(); |
549 |
} |
550 |
return false; |
551 |
} |
552 |
|
553 |
private int getCornerWidth(Object object) { |
554 |
if (object instanceof org.eclipse.gmf.gmfgraph.RoundedRectangle) { |
555 |
org.eclipse.gmf.gmfgraph.RoundedRectangle cornered = (org.eclipse.gmf.gmfgraph.RoundedRectangle) object; |
556 |
return cornered.getCornerWidth(); |
557 |
} |
558 |
return -1; |
559 |
} |
560 |
|
561 |
private int getCornerHeight(Object object) { |
562 |
if (object instanceof org.eclipse.gmf.gmfgraph.RoundedRectangle) { |
563 |
org.eclipse.gmf.gmfgraph.RoundedRectangle cornered = (org.eclipse.gmf.gmfgraph.RoundedRectangle) object; |
564 |
return cornered.getCornerHeight(); |
565 |
} |
566 |
return -1; |
567 |
} |
568 |
|
569 |
public void refresh() { |
570 |
getListener().startNonUserChange(); |
571 |
try { |
572 |
for (java.util.Iterator it = getSavedSelection().iterator(); it.hasNext();) { |
573 |
final Object next = it.next(); |
574 |
mySectionComposite.setVisible(next instanceof org.eclipse.gmf.gmfgraph.Shape); |
575 |
if (!mySectionComposite.isVisible()) { |
576 |
return; |
577 |
} |
578 |
executeAsReadAction(new Runnable() { |
579 |
|
580 |
public void run() { |
581 |
int lineWidth = getLineWidth(next); |
582 |
if (lineWidth != -1) { |
583 |
myLineWidthSpinner.setSelection(lineWidth); |
584 |
} |
585 |
int lineKind = getLineKind(next); |
586 |
myLineStyle_Solid.setSelection(lineKind == org.eclipse.swt.SWT.LINE_SOLID); |
587 |
myLineStyle_Dash.setSelection(lineKind == org.eclipse.swt.SWT.LINE_DASH); |
588 |
myLineStyle_Dot.setSelection(lineKind == org.eclipse.swt.SWT.LINE_DOT); |
589 |
myLineStyle_DashDot.setSelection(lineKind == org.eclipse.swt.SWT.LINE_DASHDOT); |
590 |
myLineStyle_DashDotDot.setSelection(lineKind == org.eclipse.swt.SWT.LINE_DASHDOTDOT); |
591 |
myLineStyle_Custom.setSelection(lineKind == org.eclipse.swt.SWT.LINE_CUSTOM); |
592 |
myFillCheckbox.setSelection(getFill(next)); |
593 |
myOutlineCheckbox.setSelection(getOutline(next)); |
594 |
myXorFillCheckbox.setSelection(getXorFill(next)); |
595 |
myXorOutlineCheckbox.setSelection(getXorOutline(next)); |
596 |
myCornerGroup.setVisible(next instanceof org.eclipse.gmf.gmfgraph.RoundedRectangle); |
597 |
if (myCornerGroup.isVisible()) { |
598 |
int cornerWidth = getCornerWidth(next); |
599 |
if (cornerWidth != -1) { |
600 |
myCornerWidthSpinner.setSelection(cornerWidth); |
601 |
} |
602 |
int cornerHeight = getCornerHeight(next); |
603 |
if (cornerHeight != -1) { |
604 |
myCornerHeightSpinner.setSelection(cornerHeight); |
605 |
} |
606 |
} |
607 |
} |
608 |
}); |
609 |
} |
610 |
} finally { |
611 |
getListener().finishNonUserChange(); |
612 |
} |
613 |
} |
614 |
|
615 |
private org.eclipse.swt.widgets.Button getLineKindButton(int lineKind) { |
616 |
switch (lineKind) { |
617 |
case org.eclipse.swt.SWT.LINE_SOLID: |
618 |
return myLineStyle_Solid; |
619 |
case org.eclipse.swt.SWT.LINE_DOT: |
620 |
return myLineStyle_Dot; |
621 |
case org.eclipse.swt.SWT.LINE_DASH: |
622 |
return myLineStyle_Dash; |
623 |
case org.eclipse.swt.SWT.LINE_DASHDOT: |
624 |
return myLineStyle_DashDot; |
625 |
case org.eclipse.swt.SWT.LINE_DASHDOTDOT: |
626 |
return myLineStyle_DashDotDot; |
627 |
case org.eclipse.swt.SWT.LINE_CUSTOM: |
628 |
return myLineStyle_Custom; |
629 |
default: |
630 |
return null; |
631 |
} |
632 |
} |
633 |
} |