From: Benjamin B. <bg...@us...> - 2005-06-02 16:21:39
|
Update of /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/dialogs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28343/Plugin/com/ibm/ecute/rsa/core/internal/dialogs Modified Files: EditQualifiersDialog.java Log Message: ECUTE 2.1 beta 1c: Support of native qualifier changes in the edit qualifiers dialog (changes of a native qualifier results in a change in the model) Index: EditQualifiersDialog.java =================================================================== RCS file: /cvsroot/sblim/ecute/Plugin/com/ibm/ecute/rsa/core/internal/dialogs/EditQualifiersDialog.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- EditQualifiersDialog.java 31 May 2005 13:12:47 -0000 1.5 +++ EditQualifiersDialog.java 2 Jun 2005 16:21:28 -0000 1.6 @@ -61,6 +61,7 @@ import org.eclipse.uml2.PackageableElement; 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; @@ -127,7 +128,6 @@ Button parentButton; Button editButton; Button removeButton; -// Button defaultButton; Composite valLegendComposite; Button applyButton; Button undoButton; @@ -186,11 +186,10 @@ String[] deletedQualifiers; int deletedQualifiersIndex; - //undo variables -// QualifierValueObject lastValueObject; -// int lastIndex; -// String lastAction; - + // in and out qualifier mapping variables + QualifierValueObject inValueObject = null; + QualifierValueObject outValueObject = null; + boolean first_inout = true; public EditQualifiersDialog(Shell shell, NamedElement element, int index, QualifiersPropertySection qualSec) { super(shell); @@ -232,7 +231,7 @@ new MessageBox(Display.getCurrent().getActiveShell(), SWT.YES|SWT.NO| SWT.ICON_QUESTION); - messageBox.setText("Perform changes?"); + messageBox.setText("Apply marks?"); messageBox.setMessage("You have made changes in the qualifier definitions.\n" + "Do you want to perform these changes now?"); if(messageBox.open() == SWT.YES){ @@ -242,6 +241,9 @@ } } fillValueTable(element); + + } else if(folder.getSelectionIndex() == 1){ + performMarksQuestion(); } } @@ -277,6 +279,8 @@ inheritComboBox.setText("Inheritance"); inheritComboBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { + // perform changes? + performMarksQuestion(); // get selected class String selected = inheritComboBox.getText(); uml2Model = getModel(element); @@ -328,6 +332,8 @@ propertiesComboBox.setText("Properties"); propertiesComboBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { + // perform changes? + performMarksQuestion(); // get selected property String selected = propertiesComboBox.getText(); if(element instanceof Class){ @@ -346,6 +352,8 @@ methodsComboBox.setText("Methods"); methodsComboBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { + // perform changes? + performMarksQuestion(); // get selected method String selected = methodsComboBox.getText(); if(element instanceof Class){ @@ -364,6 +372,8 @@ rolesComboBox.setText("Roles"); rolesComboBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { + // perform changes? + performMarksQuestion(); // get selected method String selected = rolesComboBox.getText(); if(element instanceof AssociationClass){ @@ -393,6 +403,8 @@ public void widgetSelected(SelectionEvent selectionevent) { + // perform changes? + performMarksQuestion(); if(element instanceof Property){ Property property = (Property)element; if(property.getOwner() instanceof Class) @@ -816,6 +828,8 @@ } } } else { + // perform changes? + performMarksQuestion(); this.close(); } } @@ -828,6 +842,10 @@ TableItem tableitem = valueTable.getItem(ai); QualifierValueObject valueObject = (QualifierValueObject)valueTable.getItem(ai).getData(); QualifierValueObject oldValueObject = cloneQualifierValueObject(valueObject); + + if(valueObject.name.equalsIgnoreCase("In")||valueObject.name.equalsIgnoreCase("Out")){ + setInOutValueObjects(valueObject); + } Dialog dialog = new EditValueDialog(Display.getCurrent().getActiveShell(), valueObject); if (dialog.open() == 0) { @@ -878,6 +896,30 @@ } } + private void setInOutValueObjects(QualifierValueObject valueObject){ + + if(valueObject.name.equalsIgnoreCase("In")){ + outValueObject = (QualifierValueObject)valueTable.getItem(getTableIndex(valueTable,"Out")).getData(); + }else if(valueObject.name.equalsIgnoreCase("Out")){ + inValueObject = (QualifierValueObject)valueTable.getItem(getTableIndex(valueTable,"In")).getData(); + } + } + + private int getTableIndex(Table table, String item){ + + int index = -1; + + TableItem[] items = table.getItems(); + for(int i = 0; i < items.length; i++){ + TableItem tableItem = items[i]; + if(tableItem.getText().equalsIgnoreCase(item)){ + index = i; + break; + } + } + return index; + } + private void editDefinition() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); int ai = definitionTable.getSelectionIndex(); @@ -1337,6 +1379,21 @@ } } + // set new qualifier value + for(int j = 0; j < editedValuesIndex; j++){ + + if(name.equalsIgnoreCase(editedValues[j].name)){ + qualifierValue = editedValues[j].value; + } + } + + for(int j = 0; j < removedValuesIndex; j++){ + + if(name.equalsIgnoreCase(removedValues[j].name)){ + qualifierValue = removedValues[j].value; + } + } + String as[] = {name, qualifierValue, type, definedIn, inheritance, translatable}; tableitem.setText(as); tableitem.setData(new QualifierValueObject(name, qualifierValue, type, definedIn, inheritance, @@ -1356,7 +1413,6 @@ tableitem.setBackground(RED); } } - return i; } @@ -2377,6 +2433,47 @@ deleteRemovedValues(); } + private void performMarksQuestion(){ + + if(editedValuesIndex > 0 || removedValuesIndex > 0){ + MessageBox messageBox = + new MessageBox(Display.getCurrent().getActiveShell(), + SWT.YES|SWT.NO| + SWT.ICON_QUESTION); + messageBox.setText("Apply marks?"); + messageBox.setMessage("You have changed the qualifier values.\n\n" + + "If you want to perform these changes now then\n" + + "click YES. Clicking NO will reset your changes."); + + int returnResult = messageBox.open(); + + if(returnResult == SWT.YES){ + + performValuesChanges(); + + valueTable.removeAll(); + fillValueTable(element); + + valLegendComposite.setVisible(false); + applyButton.setEnabled(false); + undoButton.setEnabled(false); + } + + else if(returnResult == SWT.NO){ + + resetEditedValues(); + resetRemovedValues(); + + valueTable.removeAll(); + fillValueTable(element); + + valLegendComposite.setVisible(false); + applyButton.setEnabled(false); + undoButton.setEnabled(false); + } + } + } + private class QualifierDefinitionObject{ private String name; private String type; @@ -2554,7 +2651,7 @@ this.name.equalsIgnoreCase("Inout")|| this.name.equalsIgnoreCase("Min")|| this.name.equalsIgnoreCase("Max")|| - this.name.equalsIgnoreCase("Octectstring")|| + this.name.equalsIgnoreCase("Octetstring")|| this.name.equalsIgnoreCase("Static")|| this.name.equalsIgnoreCase("Write")|| this.name.equalsIgnoreCase("Description")|| @@ -2825,7 +2922,7 @@ } - public void mapQualifierToModel(Element element, String qualifierName, String newValue){ + private void mapQualifierToModel(Element element, String qualifierName, String newValue){ // DESCRIPTION if(qualifierName.equalsIgnoreCase("Description")){ @@ -2861,8 +2958,208 @@ element.setValue(appliedStereo, "Value", 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 + if(element instanceof Parameter && first_inout && + (qualifierName.equalsIgnoreCase("In")||qualifierName.equalsIgnoreCase("Out"))){ + + String out = null; + String in = null; + Parameter parameter = (Parameter)element; + if(qualifierName.equalsIgnoreCase("In")){ + in = newValue; + out = outValueObject.value; + } else if(qualifierName.equalsIgnoreCase("Out")){ + in = inValueObject.value; + out = newValue; + } + + if(in.equalsIgnoreCase("true") && out.equalsIgnoreCase("false")){ + parameter.setDirection(ParameterDirectionKind.IN_LITERAL); + } else if(in.equalsIgnoreCase("true") && out.equalsIgnoreCase("true")){ + parameter.setDirection(ParameterDirectionKind.INOUT_LITERAL); + } else if(in.equalsIgnoreCase("false") && out.equalsIgnoreCase("true")){ + parameter.setDirection(ParameterDirectionKind.OUT_LITERAL); + } else if(in.equalsIgnoreCase("false") && out.equalsIgnoreCase("false")){ + parameter.setDirection(ParameterDirectionKind.IN_LITERAL); // "in" is default value in RSA + MessageBox messageBox = + new MessageBox(Display.getCurrent().getActiveShell(), + SWT.OK| + SWT.ICON_INFORMATION); + messageBox.setText("Invalid parameter direction"); + messageBox.setMessage("You have chosen an invalid parameter direction.\n\n" + + "You've set the \"in\" and \"out\" qualifiers to \"false\".\n" + + "In RSA/RSM each parameter has to have a direction.\n" + + "Since \"in\" is the default direction for a parameter in\n" + + "RSA/RSM, the \"in\" qualifier is set to \"true\" and the\n" + + "\"out\" qualifier is set to \"false\"."); + messageBox.open(); + } + } + + if(first_inout){ + first_inout = false; + } else { + first_inout = true; + } + + // MIN, MAX + 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) { + MessageBox messageBox = + new MessageBox(Display.getCurrent().getActiveShell(), + SWT.OK| + SWT.ICON_ERROR); + messageBox.setText("Illegal max value"); + messageBox.setMessage("You have chosen an invalid value for the \"max\" qualifier.\n\n" + + "The value of the \"max\" qualifier must be lower than the\n" + + "value of the \"min\" qualifier."); + messageBox.open(); + } + } + } + + //OCTETSTRING + if(qualifierName.equalsIgnoreCase("Octetstring")){ + if(newValue.equalsIgnoreCase("true")){ + uml2Model = getModel(element); + PrimitiveType octetstring = (PrimitiveType)uml2Model.getImportedMember("octetstring"); + if(element instanceof Property){ + Property prop = (Property)element; + prop.setType(octetstring); + } else if(element instanceof Operation){ + Operation op = (Operation)element; + Parameter returnType = op.getReturnResult("ReturnType"); + returnType.setType(octetstring); + } else if(element instanceof Parameter){ + Parameter param = (Parameter)element; + param.setType(octetstring); + } + } else if(newValue.equalsIgnoreCase("false")){ + + String elementString = ""; + + if(element instanceof Property){ + Property prop = (Property)element; + prop.setType(null); + elementString = "The type of this property is set to \"null\" now."; + } else if(element instanceof Operation){ + Operation op = (Operation)element; + Parameter returnType = op.getReturnResult("ReturnType"); + returnType.setType(null); + elementString = "The return type of this method is set to \"null\" now."; + } else if(element instanceof Parameter){ + Parameter param = (Parameter)element; + param.setType(null); + elementString = "The type of this parameter is set to \"null\" now."; + } + + MessageBox messageBox = + new MessageBox(Display.getCurrent().getActiveShell(), + SWT.OK| + SWT.ICON_INFORMATION); + messageBox.setText("\"Octetstring\" qualifier changed"); + messageBox.setMessage("You have set the value of the \"octetstring\" qualifier to false.\n\n" + + elementString); + messageBox.open(); + } + } + + // STATIC + 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 + 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 + 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 + if(qualifierName.equalsIgnoreCase("key")){ + if(element instanceof Property){ + Property property = (Property)element; + Stereotype stereo = property.getAppliedStereotype("CIM::Key"); + if(stereo == null){ + stereo = property.getApplicableStereotype("CIM::Key"); + } + if(newValue.equalsIgnoreCase("false")){ + property.unapply(stereo); + } else if(newValue.equalsIgnoreCase("true")){ + property.apply(stereo); + } + } + } + + /* // OCL if(qualifierName.equalsIgnoreCase("OCL")){ if (element instanceof Class){ @@ -3305,11 +3602,26 @@ private void updateEditedValues(){ + QualifierValueObject maxObject = null; + for(int i = 0; i < editedValuesIndex; i++){ QualifierValueObject object = editedValues[i]; - editValue(object, false); + if(object.name.equalsIgnoreCase("Max")){ + // ensure that changes of the max qualifier are always + // performed after the min qualifier is changed + maxObject = object; + } else { + editValue(object, false); + } + } + + if(maxObject != null){ + editValue(maxObject, false); } + first_inout = true; + + resetEditedValues(); } @@ -3415,6 +3727,7 @@ private class EditValueDialog extends Dialog{ QualifierValueObject valueObject; + Label textLabel; Button nullButton; Button trueButton; Button falseButton; @@ -3446,6 +3759,7 @@ formdata.top = new FormAttachment(0,5); label.setLayoutData(formdata); label.setText("Set value for " + valueObject.name + " (" + valueObject.datatype + ")"); + textLabel = label; if(valueObject.datatype.equalsIgnoreCase("Boolean")){ @@ -3461,7 +3775,6 @@ if (nullB.getSelection() == true){ trueButton.setEnabled(false); falseButton.setEnabled(false); - //booleanValue = "null"; } else { trueButton.setEnabled(true); falseButton.setEnabled(true); @@ -3484,7 +3797,6 @@ { trueButton.setSelection(true); falseButton.setSelection(false); - //booleanValue = "true"; } }); this.trueButton = trueButton; @@ -3541,6 +3853,41 @@ trueButton.setEnabled(true); falseButton.setEnabled(true); } + + // check datatype + if(valueObject.name.equalsIgnoreCase("Association")){ + textLabel.setText("You can't change the value of the \"association\" qualifier !\n\n" + + "Changing this value would mean that you'd like to tranform a class\n" + + "to an association or the other way round and this is not allowed."); + nullButton.setEnabled(false); + trueButton.setEnabled(false); + falseButton.setEnabled(false); + + } else if(valueObject.name.equalsIgnoreCase("Aggregate")){ + textLabel.setText("You can't change the value of the \"aggregate\" qualifier !\n\n" + + "If you want to change the kind of the association, then use the\n" + + "\"aggregation\" and \"composition\" qualifiers of the parent class.\n" + + "\"Aggregate\" is set \"false\" when \"aggregation\" is set \"false\"\n" + + "and it is set \"true\" when \"aggregation\" is set \"true\".\n\n" + + "If you want to change the direction of the association then you\n" + + "have to delete it from the model and draw it the other way round."); + nullButton.setEnabled(false); + trueButton.setEnabled(false); + falseButton.setEnabled(false); + + } else if(valueObject.name.equalsIgnoreCase("Aggregation") || + valueObject.name.equalsIgnoreCase("Composition") || + valueObject.name.equalsIgnoreCase("In") || + valueObject.name.equalsIgnoreCase("Out") || + valueObject.name.equalsIgnoreCase("Octetstring") || + valueObject.name.equalsIgnoreCase("Static") || + valueObject.name.equalsIgnoreCase("Write") || + valueObject.name.equalsIgnoreCase("Abstract") || + valueObject.name.equalsIgnoreCase("Key") ){ + + nullButton.setEnabled(false); + } + } else { textFieldValue = valueObject.value; @@ -3589,6 +3936,8 @@ if(!valueObject.value.equalsIgnoreCase("null")){ textField.setText(valueObject.value); + int end = textField.getText().length(); + textField.setSelection(0, end); } else { textField.setText("(null)"); textField.setEnabled(false); @@ -3613,6 +3962,11 @@ } } }); + + if(valueObject.name.equalsIgnoreCase("Min")){ + + nullButton.setEnabled(false); + } } return label; @@ -3625,60 +3979,13 @@ } else { nullValue = false; } - - if(valueObject.datatype.equalsIgnoreCase("String")){ - // check datatype - if(valueObject.datatype.equalsIgnoreCase("sint8")| - valueObject.datatype.equalsIgnoreCase("uint8")){ - try { - Byte byte_ = new Byte(textFieldValue); - if(valueObject.datatype.equalsIgnoreCase("uint8") && byte_.compareTo(new Byte("0")) < 0 ){ - correctDatatype = false; - } - } catch (NumberFormatException e) { - correctDatatype = false; - } - } - - if(valueObject.datatype.equalsIgnoreCase("sint16")| - valueObject.datatype.equalsIgnoreCase("uint16")){ - try { - Short short_ = new Short(textFieldValue); - if(valueObject.datatype.equalsIgnoreCase("uint16") && short_.compareTo(new Short("0")) < 0 ){ - correctDatatype = false; - } - } catch (NumberFormatException e) { - correctDatatype = false; - } - } - - if(valueObject.datatype.equalsIgnoreCase("sint32")| - valueObject.datatype.equalsIgnoreCase("uint32")){ - try { - Integer integer_ = new Integer(textFieldValue); - if(valueObject.datatype.equalsIgnoreCase("uint32") && - integer_.compareTo(new Integer("0")) < 0 ){ - correctDatatype = false; - } - } catch (NumberFormatException e) { - correctDatatype = false; - } + + // check integer datatype + if(!valueObject.datatype.equalsIgnoreCase("boolean")){ + if(valueObject.datatype.indexOf("int") > -1){ + correctDatatype = isCorrectIntValue(valueObject); } - - if(valueObject.datatype.equalsIgnoreCase("sint64")| - valueObject.datatype.equalsIgnoreCase("uint64")){ - try { - Long long_ = new Long(textFieldValue); - if(valueObject.datatype.equalsIgnoreCase("uint64") && - long_.compareTo(new Long("0")) < 0 ){ - correctDatatype = false; - } - } catch (NumberFormatException e) { - correctDatatype = false; - } - } } - if(nullButton.getSelection() == true){ correctDatatype = true; } @@ -3692,9 +3999,9 @@ messageBox.setMessage("The value does not fit the qualifier's datatype!\n" + "The type of this value must be " + valueObject.datatype + "."); messageBox.open(); - correctDatatype = true; textField.setFocus(); - textField.setSelection(0); + int end = textField.getText().length(); + textField.setSelection(0, end); } else { if(valueObject.datatype.equalsIgnoreCase("boolean")){ if(nullButton.getSelection()){ @@ -3709,6 +4016,62 @@ } this.close(); } + + correctDatatype = true; + } + + private boolean isCorrectIntValue(QualifierValueObject valueObject){ + + boolean correctDatatype = true; + + if(valueObject.datatype.equalsIgnoreCase("sint8")| + valueObject.datatype.equalsIgnoreCase("uint8")){ + try { + Byte byte_ = new Byte(textFieldValue); + if(valueObject.datatype.equalsIgnoreCase("uint8") && byte_.compareTo(new Byte("0")) < 0 ){ + correctDatatype = false; + } + } catch (NumberFormatException e) { + correctDatatype = false; + } + } + else if(valueObject.datatype.equalsIgnoreCase("sint16")| + valueObject.datatype.equalsIgnoreCase("uint16")){ + try { + Short short_ = new Short(textFieldValue); + if(valueObject.datatype.equalsIgnoreCase("uint16") && short_.compareTo(new Short("0")) < 0 ){ + correctDatatype = false; + } + } catch (NumberFormatException e) { + correctDatatype = false; + } + } + else if(valueObject.datatype.equalsIgnoreCase("sint32")| + valueObject.datatype.equalsIgnoreCase("uint32")){ + try { + Integer integer_ = new Integer(textFieldValue); + if(valueObject.datatype.equalsIgnoreCase("uint32") && + integer_.compareTo(new Integer("0")) < 0 ){ + correctDatatype = false; + } + } catch (NumberFormatException e) { + correctDatatype = false; + } + } + else if(valueObject.datatype.equalsIgnoreCase("sint64")| + valueObject.datatype.equalsIgnoreCase("uint64")){ + try { + Long long_ = new Long(textFieldValue); + if(valueObject.datatype.equalsIgnoreCase("uint64") && + long_.compareTo(new Long("0")) < 0 ){ + correctDatatype = false; + } + } catch (NumberFormatException e) { + correctDatatype = false; + } + } + + return correctDatatype; } } |