Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » ViewPart OnClose Event(ViewPart OnClose Event)
ViewPart OnClose Event [message #544327] Fri, 02 July 2010 11:32 Go to next message
zabi is currently offline zabiFriend
Messages: 11
Registered: July 2009
Junior Member
Hi,
is there any Listener to add to a viewpart so that, if the user try to close the view, a notification dialog <yes, Abort> will be opened and the user can by clicking ok close the view or by clicking abort not closing it.

Thanks
Re: ViewPart OnClose Event [message #544329 is a reply to message #544327] Fri, 02 July 2010 11:48 Go to previous messageGo to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

Try: view.getSite().getWorkbenchWindow().addPerspectiveListener(n ew
IPerspectiveListener2() { ... });
The method on IPerspectiveListener2 gets called before the view or its
controls are disposed, and the id parameter indicates which view is being
closed. Don't forget to remove the listener in your view's dispose method.

It would help to know more about what you're trying to do here. There may
be a cleaner way.


hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Re: ViewPart OnClose Event [message #544348 is a reply to message #544329] Fri, 02 July 2010 12:48 Go to previous messageGo to next message
zabi is currently offline zabiFriend
Messages: 11
Registered: July 2009
Junior Member
Thanks for your answer, but how can i avoid that the view will be closed. for example when the user click on abort button <dont like to exit the view>.

Thanks.
Re: ViewPart OnClose Event [message #544358 is a reply to message #544348] Fri, 02 July 2010 13:12 Go to previous messageGo to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

Well a standard view does not have a close button. Only an a close button if you give it a closable option in the plugin.xml. So if you remove the closable and do not have anny buttons that are couse the view to be closed. then yoru good. But your sounding likeyour talking about an Dialog.

hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Re: ViewPart OnClose Event [message #544366 is a reply to message #544358] Fri, 02 July 2010 13:19 Go to previous messageGo to next message
zabi is currently offline zabiFriend
Messages: 11
Registered: July 2009
Junior Member
Thanks for the answer,

no it is a view what i have. derived from ViewPart and is closeable. I need it closeable but if the user have not saved the jobs on the view, i must give him a notification and possibility to abort the close.

Thanks.
Re: ViewPart OnClose Event [message #544369 is a reply to message #544327] Fri, 02 July 2010 13:21 Go to previous messageGo to next message
zabi is currently offline zabiFriend
Messages: 11
Registered: July 2009
Junior Member
Some thing more: it is like on eclipse: If you edit a file and you want to close the tab, it comes a dialog to tell you if you want to save changes. its the same scenario for me.
Re: ViewPart OnClose Event [message #544372 is a reply to message #544369] Fri, 02 July 2010 13:27 Go to previous messageGo to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

You could extend the view to SavablePart so you can use the Dirty state.

hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Re: ViewPart OnClose Event [message #544663 is a reply to message #544372] Mon, 05 July 2010 08:19 Go to previous messageGo to next message
zabi is currently offline zabiFriend
Messages: 11
Registered: July 2009
Junior Member
i can not find the "SavablePart" class in the environement.
Re: ViewPart OnClose Event [message #544669 is a reply to message #544663] Mon, 05 July 2010 08:26 Go to previous messageGo to next message
Benjamin Muskalla is currently offline Benjamin MuskallaFriend
Messages: 338
Registered: July 2009
Senior Member
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/ui/ISaveablePart. html

zabi wrote:
> i can not find the "SavablePart" class in the environement.


--
Benjamin Muskalla | EclipseSource Karlsruhe
http://www.eclipsesource.com | http://twitter.com/eclipsesource
Re: ViewPart OnClose Event [message #544722 is a reply to message #544669] Mon, 05 July 2010 11:26 Go to previous messageGo to next message
zabi is currently offline zabiFriend
Messages: 11
Registered: July 2009
Junior Member
Hi,
yes it works but i how can i ovveride the text shown on the yes,no Dialog?

Thanks
Re: ViewPart OnClose Event [message #544737 is a reply to message #544722] Mon, 05 July 2010 11:53 Go to previous messageGo to next message
Martijn Cremer is currently offline Martijn CremerFriend
Messages: 77
Registered: January 2010
Location: Breda
Member

zabi wrote on Mon, 05 July 2010 13:26
Hi,
yes it works but i how can i ovveride the text shown on the yes,no Dialog?

Thanks



What thext do you want to ovride?


hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
Re: ViewPart OnClose Event [message #544825 is a reply to message #544737] Mon, 05 July 2010 15:58 Go to previous messageGo to next message
zabi is currently offline zabiFriend
Messages: 11
Registered: July 2009
Junior Member
Hi,
thanks for your answers,
i just need now to create my own dialog with yes, no cancel. you know how to do this. i have a dialog here is the code but i doese not work with no button. just ok and cancel works.

here is the code:





/**
* This dialog should used to confirm a message and get decision between yes or no (OK or CANCEL). <br/>
* The title and icon of dialog can (should) to set with a action. Included text should set per separate action.
*
* @author
* @version $Revision$
*/
public final class YesNoAbortDialog extends DefaultDialog
{

/**
* constructor.
*
* @param parentShell Composite, where dialog is extended.
* @param action Set title, icon and a short description of dialog.
*/
private YesNoAbortDialog(Shell parentShell, Action action)
{
super(parentShell, action);
}

/**
* constructor.
*
* @param parentShell Composite, where dialog is extended.
* @param action Set title, icon and a short description of dialog.
*/
private YesNoAbortDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage)
{
super(parentShell, dialogTitle, dialogTitleImage, dialogMessage);
}

/**
*
* This method call the constructor of this dialog and get the results and gives these back to the main frame. It is better to call this
*
* method for creating this dialog.
*
* @param parentShell Composite, where this dialog will be shown. Can be null
* @param action Action to call this dialog
* @param dialogMessage Values are parameter, that this dialog get from main frame to do anything
* @return A object, that can indeed more values. If no return value exist, than return null.
*/
public static boolean openDialog(final Shell parentShell, final Action action, final String dialogMessage)
{
Validate.notNull(dialogMessage);

inValues = dialogMessage;

return (new YesNoAbortDialog(parentShell, action).open() == IDialogConstants.OK_ID);
}

/**
*
* This method call the constructor of this dialog and get the results and gives these back to the main frame. It is better to call this
*
* method for creating this dialog.
*
* @param parentShell Composite, where this dialog will be shown. Can be null
* @param dialogMessage Values are parameter, that this dialog get from main frame to do anything
* @return A object, that can indeed more values. If no return value exist, than return null.
*/

public static int openDialog(final Shell parentShell, final String dialogMessage)
{
Validate.notNull(dialogMessage);

int code = new YesNoAbortDialog(parentShell, Resources.Frames.Dialog.Texts.CONFIRM_TITLE.getText(),
Resources.Frames.Dialog.Images.CONFIRM_IMAGE.getImage(), dialogMessage).open();

if (code == IDialogConstants.OK_ID)
{
return ISaveablePart2.YES;
}
else if (code == IDialogConstants.NO_ID)
{
return ISaveablePart2.NO;
}
else if (code == IDialogConstants.CANCEL_ID)
{
return ISaveablePart2.CANCEL;
}

else
{
return ISaveablePart2.DEFAULT;
}

}

/**
*
* {@inheritDoc}
*
* @see de.ebcot.prowim.portal.dialogs.DefaultDialog#createCustomAre a(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createCustomArea(Composite parent)
{
Control control = super.createCustomArea(parent);

return control;
}

/**
*
* {@inheritDoc}
*
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(o rg.eclipse.swt.widgets.Composite)
*/
@Override
protected void createButtonsForButtonBar(Composite parent)
{
// create OK and Cancel buttons by default
createButton(parent, IDialogConstants.OK_ID, Resources.Frames.Global.Texts.OK.getText(), true);
createButton(parent, IDialogConstants.NO_ID, Resources.Frames.Global.Texts.NO.getText(), true);

createButton(parent, IDialogConstants.CANCEL_ID, Resources.Frames.Global.Texts.CANCEL.getText(), false);

}

}

[Updated on: Mon, 05 July 2010 15:59]

Report message to a moderator

Re: ViewPart OnClose Event [message #544938 is a reply to message #544825] Tue, 06 July 2010 07:15 Go to previous message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi,

you can implement the ISaveablePart2 [1] interface to open your custom
dialog.

Regards, Ralf

[1]
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/ui/ISaveablePart2 .html

zabi wrote:
> Hi,
> thanks for your answers,
> i just need now to create my own dialog with yes, no cancel. you know
> how to do this. i have a dialog here is the code but i doese not work
> with no button. just ok and cancel works.
>
> here is the code:
>
> /*==========================================================
> ====================
> * File $Id$
> * Project: ProWim
> *
> * $LastChangedDate$
> * $LastChangedBy$
> * $HeadURL$
> * $LastChangedRevision$
> *-----------------------------------------------------------
> -------------------
> * (c) 05.07.2010 Ebcot Business Solutions GmbH. More info:
> http://www.ebcot.de
> * All rights reserved. Use is subject to license terms.
> *===========================================================
> ===================
> */
> package de.ebcot.prowim.portal.dialogs;
>
> import org.apache.commons.lang.Validate;
> import org.eclipse.jface.action.Action;
> import org.eclipse.jface.dialogs.IDialogConstants;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.ui.ISaveablePart2;
>
> import de.ebcot.prowim.portal.i18n.Resources;
>
>
> /**
> * This dialog should used to confirm a message and get decision between
> yes or no (OK or CANCEL). <br/>
> * The title and icon of dialog can (should) to set with a action.
> Included text should set per separate action.
> * * @author
> * @version $Revision$
> */
> public final class YesNoAbortDialog extends DefaultDialog
> {
>
> /**
> * constructor.
> * * @param parentShell Composite, where dialog is extended.
> * @param action Set title, icon and a short description of dialog.
> */
> private YesNoAbortDialog(Shell parentShell, Action action)
> {
> super(parentShell, action);
> }
>
> /**
> * constructor.
> * * @param parentShell Composite, where dialog is extended.
> * @param action Set title, icon and a short description of dialog.
> */
> private YesNoAbortDialog(Shell parentShell, String dialogTitle, Image
> dialogTitleImage, String dialogMessage)
> {
> super(parentShell, dialogTitle, dialogTitleImage, dialogMessage);
> }
>
> /**
> * * This method call the constructor of this dialog and get the
> results and gives these back to the main frame. It is better to call this
> * * method for creating this dialog.
> * * @param parentShell Composite, where this dialog will be
> shown. Can be null
> * @param action Action to call this dialog
> * @param dialogMessage Values are parameter, that this dialog get
> from main frame to do anything
> * @return A object, that can indeed more values. If no return value
> exist, than return null.
> */
> public static boolean openDialog(final Shell parentShell, final
> Action action, final String dialogMessage)
> {
> Validate.notNull(dialogMessage);
>
> inValues = dialogMessage;
>
> return (new YesNoAbortDialog(parentShell, action).open() ==
> IDialogConstants.OK_ID);
> }
>
> /**
> * * This method call the constructor of this dialog and get the
> results and gives these back to the main frame. It is better to call this
> * * method for creating this dialog.
> * * @param parentShell Composite, where this dialog will be
> shown. Can be null
> * @param dialogMessage Values are parameter, that this dialog get
> from main frame to do anything
> * @return A object, that can indeed more values. If no return value
> exist, than return null.
> */
>
> public static int openDialog(final Shell parentShell, final String
> dialogMessage)
> {
> Validate.notNull(dialogMessage);
>
> int code = new YesNoAbortDialog(parentShell,
> Resources.Frames.Dialog.Texts.CONFIRM_TITLE.getText(),
>
> Resources.Frames.Dialog.Images.CONFIRM_IMAGE.getImage(),
> dialogMessage).open();
>
> if (code == IDialogConstants.OK_ID)
> {
> return ISaveablePart2.YES;
> }
> else if (code == IDialogConstants.NO_ID)
> {
> return ISaveablePart2.NO;
> }
> else if (code == IDialogConstants.CANCEL_ID)
> {
> return ISaveablePart2.CANCEL;
> }
>
> else
> {
> return ISaveablePart2.DEFAULT;
> }
>
> }
>
> /**
> * * {@inheritDoc}
> * * @see
> de.ebcot.prowim.portal.dialogs.DefaultDialog#createCustomAre
> a(org.eclipse.swt.widgets.Composite)
> */
> @Override
> protected Control createCustomArea(Composite parent)
> {
> Control control = super.createCustomArea(parent);
>
> return control;
> }
>
> /**
> * * {@inheritDoc}
> * * @see
> org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(o
> rg.eclipse.swt.widgets.Composite)
> */
> @Override
> protected void createButtonsForButtonBar(Composite parent)
> {
> // create OK and Cancel buttons by default
> createButton(parent, IDialogConstants.OK_ID,
> Resources.Frames.Global.Texts.OK.getText(), true);
> createButton(parent, IDialogConstants.NO_ID,
> Resources.Frames.Global.Texts.NO.getText(), true);
>
> createButton(parent, IDialogConstants.CANCEL_ID,
> Resources.Frames.Global.Texts.CANCEL.getText(), false);
>
> }
>
> }
>
Previous Topic:Compiler error: The import org.eclipse.ui.views.properties cannot be resolved
Next Topic:hanging UICallBackServiceHandler without any response
Goto Forum:
  


Current Time: Thu Apr 25 09:51:16 GMT 2024

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

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

Back to the top