0ff3fc82ccc077ba9cbbd5be661c9e9242f69737
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / MinMaxDialog.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
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
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.dialogs.MessageDialog;
18 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
19 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
20 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages;
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 /**
34 * Dialog box for entering minimum and maximum time range for time compression bar.
35 *
36 * @version 1.0
37 * @author sveyrier
38 * @author Bernd Hufmann
39 *
40 */
41 public class MinMaxDialog extends Dialog {
42
43 // ------------------------------------------------------------------------
44 // Attributes
45 // ------------------------------------------------------------------------
46 /**
47 * Label for minimum.
48 */
49 protected Label fMinLabel;
50 /**
51 * Label for maximum.
52 */
53 protected Label fMaxLabel;
54 /**
55 * Label for scale
56 */
57 protected Label fScaleLabel;
58 /**
59 * Label for precision.
60 */
61 protected Label fPrecisionLabel;
62 /**
63 * Text field for minimum.
64 */
65 protected Text fMinText;
66 /**
67 * Text field for maximum.
68 */
69 protected Text fMaxText;
70 /**
71 * Text field for scale.
72 */
73 protected Text fScaleText;
74 /**
75 * Text field for precision.
76 */
77 protected Text fPrecisionText;
78 /**
79 * The sequence diagram widget reference.
80 */
81 protected SDWidget fSdWidget;
82
83 // ------------------------------------------------------------------------
84 // Constructor
85 // ------------------------------------------------------------------------
86 /**
87 * Standard constructor.
88 * @param shell The shell
89 * @param viewer The sequence diagram widget reference.
90 */
91 public MinMaxDialog(Shell shell, SDWidget viewer) {
92 super(shell);
93 fSdWidget = viewer;
94 }
95
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 */
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
110 @Override
111 protected Control createDialogArea(Composite p) {
112 p.getShell().setText(Messages.SequenceDiagram_TimeCompressionBarConfig);
113 Composite parent = (Composite) super.createDialogArea(p);
114
115 GridLayout parentLayout = new GridLayout();
116 parentLayout.numColumns = 6;
117 parent.setLayout(parentLayout);
118
119 Group g1 = new Group(parent, SWT.SHADOW_NONE);
120 g1.setLayoutData(newGridData(3));
121 GridLayout g1layout = new GridLayout();
122 g1layout.numColumns = 3;
123 g1.setLayout(g1layout);
124
125 fMinLabel = new Label(g1, SWT.RADIO);
126 fMinLabel.setText(Messages.SequenceDiagram_MinTime);
127 fMinLabel.setLayoutData(newGridData(1));
128
129 fMinText = new Text(g1, SWT.SINGLE | SWT.BORDER);
130 fMinText.setLayoutData(newGridData(2));
131 fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue()));
132
133 fMaxLabel = new Label(g1, SWT.RADIO);
134 fMaxLabel.setText(Messages.SequenceDiagram_MaxTime);
135 fMaxLabel.setLayoutData(newGridData(1));
136
137 fMaxText = new Text(g1, SWT.SINGLE | SWT.BORDER);
138 fMaxText.setLayoutData(newGridData(2));
139 fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue()));
140
141 fScaleLabel = new Label(g1, SWT.RADIO);
142 fScaleLabel.setText(Messages.SequenceDiagram_Scale);
143 fScaleLabel.setLayoutData(newGridData(1));
144
145 fScaleText = new Text(g1, SWT.SINGLE | SWT.BORDER);
146 fScaleText.setLayoutData(newGridData(2));
147 fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale()));
148
149
150 fPrecisionLabel = new Label(g1, SWT.RADIO);
151 fPrecisionLabel.setText(Messages.SequenceDiagram_Precision);
152 fPrecisionLabel.setLayoutData(newGridData(1));
153
154 fPrecisionText = new Text(g1, SWT.SINGLE | SWT.BORDER);
155 fPrecisionText.setLayoutData(newGridData(2));
156 fPrecisionText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getPrecision()));
157
158 return parent;
159 }
160
161 @Override
162 protected void okPressed() {
163 long min = 0;
164 long max = 0;
165 int scale = 0;
166 int precision = 0;
167 try {
168 min = Long.parseLong(fMinText.getText());
169 max = Long.parseLong(fMaxText.getText());
170 scale = Integer.parseInt(fScaleText.getText());
171 precision = Integer.parseInt(fPrecisionText.getText());
172
173 fSdWidget.getFrame().setMax(new TmfTimestamp(max, scale, precision));
174 fSdWidget.getFrame().setMin(new TmfTimestamp(min, scale, precision));
175
176 fSdWidget.redraw();
177
178 super.okPressed();
179 } catch (Exception e) {
180 MessageDialog.openError(getShell(), Messages.SequenceDiagram_Error, Messages.SequenceDiagram_InvalidRange);
181 }
182 }
183
184 @Override
185 protected void createButtonsForButtonBar(Composite parent) {
186 super.createButtonsForButtonBar(parent);
187 createButton(parent, IDialogConstants.CLIENT_ID, Messages.SequenceDiagram_Default, false);
188 getButton(IDialogConstants.CLIENT_ID).addSelectionListener(new SelectionListener() {
189
190 @Override
191 public void widgetSelected(SelectionEvent e) {
192 fSdWidget.getFrame().resetCustomMinMax();
193 fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue()));
194 fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue()));
195 fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale()));
196 fPrecisionText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getPrecision()));
197 fMaxText.getParent().layout(true);
198 }
199
200 @Override
201 public void widgetDefaultSelected(SelectionEvent e) {
202 // nothing to do
203 }
204 });
205 }
206 }
This page took 0.057593 seconds and 4 git commands to generate.