eclipse plugin: Implement the import project wizard
This commit is contained in:
parent
b6d460e8dd
commit
4bf3e417f6
4 changed files with 182 additions and 1 deletions
|
@ -810,5 +810,22 @@
|
|||
genModel = "org/wesnoth/WML.genmodel" />
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.importWizards">
|
||||
<category
|
||||
id="org.wesnoth.importWizards"
|
||||
name="Wesnoth">
|
||||
</category>
|
||||
<wizard
|
||||
category="org.wesnoth.importWizards"
|
||||
class="org.wesnoth.importWizards.ImportProjectWizard"
|
||||
icon="icons/wesnoth-icon_16.png"
|
||||
id="org.wesnoth.projectImportWizard"
|
||||
name="Import Wesnoth Project">
|
||||
<description>
|
||||
Import a directory as a wesnoth project
|
||||
</description>
|
||||
</wizard>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -11,7 +11,6 @@ package org.wesnoth.action;
|
|||
import org.eclipse.jface.action.IAction;
|
||||
import org.wesnoth.utils.MapUtils;
|
||||
|
||||
|
||||
public class ImportMap extends ObjectActionDelegate
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* This program and the accompanying materials are made available
|
||||
* under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.wesnoth.importWizards;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jface.preference.DirectoryFieldEditor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.wesnoth.installs.WesnothInstallsUtils;
|
||||
import org.wesnoth.wizards.WizardPageTemplate;
|
||||
|
||||
public class ImportProjectPage extends WizardPageTemplate
|
||||
{
|
||||
private DirectoryFieldEditor projectPathField_;
|
||||
private Text txtProjectName_;
|
||||
private Combo cmbInstalls_;
|
||||
|
||||
protected ImportProjectPage( )
|
||||
{
|
||||
super( "importProjectPage0" );
|
||||
|
||||
setTitle( "Import directory as wesnoth project" );
|
||||
setMessage( "Import a directory as a wesnoth project." );
|
||||
setPageComplete( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl( Composite parent )
|
||||
{
|
||||
super.createControl( parent );
|
||||
Composite container = new Composite(parent, SWT.NULL);
|
||||
setControl( container );
|
||||
|
||||
ModifyListener listener = new ModifyListener( ) {
|
||||
|
||||
@Override
|
||||
public void modifyText( ModifyEvent e )
|
||||
{
|
||||
updatePageIsComplete();
|
||||
}
|
||||
};
|
||||
|
||||
projectPathField_ = new DirectoryFieldEditor( "project_path",
|
||||
"Directory to import:", container );
|
||||
projectPathField_.getTextControl( container ).addModifyListener( listener );
|
||||
|
||||
Label lblNewLabel = new Label(container, SWT.NONE);
|
||||
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
||||
lblNewLabel.setText("Project Name:");
|
||||
|
||||
txtProjectName_ = new Text(container, SWT.BORDER);
|
||||
txtProjectName_.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
|
||||
txtProjectName_.addModifyListener( listener );
|
||||
|
||||
Label lblWesnothInstall = new Label(container, SWT.NONE);
|
||||
lblWesnothInstall.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
||||
lblWesnothInstall.setText("Wesnoth install:");
|
||||
|
||||
cmbInstalls_ = new Combo(container, SWT.READ_ONLY);
|
||||
cmbInstalls_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
||||
WesnothInstallsUtils.fillComboWithInstalls( cmbInstalls_ );
|
||||
}
|
||||
|
||||
protected void updatePageIsComplete()
|
||||
{
|
||||
setPageComplete(
|
||||
! txtProjectName_.getText( ).isEmpty( ) &&
|
||||
new File( projectPathField_.getStringValue( ) ).exists( ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the imported project's path
|
||||
* @return A string with the project path
|
||||
*/
|
||||
public String getProjectPath( )
|
||||
{
|
||||
return projectPathField_.getStringValue( );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the imported project's name
|
||||
* @return A string with the imported project's name
|
||||
*/
|
||||
public String getProjectName( )
|
||||
{
|
||||
return txtProjectName_.getText( );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selected install name
|
||||
* @return A string with the selected install name
|
||||
*/
|
||||
public String getSelectedInstallName()
|
||||
{
|
||||
return cmbInstalls_.getText( );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.wesnoth.importWizards;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.ui.IImportWizard;
|
||||
import org.wesnoth.Logger;
|
||||
import org.wesnoth.projects.ProjectUtils;
|
||||
import org.wesnoth.wizards.WizardTemplate;
|
||||
|
||||
public class ImportProjectWizard extends WizardTemplate implements IImportWizard
|
||||
{
|
||||
private ImportProjectPage page0_;
|
||||
|
||||
public ImportProjectWizard()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages()
|
||||
{
|
||||
super.addPages( );
|
||||
|
||||
page0_ = new ImportProjectPage( );
|
||||
addPage( page0_ );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish()
|
||||
{
|
||||
IRunnableWithProgress op = new IRunnableWithProgress() {
|
||||
@Override
|
||||
public void run(IProgressMonitor monitor)
|
||||
{
|
||||
ProjectUtils.createWesnothProject( page0_.getProjectName( ),
|
||||
page0_.getProjectPath( ), page0_.getSelectedInstallName(),
|
||||
monitor );
|
||||
monitor.done();
|
||||
}
|
||||
};
|
||||
try
|
||||
{
|
||||
getContainer().run(false, false, op);
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
return false;
|
||||
} catch (InvocationTargetException e)
|
||||
{
|
||||
Logger.getInstance().logException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue