[570] | 1 |
|
---|
[526] | 2 | package de.ugoe.cs.quest.ui.swt;
|
---|
| 3 |
|
---|
| 4 | import org.eclipse.swt.SWT;
|
---|
| 5 | import org.eclipse.swt.widgets.Composite;
|
---|
| 6 | import org.eclipse.swt.widgets.Button;
|
---|
| 7 | import org.eclipse.swt.widgets.FileDialog;
|
---|
| 8 | import org.eclipse.swt.widgets.List;
|
---|
| 9 | import org.eclipse.swt.widgets.MessageBox;
|
---|
| 10 | import org.eclipse.swt.layout.GridLayout;
|
---|
| 11 | import org.eclipse.swt.layout.GridData;
|
---|
| 12 |
|
---|
| 13 | import de.ugoe.cs.quest.ui.GlobalDataContainer;
|
---|
| 14 | import de.ugoe.cs.util.StringTools;
|
---|
| 15 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
| 16 |
|
---|
| 17 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
| 18 | import org.eclipse.swt.events.SelectionEvent;
|
---|
| 19 |
|
---|
| 20 | public class DataTabComposite extends Composite {
|
---|
| 21 |
|
---|
[570] | 22 | List dataList;
|
---|
[526] | 23 |
|
---|
[570] | 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 | }
|
---|
[526] | 34 |
|
---|
[570] | 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 |
|
---|
[526] | 118 | }
|
---|