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