Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Save a diagram when select other
Save a diagram when select other [message #556533] Wed, 01 September 2010 16:39 Go to next message
Pablo Nieto is currently offline Pablo NietoFriend
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hi I´m making a gmf editor which has diferent types of diagrams that are oppened by double clicking.

When I change from one diagram to another, the chenges made aren´t saved. I want to make my my editor save the diagram changes automatically when I change to another diagram page.

Anybody know how to do this?

Thanks in advance, Pablo.
Re: Save a diagram when select other [message #556615 is a reply to message #556533] Thu, 02 September 2010 06:44 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

comments below...

Pablo Nieto wrote on Wed, 01 September 2010 12:39
Hi I´m making a gmf editor which has diferent types of diagrams that are oppened by double clicking.

When I change from one diagram to another, the chenges made aren´t saved. I want to make my my editor save the diagram changes automatically when I change to another diagram page.

Anybody know how to do this?

Thanks in advance, Pablo.


You can add an IPartListener to your active page:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addPartListener(...);


You need to implement its partDeactivated() method and cast the part to IEditorPart which has a doSave() method.

The listener can be blown up as to make it aware of perspective changes, etc. Have a look at org.eclipse.ui.internal.PagePartSelectionTracker for an example.

Cheers
Rob

Rob
Re: Save a diagram when select other [message #556619 is a reply to message #556615] Thu, 02 September 2010 06:56 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo NietoFriend
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
hello

Where do I have to put that listener code? In what class?

thanks
Re: Save a diagram when select other [message #556625 is a reply to message #556619] Thu, 02 September 2010 07:12 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

well, technically anywhere you want to. You could put it in one of your Activators into the start() method and use the stop() method to unhook that listener for instance.

Rob
Re: Save a diagram when select other [message #556627 is a reply to message #556625] Thu, 02 September 2010 07:19 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo NietoFriend
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member


Hello, Sorry but I´m a bit lost.

Where are the start() and stop() methods?

Then, in these methods, I have to create an IpartListener and in this listener I have to modify the partDeactivated() mehtod and call the doSaveDocument() method for saving my document.
Am I right?

Thanks again
Re: Save a diagram when select other [message #556721 is a reply to message #556627] Thu, 02 September 2010 12:55 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

comments below...

Pablo Nieto wrote on Thu, 02 September 2010 03:19


Hello, Sorry but I´m a bit lost.

Where are the start() and stop() methods?


When you create an Eclipse Plugin project you can choose to have an "Activator" generated (http:// help.eclipse.org/helios/topic/org.eclipse.pde.doc.user/guide /tools/project_wizards/plugin_content.htm?resultof=%22%61%63 %74%69%76%61%74%6f%72%22%20%22%61%63%74%69%76%22%20). If you're unsure open the MANIFEST.MF of one of your plugins, select the "Overview" tab at the bottom, and then you can see which class the Activator of that plugin is. Inside of those classes are start() and stop() methods.

Quote:

Then, in these methods, I have to create an IpartListener and in this listener I have to modify the partDeactivated() mehtod and call the doSaveDocument() method for saving my document.
Am I right?

Thanks again

Yes, you're right. It's sufficient to add that code to the start() method. Before you call doSave() on the IEditorPart you might want to check if the editor part is an instance of your XXXDiagramEditor! Otherwise you might end up saving any editor on part changes.
Re: Save a diagram when select other [message #556812 is a reply to message #556721] Thu, 02 September 2010 17:00 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo NietoFriend
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello, thaks yor the last reply.

This is my partDeactivated method():

public void partDeactivated(IWorkbenchPart part) {
// TODO Auto-generated method stub
if (part instanceof MMSCXMLWebSecundario.diagram.part.MMSCXMLWebDiagramEditor) {
try {
((MMSCXMLWebSecundario.diagram.part.MMSCXMLWebDiagramEditor) part)
.doSaveAs();
} catch (Exception e) {
System.out.println(e);
}
System.out.println("Autoguardado");
}

}

I have done the "autoSave" but there´s another problem now:
I would like that my editor save when I change from one diagram to another, but with this implementation, when I change the current editor appears a SaveAs dialog instead of autosave.

The problem with the SaveAs is that, I can´t select the same file name, because the file is opened, and I hav to put a new file name each time.

I,ve been looking to the XXXDiagramEditor Class, and I´ve not found any method to do a "Simple Save" only SaveAs().

Do you know how to do an autoSave, without showing any dialog.

Thanks again, Pablo


Re: Save a diagram when select other [message #556919 is a reply to message #556812] Fri, 03 September 2010 08:04 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

as I proposed before you should use the doSave() method instead of doSaveAs().

Cheers

Rob
Re: [Solved] Save a diagram when select other [message #556925 is a reply to message #556919] Fri, 03 September 2010 08:19 Go to previous message
Pablo Nieto is currently offline Pablo NietoFriend
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello I´ve corrected it already:

I had to use:

((MMSCXMLWebPrincipal.diagram.part.MMSCXMLWebDiagramEditor) part).doSave(new NullProgressMonitor());

Thanks for all, Pablo.
Previous Topic:editing the doSaveDocument() Method
Next Topic:Close al diagrams when exit
Goto Forum:
  


Current Time: Fri Apr 26 03:20:26 GMT 2024

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

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

Back to the top