I've already an action defined for drag and drop, I want to keep that but I also want to add the option for the user to double click the ToolEntry and add it to the selected part of the canvas.
I could figure out the logic of that part, I'm using a custom factory with a custom ToolEntryEditPart that has the performRequest() method overriden. The problem is after I perform that request of the double click using RequestConstants.REQ.OPEN, it also fires the mouseUp method after the REQ.OPEN so my mouse cursor stays with a plus sign which means the element is still selected and if you click on canvas it can be added again. I need somehow to bypass that mouseUp event after the double click event, I don't want to change the drag and drop behaviour just add the double click behaviour.
I will post some code below.
Thank you in advance.
Martin
public class ToolEntryEditPartDClick extends ToolEntryEditPart {
private PaletteEntry paletteEntry;
public PaletteEntry getPaletteEntry() {
return paletteEntry;
}
@SuppressWarnings("restriction")
public ToolEntryEditPartDClick(PaletteEntry paletteEntry) {
super(paletteEntry);
this.paletteEntry = paletteEntry;
}
@Override
public void performRequest(org.eclipse.gef.Request req) {
if (req.getType() == RequestConstants.REQ_OPEN)
{
CommandStack cmdStack = getViewer().getEditDomain().getCommandStack();
cmdStack.execute(this.getCommand(req));
}
};
@Override
public Command getCommand(org.eclipse.gef.Request req)
{
CompoundCommand compCommand = new CompoundCommand();
compCommand.add(super.getCommand(req));
if (req.getType() == RequestConstants.REQ_OPEN) {
compCommand.add(new TestCommand(this));
}
return compCommand;
}
}
@Override
public void execute() {
GraphicalViewer viewer = MessageFlowUtils.getFlowEditorFromActivePage().getViewer();
List selectedEditParts = viewer.getSelectedEditParts();
if (selectedEditParts.size() == 0) return;
Object selectedEditPart = selectedEditParts.get(0);
if (selectedEditPart instanceof EntityEditPart) {
EntityEditPart<?> selectedPart = (EntityEditPart<?>) selectedEditPart;
Command addComponentCommand = inside(selectedPart);
if (addComponentCommand != null && addComponentCommand.canExecute()) {
addComponentCommand.execute();
}
}
//Here this executes and selects the default tool entry the problem is after this command executes, the mouseUp fires and overrides this behaviour
MessageFlowUtils.getFlowEditorFromActivePage().getPalleteViewer().setActiveTool(null);
}