eclipse plugin: Recreate the Core Library link...

...if we change the project's wesnoth install
This commit is contained in:
Timotei Dolean 2011-08-09 19:01:47 +00:00
parent 168d6a95f2
commit aea1126bff
5 changed files with 93 additions and 10 deletions

View file

@ -200,6 +200,11 @@ public class WesnothInstallsUtils
if( WorkspaceUtils.checkPathsAreSet( installName, true ) ) {
// replace current install with the default
setInstallNameForResource( resource, installName );
// re-create the core library link
ProjectUtils.createCoreLibraryFolder( resource.getProject( ),
IResource.NONE );
return true;
}

View file

@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
@ -233,6 +234,16 @@ public class Preferences extends AbstractPreferenceInitializer
return getWorkingDir( ) + "data/core/"; //$NON-NLS-1$
}
/**
* Returns the 'data/core' directory as a Path variable
*
* @return Returns the 'data/core' directory
*/
public Path getCoreDirPath( )
{
return new Path( getCoreDir( ) );
}
/**
* Returns the <b>schema.cfg</b> file path
*

View file

@ -76,6 +76,16 @@ public class ProjectCache implements Serializable
.getMacrosLocation( project ) );
}
/**
* Returns the associated project for this cache
*
* @return An IProject instance
*/
public IProject getProject( )
{
return project_;
}
/**
* Gets the properties map for this project.
*

View file

@ -20,6 +20,8 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.wesnoth.Constants;
@ -75,6 +77,52 @@ public class ProjectUtils
return cache;
}
/**
* Creates a folder that link to the project's wesnoth installation's
* 'data/core' directory
*
* @param updateFlags
* bit-wise or of update flag constants
* (IResource.ALLOW_MISSING_LOCAL, IResource.REPLACE,
* IResource.BACKGROUND_REFRESH, and IResource.HIDDEN)
* @param project
* The project to create the link for
* @return True if the creation was successfully, false otherwise
*/
public static boolean createCoreLibraryFolder( IProject project,
int updateFlags )
{
ProjectCache cache = getCacheForProject( project );
Paths paths = Preferences.getPaths( cache.getInstallName( ) );
IFolder coreLibrary = project
.getFolder( WesnothProjectsExplorer.CORE_LIBRARY_NAME );
if( ResourcesPlugin.getWorkspace( ).validateLinkLocation( coreLibrary,
paths.getCoreDirPath( ) ).getCode( ) != IStatus.ERROR ) {
try {
if( coreLibrary.exists( ) ) {
coreLibrary.delete( true, new NullProgressMonitor( ) );
}
coreLibrary
.createLink( paths.getCoreDirPath( ), updateFlags,
new NullProgressMonitor( ) );
} catch( CoreException e ) {
Logger.getInstance( ).logException( e );
return false;
}
}
else {
Logger.getInstance( ).log(
"Couldn't create link on:" + paths.getCoreDir( )
+ "; project: " + project.getName( ),
"Cannot create the Wesnoth Core Library folder for project "
+ project.getName( ) + "!" );
}
return true;
}
/**
* Creates a new wesnoth project with the specified name
* and on the specified location on disk
@ -200,10 +248,7 @@ public class ProjectUtils
monitor.worked( 10 );
// create the Core library link
IFolder coreLibrary = handle
.getFolder( WesnothProjectsExplorer.CORE_LIBRARY_NAME );
coreLibrary.createLink( new Path( paths.getCoreDir( ) ),
IResource.NONE, monitor );
createCoreLibraryFolder( handle, IResource.NONE );
monitor.worked( 10 );
// save the install name

View file

@ -3,6 +3,7 @@ package org.wesnoth.propertypages;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
@ -24,12 +25,14 @@ import org.wesnoth.projects.ProjectUtils;
public class WesnothProjectPage extends PropertyPage
{
private Combo cmbInstall_;
private ProjectCache currProjectCache_;
private ProjectCache currentProjectCache_;
private String currentInstall_;
public WesnothProjectPage( )
{
currProjectCache_ = null;
currentProjectCache_ = null;
cmbInstall_ = null;
currentInstall_ = null;
}
@Override
@ -42,7 +45,8 @@ public class WesnothProjectPage extends PropertyPage
IProject selectedProject = ( IProject ) selectedElement;
currProjectCache_ = ProjectUtils.getCacheForProject( selectedProject );
currentProjectCache_ = ProjectUtils
.getCacheForProject( selectedProject );
Composite newComposite = new Composite( parent, 0 );
newComposite.setLayout( new FillLayout( SWT.VERTICAL ) );
@ -64,7 +68,7 @@ public class WesnothProjectPage extends PropertyPage
List< WesnothInstall > installs = WesnothInstallsUtils.getInstalls( );
boolean foundInstallInList = false;
String installName = currProjectCache_.getInstallName( );
String installName = currentProjectCache_.getInstallName( );
for( WesnothInstall wesnothInstall: installs ) {
cmbInstall_.add( wesnothInstall.getName( ) );
@ -72,6 +76,7 @@ public class WesnothProjectPage extends PropertyPage
// current install is default?
if( wesnothInstall.getName( ).equalsIgnoreCase( installName ) ) {
cmbInstall_.select( cmbInstall_.getItemCount( ) - 1 );
currentInstall_ = wesnothInstall.getName( );
foundInstallInList = true;
}
}
@ -87,9 +92,16 @@ public class WesnothProjectPage extends PropertyPage
@Override
public boolean performOk( )
{
String selectedInstall = cmbInstall_.getText( );
// save settings.
if( currProjectCache_ != null && ! cmbInstall_.getText( ).isEmpty( ) ) {
currProjectCache_.setInstallName( cmbInstall_.getText( ) );
if( currentProjectCache_ != null && ! selectedInstall.isEmpty( ) ) {
currentProjectCache_.setInstallName( selectedInstall );
if( ! selectedInstall.equals( currentInstall_ ) ) {
// relink the data directory
ProjectUtils.createCoreLibraryFolder( currentProjectCache_
.getProject( ), IResource.BACKGROUND_REFRESH );
}
}
return true;