Changeset 686 for trunk


Ignore:
Timestamp:
04/08/11 16:11:53 (13 years ago)
Author:
wschamai
Message:

MOD: instantiated requirements view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modelicaml/org.openmodelica.modelicaml.helper/src/org/openmodelica/modelicaml/helper/views/InstantiatedRequirementsView.java

    r659 r686  
    22
    33import java.util.ArrayList;
     4import java.util.Collections;
     5import java.util.HashMap;
    46import java.util.List;
    57
     8import org.eclipse.emf.common.util.BasicEList;
     9import org.eclipse.emf.common.util.EList;
    610import org.eclipse.emf.ecore.EObject;
    711import org.eclipse.gmt.modisco.infra.browser.uicore.internal.model.ModelElementItem;
     
    1014import org.eclipse.papyrus.diagram.common.editparts.IUMLEditPart;
    1115import org.eclipse.swt.SWT;
     16import org.eclipse.swt.custom.CCombo;
    1217import org.eclipse.swt.custom.StyledText;
    1318import org.eclipse.swt.layout.GridData;
     
    2126import org.eclipse.ui.part.ViewPart;
    2227import org.eclipse.uml2.uml.Class;
     28import org.eclipse.uml2.uml.Element;
    2329import org.eclipse.uml2.uml.Property;
    2430import org.eclipse.uml2.uml.Stereotype;
    25 import org.eclipse.uml2.uml.Type;
    2631import org.eclipse.wb.swt.SWTResourceManager;
     32import org.openmodelica.modelicaml.common.instantiation.ClassInstantiation;
     33import org.openmodelica.modelicaml.common.instantiation.TreeObject;
     34import org.openmodelica.modelicaml.common.instantiation.TreeParent;
    2735import org.openmodelica.modelicaml.helper.dialogs.InstantiateRequirementsDialog;
    2836
     
    3745    private Composite shell;
    3846    private Class selectedClass;
    39     private List<Property> reqList = new ArrayList<Property>();
     47   
    4048    private List<ExpandItem> reqGraphicalItemsList = new ArrayList<ExpandItem>();
    4149    private List<Group> reqGraphicalGroupItemsList = new ArrayList<Group>();
     50   
     51   
     52    private HashMap<Element, ArrayList<String>> reqClassInstantiations = new HashMap<Element,ArrayList<String>>(); 
     53    private HashMap<String, Element> reqClassNameToElement = new HashMap<String, Element>();
     54    private List<String> reqClassesNames = new ArrayList<String>();
     55    private EList<Property> reqInstancesList = new BasicEList<Property>();
     56   
     57   
    4258   
    4359   
     
    8197            if (selectedElement instanceof Class ) {
    8298                selectedClass = (Class) selectedElement;
    83                 reqList = getInstatiatedRequirementsList(selectedClass);
     99                //reqList = getInstatiatedRequirementsList(selectedClass);
     100               
     101                // clear all lists
     102                reqClassInstantiations.clear();
     103                reqClassNameToElement.clear();
     104                reqClassesNames.clear();
     105                reqInstancesList.clear();
     106               
     107                // instantiate class
     108                ClassInstantiation ci = new ClassInstantiation(selectedClass, false);
     109                ci.createTree();
     110                TreeParent treeRoot = ci.getTreeRoot();
     111               
     112                // collect all requirements instances and create maps
     113                collectRequirements(treeRoot);
     114               
     115                // sort requirements classes by name
     116                reqClassesNames.addAll(reqClassNameToElement.keySet());
     117                Collections.sort(reqClassesNames);
     118               
     119//              for (String string : list) {
     120//                  Element aClass = reqClassNameToElement.get(string);
     121//                  System.err.println(string + ":  " + reqClassInstantiations.get(aClass).toString());
     122//              }
     123               
    84124                drawContents();
    85125            }
    86         }
    87     }
    88    
    89     private void clearItemsList(){
    90         for (ExpandItem item : reqGraphicalItemsList) {
    91             item.dispose();
    92         }
    93         for (Group group : reqGraphicalGroupItemsList) {
    94             group.dispose();
    95126        }
    96127    }
     
    123154       
    124155       
    125         for (Property property : reqList) {
    126                
    127                 Class req = (Class) property.getType();
     156        for (String reqClassName : reqClassesNames) {
     157               
     158                Class req = (Class) reqClassNameToElement.get(reqClassName);
     159                int numberOfInstances = reqClassInstantiations.get(req).size();
    128160               
    129161                Stereotype stereotype = req.getAppliedStereotype(reqStereotypeQname);
    130162                if (stereotype != null) {
    131163//                  String title = "" + property.getName() + " (" + req.getName() + ")";
    132                     String title = "" + property.getName();
     164//                  String title = "" + property.getName();
    133165                    Object id = "" + req.getValue(stereotype, "id");
    134                     Object text = "" + req.getValue(stereotype, "text");;
     166                    String title = "" + "(x" + numberOfInstances + ") " + id + ": " + reqClassName;
     167                    Object text = "" + req.getValue(stereotype, "text");
    135168                    String qName = "" + req.getQualifiedName();
    136169
     
    155188                    grpId.setText(id.toString() + " : " + qName);
    156189                    reqExpandItem.setControl(grpId);
     190
     191                    // Combo for requirement instance names:
     192                    CCombo reqInstancesNames = new CCombo(grpId, SWT.BORDER);
     193                    List<String> list = reqClassInstantiations.get(req);
     194                    Collections.sort(list);
     195                    reqInstancesNames.setItems(list.toArray(new String[list.size()]));
     196                    reqInstancesNames.setText(list.get(0).toString());
     197                    reqInstancesNames.setBounds(5, 20, 500, 18);
     198                    reqInstancesNames.setEditable(false);
    157199                   
    158200                    //StyledText reqText = new StyledText(grpId, SWT.FULL_SELECTION | SWT.WRAP | SWT.V_SCROLL);
     
    164206                    // Set Req. Text
    165207                    reqText.setText(text.toString());
    166                     //reqText.setBounds(29, 36, 656, 98);
    167208//                  reqText.setBounds(5, 20, expandBar.getShell().getBounds().width - 70, SWT.VERTICAL - 229);
    168                     reqText.setBounds(5, 20, 600, 80);
     209                    reqText.setBounds(5, 50, 600, 80);
    169210                    reqText.setToolTipText(qName);
    170211                   
     
    174215           
    175216        }
    176        
    177        
    178        
    179        
    180     }
    181    
    182    
    183     private List<Property> getInstatiatedRequirementsList(Class owningClass){
    184         if (owningClass != null) {
    185             List<Property> requirements = new ArrayList<Property>();
    186             for (Property property : owningClass.getAllAttributes()) { // TODO: here use the ModelicaMLAST instead to find requirements
    187                 Type pType = property.getType();
    188                
    189                 if ( pType != null && (pType.getAppliedStereotype(reqStereotypeQname) != null)) {
    190                     requirements.add(property);
     217    }
     218   
     219    private void collectRequirements(TreeParent treeRoot){
     220        TreeObject[] children = treeRoot.getChildren();
     221        for (int i = 0; i < children.length; i++) {
     222            if (children[i].isRequirementInstance()) {
     223               
     224                // add to requirements instances list
     225                reqInstancesList.add(children[i].getProperty());
     226               
     227                // add to map
     228                ArrayList<String> list = reqClassInstantiations.get(children[i].getComponentType());
     229                if (list == null) {
     230                    list = new ArrayList<String>();
     231                    list.add(children[i].getDothPath());
    191232                }
     233                else {
     234                    list.add(children[i].getDothPath());
     235                }
     236                reqClassNameToElement.put(children[i].getComponentType().getName(), children[i].getComponentType());
     237                reqClassInstantiations.put(children[i].getComponentType(), list);
     238               
    192239            }
    193             return requirements;
    194         }
    195         return null;
    196     }
    197    
     240            else if (children[i].getHasRequirements()) {
     241                collectRequirements((TreeParent)children[i]); // recursive call             
     242            }
     243        }
     244    }
     245   
     246    private void clearItemsList(){
     247        for (ExpandItem item : reqGraphicalItemsList) {
     248            item.dispose();
     249        }
     250        for (Group group : reqGraphicalGroupItemsList) {
     251            group.dispose();
     252        }
     253    }
     254
     255   
     256//  private void drawContents(){
     257//
     258//      clearItemsList();// clear the graphical view.
     259//
     260////        Label lblSelectRequirementsTo = new Label(messageComposite, SWT.NONE);
     261////        lblSelectRequirementsTo.setFont(SWTResourceManager.getFont("Arial", 10, SWT.NORMAL));
     262////        lblSelectRequirementsTo.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
     263////        lblSelectRequirementsTo.setBounds(0, 0, 238, 18);
     264////
     265////        if (reqList != null && reqList.size() > 0) {
     266////            // NEW Label for the owning class name
     267////            lblSelectRequirementsTo.setText("The following requirements are instantiated in:");
     268////            CLabel label_1 = new CLabel(messageComposite, SWT.NONE);
     269////            label_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
     270////            label_1.setTopMargin(0);
     271////            label_1.setBottomMargin(0);
     272////           
     273////            // Set the name of containing class
     274////            label_1.setText(selectedClass.getName());   
     275////            label_1.setFont(SWTResourceManager.getFont("Arial", 10, SWT.BOLD));
     276////            label_1.setBounds(244, 0, 450, 18);
     277////        }
     278////        else {
     279////            lblSelectRequirementsTo.setText("No requirements are instantiated in " + selectedClass.getName() +  ".");
     280////        }
     281//     
     282//     
     283//      for (Property property : reqList) {
     284//             
     285//              Class req = (Class) property.getType();
     286//             
     287//              Stereotype stereotype = req.getAppliedStereotype(reqStereotypeQname);
     288//              if (stereotype != null) {
     289////                    String title = "" + property.getName() + " (" + req.getName() + ")";
     290//                  String title = "" + property.getName();
     291//                  Object id = "" + req.getValue(stereotype, "id");
     292//                  Object text = "" + req.getValue(stereotype, "text");;
     293//                  String qName = "" + req.getQualifiedName();
     294//
     295//                  ExpandItem reqExpandItem = new ExpandItem(expandBar, SWT.NONE);
     296//                  reqGraphicalItemsList.add(reqExpandItem);
     297//                  reqExpandItem.setExpanded(false);
     298//                 
     299//                  // mark requirement that is already instantiated
     300//                  reqExpandItem.setImage(SWTResourceManager.getImage(InstantiateRequirementsDialog.class, "/icons/exists_already.png"));
     301//
     302//                  // Set Req. Title
     303////                    reqExpandItem.setText(id + ": " + title);
     304//                  reqExpandItem.setText(title);
     305//                 
     306//                  Group grpId = new Group(expandBar, SWT.NONE);
     307//                  reqGraphicalGroupItemsList.add(grpId);
     308//                  grpId.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
     309//                  grpId.setToolTipText(qName);
     310//                 
     311//                  // Set Req. ID
     312//                  //grpId.setText("id: " + id.toString() + "   " + qName);
     313//                  grpId.setText(id.toString() + " : " + qName);
     314//                  reqExpandItem.setControl(grpId);
     315//                 
     316//                  //StyledText reqText = new StyledText(grpId, SWT.FULL_SELECTION | SWT.WRAP | SWT.V_SCROLL);
     317//                  StyledText reqText = new StyledText(grpId, SWT.FULL_SELECTION | SWT.WRAP);
     318//                  reqText.setIndent(1);
     319//                  reqText.setFont(SWTResourceManager.getFont("Arial", 10, SWT.NORMAL));
     320//                  reqText.setEditable(false);
     321//                 
     322//                  // Set Req. Text
     323//                  reqText.setText(text.toString());
     324//                  //reqText.setBounds(29, 36, 656, 98);
     325////                    reqText.setBounds(5, 20, expandBar.getShell().getBounds().width - 70, SWT.VERTICAL - 229);
     326//                  reqText.setBounds(5, 20, 600, 80);
     327//                  reqText.setToolTipText(qName);
     328//                 
     329//                  grpId.setTabList(new Control[]{reqText});
     330//                  reqExpandItem.setHeight(reqExpandItem.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);   
     331//              }
     332//         
     333//      }
     334//  }
     335   
     336//  private List<Property> getInstatiatedRequirementsList(Class owningClass){
     337//      if (owningClass != null) {
     338//          List<Property> requirements = new ArrayList<Property>();
     339//          for (Property property : owningClass.getAllAttributes()) { // TODO: here use the ModelicaMLAST instead to find requirements
     340//              Type pType = property.getType();
     341//             
     342//              if ( pType != null && (pType.getAppliedStereotype(reqStereotypeQname) != null)) {
     343//                  requirements.add(property);
     344//              }
     345//          }
     346//         
     347//          return requirements;
     348//      }
     349//      return null;
     350//  }
     351   
     352
    198353
    199354
Note: See TracChangeset for help on using the changeset viewer.