From: Benjamin B. <bg...@us...> - 2005-05-31 13:12:57
|
Update of /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/dialogs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13859/Plugin/com/ibm/ecute/rsa/core/internal/dialogs Modified Files: EditQualifiersDialog.java Log Message: 2.1 beta 1a fixed some CIM MOF import errors in RSA/RSM Index: EditQualifiersDialog.java =================================================================== RCS file: /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/dialogs/EditQualifiersDialog.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- EditQualifiersDialog.java 25 May 2005 15:45:48 -0000 1.4 +++ EditQualifiersDialog.java 31 May 2005 13:12:47 -0000 1.5 @@ -50,10 +50,12 @@ import org.eclipse.uml2.AssociationClass; import org.eclipse.uml2.Class; import org.eclipse.uml2.Comment; +import org.eclipse.uml2.Constraint; import org.eclipse.uml2.Element; import org.eclipse.uml2.Model; import org.eclipse.uml2.MultiplicityElement; import org.eclipse.uml2.NamedElement; +import org.eclipse.uml2.OpaqueExpression; import org.eclipse.uml2.Operation; import org.eclipse.uml2.Package; import org.eclipse.uml2.PackageableElement; @@ -74,7 +76,10 @@ import com.ibm.xtools.emf.msl.EditingDomain; import com.ibm.xtools.emf.msl.ResourceSetModifyOperation; import com.ibm.xtools.modeler.UMLModeler; +import com.ibm.xtools.notation.Diagram; import com.ibm.xtools.uml.core.IUMLHelper; +import com.ibm.xtools.uml.diagram.IUMLDiagramHelper; +import com.ibm.xtools.umlnotation.UMLDiagramKind; /** * Copyright (c) 2003, International Business Machines @@ -107,6 +112,7 @@ private Color WHITE = null; Model uml2Model; + IUMLDiagramHelper diagramHelper = UMLModeler.getUMLDiagramHelper(); // value tab Composite valComposite; @@ -2536,6 +2542,33 @@ return false; } } + + public boolean isDirectMapped(){ + + if( this.name.equalsIgnoreCase("Association")|| + this.name.equalsIgnoreCase("Aggregation")|| + this.name.equalsIgnoreCase("Composition")|| + this.name.equalsIgnoreCase("Aggregate")|| + this.name.equalsIgnoreCase("In")|| + this.name.equalsIgnoreCase("Out")|| + this.name.equalsIgnoreCase("Inout")|| + this.name.equalsIgnoreCase("Min")|| + this.name.equalsIgnoreCase("Max")|| + this.name.equalsIgnoreCase("Octectstring")|| + this.name.equalsIgnoreCase("Static")|| + this.name.equalsIgnoreCase("Write")|| + this.name.equalsIgnoreCase("Description")|| + this.name.equalsIgnoreCase("Abstract")|| + this.name.equalsIgnoreCase("Deprecated")|| + this.name.equalsIgnoreCase("Key")|| + this.name.equalsIgnoreCase("ArrayType")|| + this.name.equalsIgnoreCase("OCL") + ){ + return true; + } else { + return false; + } + } } private void setElementLabel(){ @@ -2690,6 +2723,7 @@ if(!setDefaultValue){ EditingDomain editingDomain = UMLModeler.getEditingDomain(); +// if(valueObject.name.equalsIgnoreCase("OCL")) valueObject.index = -1; try { if (valueObject.index == -1) { @@ -2699,16 +2733,8 @@ protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - if(valueObject.name == "Description"){ - EList list = element.getOwnedComments(); - Iterator it = list.iterator(); - while (it.hasNext()){ - Comment comment = (Comment)it.next(); - Stereotype stereo = comment.getApplicableStereotype("Default::Documentation"); - if(stereo != null){ - comment.setBody(valueObject.value); - } - } + if(valueObject.isDirectMapped()){ + mapQualifierToModel(element, valueObject.name, valueObject.value); } else { Stereotype cimStereotype = element.getAppliedStereotype("CIM::Qualifiers"); int stereotypePropertyIndex = ((List) element.getValue(cimStereotype, "QualifierName")) @@ -2798,6 +2824,113 @@ } } + + public void mapQualifierToModel(Element element, String qualifierName, String newValue){ + + // DESCRIPTION + if(qualifierName.equalsIgnoreCase("Description")){ + EList list = element.getOwnedComments(); + Iterator it = list.iterator(); + if(it.hasNext()){ + while (it.hasNext()){ + Comment comment = (Comment)it.next(); + Stereotype stereo = comment.getApplicableStereotype("Default::Documentation"); + if(stereo != null){ + comment.setBody(newValue); + } + } + } else { + Comment descr = element.createOwnedComment(UML2Package.eINSTANCE.getComment()); + descr.setBody(newValue); + Stereotype stereo = descr.getApplicableStereotype("Default::Documentation"); + descr.apply(stereo); + } + } + + // DEPRECATED + if(qualifierName.equalsIgnoreCase("Deprecated")){ + Stereotype appliedStereo = element.getAppliedStereotype("CIM::Deprecated"); + if(appliedStereo == null){ + Stereotype stereo = element.getApplicableStereotype("CIM::Deprecated"); + element.apply(stereo); + element.setValue(stereo, "Value", newValue); + } else { + if(newValue.equalsIgnoreCase("null")){ + element.unapply(appliedStereo); + } else { + element.setValue(appliedStereo, "Value", newValue); + } + } + } +/* + // OCL + if(qualifierName.equalsIgnoreCase("OCL")){ + if (element instanceof Class){ + List elementList = ((Class)element).getPackage().getOwnedElements(); + ArrayList constraintList = new ArrayList(); + for (int i = 0; i < elementList.size(); i++){ + if (elementList.get(i) instanceof Constraint) + constraintList.add(elementList.get(i)); + } + boolean foundConstraint = false; + if (constraintList != null){ + for(int j = 0; j < constraintList.size(); j++){ + Constraint constraint = (Constraint)constraintList.get(j); + List constrainedElements = constraint.getConstrainedElements(); + for(int k = 0; k < constrainedElements.size(); k++){ + if(constrainedElements.get(k) instanceof Class){ + if(((Class)constrainedElements.get(k)).getName().equalsIgnoreCase(((Class)element).getName())){ + + foundConstraint = true; + + if(newValue.equalsIgnoreCase("null")){ + elementList.remove(constraint); + //constraint.destroy(); + //diagramHelper.destroyView((View)constraint); + } + + String tempBody, body = ""; + // prepare constraint body content + if(newValue.startsWith("{")){ + int length = newValue.length(); + tempBody = newValue.substring(2, length - 2); + } else { + tempBody = newValue; + } + int index = tempBody.indexOf(","); + boolean multiple = false; + if (index != -1) + multiple = true; + while (index != -1){ + int length = tempBody.length(); + body = body.concat(tempBody.substring(0, index - 1)); + body = body.concat("\n"); + tempBody = tempBody.substring(index + 2); + index = tempBody.indexOf(","); + } + if (multiple){ + body = body.concat(tempBody.substring(index + 1)); + } + if (!multiple) + body = tempBody; + + //set constraint body and language + ((OpaqueExpression)constraint.getSpecification()).setBody(body); + + + } + } + } + } + } + + if(!foundConstraint){ + createClassOCL((Class)element, newValue); + } + } + }*/ + } + private Class getSelectedClass(String name, Package package_, boolean otherPackages) { Class theClass = null; @@ -3189,6 +3322,95 @@ resetRemovedValues(); } + + private void createClassOCL(Class lastClass, String value){ + Package package_ = lastClass.getNearestPackage(); + Constraint constraint = (Constraint)package_.createOwnedMember(UML2Package.eINSTANCE.getConstraint()); + constraint.setName("OCL " + lastClass.getName()); + + // create specification + constraint.createSpecification(UML2Package.eINSTANCE.getOpaqueExpression()); + setOCLBody(constraint, value); +// String tempBody, body = ""; +// // prepare constraint body content +// if(value.startsWith("{")){ +// int length = value.length(); +// tempBody = value.substring(2, length - 2); +// } else { +// tempBody = value; +// } +// int index = tempBody.indexOf(","); +// boolean multiple = false; +// if (index != -1) +// multiple = true; +// while (index != -1){ +// int length = tempBody.length(); +// body = body.concat(tempBody.substring(0, index - 1)); +// body = body.concat("\n"); +// tempBody = tempBody.substring(index + 2); +// index = tempBody.indexOf(","); +// } +// if (multiple){ +// body = body.concat(tempBody.substring(index + 1)); +// } +// if (!multiple) +// body = tempBody; +// +// //set constraint body and language +// ((OpaqueExpression)constraint.getSpecification()).setBody(body); +// ((OpaqueExpression)constraint.getSpecification()).setLanguage("OCL"); + + // get the connection line between the constraint and the class + constraint.getConstrainedElements().add(lastClass); + + // add constraint to diagram + ArrayList list = new ArrayList(); + list.add(constraint); + List diagrams = diagramHelper.getDiagrams(package_, UMLDiagramKind.CLASS_LITERAL); + Iterator it = diagrams.iterator(); + Diagram thisDiagram = null; + while(it.hasNext()){ + Diagram diagram = (Diagram)it.next(); + if(diagram.getName().equalsIgnoreCase("Main")) + thisDiagram = diagram; + } + if (thisDiagram != null){ + diagramHelper.createViews(thisDiagram, list); + } + } + + private void setOCLBody(Constraint constraint, String value){ + + String tempBody, body = ""; + // prepare constraint body content + if(value.startsWith("{")){ + int length = value.length(); + tempBody = value.substring(2, length - 2); + } else { + tempBody = value; + } + int index = tempBody.indexOf(","); + boolean multiple = false; + if (index != -1) + multiple = true; + while (index != -1){ + int length = tempBody.length(); + body = body.concat(tempBody.substring(0, index - 1)); + body = body.concat("\n"); + tempBody = tempBody.substring(index + 2); + index = tempBody.indexOf(","); + } + if (multiple){ + body = body.concat(tempBody.substring(index + 1)); + } + if (!multiple) + body = tempBody; + + //set constraint body and language + ((OpaqueExpression)constraint.getSpecification()).setBody(body); + ((OpaqueExpression)constraint.getSpecification()).setLanguage("OCL"); + + } private class EditValueDialog extends Dialog{ |