Commit | Line | Data |
---|---|---|
4f3793c3 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | * | |
12 | *******************************************************************************/ | |
13 | package org.eclipse.linuxtools.lttng.ui.tracecontrol.wizards; | |
14 | ||
15 | import java.util.ArrayList; | |
16 | import java.util.List; | |
17 | ||
18 | import org.eclipse.jface.action.Action; | |
19 | import org.eclipse.jface.action.IMenuListener; | |
20 | import org.eclipse.jface.action.IMenuManager; | |
21 | import org.eclipse.jface.action.MenuManager; | |
22 | import org.eclipse.jface.dialogs.Dialog; | |
23 | import org.eclipse.jface.dialogs.IDialogConstants; | |
24 | import org.eclipse.jface.viewers.CellEditor; | |
25 | import org.eclipse.jface.viewers.CheckboxCellEditor; | |
26 | import org.eclipse.jface.viewers.TableViewer; | |
27 | import org.eclipse.jface.viewers.TextCellEditor; | |
28 | import org.eclipse.jface.viewers.Viewer; | |
29 | import org.eclipse.jface.viewers.ViewerComparator; | |
30 | import org.eclipse.jface.window.Window; | |
31 | import org.eclipse.jface.wizard.WizardPage; | |
5945cec9 FC |
32 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource.TraceState; |
33 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannel; | |
34 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannels; | |
4f3793c3 BH |
35 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; |
36 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages; | |
37 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.model.config.TraceChannelCellModifier; | |
38 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.model.config.TraceChannelTableContentProvider; | |
39 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.model.config.TraceChannelTableLabelProvider; | |
40 | import org.eclipse.swt.SWT; | |
41 | import org.eclipse.swt.events.SelectionAdapter; | |
42 | import org.eclipse.swt.events.SelectionEvent; | |
43 | import org.eclipse.swt.events.VerifyEvent; | |
44 | import org.eclipse.swt.events.VerifyListener; | |
45 | import org.eclipse.swt.layout.GridData; | |
46 | import org.eclipse.swt.layout.GridLayout; | |
47 | import org.eclipse.swt.widgets.Button; | |
48 | import org.eclipse.swt.widgets.Composite; | |
49 | import org.eclipse.swt.widgets.Control; | |
50 | import org.eclipse.swt.widgets.Display; | |
51 | import org.eclipse.swt.widgets.Event; | |
52 | import org.eclipse.swt.widgets.Label; | |
53 | import org.eclipse.swt.widgets.Listener; | |
54 | import org.eclipse.swt.widgets.Menu; | |
55 | import org.eclipse.swt.widgets.Shell; | |
56 | import org.eclipse.swt.widgets.Table; | |
57 | import org.eclipse.swt.widgets.TableColumn; | |
58 | import org.eclipse.swt.widgets.TableItem; | |
59 | import org.eclipse.swt.widgets.Text; | |
60 | ||
61 | /** | |
62 | * <b><u>KernelTraceChannelConfigurationPage</u></b> | |
63 | * <p> | |
64 | * Wizard page implementation to configure the kernel trace channels. | |
65 | * </p> | |
66 | */ | |
67 | public class KernelTraceChannelConfigurationPage extends WizardPage implements ITraceChannelConfigurationPage { | |
68 | ||
69 | // ------------------------------------------------------------------------ | |
70 | // Attributes | |
71 | // ------------------------------------------------------------------------ | |
c6f55e56 | 72 | |
4f3793c3 BH |
73 | private TraceChannels fChannels; |
74 | private TraceState fTraceState; | |
75 | private Composite container; | |
76 | private TableViewer tableViewer; | |
77 | List<String> fColumnNames; | |
78 | ||
79 | Action enableAllAction; | |
80 | Action disableAllAction; | |
81 | Action setOverrideAllAction; | |
82 | Action resetOverideAllAction; | |
83 | Action setNumSubbufAction; | |
84 | Action setSubbufSizeAction; | |
85 | Action setChanTimerAction; | |
86 | ||
87 | private ColumnData[] columnDataList = new ColumnData[] { | |
88 | new ColumnData(Messages.ChannelConfigPage_ChannelName, 150, SWT.LEFT, Messages.ChannelConfigPage_ChannelNameTooltip, new ViewerComparator() { | |
89 | @Override | |
90 | public int compare(Viewer viewer, Object e1, Object e2) { | |
91 | TraceChannel chan1 = (TraceChannel) e1; | |
92 | TraceChannel chan2 = (TraceChannel) e2; | |
93 | return chan1.getName().compareTo(chan2.getName()); | |
94 | } | |
95 | }), | |
96 | new ColumnData(Messages.ChannelConfigPage_ChannelEnabled, 150, SWT.LEFT, Messages.ChannelConfigPage_ChannelEnabledTooltip, null), | |
97 | new ColumnData(Messages.ChannelConfigPage_ChannelOverride, 150, SWT.LEFT, Messages.ChannelConfigPage_BufferOverrideTooltip, null), | |
98 | new ColumnData(Messages.ChannelConfigPage_NumSubBuf, 175, SWT.LEFT, Messages.ChannelConfigPage_NumSubBufTooltip, null), | |
99 | new ColumnData(Messages.ChannelConfigPage_SubBufSize, 150, SWT.LEFT, Messages.ChannelConfigPage_SubBufSizeTooltip, null), | |
100 | new ColumnData(Messages.ChannelConfigPage_ChannelTimer, 150, SWT.LEFT, Messages.ChannelConfigPage_ChannelTimerTooltip, null)}; | |
101 | ||
102 | ||
103 | // ------------------------------------------------------------------------ | |
104 | // Constructors | |
105 | // ------------------------------------------------------------------------ | |
106 | ||
107 | /** | |
108 | * Constructor | |
109 | * | |
110 | * @param channels The current channels information | |
111 | * @param state The trace state | |
112 | */ | |
113 | protected KernelTraceChannelConfigurationPage(TraceChannels channels, TraceState state) { | |
114 | super("TraceChannelConfigurationPage"); //$NON-NLS-1$ | |
115 | fChannels = channels; | |
116 | fTraceState = state; | |
117 | setTitle(Messages.ChannelConfigPage_PageTitle); | |
118 | } | |
119 | ||
120 | // ------------------------------------------------------------------------ | |
121 | // Operations | |
122 | // ------------------------------------------------------------------------ | |
123 | ||
124 | /* | |
125 | * (non-Javadoc) | |
126 | * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) | |
127 | */ | |
128 | @Override | |
129 | public void createControl(Composite parent) { | |
130 | container = new Composite(parent, SWT.NULL); | |
131 | container.setLayout(new GridLayout()); | |
132 | setControl(container); | |
133 | ||
134 | Composite headerComposite = new Composite(container, SWT.FILL); | |
135 | GridLayout headerLayout = new GridLayout(1, true); | |
136 | headerLayout.marginHeight = 0; | |
137 | headerLayout.marginWidth = 0; | |
138 | headerComposite.setLayout(headerLayout); | |
139 | headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
140 | ||
141 | tableViewer = new TableViewer(headerComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION ); | |
142 | tableViewer.setUseHashlookup(true); | |
143 | ||
144 | Table table = tableViewer.getTable(); | |
145 | table.setHeaderVisible(true); | |
146 | ||
147 | fColumnNames = new ArrayList<String>(); | |
148 | for (int i = 0; i < columnDataList.length; i++) { | |
149 | ||
150 | final ColumnData columnData = columnDataList[i]; | |
151 | fColumnNames.add(columnData.header); | |
152 | final TableColumn tableColumn = new TableColumn(table, SWT.LEFT); | |
153 | tableColumn.setText(columnData.header); | |
154 | tableColumn.setWidth(columnData.width); | |
155 | tableColumn.setAlignment(columnData.alignment); | |
156 | tableColumn.setToolTipText(columnData.tooltip); | |
157 | tableColumn.setMoveable(false); | |
158 | if (columnData.comparator != null) { | |
159 | tableColumn.addSelectionListener(new SelectionAdapter() { | |
160 | @Override | |
161 | public void widgetSelected(SelectionEvent e) { | |
162 | if (tableViewer.getTable().getSortDirection() == SWT.UP || (tableViewer.getTable().getSortColumn() != tableColumn)) { | |
163 | tableViewer.setComparator(columnData.comparator); | |
164 | tableViewer.getTable().setSortDirection(SWT.DOWN); | |
165 | } else { | |
166 | tableViewer.setComparator(new ViewerComparator() { | |
167 | @Override | |
168 | public int compare(Viewer viewer,Object e1, Object e2) { | |
169 | return -1 * columnData.comparator.compare(viewer, e1,e2); | |
170 | } | |
171 | }); | |
172 | tableViewer.getTable().setSortDirection(SWT.UP); | |
173 | } | |
174 | tableViewer.getTable().setSortColumn(tableColumn); | |
175 | } | |
176 | }); | |
177 | } | |
178 | } | |
179 | ||
180 | tableViewer.setColumnProperties(fColumnNames.toArray(new String[0])); | |
181 | ||
182 | // Create the cell editors | |
183 | CellEditor[] editors = new CellEditor[columnDataList.length]; | |
184 | ||
185 | // Column 1 : Completed (Checkbox) | |
186 | TextCellEditor textEditor = new TextCellEditor(table); | |
187 | editors[0] = textEditor; | |
188 | ||
189 | // Column 2 : Description (Free text) | |
190 | editors[1] = new CheckboxCellEditor(table); | |
191 | ||
192 | // Column 3 : Owner (Combo Box) | |
193 | editors[2] = new CheckboxCellEditor(table); | |
194 | ||
195 | // Column 4 : Percent complete (Text with digits only) | |
196 | textEditor = new TextCellEditor(table); | |
197 | ((Text) textEditor.getControl()).addVerifyListener( | |
198 | ||
199 | new VerifyListener() { | |
200 | ||
201 | @Override | |
202 | public void verifyText(VerifyEvent e) { | |
203 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ | |
204 | } | |
205 | }); | |
206 | editors[3] = textEditor; | |
207 | ||
208 | textEditor = new TextCellEditor(table); | |
209 | ((Text) textEditor.getControl()).addVerifyListener( | |
210 | ||
211 | new VerifyListener() { | |
212 | ||
213 | @Override | |
214 | public void verifyText(VerifyEvent e) { | |
215 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ | |
216 | } | |
217 | }); | |
218 | editors[4] = textEditor; | |
219 | ||
220 | textEditor = new TextCellEditor(table); | |
221 | ((Text) textEditor.getControl()).addVerifyListener( | |
222 | ||
223 | new VerifyListener() { | |
224 | ||
225 | @Override | |
226 | public void verifyText(VerifyEvent e) { | |
227 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ | |
228 | } | |
229 | }); | |
230 | editors[5] = textEditor; | |
231 | ||
232 | // Assign the cell editors to the viewer | |
233 | tableViewer.setCellEditors(editors); | |
234 | tableViewer.setCellModifier(new TraceChannelCellModifier(this)); | |
235 | ||
236 | tableViewer.setContentProvider(new TraceChannelTableContentProvider()); | |
237 | tableViewer.setLabelProvider(new TraceChannelTableLabelProvider()); | |
238 | ||
239 | table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
240 | ||
241 | makeActions(); | |
242 | addContextMenu(); | |
243 | } | |
244 | ||
245 | /* (non-Javadoc) | |
246 | * @see org.eclipse.jface.dialogs.DialogPage#dispose() | |
247 | */ | |
248 | @Override | |
249 | public void dispose() { | |
250 | super.dispose(); | |
251 | } | |
252 | ||
253 | /* (non-Javadoc) | |
254 | * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) | |
255 | */ | |
256 | @Override | |
257 | public void setVisible(boolean visible) { | |
258 | if (visible && (fChannels != null)) { | |
259 | // Get new channels configuration | |
260 | tableViewer.setInput(fChannels); | |
261 | ||
262 | Table table = tableViewer.getTable(); | |
263 | TableItem[] items = table.getItems(); | |
264 | for (int i = 0; i < items.length; i++) { | |
265 | if ((i % 2) != 0) { | |
266 | items[i].setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); | |
267 | } | |
268 | ||
269 | if ((fTraceState != TraceState.CREATED) && (fTraceState != TraceState.CONFIGURED)) { | |
270 | items[i].setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); | |
271 | } | |
272 | } | |
273 | ||
274 | container.layout(); | |
275 | } | |
276 | super.setVisible(visible); | |
277 | } | |
278 | ||
279 | /** | |
280 | * Gets the list of column names. | |
281 | * | |
282 | * @return list of column names | |
283 | */ | |
284 | public List<String> getColumnProperties() { | |
285 | return fColumnNames; | |
286 | } | |
287 | ||
288 | /* | |
289 | * Refreshes the table. | |
290 | */ | |
291 | public void refresh() { | |
292 | tableViewer.refresh(); | |
293 | } | |
294 | ||
295 | /** | |
296 | * Gets the trace state. | |
297 | * | |
298 | * @return trace state | |
299 | */ | |
300 | public TraceState getTraceState() { | |
301 | return fTraceState; | |
302 | } | |
303 | ||
304 | /** | |
305 | * Gets if trace is a local trace (i.e. if trace output is stored on host | |
306 | * where client is running) | |
307 | * | |
308 | * @return isLocalTrace | |
309 | */ | |
310 | public boolean isLocalTrace() { | |
311 | TraceConfigurationPage configPage = (TraceConfigurationPage) getPreviousPage(); | |
312 | return configPage.isLocalTrace(); | |
313 | } | |
314 | ||
315 | /* | |
316 | * (non-Javadoc) | |
317 | * @see org.eclipse.linuxtools.lttng.rse.ui.wizards.ITraceChannelConfigurationPage#getTraceChannels() | |
318 | */ | |
319 | @Override | |
320 | public TraceChannels getTraceChannels() { | |
321 | return fChannels; | |
322 | } | |
323 | ||
324 | /* | |
325 | * Local class to configure table columns | |
326 | */ | |
c6f55e56 | 327 | private static final class ColumnData { |
4f3793c3 BH |
328 | // Name of the column. |
329 | public final String header; | |
330 | // Width of the column. | |
331 | public final int width; | |
332 | // Alignment of the column. | |
333 | public final int alignment; | |
334 | // Tooltip of the column. | |
335 | public final String tooltip; | |
336 | // Used to sort elements of this column. Can be null. | |
337 | public final ViewerComparator comparator; | |
338 | ||
339 | public ColumnData(String h, int w, int a, String t, ViewerComparator c) { | |
340 | header = h; | |
341 | width = w; | |
342 | alignment = a; | |
343 | tooltip = t; | |
344 | comparator = c; | |
345 | } | |
346 | }; | |
347 | ||
348 | /* | |
349 | * Creates actions for context sensitive menu. | |
350 | */ | |
351 | private void makeActions() { | |
352 | ||
353 | // Create the context menu actions | |
354 | enableAllAction = new Action(Messages.ChannelConfigPage_EnableAll, LTTngUiPlugin.getDefault().getImageDescriptor(LTTngUiPlugin.ICON_ID_CHECKED)) { | |
355 | @Override | |
356 | public void run() { | |
357 | TableItem[] items = tableViewer.getTable().getItems(); | |
358 | for (int i = 0; i < items.length; i++) { | |
359 | TraceChannel chan = (TraceChannel)items[i].getData(); | |
360 | chan.setIsEnabled(true); | |
361 | } | |
362 | tableViewer.refresh(); | |
363 | } | |
364 | }; | |
365 | ||
366 | disableAllAction = new Action(Messages.ChannelConfigPage_DisableAll, LTTngUiPlugin.getDefault().getImageDescriptor(LTTngUiPlugin.ICON_ID_UNCHECKED)) { | |
367 | @Override | |
368 | public void run() { | |
369 | TableItem[] items = tableViewer.getTable().getItems(); | |
370 | for (int i = 0; i < items.length; i++) { | |
371 | TraceChannel chan = (TraceChannel)items[i].getData(); | |
372 | chan.setIsEnabled(false); | |
373 | } | |
374 | tableViewer.refresh(); | |
375 | } | |
376 | }; | |
377 | setOverrideAllAction = new Action(Messages.ChannelConfigPage_EnableAllBufferOverride, LTTngUiPlugin.getDefault().getImageDescriptor(LTTngUiPlugin.ICON_ID_CHECKED)) { | |
378 | @Override | |
379 | public void run() { | |
380 | TableItem[] items = tableViewer.getTable().getItems(); | |
381 | for (int i = 0; i < items.length; i++) { | |
382 | TraceChannel chan = (TraceChannel)items[i].getData(); | |
383 | chan.setIsChannelOverride(true); | |
384 | } | |
385 | tableViewer.refresh(); | |
386 | } | |
387 | }; | |
388 | resetOverideAllAction= new Action(Messages.ChannelConfigage_DisableAllBufferOverride, LTTngUiPlugin.getDefault().getImageDescriptor(LTTngUiPlugin.ICON_ID_UNCHECKED)) { | |
389 | @Override | |
390 | public void run() { | |
391 | TableItem[] items = tableViewer.getTable().getItems(); | |
392 | for (int i = 0; i < items.length; i++) { | |
393 | TraceChannel chan = (TraceChannel)items[i].getData(); | |
394 | chan.setIsChannelOverride(false); | |
395 | } | |
396 | tableViewer.refresh(); | |
397 | } | |
398 | }; | |
399 | setNumSubbufAction = new Action(Messages.ChannelConfigPage_SetAllNumSubBuf, LTTngUiPlugin.getDefault().getImageDescriptor(LTTngUiPlugin.ICON_ID_EDIT)) { | |
400 | @Override | |
401 | public void run() { | |
402 | TableItem[] items = tableViewer.getTable().getItems(); | |
403 | SetDialog setDialog = new SetDialog(getShell(), Messages.ChannelConfigPage_NumSubBuf); | |
404 | if (setDialog.open() == Window.OK) { | |
405 | ||
406 | for (int i = 0; i < items.length; i++) { | |
407 | TraceChannel chan = (TraceChannel)items[i].getData(); | |
408 | chan.setSubbufNum(setDialog.getValue()); | |
409 | } | |
410 | ||
411 | tableViewer.refresh(); | |
412 | } | |
413 | } | |
414 | }; | |
415 | setSubbufSizeAction = new Action(Messages.channelConfigPage_SetAllSubBufSize, LTTngUiPlugin.getDefault().getImageDescriptor(LTTngUiPlugin.ICON_ID_EDIT)) { | |
416 | @Override | |
417 | public void run() { | |
418 | TableItem[] items = tableViewer.getTable().getItems(); | |
419 | SetDialog setDialog = new SetDialog(getShell(), Messages.ChannelConfigPage_SubBufSize); | |
420 | if (setDialog.open() == Window.OK) { | |
421 | ||
422 | for (int i = 0; i < items.length; i++) { | |
423 | TraceChannel chan = (TraceChannel)items[i].getData(); | |
424 | chan.setSubbufSize(setDialog.getValue()); | |
425 | } | |
426 | ||
427 | tableViewer.refresh(); | |
428 | } | |
429 | } | |
430 | }; | |
431 | setChanTimerAction = new Action(Messages.ChannelConfigPage_SetAllChannelTimer, LTTngUiPlugin.getDefault().getImageDescriptor("ICON_ID_EDIT")) { //$NON-NLS-1$ | |
432 | @Override | |
433 | public void run() { | |
434 | TableItem[] items = tableViewer.getTable().getItems(); | |
435 | SetDialog setDialog = new SetDialog(getShell(), Messages.ChannelConfigPage_ChannelTimer); | |
436 | if (setDialog.open() == Window.OK) { | |
437 | ||
438 | for (int i = 0; i < items.length; i++) { | |
439 | TraceChannel chan = (TraceChannel)items[i].getData(); | |
440 | chan.setTimer(setDialog.getValue()); | |
441 | } | |
442 | ||
443 | tableViewer.refresh(); | |
444 | } | |
445 | } | |
446 | }; | |
447 | } | |
448 | ||
449 | /* | |
450 | * Adds context sensitive menu to table. | |
451 | */ | |
452 | private void addContextMenu() { | |
453 | MenuManager manager = new MenuManager("configChanPopupMenu"); //$NON-NLS-1$ | |
454 | manager.setRemoveAllWhenShown(true); | |
455 | manager.addMenuListener(new IMenuListener() { | |
456 | ||
457 | @Override | |
458 | public void menuAboutToShow(IMenuManager manager) { | |
459 | ||
460 | if ((fTraceState != TraceState.CREATED) && (fTraceState != TraceState.CONFIGURED)) { | |
461 | return; | |
462 | } | |
463 | manager.add(enableAllAction); | |
464 | manager.add(disableAllAction); | |
465 | manager.add(setOverrideAllAction); | |
466 | manager.add(resetOverideAllAction); | |
467 | manager.add(setNumSubbufAction); | |
468 | manager.add(setSubbufSizeAction); | |
469 | manager.add(setChanTimerAction); | |
470 | } | |
471 | }); | |
472 | ||
473 | Menu menu = manager.createContextMenu(tableViewer.getControl()); | |
474 | tableViewer.getControl().setMenu(menu); | |
475 | } | |
476 | ||
477 | /** | |
478 | * Local class dialog box implementation for setting values for all | |
479 | * rows for a given column | |
480 | */ | |
c6f55e56 | 481 | private static final class SetDialog extends Dialog { |
4f3793c3 BH |
482 | |
483 | // ------------------------------------------------------------------------ | |
484 | // Attributes | |
485 | // ------------------------------------------------------------------------ | |
486 | ||
487 | private String fWhat = null; | |
488 | private Text fValueText = null; | |
489 | private Long fValue = null; | |
490 | ||
491 | // ------------------------------------------------------------------------ | |
492 | // Constructors | |
493 | // ------------------------------------------------------------------------ | |
494 | ||
495 | public SetDialog(Shell parentShell, String what) { | |
496 | super(parentShell); | |
497 | fWhat = what; | |
498 | } | |
499 | ||
500 | // ------------------------------------------------------------------------ | |
501 | // Operations | |
502 | // ------------------------------------------------------------------------ | |
503 | ||
504 | /* | |
505 | * (non-Javadoc) | |
506 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
507 | */ | |
508 | @Override | |
509 | protected void configureShell(Shell newShell) { | |
510 | super.configureShell(newShell); | |
511 | newShell.setText(Messages.ChannelConfigPage_SetAll); | |
512 | newShell.setImage(LTTngUiPlugin.getDefault().getImage(LTTngUiPlugin.ICON_ID_EDIT)); | |
513 | } | |
514 | ||
515 | /* | |
516 | * (non-Javadoc) | |
517 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
518 | */ | |
519 | @Override | |
520 | protected Control createDialogArea(Composite parent) { | |
521 | //Main dialog panel | |
522 | Composite composite = new Composite(parent, SWT.RESIZE); | |
523 | GridLayout mainLayout = new GridLayout(3, true); | |
524 | composite.setLayout(mainLayout); | |
525 | Label what = new Label(composite, SWT.LEFT); | |
526 | what.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1)); | |
527 | what.setText(fWhat); | |
528 | ||
529 | fValueText = new Text(composite, SWT.LEFT); | |
530 | fValueText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1)); | |
531 | ||
532 | fValueText.addVerifyListener( | |
533 | new VerifyListener() { | |
534 | ||
535 | @Override | |
536 | public void verifyText(VerifyEvent e) { | |
537 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ | |
538 | } | |
539 | }); | |
540 | ||
541 | fValueText.addListener(SWT.Modify, new Listener() { | |
542 | @Override | |
543 | public void handleEvent(Event event) { | |
544 | Button ok = getButton(IDialogConstants.OK_ID); | |
545 | ok.setEnabled(validateInput(fValueText.getText())); | |
546 | } | |
547 | }); | |
548 | ||
549 | return composite; | |
550 | } | |
551 | ||
552 | /* | |
553 | * (non-Javadoc) | |
554 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
555 | */ | |
556 | @Override | |
557 | protected void createButtonsForButtonBar(Composite parent) { | |
558 | Button ok = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); | |
559 | createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); | |
560 | ||
561 | ok.setEnabled(false); | |
562 | } | |
563 | ||
564 | /* | |
565 | * (non-Javadoc) | |
566 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
567 | */ | |
568 | @Override | |
569 | protected void okPressed() { | |
570 | fValue = Long.valueOf(fValueText.getText()); | |
571 | super.okPressed(); | |
572 | } | |
573 | ||
574 | /* | |
575 | * Method to validate input. | |
576 | */ | |
577 | private boolean validateInput(String path) { | |
578 | return (path.trim().length() > 0); | |
579 | } | |
580 | ||
581 | /** | |
582 | * Gets value that the user input. | |
583 | * | |
584 | * @return value | |
585 | */ | |
586 | public Long getValue() { | |
587 | return fValue; | |
588 | } | |
589 | } | |
590 | } |