Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Plugin - save participant project save
Plugin - save participant project save [message #1063185] Wed, 12 June 2013 14:48 Go to next message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
Hi, I am playing with plugin development for the first time. I currently have a startup plugin (launches on startup of the workbench using the IStartup interface) - I know people caution to avoid these in general but the purpose is that I need to check the command line passed to eclipse and automatically/programmatically generate a project based on that command line information on startup (if there is a better way to do this I'm all ears).

The startup plugin registers a save participant:

		ISaveParticipant saveParticipant = new MySaveParticipant();
		try {
			
			ISavedState lastState = ResourcesPlugin.getWorkspace().addSaveParticipant(Activator.PLUGIN_ID,  saveParticipant);
		} catch (CoreException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}


But the participant "saving" method only seems to be getting called for the ISaveContext.SNAPSHOT save:

	public void prepareToSave(ISaveContext context) throws CoreException {
		try {
			FileOutputStream os = new FileOutputStream(s_fname, true);
			
			os.write("testing 6666".getBytes());
			os.flush();	
			os.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void saving(ISaveContext context) throws CoreException {
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		try {
			FileOutputStream os = new FileOutputStream(s_fname, true);
			
			String message = "testing 1234" + dateFormat.format(new Date()) + "\n";
			
			os.write(message.getBytes());
			
			switch (context.getKind()) {
				case ISaveContext.FULL_SAVE:
					message = "Full Save" + dateFormat.format(new Date()) + "\n"; 
					os.write(message.getBytes());
					break;
				case ISaveContext.PROJECT_SAVE:
					message = "Project Save" + dateFormat.format(new Date()) + "\n";
					os.write(message.getBytes());
					break;
				case ISaveContext.SNAPSHOT:
					message ="Snapshot Save" + dateFormat.format(new Date()) + "\n"; 
					os.write(message.getBytes());
					break;
			}
			os.flush();
			os.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}



Basically, the workbench opens and I programmatically create a project. I then go and modify a source file in the project and hit save and expect the "saving" method to be invoked in the save participant but that doesn't appear to be happening... the test text file I'm writing to only seems to indicate snapshot saves:

testing 6666testing 12342013/06/11 16:26:11
Snapshot Save2013/06/11 16:26:11
testing 6666testing 12342013/06/11 16:31:11
Snapshot Save2013/06/11 16:31:11
testing 6666testing 12342013/06/11 17:29:19
Snapshot Save2013/06/11 17:29:19


I'm sure I'm doing something wrong but am having a hard time finding any good resources online to help me figure it out. So 1) if anyone here can point out my mistake I would appreciate it and 2) if anyone can point me to some good resources for learning this stuff in detail I would also appreciate that.

Thanks a lot!

[Updated on: Mon, 08 July 2013 16:26]

Report message to a moderator

Re: Plugin - save participant project save [message #1067434 is a reply to message #1063185] Mon, 08 July 2013 16:26 Go to previous message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
Does anybody have any ideas here? I am expecting my save participant to get notified if I make changes in a Java Editor and then save that file but it is not happening. Are my expectations incorrect? Should I be using a resource change listener instead?

Thanks!
Previous Topic:refresh/update java editor programmatically before jumping to java element
Next Topic:Corrupted characters in textarea
Goto Forum:
  


Current Time: Fri Apr 26 16:28:44 GMT 2024

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

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

Back to the top