diff options
author | Wim Jongman | 2013-03-22 22:43:48 +0000 |
---|---|---|
committer | Wim Jongman | 2013-03-22 22:43:48 +0000 |
commit | 42ec396c806cd832559faf94dbcbc4d3e9f29190 (patch) | |
tree | a685487d1d416f540edea007ff6e4061bee199ff | |
parent | 48bb1cfd8db1e0b512c719b3e459b9e565bdf806 (diff) | |
download | eclipse.platform.ui.tools-42ec396c806cd832559faf94dbcbc4d3e9f29190.tar.gz eclipse.platform.ui.tools-42ec396c806cd832559faf94dbcbc4d3e9f29190.tar.xz eclipse.platform.ui.tools-42ec396c806cd832559faf94dbcbc4d3e9f29190.zip |
bug 402875: Importing model elements from legacy RCP
Added preview functionality to add compatibility views to shared area
and part descriptor. This to experiment with mixed mode.
All imported part and partdescriptors now also get a toolbar and
viewmenu with the same id.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402875
3 files changed, 156 insertions, 21 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VPartDescriptor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VPartDescriptor.java index 22a9bd94..b60c34f4 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VPartDescriptor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VPartDescriptor.java @@ -75,13 +75,20 @@ public class VPartDescriptor extends AbstractComponentEditor { actionsImport.add(new Action("Views", createImageDescriptor(ResourceProvider.IMG_Part)) { @Override public void run() { - handleImportChild(BasicPackageImpl.Literals.PART_DESCRIPTOR, RegistryUtil.HINT_VIEW); + handleImport(BasicPackageImpl.Literals.PART_DESCRIPTOR, RegistryUtil.HINT_VIEW); } }); actionsImport.add(new Action("Editors", createImageDescriptor(ResourceProvider.IMG_Part)) { @Override public void run() { - handleImportChild(BasicPackageImpl.Literals.PART_DESCRIPTOR, RegistryUtil.HINT_EDITOR); + handleImport(BasicPackageImpl.Literals.PART_DESCRIPTOR, RegistryUtil.HINT_EDITOR); + } + }); + + actionsImport.add(new Action("View as CompatibilityView", createImageDescriptor(ResourceProvider.IMG_Part)) { + @Override + public void run() { + handleImport(BasicPackageImpl.Literals.PART_DESCRIPTOR, RegistryUtil.HINT_COMPAT_VIEW); } }); } @@ -253,7 +260,7 @@ public class VPartDescriptor extends AbstractComponentEditor { } } - protected void handleImportChild(EClass eClass, String hint) { + protected void handleImport(EClass eClass, String hint) { if (eClass == BasicPackageImpl.Literals.PART_DESCRIPTOR) { ModelImportWizard wizard = new ModelImportWizard(MPartDescriptor.class, this, hint); diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VWindowSharedElementsEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VWindowSharedElementsEditor.java index 0681befa..253b0617 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VWindowSharedElementsEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VWindowSharedElementsEditor.java @@ -23,7 +23,11 @@ import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider; import org.eclipse.e4.tools.emf.ui.internal.common.ComponentLabelProvider; import org.eclipse.e4.tools.emf.ui.internal.common.VirtualEntry; import org.eclipse.e4.tools.emf.ui.internal.common.uistructure.ViewerElement; +import org.eclipse.e4.tools.emf.ui.internal.imp.ModelImportWizard; +import org.eclipse.e4.tools.emf.ui.internal.imp.RegistryUtil; import org.eclipse.e4.ui.model.application.ui.advanced.impl.AdvancedPackageImpl; +import org.eclipse.e4.ui.model.application.ui.basic.MInputPart; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.databinding.EMFDataBindingContext; @@ -42,6 +46,7 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; @@ -56,6 +61,7 @@ public class VWindowSharedElementsEditor extends AbstractComponentEditor { private EMFDataBindingContext context; private StructuredViewer viewer; private List<Action> actions = new ArrayList<Action>(); + private List<Action> actionsImport = new ArrayList<Action>(); @Inject IEclipseContext eclipseContext; @@ -101,6 +107,28 @@ public class VWindowSharedElementsEditor extends AbstractComponentEditor { handleAdd(AdvancedPackageImpl.Literals.AREA); } }); + + // -- IMPORT ACTIONS -- + actionsImport.add(new Action("Views", createImageDescriptor(ResourceProvider.IMG_Part)) { + @Override + public void run() { + handleImport(BasicPackageImpl.Literals.PART, RegistryUtil.HINT_VIEW); + } + }); + + actionsImport.add(new Action("Editors", createImageDescriptor(ResourceProvider.IMG_Part)) { + @Override + public void run() { + handleImport(BasicPackageImpl.Literals.INPUT_PART, RegistryUtil.HINT_EDITOR); + } + }); + + actionsImport.add(new Action("View as CompatibilityView", createImageDescriptor(ResourceProvider.IMG_Part)) { + @Override + public void run() { + handleImport(BasicPackageImpl.Literals.PART, RegistryUtil.HINT_COMPAT_VIEW); + } + }); } @Override @@ -248,6 +276,10 @@ public class VWindowSharedElementsEditor extends AbstractComponentEditor { protected void handleAdd(EClass eClass) { EObject eObject = EcoreUtil.create(eClass); + addToModel(eObject); + } + + private void addToModel(EObject eObject) { setElementId(eObject); Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), BasicPackageImpl.Literals.WINDOW__SHARED_ELEMENTS, eObject); @@ -258,10 +290,40 @@ public class VWindowSharedElementsEditor extends AbstractComponentEditor { } } + protected void handleImport(EClass eClass, String hint) { + if (eClass == BasicPackageImpl.Literals.PART) { + ModelImportWizard wizard = new ModelImportWizard(MPart.class, this, hint); + WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard); + if (wizardDialog.open() == WizardDialog.OK) { + MPart[] parts = (MPart[]) wizard.getElements(MPart.class); + for (MPart part : parts) { + addToModel((EObject) part); + } + } + } + if (eClass == BasicPackageImpl.Literals.INPUT_PART) { + ModelImportWizard wizard = new ModelImportWizard(MInputPart.class, this, hint); + WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard); + if (wizardDialog.open() == WizardDialog.OK) { + MInputPart[] parts = (MInputPart[]) wizard.getElements(MInputPart.class); + for (MInputPart part : parts) { + addToModel((EObject) part); + } + } + } + } + @Override public List<Action> getActions(Object element) { ArrayList<Action> l = new ArrayList<Action>(super.getActions(element)); l.addAll(actions); return l; } + + @Override + public List<Action> getActionsImport(Object element) { + ArrayList<Action> l = new ArrayList<Action>(super.getActionsImport(element)); + l.addAll(actionsImport); + return l; + } } 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 7e35e8ff..a8d1b1a9 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 @@ -32,7 +32,9 @@ import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; import org.eclipse.e4.ui.model.application.ui.basic.MInputPart; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl; +import org.eclipse.e4.ui.model.application.ui.menu.MMenu; import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; +import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; import org.eclipse.e4.ui.workbench.UIEvents.ApplicationElement; import org.eclipse.emf.ecore.util.EcoreUtil; import org.osgi.framework.BundleContext; @@ -44,6 +46,7 @@ public class RegistryUtil { public final static String HINT_VIEW = "view"; public final static String HINT_EDITOR = "editor"; + public final static String HINT_COMPAT_VIEW = "compatibilityView"; /** * @@ -64,6 +67,8 @@ public class RegistryUtil { return getCategories(elements); } else if (t.equals(MPerspective.class)) { return getPerspectives(elements); + } else if (t.equals(MPart.class) && HINT_COMPAT_VIEW.equals(hint)) { + return getViewsAsCompatibilityViews(elements); } else if (t.equals(MPart.class)) { return getViews(elements); } else if (t.equals(MInputPart.class)) { @@ -74,6 +79,8 @@ public class RegistryUtil { return getEditorPartDescriptors(elements); } else if (t.equals(MPartDescriptor.class) && HINT_VIEW.equals(hint)) { return getViewPartDescriptors(elements); + } else if (t.equals(MPartDescriptor.class) && HINT_COMPAT_VIEW.equals(hint)) { + return getPartDescriptorsAsCompatibilyViews(elements); } return new MApplicationElement[0]; } @@ -157,32 +164,74 @@ public class RegistryUtil { part.setContributionURI(getContributionURI(element, "class")); part.setToBeRendered(true); part.setVisible(true); - part.setToolbar(MMenuFactory.INSTANCE.createToolBar()); + part.setToolbar(createToolBar(part)); + part.getMenus().add(createViewMenu(part)); part.setCloseable(true); + part.getTags().add("View"); + if (element.getAttribute("category") != null) { + part.getTags().add("categoryTag:" + element.getAttribute("category")); + } + result.add(part); } return result.toArray(new MPart[0]); } + private static MToolBar createToolBar(MPart part) { + MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar(); + toolBar.setElementId(part.getElementId()); + return toolBar; + } + + private static MMenu createViewMenu(MPart part) { + MMenu menu = MMenuFactory.INSTANCE.createMenu(); + menu.setElementId(part.getElementId()); + menu.getTags().add("ViewMenu"); + return menu; + } + + private static MPart[] getViewsAsCompatibilityViews(IConfigurationElement[] elements) { + ArrayList<MPart> result = new ArrayList<MPart>(); + MPart[] parts = getViews(elements); + for (MPart part : parts) { + part.setContributionURI("bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView"); + result.add(part); + } + return result.toArray(new MPart[0]); + } + + private static MPartDescriptor[] getPartDescriptorsAsCompatibilyViews(IConfigurationElement[] elements) { + ArrayList<MPartDescriptor> result = new ArrayList<MPartDescriptor>(); + MPartDescriptor[] parts = getViewPartDescriptors(elements); + for (MPartDescriptor part : parts) { + part.setContributionURI("bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView"); + result.add(part); + } + return result.toArray(new MPartDescriptor[0]); + } + private static MInputPart[] getEditors(IConfigurationElement[] elements) { ArrayList<MInputPart> result = new ArrayList<MInputPart>(); for (IConfigurationElement element : elements) { - MInputPart part = (MInputPart) EcoreUtil.create(BasicPackageImpl.Literals.INPUT_PART); - part.setElementId(element.getAttribute("id")); - part.setLabel(element.getAttribute("name")); - part.setIconURI(getIconURI(element, "icon")); - if (element.getAttribute("class") != null) { - part.setContributionURI(getContributionURI(element, "class")); - } else { - part.setContributionURI(getContributionURI(element, "launcher")); + if ("editor".equals(element.getName())) /* Sanity Check */{ + MInputPart part = (MInputPart) EcoreUtil.create(BasicPackageImpl.Literals.INPUT_PART); + part.setElementId(element.getAttribute("id")); + part.setLabel(element.getAttribute("name")); + part.setIconURI(getIconURI(element, "icon")); + if (element.getAttribute("class") != null) { + part.setContributionURI(getContributionURI(element, "class")); + } else { + part.setContributionURI(getContributionURI(element, "launcher")); + } + part.setToBeRendered(true); + part.setVisible(true); + part.setToolbar(createToolBar(part)); + part.getMenus().add(createViewMenu(part)); + part.setCloseable(true); + result.add(part); } - part.setToBeRendered(true); - part.setVisible(true); - part.setToolbar(MMenuFactory.INSTANCE.createToolBar()); - part.setCloseable(true); - result.add(part); } return result.toArray(new MInputPart[0]); @@ -203,7 +252,16 @@ public class RegistryUtil { } part.setDirtyable(true); part.setAllowMultiple(true); - part.setToolbar(MMenuFactory.INSTANCE.createToolBar()); + + MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar(); + toolBar.setElementId(part.getElementId()); + part.setToolbar(toolBar); + + MMenu menu = MMenuFactory.INSTANCE.createMenu(); + menu.setElementId(part.getElementId()); + menu.getTags().add("ViewMenu"); + part.getMenus().add(menu); + part.setCloseable(true); result.add(part); } @@ -219,8 +277,16 @@ public class RegistryUtil { part.setElementId(element.getAttribute("id")); part.setLabel(element.getAttribute("name")); part.setIconURI(getIconURI(element, "icon")); - part.setContributionURI(getContributionURI(element, "class")); - part.setToolbar(MMenuFactory.INSTANCE.createToolBar()); + + MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar(); + toolBar.setElementId(part.getElementId()); + part.setToolbar(toolBar); + + MMenu menu = MMenuFactory.INSTANCE.createMenu(); + menu.setElementId(part.getElementId()); + menu.getTags().add("ViewMenu"); + part.getMenus().add(menu); + part.setCloseable(true); result.add(part); } @@ -367,7 +433,7 @@ public class RegistryUtil { else if (applicationElement == MPartDescriptor.class) { if (hint == HINT_EDITOR) return new RegistryStruct("", "org.eclipse.ui.editors", "editor", "name"); - if (hint == HINT_VIEW) + if (hint == HINT_VIEW || hint == HINT_COMPAT_VIEW) return new RegistryStruct("", "org.eclipse.ui.views", "view", "name"); } |