Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Confirm delete shape
Confirm delete shape [message #227252] Thu, 23 April 2009 16:04 Go to next message
Eclipse UserFriend
Originally posted by: gerg_nast.yahoo.com

Hi all,

Upon deletion of a node, I'd like to pop-up a confirmation dialog (do you
really want to delete this node? Yes/No). Where is the most suitable place
to call this dialog?

I tried in XXXEditPart.getCommand(Request) and in
XXXItemSemanticEditPolicy.getCommand(Request), but as they are also called
when the node is being selected, I did some if-checks, like:

if (_request instanceof GroupRequest &&
_request.getType().equals("delete"))

or

if (_request instanceof EditCommandRequestWrapper
&& ((EditCommandRequestWrapper)_request).getEditCommandRequest( )
instanceof DestroyElementRequest
&&
((DestroyElementRequest)((EditCommandRequestWrapper)_request ).getEditCommandRequest()).isConfirmationRequired())

but none of them seems quite ok and I'm sure that there is a better place
to open up this dialog... any suggestions?

Regards,
Gergana
Re: Confirm delete shape [message #236166 is a reply to message #227252] Wed, 15 July 2009 08:57 Go to previous messageGo to next message
Jevon  is currently offline Jevon Friend
Messages: 164
Registered: July 2009
Senior Member
Hi,

I too needed to get a confirmation dialog box working. The blog post at
http://blogs.itemis.de/wloch/2009/04/01/gmfintercepting-dele tion-of-figures/
might help.

However I found that, without having to reimplement a dozen internal
classes, a confirmation box can be added to an XXXDiagramEditor by
adding the following methods:

/**
* @generated NOT
*/
@SuppressWarnings("restriction")
public class MyDeleteAction extends PromptingDeleteAction {

public MyDeleteAction(IWorkbenchPart part) {
super(part);
}

@Override
public void run() {
if (confirm()) {
super.run();
}
}

private boolean confirm() {
return
MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiv eWorkbenchWindow().getShell(),
"Confirmation", "Are you sure you want to delete this node?");
}

}

/**
* @generated NOT
*/
@Override
protected KeyHandler getKeyHandler() {
KeyHandler handler = super.getKeyHandler();

// replace the delete action handler
getActionRegistry().registerAction(new MyDeleteAction(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActivePart()
));

// refresh delete actions
handler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
getActionRegistry().getAction(ActionFactory.DELETE.getId())) ;
handler.put(KeyStroke.getPressed(SWT.BS, 8, 0),
getActionRegistry().getAction(ActionFactory.DELETE.getId())) ;

return handler;
}

It should be easy enough to put this into a dynamic template for
XXXDiagramEditor.

Unfortunately, PromptingDeleteAction is internal, so you need to add the
suppress restrictions command to MyDeleteAction.

Jevon

Gergana wrote:
> Hi all,
>
> Upon deletion of a node, I'd like to pop-up a confirmation dialog (do
> you really want to delete this node? Yes/No). Where is the most suitable
> place to call this dialog?
>
> I tried in XXXEditPart.getCommand(Request) and in
> XXXItemSemanticEditPolicy.getCommand(Request), but as they are also
> called when the node is being selected, I did some if-checks, like:
>
> if (_request instanceof GroupRequest &&
> _request.getType().equals("delete"))
> or
>
> if (_request instanceof EditCommandRequestWrapper &&
> ((EditCommandRequestWrapper)_request).getEditCommandRequest( ) instanceof
> DestroyElementRequest &&
> ((DestroyElementRequest)((EditCommandRequestWrapper)_request ).getEditCommandRequest()).isConfirmationRequired())
>
>
> but none of them seems quite ok and I'm sure that there is a better
> place to open up this dialog... any suggestions?
>
> Regards,
> Gergana
>
>
Re: Confirm delete shape [message #236174 is a reply to message #236166] Wed, 15 July 2009 09:37 Go to previous message
Jevon  is currently offline Jevon Friend
Messages: 164
Registered: July 2009
Senior Member
A minor correction: The code below will throw NullPointerExceptions when
initialising the KeyHandler for the first time. The solution is to use
the current editor as the IWorkbenchPart rather than the current window
from PlatformUI:

getActionRegistry().registerAction(new MyDeleteAction(this));

Jevon

Jevon Wright wrote:
> Hi,
>
> I too needed to get a confirmation dialog box working. The blog post at
> http://blogs.itemis.de/wloch/2009/04/01/gmfintercepting-dele tion-of-figures/
> might help.
>
> However I found that, without having to reimplement a dozen internal
> classes, a confirmation box can be added to an XXXDiagramEditor by
> adding the following methods:
>
> /**
> * @generated NOT
> */
> @SuppressWarnings("restriction")
> public class MyDeleteAction extends PromptingDeleteAction {
>
> public MyDeleteAction(IWorkbenchPart part) {
> super(part);
> }
>
> @Override
> public void run() {
> if (confirm()) {
> super.run();
> }
> }
>
> private boolean confirm() {
> return
> MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiv eWorkbenchWindow().getShell(),
> "Confirmation", "Are you sure you want to delete this node?");
> }
>
> }
>
> /**
> * @generated NOT
> */
> @Override
> protected KeyHandler getKeyHandler() {
> KeyHandler handler = super.getKeyHandler();
>
> // replace the delete action handler
> getActionRegistry().registerAction(new MyDeleteAction(
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActivePart()
> ));
>
> // refresh delete actions
> handler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
> getActionRegistry().getAction(ActionFactory.DELETE.getId())) ;
> handler.put(KeyStroke.getPressed(SWT.BS, 8, 0),
> getActionRegistry().getAction(ActionFactory.DELETE.getId())) ;
>
> return handler;
> }
>
> It should be easy enough to put this into a dynamic template for
> XXXDiagramEditor.
>
> Unfortunately, PromptingDeleteAction is internal, so you need to add the
> suppress restrictions command to MyDeleteAction.
>
> Jevon
>
> Gergana wrote:
>> Hi all,
>>
>> Upon deletion of a node, I'd like to pop-up a confirmation dialog (do
>> you really want to delete this node? Yes/No). Where is the most
>> suitable place to call this dialog?
>>
>> I tried in XXXEditPart.getCommand(Request) and in
>> XXXItemSemanticEditPolicy.getCommand(Request), but as they are also
>> called when the node is being selected, I did some if-checks, like:
>>
>> if (_request instanceof GroupRequest &&
>> _request.getType().equals("delete"))
>> or
>>
>> if (_request instanceof EditCommandRequestWrapper &&
>> ((EditCommandRequestWrapper)_request).getEditCommandRequest( )
>> instanceof DestroyElementRequest &&
>> ((DestroyElementRequest)((EditCommandRequestWrapper)_request ).getEditCommandRequest()).isConfirmationRequired())
>>
>>
>> but none of them seems quite ok and I'm sure that there is a better
>> place to open up this dialog... any suggestions?
>>
>> Regards,
>> Gergana
>>
>>
Previous Topic:Diagram node as image
Next Topic:generate code from .gmfgen
Goto Forum:
  


Current Time: Fri Apr 19 23:03:55 GMT 2024

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

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

Back to the top