Changeset 7695
- Timestamp:
- 05/30/08 16:52:01 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/dialogs/nodeBooterDialog.java
r7691 r7695 6 6 import org.eclipse.jface.dialogs.Dialog; 7 7 import org.eclipse.jface.dialogs.IDialogConstants; 8 import org.eclipse.jface.dialogs.MessageDialog; 8 9 import org.eclipse.swt.SWT; 10 import org.eclipse.swt.events.ModifyEvent; 11 import org.eclipse.swt.events.ModifyListener; 9 12 import org.eclipse.swt.events.SelectionAdapter; 10 13 import org.eclipse.swt.events.SelectionEvent; 14 import org.eclipse.swt.events.SelectionListener; 11 15 import org.eclipse.swt.layout.GridLayout; 12 16 import org.eclipse.swt.widgets.Button; … … 24 28 public class nodeBooterDialog extends Dialog 25 29 { 26 private String deviceManagerFilePath = "/sdr/nodes/default_GPP_node/"; 30 27 31 private String deviceManagerFileName; 28 29 private String domainManagerFilePath = " "; 32 private String deviceManagerFile = "/sdr/nodes/default_GPP_node/DeviceManager.dcd.xml"; 33 34 30 35 private String domainManagerFileName; 31 32 private boolean defaultDeviceManager = true;33 private boolean defaultDomainManager = true; 36 private String domainManagerFile = "/sdr/domain/DomainManager.dmd.xml"; 37 38 34 39 35 40 private String[] command; … … 42 47 43 48 private ProcessBuilder processBuilder; 49 private Button specifyDeviceManager; 50 private Button specifyDomainManager; 51 private Button deviceBrowseButton; 52 private Button domainBrowseButton; 44 53 45 54 … … 54 63 comp.setLayout(new GridLayout(3, false)); 55 64 56 Label deviceManagerLabel = new Label(comp, SWT.NONE); 57 deviceManagerLabel.setText("Choose a Device Manager"); 58 59 deviceManagerText = new Text(comp, SWT.BORDER); 65 specifyDeviceManager = new Button(comp, SWT.CHECK); 66 specifyDeviceManager.setSelection(true); 67 specifyDeviceManager.addSelectionListener(new SelectionListener() 68 { 69 70 public void widgetDefaultSelected(SelectionEvent e) 71 { 72 // TODO Auto-generated method stub 73 74 } 75 76 public void widgetSelected(SelectionEvent e) 77 { 78 if(nodeBooterDialog.this.specifyDeviceManager.getSelection()) 79 nodeBooterDialog.this.deviceBrowseButton.setEnabled(true); 80 else 81 nodeBooterDialog.this.deviceBrowseButton.setEnabled(false); 82 83 } 84 85 86 }); 87 88 specifyDeviceManager.setText("Choose a Device Manager"); 89 90 91 deviceManagerText = new Text(comp, SWT.BORDER | SWT.READ_ONLY); 60 92 deviceManagerText.setText("DeviceManager.dcd.xml"); 61 62 Button deviceBrowseButton = new Button(comp, SWT.PUSH | SWT.CENTER); 93 94 95 96 deviceBrowseButton = new Button(comp, SWT.PUSH | SWT.CENTER); 63 97 deviceBrowseButton.setText("Browse"); 98 64 99 deviceBrowseButton.addSelectionListener(new SelectionAdapter() 65 100 { … … 67 102 { 68 103 69 defaultDeviceManager = false;70 104 deviceManagerSelector = new FileDialog(comp.getShell(), SWT.SINGLE); 71 105 deviceManagerSelector.setText("Select a Device Manager"); … … 77 111 78 112 //open the dialog and get the full path and file name 79 deviceManagerFile Path= deviceManagerSelector.open();113 deviceManagerFile = deviceManagerSelector.open(); 80 114 deviceManagerFileName = deviceManagerSelector.getFileName(); 81 82 deviceManagerText.setSize(200, 20); 115 116 117 118 //deviceManagerText.setSize(200, 20); 83 119 deviceManagerText.setText(deviceManagerFileName); 84 120 … … 87 123 }); 88 124 89 Label domainManagerLabel = new Label(comp, SWT.NONE); 90 domainManagerLabel.setText("Choose a Domain Manager"); 91 92 domainManagerText = new Text(comp, SWT.BORDER); 93 domainManagerText.setText(""); 94 95 Button domainBrowseButton = new Button(comp, SWT.PUSH | SWT.CENTER); 125 specifyDomainManager = new Button(comp, SWT.CHECK); 126 specifyDomainManager.setSelection(true); 127 specifyDomainManager.addSelectionListener(new SelectionListener() 128 { 129 130 public void widgetDefaultSelected(SelectionEvent e) 131 { 132 // TODO Auto-generated method stub 133 134 } 135 136 public void widgetSelected(SelectionEvent e) 137 { 138 if(nodeBooterDialog.this.specifyDomainManager.getSelection()) 139 nodeBooterDialog.this.domainBrowseButton.setEnabled(true); 140 else 141 nodeBooterDialog.this.domainBrowseButton.setEnabled(false); 142 143 } 144 145 }); 146 147 148 specifyDomainManager.setText("Choose a Domain Manager"); 149 150 151 domainManagerText = new Text(comp, SWT.BORDER | SWT.READ_ONLY); 152 domainManagerText.setText("DomainManager.dmd.xml"); 153 154 155 domainBrowseButton = new Button(comp, SWT.PUSH | SWT.CENTER); 96 156 domainBrowseButton.setText("Browse"); 157 97 158 domainBrowseButton.addSelectionListener(new SelectionAdapter() 98 159 { … … 100 161 { 101 162 102 defaultDomainManager = false;103 163 domainManagerSelector = new FileDialog(comp.getShell(), SWT.SINGLE); 104 164 domainManagerSelector.setText("Select a Domain Manager"); 105 domainManagerSelector.setFilterPath("/sdr/ nodes/default_GPP_node/");106 107 //only allow .d cd.xml files to be chosen108 String[] filterExt = {"*.d cd.xml"};165 domainManagerSelector.setFilterPath("/sdr/domain/"); 166 167 //only allow .dmd.xml files to be chosen 168 String[] filterExt = {"*.dmd.xml"}; 109 169 domainManagerSelector.setFilterExtensions(filterExt); 110 170 111 171 //open the dialog and get the full path and file name 112 domainManagerFile Path= domainManagerSelector.open();172 domainManagerFile = domainManagerSelector.open(); 113 173 domainManagerFileName = domainManagerSelector.getFileName(); 114 174 115 domainManagerText.setSize(200, 20);175 //domainManagerText.setSize(200, 20); 116 176 domainManagerText.setText(domainManagerFileName); 117 177 … … 127 187 if(buttonId == IDialogConstants.OK_ID) 128 188 { 129 Process p; 130 try 131 { 132 //Set the name again in case the user changed the text in the textbox 133 deviceManagerFileName = deviceManagerText.getText(); 134 135 //strip /sdr/ from the filename path because nodebooter has to be run out of /sdr 136 //deviceManagerFilePath = deviceManagerFilePath.substring(5); 137 138 //get just the path of the file without the filename (again, in case the user edited the file name) 139 if(!defaultDeviceManager) 140 deviceManagerFilePath = deviceManagerFilePath.substring(0, deviceManagerFilePath.length() - deviceManagerFileName.length()); 141 142 //place the commands and arguments into an array and create a processBuilder 143 command = new String[] {"sh","-c", "nodeBooter", "-D", "-d", deviceManagerFilePath + deviceManagerFileName}; 144 processBuilder = new ProcessBuilder(command); 145 146 //Set the working directory to /sdr 147 File workingDirectory = new File("/sdr"); 148 processBuilder.directory(workingDirectory); 149 150 for (String s:command) 189 boolean exit = true; 190 try 191 { 192 deviceManagerFile = stripSDR(deviceManagerFile); 193 domainManagerFile = stripSDR(domainManagerFile); 194 195 if( !specifyDeviceManager.getSelection() && !specifyDomainManager.getSelection()) 151 196 { 152 log.debug("buttonPressed(): " + s); 197 errorMsg("NodeBooter Error", "Please specify a device manager or a domain manager"); 198 exit = false; 153 199 } 154 155 //run the command 156 p = processBuilder.start(); 157 158 //catch command output in a scanner 159 Scanner scan = new Scanner(p.getInputStream()); 160 161 //create a new console and add it to the console manager 162 MessageConsole myConsole = OWDPlugin.getOssieConsole(true); 163 MessageConsoleStream out = myConsole.newMessageStream(); 164 165 if (!scan.hasNextLine()) 200 else 166 201 { 167 out.println("No output produced"); 202 if (!specifyDeviceManager.getSelection() && specifyDomainManager.getSelection()) 203 command = new String[] {"nodeBooter", "-D" + domainManagerFile}; 204 else if(specifyDeviceManager.getSelection() && !specifyDomainManager.getSelection()) 205 command = new String[] {"nodeBooter", "-d", deviceManagerFile}; 206 else 207 command = new String[] {"nodeBooter", "-D" + domainManagerFile, "-d", deviceManagerFile}; 208 209 processBuilder = new ProcessBuilder(command); 210 211 //Set the working directory to /sdr 212 File workingDirectory = new File("/sdr"); 213 processBuilder.directory(workingDirectory); 214 215 for (String s:command) 216 { 217 log.debug("buttonPressed(): " + s); 218 } 219 220 boolean result = OWDPlugin.runWithConsole(processBuilder, true); 221 log.debug(result); 168 222 } 169 while (scan.hasNextLine())170 {171 out.println(scan.nextLine());172 }173 223 } 174 224 catch (Exception e) … … 178 228 179 229 //call the super to close the dialog 230 if(exit) 231 super.buttonPressed(buttonId); 232 else 233 exit = true; 234 235 } 236 else 237 { 180 238 super.buttonPressed(buttonId); 181 239 } 182 else 183 { 184 super.buttonPressed(buttonId); 185 } 186 } 240 } 241 242 private String stripSDR(String input) 243 { 244 String output = input; 245 if(input.substring(0, 5).equals("/sdr/")) 246 output = input.substring(5); 247 return output; 248 } 249 private void errorMsg(String title, String message) 250 { 251 MessageDialog.openError(getShell(), title, message); 252 } 187 253 188 254 private static final Logger log =