Hello,
For 8 days (9 hours a day) now, I have
been trying to add a handle to one EditPart, but my code
still does not work. I did not find any example concerning this
topic.
What did I try to do?:
I tried to add a little collapse Figure, visible
after selecting one node, to my Node's figure at the location
"PositionConstants.NORTH_EAST" (top right corner of my node) with the behaviour
that by clicking on this collapse figure the node takes a particular constant
size. (very similar behaviour to ResizableCompartmentEditPolicy and
its collapse figure)
In the API of SelectionHandlesEditPolicy it says that this class "... manages a List of handles provided
by the subclass. Handles are Figures which are added to the HANDLE layer ...".
Therefore I think I have to subclass this EditPolicy and to install
it in my EditPart.
My 2 naive approaches:
1) Mimic the behaviour of
ResizableCompartmentEditPolicy:
I tried to adjust the methods of
ResizableCompartmentEditPolicy, CompartmentCollapseHandle and
so on, but it did not work because the ResizableCompartmentEditPolicy is
customized to the compartment (Who would have thought it?) or something else and
my knowledge about GMF is not sufficient.
2) First try to add a figure (a collapse
handle) without any behaviour by installing your own EditPolicy (subclass
of SelectionHandlesEditPolicy) and overriding the
method createSelectionHandles:
public class MyEditPart
extends
ShapeNodeEditPart {
...
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
...
installEditPolicy("MyUniqueRole", new
MyEditPolicy());
}
...
}
public class MyEditPolicy extends
SelectionHandlesEditPolicy {
@Override
protected List
createSelectionHandles() {
List list
= new
ArrayList<MyCollapseHandle>();
list.add(
new
MyCollapseHandle( (IGraphicalEditPart) getHost()));
return list;
}
}
public class MyCollapseHandle extends AbstractHandle
{
public
MyCollapseHandle(IGraphicalEditPart owner) {
int direction =
PositionConstants.NORTH_EAST;
setOwner(owner);
setLocator(new
RelativeHandleLocator(owner.getFigure(), direction));
setCursor(Cursors.ARROW);
}
@Override
protected DragTracker
createDragTracker() {
return null;
}
@Override
public void paintFigure(Graphics graphics) {
// painting of my collapse
figure ...
}
}
This did not work too. Each time I select the node
eclipse has a painting loop or somthing like that, but I can select other
EditParts and it works as usual. Thus I have to implement more
stuff.
Questions:
Can anybody help please? How do you add a selection
handle to an EditPart? I would be happy to be able to create such a selection
handle (as a first step: a selection handle without any
behaviour).
Thanks in advance,
Markus
|