Changeset 846 for trunk/quest-ui-swt/src/main
- Timestamp:
- 09/21/12 11:06:24 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/ShowGuiModelDialog.java
r777 r846 12 12 import org.eclipse.swt.widgets.Dialog; 13 13 import org.eclipse.swt.widgets.Display; 14 import org.eclipse.swt.widgets.MessageBox; 14 15 import org.eclipse.swt.widgets.Shell; 15 16 import org.eclipse.swt.widgets.Tree; … … 18 19 import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 19 20 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 21 import de.ugoe.cs.util.console.Console; 22 20 23 import org.eclipse.swt.widgets.Label; 21 24 … … 72 75 shell.setText(getText()); 73 76 74 shell.setLayout(new GridLayout( 2, false));77 shell.setLayout(new GridLayout(3, false)); 75 78 76 guiTree = new Tree(shell, SWT.BORDER );77 guiTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));79 guiTree = new Tree(shell, SWT.BORDER | SWT.MULTI); 80 guiTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 78 81 79 82 buildGuiTree(); … … 96 99 }); 97 100 btnCollapseAll.setText("Collapse all"); 101 102 Button btnMerge = new Button(shell, SWT.NONE); 103 btnMerge.addSelectionListener(new SelectionAdapter() { 104 @Override 105 public void widgetSelected(SelectionEvent e) { 106 mergeSelectedNode(guiTree); 107 } 108 }); 109 btnMerge.setText("Merge"); 110 111 //new Label(shell, SWT.NONE); 112 new Label(shell, SWT.NONE); 98 113 new Label(shell, SWT.NONE); 99 114 new Label(shell, SWT.NONE); … … 105 120 TreeItem child = new TreeItem(guiTree, SWT.NULL); 106 121 child.setText(element.toString()); 122 child.setData(element); 107 123 buildGuiTree(child, model.getChildren(element)); 108 124 } … … 113 129 TreeItem child = new TreeItem(currentParent, SWT.NULL); 114 130 child.setText(element.toString()); 131 child.setData(element); 115 132 buildGuiTree(child, model.getChildren(element)); 116 133 } … … 129 146 } 130 147 } 148 149 private void mergeSelectedNode(Tree tree) { 150 TreeItem[] selectedNodes = tree.getSelection(); 151 if( selectedNodes.length<2 ) { 152 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 153 messageBox.setMessage("Must select at least two nodes to merge!"); 154 messageBox.setText("Error"); 155 messageBox.open(); 156 return; 157 } 158 159 TreeItem firstParent = selectedNodes[0].getParentItem(); 160 for( int i=1 ; i<selectedNodes.length ; i++ ) { 161 if( firstParent!=selectedNodes[i].getParentItem() ) { 162 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 163 messageBox.setMessage("All selected nodes must have the same parent!"); 164 messageBox.setText("Error"); 165 messageBox.open(); 166 return; 167 } 168 } 169 170 try { 171 // try to merge the elements 172 IGUIElement firstElement = (IGUIElement) selectedNodes[0].getData(); 173 for( int i=1 ; i<selectedNodes.length ; i++ ) { 174 model.mergeGUIElements(firstElement, (IGUIElement) selectedNodes[i].getData()); 175 } 176 } catch( IllegalArgumentException e) { 177 Console.logException(e); 178 } 179 180 // update visualization of the model 181 firstParent.removeAll(); 182 buildGuiTree(firstParent, model.getChildren((IGUIElement) firstParent.getData())); 183 firstParent.setExpanded(true); 184 } 131 185 132 186 }
Note: See TracChangeset
for help on using the changeset viewer.