Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2013-03-16 18:23:51 -0400
committerWim Jongman2013-03-16 18:23:51 -0400
commit12d71f4a0814299f451d6ae1242862c06157263e (patch)
treefeb7ae90ed5b947cae11d8c41a43670989f06366
parentd05a633e9f8d2a17fd268d312d67deb29db01f25 (diff)
downloadorg.eclipse.e4.tools-12d71f4a0814299f451d6ae1242862c06157263e.tar.gz
org.eclipse.e4.tools-12d71f4a0814299f451d6ae1242862c06157263e.tar.xz
org.eclipse.e4.tools-12d71f4a0814299f451d6ae1242862c06157263e.zip
bug 402875: Added support for command categories and commands
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402875
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java9
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java33
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VApplicationCategoriesEditor.java39
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VCommandEditor.java33
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java174
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportWizard.java97
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryStruct.java38
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryUtil.java176
9 files changed, 595 insertions, 7 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 8727c5ff..f816882c 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,7 +32,8 @@ 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.e4.ui.workbench.swt;bundle-version="0.10.0",
+ org.eclipse.pde.core;bundle-version="3.9.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/common/component/AbstractComponentEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java
index f914f280..b1a043b7 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java
@@ -132,6 +132,15 @@ public abstract class AbstractComponentEditor {
return Collections.emptyList();
}
+ /**
+ * @param element
+ * @return the list of actions that are populated in the import menu. Can be
+ * empty but is never null.
+ */
+ public List<Action> getActionsImport(Object element) {
+ return Collections.emptyList();
+ }
+
protected String getLocalizedLabel(MUILabel element) {
return ControlFactory.getLocalizedLabel(translationProvider, element, locale);
}
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 9640c9ca..1c50f18e 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
@@ -621,7 +621,18 @@ public class ModelEditor {
manager.add(addMenu);
}
- manager.add(new Separator());
+ actions = virtualEditors.get(((VirtualEntry<?>) s.getFirstElement()).getId()).getActionsImport(s.getFirstElement());
+ if (actions.size() > 0) {
+ MenuManager menu = new MenuManager("Import");
+ for (Action a : actions) {
+ addSeparator = true;
+ menu.add(a);
+ }
+ manager.add(menu);
+ }
+
+ if (addSeparator)
+ manager.add(new Separator());
// build the extract action
if ((!((VirtualEntry<?>) s.getFirstElement()).getList().isEmpty()) && (!isModelFragment()))
@@ -655,8 +666,11 @@ public class ModelEditor {
});
} else {
+
final EObject o = (EObject) s.getFirstElement();
AbstractComponentEditor editor = getEditor(o.eClass());
+
+ // Build Add Child menu
if (editor != null) {
actions = new ArrayList<Action>(editor.getActions(s.getFirstElement()));
} else {
@@ -672,6 +686,23 @@ public class ModelEditor {
manager.add(addMenu);
}
+ // Build import menu
+ if (editor != null) {
+ actions = new ArrayList<Action>(editor.getActionsImport(s.getFirstElement()));
+ } else {
+ actions = new ArrayList<Action>();
+ }
+
+ if (actions.size() > 0) {
+ // TODO WIM - extract nls
+ MenuManager menu = new MenuManager("Import");
+ for (Action a : actions) {
+ addSeparator = true;
+ menu.add(a);
+ }
+ manager.add(menu);
+ }
+
if (o.eContainer() != null) {
addSeparator = true;
manager.add(new Action(messages.ModelEditor_Delete, ImageDescriptor.createFromImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_cross))) {
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 ed8e27ee..62c8d47b 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
@@ -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.MApplication;
import org.eclipse.e4.ui.model.application.commands.MCategory;
import org.eclipse.e4.ui.model.application.commands.impl.CommandsFactoryImpl;
@@ -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;
@@ -52,6 +54,7 @@ public class VApplicationCategoriesEditor extends AbstractComponentEditor {
private EMFDataBindingContext context;
private List<Action> actions = new ArrayList<Action>();
+ private List<Action> actionsImport = new ArrayList<Action>();
@Inject
public VApplicationCategoriesEditor() {
@@ -66,6 +69,23 @@ public class VApplicationCategoriesEditor extends AbstractComponentEditor {
handleAdd();
}
});
+ actionsImport.add(new Action(Messages.VApplicationCategoriesEditor_AddCategory, createImageDescriptor(ResourceProvider.IMG_Category)) {
+ @Override
+ public void run() {
+ handleImport();
+ }
+ });
+ }
+
+ protected void handleImport() {
+ ModelImportWizard wizard = new ModelImportWizard(MCategory.class, getEditingDomain());
+ WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard);
+ if (wizardDialog.open() == WizardDialog.OK) {
+ MCategory[] elements = (MCategory[]) wizard.getElements(MCategory.class);
+ for (MCategory category : elements) {
+ addCategory(category);
+ }
+ }
}
@Override
@@ -220,14 +240,18 @@ public class VApplicationCategoriesEditor extends AbstractComponentEditor {
}
protected void handleAdd() {
- MCategory command = CommandsFactoryImpl.eINSTANCE.createCategory();
- setElementId(command);
+ MCategory category = CommandsFactoryImpl.eINSTANCE.createCategory();
+ addCategory(category);
+ }
+
+ private void addCategory(MCategory category) {
+ setElementId(category);
- Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), ApplicationPackageImpl.Literals.APPLICATION__CATEGORIES, command);
+ Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), ApplicationPackageImpl.Literals.APPLICATION__CATEGORIES, category);
if (cmd.canExecute()) {
getEditingDomain().getCommandStack().execute(cmd);
- getEditor().setSelection(command);
+ getEditor().setSelection(category);
}
}
@@ -237,4 +261,11 @@ public class VApplicationCategoriesEditor extends AbstractComponentEditor {
l.addAll(actions);
return l;
}
+
+ @Override
+ public List<Action> getActionsImport(Object element) {
+ ArrayList<Action> l = new ArrayList<Action>(super.getActions(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/VCommandEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/virtual/VCommandEditor.java
index 64232bb6..9ea93a7c 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
@@ -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.MApplication;
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.commands.impl.CommandsFactoryImpl;
@@ -35,6 +36,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;
@@ -54,6 +56,7 @@ public class VCommandEditor extends AbstractComponentEditor {
private EStructuralFeature commandsFeature;
private List<Action> actions = new ArrayList<Action>();
+ private List<Action> actionsImport = new ArrayList<Action>();
@Inject
public VCommandEditor() {
@@ -69,6 +72,13 @@ public class VCommandEditor extends AbstractComponentEditor {
handleAdd();
}
});
+
+ actionsImport.add(new Action("Import Commands", createImageDescriptor(ResourceProvider.IMG_Command)) {
+ @Override
+ public void run() {
+ handleImport();
+ }
+ });
}
@Override
@@ -219,8 +229,11 @@ public class VCommandEditor extends AbstractComponentEditor {
protected void handleAdd() {
MCommand command = CommandsFactoryImpl.eINSTANCE.createCommand();
- setElementId(command);
+ addCommand(command);
+ }
+ private void addCommand(MCommand command) {
+ setElementId(command);
Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), commandsFeature, command);
if (cmd.canExecute()) {
@@ -229,6 +242,17 @@ public class VCommandEditor extends AbstractComponentEditor {
}
}
+ protected void handleImport() {
+ ModelImportWizard wizard = new ModelImportWizard(MCommand.class, getEditingDomain());
+ WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), wizard);
+ if (wizardDialog.open() == WizardDialog.OK) {
+ MCommand[] elements = (MCommand[]) wizard.getElements(MCommand.class);
+ for (MCommand mCommand : elements) {
+ addCommand(mCommand);
+ }
+ }
+ }
+
@Override
public IObservableList getChildList(Object element) {
return null;
@@ -240,4 +264,11 @@ public class VCommandEditor extends AbstractComponentEditor {
l.addAll(actions);
return l;
}
+
+ @Override
+ public List<Action> getActionsImport(Object element) {
+ ArrayList<Action> l = new ArrayList<Action>(super.getActions(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/ModelImportPage1.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java
new file mode 100644
index 00000000..261646bc
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportPage1.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Remain BV, Industrial-TSI BV 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wim Jongmam <wim.jongman@remainsoftware.com> - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.imp;
+
+import java.util.ArrayList;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class ModelImportPage1 extends WizardPage {
+
+ private class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof IConfigurationElement) {
+ IConfigurationElement config = (IConfigurationElement) element;
+ return config.getAttribute(wizard.getMappingName());
+ }
+ return element.toString();
+ }
+ }
+
+ private IExtensionRegistry registry;
+ private ModelImportWizard wizard;
+ protected Object[] checkedElements;
+
+ private class TableContentProvider implements IStructuredContentProvider {
+ public Object[] getElements(Object inputElement) {
+
+ if (!(inputElement instanceof RegistryStruct)) {
+ return new String[] { "Wrong input" };
+ }
+
+ RegistryStruct input = (RegistryStruct) inputElement;
+
+ return RegistryUtil.getExtensions(registry, input);
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ private class ComboContentProvider implements IStructuredContentProvider {
+ public Object[] getElements(Object inputElement) {
+ return RegistryUtil.getProvidingBundles(registry, wizard.getExtensionPoint());
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ /**
+ * Create the wizard.
+ */
+ public ModelImportPage1() {
+ super("wizardPage");
+ setTitle("Import Commands");
+ setDescription("Select plug-in and commands to import");
+ wizard = (ModelImportWizard) getWizard();
+ setPageComplete(false);
+ }
+
+ /**
+ * Create contents of the wizard.
+ *
+ * @param parent
+ */
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+
+ setControl(container);
+ container.setLayout(new GridLayout(1, false));
+
+ ComboViewer comboViewer = new ComboViewer(container, SWT.NONE);
+ Combo combo = comboViewer.getCombo();
+ combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+
+ Composite composite = new Composite(container, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ TableColumnLayout tcl_composite = new TableColumnLayout();
+ composite.setLayout(tcl_composite);
+
+ final CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
+
+ TableViewerColumn tableViewerColumn = new TableViewerColumn(checkboxTableViewer, SWT.NONE);
+ TableColumn column = tableViewerColumn.getColumn();
+ column.setResizable(false);
+ tcl_composite.setColumnData(column, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
+ column.setText("Description");
+ checkboxTableViewer.setLabelProvider(new TableLabelProvider());
+ checkboxTableViewer.setContentProvider(new TableContentProvider());
+ comboViewer.setContentProvider(new ComboContentProvider());
+
+ comboViewer.setInput("go");
+
+ comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ String bundle = ((IStructuredSelection) event.getSelection()).getFirstElement().toString();
+ RegistryStruct struct = RegistryUtil.getStruct(wizard.getApplicationElement());
+ struct.setBundle(bundle);
+ checkboxTableViewer.setInput(struct);
+
+ }
+ });
+
+ checkboxTableViewer.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ checkedElements = checkboxTableViewer.getCheckedElements();
+ if (checkedElements.length > 0) {
+ setPageComplete(true);
+ } else {
+ setPageComplete(false);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void setWizard(IWizard newWizard) {
+ this.wizard = (ModelImportWizard) newWizard;
+ super.setWizard(newWizard);
+ }
+
+ public IConfigurationElement[] getConfigurationElements() {
+ ArrayList<IConfigurationElement> result = new ArrayList<IConfigurationElement>();
+ for (Object element : checkedElements) {
+ if (element instanceof IConfigurationElement) {
+ result.add((IConfigurationElement) element);
+ }
+ }
+ return result.toArray(new IConfigurationElement[0]);
+ }
+}
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
new file mode 100644
index 00000000..505f4755
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/ModelImportWizard.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Remain BV, Industrial-TSI BV 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wim Jongmam <wim.jongman@remainsoftware.com> - initial API and implementation
+ ******************************************************************************/
+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.ui.model.application.MApplicationElement;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.wizard.Wizard;
+
+public class ModelImportWizard extends Wizard {
+
+ private Class<? extends MApplicationElement> applicationElement;
+
+ private ModelImportPage1 page1;
+
+ private EditingDomain editingDomain;
+
+ public ModelImportWizard(Class<? extends MApplicationElement> applicationElement, EditingDomain editingDomain) {
+ this.applicationElement = applicationElement;
+ this.editingDomain = editingDomain;
+ setWindowTitle("Model Command Import Wizard");
+ Assert.isNotNull(RegistryUtil.getStruct(applicationElement), "Unknown Element: " + applicationElement.getClass().getName());
+ }
+
+ @Override
+ public void addPages() {
+ page1 = new ModelImportPage1();
+ page1.setWizard(this);
+ addPage(page1);
+ }
+
+ @Override
+ public boolean performFinish() {
+
+ return true;
+ }
+
+ /**
+ * @return the {@link MApplicationElement} passed in the constructor.
+ */
+ public Class<? extends MApplicationElement> getApplicationElement() {
+ return applicationElement;
+ }
+
+ /**
+ * @return the extension point name associated with the
+ * {@link MApplicationElement} that is passed in the constructor of
+ * this wizard.
+ * @see #MAPPING_EXTENSION
+ * @see #getApplicationElement()
+ */
+ protected String getExtensionPointName() {
+ return RegistryUtil.getStruct(applicationElement).getExtensionPointName();
+ }
+
+ /**
+ * @return the extension point id associated with the
+ * {@link MApplicationElement} that is passed in the constructor of
+ * this wizard.
+ * @see #MAPPING_EXTENSION
+ * @see #getApplicationElement()
+ */
+ protected String getExtensionPoint() {
+ return RegistryUtil.getStruct(applicationElement).getExtensionPoint();
+ }
+
+ /**
+ * @return the attribute name of the {@link IConfigurationElement} that
+ * contains the description that you want to see in the wizard page.
+ * @see #MAPPING_NAME
+ */
+ protected String getMappingName() {
+ return RegistryUtil.getStruct(applicationElement).getMappingName();
+ }
+
+ /**
+ * Returns the list of {@link MApplicationElement}s of the type passed in
+ * the constructor of the wizard.
+ *
+ * @param <T>
+ *
+ * @return
+ */
+ public MApplicationElement[] getElements(Class<? extends MApplicationElement> type) {
+ return RegistryUtil.getModelElements(type, editingDomain, page1.getConfigurationElements());
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryStruct.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryStruct.java
new file mode 100644
index 00000000..09dc6fa9
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryStruct.java
@@ -0,0 +1,38 @@
+package org.eclipse.e4.tools.emf.ui.internal.imp;
+
+public class RegistryStruct {
+
+ String bundle;
+ String extensionPoint;
+ String extensionPointName;
+ String mappingName;
+
+ public RegistryStruct(String bundle, String extensionPoint,
+ String extensionPointName, String mappingName) {
+ super();
+ this.bundle = bundle;
+ this.extensionPoint = extensionPoint;
+ this.extensionPointName = extensionPointName;
+ this.mappingName = mappingName;
+ }
+
+ public String getBundle() {
+ return bundle;
+ }
+
+ public String getExtensionPoint() {
+ return extensionPoint;
+ }
+
+ public String getExtensionPointName() {
+ return extensionPointName;
+ }
+
+ public String getMappingName() {
+ return mappingName;
+ }
+
+ public void setBundle(String bundle) {
+ this.bundle = bundle;
+ }
+}
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
new file mode 100644
index 00000000..b24eca53
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/imp/RegistryUtil.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Remain BV, Industrial-TSI BV 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wim Jongmam <wim.jongman@remainsoftware.com> - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.tools.emf.ui.internal.imp;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+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.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;
+
+public class RegistryUtil {
+
+ /**
+ *
+ * @param t
+ * @param editingDomain
+ * @param elements
+ * @return
+ */
+ public static MApplicationElement[] getModelElements(Class<? extends MApplicationElement> t, EditingDomain editingDomain, IConfigurationElement... elements) {
+
+ Assert.isNotNull(t);
+ Assert.isNotNull(elements);
+ Assert.isTrue(elements.length > 0);
+
+ if (t.equals(MCommand.class)) {
+ return getCommands(elements, editingDomain);
+ } else if (t.equals(MCategory.class)) {
+ return getCategories(elements);
+ }
+ return new MApplicationElement[0];
+ }
+
+ private static MCommand[] getCommands(IConfigurationElement[] elements, EditingDomain editingDomain) {
+
+ ArrayList<MCommand> result = new ArrayList<MCommand>();
+
+ MCommandsFactory commandsFactory = MCommandsFactory.INSTANCE;
+
+ for (IConfigurationElement element : elements) {
+
+ MCommand command = commandsFactory.createCommand();
+ command.setCommandName(element.getAttribute("name"));
+ command.setDescription(element.getAttribute("description"));
+ 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();
+ for (MCategory category : categories) {
+ if (category.getElementId().equals(catId)) {
+ command.setCategory(category);
+ break;
+ }
+ }
+ }
+
+ result.add((MCommand) command);
+ }
+
+ return result.toArray(new MCommand[0]);
+ }
+
+ private static MCategory[] getCategories(IConfigurationElement[] elements) {
+
+ ArrayList<MCategory> result = new ArrayList<MCategory>();
+
+ MCommandsFactory commandsFactory = MCommandsFactory.INSTANCE;
+
+ for (IConfigurationElement element : elements) {
+
+ MCategory category = commandsFactory.createCategory();
+ category.setDescription(element.getAttribute("description"));
+ category.setElementId(element.getAttribute("id"));
+ category.setName(element.getAttribute("name"));
+
+ result.add(category);
+ }
+
+ return result.toArray(new MCategory[0]);
+ }
+
+ /**
+ * Returns a list of bundle id's that have extension to the passed extension
+ * point.
+ *
+ * @param registry
+ * @param extensionPoint
+ * @return
+ */
+ public static String[] getProvidingBundles(IExtensionRegistry registry, String extensionPoint) {
+
+ IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
+ PDEExtensionRegistry reg = new PDEExtensionRegistry(models);
+ ArrayList<String> result = new ArrayList<String>();
+
+ IExtension[] extensions = reg.findExtensions(extensionPoint, true);
+ for (IExtension extension : extensions) {
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ for (IConfigurationElement element : elements) {
+ if (!result.contains(element.getContributor().getName())) {
+ result.add(element.getContributor().getName());
+ }
+ }
+ }
+
+ String[] resultArray = result.toArray(new String[0]);
+ Arrays.sort(resultArray);
+ return resultArray;
+ }
+
+ /**
+ *
+ * @param registry
+ * @param MApplicationElement
+ * @return the array of {@link IConfigurationElement} objects that meets the
+ * passed criteria.
+ */
+ public static IConfigurationElement[] getExtensions(IExtensionRegistry registry, RegistryStruct struct) {
+
+ if (struct == 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);
+ for (IExtension extension : extensions) {
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ for (IConfigurationElement element : elements) {
+ if (element.getContributor().getName().equals(struct.getBundle())) {
+ if (element.getName().equals(struct.getExtensionPointName())) {
+ result.add(element);
+ }
+ }
+ }
+ }
+
+ return result.toArray(new IConfigurationElement[0]);
+ }
+
+ public static RegistryStruct getStruct(Class<? extends MApplicationElement> applicationElement) {
+
+ if (applicationElement == MCommand.class)
+ return new RegistryStruct("", "org.eclipse.ui.commands", "command", "name");
+
+ else if (applicationElement == MCategory.class)
+ return new RegistryStruct("", "org.eclipse.ui.commands", "category", "name");
+
+ return null;
+ }
+
+}

Back to the top