Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Descher2014-05-04 16:08:54 -0400
committerMarco Descher2014-05-06 10:33:56 -0400
commit27e6572c59925d736dff2a42a246ec0fcefcaebb (patch)
tree9cc55d7c72fb5d780fdbf4d6e6381f535d4f8dec
parentb23cad4034b1ed0244c614fa277b5599f8a0ed83 (diff)
downloadorg.eclipse.e4.tools-27e6572c59925d736dff2a42a246ec0fcefcaebb.tar.gz
org.eclipse.e4.tools-27e6572c59925d736dff2a42a246ec0fcefcaebb.tar.xz
org.eclipse.e4.tools-27e6572c59925d736dff2a42a246ec0fcefcaebb.zip
Bug 392907 - New fragment.e4xmi should add required dependencies
Signed-off-by: Marco Descher <marco@descher.at>
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java11
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/NewContributionModelWizard.java111
2 files changed, 117 insertions, 5 deletions
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java
index 69b2bbc9..0f3ed9f5 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java
@@ -197,6 +197,7 @@ public abstract class BaseApplicationModelWizard extends Wizard implements INewW
Map<Object, Object> options = new HashMap<Object, Object>();
resource.save(options);
adjustBuildPropertiesFile( modelFile );
+ adjustDependencies( modelFile );
}
catch (Exception exception) {
throw new RuntimeException(exception);
@@ -291,4 +292,14 @@ public abstract class BaseApplicationModelWizard extends Wizard implements INewW
model.save();
}
}
+
+ /**
+ * Callback hook to allow for after-file-creation modifications. Default
+ * implementation does nothing.
+ *
+ * @param file
+ * the file created by the wizard
+ */
+ protected void adjustDependencies(IFile file) {
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/NewContributionModelWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/NewContributionModelWizard.java
index 47bf7233..6c3a10ad 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/NewContributionModelWizard.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/NewContributionModelWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 BestSolution.at and others.
+ * Copyright (c) 2010-2014 BestSolution.at 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
@@ -7,13 +7,27 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Marco Descher <marco@descher.at> - Bug 392907
******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.model;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.e4.ui.model.fragment.MFragmentFactory;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
-
+import org.eclipse.osgi.service.resolver.BundleDescription;
+import org.eclipse.pde.core.plugin.IMatchRules;
+import org.eclipse.pde.core.plugin.IPluginElement;
+import org.eclipse.pde.core.plugin.IPluginExtension;
+import org.eclipse.pde.core.plugin.IPluginImport;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.core.plugin.IPluginObject;
+import org.eclipse.pde.core.plugin.PluginRegistry;
+import org.eclipse.pde.internal.core.bundle.WorkspaceBundlePluginModel;
+import org.eclipse.pde.internal.core.project.PDEProject;
public class NewContributionModelWizard extends BaseApplicationModelWizard {
@@ -21,14 +35,101 @@ public class NewContributionModelWizard extends BaseApplicationModelWizard {
public String getDefaultFileName() {
return "fragment.e4xmi";
}
-
+
@Override
protected EObject createInitialModel() {
return (EObject) MFragmentFactory.INSTANCE.createModelFragments();
}
-
+
@Override
protected NewModelFilePage createWizardPage(ISelection selection) {
- return new NewModelFilePage(selection,getDefaultFileName());
+ return new NewModelFilePage(selection, getDefaultFileName());
+ }
+
+ /**
+ * Add the required dependencies (org.eclipse.e4.ui.model.workbench) and
+ * register fragment.e4xmi at the required extension point
+ * (org.eclipse.e4.workbench.model)
+ */
+ @Override
+ protected void adjustDependencies(IFile file) {
+ IProject project = file.getProject();
+ IFile pluginXml = PDEProject.getPluginXml(project);
+ IFile manifest = PDEProject.getManifest(project);
+
+ WorkspaceBundlePluginModel fModel = new WorkspaceBundlePluginModel(
+ manifest, pluginXml);
+ try {
+ addWorkbenchDependencyIfRequired(fModel);
+ registerWithExtensionPointIfRequired(project, fModel, file);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ private void addWorkbenchDependencyIfRequired(
+ WorkspaceBundlePluginModel fModel) throws CoreException {
+ IPluginImport[] imports = fModel.getPluginBase().getImports();
+
+ final String WORKBENCH_IMPORT_ID = "org.eclipse.e4.ui.model.workbench"; //$NON-NLS-1$
+
+ for (IPluginImport iPluginImport : imports) {
+ if (WORKBENCH_IMPORT_ID.equalsIgnoreCase(iPluginImport.getId()))
+ return;
+ }
+
+ String version = "";
+ IPluginModelBase findModel = PluginRegistry
+ .findModel(WORKBENCH_IMPORT_ID);
+ if (findModel != null) {
+ BundleDescription bundleDescription = findModel
+ .getBundleDescription();
+ if (bundleDescription != null)
+ version = bundleDescription.getVersion().toString();
+ }
+
+ IPluginImport workbenchImport = fModel.getPluginFactory()
+ .createImport();
+ workbenchImport.setId(WORKBENCH_IMPORT_ID);
+ workbenchImport.setVersion(version);
+ workbenchImport.setMatch(IMatchRules.GREATER_OR_EQUAL);
+ fModel.getPluginBase().add(workbenchImport);
+ fModel.save();
+ }
+
+ /**
+ * Register the fragment.e4xmi with the org.eclipse.e4.workbench.model
+ * extension point, if there is not already a fragment registered.
+ */
+ private void registerWithExtensionPointIfRequired(IProject project,
+ WorkspaceBundlePluginModel fModel, IFile file) throws CoreException {
+ IPluginExtension[] extensions = fModel.getPluginBase().getExtensions();
+
+ final String WORKBENCH_MODEL_EP_ID = "org.eclipse.e4.workbench.model"; //$NON-NLS-1$
+ final String FRAGMENT = "fragment";
+
+ for (IPluginExtension iPluginExtension : extensions) {
+ if (WORKBENCH_MODEL_EP_ID
+ .equalsIgnoreCase(iPluginExtension.getId())) {
+ IPluginObject[] children = iPluginExtension.getChildren();
+ for (IPluginObject child : children) {
+ if (FRAGMENT.equalsIgnoreCase(child.getName())) //$NON-NLS-1$
+ return;
+ }
+ }
+ }
+
+ IPluginExtension extPointFragmentRegister = fModel.getPluginFactory()
+ .createExtension();
+ IPluginElement element = extPointFragmentRegister.getModel()
+ .getFactory().createElement(extPointFragmentRegister);
+ element.setName(FRAGMENT);
+ element.setAttribute("uri", file.getName()); //$NON-NLS-1$
+ extPointFragmentRegister.setId(project.getName() + "." + FRAGMENT); //$NON-NLS-1$
+ extPointFragmentRegister.setPoint(WORKBENCH_MODEL_EP_ID);
+ extPointFragmentRegister.add(element);
+ fModel.getPluginBase().add(extPointFragmentRegister);
+ fModel.save();
}
} \ No newline at end of file

Back to the top