From: Benjamin B. <bg...@us...> - 2005-07-28 18:00:04
|
Update of /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/properties In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22981/Plugin/com/ibm/ecute/rsa/core/internal/properties Modified Files: QualifiersPropertySection.java FlavorsHelper.java Added Files: CheckAndRepair.java Log Message: propagation of min, max and write qualifiers when override is set interactively Index: FlavorsHelper.java =================================================================== RCS file: /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/properties/FlavorsHelper.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- FlavorsHelper.java 25 Jul 2005 07:57:18 -0000 1.5 +++ FlavorsHelper.java 28 Jul 2005 17:59:51 -0000 1.6 @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Vector; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -19,6 +20,7 @@ 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.NamedElement; import org.eclipse.uml2.OpaqueExpression; @@ -26,12 +28,14 @@ import org.eclipse.uml2.Package; import org.eclipse.uml2.Parameter; import org.eclipse.uml2.ParameterDirectionKind; +import org.eclipse.uml2.PrimitiveType; import org.eclipse.uml2.Property; import org.eclipse.uml2.Stereotype; import org.eclipse.uml2.Type; import org.eclipse.uml2.UML2Package; import com.ibm.ecute.EcuteEclipsePlugin; +import com.ibm.ecute.Qualifiers.Qualifier; import com.ibm.ecute.Qualifiers.QualifiersList; import com.ibm.ecute.utils.License; import com.ibm.ecute.rsa.core.internal.properties.EffectiveInheritedValue; @@ -59,6 +63,13 @@ private static String QUALIFIERS_CONSTRAINT_NAME = "QualifiersList"; + public static final int TCATEGORY=0; + public static final int TCLASS=1; + public static final int TMETHOD=2; + public static final int TATTRIBUTE=3; + public static final int TPARAMETER=4; + public static final int TLINK1=5; + public static final int TLINK2=6; Model model; QualifiersList qualifiersList; @@ -71,13 +82,13 @@ this.qualifiersList = this.getQualifiersList(); } - public void setModelFlavors(){ - ArrayList modelSubClasses = getAllModelSubClasses(); - for(int i = 0; i < modelSubClasses.size(); i++){ - Class modelSubClass = (Class)modelSubClasses.get(i); - setClassFlavors(modelSubClass); - } - } +// public void setModelFlavors(){ +// ArrayList modelSubClasses = getAllModelSubClasses(); +// for(int i = 0; i < modelSubClasses.size(); i++){ +// Class modelSubClass = (Class)modelSubClasses.get(i); +// setClassFlavors(modelSubClass); +// } +// } private void setClassFlavors(Class class_){ ArrayList parentClasses = getAllParentClasses(class_); @@ -239,6 +250,15 @@ return false; } + + private boolean isNativeMappedQualifier(Qualifier qualifier){ + + if(isNativeMappedQualifier(qualifier.name)){ + return true; + } else { + return false; + } + } private ArrayList getAllParentClasses(Class class_){ @@ -272,45 +292,7 @@ // return parentClasses; // } - private ArrayList getAllChildClasses(Class class_){ - - ArrayList childClasses = new ArrayList(); - - // get model classes - ArrayList modelClasses = getAllModelClasses((NamedElement)class_); - if(modelClasses.size() <= 0){ - return null; - } - - ArrayList currentChildren = new ArrayList(); - currentChildren.add(class_); - - while(currentChildren.size() > 0){ - //int m = currentChildren.size(); - //for(int i = 0; i < m; i++){ - String childClassName = ((Class)currentChildren.get(0)).getName(); - int n = modelClasses.size(); - for(int j = 0; j < n; j++){ - if(((Class)modelClasses.get(j)).getGenerals().size() > 0 && - (Class)((Class)modelClasses.get(j)).getGenerals().get(0) != null){ - String className = ((Class)((Class)modelClasses.get(j)).getGenerals().get(0)).getName(); - if(className.equalsIgnoreCase(childClassName)){ - currentChildren.add(modelClasses.get(j)); - childClasses.add(modelClasses.get(j)); - //m++; - modelClasses.remove(j); - j--; n--; - } - } - } - currentChildren.remove(0); - // i--; m--; - //} - } - - childClasses.trimToSize(); - return childClasses; - } + // public ArrayList getAllChildClasses(UMLClass class_){ // @@ -343,53 +325,22 @@ // return childClasses; // } - private ArrayList getAllModelClasses(NamedElement element){ - ArrayList classes = new ArrayList(); - Model model; - - // goto the model - while(!(element instanceof Model)){ - element = (NamedElement)element.getOwner(); - } - - if(!(element instanceof Model)){ - return null; - } else { - model = (Model)element; - } - - // get all owned packages - List packagesList = model.getOwnedMembers(); - - // get classes from packages and add to list - for(int i = 0; i < packagesList.size(); i++){ - Package currentPackage = (Package)packagesList.get(i); - List packageMembersList = currentPackage.getOwnedElements(); - for(int j = 0; j < packageMembersList.size(); j++){ - if(packageMembersList.get(j) instanceof Class){ - classes.add(packageMembersList.get(j)); - } - } - } - - classes.trimToSize(); - return classes; - } + - private ArrayList getAllModelSubClasses(){ - ArrayList modelClasses = getAllModelClasses(this.model); - ArrayList modelSubClasses = new ArrayList(); - - for(int i = 0; i < modelClasses.size(); i++){ - Class modelClass = (Class)modelClasses.get(i); - if(modelClass.getGenerals().size() > 0){ - modelSubClasses.add(modelClass); - } - } - - modelSubClasses.trimToSize(); - return modelSubClasses; - } +// private ArrayList getAllModelSubClasses(){ +// ArrayList modelClasses = getAllModelClasses(this.model); +// ArrayList modelSubClasses = new ArrayList(); +// +// for(int i = 0; i < modelClasses.size(); i++){ +// Class modelClass = (Class)modelClasses.get(i); +// if(modelClass.getGenerals().size() > 0){ +// modelSubClasses.add(modelClass); +// } +// } +// +// modelSubClasses.trimToSize(); +// return modelSubClasses; +// } private ArrayList getOverrideAttributes(Class class_){ ArrayList overrideAttributes = new ArrayList(); @@ -887,9 +838,9 @@ } if(attribute != null){ - Type datatype = property.getType(); - if(datatype != null){ - if(datatype.getName().equalsIgnoreCase("Octetstring")){ + Type type = attribute.getType(); + if(type != null){ + if(type.getName().equalsIgnoreCase("Octetstring")){ return(new EffectiveInheritedValue("true", (Class)parents.get(j))); } @@ -1061,8 +1012,12 @@ } if(attribute != null){ - if(!attribute.isReadOnly()){ - return(new EffectiveInheritedValue("true", (Class)parents.get(j))); + if(override(attribute) || !override(attribute) && j == parents.size()-1){ + if(!attribute.isReadOnly()){ + return(new EffectiveInheritedValue("true", (Class)parents.get(j))); + } else { + return(new EffectiveInheritedValue("false", (Class)parents.get(j))); + } } if(!override(attribute) && j != parents.size()-1){ return null; @@ -1263,7 +1218,7 @@ return qualifierValue; } - private static boolean override(NamedElement namedElement){ + public static boolean override(NamedElement namedElement){ Stereotype cimStereotype = namedElement.getAppliedStereotype("CIM::Qualifiers"); List qualifierNames = (List) namedElement.getValue(cimStereotype, "QualifierName"); @@ -1311,6 +1266,492 @@ return true; } + public void applyNativeInheritedValues(NamedElement element, boolean skipEnableOverride){ + + EditingDomain editingDomain = UMLModeler.getEditingDomain(); + ArrayList applicableQualifiers = getApplicableQualifiers(element); + // remove qualifiers with Restricted flavor + for(int i = 0; i < applicableQualifiers.size(); i++){ + Qualifier qualifier = (Qualifier)applicableQualifiers.get(i); + if(qualifier.RestrictedFlavor){ + applicableQualifiers.remove(i); + } + // remove qualifiers with Enable ToSubclass flavor + if(skipEnableOverride && !qualifier.DissableOverrideFlavor && !qualifier.RestrictedFlavor){ + applicableQualifiers.remove(i); + } + } + + boolean isComposition = false; + boolean minmax = false; + int minValue = 0; + int maxValue = -1; + + for(int i = 0; i < applicableQualifiers.size(); i++){ + if(isNativeMappedQualifier((Qualifier)applicableQualifiers.get(i))){ + String qualifierName = ((Qualifier)applicableQualifiers.get(i)).name; + String qualifierValue = null; + if(effectiveInheritedValue(element, qualifierName) != null){ + qualifierValue = effectiveInheritedValue(element, qualifierName).getValue(); + } + + if(qualifierName.equalsIgnoreCase("Min") && qualifierValue != null){ + minValue = new Integer(qualifierValue).intValue(); + minmax = true; + continue; + } else if(qualifierName.equalsIgnoreCase("Max") && qualifierValue != null){ + maxValue = new Integer(qualifierValue).intValue(); + minmax = true; + continue; + } + + if(qualifierValue != null && qualifierName.equalsIgnoreCase("Composition") + && qualifierValue.equalsIgnoreCase("true")){ + isComposition = true; + + } else if(qualifierValue != null && qualifierName.equalsIgnoreCase("Aggregation") + && isComposition){ + continue; + } + + if(qualifierValue != null && !qualifierName.equalsIgnoreCase("Description") && + !qualifierName.equalsIgnoreCase("Key")){ + + try { + final NamedElement namedElement = element; + final String qualName = qualifierName; + final String qualValue = qualifierValue; + + editingDomain.run(new ResourceSetModifyOperation("applyNativeInheritedValues") { + + protected void execute(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + mapQualifierToModel(namedElement, qualName, qualValue); + } + }, new NullProgressMonitor()); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + // apply min and max qualifier + if(minmax && element instanceof Property){ + try { + final NamedElement namedElement = element; + final String minV = (new Integer(minValue)).toString(); + final String maxV = (new Integer(maxValue)).toString(); + final boolean minFirst; + + int elementCurrentMax = ((Property)element).getUpper(); + int elementCurrentMin = ((Property)element).getLower(); + + if(maxValue < elementCurrentMin){ + minFirst = true; + } else { + minFirst = false; + } + + + editingDomain.run(new ResourceSetModifyOperation("applyNativeInheritedValues") { + + protected void execute(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + if(minFirst){ + mapQualifierToModel(namedElement, "Min", minV); + mapQualifierToModel(namedElement, "Max", maxV); + } else { + mapQualifierToModel(namedElement, "Max", maxV); + mapQualifierToModel(namedElement, "Min", minV); + } + } + }, new NullProgressMonitor()); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + if(element instanceof Class){ + Class class_ = (Class)element; + // apply native inherited values for class attributes + List properties = class_.getOwnedAttributes(); + for(int i = 0; i < properties.size(); i++){ + applyNativeInheritedValues((Property)properties.get(i), true); + } + // apply native inherited values for class methods + List methods = class_.getOwnedOperations(); + for(int i = 0; i < methods.size(); i++){ + applyNativeInheritedValues((Operation)methods.get(i), true); + } + + } + + if(element instanceof AssociationClass){ + AssociationClass aClass = (AssociationClass)element; + List ownedEnds = aClass.getOwnedEnds(); + for(int i = 0; i < ownedEnds.size(); i++){ + applyNativeInheritedValues((Property)ownedEnds.get(i), true); + } + } else if(element instanceof Operation){ + Operation operation = (Operation)element; + List parameters = operation.getOwnedParameters(); + for(int i = 0; i < parameters.size(); i++){ + applyNativeInheritedValues((Parameter)parameters.get(i), true); + } + } + } + + private ArrayList getApplicableQualifiers(NamedElement element){ + + String elementType = getNamedElementType(element); + + QualifiersList qualifiersList=null; + try { + qualifiersList = EcuteEclipsePlugin.getDefault().getQualifiersList(); + } catch (Exception e) { + e.printStackTrace(); + } + Vector vector = qualifiersList.GetElements(); + ArrayList applicableQualifers = new ArrayList(); + + for(int i=0; i < vector.size(); i++){ + Qualifier qualifier = (Qualifier)vector.get(i); + String qualifierScope = qualifier.scope2String(); + if(qualifierScope.indexOf(elementType) > -1){ + applicableQualifers.add(qualifier); + } + } + + return applicableQualifers; + } + + public void mapQualifierToModel(Element element, String qualifierName, String newValue){ + + // AGGREGATION, COMPOSITION + if(element instanceof AssociationClass){ + EList ownedEnds = ((AssociationClass)element).getOwnedEnds(); + Property prop1 = (Property)ownedEnds.get(0); + Property prop2 = (Property)ownedEnds.get(1); + + if(qualifierName.equalsIgnoreCase("Aggregation")){ + if(newValue.equalsIgnoreCase("false")){ + prop1.setAggregation(AggregationKind.NONE_LITERAL); + prop2.setAggregation(AggregationKind.NONE_LITERAL); // just to be sure + } else { + prop1.setAggregation(AggregationKind.SHARED_LITERAL); + prop2.setAggregation(AggregationKind.NONE_LITERAL); // just to be sure + } + } else if(qualifierName.equalsIgnoreCase("Composition")){ + if(newValue.equalsIgnoreCase("false")){ + prop1.setAggregation(AggregationKind.SHARED_LITERAL); + prop2.setAggregation(AggregationKind.NONE_LITERAL); // just to be sure + } else { + prop1.setAggregation(AggregationKind.COMPOSITE_LITERAL); + prop2.setAggregation(AggregationKind.NONE_LITERAL); // just to be sure + } + } + + // IN, OUT + } else if(element instanceof Parameter && + (qualifierName.equalsIgnoreCase("In")||qualifierName.equalsIgnoreCase("Out"))){ + + Parameter parameter = (Parameter)element; + + if(newValue.equalsIgnoreCase("true") && qualifierName.equalsIgnoreCase("In")){ + if(parameter.getDirection() == ParameterDirectionKind.OUT_LITERAL){ + parameter.setDirection(ParameterDirectionKind.INOUT_LITERAL); + } else if(parameter.getDirection() == ParameterDirectionKind.IN_LITERAL){ + // do nothing + } else if(parameter.getDirection() == ParameterDirectionKind.INOUT_LITERAL){ + // do nothing + } + + } else if(newValue.equalsIgnoreCase("true") && qualifierName.equalsIgnoreCase("Out")){ + if(parameter.getDirection() == ParameterDirectionKind.OUT_LITERAL){ + // do nothing + } else if(parameter.getDirection() == ParameterDirectionKind.IN_LITERAL){ + parameter.setDirection(ParameterDirectionKind.OUT_LITERAL); + } else if(parameter.getDirection() == ParameterDirectionKind.INOUT_LITERAL){ + // do nothing + } + } + + + // MIN, MAX + } else if(element instanceof Property){ + if(qualifierName.equalsIgnoreCase("Min")){ + int min = new Integer(newValue).intValue(); + ((Property) element).setLowerBound(min); + } + if(qualifierName.equalsIgnoreCase("Max")){ + if(newValue.equalsIgnoreCase("null")){ + newValue = "-1"; + } + int max = new Integer(newValue).intValue(); + try { + ((Property) element).setUpperBound(max); + } catch (RuntimeException e) { + // TODO + e.printStackTrace(); + } + } + } + + // DESCRIPTION + if(qualifierName.equalsIgnoreCase("Description")){ + EList list = element.getOwnedComments(); + if(newValue.equalsIgnoreCase("null")){ + list.clear(); + return; + } + 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 + }else 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); + } + } + + + //OCTETSTRING + } else if(qualifierName.equalsIgnoreCase("Octetstring")){ + if(newValue.equalsIgnoreCase("true")){ + PrimitiveType octetstring = (PrimitiveType)model.getImportedMember("octetstring"); + if(element instanceof Property){ + Property prop = (Property)element; + prop.setType(octetstring); + } else if(element instanceof Operation){ + Operation op = (Operation)element; + Parameter returnType = (Parameter)op.getReturnResults().get(0); + if(returnType == null){ + Parameter returnResult = op.createOwnedParameter(UML2Package.eINSTANCE.getParameter()); + returnResult.setDirection(ParameterDirectionKind.RETURN_LITERAL); + returnResult.setName("ReturnType"); + returnType.setType(octetstring); + } else { + returnType.setType(octetstring); + } + } else if(element instanceof Parameter){ + Parameter param = (Parameter)element; + param.setType(octetstring); + } + } + + + // STATIC + } else if(qualifierName.equalsIgnoreCase("static")){ + if(newValue.equalsIgnoreCase("true")){ + if(element instanceof Property){ + ((Property)element).setIsStatic(true); + } else if(element instanceof Operation){ + ((Operation)element).setIsStatic(true); + } + } else if(newValue.equalsIgnoreCase("false")){ + if(element instanceof Property){ + ((Property)element).setIsStatic(false); + } else if(element instanceof Operation){ + ((Operation)element).setIsStatic(false); + } + } + + + // WRITE + } else if(qualifierName.equalsIgnoreCase("write")){ + if(element instanceof Property){ + if(newValue.equalsIgnoreCase("true")){ + ((Property)element).setIsReadOnly(false); + } else if(newValue.equalsIgnoreCase("false")){ + ((Property)element).setIsReadOnly(true); + } + } + + + // ABSTRACT + } else if(qualifierName.equalsIgnoreCase("abstract")){ + if(element instanceof Class){ + if(newValue.equalsIgnoreCase("true")){ + ((Class)element).setIsAbstract(true); + } else if(newValue.equalsIgnoreCase("false")){ + ((Class)element).setIsAbstract(false); + } + } + + + // KEY + } else if(qualifierName.equalsIgnoreCase("key")){ + boolean keyIsApplied = true; + if(element instanceof Property){ + Property property = (Property)element; + Stereotype stereo = property.getAppliedStereotype("CIM::Key"); + if(stereo == null){ + stereo = property.getApplicableStereotype("CIM::Key"); + keyIsApplied = false; + } + if(newValue.equalsIgnoreCase("false")){ + property.unapply(stereo); + } else if(newValue.equalsIgnoreCase("true") && !keyIsApplied){ + property.apply(stereo); + } + } + } + + + // OCL +// if(qualifierName.equalsIgnoreCase("OCL")){ +// if (element instanceof Class){ +// List elementList = ((Class)element).getNearestPackage().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")){ +// +// //constraint.setSpecification(null); +// constrainedElements.remove(0); +// +// ArrayList tempList = new ArrayList(elementList.size()-1); +// for(int m = 0; m < elementList.size(); m++){ +// +// if(!(elementList.get(m) instanceof Constraint)){ +// tempList.add(elementList.get(m)); +// } else { +// Constraint constr = (Constraint)elementList.get(m); +// if(!constr.getName().equalsIgnoreCase(constraint.getName())){ +// tempList.add(constr); +// } +// } +// } +// elementList = tempList; +// constraint.destroy(); +// break; +// } +// +// String tempBody, body = ""; +// // prepare constraint body content +// if(newValue.startsWith("{")){ +// newValue = newValue.substring(1); +// } +// if(newValue.endsWith("}")){ +// int length = newValue.length(); +// newValue = newValue.substring(0, length -1); +// } +// tempBody = newValue.trim(); +// +// 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 +// ((OpaqueExpression)constraint.getSpecification()).setBody(body); +// } +// } +// } +// } +// } +// +// if(!foundConstraint && !newValue.equalsIgnoreCase("null")){ +// createClassOCL((Class)element, newValue); +// } +// } +// } + } + + private String getNamedElementType(NamedElement element){ + + String elementType = null; + if(element instanceof Class){ + elementType = "Class"; + if(element instanceof AssociationClass){ + elementType = "Association"; + } + } else if(element instanceof Property){ + if(propertyIsOwnedEnd((Property)element)){ + elementType = "Reference"; + } else { + elementType = "Property"; + } + } else if(element instanceof Operation){ + elementType = "Method"; + } else if(element instanceof Parameter){ + elementType = "Parameter"; + } + + return elementType; + } + + private int getNamedElementIntType(NamedElement element){ + int elementType = -1; + if(element instanceof Class){ + elementType = TCLASS; + } else if(element instanceof Property){ + if(propertyIsOwnedEnd((Property)element)){ + elementType = TLINK1; + } else { + elementType = TATTRIBUTE; + } + } else if(element instanceof Operation){ + elementType = TMETHOD; + } else if(element instanceof Parameter){ + elementType = TPARAMETER; + } + + return elementType; + } + } --- NEW FILE: CheckAndRepair.java --- /* * Created on 27.07.2005 */ package com.ibm.ecute.rsa.core.internal.properties; import java.util.ArrayList; import java.util.List; import org.eclipse.uml2.AssociationClass; import org.eclipse.uml2.Class; import org.eclipse.uml2.Model; import org.eclipse.uml2.NamedElement; import org.eclipse.uml2.Package; import org.eclipse.uml2.Property; import com.ibm.ecute.utils.License; /** * Copyright (c) 2005, International Business Machines * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES * RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html * * @author Benjamin Bender <be...@de...> * */ public class CheckAndRepair { // Copyright private static final String COPYRIGHT = License.COPYRIGHT; private Model model; private FlavorsHelper flavorsHelper; public CheckAndRepair(Model model){ this.model = model; this.flavorsHelper = new FlavorsHelper(model); } public void applyAllNativeInheritedValues(NamedElement element){ ArrayList orderedModelClasses = getOrderedModelClasses(element); for(int i = 0; i < orderedModelClasses.size(); i++){ flavorsHelper.applyNativeInheritedValues((NamedElement)orderedModelClasses.get(i), true); } } private ArrayList getOrderedModelClasses(NamedElement element){ ArrayList classes = getAllModelClasses(element); ArrayList orderedClasses = new ArrayList(classes.size()); // get all classes without parents for(int i = 0; i < classes.size(); i++){ if(((Class)classes.get(i)).getGenerals().size() == 0){ orderedClasses.add(classes.get(i)); } } ArrayList tempList = orderedClasses; while(orderedClasses.size() < classes.size()){ ArrayList newOrderedClasses = new ArrayList(); for(int i = 0; i < tempList.size(); i++){ Class class_ = (Class)tempList.get(i); ArrayList childClasses = getAllChildClasses(class_); newOrderedClasses.addAll(childClasses); } orderedClasses.addAll(newOrderedClasses); tempList = newOrderedClasses; } return orderedClasses; } private ArrayList getAllModelClasses(NamedElement element){ ArrayList classes = new ArrayList(); // this call is usually used to modify the ownedMembers in the model List tempList = model.getOwnedMembers(); // so the list has to be copied to work with it ArrayList packagesList = new ArrayList(tempList.size()); for(int i = 0; i < tempList.size(); i++){ packagesList.add(tempList.get(i)); } // get classes from packages and add to list for(int i = 0; i < packagesList.size(); i++){ Package currentPackage = (Package)packagesList.get(i); List packageMembersList = currentPackage.getOwnedElements(); for(int j = 0; j < packageMembersList.size(); j++){ if(packageMembersList.get(j) instanceof Class){ classes.add(packageMembersList.get(j)); } else if(packageMembersList.get(j) instanceof Package){ packagesList.add(packageMembersList.get(j)); } } } classes.trimToSize(); return classes; } public ArrayList getAllChildClasses(Class class_){ ArrayList childClasses = new ArrayList(); // get model classes ArrayList modelClasses = getAllModelClasses((NamedElement)class_); if(modelClasses.size() <= 0){ return null; } ArrayList currentChildren = new ArrayList(); currentChildren.add(class_); while(currentChildren.size() > 0){ String childClassName = ((Class)currentChildren.get(0)).getName(); int n = modelClasses.size(); for(int j = 0; j < n; j++){ if(((Class)modelClasses.get(j)).getGenerals().size() > 0 && (Class)((Class)modelClasses.get(j)).getGenerals().get(0) != null){ String className = ((Class)((Class)modelClasses.get(j)).getGenerals().get(0)).getName(); if(className.equalsIgnoreCase(childClassName)){ currentChildren.add(modelClasses.get(j)); childClasses.add(modelClasses.get(j)); //m++; modelClasses.remove(j); j--; n--; } } } currentChildren.remove(0); } childClasses.trimToSize(); return childClasses; } public ArrayList getOverrideSubProperties(Property property){ ArrayList subproperties = new ArrayList(); // check if property is a class property or an association end boolean isReference = isReference(property); // get subclasses of the class which contains the property ArrayList subclasses = getAllChildClasses((Class)property.getOwner()); // check if subclasses define the searched property for(int i = 0; i < subclasses.size(); i++){ Class subClass = (Class)subclasses.get(i); Property subProperty; if(isReference){ AssociationClass subAClass = (AssociationClass)subClass; subProperty = subAClass.getOwnedEnd(property.getName()); } else { subProperty = subClass.getOwnedAttribute(property.getName()); } if(subProperty != null){ // if the subclass defines the property then check if the subProperty has // the override qualifiers set if(FlavorsHelper.override(subProperty)){ subproperties.add(subProperty); } } } return subproperties; } public boolean isReference(NamedElement element){ boolean isRef = false; if(element instanceof Property){ Property property = (Property)element; if(property.getOwner() instanceof AssociationClass){ AssociationClass aClass = (AssociationClass)property.getOwner(); if(aClass.getOwnedEnd(property.getName()) != null){ isRef = true; } } } return isRef; } } Index: QualifiersPropertySection.java =================================================================== RCS file: /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/properties/QualifiersPropertySection.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- QualifiersPropertySection.java 25 Jul 2005 07:57:18 -0000 1.23 +++ QualifiersPropertySection.java 28 Jul 2005 17:59:51 -0000 1.24 @@ -89,6 +89,8 @@ private Button editValueButton; public Button showAllButton; + private Button inheritedValueButton; + private Button checkAndRepairButton; private TableColumn nameColumn; private TableColumn valueColumn; private TableColumn definedInColumn; @@ -117,7 +119,7 @@ FormData formdata = new FormData(); formdata.left = new FormAttachment(0,5); formdata.top = new FormAttachment(0,0); - editValueButton = getWidgetFactory().createButton(composite1, "Edit qualifiers", 8); + editValueButton = getWidgetFactory().createButton(composite1, "Edit qualifiers...", 8); editValueButton.setLayoutData(formdata); editValueButton.addSelectionListener(new SelectionAdapter() { @@ -145,6 +147,43 @@ } }); + + //formdata inherited values buootn + formdata = new FormData(); + formdata.left = new FormAttachment(showAllButton,30); + formdata.top = new FormAttachment(0,0); + inheritedValueButton = getWidgetFactory().createButton(composite1, "Apply inherited values", 8); + inheritedValueButton.setLayoutData(formdata); + inheritedValueButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent selectionevent) + { + final NamedElement element = (NamedElement)getEObject(); + FlavorsHelper flavorHelper = new FlavorsHelper(element.getModel()); + flavorHelper.applyNativeInheritedValues(element, true); + refresh(); + } + + }); + + //formdata inherited values buootn + formdata = new FormData(); + formdata.left = new FormAttachment(inheritedValueButton,10); + formdata.top = new FormAttachment(0,0); + checkAndRepairButton = getWidgetFactory().createButton(composite1, "Check and Repair", 8); + checkAndRepairButton.setLayoutData(formdata); + checkAndRepairButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent selectionevent) + { + final NamedElement element = (NamedElement)getEObject(); + CheckAndRepair checkAndRepair = new CheckAndRepair(element.getModel()); + checkAndRepair.applyAllNativeInheritedValues(element); + refresh(); + } + + }); + //Table qualifiersTable = getWidgetFactory().createTable(composite1, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE| SWT.MouseDoubleClick); |