From 81a862147f0bc317f6f65ef155266f31bfa1f73f Mon Sep 17 00:00:00 2001
From: cletavernie
Date: Fri, 27 Jul 2012 12:31:19 +0000
Subject: 386118: [EMF Facet] Papyrus should progressively support EMF Facet
0.2 https://bugs.eclipse.org/bugs/show_bug.cgi?id=386118
- Improve the resolution of EObjects in EMFHelper, to be able to handle EMF Facet 0.2 encapsulated TreeElements
- Add a new Papyrus EMF Editor based on EMF Facet 0.2 (Extra plug-in). The previous editor, based en EMF Facet 0.1, is still available.
- New utility methods added in EMFHelper
---
.../META-INF/MANIFEST.MF | 8 +-
.../plugin.xml | 11 +-
.../infra/emf/editor/part/PapyrusEditor.java | 6 +-
.../infra/emf/editor/part/PapyrusEditor2.java | 305 +++++++++++++++++++++
.../papyrus/infra/emf/editor/util/ActionUtil.java | 18 +-
.../emf/embeddededitor/editor/EmbeddedEditor.java | 4 +
.../META-INF/MANIFEST.MF | 2 +
.../newchild/menu/AbstractCustomFillElement.java | 6 +
.../infra/emf/newchild/menu/CustomFillElement.java | 2 +
.../infra/emf/newchild/menu/FillNewChild.java | 42 ++-
.../infra/emf/newchild/menu/FillerFactory.java | 1 +
.../infra/emf/newchild/menu/MyCustomFiller.java | 4 +-
.../META-INF/MANIFEST.MF | 3 +-
.../strategy/SemanticEMFContentProvider.java | 5 +-
.../eclipse/papyrus/infra/emf/utils/EMFHelper.java | 141 +++++++++-
15 files changed, 534 insertions(+), 24 deletions(-)
create mode 100644 plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor2.java
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/META-INF/MANIFEST.MF
index a0daea9223a..8281abc47c0 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/META-INF/MANIFEST.MF
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/META-INF/MANIFEST.MF
@@ -18,7 +18,13 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.1.0",
org.eclipse.papyrus.views.properties;bundle-version="0.9.0",
org.eclipse.papyrus.infra.widgets;bundle-version="0.9.0",
- org.eclipse.emf.transaction;bundle-version="1.4.0"
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.emf.facet.efacet.core;bundle-version="0.2.0",
+ org.eclipse.emf.facet.custom.core;bundle-version="0.2.0",
+ org.eclipse.emf.facet.custom.ui;bundle-version="0.2.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.9.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: dependent
+Export-Package: org.eclipse.papyrus.infra.emf.editor.part,
+ org.eclipse.papyrus.infra.emf.editor.providers
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/plugin.xml b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/plugin.xml
index 4e5269bbe93..d2a34ed27c8 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/plugin.xml
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/plugin.xml
@@ -21,7 +21,16 @@
extensions="xmi"
icon="icons/papyrus_model.png"
id="org.eclipse.papyrus.emf.editor"
- name="Papyrus EMF Editor">
+ name="Papyrus EMF Editor (EMF Facet 0.1)">
+
+
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor.java
index 3939406c91c..ac3b8b43ccc 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor.java
@@ -110,7 +110,7 @@ public class PapyrusEditor extends EcoreEditor implements ITabbedPropertySheetPa
});
- Tree tree = new Tree(parent, SWT.BORDER | SWT.MULTI);
+ Tree tree = new Tree(parent, getTreeStyle() | SWT.MULTI);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
selectionViewer = new TreeViewer(tree);
@@ -168,6 +168,10 @@ public class PapyrusEditor extends EcoreEditor implements ITabbedPropertySheetPa
updateProblemIndication();
}
+ protected int getTreeStyle() {
+ return SWT.BORDER;
+ }
+
@Override
protected void initializeEditingDomain() {
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor2.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor2.java
new file mode 100644
index 00000000000..96f6dcdc2fd
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor2.java
@@ -0,0 +1,305 @@
+package org.eclipse.papyrus.infra.emf.editor.part;
+
+import java.util.EventObject;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.presentation.EcoreEditor;
+import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
+import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor;
+import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
+import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
+import org.eclipse.emf.facet.custom.core.ICustomizationCatalogManager;
+import org.eclipse.emf.facet.custom.core.ICustomizationCatalogManagerFactory;
+import org.eclipse.emf.facet.custom.core.ICustomizationManager;
+import org.eclipse.emf.facet.custom.core.ICustomizationManagerFactory;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.ui.ICustomizedContentProviderFactory;
+import org.eclipse.emf.facet.custom.ui.IResolvingCustomizedLabelProviderFactory;
+import org.eclipse.emf.transaction.TransactionalCommandStack;
+import org.eclipse.emf.transaction.impl.TransactionalCommandStackImpl;
+import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.papyrus.infra.emf.editor.actions.MoDiscoDropAdapter;
+import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
+import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
+import org.eclipse.papyrus.infra.widgets.editors.StringEditor;
+import org.eclipse.papyrus.infra.widgets.providers.PatternViewerFilter;
+import org.eclipse.papyrus.views.properties.widgets.layout.GridData;
+import org.eclipse.papyrus.views.properties.widgets.layout.PropertiesLayout;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+
+/**
+ * An extended EMF editor
+ *
+ * This generic editor provides the following features :
+ *
+ * - EMF Facet browser customization
+ * - Papyrus customizable property view
+ * - Papyrus customizable new child
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetPageContributor, CommandStackListener {
+
+ public static final String PROPERTY_VIEW_ID = "CustomizablePropertyView"; //$NON-NLS-1$
+
+ /**
+ * The Property sheet page for this editor
+ */
+ protected IPropertySheetPage iPropertySheetPage;
+
+ @Override
+ public void createPages() {
+ // Creates the model from the editor input
+ //
+ createModel();
+
+ getContainer().setBackground(new Color(getContainer().getDisplay(), 255, 255, 255));
+ getContainer().setBackgroundMode(SWT.INHERIT_DEFAULT);
+
+ Composite gParent = new Composite(getContainer(), SWT.NONE);
+ gParent.setLayout(new FillLayout());
+
+ //SashForm parent = new SashForm(gParent, SWT.VERTICAL | SWT.V_SCROLL | SWT.H_SCROLL);
+ //parent.setLayout(new FillLayout());
+
+ Composite parent = new Composite(gParent, SWT.NONE);
+ parent.setLayout(new PropertiesLayout());
+
+ // Only creates the other pages if there is something that can be edited
+ //
+ if(!getEditingDomain().getResourceSet().getResources().isEmpty()) {
+ // Create a page for the selection tree view.
+ //
+
+ final PatternViewerFilter filter = new PatternViewerFilter();
+ filter.setShowIfHasVisibleParent(true);
+
+ final StringEditor filterPattern = new StringEditor(parent, SWT.NONE, "Filter");
+ filterPattern.addCommitListener(new ICommitListener() {
+
+ public void commit(AbstractEditor editor) {
+ filter.setPattern((String)filterPattern.getValue());
+ selectionViewer.refresh();
+ }
+
+ });
+
+ Tree tree = new Tree(parent, getTreeStyle() | SWT.MULTI);
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ selectionViewer = new TreeViewer(tree);
+ selectionViewer.setFilters(new ViewerFilter[]{ filter });
+ setCurrentViewer(selectionViewer);
+
+ initializeCustomizationCatalogManager();
+
+ IStructuredContentProvider contentProvider = createContentProvider();
+
+ ILabelProvider labelProvider = createLabelProvider();
+
+ editingDomain.getCommandStack().addCommandStackListener(this);
+
+ selectionViewer.setContentProvider(contentProvider);
+ selectionViewer.setLabelProvider(labelProvider);
+
+ selectionViewer.setInput(getTreeViewerInput());
+ // selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
+
+ new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
+
+ createContextMenuFor(selectionViewer);
+ int pageIndex = addPage(gParent);
+ setPageText(pageIndex, "Model"); //$NON-NLS-1$
+
+ setActivePage(0);
+
+ // Preview preview = new Preview(this);
+ // preview.createPartControl(parent);
+ // addPreview(preview);
+
+ parent.layout();
+ }
+
+ // Ensures that this editor will only display the page's tab
+ // area if there are more than one page
+ //
+ getContainer().addControlListener(new ControlAdapter() {
+
+ boolean guard = false;
+
+ @Override
+ public void controlResized(ControlEvent event) {
+ if(!guard) {
+ guard = true;
+ hideTabs();
+ guard = false;
+ }
+ }
+ });
+
+ if(getActionBarContributor() instanceof ActionBarContributor) {
+ ((ActionBarContributor)getActionBarContributor()).setEditingDomain(getEditingDomain());
+ }
+
+ updateProblemIndication();
+ }
+
+ protected Object getTreeViewerInput() {
+ List roots = new LinkedList();
+ for(Resource resource : getResourceSet().getResources()) {
+ for(EObject rootEObject : resource.getContents()) {
+ roots.add(rootEObject);
+ }
+ }
+ return roots;
+ }
+
+ protected int getTreeStyle() {
+ return SWT.BORDER;
+ }
+
+ @Override
+ protected void initializeEditingDomain() {
+ // Create an adapter factory that yields item providers.
+ //
+ adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+
+ adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
+
+ // Create the command stack that will notify this editor as commands are executed.
+ //
+ TransactionalCommandStack commandStack = new TransactionalCommandStackImpl();
+
+ // Add a listener to set the most recent command's affected objects to be the selection of the viewer with focus.
+ //
+ commandStack.addCommandStackListener(new CommandStackListener() {
+
+ public void commandStackChanged(final EventObject event) {
+ getContainer().getDisplay().asyncExec(new Runnable() {
+
+ public void run() {
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+
+ // Try to select the affected objects.
+ //
+ Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand();
+ if(mostRecentCommand != null) {
+ setSelectionToViewer(mostRecentCommand.getAffectedObjects());
+ }
+ if(propertySheetPage != null && !propertySheetPage.getControl().isDisposed()) {
+ propertySheetPage.refresh();
+ }
+ }
+ });
+ }
+ });
+
+ // Create the editing domain with a special command stack.
+ //
+ editingDomain = new TransactionalEditingDomainImpl(adapterFactory, commandStack);
+ editingDomain.setResourceToReadOnlyMap(new HashMap());
+ }
+
+ @Override
+ protected void createContextMenuFor(StructuredViewer viewer) {
+ MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$
+ contextMenu.add(new Separator("additions")); //$NON-NLS-1$
+ contextMenu.setRemoveAllWhenShown(true);
+ contextMenu.addMenuListener(this);
+ Menu menu = contextMenu.createContextMenu(viewer.getControl());
+ viewer.getControl().setMenu(menu);
+
+ int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
+ Transfer[] transfers = new Transfer[]{ LocalTransfer.getInstance() };
+ viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
+ viewer.addDropSupport(dndOperations, transfers, new MoDiscoDropAdapter(editingDomain, viewer));
+ }
+
+ @Override
+ public IPropertySheetPage getPropertySheetPage() {
+ if(iPropertySheetPage == null) {
+ iPropertySheetPage = new TabbedPropertySheetPage(this);
+ }
+ return iPropertySheetPage;
+ }
+
+ protected ICustomizationManager getCustomizationManager() {
+ if(customizationManager == null) {
+ customizationManager = ICustomizationManagerFactory.DEFAULT.getOrCreateICustomizationManager(getResourceSet());
+ }
+ return customizationManager;
+ }
+
+ protected void initializeCustomizationCatalogManager() {
+ ICustomizationCatalogManager customCatalog = ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(getResourceSet());
+ List allCustomizations = customCatalog.getRegisteredCustomizations();
+ for(Customization customization : allCustomizations) {
+ if(customization.isMustBeLoadedByDefault()) {
+ System.out.println("Apply default customization: " + customization.getName());
+ getCustomizationManager().getManagedCustomizations().add(customization);
+ }
+ }
+ }
+
+ protected IStructuredContentProvider createContentProvider() {
+ return ICustomizedContentProviderFactory.DEFAULT.createCustomizedTreeContentProvider(getCustomizationManager());
+ }
+
+ protected ResourceSet getResourceSet() {
+ return getEditingDomain().getResourceSet();
+ }
+
+ protected ILabelProvider createLabelProvider() {
+ return IResolvingCustomizedLabelProviderFactory.DEFAULT.createCustomizedLabelProvider(getCustomizationManager());
+ }
+
+ public void commandStackChanged(EventObject event) {
+ getViewer().refresh();
+ }
+
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ super.doSave(monitor);
+ }
+
+ public String getContributorId() {
+ return PROPERTY_VIEW_ID;
+ }
+
+ private ICustomizationManager customizationManager;
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/util/ActionUtil.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/util/ActionUtil.java
index 2408b404a3e..4ac9ad61cbf 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/util/ActionUtil.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/util/ActionUtil.java
@@ -16,10 +16,10 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
/**
* Utility class for Actions
@@ -45,9 +45,9 @@ public class ActionUtil {
public static Collection