38 |
38 |
import org.eclipse.jface.viewers.Viewer;
|
39 |
39 |
import org.eclipse.jface.viewers.ViewerCell;
|
40 |
40 |
import org.eclipse.swt.SWT;
|
|
41 |
import org.eclipse.swt.events.MouseEvent;
|
|
42 |
import org.eclipse.swt.events.MouseListener;
|
|
43 |
import org.eclipse.swt.events.SelectionEvent;
|
|
44 |
import org.eclipse.swt.events.SelectionListener;
|
41 |
45 |
import org.eclipse.swt.graphics.Color;
|
|
46 |
import org.eclipse.swt.graphics.Point;
|
42 |
47 |
import org.eclipse.swt.layout.FormData;
|
|
48 |
import org.eclipse.swt.layout.FormLayout;
|
43 |
49 |
import org.eclipse.swt.layout.GridData;
|
44 |
50 |
import org.eclipse.swt.layout.GridLayout;
|
|
51 |
import org.eclipse.swt.layout.RowLayout;
|
45 |
52 |
import org.eclipse.swt.widgets.Button;
|
46 |
53 |
import org.eclipse.swt.widgets.Composite;
|
47 |
54 |
import org.eclipse.swt.widgets.Control;
|
48 |
55 |
import org.eclipse.swt.widgets.Label;
|
49 |
56 |
import org.eclipse.swt.widgets.Layout;
|
|
57 |
import org.eclipse.swt.widgets.Spinner;
|
50 |
58 |
import org.eclipse.swt.widgets.ToolBar;
|
51 |
59 |
import org.eclipse.ui.IPartListener;
|
52 |
60 |
import org.eclipse.ui.IPartService;
|
... | ... | |
70 |
78 |
* Display area.
|
71 |
79 |
*/
|
72 |
80 |
protected TreeViewer treeViewer;
|
|
81 |
private TreeViewerColumn layoutDataColumn;
|
|
82 |
private TreeViewerColumn layoutColumn;
|
|
83 |
private TreeViewerColumn nameColumn;
|
|
84 |
protected Point mousePosition;
|
73 |
85 |
|
74 |
86 |
/**
|
75 |
87 |
* Instantiates a new queries view.
|
... | ... | |
89 |
101 |
public void createPartControl(Composite parent) {
|
90 |
102 |
treeViewer = new TreeViewer (parent, SWT.NONE);
|
91 |
103 |
treeViewer.setContentProvider(new ITreeContentProvider() {
|
92 |
|
|
|
104 |
|
93 |
105 |
@Override
|
94 |
106 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { }
|
95 |
|
|
|
107 |
|
96 |
108 |
@Override
|
97 |
109 |
public void dispose() { }
|
98 |
|
|
|
110 |
|
99 |
111 |
@Override
|
100 |
112 |
public boolean hasChildren(Object element) {
|
101 |
113 |
if (element instanceof Composite) {
|
... | ... | |
105 |
117 |
}
|
106 |
118 |
return false;
|
107 |
119 |
}
|
108 |
|
|
|
120 |
|
109 |
121 |
@Override
|
110 |
122 |
public Object getParent(Object element) {
|
111 |
123 |
if (element instanceof Composite) {
|
... | ... | |
115 |
127 |
}
|
116 |
128 |
return null;
|
117 |
129 |
}
|
118 |
|
|
|
130 |
|
119 |
131 |
@SuppressWarnings("rawtypes")
|
120 |
132 |
@Override
|
121 |
133 |
public Object[] getElements(Object inputElement) {
|
122 |
134 |
if (inputElement == null) return new Object[0];
|
123 |
|
|
|
135 |
|
124 |
136 |
if (inputElement instanceof TXMEditor) {
|
125 |
137 |
Object[] o = new Object[1];
|
126 |
138 |
o[0] = ((TXMEditor)inputElement).getContainer();
|
... | ... | |
128 |
140 |
}
|
129 |
141 |
return null;
|
130 |
142 |
}
|
131 |
|
|
|
143 |
|
132 |
144 |
@Override
|
133 |
145 |
public Object[] getChildren(Object element) {
|
134 |
146 |
if (element instanceof Composite) {
|
... | ... | |
141 |
153 |
return new Object[0];
|
142 |
154 |
}
|
143 |
155 |
});
|
144 |
|
|
145 |
|
|
146 |
|
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
|
147 |
|
|
148 |
|
@Override
|
149 |
|
public void doubleClick(DoubleClickEvent event) {
|
150 |
|
Object o = ((StructuredSelection)event.getSelection()).getFirstElement();
|
151 |
|
if (o != null && o instanceof Control) {
|
152 |
|
Control w = (Control) o;
|
153 |
|
Color b = w.getDisplay().getSystemColor(SWT.COLOR_BLUE);
|
154 |
|
|
155 |
|
if (isHighlighted(w)) {
|
156 |
|
w.setBackground(null);
|
157 |
|
} else {
|
158 |
|
w.setBackground(b);
|
159 |
|
}
|
160 |
|
}
|
161 |
|
treeViewer.refresh();
|
162 |
|
}
|
163 |
|
});
|
164 |
|
|
|
156 |
|
165 |
157 |
treeViewer.getTree().setHeaderVisible(true);
|
166 |
158 |
treeViewer.getTree().setLinesVisible(true);
|
167 |
|
|
168 |
|
TreeViewerColumn nameColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
|
|
159 |
|
|
160 |
nameColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
|
169 |
161 |
nameColumn.getColumn().setText("Element");
|
170 |
162 |
nameColumn.getColumn().pack();
|
171 |
163 |
nameColumn.setLabelProvider(new CellLabelProvider() {
|
172 |
164 |
@Override
|
173 |
165 |
public void update(ViewerCell cell) {
|
174 |
166 |
Object element = cell.getElement();
|
175 |
|
|
|
167 |
|
176 |
168 |
if (element instanceof GLComposite) {
|
177 |
169 |
GLComposite c = (GLComposite)element;
|
178 |
170 |
String s = c.getName();
|
... | ... | |
184 |
176 |
} else if(element instanceof Label) {
|
185 |
177 |
Label c = (Label) element;
|
186 |
178 |
cell.setText(c.getClass().getSimpleName()+" '"+c.getText()+"'");
|
|
179 |
} else if(element instanceof Spinner) {
|
|
180 |
Spinner c = (Spinner) element;
|
|
181 |
cell.setText(c.getClass().getSimpleName()+" '"+c.getSelection()+"'\n\tmin="+c.getMinimum()+" max="+c.getMaximum());
|
187 |
182 |
} else {
|
188 |
183 |
cell.setText(element.getClass().getSimpleName());
|
189 |
184 |
}
|
190 |
185 |
}
|
191 |
186 |
});
|
192 |
|
|
193 |
|
TreeViewerColumn layoutColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
|
|
187 |
|
|
188 |
treeViewer.getTree().addMouseListener(new MouseListener() {
|
|
189 |
|
|
190 |
@Override
|
|
191 |
public void mouseUp(MouseEvent e) {}
|
|
192 |
|
|
193 |
@Override
|
|
194 |
public void mouseDown(MouseEvent e) {
|
|
195 |
mousePosition = new Point(e.x, e.y);
|
|
196 |
}
|
|
197 |
|
|
198 |
@Override
|
|
199 |
public void mouseDoubleClick(MouseEvent e) {}
|
|
200 |
});
|
|
201 |
|
|
202 |
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
|
|
203 |
|
|
204 |
@Override
|
|
205 |
public void doubleClick(DoubleClickEvent event) {
|
|
206 |
|
|
207 |
|
|
208 |
Object o = ((StructuredSelection)event.getSelection()).getFirstElement();
|
|
209 |
|
|
210 |
int col = getPointedColumn();
|
|
211 |
|
|
212 |
if (col == 0) {
|
|
213 |
if (o != null && o instanceof Control) {
|
|
214 |
Control w = (Control) o;
|
|
215 |
Color b = w.getDisplay().getSystemColor(SWT.COLOR_BLUE);
|
|
216 |
if (isHighlighted(w)) {
|
|
217 |
w.setBackground(null);
|
|
218 |
} else {
|
|
219 |
w.setBackground(b);
|
|
220 |
}
|
|
221 |
treeViewer.refresh();
|
|
222 |
}
|
|
223 |
} else if (col == 1) { // open layout editor
|
|
224 |
if (o != null && o instanceof Composite) {
|
|
225 |
Composite w = (Composite) o;
|
|
226 |
Layout l = w.getLayout();
|
|
227 |
if (l instanceof GridLayout) {
|
|
228 |
|
|
229 |
} else if (l instanceof RowLayout) {
|
|
230 |
|
|
231 |
} else if (l instanceof FormLayout) {
|
|
232 |
|
|
233 |
}
|
|
234 |
}
|
|
235 |
} else { // open layout data editor
|
|
236 |
if (o != null && o instanceof Control) {
|
|
237 |
Control w = (Control) o;
|
|
238 |
Object ld = w.getLayoutData();
|
|
239 |
if (ld instanceof GridLayout) {
|
|
240 |
|
|
241 |
} else if (ld instanceof RowLayout) {
|
|
242 |
|
|
243 |
} else if (ld instanceof FormLayout) {
|
|
244 |
|
|
245 |
}
|
|
246 |
}
|
|
247 |
}
|
|
248 |
}
|
|
249 |
});
|
|
250 |
|
|
251 |
layoutColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
|
194 |
252 |
layoutColumn.getColumn().setText("Layout");
|
195 |
253 |
layoutColumn.getColumn().pack();
|
196 |
254 |
layoutColumn.setLabelProvider(new CellLabelProvider() {
|
197 |
255 |
@Override
|
198 |
256 |
public void update(ViewerCell cell) {
|
199 |
257 |
Object element = cell.getElement();
|
200 |
|
|
|
258 |
|
201 |
259 |
if (element instanceof Composite) {
|
202 |
260 |
String s = getLayoutDetails(((Composite)element).getLayout());
|
203 |
261 |
cell.setText(s);
|
... | ... | |
206 |
264 |
}
|
207 |
265 |
}
|
208 |
266 |
});
|
209 |
|
|
210 |
|
TreeViewerColumn layoutDataColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
|
|
267 |
|
|
268 |
layoutDataColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
|
211 |
269 |
layoutDataColumn.getColumn().setText("L-data");
|
212 |
270 |
layoutDataColumn.getColumn().pack();
|
213 |
271 |
layoutDataColumn.setLabelProvider(new CellLabelProvider() {
|
214 |
272 |
@Override
|
215 |
273 |
public void update(ViewerCell cell) {
|
216 |
274 |
Object element = cell.getElement();
|
217 |
|
|
|
275 |
|
218 |
276 |
if (element instanceof Control) {
|
219 |
277 |
String s = getLayoutDataDetails(((Control)element).getLayoutData());
|
220 |
278 |
cell.setText(s);
|
... | ... | |
223 |
281 |
}
|
224 |
282 |
}
|
225 |
283 |
});
|
226 |
|
|
|
284 |
|
227 |
285 |
}
|
228 |
286 |
protected String getLayoutDataDetails(Object layoutData) {
|
229 |
287 |
if (layoutData == null) return "no layout data";
|
230 |
|
|
|
288 |
|
231 |
289 |
if (layoutData instanceof GridData) {
|
232 |
290 |
GridData data = (GridData)layoutData;
|
233 |
291 |
return "GD: "+data.heightHint+" "+data.widthHint
|
... | ... | |
242 |
300 |
return layoutData.toString();
|
243 |
301 |
}
|
244 |
302 |
|
|
303 |
public int getPointedColumn() {
|
|
304 |
Point p = mousePosition;
|
|
305 |
if (p == null) return 0;
|
|
306 |
|
|
307 |
int x = p.x; // + lineTableViewer.getTable().get;
|
|
308 |
int sumWidthColumn = 0;
|
|
309 |
|
|
310 |
sumWidthColumn += this.nameColumn.getColumn().getWidth();
|
|
311 |
if (x < sumWidthColumn)
|
|
312 |
return 0;
|
|
313 |
|
|
314 |
sumWidthColumn += this.layoutColumn.getColumn().getWidth();
|
|
315 |
if (x < sumWidthColumn)
|
|
316 |
return 1;
|
|
317 |
|
|
318 |
return 2;
|
|
319 |
}
|
|
320 |
|
245 |
321 |
public static String getLayoutDetails(Layout layout) {
|
246 |
322 |
if (layout == null) return "no layout";
|
247 |
|
|
|
323 |
|
248 |
324 |
if (layout instanceof GridLayout) {
|
249 |
325 |
GridLayout gl = (GridLayout)layout;
|
250 |
326 |
return "GL: "+gl.horizontalSpacing+" "+gl.verticalSpacing+" "+gl.marginHeight+" "+gl.marginWidth
|
251 |
327 |
+"\n "+gl.marginBottom+" "+gl.marginLeft+" "+gl.marginRight+" "+gl.marginTop
|
252 |
328 |
+"\n "+gl.numColumns+" "+gl.makeColumnsEqualWidth;
|
253 |
|
|
|
329 |
|
254 |
330 |
} else {
|
255 |
331 |
return layout.toString();
|
256 |
332 |
}
|
... | ... | |
276 |
352 |
if (c == null) return false;
|
277 |
353 |
Color b = c.getDisplay().getSystemColor(SWT.COLOR_BLUE);
|
278 |
354 |
Color current = c.getBackground();
|
279 |
|
|
|
355 |
|
280 |
356 |
return current != null
|
281 |
357 |
&& current.getGreen() == b.getGreen()
|
282 |
358 |
&& current.getBlue() == b.getBlue()
|
283 |
359 |
&& current.getRed() == b.getRed();
|
284 |
360 |
}
|
285 |
|
|
|
361 |
|
286 |
362 |
@Override
|
287 |
363 |
public void propertyChanged(Object source, int propId) { }
|
288 |
364 |
|