📄 newprojectcreationwizard.java
字号:
/*
* Copyright (c) 2003, Alexander Greif
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Flow4J-Eclipse project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.orthanc.flow4j.designer.ui.wizards;
import java.lang.reflect.InvocationTargetException;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import net.orthanc.flow4j.designer.core.WorkspaceRunnableAdapter;
import net.orthanc.flow4j.designer.ui.Flow4jPluginImages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
/**
*
* Class NewProjectCreationWizard TODO
* @author agreif
*
*/
public class NewProjectCreationWizard extends BasicNewResourceWizard {
private WizardNewProjectCreationPage mainPage;
private NewProjectCreationWizardPageJ javaPage;
private IConfigurationElement configElement;
private IProject newProject;
/**
* Creates the project creation wizard.
*
*/
public NewProjectCreationWizard() {
super();
setWindowTitle(Flow4JPlugin.getResourceString("Wizard_NewProject.windowTitle"));
}
/**
* Adds the wizard pages
* @see org.eclipse.jface.wizard.IWizard#addPages()
*/
public void addPages() {
super.addPages();
mainPage = new WizardNewProjectCreationPage("WizardPage_NewProject");
mainPage.setTitle(Flow4JPlugin.getResourceString("WizardPage_NewProject.pageTitle"));
mainPage.setDescription(Flow4JPlugin.getResourceString("WizardPage_NewProject.pageDescription"));
mainPage.setImageDescriptor(Flow4jPluginImages.DESC_WIZBAN_NEWFLOW4JPROJECT);
this.addPage(mainPage);
// the java wizard page
javaPage = new NewProjectCreationWizardPageJ(mainPage);
this.addPage(javaPage);
}
/*
* Finishes the Wizard and creates the project.
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
public boolean performFinish() {
IWorkspaceRunnable op= new IWorkspaceRunnable() {
//IRunnableWithProgress op= new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws /*InvocationTargetException, InterruptedException,*/ CoreException, OperationCanceledException {
try {
finishPage(monitor);
} catch (InterruptedException e) {
throw new OperationCanceledException(e.getMessage());
} catch(CoreException e) {
Flow4JPlugin.log(e);
}
}
};
try {
getContainer().run(false, true, new WorkspaceRunnableAdapter(op));
} catch (InvocationTargetException e) {
Flow4JPlugin.log(e);
Flow4JPlugin.message("Creation of element failed.");
return false;
} catch (InterruptedException e) {
Flow4JPlugin.log(e);
Flow4JPlugin.message("Creation of element failed.");
return false;
}
return true;
}
/**
* Creates the java projects and add the Flow4J Nature
* @param monitor
* @throws InterruptedException
* @throws CoreException
*/
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
monitor.beginTask("", 10); //$NON-NLS-1$
javaPage.performFinish(monitor);
IJavaProject javaProject = javaPage.getJavaProject();
// add flow4j projects features
configureFlow4JProject(javaProject, new SubProgressMonitor(monitor, 2));
BasicNewProjectResourceWizard.updatePerspective(configElement);
selectAndReveal(javaProject.getProject());
monitor.done();
}
/**
* Configures the Flow4J project.
* Adds the Flow4J nature and automatically the builder.
* Also adds the flow4j runtime library to the classpath.
* @param monitor the progress monitor
* @throws CoreException
* @throws InterruptedException
*/
private void configureFlow4JProject(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException, InterruptedException {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
try {
IProject project= mainPage.getProjectHandle();
Flow4JPlugin.addFlow4JNature(project, new SubProgressMonitor(monitor, 1));
Flow4JPlugin.addFlow4jRuntimeLibrary(javaProject);
} finally {
monitor.done();
}
}
/* (non-Javadoc)
* @see IWizard#performCancel()
*/
public boolean performCancel() {
javaPage.performCancel();
return super.performCancel();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -