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