Changeset 7695

Show
Ignore:
Timestamp:
05/30/08 16:52:01 (5 years ago)
Author:
Snyder.Jason
Message:

fixed logic so it actually works

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/dialogs/nodeBooterDialog.java

    r7691 r7695  
    66import org.eclipse.jface.dialogs.Dialog; 
    77import org.eclipse.jface.dialogs.IDialogConstants; 
     8import org.eclipse.jface.dialogs.MessageDialog; 
    89import org.eclipse.swt.SWT; 
     10import org.eclipse.swt.events.ModifyEvent; 
     11import org.eclipse.swt.events.ModifyListener; 
    912import org.eclipse.swt.events.SelectionAdapter; 
    1013import org.eclipse.swt.events.SelectionEvent; 
     14import org.eclipse.swt.events.SelectionListener; 
    1115import org.eclipse.swt.layout.GridLayout; 
    1216import org.eclipse.swt.widgets.Button; 
     
    2428public class nodeBooterDialog extends Dialog 
    2529{ 
    26         private String deviceManagerFilePath = "/sdr/nodes/default_GPP_node/"; 
     30 
    2731        private String deviceManagerFileName; 
    28  
    29         private String domainManagerFilePath = "                            "; 
     32        private String deviceManagerFile = "/sdr/nodes/default_GPP_node/DeviceManager.dcd.xml"; 
     33         
     34 
    3035        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 
    3439 
    3540        private String[] command; 
     
    4247 
    4348        private ProcessBuilder processBuilder; 
     49    private Button specifyDeviceManager; 
     50    private Button specifyDomainManager; 
     51    private Button deviceBrowseButton; 
     52    private Button domainBrowseButton; 
    4453 
    4554 
     
    5463                comp.setLayout(new GridLayout(3, false)); 
    5564                 
    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); 
    6092                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); 
    6397                deviceBrowseButton.setText("Browse"); 
     98                 
    6499                deviceBrowseButton.addSelectionListener(new SelectionAdapter() 
    65100                { 
     
    67102                        { 
    68103 
    69                                 defaultDeviceManager = false; 
    70104                                deviceManagerSelector = new FileDialog(comp.getShell(), SWT.SINGLE); 
    71105                                deviceManagerSelector.setText("Select a Device Manager"); 
     
    77111 
    78112                                //open the dialog and get the full path and file name 
    79                                 deviceManagerFilePath = deviceManagerSelector.open(); 
     113                                deviceManagerFile = deviceManagerSelector.open(); 
    80114                                deviceManagerFileName = deviceManagerSelector.getFileName(); 
    81  
    82                                 deviceManagerText.setSize(200, 20); 
     115                                 
     116                                 
     117 
     118                                //deviceManagerText.setSize(200, 20); 
    83119                                deviceManagerText.setText(deviceManagerFileName); 
    84120 
     
    87123                }); 
    88124 
    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); 
    96156                domainBrowseButton.setText("Browse"); 
     157                 
    97158                domainBrowseButton.addSelectionListener(new SelectionAdapter() 
    98159                { 
     
    100161                        { 
    101162 
    102                                 defaultDomainManager = false; 
    103163                                domainManagerSelector = new FileDialog(comp.getShell(), SWT.SINGLE); 
    104164                                domainManagerSelector.setText("Select a Domain Manager"); 
    105                                 domainManagerSelector.setFilterPath("/sdr/nodes/default_GPP_node/"); 
    106  
    107                                 //only allow .dcd.xml files to be chosen 
    108                                 String[] filterExt = {"*.dcd.xml"}; 
     165                                domainManagerSelector.setFilterPath("/sdr/domain/"); 
     166 
     167                                //only allow .dmd.xml files to be chosen 
     168                                String[] filterExt = {"*.dmd.xml"}; 
    109169                                domainManagerSelector.setFilterExtensions(filterExt); 
    110170 
    111171                                //open the dialog and get the full path and file name 
    112                                 domainManagerFilePath = domainManagerSelector.open(); 
     172                                domainManagerFile = domainManagerSelector.open(); 
    113173                                domainManagerFileName = domainManagerSelector.getFileName(); 
    114174 
    115                                 domainManagerText.setSize(200, 20); 
     175                                //domainManagerText.setSize(200, 20); 
    116176                                domainManagerText.setText(domainManagerFileName); 
    117177 
     
    127187                if(buttonId == IDialogConstants.OK_ID) 
    128188                { 
    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()) 
    151196                                { 
    152                     log.debug("buttonPressed(): " + s); 
     197                                    errorMsg("NodeBooter Error", "Please specify a device manager or a domain manager"); 
     198                                    exit = false; 
    153199                                } 
    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 
    166201                                { 
    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); 
    168222                                } 
    169                                 while (scan.hasNextLine()) 
    170                                 { 
    171                                         out.println(scan.nextLine()); 
    172                                 } 
    173223                        } 
    174224                        catch (Exception e) 
     
    178228 
    179229                        //call the super to close the dialog 
     230                        if(exit) 
     231                            super.buttonPressed(buttonId); 
     232                        else 
     233                            exit = true; 
     234                 
     235                } 
     236                else 
     237                { 
    180238                        super.buttonPressed(buttonId); 
    181239                } 
    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    } 
    187253 
    188254    private static final Logger log =