2
* This file is part of Zaluum
4
* Zaluum is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
9
* Zaluum is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with Zaluum. If not, see <http://www.gnu.org/licenses/>.
17
* Copyright 2008,2009 Frederic Perez Ordeig
19
package org.zaluum.ide.editor.cmodel;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jface.dialogs.TitleAreaDialog;
23
import org.eclipse.jface.viewers.ArrayContentProvider;
24
import org.eclipse.jface.viewers.ComboViewer;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.viewers.LabelProvider;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.widgets.Combo;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Control;
32
import org.eclipse.swt.widgets.Shell;
33
import org.eclipse.ui.statushandlers.StatusManager;
34
import org.zaluum.cmodel.CType;
35
import org.zaluum.cmodel.EnumCType;
36
import org.zaluum.cmodel.IntCType;
37
import org.zaluum.cmodel.Value;
38
import org.zaluum.cmodel.CType.ValueCreationException;
39
import org.zaluum.ide.util.Activator;
41
public class ValueSelectDialog extends TitleAreaDialog {
44
private ComboViewer vwr;
45
private final CType cType;
48
public ValueSelectDialog(Shell parentShell, CType cType) {
54
protected Control createDialogArea(Composite p) {
55
Composite c = (Composite) super.createDialogArea(p);
56
setTitle("Value selection");
57
setMessage("Select a value to push");
58
GridData gd = new GridData(SWT.LEFT, SWT.TOP, true, true);
59
if (cType instanceof IntCType){
60
combo = new Combo(c,SWT.DROP_DOWN);
61
combo.setLayoutData(gd);
62
}else if (cType instanceof EnumCType)
64
combo = new Combo(c, SWT.DROP_DOWN|SWT.READ_ONLY);
65
combo.setLayoutData(gd);
66
vwr = new ComboViewer(combo);
67
vwr.setContentProvider(ArrayContentProvider.getInstance());
68
vwr.setLabelProvider(new LabelProvider());
69
vwr.setInput(((EnumCType) cType).getMembers().toArray());
76
protected void okPressed() {
78
if (cType instanceof IntCType) {
79
int i = Integer.parseInt(combo.getText());
80
result = IntCType.Int.createValueFromInt(i);
81
} else if (cType instanceof EnumCType){
82
Object selected = ((IStructuredSelection) vwr.getSelection())
84
result = (Value) selected;
86
} catch (NumberFormatException e1) {
87
StatusManager.getManager().handle(
88
new Status(Status.WARNING, Activator.PLUGIN_ID,
89
"Not a number", e1), StatusManager.SHOW);
90
} catch (ValueCreationException e) {
91
StatusManager.getManager().handle(
92
new Status(Status.WARNING, Activator.PLUGIN_ID,
93
"Cannot create value", e), StatusManager.SHOW);
99
public Value getResult() {
b'\\ No newline at end of file'