diff options
author | Wim Jongman | 2013-03-17 23:58:47 +0000 |
---|---|---|
committer | Wim Jongman | 2013-03-17 23:58:47 +0000 |
commit | ff55e2853be0606226374a4ef3f07f855ddc2877 (patch) | |
tree | 0123941c30bc6a6dc3e1bbf25e4a3dc3046581bf | |
parent | 8c49cc78f601c0c87e9297221ce583bb573c340d (diff) | |
download | org.eclipse.e4.tools-ff55e2853be0606226374a4ef3f07f855ddc2877.tar.gz org.eclipse.e4.tools-ff55e2853be0606226374a4ef3f07f855ddc2877.tar.xz org.eclipse.e4.tools-ff55e2853be0606226374a4ef3f07f855ddc2877.zip |
bug 402875: added support for views, perspectives and handlersI20130318-0745
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402875
6 files changed, 211 insertions, 7 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java index 1c50f18e..82203d48 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java @@ -623,7 +623,7 @@ public class ModelEditor { actions = virtualEditors.get(((VirtualEntry<?>) s.getFirstElement()).getId()).getActionsImport(s.getFirstElement()); if (actions.size() > 0) { - MenuManager menu = new MenuManager("Import"); + MenuManager menu = new MenuManager("Import 3x"); for (Action a : actions) { addSeparator = true; menu.add(a); diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartSashContainerEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartSashContainerEditor.java index f973855b..4d1006dc 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartSashContainerEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartSashContainerEditor.java @@ -25,10 +25,12 @@ import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor; 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.uistructure.UIViewer; +import org.eclipse.e4.tools.emf.ui.internal.imp.ModelImportWizard; import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl; import org.eclipse.e4.ui.model.application.ui.MElementContainer; import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.model.application.ui.advanced.impl.AdvancedPackageImpl; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl; import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl; @@ -56,6 +58,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; @@ -70,6 +73,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; public class PartSashContainerEditor extends AbstractComponentEditor { @@ -79,12 +83,16 @@ public class PartSashContainerEditor extends AbstractComponentEditor { private IListProperty ELEMENT_CONTAINER__CHILDREN = EMFProperties.list(UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN); private EStackLayout stackLayout; private List<Action> actions = new ArrayList<Action>(); + private List<Action> actionsImport = new ArrayList<Action>(); @Inject @Optional private IProject project; @Inject + private Shell shell; + + @Inject public PartSashContainerEditor() { super(); } @@ -127,6 +135,15 @@ public class PartSashContainerEditor extends AbstractComponentEditor { handleAddChild(AdvancedPackageImpl.Literals.PLACEHOLDER); } }); + + // --- Import Actions --- + actionsImport.add(new Action(Messages.PartSashContainerEditor_AddPart, createImageDescriptor(ResourceProvider.IMG_Part)) { + @Override + public void run() { + handleImportChild(BasicPackageImpl.Literals.PART); + } + }); + } @Override @@ -420,6 +437,10 @@ public class PartSashContainerEditor extends AbstractComponentEditor { protected void handleAddChild(EClass eClass) { EObject eObject = EcoreUtil.create(eClass); + addToModel(eObject); + } + + private void addToModel(EObject eObject) { setElementId(eObject); Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, eObject); @@ -430,10 +451,31 @@ public class PartSashContainerEditor extends AbstractComponentEditor { } } + protected void handleImportChild(EClass eClass) { + + if (eClass == BasicPackageImpl.Literals.PART) { + ModelImportWizard wizard = new ModelImportWizard(MPart.class, this); + WizardDialog wizardDialog = new WizardDialog(shell, wizard); + if (wizardDialog.open() == WizardDialog.OK) { + MPart[] parts = (MPart[]) wizard.getElements(MPart.class); + for (MPart 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/common/component/PerspectiveStackEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveStackEditor.java index 701b8e28..a9d69634 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveStackEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PerspectiveStackEditor.java @@ -25,6 +25,7 @@ import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor; 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.uistructure.UIViewer; +import org.eclipse.e4.tools.emf.ui.internal.imp.ModelImportWizard; import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl; import org.eclipse.e4.ui.model.application.ui.MElementContainer; import org.eclipse.e4.ui.model.application.ui.MUIElement; @@ -48,6 +49,7 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; @@ -61,6 +63,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; public class PerspectiveStackEditor extends AbstractComponentEditor { private Composite composite; @@ -69,6 +72,7 @@ public class PerspectiveStackEditor extends AbstractComponentEditor { private IListProperty ELEMENT_CONTAINER__CHILDREN = EMFProperties.list(UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN); private EStackLayout stackLayout; private List<Action> actions = new ArrayList<Action>(); + private List<Action> actionsImport = new ArrayList<Action>(); @Inject @Optional @@ -79,6 +83,9 @@ public class PerspectiveStackEditor extends AbstractComponentEditor { super(); } + @Inject + Shell shell; + @PostConstruct void init() { actions.add(new Action(Messages.PerspectiveStackEditor_AddPerspective, createImageDescriptor(ResourceProvider.IMG_Perspective)) { @@ -87,6 +94,14 @@ public class PerspectiveStackEditor extends AbstractComponentEditor { handleAddPerspective(); } }); + + // --- import --- + actionsImport.add(new Action(Messages.PerspectiveStackEditor_AddPerspective, createImageDescriptor(ResourceProvider.IMG_Perspective)) { + @Override + public void run() { + handleImportPerspective(); + } + }); } @Override @@ -323,13 +338,26 @@ public class PerspectiveStackEditor extends AbstractComponentEditor { protected void handleAddPerspective() { MPerspective eObject = MAdvancedFactory.INSTANCE.createPerspective(); - setElementId(eObject); + addToModel(eObject); + } - Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, eObject); + protected void handleImportPerspective() { + ModelImportWizard wizard = new ModelImportWizard(MPerspective.class, this); + WizardDialog wizardDialog = new WizardDialog(shell, wizard); + if (wizardDialog.open() == WizardDialog.OK) { + MPerspective[] elements = (MPerspective[]) wizard.getElements(MPerspective.class); + for (MPerspective category : elements) { + addToModel(category); + } + } + } + private void addToModel(MPerspective perspective) { + setElementId(perspective); + Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, perspective); if (cmd.canExecute()) { getEditingDomain().getCommandStack().execute(cmd); - getEditor().setSelection(eObject); + getEditor().setSelection(perspective); } } @@ -339,4 +367,11 @@ public class PerspectiveStackEditor extends AbstractComponentEditor { 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/common/component/virtual/VHandlerEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VHandlerEditor.java index 88994796..a612c95f 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VHandlerEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VHandlerEditor.java @@ -20,6 +20,7 @@ import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor; 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.imp.ModelImportWizard; import org.eclipse.e4.ui.model.application.commands.MCommandsFactory; import org.eclipse.e4.ui.model.application.commands.MHandler; import org.eclipse.e4.ui.model.application.commands.MHandlerContainer; @@ -34,6 +35,7 @@ import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; @@ -51,6 +53,7 @@ public class VHandlerEditor extends AbstractComponentEditor { private EMFDataBindingContext context; private TableViewer viewer; private List<Action> actions = new ArrayList<Action>(); + private List<Action> actionsImport = new ArrayList<Action>(); @Inject public VHandlerEditor() { @@ -65,6 +68,14 @@ public class VHandlerEditor extends AbstractComponentEditor { handleAdd(); } }); + + // -- import -- + actionsImport.add(new Action(Messages.VHandlerEditor_AddHandler, createImageDescriptor(ResourceProvider.IMG_Handler)) { + @Override + public void run() { + handleImport(); + } + }); } @Override @@ -220,20 +231,40 @@ public class VHandlerEditor extends AbstractComponentEditor { protected void handleAdd() { MHandler handler = MCommandsFactory.INSTANCE.createHandler(); - setElementId(handler); + addToModel(handler); + } + private void addToModel(MHandler handler) { + setElementId(handler); Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.HANDLER_CONTAINER__HANDLERS, handler); - if (cmd.canExecute()) { getEditingDomain().getCommandStack().execute(cmd); getEditor().setSelection(handler); } } + protected void handleImport() { + ModelImportWizard wizard = new ModelImportWizard(MHandler.class, this); + WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard); + if (wizardDialog.open() == WizardDialog.OK) { + MHandler[] elements = (MHandler[]) wizard.getElements(MHandler.class); + for (MHandler handler : elements) { + addToModel(handler); + } + } + } + @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; + } }
\ No newline at end of file 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 d22adc79..85e994a4 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 @@ -31,7 +31,7 @@ public class ModelImportWizard extends Wizard { public ModelImportWizard(Class<? extends MApplicationElement> applicationElement, AbstractComponentEditor editor) { this.applicationElement = applicationElement; this.editor = editor; - this.application = (MApplication) editor.getMaster().getValue(); + this.application = (MApplication) editor.getEditor().getModelProvider().getRoot().get(0); setWindowTitle("Model Command Import Wizard"); Assert.isNotNull(RegistryUtil.getStruct(applicationElement), "Unknown Element: " + applicationElement.getClass().getName()); } 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 a02739ab..c4c7cf32 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 @@ -25,7 +25,14 @@ 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.e4.ui.model.application.commands.MHandler; +import org.eclipse.e4.ui.model.application.ui.advanced.MAdvancedFactory; +import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; +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.MMenuFactory; import org.eclipse.e4.ui.workbench.UIEvents.ApplicationElement; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; @@ -50,6 +57,12 @@ public class RegistryUtil { return getCommands(elements, application); } else if (t.equals(MCategory.class)) { return getCategories(elements); + } else if (t.equals(MPerspective.class)) { + return getPerspectives(elements); + } else if (t.equals(MPart.class)) { + return getParts(elements); + } else if (t.equals(MHandler.class)) { + return getHandlers(elements, application); } return new MApplicationElement[0]; } @@ -84,6 +97,25 @@ public class RegistryUtil { return result.toArray(new MCommand[0]); } + private static MPerspective[] getPerspectives(IConfigurationElement[] elements) { + + ArrayList<MPerspective> result = new ArrayList<MPerspective>(); + + MAdvancedFactory factory = MAdvancedFactory.INSTANCE; + + for (IConfigurationElement element : elements) { + MPerspective perspective = factory.createPerspective(); + perspective.setLabel(element.getAttribute("name")); + perspective.setIconURI(getIconURI(element, "icon")); + perspective.setElementId(element.getAttribute("id")); + perspective.setToBeRendered(true); + perspective.setVisible(true); + result.add((MPerspective) perspective); + } + + return result.toArray(new MPerspective[0]); + } + private static MCategory[] getCategories(IConfigurationElement[] elements) { ArrayList<MCategory> result = new ArrayList<MCategory>(); @@ -103,6 +135,58 @@ public class RegistryUtil { return result.toArray(new MCategory[0]); } + private static MPart[] getParts(IConfigurationElement[] elements) { + + ArrayList<MPart> result = new ArrayList<MPart>(); + for (IConfigurationElement element : elements) { + MPart part = (MPart) EcoreUtil.create(BasicPackageImpl.Literals.PART); + part.setElementId(element.getAttribute("id")); + part.setLabel(element.getAttribute("name")); + part.setIconURI(getIconURI(element, "icon")); + part.setContributionURI(getContributionURI(element, "class")); + part.setToBeRendered(true); + part.setVisible(true); + part.setToolbar(MMenuFactory.INSTANCE.createToolBar()); + part.setCloseable(true); + result.add(part); + } + + return result.toArray(new MPart[0]); + } + + private static MHandler[] getHandlers(IConfigurationElement[] elements, MApplication application) { + + ArrayList<MHandler> result = new ArrayList<MHandler>(); + for (IConfigurationElement element : elements) { + MHandler hand = (MHandler) MCommandsFactory.INSTANCE.createHandler(); + hand.setElementId(element.getAttribute("id")); + hand.setContributionURI(getContributionURI(element, "class")); + + String cmdId = element.getAttribute("commandId"); + + if (cmdId != null && cmdId.trim().length() > 0) { + List<MCommand> categories = application.getCommands(); + for (MCommand command : categories) { + if (command.getElementId().equals(cmdId)) { + hand.setCommand(command); + break; + } + } + } + result.add(hand); + } + return result.toArray(new MHandler[0]); + } + + private static String getIconURI(IConfigurationElement element, String attribute) { + // FIXME don't assume local icon + return "platform:/plugin/" + element.getContributor().getName() + "/" + element.getAttribute(attribute); + } + + private static String getContributionURI(IConfigurationElement element, String attribute) { + return "bundleclass://" + element.getContributor().getName() + "/" + element.getAttribute(attribute); + } + /** * Returns a list of bundle id's that have extension to the passed extension * point. @@ -183,6 +267,18 @@ public class RegistryUtil { else if (applicationElement == MCategory.class) return new RegistryStruct("", "org.eclipse.ui.commands", "category", "name"); + else if (applicationElement == MPerspective.class) + return new RegistryStruct("", "org.eclipse.ui.perspectives", "perspective", "name"); + + else if (applicationElement == MPart.class) + return new RegistryStruct("", "org.eclipse.ui.views", "view", "name"); + + else if (applicationElement == MHandler.class) + return new RegistryStruct("", "org.eclipse.ui.handlers", "handler", "commandId"); + + else if (applicationElement == MPart.class) + return new RegistryStruct("", "org.eclipse.ui.views", "view", "name"); + return null; } |