Changeset 1635 for trunk/modelicaml


Ignore:
Timestamp:
08/20/12 13:13:59 (12 years ago)
Author:
wschamai
Message:

MOD: progress monitor for instantiating a class and validating the components modifications

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modelicaml/org.openmodelica.modelicaml.view.componentstree/src/org/openmodelica/modelicaml/view/componentstree/views/ComponentsTree.java

    r1633 r1635  
    6262import org.eclipse.jface.dialogs.MessageDialog;
    6363import org.eclipse.jface.dialogs.ProgressMonitorDialog;
     64import org.eclipse.jface.operation.IRunnableWithProgress;
    6465import org.eclipse.jface.resource.ImageDescriptor;
    6566import org.eclipse.jface.util.LocalSelectionTransfer;
     
    21792180       
    21802181        // build new tree
    2181         createTree();
     2182        if (sel instanceof IStructuredSelection) {
     2183            EObject selectedElement = null;
     2184       
     2185            if (getCurrentSelections() != null && getCurrentSelections().size() > 0 ) {
     2186                selectedElement = (EObject) adaptSelectedElement(getCurrentSelections().get(0));
     2187                if (selectedElement instanceof Class ) {
     2188                    selectedClass = (Class) selectedElement;
     2189
     2190                    createTree();
     2191                }
     2192            }
     2193        }
    21822194       
    21832195        // set new input from the selection.
     
    22802292            getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener);
    22812293           
    2282             createTree();
     2294            if (sel instanceof IStructuredSelection) {
     2295                EObject selectedElement = null;
     2296           
     2297                if (getCurrentSelections() != null && getCurrentSelections().size() > 0 ) {
     2298                    selectedElement = (EObject) adaptSelectedElement(getCurrentSelections().get(0));
     2299                    if (selectedElement instanceof Class ) {
     2300                        selectedClass = (Class) selectedElement;
     2301
     2302                        createTree();
     2303                    }
     2304                }
     2305            }
     2306           
     2307//          createTree();
    22832308        }
    22842309    }
     
    22922317     */
    22932318    private void createClassTree(Class selectedClass){
    2294         // reset
    2295 //      org.openmodelica.modelicaml.common.instantiation.TreeUtls.componentsTreeRoot = null;
    2296        
     2319
    22972320        if (selectedClass != null && !(selectedClass instanceof Behavior) && isValid(selectedClass)) {
    22982321           
     
    23042327            root = ast.getTreeRoot();
    23052328           
    2306             // set the static variable to be used by other plugins. This is done in order to avoid cyclic plugin dependecies
     2329            // set the static variable to be used by other plugins. This is done in order to avoid cyclic plugin dependencies
    23072330            org.openmodelica.modelicaml.common.instantiation.TreeUtls.classInstantiation = ast;
    23082331            org.openmodelica.modelicaml.common.instantiation.TreeUtls.componentsTreeRoot = root;
     
    23142337    public void createTree(){
    23152338       
    2316         if (sel instanceof IStructuredSelection) {
    2317             EObject selectedElement = null;
    2318        
    2319             if (getCurrentSelections() != null && getCurrentSelections().size() > 0 ) {
    2320                 selectedElement = (EObject) adaptSelectedElement(getCurrentSelections().get(0));
    2321             }
     2339        if (selectedClass != null && !(selectedClass instanceof Behavior) && isValid(selectedClass)) {
    23222340           
    2323             if (selectedElement instanceof Class ) {
    2324                 selectedClass = (Class) selectedElement;
    2325                
    2326                 if (selectedClass != null && !(selectedClass instanceof Behavior) && isValid(selectedClass)) {
    2327                     actionSimulate.setEnabled(true);
    2328                     actionValidate.setEnabled(true);
    2329                     actionReload.setEnabled(true);
    2330                     actionCollapseAll.setEnabled(true);
    2331                    
    2332                     createClassTree(selectedClass); // build the entire tree
    2333                 }
    2334                 else {
    2335                     actionSimulate.setEnabled(false);
    2336                     actionValidate.setEnabled(false);
    2337                     actionReload.setEnabled(false);
    2338                     actionCollapseAll.setEnabled(false);
    2339                 }
    2340             }
     2341            // set actions
     2342            actionSimulate.setEnabled(true);
     2343            actionValidate.setEnabled(true);
     2344            actionReload.setEnabled(true);
     2345            actionCollapseAll.setEnabled(true);
     2346           
     2347            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(ModelicaMLServices.getShell());
     2348            progressDialog.getProgressMonitor().setTaskName("Instantiating " + ModelicaMLServices.getName(selectedClass));
     2349           
     2350            try {
     2351                progressDialog.run(false, true, new IRunnableWithProgress() {
     2352                   
     2353                    @Override
     2354                    public void run(IProgressMonitor monitor) throws InvocationTargetException,
     2355                            InterruptedException {
     2356
     2357                        monitor.subTask("Creating class components tree ...");
     2358                        // instantiate the selected class
     2359                        createClassTree(selectedClass); // build the entire tree
     2360                       
     2361                        //validate component modifications
     2362                        monitor.subTask("Validating component modifications ...");
     2363
     2364                        ComponentModificationValidator validator = new ComponentModificationValidator(root);
     2365                        validator.validate();
     2366                       
     2367                        viewer.refresh();
     2368                       
     2369                        monitor.done();
     2370                    }
     2371                });
     2372            } catch (InvocationTargetException e) {
     2373                e.printStackTrace();
     2374                MessageDialog.openError(ModelicaMLServices.getShell(), "Class Instantiation Error", "Could not invoce the class instantiation operation.");
     2375            } catch (InterruptedException e) {
     2376                e.printStackTrace();
     2377                MessageDialog.openInformation(ModelicaMLServices.getShell(), "Class Instantiation Canceled", "Class instantiation operation was canceled.");
     2378            }
     2379        }
     2380        else {
     2381            actionSimulate.setEnabled(false);
     2382            actionValidate.setEnabled(false);
     2383            actionReload.setEnabled(false);
     2384            actionCollapseAll.setEnabled(false);
     2385        }
     2386       
     2387       
     2388//      if (sel instanceof IStructuredSelection) {
     2389//          EObject selectedElement = null;
     2390//       
     2391//          if (getCurrentSelections() != null && getCurrentSelections().size() > 0 ) {
     2392//              selectedElement = (EObject) adaptSelectedElement(getCurrentSelections().get(0));
     2393//          }
     2394//         
     2395//          if (selectedElement instanceof Class ) {
     2396//              selectedClass = (Class) selectedElement;
     2397//             
     2398//              if (selectedClass != null && !(selectedClass instanceof Behavior) && isValid(selectedClass)) {
     2399//                  actionSimulate.setEnabled(true);
     2400//                  actionValidate.setEnabled(true);
     2401//                  actionReload.setEnabled(true);
     2402//                  actionCollapseAll.setEnabled(true);
     2403//                 
     2404//                  ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(ModelicaMLServices.getShell());
     2405//                  progressDialog.getProgressMonitor().setTaskName("Instantiating " + ModelicaMLServices.getName(selectedClass));
     2406//                 
     2407//                  try {
     2408//                      progressDialog.run(false, true, new IRunnableWithProgress() {
     2409//                         
     2410//                          @Override
     2411//                          public void run(IProgressMonitor monitor) throws InvocationTargetException,
     2412//                                  InterruptedException {
     2413//
     2414//                              monitor.subTask("Creating class components tree ...");
     2415//                              // instantiate the selected class
     2416//                              createClassTree(selectedClass); // build the entire tree
     2417//                             
     2418//                              //validate component modifications
     2419//                              monitor.subTask("Validating component modifications ...");
     2420//
     2421//                              ComponentModificationValidator validator = new ComponentModificationValidator(root);
     2422//                              validator.validate();
     2423//                             
     2424//                              viewer.refresh();
     2425//                             
     2426//                              monitor.done();
     2427//                          }
     2428//                      });
     2429//                  } catch (InvocationTargetException e) {
     2430//                      e.printStackTrace();
     2431//                      MessageDialog.openError(ModelicaMLServices.getShell(), "Class Instantiation Error", "Could not invoce the class instantiation operation.");
     2432//                  } catch (InterruptedException e) {
     2433//                      e.printStackTrace();
     2434//                      MessageDialog.openInformation(ModelicaMLServices.getShell(), "Class Instantiation Canceled", "Class instantiation operation was canceled.");
     2435//                  }
     2436//              }
     2437//              else {
     2438//                  actionSimulate.setEnabled(false);
     2439//                  actionValidate.setEnabled(false);
     2440//                  actionReload.setEnabled(false);
     2441//                  actionCollapseAll.setEnabled(false);
     2442//              }
     2443//          }
    23412444
    23422445//          createTree(selectedClass); // build the entire tree
    2343         }
     2446//      }
    23442447    }
    23452448   
Note: See TracChangeset for help on using the changeset viewer.