Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Changing path variable in project properties only works when "linked resources" has not be
Changing path variable in project properties only works when "linked resources" has not be [message #1010545] Sun, 17 February 2013 16:53
jan baeyens is currently offline jan baeyens
Messages: 10
Registered: March 2012
Junior Member
Hi
I am developing a plugin and I use the IPathVariableManager to set a project specific path variable "ArduinoHardwareLibPath".
I want to change the "ArduinoHardwareLibPath" based on a setting in the project properties.
This works fine if the path variable "ArduinoHardwareLibPath" does not exists or when I do the changes without visiting the "linked resources" page in the project properties.
I have enabled a PathVariableChangeListener and learned this way that the value is set back to the old value.
I assue this is done because of the closing of the "linked resource" window which still contains the old value. (I mostly opened this to see the old value bfore changing it) This is confirmed because not visiting "Linked resources" make the code to work (no extra call to PathVariableChangeListener and the value is changed)

My question is: how can I make this work all the time?
Below is the code of the method caled as a result of the PropertyPage.performOk()

Best regards
Jantje

	public static void setWorkSpacePathVariables(IProject project, URI newPath) {
		IPathVariableManager pathMan = project.getPathVariableManager();

		//this code has been added for debuggin and needs to be removed as it will create a change listener for each call which is a really bad idea
		pathMan.addChangeListener(new IPathVariableChangeListener() {
			
			@Override
			public void pathVariableChanged(IPathVariableChangeEvent event) {
				// This method is called  after the setURIValue value below and then later again with the old value
				System.out.println(event.getVariableName());
			}
		});

		try {
			//I read the original value for debuggin reasons. Needs to be removed
			URI orgPath = pathMan.getURIValue(ArduinoConst.WORKSPACE_PATH_VARIABLE_NAME_HARDWARE_LIB);
			pathMan.setURIValue(ArduinoConst.WORKSPACE_PATH_VARIABLE_NAME_HARDWARE_LIB,newPath);
			//I read the value back for debugging to see wether it works
			URI readPath = pathMan.getURIValue(ArduinoConst.WORKSPACE_PATH_VARIABLE_NAME_HARDWARE_LIB);
			//For debugging I thow an error when the read value does not match the written value.
			if (!readPath.toString().equals(newPath.toString()))
			{
				//this has never happened
				Common.log(new Status(Status.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Failed to clean the workspace path variables.",null));
			}
		} catch (CoreException e) {
			Common.log(new Status(Status.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Failed to create the workspace path variables. The setup will not work properly", e));
			e.printStackTrace();
		}
	}

Previous Topic:Several editors in One
Next Topic:the SVN repository URL
Goto Forum:
  


Current Time: Wed Sep 17 23:46:28 GMT 2014

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

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