Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 222554 Details for
Bug 389037
New project wizard should have an option to select templates from available PHP facets
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
first patch
org.eclipse.pdt.patch (text/plain), 36.91 KB, created by
Martin Eisengardt
on 2012-10-19 02:51:20 EDT
(
hide
)
Description:
first patch
Filename:
MIME Type:
Creator:
Martin Eisengardt
Created:
2012-10-19 02:51:20 EDT
Size:
36.91 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.php.core >diff --git src/org/eclipse/php/internal/core/facet/PHPFacets.java src/org/eclipse/php/internal/core/facet/PHPFacets.java >index c880ead..8e8bef3 100644 >--- src/org/eclipse/php/internal/core/facet/PHPFacets.java >+++ src/org/eclipse/php/internal/core/facet/PHPFacets.java >@@ -177,4 +177,16 @@ > 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(); >+ } >+ > } >#P org.eclipse.php.ui >diff --git META-INF/MANIFEST.MF META-INF/MANIFEST.MF >index 0cde71e..93295f4 100644 >--- META-INF/MANIFEST.MF >+++ META-INF/MANIFEST.MF >@@ -41,7 +41,9 @@ > 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 src/org/eclipse/php/internal/ui/PHPUIMessages.java src/org/eclipse/php/internal/ui/PHPUIMessages.java >index c1d54f1..e5ae6b0 100644 >--- src/org/eclipse/php/internal/ui/PHPUIMessages.java >+++ src/org/eclipse/php/internal/ui/PHPUIMessages.java >@@ -167,6 +167,7 @@ > 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 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 src/org/eclipse/php/internal/ui/PHPUIMessages.properties src/org/eclipse/php/internal/ui/PHPUIMessages.properties >index 3c39390..ec0e8e4 100644 >--- src/org/eclipse/php/internal/ui/PHPUIMessages.properties >+++ src/org/eclipse/php/internal/ui/PHPUIMessages.properties >@@ -375,6 +375,8 @@ > 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 src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java >index 4b6cfaa..2a90a96 100644 >--- src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java >+++ src/org/eclipse/php/internal/ui/wizards/PHPProjectCreationWizard.java >@@ -42,6 +42,8 @@ > > protected int fLastPageIndex = -1; > >+ private PHPProjectWizardFacetsPage fFacetsPage; >+ > public PHPProjectCreationWizard() { > setDefaultPageImageDescriptor(PHPPluginImages.DESC_WIZBAN_ADD_PHP_PROJECT); > setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings()); >@@ -57,6 +59,13 @@ > fFirstPage > .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); >@@ -145,7 +154,7 @@ > > public boolean performCancel() { > if (!fFirstPage.isExistingLocation()) >- fLastPage.performCancel(); >+ fFirstPage.performCancel(); > return super.performCancel(); > } > >diff --git src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFacetsPage.java src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFacetsPage.java >new file mode 100644 >index 0000000..2bb8ca0 >--- /dev/null >+++ src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFacetsPage.java >@@ -0,0 +1,207 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. 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 >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ * Zend Technologies >+ *******************************************************************************/ >+package org.eclipse.php.internal.ui.wizards; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.dltk.ui.wizards.NewElementWizardPage; >+import org.eclipse.jface.wizard.IWizardPage; >+import org.eclipse.php.internal.core.PHPCorePlugin; >+import org.eclipse.php.internal.core.facet.PHPFacets; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.TabFolder; >+import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; >+import org.eclipse.wst.common.project.facet.core.IPreset; >+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; >+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; >+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent; >+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener; >+import org.eclipse.wst.common.project.facet.core.events.IProjectFacetsChangedEvent; >+import org.eclipse.wst.common.project.facet.core.util.AbstractFilter; >+import org.eclipse.wst.common.project.facet.core.util.FilterEvent; >+import org.eclipse.wst.common.project.facet.core.util.IFilter; >+import org.eclipse.wst.common.project.facet.ui.PresetSelectionPanel; >+ >+public class PHPProjectWizardFacetsPage extends NewElementWizardPage implements >+ IPHPProjectCreateWizardPage { >+ >+ private PHPProjectWizardFirstPage fFirstPage; >+ >+ private IFacetedProjectWorkingCopy fpjwc; >+ private final IFacetedProjectListener fpjwcListener; >+ private IFacetedProjectListener fpjwcListenerForPreset; >+ >+ private Composite ppanelParent; >+ >+ private PresetSelectionPanel ppanel; >+ >+ private TabFolder tabFolder; >+ >+ private Composite top; >+ >+ /** >+ * Constructor for ScriptProjectWizardSecondPage. >+ */ >+ public PHPProjectWizardFacetsPage(PHPProjectWizardFirstPage mainPage) { >+ super("PHPProjectWizardFacetsPage"); >+ fFirstPage = mainPage; >+ >+ this.fpjwcListener = new IFacetedProjectListener() { >+ public void handleEvent(final IFacetedProjectEvent event) { >+ final Runnable runnable = new Runnable() { >+ public void run() { >+ validateFacets(); >+ } >+ }; >+ >+ getContainer().getShell().getDisplay().asyncExec(runnable); >+ } >+ }; >+ } >+ >+ /** >+ * taken from org.eclipse.wst.web.ui.internal.wizards. >+ * DataModelFacetCreationWizardPage >+ * >+ * @param top >+ */ >+ protected void createPresetPanel(Composite top) { >+ final IFilter<IPreset> filter = new AbstractFilter<IPreset>() { >+ { >+ fpjwcListenerForPreset = new IFacetedProjectListener() { >+ public void handleEvent(final IFacetedProjectEvent event) { >+ handleProjectFacetsChangedEvent((IProjectFacetsChangedEvent) event); >+ } >+ }; >+ } >+ >+ public boolean check(final IPreset preset) { >+ final IProjectFacetVersion primaryFacetVersion = PHPFacets >+ .getCoreVersion(); >+ return preset.getProjectFacets().contains(primaryFacetVersion); >+ } >+ >+ private void handleProjectFacetsChangedEvent( >+ final IProjectFacetsChangedEvent event) { >+ for (IProjectFacetVersion fv : event >+ .getFacetsWithChangedVersions()) { >+ if (fv.getProjectFacet() == PHPFacets.getCoreVersion()) { >+ final IFilterEvent<IPreset> filterEvent = new FilterEvent<IPreset>( >+ this, IFilterEvent.Type.FILTER_CHANGED); >+ >+ notifyListeners(filterEvent); >+ } >+ } >+ >+ checkTabChanges(); >+ } >+ }; >+ >+ ppanel = new PresetSelectionPanel(top, fpjwc, filter); >+ >+ ppanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ } >+ >+ private void validateFacets() { >+ final IStatus status = this.fpjwc.validate(); >+ if (status != null && !status.isOK()) { >+ setErrorMessage(status.getMessage()); >+ } else { >+ setErrorMessage(null); >+ } >+ } >+ >+ private void checkTabChanges() { >+ // TODO >+ } >+ >+ public void createControl(Composite parent) { >+ top = createTopLevelComposite(parent); >+ addExtendedControls(top); >+ setControl(top); >+ } >+ >+ private void addExtendedControls(Composite top) { >+ this.tabFolder = new TabFolder(top, SWT.NONE); >+ this.tabFolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ // invisible as long as there are additional configuration pages >+ this.tabFolder.setVisible(false); >+ } >+ >+ protected Composite createTopLevelComposite(Composite parent) { >+ final Composite top = new Composite(parent, SWT.NONE); >+ top.setLayout(new GridLayout(1, true)); >+ top.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ this.ppanelParent = new Composite(top, SWT.NONE); >+ this.ppanelParent.setLayout(new GridLayout()); >+ this.ppanelParent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ return top; >+ } >+ >+ @Override >+ public void setVisible(boolean visible) { >+ super.setVisible(visible); >+ >+ if (this.fpjwc == null) { >+ // we are coming from first page. Do not do anything. First page >+ // will call initPage >+ return; >+ } >+ >+ if (visible) { >+ internalInit(); >+ } else { >+ this.fpjwc.removeListener(this.fpjwcListener); >+ this.fpjwc.removeListener(this.fpjwcListenerForPreset); >+ >+ IWizardPage currentPage = getContainer().getCurrentPage(); >+ if (currentPage instanceof IPHPProjectCreateWizardPage) { >+ // going forward from facets page to 2nd one (or first page) >+ ((IPHPProjectCreateWizardPage) currentPage).initPage(); >+ } >+ } >+ } >+ >+ private void internalInit() { >+ this.fpjwc.addListener(this.fpjwcListener, >+ IFacetedProjectEvent.Type.VALIDATION_PROBLEMS_CHANGED); >+ this.fpjwc.addListener(fpjwcListenerForPreset, >+ IFacetedProjectEvent.Type.PROJECT_FACETS_CHANGED); >+ } >+ >+ public void initPage() { >+ final IProject project = this.fFirstPage.getProjectHandle(); >+ try { >+ if (this.ppanel != null && !this.ppanel.isDisposed()) { >+ ppanel.setVisible(false); >+ ppanel.dispose(); >+ } >+ PHPFacets.createFacetedProject(project, >+ this.fFirstPage.getPHPVersionValue(), >+ new NullProgressMonitor()); >+ this.fpjwc = ProjectFacetsManager.create(project) >+ .createWorkingCopy(); >+ createPresetPanel(ppanelParent); >+ checkTabChanges(); >+ top.layout(true); >+ internalInit(); >+ } catch (CoreException e) { >+ PHPCorePlugin.log(e); >+ } >+ } >+ >+} >diff --git src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java >index b4fdb83..8bfbc7e 100644 >--- src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardFirstPage.java >+++ 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.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.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 @@ > */ > public class PHPProjectWizardFirstPage extends WizardPage implements > IPHPProjectCreateWizardPage { >+ > public PHPProjectWizardFirstPage() { > super(PAGE_NAME); > setPageComplete(false); >@@ -59,6 +71,16 @@ > setDescription(NewWizardMessages.ScriptProjectWizardFirstPage_page_description); > 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 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 src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java >index 2e1c0c5..a4209e2 100644 >--- src/org/eclipse/php/internal/ui/wizards/PHPProjectWizardSecondPage.java >+++ 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 @@ > > private boolean fKeepContent; > >- private File fDotProjectBackup; >- private File fDotBuildpathBackup; > private Boolean fIsAutobuild; > > /** >@@ -85,9 +75,6 @@ > fFirstPage = mainPage; > fCurrProjectLocation = null; > fKeepContent = false; >- >- fDotProjectBackup = null; >- fDotBuildpathBackup = null; > fIsAutobuild = null; > } > >@@ -97,27 +84,6 @@ > > protected boolean useNewSourcePage() { > 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() { >@@ -172,21 +138,6 @@ > 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(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 @@ > 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 @@ > 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. >@@ -633,13 +412,6 @@ > public void createProject(IProject project, URI locationURI, > IProgressMonitor monitor) throws CoreException { > PHPProjectUtils.createProjectAt(project, locationURI, monitor); >- } >- >- /** >- * Called from the wizard on cancel. >- */ >- public void performCancel() { >- removeProject(); > } > > public IProject getCurrProject() { >diff --git src/org/eclipse/php/ui/wizards/INewProjectWizardFragementFactory.java src/org/eclipse/php/ui/wizards/INewProjectWizardFragementFactory.java >new file mode 100644 >index 0000000..c777bb2 >--- /dev/null >+++ src/org/eclipse/php/ui/wizards/INewProjectWizardFragementFactory.java >@@ -0,0 +1,29 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. 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 >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ * Zend Technologies >+ *******************************************************************************/ >+package org.eclipse.php.ui.wizards; >+ >+import org.eclipse.php.internal.ui.wizards.WizardFragment; >+ >+/** >+ * Factory for creating fragments for the new project wizard. >+ * >+ */ >+public interface INewProjectWizardFragementFactory { >+ >+ /** >+ * Creates a WizardFragment used for the new project wizard. >+ * >+ * @return the wizard fragment >+ */ >+ public WizardFragment createWizardFragment(); >+ >+} >diff --git src/org/eclipse/php/ui/wizards/INewProjectWizardOperation.java src/org/eclipse/php/ui/wizards/INewProjectWizardOperation.java >new file mode 100644 >index 0000000..b2239cf >--- /dev/null >+++ src/org/eclipse/php/ui/wizards/INewProjectWizardOperation.java >@@ -0,0 +1,59 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. 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 >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ * Zend Technologies >+ *******************************************************************************/ >+package org.eclipse.php.ui.wizards; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.php.internal.ui.wizards.WizardModel; >+ >+/** >+ * A single operation for the new project wizard >+ * >+ */ >+public interface INewProjectWizardOperation { >+ >+ /** >+ * Invoked before switching from facets page to the php include page. Can be >+ * used to preset/manipulate the include path. The given project is already >+ * prepared/ the default. >+ * >+ * @param projectHandle >+ * The project handle >+ * @param model >+ * the wizard data model >+ * @param keep >+ * true to keep the sources (overwrite existing project) or false >+ * to create a new project >+ */ >+ public void onPreparePhpProject(IProject projectHandle, WizardModel model, >+ boolean keep); >+ >+ /** >+ * Invoked after the user clicks on finish >+ * >+ * @param projectHandle >+ * the final php project >+ * @param model >+ * the wizard data model >+ */ >+ public void onFinish(IProject projectHandle, WizardModel model); >+ >+ /** >+ * Invoked after the user clicks on cancel. should be used for cleanup. >+ * >+ * @param projectHandle >+ * the temporary php project >+ * @param model >+ * the wizard data model >+ */ >+ public void onCancel(IProject projectHandle, WizardModel model); >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 389037
: 222554 |
222557
|
222558
|
222559