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