fix "illegal" inheritance
Several classes in the RCP are not ment to be subclassed. Inheriting
from such classes outside of their original bundle is called "illegal".
This change fixes such illegal inheritance dependencies.
Change-Id: I393e48bbb5b4914425a3e1c659914126d67c9882
Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/NewPluginProjectWizard.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/NewPluginProjectWizard.java
index ca3c97e..c5995a1 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/NewPluginProjectWizard.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/NewPluginProjectWizard.java
@@ -1,89 +1,201 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2014 John Krasnay 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:
* John Krasnay - initial API and implementation
+ * Florian Thienel - fix illegal inheritance from BasicNewProjectResourceWizard
*******************************************************************************/
package org.eclipse.vex.ui.internal.config;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.text.MessageFormat;
+import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
+import org.eclipse.ui.dialogs.WizardNewProjectReferencePage;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.ide.undo.CreateProjectOperation;
+import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
+import org.eclipse.ui.internal.ide.StatusUtil;
+import org.eclipse.ui.statushandlers.IStatusAdapterConstants;
+import org.eclipse.ui.statushandlers.StatusAdapter;
+import org.eclipse.ui.statushandlers.StatusManager;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
+import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
import org.eclipse.vex.ui.internal.VexPlugin;
-/**
- * Wizard for creating a new Vex Plugin Project.
- */
-public class NewPluginProjectWizard extends BasicNewProjectResourceWizard {
+public class NewPluginProjectWizard extends Wizard implements INewWizard, IExecutableExtension {
+
+ private IWorkbench workbench;
+ private IConfigurationElement configurationElement;
+
+ private WizardNewProjectCreationPage mainPage;
+ private WizardNewProjectReferencePage referencePage;
@Override
- public void init(final IWorkbench workbench, final IStructuredSelection currentSelection) {
- super.init(workbench, currentSelection);
+ public void init(final IWorkbench workbench, final IStructuredSelection selection) {
+ this.workbench = workbench;
setWindowTitle(Messages.getString("NewPluginProjectWizard.title")); //$NON-NLS-1$
}
@Override
- public boolean performFinish() {
-
- boolean success = super.performFinish();
- if (success) {
- try {
- createVexPluginXml();
- registerVexPluginNature();
- // the new plug-in project is automatically added to the ConfigurationRegistry
- } catch (final CoreException e) {
- VexPlugin.getDefault().log(IStatus.ERROR, Messages.getString("NewPluginProjectWizard.createError"), e); //$NON-NLS-1$
- success = false;
- }
-
- }
-
- return success;
+ public void setInitializationData(final IConfigurationElement configurationElement, final String propertyName, final Object data) throws CoreException {
+ this.configurationElement = configurationElement;
}
- // ====================================================== PRIVATE
+ @Override
+ public void addPages() {
+ super.addPages();
- private void createVexPluginXml() throws CoreException {
+ mainPage = new WizardNewProjectCreationPage("NewPluginProjectPage"); //$NON-NLS-1$
+ mainPage.setTitle("Project");
+ mainPage.setDescription("Create a plug-in project.");
+ addPage(mainPage);
- final IProject project = getNewProject();
+ if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length > 0) {
+ referencePage = new WizardNewProjectReferencePage("ReferenceProjectPage");//$NON-NLS-1$
+ referencePage.setTitle("Project References");
+ referencePage.setDescription("Select referenced projects.");
+ addPage(referencePage);
+ }
+ }
- ByteArrayOutputStream baos;
- PrintStream out;
+ @Override
+ public boolean performFinish() {
+ final IProject newProject = createNewProject();
- baos = new ByteArrayOutputStream();
- out = new PrintStream(baos);
+ if (newProject == null) {
+ return false;
+ }
+ final IWorkingSet[] workingSets = mainPage.getSelectedWorkingSets();
+ workbench.getWorkingSetManager().addToWorkingSets(newProject, workingSets);
+
+ BasicNewProjectResourceWizard.updatePerspective(configurationElement);
+ BasicNewResourceWizard.selectAndReveal(newProject, workbench.getActiveWorkbenchWindow());
+
+ try {
+ createVexPluginXml(newProject);
+ registerVexPluginNature(newProject);
+ } catch (final CoreException e) {
+ VexPlugin.getDefault().log(IStatus.ERROR, Messages.getString("NewPluginProjectWizard.createError"), e); //$NON-NLS-1$
+ return false;
+ }
+
+ return true;
+ }
+
+ private IProject createNewProject() {
+ final IProject newProjectHandle = mainPage.getProjectHandle();
+
+ final URI location;
+ if (!mainPage.useDefaults()) {
+ location = mainPage.getLocationURI();
+ } else {
+ location = null;
+ }
+
+ final IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
+ description.setLocationURI(location);
+
+ // update the referenced project if provided
+ if (referencePage != null) {
+ final IProject[] refProjects = referencePage.getReferencedProjects();
+ if (refProjects.length > 0) {
+ description.setReferencedProjects(refProjects);
+ }
+ }
+
+ // create the new project operation
+ final IRunnableWithProgress createOperation = new IRunnableWithProgress() {
+ public void run(final IProgressMonitor monitor) throws InvocationTargetException {
+ final CreateProjectOperation createProject = new CreateProjectOperation(description, Messages.getString("NewPluginProjectWizard.title"));
+ try {
+ createProject.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
+ } catch (final ExecutionException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ };
+
+ // run the new project creation operation
+ try {
+ getContainer().run(true, true, createOperation);
+ } catch (final InterruptedException e) {
+ return null;
+ } catch (final InvocationTargetException e) {
+ final Throwable t = e.getTargetException();
+ if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
+ final CoreException cause = (CoreException) t.getCause();
+ final StatusAdapter status;
+ if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
+ status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING,
+ MessageFormat.format("The underlying file system is case insensitive. There is an existing project or directory that conflicts with ''{0}''.", newProjectHandle.getName()),
+ cause));
+ } else {
+ status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), "Creation Problems", cause));
+ }
+ status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, "Creation Problems");
+ StatusManager.getManager().handle(status, StatusManager.BLOCK);
+ } else {
+ final StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0, MessageFormat.format("Internal error: {0}", t.getMessage()), t));
+ status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, "Creation Problems");
+ StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
+ }
+ return null;
+ }
+
+ return newProjectHandle;
+ }
+
+ private void createVexPluginXml(final IProject project) throws CoreException {
+ final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ final PrintStream out = new PrintStream(buffer);
out.println("<?xml version='1.0'?>"); //$NON-NLS-1$
out.println("<plugin>"); //$NON-NLS-1$
out.println("</plugin>"); //$NON-NLS-1$
out.close();
final IFile pluginXml = project.getFile(PluginProject.PLUGIN_XML);
- pluginXml.create(new ByteArrayInputStream(baos.toByteArray()), true, null);
+ pluginXml.create(new ByteArrayInputStream(buffer.toByteArray()), true, null);
- // By default open the Default Text Editor for vex-plugin.xml.
- // This isn't perfect, because the Vex icon is still shown, but
- // it'll do until we create a custom editor.
+ /*
+ * By default open the Default Text Editor for vex-plugin.xml. This isn't perfect, because the Vex icon is still
+ * be shown, but it'll do until we create a custom editor.
+ */
IDE.setDefaultEditor(pluginXml, "org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
}
- private void registerVexPluginNature() throws CoreException {
- final IProject project = getNewProject();
+ private void registerVexPluginNature(final IProject project) throws CoreException {
final IProjectDescription description = project.getDescription();
final String[] natures = description.getNatureIds();
final String[] newNatures = new String[natures.length + 1];
@@ -92,4 +204,5 @@
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
+
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/views/DebugView.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/views/DebugView.java
index 573a9a1..b7378ac 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/views/DebugView.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/views/DebugView.java
@@ -1,12 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2014 John Krasnay 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:
* John Krasnay - initial API and implementation
+ * Florian Thienel - fix illegal inheritance from IPage
*******************************************************************************/
package org.eclipse.vex.ui.internal.views;
@@ -16,46 +17,49 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.IPage;
-import org.eclipse.ui.part.IPageBookViewPage;
import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageBookView;
import org.eclipse.vex.ui.internal.Messages;
import org.eclipse.vex.ui.internal.editor.VexEditor;
-/**
- * A view that shows stats about the current Vex editor as a debugging aid.
- */
public class DebugView extends PageBookView {
@Override
protected IPage createDefaultPage(final PageBook book) {
- final IPageBookViewPage page = new IPageBookViewPage() {
+ final Page page = new Page() {
+ @Override
public void createControl(final Composite parent) {
label = new Label(parent, SWT.NONE);
label.setText(Messages.getString("DebugView.noActiveEditor")); //$NON-NLS-1$
}
+ @Override
public void dispose() {
}
+ @Override
public Control getControl() {
return label;
}
+ @Override
public IPageSite getSite() {
return site;
}
- public void init(final IPageSite site) throws PartInitException {
+ @Override
+ public void init(final IPageSite site) {
this.site = site;
}
+ @Override
public void setActionBars(final IActionBars actionBars) {
}
+ @Override
public void setFocus() {
}
@@ -83,7 +87,6 @@
@Override
protected IWorkbenchPart getBootstrapPart() {
- // TODO Auto-generated method stub
return null;
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
index 2c9fc14..a3efbfa 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
@@ -1,13 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2014 John Krasnay 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:
* John Krasnay - initial API and implementation
* Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
+ * Florian Thienel - fix illegal inheritance from BasicNewResourceWizard
*******************************************************************************/
package org.eclipse.vex.ui.internal.wizards;
@@ -20,8 +21,10 @@
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
@@ -46,27 +49,27 @@
import org.eclipse.vex.ui.internal.editor.DocumentTypeSelectionPage;
import org.eclipse.vex.ui.internal.editor.VexEditor;
-/**
- * Wizard for creating a new Vex document.
- */
-public class NewDocumentWizard extends BasicNewResourceWizard {
+public class NewDocumentWizard extends Wizard implements INewWizard {
+
+ private IWorkbench workbench;
+ private IStructuredSelection selection;
private DocumentTypeSelectionPage typePage;
private DocumentFileCreationPage filePage;
- @Override
- public void addPages() {
- typePage = new DocumentTypeSelectionPage();
- filePage = new DocumentFileCreationPage("filePage", getSelection()); //$NON-NLS-1$
- addPage(typePage);
- addPage(filePage);
+ public void init(final IWorkbench workbench, final IStructuredSelection currentSelection) {
+ this.workbench = workbench;
+ selection = currentSelection;
+
+ setWindowTitle(Messages.getString("NewDocumentWizard.title")); //$NON-NLS-1$
}
@Override
- public void init(final IWorkbench workbench, final IStructuredSelection currentSelection) {
-
- super.init(workbench, currentSelection);
- setWindowTitle(Messages.getString("NewDocumentWizard.title")); //$NON-NLS-1$
+ public void addPages() {
+ typePage = new DocumentTypeSelectionPage();
+ filePage = new DocumentFileCreationPage("filePage", selection); //$NON-NLS-1$
+ addPage(typePage);
+ addPage(filePage);
}
@Override
@@ -91,14 +94,14 @@
filePage.setInitialContents(bais);
final IFile file = filePage.createNewFile();
IDE.setDefaultEditor(file, VexEditor.ID);
- this.selectAndReveal(file);
registerEditorForFilename("*." + file.getFileExtension(), VexEditor.ID); //$NON-NLS-1$
// Open editor on new file.
- final IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
- if (dw != null) {
- final IWorkbenchPage page = dw.getActivePage();
+ final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow != null) {
+ BasicNewResourceWizard.selectAndReveal(file, activeWorkbenchWindow);
+ final IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
if (page != null) {
IDE.openEditor(page, file, true);
}
@@ -153,16 +156,9 @@
return document;
}
- /**
- * Register an editor to use for files with the given filename.
- *
+ /*
* NOTE: this method uses internal, undocumented Eclipse functionality. It may therefore break in a future version
* of Eclipse.
- *
- * @param fileName
- * Filename to be registered. Use the form "*.ext" to register all files with a given extension.
- * @param editorId
- * ID of the editor to use for the given filename.
*/
private static void registerEditorForFilename(final String fileName, final String editorId) {
@@ -222,9 +218,6 @@
}
- /**
- * Return the IEditorDescriptor for the given editor ID.
- */
private static EditorDescriptor getEditorDescriptor(final String editorId) {
final EditorRegistry reg = (EditorRegistry) PlatformUI.getWorkbench().getEditorRegistry();
for (final IEditorDescriptor editor : reg.getSortedEditorsFromPlugins()) {