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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.dialogs
;
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
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.SelectionEvent
;
20 import org
.eclipse
.swt
.events
.SelectionListener
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Control
;
25 import org
.eclipse
.swt
.widgets
.Group
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Shell
;
28 import org
.eclipse
.swt
.widgets
.Text
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.SDWidget
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.util
.Messages
;
34 * Dialog box for entering minimum and maximum time range for time compression bar.
38 * @author Bernd Hufmann
41 public class MinMaxDialog
extends Dialog
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * Text field for minimum.
49 private Text fMinText
;
51 * Text field for maximum.
53 private Text fMaxText
;
55 * Text field for scale.
57 private Text fScaleText
;
59 * Text field for precision.
61 private Text fPrecisionText
;
63 * The sequence diagram widget reference.
65 private SDWidget fSdWidget
;
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
71 * Standard constructor.
72 * @param shell The shell
73 * @param viewer The sequence diagram widget reference.
75 public MinMaxDialog(Shell shell
, SDWidget viewer
) {
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
84 * Method to create a grid data base on horizontal span.
85 * @param span The horizontal span
86 * @return a grid data object
88 protected GridData
newGridData(int span
) {
89 GridData data
= new GridData(GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
);
90 data
.horizontalSpan
= span
;
95 protected Control
createDialogArea(Composite p
) {
96 p
.getShell().setText(Messages
.SequenceDiagram_TimeCompressionBarConfig
);
97 Composite parent
= (Composite
) super.createDialogArea(p
);
99 GridLayout parentLayout
= new GridLayout();
100 parentLayout
.numColumns
= 6;
101 parent
.setLayout(parentLayout
);
103 Group g1
= new Group(parent
, SWT
.SHADOW_NONE
);
104 g1
.setLayoutData(newGridData(3));
105 GridLayout g1layout
= new GridLayout();
106 g1layout
.numColumns
= 3;
107 g1
.setLayout(g1layout
);
109 Label minLabel
= new Label(g1
, SWT
.RADIO
);
110 minLabel
.setText(Messages
.SequenceDiagram_MinTime
);
111 minLabel
.setLayoutData(newGridData(1));
113 fMinText
= new Text(g1
, SWT
.SINGLE
| SWT
.BORDER
);
114 fMinText
.setLayoutData(newGridData(2));
115 fMinText
.setText(String
.valueOf(fSdWidget
.getFrame().getMinTime().getValue()));
117 Label maxLabel
= new Label(g1
, SWT
.RADIO
);
118 maxLabel
.setText(Messages
.SequenceDiagram_MaxTime
);
119 maxLabel
.setLayoutData(newGridData(1));
121 fMaxText
= new Text(g1
, SWT
.SINGLE
| SWT
.BORDER
);
122 fMaxText
.setLayoutData(newGridData(2));
123 fMaxText
.setText(String
.valueOf(fSdWidget
.getFrame().getMaxTime().getValue()));
125 Label scaleLabel
= new Label(g1
, SWT
.RADIO
);
126 scaleLabel
.setText(Messages
.SequenceDiagram_Scale
);
127 scaleLabel
.setLayoutData(newGridData(1));
129 fScaleText
= new Text(g1
, SWT
.SINGLE
| SWT
.BORDER
);
130 fScaleText
.setLayoutData(newGridData(2));
131 fScaleText
.setText(String
.valueOf(fSdWidget
.getFrame().getMinTime().getScale()));
134 Label precisionLabel
= new Label(g1
, SWT
.RADIO
);
135 precisionLabel
.setText(Messages
.SequenceDiagram_Precision
);
136 precisionLabel
.setLayoutData(newGridData(1));
138 fPrecisionText
= new Text(g1
, SWT
.SINGLE
| SWT
.BORDER
);
139 fPrecisionText
.setLayoutData(newGridData(2));
140 fPrecisionText
.setText(String
.valueOf(fSdWidget
.getFrame().getMinTime().getPrecision()));
146 protected void okPressed() {
152 min
= Long
.parseLong(fMinText
.getText());
153 max
= Long
.parseLong(fMaxText
.getText());
154 scale
= Integer
.parseInt(fScaleText
.getText());
155 precision
= Integer
.parseInt(fPrecisionText
.getText());
157 fSdWidget
.getFrame().setMax(new TmfTimestamp(max
, scale
, precision
));
158 fSdWidget
.getFrame().setMin(new TmfTimestamp(min
, scale
, precision
));
163 } catch (Exception e
) {
164 MessageDialog
.openError(getShell(), Messages
.SequenceDiagram_Error
, Messages
.SequenceDiagram_InvalidRange
);
169 protected void createButtonsForButtonBar(Composite parent
) {
170 super.createButtonsForButtonBar(parent
);
171 createButton(parent
, IDialogConstants
.CLIENT_ID
, Messages
.SequenceDiagram_Default
, false);
172 getButton(IDialogConstants
.CLIENT_ID
).addSelectionListener(new SelectionListener() {
175 public void widgetSelected(SelectionEvent e
) {
176 fSdWidget
.getFrame().resetCustomMinMax();
177 fMinText
.setText(String
.valueOf(fSdWidget
.getFrame().getMinTime().getValue()));
178 fMaxText
.setText(String
.valueOf(fSdWidget
.getFrame().getMaxTime().getValue()));
179 fScaleText
.setText(String
.valueOf(fSdWidget
.getFrame().getMinTime().getScale()));
180 fPrecisionText
.setText(String
.valueOf(fSdWidget
.getFrame().getMinTime().getPrecision()));
181 fMaxText
.getParent().layout(true);
185 public void widgetDefaultSelected(SelectionEvent e
) {