tmf: Move timestamps to their own package
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / MinMaxDialog.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
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
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
15
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
20 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
21 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
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 /**
35 * Dialog box for entering minimum and maximum time range for time compression bar.
36 *
37 * @version 1.0
38 * @author sveyrier
39 * @author Bernd Hufmann
40 *
41 */
42 public class MinMaxDialog extends Dialog {
43
44 // ------------------------------------------------------------------------
45 // Attributes
46 // ------------------------------------------------------------------------
47 /**
48 * Label for minimum.
49 */
50 protected Label fMinLabel;
51 /**
52 * Label for maximum.
53 */
54 protected Label fMaxLabel;
55 /**
56 * Label for scale
57 */
58 protected Label fScaleLabel;
59 /**
60 * Label for precision.
61 */
62 protected Label fPrecisionLabel;
63 /**
64 * Text field for minimum.
65 */
66 protected Text fMinText;
67 /**
68 * Text field for maximum.
69 */
70 protected Text fMaxText;
71 /**
72 * Text field for scale.
73 */
74 protected Text fScaleText;
75 /**
76 * Text field for precision.
77 */
78 protected Text fPrecisionText;
79 /**
80 * The sequence diagram widget reference.
81 */
82 protected SDWidget fSdWidget;
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 fSdWidget = viewer;
95 }
96
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 */
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
111 /*
112 * (non-Javadoc)
113 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
114 */
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 fMinLabel = new Label(g1, SWT.RADIO);
131 fMinLabel.setText(SDMessages._124);
132 fMinLabel.setLayoutData(newGridData(1));
133
134 fMinText = new Text(g1, SWT.SINGLE | SWT.BORDER);
135 fMinText.setLayoutData(newGridData(2));
136 fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue()));
137
138 fMaxLabel = new Label(g1, SWT.RADIO);
139 fMaxLabel.setText(SDMessages._125);
140 fMaxLabel.setLayoutData(newGridData(1));
141
142 fMaxText = new Text(g1, SWT.SINGLE | SWT.BORDER);
143 fMaxText.setLayoutData(newGridData(2));
144 fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue()));
145
146 fScaleLabel = new Label(g1, SWT.RADIO);
147 fScaleLabel.setText(SDMessages._136);
148 fScaleLabel.setLayoutData(newGridData(1));
149
150 fScaleText = new Text(g1, SWT.SINGLE | SWT.BORDER);
151 fScaleText.setLayoutData(newGridData(2));
152 fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale()));
153
154
155 fPrecisionLabel = new Label(g1, SWT.RADIO);
156 fPrecisionLabel.setText(SDMessages._137);
157 fPrecisionLabel.setLayoutData(newGridData(1));
158
159 fPrecisionText = new Text(g1, SWT.SINGLE | SWT.BORDER);
160 fPrecisionText.setLayoutData(newGridData(2));
161 fPrecisionText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getPrecision()));
162
163 return parent;
164 }
165
166 /*
167 * (non-Javadoc)
168 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
169 */
170 @Override
171 protected void okPressed() {
172 long min = 0;
173 long max = 0;
174 int scale = 0;
175 int precision = 0;
176 try {
177 min = Long.parseLong(fMinText.getText());
178 max = Long.parseLong(fMaxText.getText());
179 scale = Integer.parseInt(fScaleText.getText());
180 precision = Integer.parseInt(fPrecisionText.getText());
181
182 fSdWidget.getFrame().setMax(new TmfTimestamp(max, scale, precision));
183 fSdWidget.getFrame().setMin(new TmfTimestamp(min, scale, precision));
184
185 fSdWidget.redraw();
186
187 super.okPressed();
188 } catch (Exception e) {
189 MessageDialog.openError(getShell(), SDMessages._98, SDMessages._99);
190 }
191 }
192
193 /*
194 * (non-Javadoc)
195 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
196 */
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() {
202 /*
203 * (non-Javadoc)
204 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
205 */
206 @Override
207 public void widgetSelected(SelectionEvent e) {
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);
214 }
215
216 /*
217 * (non-Javadoc)
218 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
219 */
220 @Override
221 public void widgetDefaultSelected(SelectionEvent e) {
222 // nothing to do
223 }
224 });
225 }
226 }
This page took 0.035827 seconds and 6 git commands to generate.