- Timestamp:
- 04/08/11 16:11:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/modelicaml/org.openmodelica.modelicaml.helper/src/org/openmodelica/modelicaml/helper/views/InstantiatedRequirementsView.java
r659 r686 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.HashMap; 4 6 import java.util.List; 5 7 8 import org.eclipse.emf.common.util.BasicEList; 9 import org.eclipse.emf.common.util.EList; 6 10 import org.eclipse.emf.ecore.EObject; 7 11 import org.eclipse.gmt.modisco.infra.browser.uicore.internal.model.ModelElementItem; … … 10 14 import org.eclipse.papyrus.diagram.common.editparts.IUMLEditPart; 11 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.custom.CCombo; 12 17 import org.eclipse.swt.custom.StyledText; 13 18 import org.eclipse.swt.layout.GridData; … … 21 26 import org.eclipse.ui.part.ViewPart; 22 27 import org.eclipse.uml2.uml.Class; 28 import org.eclipse.uml2.uml.Element; 23 29 import org.eclipse.uml2.uml.Property; 24 30 import org.eclipse.uml2.uml.Stereotype; 25 import org.eclipse.uml2.uml.Type;26 31 import org.eclipse.wb.swt.SWTResourceManager; 32 import org.openmodelica.modelicaml.common.instantiation.ClassInstantiation; 33 import org.openmodelica.modelicaml.common.instantiation.TreeObject; 34 import org.openmodelica.modelicaml.common.instantiation.TreeParent; 27 35 import org.openmodelica.modelicaml.helper.dialogs.InstantiateRequirementsDialog; 28 36 … … 37 45 private Composite shell; 38 46 private Class selectedClass; 39 private List<Property> reqList = new ArrayList<Property>();47 40 48 private List<ExpandItem> reqGraphicalItemsList = new ArrayList<ExpandItem>(); 41 49 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 42 58 43 59 … … 81 97 if (selectedElement instanceof Class ) { 82 98 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 84 124 drawContents(); 85 125 } 86 }87 }88 89 private void clearItemsList(){90 for (ExpandItem item : reqGraphicalItemsList) {91 item.dispose();92 }93 for (Group group : reqGraphicalGroupItemsList) {94 group.dispose();95 126 } 96 127 } … … 123 154 124 155 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(); 128 160 129 161 Stereotype stereotype = req.getAppliedStereotype(reqStereotypeQname); 130 162 if (stereotype != null) { 131 163 // String title = "" + property.getName() + " (" + req.getName() + ")"; 132 String title = "" + property.getName();164 // String title = "" + property.getName(); 133 165 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"); 135 168 String qName = "" + req.getQualifiedName(); 136 169 … … 155 188 grpId.setText(id.toString() + " : " + qName); 156 189 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); 157 199 158 200 //StyledText reqText = new StyledText(grpId, SWT.FULL_SELECTION | SWT.WRAP | SWT.V_SCROLL); … … 164 206 // Set Req. Text 165 207 reqText.setText(text.toString()); 166 //reqText.setBounds(29, 36, 656, 98);167 208 // 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); 169 210 reqText.setToolTipText(qName); 170 211 … … 174 215 175 216 } 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 requirements187 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()); 191 232 } 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 192 239 } 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 198 353 199 354
Note: See TracChangeset
for help on using the changeset viewer.