25
|
1 package de.mpg.mpiwg.itgroup.digilib.digiImage.properties;
|
|
2
|
|
3 import java.util.HashMap;
|
|
4 import java.util.Map;
|
|
5
|
|
6 import org.eclipse.jface.viewers.ISelection;
|
|
7 import org.eclipse.jface.viewers.IStructuredSelection;
|
|
8 import org.eclipse.swt.SWT;
|
|
9 import org.eclipse.swt.custom.CLabel;
|
|
10 import org.eclipse.swt.events.ModifyListener;
|
|
11 import org.eclipse.swt.layout.FormAttachment;
|
|
12 import org.eclipse.swt.layout.FormData;
|
|
13 import org.eclipse.swt.layout.GridLayout;
|
|
14 import org.eclipse.swt.widgets.Button;
|
|
15 import org.eclipse.swt.widgets.Composite;
|
|
16 import org.eclipse.swt.widgets.Text;
|
|
17 import org.eclipse.ui.IWorkbenchPart;
|
|
18 import org.eclipse.ui.views.properties.IPropertySource;
|
|
19 import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
|
|
20 import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
|
|
21 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
|
|
22
|
|
23 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImage;
|
|
24 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageParameter;
|
|
25
|
26
|
26 /**
|
|
27 * @author dwinter
|
|
28 * Shows the properties of a digiImage
|
|
29 *
|
|
30 */
|
25
|
31 public class DigiImagePropertySection extends AbstractPropertySection {
|
|
32
|
|
33 private DigiImage digiImage;
|
|
34 private Map<String,Text> texts = new HashMap<String,Text>();
|
|
35
|
|
36
|
|
37 private Map<String,ModifyListener> listeners = new HashMap<String,ModifyListener>();
|
|
38 private Button button;
|
|
39
|
26
|
40
|
25
|
41
|
26
|
42 /* (non-Javadoc)
|
|
43 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
|
|
44 */
|
25
|
45 public void createControls(Composite parent,
|
|
46 TabbedPropertySheetPage aTabbedPropertySheetPage) {
|
|
47 super.createControls(parent, aTabbedPropertySheetPage);
|
|
48
|
|
49 DigiImageParameter dp = new DigiImageParameter("");
|
|
50 GridLayout gridLayout = new GridLayout(1,false);
|
|
51 parent.setLayout(gridLayout);
|
|
52 for (String key: dp.createMapFromParameters(null).keySet()){
|
|
53
|
|
54 Composite composite = getWidgetFactory()
|
|
55 .createFlatFormComposite(parent);
|
|
56 FormData data;
|
|
57
|
|
58 Text t = getWidgetFactory().createText(composite, "");
|
|
59 texts.put(key, t);
|
|
60 data = new FormData();
|
|
61 data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
|
|
62 data.right = new FormAttachment(100, 0);
|
|
63 data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
|
|
64 t.setLayoutData(data);
|
|
65
|
|
66
|
|
67 CLabel labelLabel = getWidgetFactory()
|
|
68 .createCLabel(composite, key); //$NON-NLS-1$
|
|
69 data = new FormData();
|
|
70 data.left = new FormAttachment(0, 0);
|
|
71 data.right = new FormAttachment(t,
|
|
72 -ITabbedPropertyConstants.HSPACE);
|
|
73 data.top = new FormAttachment(t, 0, SWT.CENTER);
|
|
74 labelLabel.setLayoutData(data);
|
|
75 }
|
|
76 Composite composite = getWidgetFactory()
|
|
77 .createFlatFormComposite(parent);
|
|
78 button = getWidgetFactory().createButton(composite, "redraw", SWT.None);
|
|
79
|
|
80 }
|
|
81
|
26
|
82 /* (non-Javadoc)
|
|
83 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#setInput(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
|
|
84 */
|
25
|
85 public void setInput(IWorkbenchPart part, ISelection selection) {
|
|
86 super.setInput(part, selection);
|
|
87
|
26
|
88 //Assert.isTrue(selection instanceof IStructuredSelection);
|
|
89 assert (IStructuredSelection.class.isInstance(selection)==true) : "wrong instance type";
|
|
90
|
25
|
91 Object input = ((IStructuredSelection) selection).getFirstElement();
|
26
|
92 //Assert.isTrue(input instanceof DigiImage);
|
|
93
|
|
94 assert (DigiImage.class.isInstance(input)==true) : "wrong instance type for input";
|
25
|
95 this.digiImage = (DigiImage) input;
|
|
96
|
26
|
97 //Map<String, String> pms = digiImage.getParameter().createMapFromParameters(null);
|
25
|
98
|
|
99 for(String key: digiImage.getParameter().createMapFromParameters(null).keySet()){
|
|
100
|
|
101
|
26
|
102 ModifyListener listener = new DigiImagePropertyListener(key,digiImage);
|
25
|
103
|
|
104 texts.get(key).addModifyListener(listener);
|
|
105 listeners.put(key, listener);
|
|
106 }
|
|
107 button.addMouseListener(new RedrawButtonListener(digiImage,texts));
|
|
108
|
|
109 }
|
|
110
|
26
|
111 /* (non-Javadoc)
|
|
112 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh()
|
|
113 */
|
25
|
114 public void refresh() {
|
|
115
|
|
116 DigiImageProperties properties = (DigiImageProperties) digiImage
|
|
117 .getAdapter(IPropertySource.class);
|
|
118
|
|
119 for(String key: texts.keySet()){
|
|
120
|
|
121 Text labelText=texts.get(key);
|
|
122 labelText.removeModifyListener(listeners.get(key));
|
|
123
|
|
124 labelText.setText((String)properties.getPropertyValue(key));
|
|
125 labelText.addModifyListener(listeners.get(key));
|
|
126
|
|
127 }
|
|
128 super.refresh();
|
|
129 }
|
|
130
|
26
|
131
|
25
|
132 }
|