Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2013-03-18 21:44:53 +0000
committerWim Jongman2013-03-18 21:44:53 +0000
commitd94be04547b2f6c757a9b2accea934f3ce6c0467 (patch)
treebcbaebd6b7b7f0143b6b96c2766768ab09819485
parent279c039e46a5bd24a18804a22ef407c41f3a579a (diff)
downloadorg.eclipse.e4.tools-d94be04547b2f6c757a9b2accea934f3ce6c0467.tar.gz
org.eclipse.e4.tools-d94be04547b2f6c757a9b2accea934f3ce6c0467.tar.xz
org.eclipse.e4.tools-d94be04547b2f6c757a9b2accea934f3ce6c0467.zip
Bug 402875 Added support for editors
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402875
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java2
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartSashContainerEditor.java27
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartStackEditor.java56
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VPartDescriptor.java52
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java14
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportWizard.java28
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryUtil.java104
7 files changed, 259 insertions, 24 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 82203d48..4c933c0a 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
@@ -695,7 +695,7 @@ public class ModelEditor {
if (actions.size() > 0) {
// TODO WIM - extract nls
- 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 4d1006dc..de1733f5 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
@@ -26,10 +26,12 @@ 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.tools.emf.ui.internal.imp.RegistryUtil;
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.MInputPart;
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;
@@ -137,10 +139,16 @@ public class PartSashContainerEditor extends AbstractComponentEditor {
});
// --- Import Actions ---
- actionsImport.add(new Action(Messages.PartSashContainerEditor_AddPart, createImageDescriptor(ResourceProvider.IMG_Part)) {
+ actionsImport.add(new Action("Views", createImageDescriptor(ResourceProvider.IMG_Part)) {
@Override
public void run() {
- handleImportChild(BasicPackageImpl.Literals.PART);
+ handleImportChild(BasicPackageImpl.Literals.PART, RegistryUtil.HINT_VIEW);
+ }
+ });
+ actionsImport.add(new Action("Editors", createImageDescriptor(ResourceProvider.IMG_Part)) {
+ @Override
+ public void run() {
+ handleImportChild(BasicPackageImpl.Literals.INPUT_PART, RegistryUtil.HINT_EDITOR);
}
});
@@ -451,10 +459,10 @@ public class PartSashContainerEditor extends AbstractComponentEditor {
}
}
- protected void handleImportChild(EClass eClass) {
+ protected void handleImportChild(EClass eClass, String hint) {
if (eClass == BasicPackageImpl.Literals.PART) {
- ModelImportWizard wizard = new ModelImportWizard(MPart.class, this);
+ ModelImportWizard wizard = new ModelImportWizard(MPart.class, this, hint);
WizardDialog wizardDialog = new WizardDialog(shell, wizard);
if (wizardDialog.open() == WizardDialog.OK) {
MPart[] parts = (MPart[]) wizard.getElements(MPart.class);
@@ -463,6 +471,17 @@ public class PartSashContainerEditor extends AbstractComponentEditor {
}
}
}
+
+ if (eClass == BasicPackageImpl.Literals.INPUT_PART) {
+ ModelImportWizard wizard = new ModelImportWizard(MInputPart.class, this);
+ WizardDialog wizardDialog = new WizardDialog(shell, wizard);
+ if (wizardDialog.open() == WizardDialog.OK) {
+ MInputPart[] parts = (MInputPart[]) wizard.getElements(MInputPart.class);
+ for (MInputPart part : parts) {
+ addToModel((EObject) part);
+ }
+ }
+ }
}
@Override
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartStackEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartStackEditor.java
index 40f22b5a..eea40876 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartStackEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartStackEditor.java
@@ -25,10 +25,13 @@ 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.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.impl.UiPackageImpl;
import org.eclipse.emf.common.command.Command;
@@ -53,6 +56,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;
@@ -77,6 +81,7 @@ public class PartStackEditor extends AbstractComponentEditor {
private IListProperty ELEMENT_CONTAINER__CHILDREN = EMFProperties.list(UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN);
private StackLayout stackLayout;
private List<Action> actions = new ArrayList<Action>();
+ private List<Action> actionsImport = new ArrayList<Action>();
@Inject
@Optional
@@ -108,6 +113,21 @@ public class PartStackEditor extends AbstractComponentEditor {
handleAddChild(AdvancedPackageImpl.Literals.PLACEHOLDER);
}
});
+
+ // --- Import Actions ---
+ actionsImport.add(new Action("Views", createImageDescriptor(ResourceProvider.IMG_Part)) {
+ @Override
+ public void run() {
+ handleImportChild(BasicPackageImpl.Literals.PART);
+ }
+ });
+ actionsImport.add(new Action("Editors", createImageDescriptor(ResourceProvider.IMG_Part)) {
+ @Override
+ public void run() {
+ handleImportChild(BasicPackageImpl.Literals.INPUT_PART);
+ }
+ });
+
}
@Override
@@ -365,6 +385,10 @@ public class PartStackEditor 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);
@@ -375,10 +399,42 @@ public class PartStackEditor extends AbstractComponentEditor {
}
}
+ protected void handleImportChild(EClass eClass) {
+
+ if (eClass == BasicPackageImpl.Literals.PART) {
+ ModelImportWizard wizard = new ModelImportWizard(MPart.class, this);
+ 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);
+ 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/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 be122480..22a9bd94 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
@@ -20,12 +20,15 @@ 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.tools.emf.ui.internal.imp.RegistryUtil;
import org.eclipse.e4.ui.model.application.descriptor.basic.MBasicFactory;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptorContainer;
import org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.databinding.EMFDataBindingContext;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.command.MoveCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
@@ -34,6 +37,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 +55,7 @@ public class VPartDescriptor extends AbstractComponentEditor {
private EMFDataBindingContext context;
private TableViewer viewer;
private List<Action> actions = new ArrayList<Action>();
+ private List<Action> actionsImport = new ArrayList<Action>();
@Inject
public VPartDescriptor() {
@@ -65,6 +70,20 @@ public class VPartDescriptor extends AbstractComponentEditor {
handleAdd();
}
});
+
+ // --- Import Actions ---
+ actionsImport.add(new Action("Views", createImageDescriptor(ResourceProvider.IMG_Part)) {
+ @Override
+ public void run() {
+ handleImportChild(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);
+ }
+ });
}
@Override
@@ -219,14 +238,32 @@ public class VPartDescriptor extends AbstractComponentEditor {
}
protected void handleAdd() {
- MPartDescriptor command = MBasicFactory.INSTANCE.createPartDescriptor();
- setElementId(command);
+ MPartDescriptor partDescription = MBasicFactory.INSTANCE.createPartDescriptor();
+ addToModel(partDescription);
+ }
+
+ private void addToModel(MPartDescriptor partDescription) {
+ setElementId(partDescription);
- Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), BasicPackageImpl.Literals.PART_DESCRIPTOR_CONTAINER__DESCRIPTORS, command);
+ Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), BasicPackageImpl.Literals.PART_DESCRIPTOR_CONTAINER__DESCRIPTORS, partDescription);
if (cmd.canExecute()) {
getEditingDomain().getCommandStack().execute(cmd);
- getEditor().setSelection(command);
+ getEditor().setSelection(partDescription);
+ }
+ }
+
+ protected void handleImportChild(EClass eClass, String hint) {
+
+ if (eClass == BasicPackageImpl.Literals.PART_DESCRIPTOR) {
+ ModelImportWizard wizard = new ModelImportWizard(MPartDescriptor.class, this, hint);
+ WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard);
+ if (wizardDialog.open() == WizardDialog.OK) {
+ MPartDescriptor[] parts = (MPartDescriptor[]) wizard.getElements(MPartDescriptor.class);
+ for (MPartDescriptor part : parts) {
+ addToModel(part);
+ }
+ }
}
}
@@ -236,4 +273,11 @@ public class VPartDescriptor 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/imp/ModelImportPage1.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java
index f85a8147..a3badfda 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
@@ -94,8 +94,8 @@ public class ModelImportPage1 extends WizardPage {
*/
public ModelImportPage1() {
super("wizardPage");
- setTitle("Import Commands");
- setDescription("Select plug-in and commands to import");
+ setTitle("Import ");
+ setDescription("Select plug-in and elements to import");
wizard = (ModelImportWizard) getWizard();
setPageComplete(false);
}
@@ -137,7 +137,7 @@ public class ModelImportPage1 extends WizardPage {
public void selectionChanged(SelectionChangedEvent event) {
String bundle = ((IStructuredSelection) event.getSelection()).getFirstElement().toString();
- RegistryStruct struct = RegistryUtil.getStruct(wizard.getApplicationElement());
+ RegistryStruct struct = RegistryUtil.getStruct(wizard.getApplicationElement(), wizard.getHint());
struct.setBundle(bundle);
checkboxTableViewer.setInput(struct);
@@ -159,6 +159,14 @@ public class ModelImportPage1 extends WizardPage {
@Override
public void setWizard(IWizard newWizard) {
this.wizard = (ModelImportWizard) newWizard;
+ setTitle("Import " + wizard.getApplicationElement().getSimpleName());
+
+ String hint = wizard.getHint();
+ if (hint != null && hint.length() > 0) {
+ setDescription("Select plug-in and elements (" + hint + ") to import");
+ // else already set
+ }
+
super.setWizard(newWizard);
}
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 85e994a4..b53e6ec3 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
@@ -28,12 +28,19 @@ public class ModelImportWizard extends Wizard {
private AbstractComponentEditor editor;
+ private final String hint;
+
public ModelImportWizard(Class<? extends MApplicationElement> applicationElement, AbstractComponentEditor editor) {
+ this(applicationElement, editor, "");
+ }
+
+ public ModelImportWizard(Class<? extends MApplicationElement> applicationElement, AbstractComponentEditor editor, String hint) {
this.applicationElement = applicationElement;
this.editor = editor;
+ this.hint = hint;
this.application = (MApplication) editor.getEditor().getModelProvider().getRoot().get(0);
- setWindowTitle("Model Command Import Wizard");
- Assert.isNotNull(RegistryUtil.getStruct(applicationElement), "Unknown Element: " + applicationElement.getClass().getName());
+ setWindowTitle("Model " + applicationElement.getSimpleName() + " Import Wizard");
+ Assert.isNotNull(RegistryUtil.getStruct(applicationElement, getHint()), "Unknown Element: " + applicationElement.getClass().getName());
}
@Override
@@ -64,7 +71,7 @@ public class ModelImportWizard extends Wizard {
* @see #getApplicationElement()
*/
protected String getExtensionPointName() {
- return RegistryUtil.getStruct(applicationElement).getExtensionPointName();
+ return RegistryUtil.getStruct(applicationElement, getHint()).getExtensionPointName();
}
/**
@@ -75,7 +82,7 @@ public class ModelImportWizard extends Wizard {
* @see #getApplicationElement()
*/
protected String getExtensionPoint() {
- return RegistryUtil.getStruct(applicationElement).getExtensionPoint();
+ return RegistryUtil.getStruct(applicationElement, getHint()).getExtensionPoint();
}
/**
@@ -84,7 +91,7 @@ public class ModelImportWizard extends Wizard {
* @see #MAPPING_NAME
*/
protected String getMappingName() {
- return RegistryUtil.getStruct(applicationElement).getMappingName();
+ return RegistryUtil.getStruct(applicationElement, getHint()).getMappingName();
}
/**
@@ -96,7 +103,7 @@ public class ModelImportWizard extends Wizard {
* @return
*/
public MApplicationElement[] getElements(Class<? extends MApplicationElement> type) {
- return RegistryUtil.getModelElements(type, application, page1.getConfigurationElements());
+ return RegistryUtil.getModelElements(type, getHint(), application, page1.getConfigurationElements());
}
public AbstractComponentEditor getEditor() {
@@ -111,4 +118,13 @@ public class ModelImportWizard extends Wizard {
public boolean isLiveModel() {
return editor.getEditor().isLiveModel();
}
+
+ /**
+ * Returns the hint that explains the meaning of the caller.
+ *
+ * @return
+ */
+ public String getHint() {
+ return hint;
+ }
}
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 c4c7cf32..7e35e8ff 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
@@ -26,8 +26,10 @@ 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.descriptor.basic.MPartDescriptor;
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.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.MMenuFactory;
@@ -40,6 +42,9 @@ import org.osgi.framework.ServiceReference;
public class RegistryUtil {
+ public final static String HINT_VIEW = "view";
+ public final static String HINT_EDITOR = "editor";
+
/**
*
* @param t
@@ -47,7 +52,7 @@ public class RegistryUtil {
* @param elements
* @return
*/
- public static MApplicationElement[] getModelElements(Class<? extends MApplicationElement> t, MApplication application, IConfigurationElement... elements) {
+ public static MApplicationElement[] getModelElements(Class<? extends MApplicationElement> t, String hint, MApplication application, IConfigurationElement... elements) {
Assert.isNotNull(t);
Assert.isNotNull(elements);
@@ -60,9 +65,15 @@ public class RegistryUtil {
} else if (t.equals(MPerspective.class)) {
return getPerspectives(elements);
} else if (t.equals(MPart.class)) {
- return getParts(elements);
+ return getViews(elements);
+ } else if (t.equals(MInputPart.class)) {
+ return getEditors(elements);
} else if (t.equals(MHandler.class)) {
return getHandlers(elements, application);
+ } else if (t.equals(MPartDescriptor.class) && HINT_EDITOR.equals(hint)) {
+ return getEditorPartDescriptors(elements);
+ } else if (t.equals(MPartDescriptor.class) && HINT_VIEW.equals(hint)) {
+ return getViewPartDescriptors(elements);
}
return new MApplicationElement[0];
}
@@ -135,7 +146,7 @@ public class RegistryUtil {
return result.toArray(new MCategory[0]);
}
- private static MPart[] getParts(IConfigurationElement[] elements) {
+ private static MPart[] getViews(IConfigurationElement[] elements) {
ArrayList<MPart> result = new ArrayList<MPart>();
for (IConfigurationElement element : elements) {
@@ -154,6 +165,69 @@ public class RegistryUtil {
return result.toArray(new MPart[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"));
+ }
+ part.setToBeRendered(true);
+ part.setVisible(true);
+ part.setToolbar(MMenuFactory.INSTANCE.createToolBar());
+ part.setCloseable(true);
+ result.add(part);
+ }
+
+ return result.toArray(new MInputPart[0]);
+ }
+
+ private static MPartDescriptor[] getEditorPartDescriptors(IConfigurationElement[] elements) {
+
+ ArrayList<MPartDescriptor> result = new ArrayList<MPartDescriptor>();
+ for (IConfigurationElement element : elements) {
+ MPartDescriptor part = (MPartDescriptor) EcoreUtil.create(org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl.Literals.PART_DESCRIPTOR);
+ 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.setDirtyable(true);
+ part.setAllowMultiple(true);
+ part.setToolbar(MMenuFactory.INSTANCE.createToolBar());
+ part.setCloseable(true);
+ result.add(part);
+ }
+
+ return result.toArray(new MPartDescriptor[0]);
+ }
+
+ private static MPartDescriptor[] getViewPartDescriptors(IConfigurationElement[] elements) {
+
+ ArrayList<MPartDescriptor> result = new ArrayList<MPartDescriptor>();
+ for (IConfigurationElement element : elements) {
+ MPartDescriptor part = (MPartDescriptor) EcoreUtil.create(org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl.Literals.PART_DESCRIPTOR);
+ 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());
+ part.setCloseable(true);
+ result.add(part);
+ }
+
+ return result.toArray(new MPartDescriptor[0]);
+ }
+
private static MHandler[] getHandlers(IConfigurationElement[] elements, MApplication application) {
ArrayList<MHandler> result = new ArrayList<MHandler>();
@@ -179,7 +253,13 @@ public class RegistryUtil {
}
private static String getIconURI(IConfigurationElement element, String attribute) {
- // FIXME don't assume local icon
+ if (element.getAttribute(attribute) == null) {
+ return "";
+ }
+ // FIXME any other cases?
+ if (element.getAttribute(attribute).startsWith("platform:")) {
+ return element.getAttribute(attribute);
+ }
return "platform:/plugin/" + element.getContributor().getName() + "/" + element.getAttribute(attribute);
}
@@ -259,7 +339,7 @@ public class RegistryUtil {
* @return the structure that matches the extension registry to the passed
* {@link ApplicationElement}
*/
- public static RegistryStruct getStruct(Class<? extends MApplicationElement> applicationElement) {
+ public static RegistryStruct getStruct(Class<? extends MApplicationElement> applicationElement, String hint) {
if (applicationElement == MCommand.class)
return new RegistryStruct("", "org.eclipse.ui.commands", "command", "name");
@@ -276,8 +356,20 @@ public class RegistryUtil {
else if (applicationElement == MHandler.class)
return new RegistryStruct("", "org.eclipse.ui.handlers", "handler", "commandId");
- else if (applicationElement == MPart.class)
+ else if (applicationElement == MPart.class) {
return new RegistryStruct("", "org.eclipse.ui.views", "view", "name");
+ }
+
+ else if (applicationElement == MInputPart.class) {
+ return new RegistryStruct("", "org.eclipse.ui.editors", "editor", "name");
+ }
+
+ else if (applicationElement == MPartDescriptor.class) {
+ if (hint == HINT_EDITOR)
+ return new RegistryStruct("", "org.eclipse.ui.editors", "editor", "name");
+ if (hint == HINT_VIEW)
+ return new RegistryStruct("", "org.eclipse.ui.views", "view", "name");
+ }
return null;
}

Back to the top