diff options
7 files changed, 119 insertions, 76 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF index f816882c..8727c5ff 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF @@ -32,8 +32,7 @@ Require-Bundle: org.eclipse.core.databinding;bundle-version="1.3.0", org.eclipse.e4.ui.widgets;bundle-version="0.11.0", org.eclipse.equinox.preferences;bundle-version="3.4.0", org.eclipse.e4.tools;bundle-version="0.12.0", - org.eclipse.e4.ui.workbench.swt;bundle-version="0.10.0", - org.eclipse.pde.core;bundle-version="3.9.0" + org.eclipse.e4.ui.workbench.swt;bundle-version="0.10.0" Bundle-ActivationPolicy: lazy Import-Package: javax.annotation;version="1.0.0", javax.inject;version="1.0.0", diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DefaultEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DefaultEditor.java index 2691e269..78485075 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DefaultEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DefaultEditor.java @@ -1,44 +1,44 @@ -package org.eclipse.e4.tools.emf.ui.internal.common.component;
-
-import org.eclipse.core.databinding.observable.list.IObservableList;
-import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-
-public class DefaultEditor extends AbstractComponentEditor {
-
- @Override
- public Image getImage(Object element, Display display) {
- // no image
- return null;
- }
-
- @Override
- public String getLabel(Object element) {
- return element.getClass().getInterfaces()[0].getSimpleName() + " " + Messages.Special_UnknownElement; //$NON-NLS-1$
- }
-
- @Override
- public String getDetailLabel(Object element) {
- return Messages.Special_UnknownElement_Detail;
- }
-
- @Override
- public String getDescription(Object element) {
- return null;
- }
-
- @Override
- protected Composite doGetEditor(Composite parent, Object object) {
- return new Composite(parent, SWT.NONE);
- }
-
- @Override
- public IObservableList getChildList(Object element) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
+package org.eclipse.e4.tools.emf.ui.internal.common.component; + +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +public class DefaultEditor extends AbstractComponentEditor { + + @Override + public Image getImage(Object element, Display display) { + // no image + return null; + } + + @Override + public String getLabel(Object element) { + return element.getClass().getInterfaces()[0].getSimpleName() + " " + Messages.Special_UnknownElement; //$NON-NLS-1$ + } + + @Override + public String getDetailLabel(Object element) { + return Messages.Special_UnknownElement_Detail; + } + + @Override + public String getDescription(Object element) { + return null; + } + + @Override + protected Composite doGetEditor(Composite parent, Object object) { + return new Composite(parent, SWT.NONE); + } + + @Override + public IObservableList getChildList(Object element) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VApplicationCategoriesEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VApplicationCategoriesEditor.java index 62c8d47b..9dd22f59 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VApplicationCategoriesEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VApplicationCategoriesEditor.java @@ -78,7 +78,7 @@ public class VApplicationCategoriesEditor extends AbstractComponentEditor { } protected void handleImport() { - ModelImportWizard wizard = new ModelImportWizard(MCategory.class, getEditingDomain()); + ModelImportWizard wizard = new ModelImportWizard(MCategory.class, this); WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard); if (wizardDialog.open() == WizardDialog.OK) { MCategory[] elements = (MCategory[]) wizard.getElements(MCategory.class); diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VCommandEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VCommandEditor.java index 9ea93a7c..c57f5315 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VCommandEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VCommandEditor.java @@ -243,7 +243,7 @@ public class VCommandEditor extends AbstractComponentEditor { } protected void handleImport() { - ModelImportWizard wizard = new ModelImportWizard(MCommand.class, getEditingDomain()); + ModelImportWizard wizard = new ModelImportWizard(MCommand.class, this); WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard); if (wizardDialog.open() == WizardDialog.OK) { MCommand[] elements = (MCommand[]) wizard.getElements(MCommand.class); diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java index 261646bc..f85a8147 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java @@ -67,7 +67,7 @@ public class ModelImportPage1 extends WizardPage { RegistryStruct input = (RegistryStruct) inputElement; - return RegistryUtil.getExtensions(registry, input); + return RegistryUtil.getExtensions(registry, input, wizard.isLiveModel()); } public void dispose() { @@ -79,7 +79,7 @@ public class ModelImportPage1 extends WizardPage { private class ComboContentProvider implements IStructuredContentProvider { public Object[] getElements(Object inputElement) { - return RegistryUtil.getProvidingBundles(registry, wizard.getExtensionPoint()); + return RegistryUtil.getProvidingBundles(registry, wizard.getExtensionPoint(), wizard.isLiveModel()); } public void dispose() { diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportWizard.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportWizard.java index 505f4755..b4acc1ce 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportWizard.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportWizard.java @@ -13,8 +13,9 @@ package org.eclipse.e4.tools.emf.ui.internal.imp; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor; +import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplicationElement; -import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.jface.wizard.Wizard; public class ModelImportWizard extends Wizard { @@ -23,11 +24,14 @@ public class ModelImportWizard extends Wizard { private ModelImportPage1 page1; - private EditingDomain editingDomain; + private MApplication application; - public ModelImportWizard(Class<? extends MApplicationElement> applicationElement, EditingDomain editingDomain) { + private AbstractComponentEditor editor; + + public ModelImportWizard(Class<? extends MApplicationElement> applicationElement, AbstractComponentEditor editor) { this.applicationElement = applicationElement; - this.editingDomain = editingDomain; + this.editor = editor; + this.application = (MApplication) editor.getMaster().getValue(); setWindowTitle("Model Command Import Wizard"); Assert.isNotNull(RegistryUtil.getStruct(applicationElement), "Unknown Element: " + applicationElement.getClass().getName()); } @@ -92,6 +96,19 @@ public class ModelImportWizard extends Wizard { * @return */ public MApplicationElement[] getElements(Class<? extends MApplicationElement> type) { - return RegistryUtil.getModelElements(type, editingDomain, page1.getConfigurationElements()); + return RegistryUtil.getModelElements(type, application, page1.getConfigurationElements()); + } + + public AbstractComponentEditor getEditor() { + return editor; + } + + /** + * Returns if this is a live model. + * + * @return true or false + */ + public boolean isLiveModel() { + return !editor.getEditor().isLiveModel(); } } diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryUtil.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryUtil.java index b24eca53..a02739ab 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryUtil.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryUtil.java @@ -13,45 +13,48 @@ package org.eclipse.e4.tools.emf.ui.internal.imp; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.e4.tools.emf.ui.common.IExtensionLookup; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplicationElement; import org.eclipse.e4.ui.model.application.commands.MCategory; import org.eclipse.e4.ui.model.application.commands.MCommand; import org.eclipse.e4.ui.model.application.commands.MCommandsFactory; -import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.pde.core.plugin.IPluginModelBase; -import org.eclipse.pde.core.plugin.PluginRegistry; -import org.eclipse.pde.internal.core.PDEExtensionRegistry; +import org.eclipse.e4.ui.workbench.UIEvents.ApplicationElement; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; public class RegistryUtil { /** * * @param t - * @param editingDomain + * @param application * @param elements * @return */ - public static MApplicationElement[] getModelElements(Class<? extends MApplicationElement> t, EditingDomain editingDomain, IConfigurationElement... elements) { + public static MApplicationElement[] getModelElements(Class<? extends MApplicationElement> t, MApplication application, IConfigurationElement... elements) { Assert.isNotNull(t); Assert.isNotNull(elements); Assert.isTrue(elements.length > 0); if (t.equals(MCommand.class)) { - return getCommands(elements, editingDomain); + return getCommands(elements, application); } else if (t.equals(MCategory.class)) { return getCategories(elements); } return new MApplicationElement[0]; } - private static MCommand[] getCommands(IConfigurationElement[] elements, EditingDomain editingDomain) { + private static MCommand[] getCommands(IConfigurationElement[] elements, MApplication application) { ArrayList<MCommand> result = new ArrayList<MCommand>(); @@ -65,9 +68,8 @@ public class RegistryUtil { command.setElementId(element.getAttribute("id")); String catId = element.getAttribute("categoryId"); - if (catId != null || catId.trim().length() == 0) { - MApplication app = (MApplication) editingDomain.getResourceSet().getResources().get(0).getContents().get(0); - List<MCategory> categories = app.getCategories(); + if (catId != null && catId.trim().length() > 0) { + List<MCategory> categories = application.getCategories(); for (MCategory category : categories) { if (category.getElementId().equals(catId)) { command.setCategory(category); @@ -109,13 +111,17 @@ public class RegistryUtil { * @param extensionPoint * @return */ - public static String[] getProvidingBundles(IExtensionRegistry registry, String extensionPoint) { + public static String[] getProvidingBundles(IExtensionRegistry registry, String extensionPoint, boolean isLive) { + + IExtensionLookup service = getService(IExtensionLookup.class, null); + + if (service == null) { + return new String[] { "No " + IExtensionLookup.class.getName() + " service found." }; + } - IPluginModelBase[] models = PluginRegistry.getWorkspaceModels(); - PDEExtensionRegistry reg = new PDEExtensionRegistry(models); ArrayList<String> result = new ArrayList<String>(); - IExtension[] extensions = reg.findExtensions(extensionPoint, true); + IExtension[] extensions = service.findExtensions(extensionPoint, isLive); for (IExtension extension : extensions) { IConfigurationElement[] elements = extension.getConfigurationElements(); for (IConfigurationElement element : elements) { @@ -133,21 +139,20 @@ public class RegistryUtil { /** * * @param registry - * @param MApplicationElement + * @param struct * @return the array of {@link IConfigurationElement} objects that meets the * passed criteria. */ - public static IConfigurationElement[] getExtensions(IExtensionRegistry registry, RegistryStruct struct) { + public static IConfigurationElement[] getExtensions(IExtensionRegistry registry, RegistryStruct struct, boolean isLive) { - if (struct == null) { + IExtensionLookup service = getService(IExtensionLookup.class, null); + if (struct == null || service == null) { return new IConfigurationElement[0]; } - IPluginModelBase[] models = PluginRegistry.getWorkspaceModels(); - PDEExtensionRegistry reg = new PDEExtensionRegistry(models); ArrayList<IConfigurationElement> result = new ArrayList<IConfigurationElement>(); - IExtension[] extensions = reg.findExtensions(struct.getExtensionPoint(), true); + IExtension[] extensions = service.findExtensions(struct.getExtensionPoint(), isLive); for (IExtension extension : extensions) { IConfigurationElement[] elements = extension.getConfigurationElements(); for (IConfigurationElement element : elements) { @@ -162,6 +167,14 @@ public class RegistryUtil { return result.toArray(new IConfigurationElement[0]); } + /** + * This will return a structure that contains the registry information we + * are looking for. + * + * @param applicationElement + * @return the structure that matches the extension registry to the passed + * {@link ApplicationElement} + */ public static RegistryStruct getStruct(Class<? extends MApplicationElement> applicationElement) { if (applicationElement == MCommand.class) @@ -173,4 +186,18 @@ public class RegistryUtil { return null; } + private static <T> T getService(Class<T> clazz, String filter) { + + try { + BundleContext context = FrameworkUtil.getBundle(RegistryUtil.class).getBundleContext(); + Collection<ServiceReference<T>> references; + references = context.getServiceReferences(clazz, filter); + for (ServiceReference<T> reference : references) { + return context.getService(reference); + } + } catch (InvalidSyntaxException e) { + // FIXME log + } + return null; + } } |