[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[News.eclipse.technology.gmf] Re: Modifying XXXStructuralFeaturesParser to work on different semantical elements; was: Re: Label icons and label display string using UML2 ecore model

Hi Thomas!
thanks for your reply.
In the meantime I solved on my own...but I will have a look at your solution...
In my solution the type of a property is not editable, it is necessary to select the type in the property view (I think this is correct because the type of a property could be a valid type).
For operations, I can show an unknown number of input parameter and the type of the out parameter; but at moment I don't know how to allow adding parameter to an operation because the operation is mapped as a label in a compartment. so I need to add parameter from the model editor...any idea about that?
thanks again
michele


Thomas Weiler ha scritto:
Hi Michele!

Sorry for the late answer but I missed your posting.

Michele Puccio schrieb:
Hi Thomas can you explain how did you modify StructuralFeaturesParser
to display property as *name:Type*? I tried but I had no luck... Thanks

In the PropertyEditPart I have created a method "List getParserElements()" which returns a list containing the property itself and its type.


Additionally I have modified the generated method String getLabelText() in the following way

protected String getLabelText() {
String text = null;
/**
* Creates a list of EObjectAdapters for each semantical element referenced
* by the label and gives this list to
* VariabilityStructuralFeaturesParser.getPrintString
*/
if (getParser() != null) {
List adapters = new ArrayList();
List elements = getParserElements();
for (Iterator it = elements.iterator(); it.hasNext();) {
adapters.add(new EObjectAdapter((EObject) it.next()));
}
text = ((VariabilityStructuralFeaturesParser) getParser()) ..getPrintString(adapters, getParserOptions().intValue());
}
if (text == null || text.length() == 0) {
text = defaultText;
}
return text;
}


In the method createPropertyProperty_XXXXParser of XXXParserProvider I have added the feature "name" twice to the list of features handled by the parser (one for the property's name and one for the name of it's type)

features.add(UMLPackage.eINSTANCE.getNamedElement().getEStructuralFeature("name"));

//$NON-NLS-1$
features.add(UMLPackage.eINSTANCE.getNamedElement().getEStructuralFeature("name"));


//$NON-NLS-1$
VariabilityStructuralFeaturesParser parser = new VariabilityStructuralFeaturesParser(features);


PropertyProcessor processor = new PropertyProcessor();
parser.setViewProcessor(processor);


Changes in XXXStructuralFeaturesParser:

/**
* Returns the print string which is build up from features of the given
* adapters
*
* @param adapters
* EObjectAdapters for the semantical elements referenced
* @param flags
* @return Print string e.g. for label
*/
public String getPrintString(List adapters, int flags) {
return getStringByPattern(adapters, flags, getViewPattern(), getViewProcessor());
}


/**
* Returns a string in accordance to the given pattern and based on the
list
* of semantical elements/adapters
*
*/
protected String getStringByPattern(List adapters, int flags, String pattern, EditableLabelProcessor processor) {
List values = new ArrayList(features.size());
Iterator el = adapters.iterator();
for (Iterator it = features.iterator(); it.hasNext() && el.hasNext();){
EObject element = (EObject) ((IAdaptable) el.next()) ..getAdapter(EObject.class);


EStructuralFeature feature = (EStructuralFeature) it.next();
Object value = element.eGet(feature);
value = getValidValue(feature, value);
values.add(value);
}
return processor.format(values.toArray(new Object[values.size()]),new StringBuffer()).toString();
}


Additionaly I have defined a class PropertyProcessor (which can also be
used for supporting direct editing):

public class PropertyProcessor extends EditableLabelProcessor {

    @Override
    public Object format(Object[] objects, StringBuffer buffer) {
        String retString = objects[0] + "";
        if (objects.length == 2) {
            retString = retString + ":" + objects[1];
        }
        return retString;
    }

@Override
public Object[] parse(String editString) {
List result = new ArrayList();
int index = editString.indexOf(":");
String name = null;
if(index!=-1){
name = editString.substring(0, index);
String type = editString.substring(index+1);
result.add(name);
result.add(type);
}else{
name = editString;
result.add(name);
}


        return result.toArray();
    }

}

The same mechanism can be used for e.g. displaying an operation in the form "name(parameter:type):returnType".

I hope I have not missed something. Please do not hesitate to ask again
if something is unclear.

Thomas