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 10:48 Go to next message
Kevin Regan is currently offline Kevin Regan
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 12:26]

Report message to a moderator

Re: Plugin - save participant project save [message #1067434 is a reply to message #1063185] Mon, 08 July 2013 12:26 Go to previous message
Kevin Regan is currently offline Kevin Regan
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:Unable to evaluate the selected expression
Goto Forum:
  


Current Time: Mon Apr 21 00:41:42 EDT 2014

Powered by FUDForum. Page generated in 0.01543 seconds