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

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