Java Reference
In-Depth Information
public List<EObject> getSemanticElementsBeingParsed(EObject
element) {
List<EObject> result = new ArrayList<EObject>();
if (element instanceof Attribute) {
result.add(element);
}
return result;
}
};}
return myParser;
}
public boolean provides(IOperation operation) {
if (operation instanceof GetParserOperation) {
IAdaptable hint = ((GetParserOperation) operation).getHint();
String visualID = (String) hint.getAdapter(String. class );
return AttributeEditPart.VISUAL_ID ==
DncVisualIDRegistry.getVisualID(visualID)
&& hint.getAdapter(EObject. class ) instanceof Attribute;
}
return false;
}
}
Starting at the bottom, we find that the IProvider.provides() method
returns true if the GetParserOperation passed contains a hint that resolves
to the AttributeEditPart 's visual ID and an instance of our Attribute
class. With this parser provider registered as a service provider, its getParser()
method is invoked to supply an implementation of ISemanticParser . The
implementation of the parser is crude, but it functions adequately for our sam-
ple. Notice that it loads all models in the resource set that are looking for
Datatypes to validate against. The idea with types is that a types.oocore , or
similar, is provided and loaded automatically, or users are given the option to
load their own types. The most important aspect of the parser is the
getParseCommand() method. As with all model modifications that take place
within the context of a GMF application, a transactional command is used
within the editing domain to effect the change.
Operation Parser Provider
Our Operation parser provider needs to be slightly more complex than our
Attribute parser provider, given the relative complexity of an Operation sig-
nature. We need to take into account the name of the operation, the return type ,
and each parameter name and type . As usual, we surround our parameters with
Search WWH ::




Custom Search