source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/DataTabComposite.java @ 922

Last change on this file since 922 was 922, checked in by sherbold, 12 years ago
  • renaming of packages from de.ugoe.cs.quest to de.ugoe.cs.autoquest
  • Property svn:mime-type set to text/plain
File size: 4.2 KB
Line 
1package de.ugoe.cs.autoquest.ui.swt;
2
3import org.eclipse.swt.SWT;
4import org.eclipse.swt.widgets.Composite;
5import org.eclipse.swt.widgets.Button;
6import org.eclipse.swt.widgets.FileDialog;
7import org.eclipse.swt.widgets.List;
8import org.eclipse.swt.widgets.MessageBox;
9import org.eclipse.swt.layout.GridLayout;
10import org.eclipse.swt.layout.GridData;
11
12import de.ugoe.cs.util.StringTools;
13import de.ugoe.cs.util.console.CommandExecuter;
14import de.ugoe.cs.util.console.GlobalDataContainer;
15
16import org.eclipse.swt.events.SelectionAdapter;
17import org.eclipse.swt.events.SelectionEvent;
18
19public class DataTabComposite extends Composite {
20
21    List dataList;
22
23    /**
24     * Create the composite.
25     *
26     * @param parent
27     * @param style
28     */
29    public DataTabComposite(Composite parent, int style) {
30        super(parent, style);
31        createContent();
32    }
33
34    private void createContent() {
35        setLayout(new GridLayout(3, false));
36
37        dataList = new List(this, SWT.BORDER | SWT.V_SCROLL);
38        dataList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
39
40        Button btnLoad = new Button(this, SWT.NONE);
41        btnLoad.addSelectionListener(new SelectionAdapter() {
42            @Override
43            public void widgetSelected(SelectionEvent e) {
44                GetObjectNameDialog getObjectNameDialog =
45                    new GetObjectNameDialog(getShell(), SWT.NONE);
46                getObjectNameDialog.open();
47                String objectName = getObjectNameDialog.getObjectName();
48                if ("".equals(objectName)) {
49                    return;
50                }
51                FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
52                String filename = fileDialog.open();
53                if (filename == null) {
54                    return;
55                }
56                String command = "loadObject " + filename + " " + objectName;
57                CommandExecuter.getInstance().exec(command);
58                updateDataList();
59            }
60        });
61        btnLoad.setText("Load");
62
63        Button btnSave = new Button(this, SWT.NONE);
64        btnSave.addSelectionListener(new SelectionAdapter() {
65            @Override
66            public void widgetSelected(SelectionEvent e) {
67                String[] selectedStrings = dataList.getSelection();
68                if (selectedStrings.length == 0) {
69                    SWTHelpers.noSelectionError(getShell());
70                    return;
71                }
72                if (selectedStrings.length > 1) {
73                    MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
74                    messageBox.setText("Error");
75                    messageBox.setMessage("Only one object storable at a time." +
76                        StringTools.ENDLINE + "Please select only one object.");
77                    return;
78                }
79                FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE);
80                String filename = fileDialog.open();
81                if (filename == null) {
82                    return;
83                }
84                String command = "saveObject " + filename + " " + selectedStrings[0];
85                CommandExecuter.getInstance().exec(command);
86            }
87        });
88        btnSave.setText("Save");
89
90        Button btnDelete_2 = new Button(this, SWT.NONE);
91        btnDelete_2.addSelectionListener(new SelectionAdapter() {
92            @Override
93            public void widgetSelected(SelectionEvent e) {
94                if (SWTHelpers.deleteSelectedFromStorage(dataList)) {
95                    updateDataList();
96                }
97                else {
98                    SWTHelpers.noSelectionError(getShell());
99                }
100            }
101        });
102        btnDelete_2.setText("Delete");
103    }
104
105    @Override
106    protected void checkSubclass() {
107        // Disable the check that prevents subclassing of SWT components
108    }
109
110    public void updateDataList() {
111        dataList.removeAll();
112        for (String key : GlobalDataContainer.getInstance().getAllKeys()) {
113            dataList.add(key + " (" + GlobalDataContainer.getInstance().getData(key).getClass().toString() + ")");
114        }
115    }
116
117}
Note: See TracBrowser for help on using the repository browser.