aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Pospychala2012-11-02 04:16:16 (EDT)
committerJacek Pospychala2012-11-02 04:17:24 (EDT)
commit721cdafd4af55af42d40fa12b34fced9a46bf793 (patch)
tree29ed235d6db4c20b27398ba010ed948b863762e0
parent537ff78cbe6aeda5d8317eda52ecf6cb56db34b3 (diff)
downloadorg.eclipse.pdt-721cdafd4af55af42d40fa12b34fced9a46bf793.zip
org.eclipse.pdt-721cdafd4af55af42d40fa12b34fced9a46bf793.tar.gz
org.eclipse.pdt-721cdafd4af55af42d40fa12b34fced9a46bf793.tar.bz2
Bug 389037 - New project wizard should have an option to select
templates from available PHP facets
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java12
-rw-r--r--plugins/org.eclipse.php.ui/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java2
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties2
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java11
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java321
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java228
7 files changed, 346 insertions, 234 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java
index c880ead..8e8bef3 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/facet/PHPFacets.java
@@ -177,4 +177,16 @@ public class PHPFacets {
facetedProject.installProjectFacet(convertToFacetVersion(phpVersion),
null, monitor);
}
+
+ /**
+ * Returns the faceted version of the core facet
+ *
+ * @return core facet
+ */
+ public static IProjectFacetVersion getCoreVersion() {
+ IProjectFacet coreFacet = ProjectFacetsManager
+ .getProjectFacet(PHPFacetsConstants.PHP_CORE_COMPONENT);
+ return coreFacet.getDefaultVersion();
+ }
+
}
diff --git a/plugins/org.eclipse.php.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.php.ui/META-INF/MANIFEST.MF
index 0cde71e..93295f4 100644
--- a/plugins/org.eclipse.php.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.php.ui/META-INF/MANIFEST.MF
@@ -41,7 +41,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.wst.css.core,
org.eclipse.wst.css.ui,
org.eclipse.emf.common,
- org.eclipse.dltk.core.manipulation
+ org.eclipse.dltk.core.manipulation,
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.wst.common.project.facet.ui
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.php.internal.ui;x-internal:=true,
org.eclipse.php.internal.ui.actions;x-internal:=true,
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java
index c1d54f1..e5ae6b0 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java
@@ -167,6 +167,7 @@ public final class PHPUIMessages extends NLS {
public static String PhpTemplateNumberVariableResolver_2;
public static String Search_Error_openEditor_message;
public static String PHPProjectCreationWizard_Page1Title;
+ public static String PHPProjectCreationWizard_PageFacetsTitle;
public static String PHPSearchResultPage_sortByName;
public static String newPhpFile_wizard_templatePage_usePhpTemplate;
public static String ShowInNavigatorView_dialog_title;
@@ -296,6 +297,7 @@ public final class PHPUIMessages extends NLS {
public static String DragAdapter_problemTitle;
public static String CustomFiltersDialog_filterList_label;
public static String PHPProjectCreationWizard_Page1Description;
+ public static String PHPProjectCreationWizard_PageFacetsDescription;
public static String typingPage_autoAdd_phpDoc_tags;
public static String PHPBuildPreferencePage_title;
public static String PHPOutlineElementComparer_2;
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties
index 3c39390..ec0e8e4 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties
@@ -375,6 +375,8 @@ ProjectsWorkbookPage_chooseProjects_title=Workspace Folder Selection
PHPProjectCreationWizard_WizardTitle=New PHP Project
PHPProjectCreationWizard_Page1Title=Create a PHP Project
PHPProjectCreationWizard_Page1Description=Create a PHP project in the workspace or in an external location.
+PHPProjectCreationWizard_PageFacetsTitle=PHP Facets
+PHPProjectCreationWizard_PageFacetsDescription=Modify the PHP Facets
PHPProjectCreationWizard_Page2Title=PHP Include Path
PHPProjectCreationWizard_Page2Description=Configure PHP Include Path
PHPProjectCreationWizard_Page3Title=PHP Build Path
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java
index 4b6cfaa..2a90a96 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java
@@ -42,6 +42,8 @@ public class PHPProjectCreationWizard extends NewElementWizard implements
protected int fLastPageIndex = -1;
+ private PHPProjectWizardFacetsPage fFacetsPage;
+
public PHPProjectCreationWizard() {
setDefaultPageImageDescriptor(PHPPluginImages.DESC_WIZBAN_ADD_PHP_PROJECT);
setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings());
@@ -58,6 +60,13 @@ public class PHPProjectCreationWizard extends NewElementWizard implements
.setDescription(PHPUIMessages.PHPProjectCreationWizard_Page1Description);
addPage(fFirstPage);
+ fFacetsPage = new PHPProjectWizardFacetsPage(fFirstPage);
+ fFacetsPage
+ .setTitle(PHPUIMessages.PHPProjectCreationWizard_PageFacetsTitle);
+ fFacetsPage
+ .setDescription(PHPUIMessages.PHPProjectCreationWizard_PageFacetsDescription);
+ addPage(fFacetsPage);
+
// Second page (Include Path)
fSecondPage = new PHPProjectWizardSecondPage(fFirstPage);
fSecondPage.setTitle(PHPUIMessages.PHPProjectCreationWizard_Page2Title);
@@ -145,7 +154,7 @@ public class PHPProjectCreationWizard extends NewElementWizard implements
public boolean performCancel() {
if (!fFirstPage.isExistingLocation())
- fLastPage.performCancel();
+ fFirstPage.performCancel();
return super.performCancel();
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java
index b4fdb83..8bfbc7e 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java
@@ -11,25 +11,34 @@
*******************************************************************************/
package org.eclipse.php.internal.ui.wizards;
-import java.io.File;
+import java.io.*;
+import java.lang.reflect.InvocationTargetException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.*;
+import org.eclipse.dltk.core.DLTKCore;
import org.eclipse.dltk.core.environment.EnvironmentManager;
import org.eclipse.dltk.core.environment.IEnvironment;
+import org.eclipse.dltk.internal.corext.util.Messages;
+import org.eclipse.dltk.internal.ui.util.CoreUtility;
import org.eclipse.dltk.internal.ui.wizards.NewWizardMessages;
import org.eclipse.dltk.internal.ui.wizards.dialogfields.*;
import org.eclipse.dltk.ui.DLTKUIPlugin;
import org.eclipse.dltk.ui.environment.IEnvironmentUI;
+import org.eclipse.dltk.ui.util.ExceptionHandler;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.php.internal.core.PHPVersion;
@@ -37,6 +46,7 @@ import org.eclipse.php.internal.ui.IPHPHelpContextIds;
import org.eclipse.php.internal.ui.PHPUIMessages;
import org.eclipse.php.internal.ui.PHPUiPlugin;
import org.eclipse.php.internal.ui.preferences.*;
+import org.eclipse.php.ui.util.PHPProjectUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
@@ -44,6 +54,7 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
@@ -52,6 +63,7 @@ import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
*/
public class PHPProjectWizardFirstPage extends WizardPage implements
IPHPProjectCreateWizardPage {
+
public PHPProjectWizardFirstPage() {
super(PAGE_NAME);
setPageComplete(false);
@@ -60,6 +72,16 @@ public class PHPProjectWizardFirstPage extends WizardPage implements
fInitialName = ""; //$NON-NLS-1$
}
+ private static final String FILENAME_PROJECT = ".project"; //$NON-NLS-1$
+ protected static final String FILENAME_BUILDPATH = ".buildpath"; //$NON-NLS-1$
+ protected URI fCurrProjectLocation; // null if location is platform location
+
+ private boolean fKeepContent;
+
+ private File fDotProjectBackup;
+ private File fDotBuildpathBackup;
+ private Boolean fIsAutobuild;
+
private static final String PAGE_NAME = NewWizardMessages.ScriptProjectWizardFirstPage_page_title;
public static final String ERROR_MESSAGE = "ErrorMessage";
@@ -617,16 +639,307 @@ public class PHPProjectWizardFirstPage extends WizardPage implements
public void setVisible(boolean visible) {
super.setVisible(visible);
- IWizardPage currentPage = getContainer().getCurrentPage();
- if (!visible && currentPage != null) {
- // going forward from 1st page to 2nd one
+ if (visible) {
+ // if there is a project we are going from 2nd to 1st
+ // remove the project
+ removeProject();
+ } else {
+ IWizardPage currentPage = getContainer().getCurrentPage();
if (currentPage instanceof IPHPProjectCreateWizardPage) {
+ // going forward from 1st page to 2nd one
+ changeToNewProject();
((IPHPProjectCreateWizardPage) currentPage).initPage();
}
}
}
+ private void removeProject() {
+ if (fNameGroup == null || fNameGroup.getName() == null
+ || fNameGroup.getName().length() == 0) {
+ return;
+ }
+ if (getProjectHandle() == null || !getProjectHandle().exists()) {
+ return;
+ }
+
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ doRemoveProject(monitor);
+ }
+ };
+
+ try {
+ getContainer().run(true, true,
+ new WorkspaceModifyDelegatingOperation(op));
+ } catch (InvocationTargetException e) {
+ final String title = NewWizardMessages.ScriptProjectWizardSecondPage_error_remove_title;
+ final String message = NewWizardMessages.ScriptProjectWizardSecondPage_error_remove_message;
+ ExceptionHandler.handle(e, getShell(), title, message);
+ } catch (InterruptedException e) {
+ // cancel pressed
+ }
+ }
+
+ final void doRemoveProject(IProgressMonitor monitor)
+ throws InvocationTargetException {
+ final boolean noProgressMonitor = (fCurrProjectLocation == null); // inside
+ // workspace
+ if (monitor == null || noProgressMonitor) {
+ monitor = new NullProgressMonitor();
+ }
+ monitor.beginTask(
+ NewWizardMessages.ScriptProjectWizardSecondPage_operation_remove,
+ 3);
+ try {
+ try {
+ URI projLoc = getProjectHandle().getLocationURI();
+
+ boolean removeContent = !fKeepContent
+ && getProjectHandle().isSynchronized(
+ IResource.DEPTH_INFINITE);
+ getProjectHandle().delete(removeContent, false,
+ new SubProgressMonitor(monitor, 2));
+
+ } finally {
+ CoreUtility.enableAutoBuild(fIsAutobuild.booleanValue()); // fIsAutobuild
+ // must
+ // be
+ // set
+ fIsAutobuild = null;
+ }
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ fKeepContent = false;
+ }
+ }
+
+ private void changeToNewProject() {
+ fKeepContent = this.getDetect();
+
+ final IRunnableWithProgress op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ try {
+ if (fIsAutobuild == null) {
+ fIsAutobuild = Boolean.valueOf(CoreUtility
+ .enableAutoBuild(false));
+ }
+ updateProject(monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } catch (OperationCanceledException e) {
+ throw new InterruptedException();
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+
+ try {
+ getContainer().run(true, false,
+ new WorkspaceModifyDelegatingOperation(op));
+ } catch (InvocationTargetException e) {
+ final String title = NewWizardMessages.ScriptProjectWizardSecondPage_error_title;
+ final String message = NewWizardMessages.ScriptProjectWizardSecondPage_error_message;
+ ExceptionHandler.handle(e, getShell(), title, message);
+ } catch (InterruptedException e) {
+ // cancel pressed
+ }
+ }
+
+ /**
+ * Called from the wizard on cancel.
+ */
+ public void performCancel() {
+ removeProject();
+ }
+
+ /**
+ * Helper method to create and open a IProject. The project location is
+ * configured. No natures are added.
+ *
+ * @param project
+ * The handle of the project to create.
+ * @param locationURI
+ * The location of the project or <code>null</code> to create the
+ * project in the workspace
+ * @param monitor
+ * a progress monitor to report progress or <code>null</code> if
+ * progress reporting is not desired
+ * @throws CoreException
+ * if the project couldn't be created
+ * @see org.eclipse.core.resources.IProjectDescription#setLocationURI(java.net.URI)
+ *
+ */
+ public void createProject(IProject project, URI locationURI,
+ IProgressMonitor monitor) throws CoreException {
+ PHPProjectUtils.createProjectAt(project, locationURI, monitor);
+ }
+
+ protected void rememberExistingFiles(URI projectLocation)
+ throws CoreException {
+ fDotProjectBackup = null;
+ fDotBuildpathBackup = null;
+
+ IFileStore file = EFS.getStore(projectLocation);
+ if (file.fetchInfo().exists()) {
+ IFileStore projectFile = file.getChild(FILENAME_PROJECT);
+ if (projectFile.fetchInfo().exists()) {
+ fDotProjectBackup = createBackup(projectFile, "project-desc"); //$NON-NLS-1$
+ }
+ IFileStore buildpathFile = file.getChild(FILENAME_BUILDPATH);
+ if (buildpathFile.fetchInfo().exists()) {
+ fDotBuildpathBackup = createBackup(buildpathFile,
+ "buildpath-desc"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private void restoreExistingFiles(URI projectLocation,
+ IProgressMonitor monitor) throws CoreException {
+ int ticks = ((fDotProjectBackup != null ? 1 : 0) + (fDotBuildpathBackup != null ? 1
+ : 0)) * 2;
+ monitor.beginTask("", ticks); //$NON-NLS-1$
+ try {
+ if (fDotProjectBackup != null) {
+ IFileStore projectFile = EFS.getStore(projectLocation)
+ .getChild(FILENAME_PROJECT);
+ projectFile
+ .delete(EFS.NONE, new SubProgressMonitor(monitor, 1));
+ copyFile(fDotProjectBackup, projectFile,
+ new SubProgressMonitor(monitor, 1));
+ }
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ DLTKUIPlugin.PLUGIN_ID,
+ IStatus.ERROR,
+ NewWizardMessages.ScriptProjectWizardSecondPage_problem_restore_project,
+ e);
+ throw new CoreException(status);
+ }
+ try {
+ if (fDotBuildpathBackup != null) {
+ IFileStore buildpathFile = EFS.getStore(projectLocation)
+ .getChild(FILENAME_BUILDPATH);
+ buildpathFile.delete(EFS.NONE, new SubProgressMonitor(monitor,
+ 1));
+ copyFile(fDotBuildpathBackup, buildpathFile,
+ new SubProgressMonitor(monitor, 1));
+ }
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ DLTKUIPlugin.PLUGIN_ID,
+ IStatus.ERROR,
+ NewWizardMessages.ScriptProjectWizardSecondPage_problem_restore_buildpath,
+ e);
+ throw new CoreException(status);
+ }
+ }
+
+ private File createBackup(IFileStore source, String name)
+ throws CoreException {
+ try {
+ File bak = File.createTempFile("eclipse-" + name, ".bak"); //$NON-NLS-1$//$NON-NLS-2$
+ copyFile(source, bak);
+ return bak;
+ } catch (IOException e) {
+ IStatus status = new Status(
+ IStatus.ERROR,
+ DLTKUIPlugin.PLUGIN_ID,
+ IStatus.ERROR,
+ Messages.format(
+ NewWizardMessages.ScriptProjectWizardSecondPage_problem_backup,
+ name), e);
+ throw new CoreException(status);
+ }
+ }
+
+ private void copyFile(IFileStore source, File target) throws IOException,
+ CoreException {
+ InputStream is = source.openInputStream(EFS.NONE, null);
+ FileOutputStream os = new FileOutputStream(target);
+ copyFile(is, os);
+ }
+
+ private void copyFile(File source, IFileStore target,
+ IProgressMonitor monitor) throws IOException, CoreException {
+ FileInputStream is = new FileInputStream(source);
+ OutputStream os = target.openOutputStream(EFS.NONE, monitor);
+ copyFile(is, os);
+ }
+
+ private void copyFile(InputStream is, OutputStream os) throws IOException {
+ try {
+ byte[] buffer = new byte[8192];
+ while (true) {
+ int bytesRead = is.read(buffer);
+ if (bytesRead == -1)
+ break;
+
+ os.write(buffer, 0, bytesRead);
+ }
+ } finally {
+ try {
+ is.close();
+ } finally {
+ os.close();
+ }
+ }
+ }
+
+ protected URI getProjectLocationURI() throws CoreException {
+ if (this.isInWorkspace()) {
+ return null;
+ }
+ return this.getLocationURI();
+ }
+
+ protected void updateProject(IProgressMonitor monitor)
+ throws CoreException, InterruptedException {
+
+ IProject projectHandle = this.getProjectHandle();
+ DLTKCore.create(projectHandle);
+ fCurrProjectLocation = getProjectLocationURI();
+
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ try {
+ monitor.beginTask(
+ NewWizardMessages.ScriptProjectWizardSecondPage_operation_initialize,
+ 70);
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+
+ URI realLocation = fCurrProjectLocation;
+ if (fCurrProjectLocation == null) { // inside workspace
+ try {
+ URI rootLocation = ResourcesPlugin.getWorkspace().getRoot()
+ .getLocationURI();
+ realLocation = new URI(rootLocation.getScheme(), null, Path
+ .fromPortableString(rootLocation.getPath())
+ .append(projectHandle.getName()).toString(), null);
+ } catch (URISyntaxException e) {
+ Assert.isTrue(false, "Can't happen"); //$NON-NLS-1$
+ }
+ }
+
+ rememberExistingFiles(realLocation);
+
+ createProject(projectHandle, fCurrProjectLocation,
+ new SubProgressMonitor(monitor, 20));
+ } finally {
+ monitor.done();
+ }
+ }
+
public void initPage() {
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java
index 2e1c0c5..a4209e2 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java
@@ -11,26 +11,18 @@
*******************************************************************************/
package org.eclipse.php.internal.ui.wizards;
-import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.*;
import org.eclipse.dltk.core.*;
-import org.eclipse.dltk.internal.corext.util.Messages;
import org.eclipse.dltk.internal.ui.util.CoreUtility;
import org.eclipse.dltk.internal.ui.wizards.BuildpathDetector;
import org.eclipse.dltk.internal.ui.wizards.NewWizardMessages;
-import org.eclipse.dltk.ui.DLTKUIPlugin;
import org.eclipse.dltk.ui.util.ExceptionHandler;
import org.eclipse.dltk.ui.util.IStatusChangeListener;
import org.eclipse.dltk.ui.wizards.BuildpathsBlock;
@@ -74,8 +66,6 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
private boolean fKeepContent;
- private File fDotProjectBackup;
- private File fDotBuildpathBackup;
private Boolean fIsAutobuild;
/**
@@ -85,9 +75,6 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
fFirstPage = mainPage;
fCurrProjectLocation = null;
fKeepContent = false;
-
- fDotProjectBackup = null;
- fDotBuildpathBackup = null;
fIsAutobuild = null;
}
@@ -99,27 +86,6 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
- */
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- IWizardPage currentPage = getContainer().getCurrentPage();
- if (!visible && currentPage != null) {
- // going back from 2nd page to 1st one
- if (currentPage instanceof PHPProjectWizardFirstPage) {
- IWizardPage nextPage = currentPage.getNextPage();
- if (nextPage instanceof PHPProjectWizardSecondPage) {
- ((PHPProjectWizardSecondPage) nextPage).removeProject();
- } else {
- throw (new IllegalStateException());
- }
- }
- }
- }
-
private void changeToNewProject() {
fKeepContent = fFirstPage.getDetect();
@@ -173,21 +139,6 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
throw new OperationCanceledException();
}
- URI realLocation = fCurrProjectLocation;
- if (fCurrProjectLocation == null) { // inside workspace
- try {
- URI rootLocation = ResourcesPlugin.getWorkspace().getRoot()
- .getLocationURI();
- realLocation = new URI(rootLocation.getScheme(), null, Path
- .fromPortableString(rootLocation.getPath())
- .append(getProject().getName()).toString(), null);
- } catch (URISyntaxException e) {
- Assert.isTrue(false, "Can't happen"); //$NON-NLS-1$
- }
- }
-
- rememberExistingFiles(realLocation);
-
createProject(getProject(), fCurrProjectLocation,
new SubProgressMonitor(monitor, 20));
@@ -394,119 +345,6 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
return fFirstPage.getLocationURI();
}
- protected void rememberExistingFiles(URI projectLocation)
- throws CoreException {
- fDotProjectBackup = null;
- fDotBuildpathBackup = null;
-
- IFileStore file = EFS.getStore(projectLocation);
- if (file.fetchInfo().exists()) {
- IFileStore projectFile = file.getChild(FILENAME_PROJECT);
- if (projectFile.fetchInfo().exists()) {
- fDotProjectBackup = createBackup(projectFile, "project-desc"); //$NON-NLS-1$
- }
- IFileStore buildpathFile = file.getChild(FILENAME_BUILDPATH);
- if (buildpathFile.fetchInfo().exists()) {
- fDotBuildpathBackup = createBackup(buildpathFile,
- "buildpath-desc"); //$NON-NLS-1$
- }
- }
- }
-
- private void restoreExistingFiles(URI projectLocation,
- IProgressMonitor monitor) throws CoreException {
- int ticks = ((fDotProjectBackup != null ? 1 : 0) + (fDotBuildpathBackup != null ? 1
- : 0)) * 2;
- monitor.beginTask("", ticks); //$NON-NLS-1$
- try {
- if (fDotProjectBackup != null) {
- IFileStore projectFile = EFS.getStore(projectLocation)
- .getChild(FILENAME_PROJECT);
- projectFile
- .delete(EFS.NONE, new SubProgressMonitor(monitor, 1));
- copyFile(fDotProjectBackup, projectFile,
- new SubProgressMonitor(monitor, 1));
- }
- } catch (IOException e) {
- IStatus status = new Status(
- IStatus.ERROR,
- DLTKUIPlugin.PLUGIN_ID,
- IStatus.ERROR,
- NewWizardMessages.ScriptProjectWizardSecondPage_problem_restore_project,
- e);
- throw new CoreException(status);
- }
- try {
- if (fDotBuildpathBackup != null) {
- IFileStore buildpathFile = EFS.getStore(projectLocation)
- .getChild(FILENAME_BUILDPATH);
- buildpathFile.delete(EFS.NONE, new SubProgressMonitor(monitor,
- 1));
- copyFile(fDotBuildpathBackup, buildpathFile,
- new SubProgressMonitor(monitor, 1));
- }
- } catch (IOException e) {
- IStatus status = new Status(
- IStatus.ERROR,
- DLTKUIPlugin.PLUGIN_ID,
- IStatus.ERROR,
- NewWizardMessages.ScriptProjectWizardSecondPage_problem_restore_buildpath,
- e);
- throw new CoreException(status);
- }
- }
-
- private File createBackup(IFileStore source, String name)
- throws CoreException {
- try {
- File bak = File.createTempFile("eclipse-" + name, ".bak"); //$NON-NLS-1$//$NON-NLS-2$
- copyFile(source, bak);
- return bak;
- } catch (IOException e) {
- IStatus status = new Status(
- IStatus.ERROR,
- DLTKUIPlugin.PLUGIN_ID,
- IStatus.ERROR,
- Messages.format(
- NewWizardMessages.ScriptProjectWizardSecondPage_problem_backup,
- name), e);
- throw new CoreException(status);
- }
- }
-
- private void copyFile(IFileStore source, File target) throws IOException,
- CoreException {
- InputStream is = source.openInputStream(EFS.NONE, null);
- FileOutputStream os = new FileOutputStream(target);
- copyFile(is, os);
- }
-
- private void copyFile(File source, IFileStore target,
- IProgressMonitor monitor) throws IOException, CoreException {
- FileInputStream is = new FileInputStream(source);
- OutputStream os = target.openOutputStream(EFS.NONE, monitor);
- copyFile(is, os);
- }
-
- private void copyFile(InputStream is, OutputStream os) throws IOException {
- try {
- byte[] buffer = new byte[8192];
- while (true) {
- int bytesRead = is.read(buffer);
- if (bytesRead == -1)
- break;
-
- os.write(buffer, 0, bytesRead);
- }
- } finally {
- try {
- is.close();
- } finally {
- os.close();
- }
- }
- }
-
/**
* Called from the wizard on finish.
*/
@@ -554,65 +392,6 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
ProjectOptions.setPhpVersion(phpVersion, getProject());
}
- private void removeProject() {
- if (getProject() == null || !getProject().exists()) {
- return;
- }
-
- IRunnableWithProgress op = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
- doRemoveProject(monitor);
- }
- };
-
- try {
- getContainer().run(true, true,
- new WorkspaceModifyDelegatingOperation(op));
- } catch (InvocationTargetException e) {
- final String title = NewWizardMessages.ScriptProjectWizardSecondPage_error_remove_title;
- final String message = NewWizardMessages.ScriptProjectWizardSecondPage_error_remove_message;
- ExceptionHandler.handle(e, getShell(), title, message);
- } catch (InterruptedException e) {
- // cancel pressed
- }
- }
-
- final void doRemoveProject(IProgressMonitor monitor)
- throws InvocationTargetException {
- final boolean noProgressMonitor = (fCurrProjectLocation == null); // inside
- // workspace
- if (monitor == null || noProgressMonitor) {
- monitor = new NullProgressMonitor();
- }
- monitor.beginTask(
- NewWizardMessages.ScriptProjectWizardSecondPage_operation_remove,
- 3);
- try {
- try {
- URI projLoc = getProject().getLocationURI();
-
- boolean removeContent = !fKeepContent
- && getProject()
- .isSynchronized(IResource.DEPTH_INFINITE);
- getProject().delete(removeContent, false,
- new SubProgressMonitor(monitor, 2));
-
- } finally {
- CoreUtility.enableAutoBuild(fIsAutobuild.booleanValue()); // fIsAutobuild
- // must
- // be
- // set
- fIsAutobuild = null;
- }
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- } finally {
- monitor.done();
- fKeepContent = false;
- }
- }
-
/**
* Helper method to create and open a IProject. The project location is
* configured. No natures are added.
@@ -635,13 +414,6 @@ public class PHPProjectWizardSecondPage extends CapabilityConfigurationPage
PHPProjectUtils.createProjectAt(project, locationURI, monitor);
}
- /**
- * Called from the wizard on cancel.
- */
- public void performCancel() {
- removeProject();
- }
-
public IProject getCurrProject() {
return getProject();
}