Java Reference
In-Depth Information
Attribute Parser Provider
For attributes, we want to enter
name:Type
in the label on the diagram and have
it parsed properly to set the
name
and
dataType
fields of the underlying
Attribute
domain element. Of course, we want the label to display
name:Type
even when changes are made to the underlying model through the
properties view, for example. To begin, we create a new (empty)
org.
eclipse.dnc.diagram.custom
plug-in to our workspace and contribute to
the
parserProviders
extension-point, as follows:
<extension
point="org.eclipse.gmf.runtime.common.ui.services.parserProviders">
<ParserProvider
class="org.eclipse.dnc.diagram.providers.AttributeParserProvider">
<Priority name="Low"/>
</ParserProvider>
</extension>
We need to provide the
AttributeParserProvider
class, which extends
the runtime's
AbstractProvider
and implements the
IParserProvider
interface. This is the class, which still could use some optimization but works
well enough for now:
public class
AttributeParserProvider
extends
AbstractProvider
implements
IParserProvider {
private
IParser myParser;
public
IParser getParser(IAdaptable hint) {
if
(myParser ==
null
) {
myParser =
new
ISemanticParser() {
public
IContentAssistProcessor getCompletionProcessor(IAdaptable
element) {
return
null;
}
public
String getEditString(IAdaptable element,
int
flags) {
Attribute attribute = getAttribute(element);
return
attribute.getName() !=
null
? attribute.getName()
+ ":" + (attribute.getDataType() !=
null
?
attribute.getDataType().getName() : "") : "";
}
public
ICommand getParseCommand(IAdaptable element,
final
String newString,
int
flags) {
int
index = newString.indexOf(":");
final
String name;
final
String typeName;
Search WWH ::
Custom Search