Java Reference
In-Depth Information
Our
LinkDecoratorProvider
class appears next. It extends the
AbstractProvider
and implements the
IDecoratorProvider
. In both the
provides()
and
createDecorators()
methods, we use the
getDecorator
TargetNode()
static method on our
LinkDecorator
class, which is listed
below our provider code.
public class
LinkDecoratorProvider
extends
AbstractProvider
implements
IDecoratorProvider {
public static final
String HYPERLINK_DECORATOR_ID = "hyperlink";
public boolean
provides(IOperation operation) {
if
(
false
== operation
instanceof
CreateDecoratorsOperation) {
return false
;
}
IDecoratorTarget decoratorTarget =
((CreateDecoratorsOperation) operation).getDecoratorTarget();
return
LinkDecorator.getDecoratorTargetNode(decoratorTarget) !=
null
;
}
public void
createDecorators(IDecoratorTarget decoratorTarget) {
Node node =
LinkDecorator.getDecoratorTargetNode(decoratorTarget);
if
(node !=
null
) {
decoratorTarget.installDecorator(HYPERLINK_DECORATOR_ID,
new
LinkDecorator(decoratorTarget));
}
}
}
public class
LinkDecorator
extends
AbstractDecorator {
private static final
Image LINK;
static
{
URL url = FileLocator.find(Activator.getDefault().getBundle(),
new
Path("images" + IPath.SEPARATOR + "link.gif"),
null
);
ImageDescriptor imgDesc = ImageDescriptor.createFromURL(url);
LINK = imgDesc.createImage();
}
public
LinkDecorator(IDecoratorTarget decoratorTarget) {
super
(decoratorTarget);
}
static public
Node getDecoratorTargetNode(IDecoratorTarget
decoratorTarget) {
CustomStyle style =
null
;
View node = (View) decoratorTarget.getAdapter(View.
class
);
if
(node !=
null
&& node.eContainer()
instanceof
Diagram) {
style = (CustomStyle)
node.getStyle(StylePackage.eINSTANCE.getCustomStyle());
if
(style !=
null
) {
Search WWH ::
Custom Search