Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2005, 2014 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 | |
2bdf0193 | 13 | package org.eclipse.tracecompass.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; | |
73005152 BH |
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; | |
2bdf0193 AM |
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; | |
73005152 BH |
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 | // ------------------------------------------------------------------------ | |
df0b8ff4 | 46 | /** |
c8422608 | 47 | * Text field for minimum. |
df0b8ff4 | 48 | */ |
cab6c8ff | 49 | private Text fMinText; |
df0b8ff4 | 50 | /** |
c8422608 | 51 | * Text field for maximum. |
df0b8ff4 | 52 | */ |
cab6c8ff | 53 | private Text fMaxText; |
df0b8ff4 | 54 | /** |
c8422608 | 55 | * Text field for scale. |
df0b8ff4 | 56 | */ |
cab6c8ff | 57 | private Text fScaleText; |
df0b8ff4 | 58 | /** |
065cc19b | 59 | * Text field for precision (legacy, value will be ignored). |
df0b8ff4 | 60 | */ |
cab6c8ff | 61 | private Text fPrecisionText; |
df0b8ff4 BH |
62 | /** |
63 | * The sequence diagram widget reference. | |
64 | */ | |
cab6c8ff | 65 | private SDWidget fSdWidget; |
df0b8ff4 BH |
66 | |
67 | // ------------------------------------------------------------------------ | |
68 | // Constructor | |
69 | // ------------------------------------------------------------------------ | |
70 | /** | |
71 | * Standard constructor. | |
72 | * @param shell The shell | |
c8422608 | 73 | * @param viewer The sequence diagram widget reference. |
df0b8ff4 BH |
74 | */ |
75 | public MinMaxDialog(Shell shell, SDWidget viewer) { | |
76 | super(shell); | |
eb63f5ff | 77 | fSdWidget = viewer; |
73005152 BH |
78 | } |
79 | ||
df0b8ff4 BH |
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 | */ | |
73005152 BH |
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) { | |
92330441 | 96 | p.getShell().setText(Messages.SequenceDiagram_TimeCompressionBarConfig); |
73005152 BH |
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 | ||
f26e290b BH |
109 | Label minLabel = new Label(g1, SWT.RADIO); |
110 | minLabel.setText(Messages.SequenceDiagram_MinTime); | |
111 | minLabel.setLayoutData(newGridData(1)); | |
73005152 | 112 | |
eb63f5ff BH |
113 | fMinText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
114 | fMinText.setLayoutData(newGridData(2)); | |
115 | fMinText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getValue())); | |
73005152 | 116 | |
f26e290b BH |
117 | Label maxLabel = new Label(g1, SWT.RADIO); |
118 | maxLabel.setText(Messages.SequenceDiagram_MaxTime); | |
119 | maxLabel.setLayoutData(newGridData(1)); | |
73005152 | 120 | |
eb63f5ff BH |
121 | fMaxText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
122 | fMaxText.setLayoutData(newGridData(2)); | |
123 | fMaxText.setText(String.valueOf(fSdWidget.getFrame().getMaxTime().getValue())); | |
73005152 | 124 | |
f26e290b BH |
125 | Label scaleLabel = new Label(g1, SWT.RADIO); |
126 | scaleLabel.setText(Messages.SequenceDiagram_Scale); | |
127 | scaleLabel.setLayoutData(newGridData(1)); | |
73005152 | 128 | |
eb63f5ff BH |
129 | fScaleText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
130 | fScaleText.setLayoutData(newGridData(2)); | |
131 | fScaleText.setText(String.valueOf(fSdWidget.getFrame().getMinTime().getScale())); | |
73005152 | 132 | |
c8422608 | 133 | |
f26e290b BH |
134 | Label precisionLabel = new Label(g1, SWT.RADIO); |
135 | precisionLabel.setText(Messages.SequenceDiagram_Precision); | |
136 | precisionLabel.setLayoutData(newGridData(1)); | |
73005152 | 137 | |
eb63f5ff BH |
138 | fPrecisionText = new Text(g1, SWT.SINGLE | SWT.BORDER); |
139 | fPrecisionText.setLayoutData(newGridData(2)); | |
065cc19b | 140 | fPrecisionText.setText(String.valueOf(0)); |
73005152 BH |
141 | |
142 | return parent; | |
143 | } | |
144 | ||
145 | @Override | |
146 | protected void okPressed() { | |
73005152 BH |
147 | long min = 0; |
148 | long max = 0; | |
5179fc01 | 149 | int scale = 0; |
73005152 | 150 | try { |
eb63f5ff BH |
151 | min = Long.parseLong(fMinText.getText()); |
152 | max = Long.parseLong(fMaxText.getText()); | |
153 | scale = Integer.parseInt(fScaleText.getText()); | |
73005152 | 154 | |
065cc19b AM |
155 | fSdWidget.getFrame().setMax(new TmfTimestamp(max, scale)); |
156 | fSdWidget.getFrame().setMin(new TmfTimestamp(min, scale)); | |
73005152 | 157 | |
eb63f5ff | 158 | fSdWidget.redraw(); |
73005152 BH |
159 | |
160 | super.okPressed(); | |
161 | } catch (Exception e) { | |
92330441 | 162 | MessageDialog.openError(getShell(), Messages.SequenceDiagram_Error, Messages.SequenceDiagram_InvalidRange); |
73005152 BH |
163 | } |
164 | } | |
165 | ||
166 | @Override | |
167 | protected void createButtonsForButtonBar(Composite parent) { | |
168 | super.createButtonsForButtonBar(parent); | |
92330441 | 169 | createButton(parent, IDialogConstants.CLIENT_ID, Messages.SequenceDiagram_Default, false); |
73005152 | 170 | getButton(IDialogConstants.CLIENT_ID).addSelectionListener(new SelectionListener() { |
11252342 | 171 | |
73005152 BH |
172 | @Override |
173 | public void widgetSelected(SelectionEvent e) { | |
eb63f5ff BH |
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())); | |
065cc19b | 178 | fPrecisionText.setText(String.valueOf(0)); |
eb63f5ff | 179 | fMaxText.getParent().layout(true); |
73005152 BH |
180 | } |
181 | ||
182 | @Override | |
183 | public void widgetDefaultSelected(SelectionEvent e) { | |
df0b8ff4 | 184 | // nothing to do |
73005152 | 185 | } |
73005152 BH |
186 | }); |
187 | } | |
188 | } |