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; | |
3bd46eef | 19 | import org.eclipse.linuxtools.tmf.core.timestamp.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 | */ | |
eb63f5ff | 50 | protected Label fMinLabel; |
df0b8ff4 BH |
51 | /** |
52 | * Label for maximum. | |
53 | */ | |
eb63f5ff | 54 | protected Label fMaxLabel; |
df0b8ff4 BH |
55 | /** |
56 | * Label for scale | |
57 | */ | |
eb63f5ff | 58 | protected Label fScaleLabel; |
df0b8ff4 BH |
59 | /** |
60 | * Label for precision. | |
61 | */ | |
eb63f5ff | 62 | protected Label fPrecisionLabel; |
df0b8ff4 BH |
63 | /** |
64 | * Text field for minimum. | |
65 | */ | |
eb63f5ff | 66 | protected Text fMinText; |
df0b8ff4 BH |
67 | /** |
68 | * Text field for maximum. | |
69 | */ | |
eb63f5ff | 70 | protected Text fMaxText; |
df0b8ff4 BH |
71 | /** |
72 | * Text field for scale. | |
73 | */ | |
eb63f5ff | 74 | protected Text fScaleText; |
df0b8ff4 BH |
75 | /** |
76 | * Text field for precision. | |
77 | */ | |
eb63f5ff | 78 | protected Text fPrecisionText; |
df0b8ff4 BH |
79 | /** |
80 | * The sequence diagram widget reference. | |
81 | */ | |
eb63f5ff | 82 | protected SDWidget fSdWidget; |
df0b8ff4 BH |
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); | |
eb63f5ff | 94 | fSdWidget = 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 | ||
eb63f5ff BH |
130 | fMinLabel = new Label(g1, SWT.RADIO); |
131 | fMinLabel.setText(SDMessages._124); | |
132 | fMinLabel.setLayoutData(newGridData(1)); | |
73005152 | 133 | |
eb63f5ff BH |
134 | fMinText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
135 | fMinText.setLayoutData(newGridData(2)); | |
136 | fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue())); | |
73005152 | 137 | |
eb63f5ff BH |
138 | fMaxLabel = new Label(g1, SWT.RADIO); |
139 | fMaxLabel.setText(SDMessages._125); | |
140 | fMaxLabel.setLayoutData(newGridData(1)); | |
73005152 | 141 | |
eb63f5ff BH |
142 | fMaxText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
143 | fMaxText.setLayoutData(newGridData(2)); | |
144 | fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue())); | |
73005152 | 145 | |
eb63f5ff BH |
146 | fScaleLabel = new Label(g1, SWT.RADIO); |
147 | fScaleLabel.setText(SDMessages._136); | |
148 | fScaleLabel.setLayoutData(newGridData(1)); | |
73005152 | 149 | |
eb63f5ff BH |
150 | fScaleText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
151 | fScaleText.setLayoutData(newGridData(2)); | |
152 | fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale())); | |
73005152 BH |
153 | |
154 | ||
eb63f5ff BH |
155 | fPrecisionLabel = new Label(g1, SWT.RADIO); |
156 | fPrecisionLabel.setText(SDMessages._137); | |
157 | fPrecisionLabel.setLayoutData(newGridData(1)); | |
73005152 | 158 | |
eb63f5ff BH |
159 | fPrecisionText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
160 | fPrecisionText.setLayoutData(newGridData(2)); | |
161 | fPrecisionText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getPrecision())); | |
73005152 BH |
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 | 176 | try { |
eb63f5ff BH |
177 | min = Long.parseLong(fMinText.getText()); |
178 | max = Long.parseLong(fMaxText.getText()); | |
179 | scale = Integer.parseInt(fScaleText.getText()); | |
180 | precision = Integer.parseInt(fPrecisionText.getText()); | |
73005152 | 181 | |
eb63f5ff BH |
182 | fSdWidget.getFrame().setMax(new TmfTimestamp(max, scale, precision)); |
183 | fSdWidget.getFrame().setMin(new TmfTimestamp(min, scale, precision)); | |
73005152 | 184 | |
eb63f5ff | 185 | fSdWidget.redraw(); |
73005152 BH |
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) { | |
eb63f5ff BH |
208 | fSdWidget.getFrame().resetCustomMinMax(); |
209 | fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue())); | |
210 | fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue())); | |
211 | fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale())); | |
212 | fPrecisionText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getPrecision())); | |
213 | fMaxText.getParent().layout(true); | |
73005152 BH |
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 | } |