Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
4 | * | |
73005152 BH |
5 | * All rights reserved. This program and the accompanying materials |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
73005152 BH |
9 | * |
10 | * Contributors: | |
11 | * IBM - Initial API and implementation | |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
df0b8ff4 | 14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs; |
73005152 BH |
15 | |
16 | import org.eclipse.jface.dialogs.Dialog; | |
17 | import org.eclipse.jface.dialogs.IDialogConstants; | |
18 | import org.eclipse.jface.dialogs.MessageDialog; | |
6c13869b | 19 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
73005152 | 20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget; |
df0b8ff4 | 21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages; |
73005152 BH |
22 | import org.eclipse.swt.SWT; |
23 | import org.eclipse.swt.events.SelectionEvent; | |
24 | import org.eclipse.swt.events.SelectionListener; | |
25 | import org.eclipse.swt.layout.GridData; | |
26 | import org.eclipse.swt.layout.GridLayout; | |
27 | import org.eclipse.swt.widgets.Composite; | |
28 | import org.eclipse.swt.widgets.Control; | |
29 | import org.eclipse.swt.widgets.Group; | |
30 | import org.eclipse.swt.widgets.Label; | |
31 | import org.eclipse.swt.widgets.Shell; | |
32 | import org.eclipse.swt.widgets.Text; | |
33 | ||
34 | /** | |
df0b8ff4 BH |
35 | * Dialog box for entering minimum and maximum time range for time compression bar. |
36 | * | |
37 | * @version 1.0 | |
73005152 | 38 | * @author sveyrier |
df0b8ff4 | 39 | * @author Bernd Hufmann |
73005152 BH |
40 | * |
41 | */ | |
42 | public class MinMaxDialog extends Dialog { | |
43 | ||
df0b8ff4 BH |
44 | // ------------------------------------------------------------------------ |
45 | // Attributes | |
46 | // ------------------------------------------------------------------------ | |
47 | /** | |
48 | * Label for minimum. | |
49 | */ | |
73005152 | 50 | protected Label minLabel; |
df0b8ff4 BH |
51 | /** |
52 | * Label for maximum. | |
53 | */ | |
73005152 | 54 | protected Label maxLabel; |
df0b8ff4 BH |
55 | /** |
56 | * Label for scale | |
57 | */ | |
73005152 | 58 | protected Label scaleLabel; |
df0b8ff4 BH |
59 | /** |
60 | * Label for precision. | |
61 | */ | |
73005152 | 62 | protected Label precisionLabel; |
df0b8ff4 BH |
63 | /** |
64 | * Text field for minimum. | |
65 | */ | |
73005152 | 66 | protected Text minText; |
df0b8ff4 BH |
67 | /** |
68 | * Text field for maximum. | |
69 | */ | |
73005152 | 70 | protected Text maxText; |
df0b8ff4 BH |
71 | /** |
72 | * Text field for scale. | |
73 | */ | |
73005152 | 74 | protected Text scaleText; |
df0b8ff4 BH |
75 | /** |
76 | * Text field for precision. | |
77 | */ | |
73005152 | 78 | protected Text precisionText; |
df0b8ff4 BH |
79 | /** |
80 | * The sequence diagram widget reference. | |
81 | */ | |
82 | protected SDWidget sdWidget; | |
83 | ||
84 | // ------------------------------------------------------------------------ | |
85 | // Constructor | |
86 | // ------------------------------------------------------------------------ | |
87 | /** | |
88 | * Standard constructor. | |
89 | * @param shell The shell | |
90 | * @param viewer The sequence diagram widget reference. | |
91 | */ | |
92 | public MinMaxDialog(Shell shell, SDWidget viewer) { | |
93 | super(shell); | |
94 | sdWidget = viewer; | |
73005152 BH |
95 | } |
96 | ||
df0b8ff4 BH |
97 | // ------------------------------------------------------------------------ |
98 | // Methods | |
99 | // ------------------------------------------------------------------------ | |
100 | /** | |
101 | * Method to create a grid data base on horizontal span. | |
102 | * @param span The horizontal span | |
103 | * @return a grid data object | |
104 | */ | |
73005152 BH |
105 | protected GridData newGridData(int span) { |
106 | GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
107 | data.horizontalSpan = span; | |
108 | return data; | |
109 | } | |
110 | ||
df0b8ff4 BH |
111 | /* |
112 | * (non-Javadoc) | |
113 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
114 | */ | |
73005152 BH |
115 | @Override |
116 | protected Control createDialogArea(Composite p) { | |
117 | p.getShell().setText(SDMessages._123); | |
118 | Composite parent = (Composite) super.createDialogArea(p); | |
119 | ||
120 | GridLayout parentLayout = new GridLayout(); | |
121 | parentLayout.numColumns = 6; | |
122 | parent.setLayout(parentLayout); | |
123 | ||
124 | Group g1 = new Group(parent, SWT.SHADOW_NONE); | |
125 | g1.setLayoutData(newGridData(3)); | |
126 | GridLayout g1layout = new GridLayout(); | |
127 | g1layout.numColumns = 3; | |
128 | g1.setLayout(g1layout); | |
129 | ||
130 | minLabel = new Label(g1, SWT.RADIO); | |
131 | minLabel.setText(SDMessages._124); | |
132 | minLabel.setLayoutData(newGridData(1)); | |
133 | ||
134 | minText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
135 | minText.setLayoutData(newGridData(2)); | |
136 | minText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getValue())); | |
137 | ||
138 | maxLabel = new Label(g1, SWT.RADIO); | |
139 | maxLabel.setText(SDMessages._125); | |
140 | maxLabel.setLayoutData(newGridData(1)); | |
141 | ||
142 | maxText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
143 | maxText.setLayoutData(newGridData(2)); | |
144 | maxText.setText(String.valueOf(sdWidget.getFrame().getMaxTime().getValue())); | |
145 | ||
146 | scaleLabel = new Label(g1, SWT.RADIO); | |
147 | scaleLabel.setText(SDMessages._136); | |
148 | scaleLabel.setLayoutData(newGridData(1)); | |
149 | ||
150 | scaleText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
151 | scaleText.setLayoutData(newGridData(2)); | |
152 | scaleText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getScale())); | |
153 | ||
154 | ||
155 | precisionLabel = new Label(g1, SWT.RADIO); | |
156 | precisionLabel.setText(SDMessages._137); | |
157 | precisionLabel.setLayoutData(newGridData(1)); | |
158 | ||
159 | precisionText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
160 | precisionText.setLayoutData(newGridData(2)); | |
161 | precisionText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getPrecision())); | |
162 | ||
163 | return parent; | |
164 | } | |
165 | ||
df0b8ff4 BH |
166 | /* |
167 | * (non-Javadoc) | |
168 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
169 | */ | |
73005152 BH |
170 | @Override |
171 | protected void okPressed() { | |
73005152 BH |
172 | long min = 0; |
173 | long max = 0; | |
5179fc01 FC |
174 | int scale = 0; |
175 | int precision = 0; | |
73005152 BH |
176 | try { |
177 | min = Long.parseLong(minText.getText()); | |
178 | max = Long.parseLong(maxText.getText()); | |
5179fc01 FC |
179 | scale = Integer.parseInt(scaleText.getText()); |
180 | precision = Integer.parseInt(precisionText.getText()); | |
73005152 BH |
181 | |
182 | sdWidget.getFrame().setMax(new TmfTimestamp(max, scale, precision)); | |
183 | sdWidget.getFrame().setMin(new TmfTimestamp(min, scale, precision)); | |
184 | ||
185 | sdWidget.redraw(); | |
186 | ||
187 | super.okPressed(); | |
188 | } catch (Exception e) { | |
189 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._99); | |
190 | } | |
191 | } | |
192 | ||
df0b8ff4 BH |
193 | /* |
194 | * (non-Javadoc) | |
195 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
196 | */ | |
73005152 BH |
197 | @Override |
198 | protected void createButtonsForButtonBar(Composite parent) { | |
199 | super.createButtonsForButtonBar(parent); | |
200 | createButton(parent, IDialogConstants.CLIENT_ID, SDMessages._126, false); | |
201 | getButton(IDialogConstants.CLIENT_ID).addSelectionListener(new SelectionListener() { | |
df0b8ff4 BH |
202 | /* |
203 | * (non-Javadoc) | |
204 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) | |
205 | */ | |
73005152 BH |
206 | @Override |
207 | public void widgetSelected(SelectionEvent e) { | |
208 | sdWidget.getFrame().resetCustomMinMax(); | |
209 | minText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getValue())); | |
210 | maxText.setText(String.valueOf(sdWidget.getFrame().getMaxTime().getValue())); | |
211 | scaleText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getScale())); | |
212 | precisionText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getPrecision())); | |
213 | maxText.getParent().layout(true); | |
214 | } | |
215 | ||
df0b8ff4 BH |
216 | /* |
217 | * (non-Javadoc) | |
218 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) | |
219 | */ | |
73005152 BH |
220 | @Override |
221 | public void widgetDefaultSelected(SelectionEvent e) { | |
df0b8ff4 | 222 | // nothing to do |
73005152 | 223 | } |
73005152 BH |
224 | }); |
225 | } | |
226 | } |