tmf: log when an error message is displayed in a MessageBox
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / uml2sd / dialogs / MinMaxDialog.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2014 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.tracecompass.tmf.ui.views.uml2sd.dialogs;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.events.SelectionListener;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Group;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.swt.widgets.Text;
28 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
29 import org.eclipse.tracecompass.tmf.ui.project.model.TraceUtils;
30 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDWidget;
31 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.util.Messages;
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 * Text field for minimum.
48 */
49 private Text fMinText;
50 /**
51 * Text field for maximum.
52 */
53 private Text fMaxText;
54 /**
55 * Text field for scale.
56 */
57 private Text fScaleText;
58 /**
59 * Text field for precision (legacy, value will be ignored).
60 */
61 private Text fPrecisionText;
62 /**
63 * The sequence diagram widget reference.
64 */
65 private SDWidget fSdWidget;
66
67 // ------------------------------------------------------------------------
68 // Constructor
69 // ------------------------------------------------------------------------
70 /**
71 * Standard constructor.
72 * @param shell The shell
73 * @param viewer The sequence diagram widget reference.
74 */
75 public MinMaxDialog(Shell shell, SDWidget viewer) {
76 super(shell);
77 fSdWidget = viewer;
78 }
79
80 // ------------------------------------------------------------------------
81 // Methods
82 // ------------------------------------------------------------------------
83 /**
84 * Method to create a grid data base on horizontal span.
85 * @param span The horizontal span
86 * @return a grid data object
87 */
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;
91 return data;
92 }
93
94 @Override
95 protected Control createDialogArea(Composite p) {
96 p.getShell().setText(Messages.SequenceDiagram_TimeCompressionBarConfig);
97 Composite parent = (Composite) super.createDialogArea(p);
98
99 GridLayout parentLayout = new GridLayout();
100 parentLayout.numColumns = 6;
101 parent.setLayout(parentLayout);
102
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);
108
109 Label minLabel = new Label(g1, SWT.RADIO);
110 minLabel.setText(Messages.SequenceDiagram_MinTime);
111 minLabel.setLayoutData(newGridData(1));
112
113 fMinText = new Text(g1, SWT.SINGLE | SWT.BORDER);
114 fMinText.setLayoutData(newGridData(2));
115 fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue()));
116
117 Label maxLabel = new Label(g1, SWT.RADIO);
118 maxLabel.setText(Messages.SequenceDiagram_MaxTime);
119 maxLabel.setLayoutData(newGridData(1));
120
121 fMaxText = new Text(g1, SWT.SINGLE | SWT.BORDER);
122 fMaxText.setLayoutData(newGridData(2));
123 fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue()));
124
125 Label scaleLabel = new Label(g1, SWT.RADIO);
126 scaleLabel.setText(Messages.SequenceDiagram_Scale);
127 scaleLabel.setLayoutData(newGridData(1));
128
129 fScaleText = new Text(g1, SWT.SINGLE | SWT.BORDER);
130 fScaleText.setLayoutData(newGridData(2));
131 fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale()));
132
133
134 Label precisionLabel = new Label(g1, SWT.RADIO);
135 precisionLabel.setText(Messages.SequenceDiagram_Precision);
136 precisionLabel.setLayoutData(newGridData(1));
137
138 fPrecisionText = new Text(g1, SWT.SINGLE | SWT.BORDER);
139 fPrecisionText.setLayoutData(newGridData(2));
140 fPrecisionText.setText(String.valueOf(0));
141
142 return parent;
143 }
144
145 @Override
146 protected void okPressed() {
147 long min = 0;
148 long max = 0;
149 int scale = 0;
150 try {
151 min = Long.parseLong(fMinText.getText());
152 max = Long.parseLong(fMaxText.getText());
153 scale = Integer.parseInt(fScaleText.getText());
154
155 fSdWidget.getFrame().setMax(new TmfTimestamp(max, scale));
156 fSdWidget.getFrame().setMin(new TmfTimestamp(min, scale));
157
158 fSdWidget.redraw();
159
160 super.okPressed();
161 } catch (Exception e) {
162 TraceUtils.displayErrorMsg(Messages.SequenceDiagram_Error, Messages.SequenceDiagram_InvalidRange);
163 }
164 }
165
166 @Override
167 protected void createButtonsForButtonBar(Composite parent) {
168 super.createButtonsForButtonBar(parent);
169 createButton(parent, IDialogConstants.CLIENT_ID, Messages.SequenceDiagram_Default, false);
170 getButton(IDialogConstants.CLIENT_ID).addSelectionListener(new SelectionListener() {
171
172 @Override
173 public void widgetSelected(SelectionEvent e) {
174 fSdWidget.getFrame().resetCustomMinMax();
175 fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue()));
176 fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue()));
177 fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale()));
178 fPrecisionText.setText(String.valueOf(0));
179 fMaxText.getParent().layout(true);
180 }
181
182 @Override
183 public void widgetDefaultSelected(SelectionEvent e) {
184 // nothing to do
185 }
186 });
187 }
188 }
This page took 0.034919 seconds and 5 git commands to generate.