From: Benjamin B. <bg...@us...> - 2005-05-10 09:12:19
|
Update of /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/properties In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12154/Plugin/com/ibm/ecute/rsa/core/internal/properties Modified Files: QualifiersPropertySection.java Log Message: Version 2.1 alpha 6d Edit qualifiers dialog with main functionality added to RSA Index: QualifiersPropertySection.java =================================================================== RCS file: /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/properties/QualifiersPropertySection.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- QualifiersPropertySection.java 8 Apr 2005 09:11:18 -0000 1.11 +++ QualifiersPropertySection.java 10 May 2005 09:11:54 -0000 1.12 @@ -3,6 +3,9 @@ */ package com.ibm.ecute.rsa.core.internal.properties; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Iterator; @@ -14,37 +17,43 @@ import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.PlatformUI; import org.eclipse.uml2.AggregationKind; 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.Parameter; import org.eclipse.uml2.ParameterDirectionKind; 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.rsa.ui.internal.wizards.command.QualifierValueValidator; +import com.ibm.ecute.rsa.core.internal.dialogs.EditQualifiersDialog; import com.ibm.ecute.utils.License; import com.ibm.xtools.common.ui.properties.TabbedPropertySheetPage; import com.ibm.xtools.emf.msl.EditingDomain; @@ -64,16 +73,17 @@ * You can obtain a current copy of the Common Public License from * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html * - * @author Susanne Katz <ka...@de...> + * @author Susanne Katz <ka...@de...> + * Benjamin Bender <be...@de...> */ -public class QualifiersPropertySection extends AbstractModelerPropertySection { +public class QualifiersPropertySection extends AbstractModelerPropertySection{ // Copyright private static final String COPYRIGHT = License.COPYRIGHT; + + private static String QUALIFIERS_CONSTRAINT_NAME = "QualifiersList"; private Button editValueButton; - private Button defaultValueButton; - private Button removeButton; - private Button showAllButton; + public Button showAllButton; private TableColumn nameColumn; private TableColumn valueColumn; private TableColumn definedInColumn; @@ -82,7 +92,9 @@ private TableColumn flavorColumn; private Table qualifiersTable; private ArrayList defaultValueQualifiers; - //private Font boldFont; + + private static QualifiersList qualifiersList = null; + private boolean qualifiersListChanged = false; public QualifiersPropertySection() @@ -94,84 +106,41 @@ super.createControls(composite, tabbedpropertysheetpage); Composite composite1 = getWidgetFactory().createFlatFormComposite(composite); defaultValueQualifiers = new ArrayList(); - //formdata label - FormData formdata = new FormData(); - formdata.left = new FormAttachment(0, 0); - formdata.top = new FormAttachment(0, 0); - CLabel clabel = getWidgetFactory().createCLabel(composite1, "Qualifiers:"); - clabel.setLayoutData(formdata); - //formdata checkButton - formdata = new FormData(); - formdata.left = new FormAttachment(0, 0); - formdata.top = new FormAttachment(clabel, 4); - showAllButton = getWidgetFactory().createButton(composite1, "Show qualifiers with default value", SWT.CHECK); - showAllButton.setSelection(true); - showAllButton.setLayoutData(formdata); - showAllButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent selectionevent) - { - showAll(); - } - - }); //formdata editValueButton - formdata = new FormData(); - formdata.left = new FormAttachment(0,0); - formdata.top = new FormAttachment(showAllButton, 4); - editValueButton = getWidgetFactory().createButton(composite1, "Edit value", 8); + FormData formdata = new FormData(); + formdata.left = new FormAttachment(0,5); + formdata.top = new FormAttachment(0,0); + editValueButton = getWidgetFactory().createButton(composite1, "Edit qualifiers", 8); editValueButton.setLayoutData(formdata); editValueButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent selectionevent) { int ai = qualifiersTable.getSelectionIndex(); - if(ai != -1) - { - editValue(ai, false); - } - } - - }); - //formdata removeButton - formdata = new FormData(); - formdata.left = new FormAttachment(editValueButton, 4); - formdata.top = new FormAttachment(showAllButton, 4); - removeButton = getWidgetFactory().createButton(composite1, "Remove Qualifier", 8); - removeButton.setLayoutData(formdata); - removeButton.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent selectionevent) - { - int ai = qualifiersTable.getSelectionIndex(); - if(ai != -1) - { - removeQualifier(ai); - } + editValue(ai, false); } }); - //formdata defaultValueButton + + //formdata checkButton formdata = new FormData(); - formdata.left = new FormAttachment(removeButton, 4); - formdata.top = new FormAttachment(showAllButton, 4); - defaultValueButton = getWidgetFactory().createButton(composite1, "Default value", 8); - defaultValueButton.setLayoutData(formdata); - defaultValueButton.addSelectionListener(new SelectionAdapter() { + formdata.left = new FormAttachment(editValueButton, 30); + formdata.top = new FormAttachment(0,4); + showAllButton = getWidgetFactory().createButton(composite1, "Show qualifiers with default value", SWT.CHECK); + showAllButton.setSelection(true); + showAllButton.setLayoutData(formdata); + showAllButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent selectionevent) { - int ai = qualifiersTable.getSelectionIndex(); - if(ai != -1) - { - editValue(ai, true); - } + showAll(); } }); //Table - qualifiersTable = getWidgetFactory().createTable(composite1, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE); + qualifiersTable = getWidgetFactory().createTable(composite1, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE| SWT.MouseDoubleClick); qualifiersTable.setHeaderVisible(true); qualifiersTable.setLinesVisible(true); nameColumn = new TableColumn(qualifiersTable, 0); @@ -186,15 +155,15 @@ flavorColumn.setText("Flavor"); scopeColumn = new TableColumn(qualifiersTable, 0); scopeColumn.setText("Scope"); - qualifiersTable.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent selectionevent) - { - removeButton.setEnabled(isRemoveAllowed()); - editValueButton.setEnabled(isEditValueAllowed()); - defaultValueButton.setEnabled(isEditValueAllowed()); - } + qualifiersTable.addMouseListener(new MouseAdapter() { + public void mouseDoubleClick(MouseEvent e){ + int ai = qualifiersTable.getSelectionIndex(); + if(ai != -1) + { + editValue(ai, false); + } + } }); //formdata table @@ -203,22 +172,23 @@ formdata.right = new FormAttachment(100, 0); formdata.top = new FormAttachment(editValueButton, 4); formdata.bottom = new FormAttachment(100, -4); - //formdata.width = 600; formdata.height = 800; qualifiersTable.setLayoutData(formdata); - - //boldFont = new Font(Display.getDefault(), "TableItemFont_BOLD", 8, SWT.BOLD); + editValueButton.setEnabled(true); } public void refresh() { + if(!existsQualifierListConstraint()){ + + createQualifiersListConstraint(); + } + qualifiersTable.removeAll(); defaultValueQualifiers.clear(); - defaultValueButton.setEnabled(false); - removeButton.setEnabled(false); - editValueButton.setEnabled(false); + editValueButton.setEnabled(true); if(!(getEObject() instanceof NamedElement)) { packColumns(); @@ -235,13 +205,79 @@ if(((Parameter)element).getDirection().getValue() == ParameterDirectionKind.RETURN) return null; } - QualifiersList qualifiersList=null; - try { - qualifiersList = EcuteEclipsePlugin.getDefault().getQualifiersList(); - } catch (Exception e) { - //TODO Show ErrorDialog! - e.printStackTrace(); - } + + // tried to change the OCL qualifier of a class automatically + // when a class constraint body is changed --> failed +/* + 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)); + } + 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())){ + String body = ((OpaqueExpression)constraint.getSpecification()).getBody(); + int index = body.indexOf("\n"); + String qualifierValue = "{\""; + if (index != -1){ + qualifierValue = qualifierValue.concat(body.substring(0, index)); + } else { + qualifierValue = qualifierValue.concat(body.substring(0)); + } + qualifierValue = qualifierValue.concat("\""); + body = body.substring(index +1); + index = body.indexOf("\n"); + while (index != -1){ + qualifierValue = qualifierValue.concat(",\""); + qualifierValue = qualifierValue.concat(body.substring(0, index)); + qualifierValue = qualifierValue.concat("\""); + body = body.substring(index +1); + index = body.indexOf("\n"); + if(index == -1){ + qualifierValue = qualifierValue.concat(",\""); + qualifierValue = qualifierValue.concat(body.substring(0)); + qualifierValue = qualifierValue.concat("\""); + } + } + qualifierValue = qualifierValue.concat("}"); + System.out.println("OCL qualifier: " + qualifierValue); + Class thisClass = (Class)constrainedElements.get(k); + + Stereotype cimStereotype = thisClass.getAppliedStereotype("CIM::Qualifiers"); + List qualifierNameList = (List) thisClass.getValue(cimStereotype, "QualifierName"); + int stereotypeOCLIndex = -1; + for(int i = 0; i < qualifierNameList.size(); i++){ + if(qualifierNameList.get(i).toString().equalsIgnoreCase("OCL")){ + stereotypeOCLIndex = i; + } + } + thisClass.setValue(cimStereotype, "QualifierValue["+stereotypeOCLIndex+"]", qualifierValue); + } + } + } + } + } + } +*/ + if (qualifiersList == null || qualifiersListChanged == true){ + try { + qualifiersListChanged = false; + qualifiersList = EcuteEclipsePlugin.getDefault().getQualifiersList(getModel(), QUALIFIERS_CONSTRAINT_NAME); + if (qualifiersList == null){ + qualifiersList = EcuteEclipsePlugin.getDefault().getQualifiersList(); + } + } catch (Exception e) { + //TODO Show ErrorDialog! + e.printStackTrace(); + } + } Vector vector = qualifiersList.GetElements(); //make a copy of the qualifiers list to remove the qualifiers already displayed ArrayList allAvailableQualifers = new ArrayList(); @@ -649,107 +685,18 @@ protected void editValue(int ai, boolean setDefaultValue) { - //new EditQualifiers(); + if(!(getEObject() instanceof NamedElement)){ + return; + } + final NamedElement element = (NamedElement) getEObject(); - final QualifierValueObject qualifier = (QualifierValueObject)qualifiersTable.getItem(ai).getData(); - if(qualifier == null) - { - return; - } - - if(!(getEObject() instanceof Element)){ - return; - } - final Element element = (Element) getEObject(); - - if(!setDefaultValue){ - - InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Value Editor", - "Set new value for "+qualifier.name, qualifier.value, new QualifierValueValidator()); - - if (dialog.open() == 0) { - final String newValue = dialog.getValue(); - if (!qualifier.value.equalsIgnoreCase(newValue)) { - - EditingDomain editingDomain = UMLModeler.getEditingDomain(); - try { - if (qualifier.index == -1) { - //add Qualifier to Stereotype-Properties - - editingDomain.run(new ResourceSetModifyOperation("EditQualifier") { - - protected void execute(IProgressMonitor monitor) throws InvocationTargetException, - InterruptedException { - - Stereotype cimStereotype = element.getAppliedStereotype("CIM::Qualifiers"); - int stereotypePropertyIndex = ((List) element.getValue(cimStereotype, "QualifierName")) - .size(); - element.setValue(cimStereotype, "QualifierName[" + stereotypePropertyIndex + "]", qualifier.name); - element.setValue(cimStereotype, "QualifierValue[" + stereotypePropertyIndex + "]", newValue); - } - - }, new NullProgressMonitor()); - - } else { - - editingDomain.run(new ResourceSetModifyOperation("EditQualifier") { - - protected void execute(IProgressMonitor monitor) throws InvocationTargetException, - InterruptedException { - Stereotype cimStereotype = element.getAppliedStereotype("CIM::Qualifiers"); - element.setValue(cimStereotype, "QualifierValue[" + qualifier.index + "]", newValue); - } - - }, new NullProgressMonitor()); - - } - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - refresh(); - } - } - }else{ - - EditingDomain editingDomain = UMLModeler.getEditingDomain(); - try { - if(qualifier.index == -1){ - editingDomain.run( new ResourceSetModifyOperation("SetDefaultValue") { - - protected void execute(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - - Stereotype cimStereotype = element.getAppliedStereotype("CIM::Qualifiers"); - int stereotypePropertyIndex = ((List) element.getValue(cimStereotype, "QualifierName")).size(); - element.setValue(cimStereotype, "QualifierName["+stereotypePropertyIndex+"]", qualifier.name); - element.setValue(cimStereotype, "QualifierValue["+stereotypePropertyIndex+"]", qualifier.defaultValue); - } - }, new NullProgressMonitor()); - } else{ - editingDomain.run( new ResourceSetModifyOperation("SetDefaultValue") { - - protected void execute(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - - Stereotype cimStereotype = element.getAppliedStereotype("CIM::Qualifiers"); - element.setValue(cimStereotype, "QualifierValue["+qualifier.index+"]", qualifier.defaultValue); } - }, new NullProgressMonitor()); - } - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - refresh(); - } + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + + EditQualifiersDialog editPage = new EditQualifiersDialog(shell, element, ai, this); + if(editPage.open() == 0){ + refresh(); + } + return; } private int addQualiferToTable(String qualifierName, String qualifierValue, String definedIn, Qualifier qualifier, int index, boolean isDefaultQualifier) @@ -778,8 +725,6 @@ if(definedIn==null) definedIn = ""; - - String scope = ""; String flavor = ""; String defaultValue = "null"; @@ -805,14 +750,12 @@ }; tableitem.setText(as); tableitem.setData(new QualifierValueObject(name, qualifierValue, defaultValue, index)); -// if(showAllButton.getSelection()){ -// if(!isDefaultQualifier){ -// tableitem.setFont(boldFont); -// } -// } + return i; } + + protected boolean isRemoveAllowed() { if(isReadOnly()) @@ -831,8 +774,7 @@ return false; } } - - //TODO return true; + return true; } @@ -850,8 +792,7 @@ return false; } } - - //TODO return true; + return true; } @@ -895,7 +836,385 @@ update(notification, eobject); } - private class QualifierValueObject{ + public void mapQualifierToModel(Element element, String qualifierName, String newValue){ + if (element instanceof Class){ + if(qualifierName.equalsIgnoreCase("Description")){ + Comment descr = element.createOwnedComment(UML2Package.eINSTANCE.getComment()); + descr.setBody(newValue); + Stereotype stereo = descr.getApplicableStereotype("Default::Documentation"); + descr.apply(stereo); + } + if(qualifierName.equalsIgnoreCase("OCL")){ + 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)); + } + 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())){ + 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); + + + } + } + } + } + } + } + } + } + + public boolean getShowAll(){ + return showAllButton.getSelection(); + } + + public void setShowAll(boolean setValue){ + showAllButton.setSelection(setValue); + } + + public Model getModel(){ + + Model thisModel = null; + + NamedElement element = (NamedElement)getEObject(); + while(element.getOwner() != null){ + element = (NamedElement)element.getOwner(); + } + thisModel = (Model)element; + + return thisModel; + } + + private boolean existsQualifierListConstraint(){ + + Model model = getModel(); + Constraint qualifiersConstraint = model.getOwnedRule(QUALIFIERS_CONSTRAINT_NAME); + if(qualifiersConstraint == null){ + return false; + } else { + return true; + } + } + + private void createQualifiersListConstraint() { + EditingDomain editingDomain = UMLModeler.getEditingDomain(); + try { + + editingDomain.run(new ResourceSetModifyOperation("EditQualifier") { + + protected void execute(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + + Model model = getModel(); + Constraint qualifiersListConstraint = model.createOwnedRule(UML2Package.eINSTANCE.getConstraint()); + qualifiersListConstraint.setName(QUALIFIERS_CONSTRAINT_NAME); + qualifiersListConstraint.getConstrainedElements().add(model); + // create specification + qualifiersListConstraint.createSpecification(UML2Package.eINSTANCE.getOpaqueExpression()); + // set constraint body + String qualifierListTXTcontent = null; + try { + + String filename = EcuteEclipsePlugin.getDefault().getQualifierListDestination(); + + File f = new File(filename); + byte buffer[] = new byte[(int)f.length()]; + FileInputStream in = null; + String str = null; + + try + { + in = new FileInputStream(f); + + int len = in.read( buffer, 0, (int)f.length() ); + str = new String( buffer, 0, len ); + + } + catch ( IOException e ) { + e.printStackTrace(); + } + finally + { + try { + if ( in != null ) in.close(); + } catch (IOException e) {} + } + + if(str != null){ + while(str.startsWith("#")){ + int index = str.indexOf("\n"); + str = str.substring(index + 1); + } + } + qualifierListTXTcontent = str; + + } catch (Exception e) { + e.printStackTrace(); + } + + if(qualifierListTXTcontent != null){ + ((OpaqueExpression)qualifiersListConstraint.getSpecification()).setBody(qualifierListTXTcontent); + } + } + }, new NullProgressMonitor()); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void updateQualifiersListConstraint(final QualifiersList qualifiersList) { + EditingDomain editingDomain = UMLModeler.getEditingDomain(); + try { + + editingDomain.run(new ResourceSetModifyOperation("updateQualifiersListConstraint") { + + protected void execute(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + + Model model = getModel(); + Constraint qualifiersListConstraint = model.getOwnedRule(QUALIFIERS_CONSTRAINT_NAME); + // get constraint specification + OpaqueExpression constraintSpec = (OpaqueExpression)qualifiersListConstraint.getSpecification(); + // convert qualifiers list + String qualifierListString = convertQualifierListToString(qualifiersList); + // add new list to constraint + constraintSpec.setBody(qualifierListString); + } + }, new NullProgressMonitor()); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void removeQualifierStereotypesFromModel(final String qualifierName, final boolean classScope, + final boolean associationScope, final boolean propertyScope, final boolean methodScope, + final boolean parameterScope, final boolean referenceScope) { + + EditingDomain editingDomain = UMLModeler.getEditingDomain(); + try { + + editingDomain.run(new ResourceSetModifyOperation("removeQualifierStereotypesFromModel") { + + protected void execute(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + + Model model = getModel(); + List packages = model.getOwnedMembers(); + for(int i = 0; i < packages.size(); i++){ + List packageMembers = ((Package)packages.get(i)).getOwnedMembers(); + for(int j = 0; j < packageMembers.size(); j++){ + if(associationScope || referenceScope){ + if(packageMembers.get(j) instanceof AssociationClass){ + AssociationClass aClass = (AssociationClass)packageMembers.get(j); + if(associationScope){ + removeStereotypeFromUMLElement(qualifierName, aClass); + } + if(referenceScope){ + List ownedEnds = aClass.getOwnedEnds(); + for(int m = 0; m < ownedEnds.size(); m++){ + Property property = (Property)ownedEnds.get(m); + removeStereotypeFromUMLElement(qualifierName, property); + } + } + } + } + + if(classScope||propertyScope||methodScope||parameterScope) { + + if(packageMembers.get(j) instanceof Class && !(packageMembers.get(j) instanceof AssociationClass)){ + Class cClass = (Class)packageMembers.get(j); + + if(classScope){ + removeStereotypeFromUMLElement(qualifierName, cClass); + } + if(propertyScope){ + List attributes = cClass.getOwnedAttributes(); + for(int m = 0; m < attributes.size(); m++){ + Property property = (Property)attributes.get(m); + removeStereotypeFromUMLElement(qualifierName, property); + } + } + if(methodScope || parameterScope){ + List methods = cClass.getOwnedOperations(); + for(int n = 0; n < methods.size(); n++){ + Operation operation = (Operation)methods.get(n); + if(methodScope){ + removeStereotypeFromUMLElement(qualifierName, operation); + } + if (parameterScope){ + List parameters = operation.getOwnedParameters(); + for(int p = 0; p < parameters.size(); p++){ + Parameter parameter = (Parameter)parameters.get(p); + removeStereotypeFromUMLElement(qualifierName, parameter); + } + } + } + } + } + } + } + } + } + }, new NullProgressMonitor()); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public QualifiersList getQualifiersList(){ + return qualifiersList; + } + + public void setQualifiersList(QualifiersList newList){ + + qualifiersList = newList; + } + + public boolean getQualifiersListChanged(){ + return qualifiersListChanged; + } + + public void setQualifiersListChanged(boolean newValue){ + qualifiersListChanged = newValue; + } + + public String convertQualifierListToString(QualifiersList qualifiersList){ + + String qualifiersListString = ""; + + Vector listElements = qualifiersList.GetElements(); + int size = listElements.size(); + + for(int i = 0; i < size; i++){ + String item = ""; + Qualifier currentQualifier = (Qualifier)listElements.get(i); + String type = ""; + if(currentQualifier.type2String() != null){ + type = (currentQualifier.type2String()).toLowerCase(); + } + item = item.concat(currentQualifier.name + "=" + type + ","); + String defaultValue = ""; + if(currentQualifier.defaultValue == null){ + defaultValue = "nnuullll"; + } else { + defaultValue = currentQualifier.defaultValue; + } + item = item.concat(defaultValue +","); + if(currentQualifier.classScope) + item = item.concat(" class"); + if(currentQualifier.associationScope) + item = item.concat(" association"); + if(currentQualifier.indicationScope) + item = item.concat(" indication"); + if(currentQualifier.propertyScope) + item = item.concat(" property"); + if(currentQualifier.methodScope) + item = item.concat(" method"); + if(currentQualifier.parameterScope) + item = item.concat(" parameter"); + if(currentQualifier.referenceScope) + item = item.concat(" reference"); + item = item.concat(","); + + if(currentQualifier.DissableOverrideFlavor) + item = item.concat(" DissableOverride"); + if(currentQualifier.RestrictedFlavor) + item = item.concat(" Restricted"); + if(currentQualifier.TranslatableFlavor) + item = item.concat(" TranslatableFlavor"); + item = item.concat("\r\n"); + + qualifiersListString = qualifiersListString.concat(item); + } + + return qualifiersListString; + } + + private void removeStereotypeFromUMLElement(final String qualifierName, Element element) { + + boolean containsQualifier = false; + + Stereotype cimStereotype = element.getAppliedStereotype("CIM::Qualifiers"); + List qualifierNames = (List) element.getValue(cimStereotype, "QualifierName"); + + for(int j = 0; j < qualifierNames.size(); j++){ + + String name = (String)qualifierNames.get(j); + if(name.equalsIgnoreCase(qualifierName)){ + containsQualifier = true; + j = qualifierNames.size(); + } + } + + if(containsQualifier){ + // new Stereotype + Stereotype newCimStereotype = element.getAppliedStereotype("CIM::Qualifiers"); + List newQualifierNames = (List) element.getValue(newCimStereotype, "QualifierName"); + List newQualifierValues = (List) element.getValue(newCimStereotype, "QualifierValue"); + + List names = new ArrayList(); + List values = new ArrayList(); + names.addAll(newQualifierNames); + values.addAll(newQualifierValues); + newQualifierNames.clear(); + newQualifierValues.clear(); + + for(int i = 0; i < names.size(); i++){ + String name = (String)names.get(i); + String value = (String)values.get(i); + + if(!qualifierName.equalsIgnoreCase(name)){ + newQualifierNames.add(name); + newQualifierValues.add(value); + } + } + + for(int j = 0; j < newQualifierNames.size(); j++){ + element.setValue(newCimStereotype, "QualifierName[" + j + "]", newQualifierNames.get(j)); + element.setValue(newCimStereotype, "QualifierValue[" + j + "]", newQualifierValues.get(j)); + } + } + } + + private class QualifierValueObject{ private String name; private String value; private String defaultValue; |