Old GEF problem [message #1785817] |
Fri, 20 April 2018 09:36  |
Filip Raszka Messages: 5 Registered: April 2018 |
Junior Member |
|
|
Hi, im using GEF 3.9 and I encountered a problem, which im not sure whether is connected with the old version of GEF, or some bug in my code.
In palette of the editor in my application I have CombinedTemplateCreationEntry. I think, that after selecting this entry and clicking on the editor there should be CreateRequest genereated and sent to corresponding Part.
I have a Part implemented with installed XYLayoutPolicy. It does handle the request as intended. The problem is, CreateRequest is generated instantly after I hover over the Part with the entry selected from palette. I believe it should be generated only after the Part is clicked on.
I have also implemented the drag-and-drop functionality, and it works fine. But I'd like to be able to pick a tool from palette and then create some elements by clicking on the container Part of the editor. Right now, the request is handled instanlty after mouse enters the container Part.
Code fragments:
- installing Policy in NodeEditPart:
@Override
protected void createEditPolicies()
{
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ChangeLayoutPolicy());
installEditPolicy(EditPolicy.NODE_ROLE, new RenamePolicy());
}
- Handling Request in Policy (called instantly after the hover):
@Override
protected Command getCreateCommand(CreateRequest request){
try{
if(request.getType() == REQ_CREATE && getHost() instanceof CrmWorkflowEditPart){
// preparing the command
-Creating the Entry fragment in getPaletteRoot():
PaletteDrawer stateElements = new PaletteDrawer("Stany");
root.add(stateElements);
ImageDescriptor workflowStateImage = ImagesUtil.getImageDescriptor(ImagesUtil.STATE);
PaletteNodeCreationFactory workflowStateFactory = new PaletteNodeCreationFactory(WorkflowState.class);
CombinedTemplateCreationEntry stateEntry = new CombinedTemplateCreationEntry("Workflow State", "Stan", WorkflowState.class,
workflowStateFactory, workflowStateImage, workflowStateImage);
stateElements.add(stateEntry);
stateEntry is the entry.
Thanks for Your time
|
|
|
Re: Old GEF problem [message #1785911 is a reply to message #1785817] |
Mon, 23 April 2018 05:31   |
|
Hi Filip,
the request is created and issued to the part you are currently hovering in order to determine whether the create operation is allowed there. In case the part replies with a command that is executable, the cursor will be updated to indicate that the creation is possible. As this decision is taken by the part, the request has to be sent to it in order to obtain the command already when hovering. When being clicked, the command is then executed.
Please be aware that there is a difference in handling a request by returning a command (this is what the part or more precisely its policies are responsible for) and executing the command when the click occurs (which is done by the tool).
Regards,
Alexander
|
|
|
Re: Old GEF problem [message #1785921 is a reply to message #1785911] |
Mon, 23 April 2018 07:32   |
Filip Raszka Messages: 5 Registered: April 2018 |
Junior Member |
|
|
Hi Alexander,
Thank you very much for the reply. I understand that now. However, I'd like to have one more question. In order to execute the command, I need to get some input from the user. If that was handled in the command, then canceling the prompt window would result in a "empty" command, which would be technically executed, and so present on the command stack and liable to undo/redo. The prompt window should appear only after the click, and If the user cancels it, I'd like the command to never be executed. How can I "dispose" of the command from inside of it, or intercept the command after the click, but before execution by the tool?
Again, thank You for Your time.
[Updated on: Mon, 23 April 2018 07:40] Report message to a moderator
|
|
|
Re: Old GEF problem [message #1785936 is a reply to message #1785921] |
Mon, 23 April 2018 10:30   |
|
You should not collect the user input from within the command. Instead, you should intercept the creation process and populate the request. Take a look into the CreationTool#handleButtonDown() or #handleButtonUp().
|
|
|
Re: Old GEF problem [message #1785940 is a reply to message #1785936] |
Mon, 23 April 2018 11:14   |
Filip Raszka Messages: 5 Registered: April 2018 |
Junior Member |
|
|
Avoiding collecting user input from within the command is what I did - however, right now im doing it inside the policy, and that causes the premature window appearing problem. I checked these methods and I have another question - does the tool, at the time handleButtonUp/Down is called, already have the command, the same that will be later executed, taken from the part? Then I'd need to fill it with user data and pass on. Or will the tool query for a command again, and I should instead update request and handle it in the policy (then policy would need to expect two "types" of requests - one without data, checking whether the creation is possible, and another with data).
Im sorry if I misunderstand something. Your responses have been very helpful so far.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02643 seconds