Commit | Line | Data |
---|---|---|
73005152 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2005, 2008, 2011 IBM Corporation and others. | |
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 | * $Id: MinMaxDialog.java,v 1.2 2008/01/24 02:28:51 apnan Exp $ | |
8 | * | |
9 | * Contributors: | |
10 | * IBM - Initial API and implementation | |
11 | * Bernd Hufmann - Updated for TMF | |
12 | **********************************************************************/ | |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.util; | |
14 | ||
15 | import org.eclipse.jface.dialogs.Dialog; | |
16 | import org.eclipse.jface.dialogs.IDialogConstants; | |
17 | import org.eclipse.jface.dialogs.MessageDialog; | |
6c13869b | 18 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
73005152 BH |
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget; |
20 | import org.eclipse.swt.SWT; | |
21 | import org.eclipse.swt.events.SelectionEvent; | |
22 | import org.eclipse.swt.events.SelectionListener; | |
23 | import org.eclipse.swt.layout.GridData; | |
24 | import org.eclipse.swt.layout.GridLayout; | |
25 | import org.eclipse.swt.widgets.Composite; | |
26 | import org.eclipse.swt.widgets.Control; | |
27 | import org.eclipse.swt.widgets.Group; | |
28 | import org.eclipse.swt.widgets.Label; | |
29 | import org.eclipse.swt.widgets.Shell; | |
30 | import org.eclipse.swt.widgets.Text; | |
31 | ||
32 | /** | |
33 | * @author sveyrier | |
34 | * | |
35 | */ | |
36 | public class MinMaxDialog extends Dialog { | |
37 | ||
38 | protected Label minLabel; | |
39 | ||
40 | protected Label maxLabel; | |
41 | ||
42 | protected Label scaleLabel; | |
43 | ||
44 | protected Label precisionLabel; | |
45 | ||
46 | protected Text minText; | |
47 | ||
48 | protected Text maxText; | |
49 | ||
50 | protected Text scaleText; | |
51 | ||
52 | protected Text precisionText; | |
53 | ||
54 | SDWidget sdWidget; | |
55 | ||
56 | public MinMaxDialog(Shell s, SDWidget v) { | |
57 | super(s); | |
58 | sdWidget = v; | |
59 | } | |
60 | ||
61 | protected GridData newGridData(int span) { | |
62 | GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); | |
63 | data.horizontalSpan = span; | |
64 | return data; | |
65 | } | |
66 | ||
67 | @Override | |
68 | protected Control createDialogArea(Composite p) { | |
69 | p.getShell().setText(SDMessages._123); | |
70 | Composite parent = (Composite) super.createDialogArea(p); | |
71 | ||
72 | GridLayout parentLayout = new GridLayout(); | |
73 | parentLayout.numColumns = 6; | |
74 | parent.setLayout(parentLayout); | |
75 | ||
76 | Group g1 = new Group(parent, SWT.SHADOW_NONE); | |
77 | g1.setLayoutData(newGridData(3)); | |
78 | GridLayout g1layout = new GridLayout(); | |
79 | g1layout.numColumns = 3; | |
80 | g1.setLayout(g1layout); | |
81 | ||
82 | minLabel = new Label(g1, SWT.RADIO); | |
83 | minLabel.setText(SDMessages._124); | |
84 | minLabel.setLayoutData(newGridData(1)); | |
85 | ||
86 | minText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
87 | minText.setLayoutData(newGridData(2)); | |
88 | minText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getValue())); | |
89 | ||
90 | maxLabel = new Label(g1, SWT.RADIO); | |
91 | maxLabel.setText(SDMessages._125); | |
92 | maxLabel.setLayoutData(newGridData(1)); | |
93 | ||
94 | maxText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
95 | maxText.setLayoutData(newGridData(2)); | |
96 | maxText.setText(String.valueOf(sdWidget.getFrame().getMaxTime().getValue())); | |
97 | ||
98 | scaleLabel = new Label(g1, SWT.RADIO); | |
99 | scaleLabel.setText(SDMessages._136); | |
100 | scaleLabel.setLayoutData(newGridData(1)); | |
101 | ||
102 | scaleText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
103 | scaleText.setLayoutData(newGridData(2)); | |
104 | scaleText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getScale())); | |
105 | ||
106 | ||
107 | precisionLabel = new Label(g1, SWT.RADIO); | |
108 | precisionLabel.setText(SDMessages._137); | |
109 | precisionLabel.setLayoutData(newGridData(1)); | |
110 | ||
111 | precisionText = new Text(g1, SWT.SINGLE | SWT.BORDER); | |
112 | precisionText.setLayoutData(newGridData(2)); | |
113 | precisionText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getPrecision())); | |
114 | ||
115 | return parent; | |
116 | } | |
117 | ||
118 | @Override | |
119 | protected void okPressed() { | |
120 | // double min=0; | |
121 | // double max=0; | |
122 | long min = 0; | |
123 | long max = 0; | |
5179fc01 FC |
124 | int scale = 0; |
125 | int precision = 0; | |
73005152 BH |
126 | try { |
127 | min = Long.parseLong(minText.getText()); | |
128 | max = Long.parseLong(maxText.getText()); | |
5179fc01 FC |
129 | scale = Integer.parseInt(scaleText.getText()); |
130 | precision = Integer.parseInt(precisionText.getText()); | |
73005152 BH |
131 | |
132 | sdWidget.getFrame().setMax(new TmfTimestamp(max, scale, precision)); | |
133 | sdWidget.getFrame().setMin(new TmfTimestamp(min, scale, precision)); | |
134 | ||
135 | sdWidget.redraw(); | |
136 | ||
137 | super.okPressed(); | |
138 | } catch (Exception e) { | |
139 | MessageDialog.openError(getShell(), SDMessages._98, SDMessages._99); | |
140 | } | |
141 | } | |
142 | ||
143 | @Override | |
144 | protected void createButtonsForButtonBar(Composite parent) { | |
145 | super.createButtonsForButtonBar(parent); | |
146 | createButton(parent, IDialogConstants.CLIENT_ID, SDMessages._126, false); | |
147 | getButton(IDialogConstants.CLIENT_ID).addSelectionListener(new SelectionListener() { | |
148 | ||
149 | @Override | |
150 | public void widgetSelected(SelectionEvent e) { | |
151 | sdWidget.getFrame().resetCustomMinMax(); | |
152 | minText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getValue())); | |
153 | maxText.setText(String.valueOf(sdWidget.getFrame().getMaxTime().getValue())); | |
154 | scaleText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getScale())); | |
155 | precisionText.setText(String.valueOf(sdWidget.getFrame().getMinTime().getPrecision())); | |
156 | maxText.getParent().layout(true); | |
157 | } | |
158 | ||
159 | @Override | |
160 | public void widgetDefaultSelected(SelectionEvent e) { | |
161 | ||
162 | } | |
163 | ||
164 | }); | |
165 | } | |
166 | } |