Home » Eclipse Projects » Remote Application Platform (RAP) » ViewPart OnClose Event(ViewPart OnClose Event)
ViewPart OnClose Event [message #544327] |
Fri, 02 July 2010 07:32  |
Eclipse User |
|
|
|
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 #544825 is a reply to message #544737] |
Mon, 05 July 2010 11:58   |
Eclipse User |
|
|
|
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 11:59] by Moderator
|
|
|
Re: ViewPart OnClose Event [message #544938 is a reply to message #544825] |
Tue, 06 July 2010 03:15  |
Eclipse User |
|
|
|
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);
>
> }
>
> }
>
|
|
|
Goto Forum:
Current Time: Fri Jul 25 16:09:36 EDT 2025
Powered by FUDForum. Page generated in 0.04390 seconds
|