- Timestamp:
- 08/17/12 11:38:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/DataTabComposite.java
r526 r570 1 1 2 package de.ugoe.cs.quest.ui.swt; 2 3 … … 19 20 public class DataTabComposite extends Composite { 20 21 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 } 22 List dataList; 100 23 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 } 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 } 112 117 113 118 }
Note: See TracChangeset
for help on using the changeset viewer.