Commit | Line | Data |
---|---|---|
e8d771d5 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 org.eclipse.jface.wizard.WizardPage; | |
6c13869b FC |
16 | import org.eclipse.linuxtools.lttng.core.tracecontrol.model.config.TraceChannel; |
17 | import org.eclipse.linuxtools.lttng.core.tracecontrol.model.config.TraceChannels; | |
e8d771d5 BH |
18 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages; |
19 | import org.eclipse.swt.SWT; | |
20 | import org.eclipse.swt.events.VerifyEvent; | |
21 | import org.eclipse.swt.events.VerifyListener; | |
22 | import org.eclipse.swt.layout.GridData; | |
23 | import org.eclipse.swt.layout.GridLayout; | |
24 | import org.eclipse.swt.widgets.Composite; | |
25 | import org.eclipse.swt.widgets.Event; | |
26 | import org.eclipse.swt.widgets.Label; | |
27 | import org.eclipse.swt.widgets.Listener; | |
28 | import org.eclipse.swt.widgets.Text; | |
29 | ||
30 | /** | |
31 | * <b><u>UstTraceChannelConfigurationPage</u></b> | |
32 | * <p> | |
33 | * Wizard page implementation to configure the UST trace channels. | |
34 | * </p> | |
35 | */ | |
36 | public class UstTraceChannelConfigurationPage extends WizardPage implements ITraceChannelConfigurationPage { | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Attributes | |
40 | // ------------------------------------------------------------------------ | |
41 | private TraceChannels fChannels; | |
42 | private Composite fContainer; | |
43 | private Text fChannelTimerText; | |
44 | ||
45 | // ------------------------------------------------------------------------ | |
46 | // Constructors | |
47 | // ------------------------------------------------------------------------ | |
48 | ||
49 | /** | |
50 | * Constructor | |
51 | * | |
52 | * @param channels | |
53 | */ | |
54 | protected UstTraceChannelConfigurationPage(TraceChannels channels) { | |
55 | super("UstTraceChannelConfigurationPage"); //$NON-NLS-1$ | |
56 | fChannels = channels; | |
57 | setTitle(Messages.ChannelConfigPage_PageTitle); | |
58 | } | |
59 | ||
60 | ||
61 | // ------------------------------------------------------------------------ | |
62 | // Operations | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | /* | |
66 | * (non-Javadoc) | |
67 | * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) | |
68 | */ | |
69 | @Override | |
70 | public void createControl(Composite parent) { | |
71 | fContainer = new Composite(parent, SWT.NULL); | |
72 | fContainer.setLayout(new GridLayout()); | |
73 | setControl(fContainer); | |
74 | ||
75 | Composite headerComposite = new Composite(fContainer, SWT.FILL); | |
76 | GridLayout headerLayout = new GridLayout(4, true); | |
77 | headerLayout.marginHeight = 0; | |
78 | headerLayout.marginWidth = 0; | |
79 | headerComposite.setLayout(headerLayout); | |
80 | headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
81 | ||
82 | Label label = new Label(headerComposite, SWT.LEFT); | |
83 | label.setText(Messages.ChannelConfigPage_ChannelTimer + ":"); //$NON-NLS-1$ | |
84 | label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | |
85 | ||
86 | fChannelTimerText = new Text(headerComposite, SWT.LEFT); | |
87 | fChannelTimerText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1)); | |
88 | fChannelTimerText.setToolTipText(Messages.ChannelConfigPage_ChannelTimerTooltip); | |
89 | ||
90 | TraceChannel chan = fChannels.get(TraceChannel.UST_TRACE_CHANNEL_NAME); | |
91 | if (chan.getTimer() == TraceChannel.UNKNOWN_VALUE) { | |
92 | fChannelTimerText.setText(TraceChannel.UNKNOWN_STRING); | |
93 | } | |
94 | else { | |
95 | fChannelTimerText.setText(String.valueOf(chan.getTimer())); | |
96 | } | |
97 | ||
98 | fChannelTimerText.addVerifyListener(new VerifyListener() { | |
99 | @Override | |
100 | public void verifyText(VerifyEvent e) { | |
101 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ | |
102 | } | |
103 | }); | |
104 | ||
105 | fChannelTimerText.addListener(SWT.Modify, new Listener() { | |
106 | @Override | |
107 | public void handleEvent(Event event) { | |
108 | String valueString = fChannelTimerText.getText(); | |
109 | TraceChannel chan = fChannels.get(TraceChannel.UST_TRACE_CHANNEL_NAME); | |
110 | if (valueString.length() == 0) { | |
111 | valueString = "0"; //$NON-NLS-1$ | |
112 | } | |
113 | else if(TraceChannel.UNKNOWN_STRING.equals(valueString)) { | |
114 | chan.setTimer(TraceChannel.UNKNOWN_VALUE); | |
115 | } | |
116 | else { | |
117 | chan.setTimer(Integer.parseInt(valueString)); | |
118 | } | |
119 | } | |
120 | }); | |
121 | } | |
122 | ||
123 | /* (non-Javadoc) | |
124 | * @see org.eclipse.jface.dialogs.DialogPage#dispose() | |
125 | */ | |
126 | @Override | |
127 | public void dispose() { | |
128 | super.dispose(); | |
129 | } | |
130 | ||
131 | /* | |
132 | * (non-Javadoc) | |
133 | * @see org.eclipse.linuxtools.lttng.rse.ui.wizards.ITraceChannelConfigurationPage#getTraceChannels() | |
134 | */ | |
135 | @Override | |
136 | public TraceChannels getTraceChannels() { | |
137 | return fChannels; | |
138 | } | |
139 | } |