Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [HELP] Creating an element in the canvas by double clicking an palette element(I want to drop an element from the palette to the canvas by first selecting the target and then double click the element to throw it in the canvas)
[HELP] Creating an element in the canvas by double clicking an palette element [message #1449782] Tue, 21 October 2014 20:42
Martin Cousido is currently offline Martin CousidoFriend
Messages: 5
Registered: October 2014
Junior Member
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);
    }
Previous Topic:Zest Sequence Diagrams
Next Topic:Custom Ruler Units
Goto Forum:
  


Current Time: Fri Apr 19 07:29:38 GMT 2024

Powered by FUDForum. Page generated in 0.02834 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top