📄 newprojectcreationwizardpagej.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 org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.wizards.JavaCapabilityConfigurationPage;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
/**
* Class NewProjectCreationWizardPageJ TODO
* @author agreif
*
*/
public class NewProjectCreationWizardPageJ
extends JavaCapabilityConfigurationPage {
private WizardNewProjectCreationPage fMainPage;
private IPath fCurrProjectLocation;
protected IProject fCurrProject;
protected boolean fCanRemoveContent;
/**
* Constructor for NewProjectCreationWizardPage.
*/
public NewProjectCreationWizardPageJ(WizardNewProjectCreationPage mainPage) {
super();
fMainPage= mainPage;
fCurrProjectLocation= null;
fCurrProject= null;
fCanRemoveContent= false;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
*/
public void setVisible(boolean visible) {
if (visible) {
changeToNewProject();
} else {
removeProject();
}
super.setVisible(visible);
}
/**
* TODO
*
*/
private void changeToNewProject() {
IProject newProjectHandle= fMainPage.getProjectHandle();
IPath newProjectLocation= fMainPage.getLocationPath();
if (fMainPage.useDefaults()) {
fCanRemoveContent= !newProjectLocation.append(fMainPage.getProjectName()).toFile().exists();
} else {
fCanRemoveContent= !newProjectLocation.toFile().exists();
}
final boolean initialize= !(newProjectHandle.equals(fCurrProject) && newProjectLocation.equals(fCurrProjectLocation));
IRunnableWithProgress op= new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
updateProject(initialize, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
getContainer().run(false, true, op);
} catch (InvocationTargetException e) {
Flow4JPlugin.message("An error occurred while creating project. Check log for details.");
Flow4JPlugin.log(e);
} catch (InterruptedException e) {
// cancel pressed
}
}
/**
* TODO
* @param initialize
* @param monitor
* @throws CoreException
* @throws InterruptedException
*/
protected void updateProject(boolean initialize, IProgressMonitor monitor) throws CoreException, InterruptedException {
fCurrProject= fMainPage.getProjectHandle();
fCurrProjectLocation= fMainPage.getLocationPath();
boolean noProgressMonitor= !initialize && fCanRemoveContent;
if (monitor == null || noProgressMonitor ) {
monitor= new NullProgressMonitor();
}
try {
monitor.beginTask("Creating project and examining existing resources...", 2); //$NON-NLS-1$
createProject(fCurrProject, fCurrProjectLocation, new SubProgressMonitor(monitor, 1));
if (initialize) {
IClasspathEntry[] entries= null;
IPath outputLocation= null;
init(JavaCore.create(fCurrProject), outputLocation, entries, false);
}
monitor.worked(1);
} finally {
monitor.done();
}
}
/**
* Called from the wizard on finish.
*/
public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException {
try {
if (fCurrProject == null) {
updateProject(true, new SubProgressMonitor(monitor, 1));
}
configureJavaProject(new SubProgressMonitor(monitor, 2));
} finally {
fCurrProject= null;
}
}
/**
* TODO
*
*/
private void removeProject() {
if (fCurrProject == null || !fCurrProject.exists()) {
return;
}
IRunnableWithProgress op= new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
boolean noProgressMonitor= Platform.getLocation().equals(fCurrProjectLocation);
if (monitor == null || noProgressMonitor) {
monitor= new NullProgressMonitor();
}
monitor.beginTask("Removing project...", 3); //$NON-NLS-1$
try {
fCurrProject.delete(fCanRemoveContent, false, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
fCurrProject= null;
fCanRemoveContent= false;
}
}
};
try {
getContainer().run(false, true, op);
} catch (InvocationTargetException e) {
Flow4JPlugin.message("An error occurred while removing a temporary project"); //$NON-NLS-1$
Flow4JPlugin.log(e);
} catch (InterruptedException e) {
// cancel pressed
}
}
/**
* Called from the wizard on cancel.
*/
public void performCancel() {
removeProject();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -