Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How do I know if Save button is pressed?
How do I know if Save button is pressed? [message #330929] Mon, 18 August 2008 07:11 Go to next message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
Hello,

How do I come to know if user presses 'Save' button in Eclipse IDE?
Is there any listener or some other place where I get a notification about
the save button having been pressed?
Please guide.

Thanks.
Re: How do I know if Save button is pressed? [message #330930 is a reply to message #330929] Mon, 18 August 2008 09:47 Go to previous messageGo to next message
Achim Loerke is currently offline Achim LoerkeFriend
Messages: 376
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

On Mon, 18 Aug 2008 07:11:10 +0000 (UTC), kaprasannagt@gmail.com
(kaprasanna) wrote:

>Hello,
>
>How do I come to know if user presses 'Save' button in Eclipse IDE?
>Is there any listener or some other place where I get a notification about
>the save button having been pressed?
>Please guide.
>
>Thanks.

I assume you are talking about saving an editor. You save your editor
by implementing IEditorPart (which comes for free if you subclass your
editor from EditorPart). You have to implement the save() and saveAs()
methods.
If you are not using an editor it should be sufficient to implement
ISaveablePart where the save/saveAs methods are introduced.


Achim
--
Achim Lörke

Eclipse-Stammtisch in the Braunschweig, Germany area:
http://www.bredex.de/de/news/events.html


Achim Lörke

Re: How do I know if Save button is pressed? [message #330938 is a reply to message #330930] Mon, 18 August 2008 14:52 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Achim Lörke wrote:
> I assume you are talking about saving an editor. You save your editor
> by implementing IEditorPart (which comes for free if you subclass your
> editor from EditorPart). You have to implement the save() and saveAs()
> methods.
> If you are not using an editor it should be sufficient to implement
> ISaveablePart where the save/saveAs methods are introduced.

And if it's just the save command in general (not in your specific part)
then you can use an IExecutionListener and ICommandService to listen for
the save command to be executed. In 3.3, it won't tell you when the
button is pressed, though.

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: How do I know if Save button is pressed? [message #330951 is a reply to message #330938] Tue, 19 August 2008 13:25 Go to previous messageGo to next message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
Hi,
Thanks for the replies.

I am indeed using Eclipse 3.3.2.

I tried with ISaveablePart but it doesn't allow me to save some swing
components which are on top of a view.

As in, when some change happens (say in a text field), I'd like to have
the save button on the toolbar to be enabled and then I can take action in
the doSave() method.

What's the solution?

Thanks in advance.
Re: How do I know if Save button is pressed? [message #330957 is a reply to message #330951] Tue, 19 August 2008 14:12 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

kaprasanna wrote:
> As in, when some change happens (say in a text field), I'd like to have
> the save button on the toolbar to be enabled and then I can take action
> in the doSave() method.

your view needs to both update the isDirty() flag and fire the
PROP_DIRTY property. That tells eclipse to 1) add the '*' to your view
tab and 2) enable the save button/command.

See org.eclipse.ui.part.WorkbenchPart.firePropertyChange(int), which is
often used in a part's implementation of setDirty(boolean)

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: How do I know if Save button is pressed? [message #330979 is a reply to message #330957] Wed, 20 August 2008 10:55 Go to previous messageGo to next message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
Hi Paul,

My view implements ISaveablePart so I implement following methods :
isSaveOnCloseNeeded, isDirty, doSave.
Save on close works just great..
Problem is I can't get the save buton to be enabled on demand. This is how
isDirty() looks like :

public boolean isDirty () {
if(something) {
firePropertyChange(PROP_DIRTY);
return true;
}
else
return false;
}

Not only the save button doesn't get enabled, I get this error : unhandled
event loop exception java.lang.StackOverFlow at the firePropertyChange()
line.

What is wrong? What I must be doing?
Please guide.

Thanks.
Re: How do I know if Save button is pressed? [message #330983 is a reply to message #330979] Wed, 20 August 2008 13:32 Go to previous messageGo to next message
Achim Loerke is currently offline Achim LoerkeFriend
Messages: 376
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

On Wed, 20 Aug 2008 10:55:57 +0000 (UTC), kaprasannagt@gmail.com
(kaprasanna) wrote:

>Hi Paul,
>
>My view implements ISaveablePart so I implement following methods :
>isSaveOnCloseNeeded, isDirty, doSave.
>Save on close works just great..
>Problem is I can't get the save buton to be enabled on demand. This is how
>isDirty() looks like :
>
> ...
>
>Not only the save button doesn't get enabled, I get this error : unhandled
>event loop exception java.lang.StackOverFlow at the firePropertyChange()
>line.
>
>What is wrong? What I must be doing?
>Please guide.
>
>Thanks.

You should implement something like


private boolean isDirty = false;

public boolean isDirty() {
return isDirty;
}

public void setDirty(boolean dirty) {
isDirty = dirty;
firePropertyChange(PROP_DIRTY);
}

firePropertyChange() whill notify the platform which will in turn call
isDirty() to get the dirty state. Using your implementation triggers
another property change and therefore goes into an indefinite
recursion.


Achim
--
Achim Lörke

Eclipse-Stammtisch in the Braunschweig, Germany area:
http://www.bredex.de/de/news/events.html


Achim Lörke

Re: How do I know if Save button is pressed? [message #331010 is a reply to message #330983] Thu, 21 August 2008 07:46 Go to previous message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
It all works just great..
Thank you so much for all the replies...
Previous Topic:Host name for Eclipse Application.
Next Topic:Building Eclipse 3.4 From Sources Fails
Goto Forum:
  


Current Time: Fri Sep 06 05:28:21 GMT 2024

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

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

Back to the top