Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.classpath14
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/META-INF/MANIFEST.MF9
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/plugin.xml12
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/ActionBarContributor.java19
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor.java (renamed from plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/PapyrusEditor2.java)92
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF7
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/ui/DynamicNewChild.java136
8 files changed, 218 insertions, 78 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.classpath b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.classpath
index 94c7bb7e8ed..8a8f1668cdc 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.classpath
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath> \ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.settings/org.eclipse.jdt.core.prefs
index 8bca62fefcf..f287d53cf45 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,7 @@
-#Wed Jul 27 11:41:38 CEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6
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 03ea0139cbc..78021654d14 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
@@ -1,13 +1,11 @@
Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.infra.emf.editor.part,
- org.eclipse.papyrus.infra.emf.editor.providers
+Export-Package: org.eclipse.papyrus.infra.emf.editor.part
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.emf.ecore;bundle-version="2.7.0",
org.eclipse.emf.ecore.editor;bundle-version="2.7.0",
org.eclipse.core.resources;bundle-version="3.7.100",
org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.200",
- org.eclipse.papyrus.infra.emf.newchild;bundle-version="1.1.0",
org.eclipse.papyrus.views.properties;bundle-version="1.1.0",
org.eclipse.papyrus.infra.widgets;bundle-version="1.1.0",
org.eclipse.emf.transaction;bundle-version="1.4.0",
@@ -17,7 +15,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.emf;bundle-version="1.1.0",
org.eclipse.papyrus.infra.core;bundle-version="1.1.0",
org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.1.0"
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.newchild;bundle-version="1.1.0"
Bundle-Vendor: Eclipse Modeling Project
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.1.0.qualifier
@@ -27,5 +26,5 @@ Bundle-Activator: org.eclipse.papyrus.infra.emf.editor.Activator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.papyrus.infra.emf.editor;singleton:=t
rue
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
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 d2a34ed27c8..c8170edb38b 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
@@ -18,19 +18,9 @@
class="org.eclipse.papyrus.infra.emf.editor.part.PapyrusEditor"
contributorClass="org.eclipse.papyrus.infra.emf.editor.part.ActionBarContributor"
default="false"
- extensions="xmi"
icon="icons/papyrus_model.png"
id="org.eclipse.papyrus.emf.editor"
- name="Papyrus EMF Editor (EMF Facet 0.1)">
- </editor>
- <editor
- class="org.eclipse.papyrus.infra.emf.editor.part.PapyrusEditor2"
- contributorClass="org.eclipse.papyrus.infra.emf.editor.part.ActionBarContributor"
- default="false"
- extensions="xmi"
- icon="icons/papyrus_model.png"
- id="org.eclipse.papyrus.emf.editor2"
- name="Papyrus EMF Editor (EMF Facet 0.2)">
+ name="Papyrus EMF Editor">
</editor>
</extension>
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/ActionBarContributor.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/ActionBarContributor.java
index 47b01f7e4dd..45df42eb359 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/ActionBarContributor.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.editor/src/org/eclipse/papyrus/infra/emf/editor/part/ActionBarContributor.java
@@ -22,9 +22,7 @@ import org.eclipse.emf.edit.ui.action.DeleteAction;
import org.eclipse.emf.edit.ui.action.PasteAction;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.papyrus.infra.emf.editor.actions.MoDiscoCopyAction;
import org.eclipse.papyrus.infra.emf.editor.actions.MoDiscoCutAction;
@@ -32,7 +30,8 @@ import org.eclipse.papyrus.infra.emf.editor.actions.MoDiscoDeleteAction;
import org.eclipse.papyrus.infra.emf.editor.actions.MoDiscoPasteAction;
import org.eclipse.papyrus.infra.emf.editor.actions.ValidationAction;
import org.eclipse.papyrus.infra.emf.editor.util.ActionUtil;
-import org.eclipse.papyrus.infra.emf.newchild.runtime.NewchildManager;
+import org.eclipse.papyrus.infra.newchild.CreationMenuRegistry;
+import org.eclipse.papyrus.infra.newchild.ui.DynamicNewChild;
/**
* The Action bar contributor for the Context Editor
@@ -43,7 +42,7 @@ import org.eclipse.papyrus.infra.emf.newchild.runtime.NewchildManager;
*/
public class ActionBarContributor extends EcoreActionBarContributor {
- protected IStructuredSelection lastSelection;
+ DynamicNewChild contribution = new DynamicNewChild();
/**
*
@@ -55,6 +54,8 @@ public class ActionBarContributor extends EcoreActionBarContributor {
validateAction = new ValidationAction();
}
+ protected CreationMenuRegistry creationMenuRegistry = new CreationMenuRegistry();
+
public void setEditingDomain(EditingDomain domain) {
if (validateAction instanceof ValidationAction) {
((ValidationAction) validateAction).setEditingDomain(domain);
@@ -69,8 +70,8 @@ public class ActionBarContributor extends EcoreActionBarContributor {
@Override
public void menuAboutToShow(IMenuManager menuManager) {
super.menuAboutToShow(menuManager);
- menuManager.insertBefore("edit", new Separator(NewchildManager.TOP)); //$NON-NLS-1$
- NewchildManager.instance.fillMenu(menuManager, lastSelection);
+
+ menuManager.insertBefore("edit", contribution);
}
@Override
@@ -90,12 +91,6 @@ public class ActionBarContributor extends EcoreActionBarContributor {
SelectionChangedEvent newEvent = new SelectionChangedEvent(event.getSelectionProvider(), newSelection);
super.selectionChanged(newEvent);
-
- if (newSelection instanceof IStructuredSelection) {
- this.lastSelection = (IStructuredSelection) newSelection;
- } else {
- this.lastSelection = null;
- }
}
@Override
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/PapyrusEditor.java
index a8555e8bb3d..f5247a3c285 100644
--- 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/PapyrusEditor.java
@@ -1,3 +1,14 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
package org.eclipse.papyrus.infra.emf.editor.part;
import java.util.EventObject;
@@ -12,17 +23,14 @@ 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.ecore.resource.impl.ResourceSetImpl;
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.transaction.TransactionalCommandStack;
-import org.eclipse.emf.transaction.impl.TransactionalCommandStackImpl;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
@@ -33,8 +41,11 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
import org.eclipse.papyrus.emf.facet.custom.ui.ICustomizedContentProviderFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.editor.Activator;
import org.eclipse.papyrus.infra.emf.editor.actions.MoDiscoDropAdapter;
-import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl;
import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
import org.eclipse.papyrus.infra.widgets.editors.StringEditor;
@@ -69,7 +80,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
* @author Camille Letavernier
*
*/
-public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetPageContributor, CommandStackListener {
+public class PapyrusEditor extends EcoreEditor implements ITabbedPropertySheetPageContributor, CommandStackListener {
public static final String PROPERTY_VIEW_ID = "CustomizablePropertyView"; //$NON-NLS-1$
@@ -108,6 +119,7 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
final StringEditor filterPattern = new StringEditor(parent, SWT.NONE, "Filter");
filterPattern.addCommitListener(new ICommitListener() {
+ @Override
public void commit(AbstractEditor editor) {
filter.setPattern((String) filterPattern.getValue());
selectionViewer.refresh();
@@ -144,10 +156,6 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
setActivePage(0);
- // Preview preview = new Preview(this);
- // preview.createPartControl(parent);
- // addPreview(preview);
-
parent.layout();
}
@@ -175,6 +183,12 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
updateProblemIndication();
}
+ @Override
+ protected void handleChangedResources() {
+ super.handleChangedResources();
+ getViewer().setInput(getTreeViewerInput());
+ }
+
protected Object getTreeViewerInput() {
List<EObject> roots = new LinkedList<EObject>();
for (Resource resource : getResourceSet().getResources()) {
@@ -191,25 +205,19 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
@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());
+ ResourceSet resourceSet = new ResourceSetImpl();
- // Create the command stack that will notify this editor as commands are executed.
- //
- TransactionalCommandStack commandStack = new TransactionalCommandStackImpl();
+ editingDomain = (TransactionalEditingDomainImpl) TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(resourceSet);
+ editingDomain.setResourceToReadOnlyMap(new HashMap<Resource, Boolean>());
// 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() {
+ editingDomain.getCommandStack().addCommandStackListener(new CommandStackListener() {
+ @Override
public void commandStackChanged(final EventObject event) {
getContainer().getDisplay().asyncExec(new Runnable() {
+ @Override
public void run() {
firePropertyChange(IEditorPart.PROP_DIRTY);
@@ -234,20 +242,20 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
}
});
- // Create the editing domain with a special command stack.
- //
- editingDomain = new TransactionalEditingDomainImpl(adapterFactory, commandStack);
- editingDomain.setResourceToReadOnlyMap(new HashMap<Resource, Boolean>());
+ adapterFactory = (ComposedAdapterFactory) editingDomain.getAdapterFactory();
}
@Override
protected void createContextMenuFor(StructuredViewer viewer) {
MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$
+ contextMenu.add(new Separator("newChild")); //$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);
+ System.out.println(menu.hashCode());
+ System.out.println(contextMenu.hashCode());
int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
@@ -263,20 +271,23 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
return iPropertySheetPage;
}
- protected ICustomizationManager getCustomizationManager() {
+ protected final ICustomizationManager getCustomizationManager() {
+ if (customizationManager == null) {
+ customizationManager = createCustomizationManager();
+ }
+ return customizationManager;
+ }
+
+ protected ICustomizationManager createCustomizationManager() {
return org.eclipse.papyrus.infra.emf.Activator.getDefault().getCustomizationManager();
- // if(customizationManager == null) {
- // customizationManager = ICustomizationManagerFactory.DEFAULT.getOrCreateICustomizationManager(getResourceSet());
- // }
- // return customizationManager;
}
protected void initializeCustomizationCatalogManager() {
// ICustomizationCatalogManager customCatalog = ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(getResourceSet());
- // ICustomizationCatalogManager customCatalog = Activator.getDefault().getCustomizationManager()
+ // ICustomizationCatalogManager customCatalog = Activator.getDefault().getCustomizationManager();
// List<Customization> allCustomizations = customCatalog.getRegisteredCustomizations();
- // for(Customization customization : allCustomizations) {
- // if(customization.isMustBeLoadedByDefault()) {
+ // for (Customization customization : allCustomizations) {
+ // if (customization.isMustBeLoadedByDefault()) {
// System.out.println("Apply default customization: " + customization.getName());
// getCustomizationManager().getManagedCustomizations().add(customization);
// }
@@ -292,10 +303,16 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
}
protected ILabelProvider createLabelProvider() {
- // return IResolvingCustomizedLabelProviderFactory.DEFAULT.createCustomizedLabelProvider(getCustomizationManager());
- return new EMFLabelProvider();
+ LabelProviderService labelService = new LabelProviderServiceImpl();
+ try {
+ labelService.startService();
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ }
+ return labelService.getLabelProvider();
}
+ @Override
public void commandStackChanged(EventObject event) {
getViewer().refresh();
}
@@ -305,6 +322,7 @@ public class PapyrusEditor2 extends EcoreEditor implements ITabbedPropertySheetP
super.doSave(monitor);
}
+ @Override
public String getContributorId() {
return PROPERTY_VIEW_ID;
}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF b/plugins/infra/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF
index 2497b8847e3..afb9b97724f 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF
+++ b/plugins/infra/org.eclipse.papyrus.infra.newchild/META-INF/MANIFEST.MF
@@ -2,7 +2,8 @@ Manifest-Version: 1.0
Export-Package: org.eclipse.papyrus.infra.newchild,
org.eclipse.papyrus.infra.newchild.elementcreationmenumodel,
org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.impl,
- org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.util
+ org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.util,
+ org.eclipse.papyrus.infra.newchild.ui
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.emf;bundle-version="2.6.0",
@@ -16,7 +17,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.services.edit;bundle-version="1.1.0",
org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.1.0",
org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.1.0"
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.1.0"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
diff --git a/plugins/infra/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/ui/DynamicNewChild.java b/plugins/infra/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/ui/DynamicNewChild.java
new file mode 100644
index 00000000000..ec502c3a7df
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.newchild/src/org/eclipse/papyrus/infra/newchild/ui/DynamicNewChild.java
@@ -0,0 +1,136 @@
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 CEA LIST 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:
+ *
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 413703
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.newchild.ui;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.newchild.CreationMenuFactory;
+import org.eclipse.papyrus.infra.newchild.CreationMenuRegistry;
+import org.eclipse.papyrus.infra.newchild.elementcreationmenumodel.Folder;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This class has in charge to create menu from elementCreationMenuModel
+ *
+ */
+public class DynamicNewChild extends ContributionItem {
+
+ protected TransactionalEditingDomain editingDomain;
+
+ protected CreationMenuRegistry creationMenuRegistry;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public DynamicNewChild() {
+ creationMenuRegistry = new CreationMenuRegistry();
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param id
+ */
+ public DynamicNewChild(String id) {
+ super(id);
+ }
+
+
+ protected IContributionItem[] getContributionItems() {
+ return new IContributionItem[0];
+ }
+
+ @Override
+ public boolean isDynamic() {
+ return true;
+ }
+
+
+
+ @Override
+ public void fill(Menu menu, int index) {
+ EObject eObject = getSelection();
+ if (eObject != null && editingDomain != null) {
+ CreationMenuFactory creationMenuFactory = new CreationMenuFactory(editingDomain);
+ ArrayList<Folder> folders = creationMenuRegistry.getRootFolder();
+ Iterator<Folder> iterFolder = folders.iterator();
+ while (iterFolder.hasNext()) {
+ Folder currentFolder = iterFolder.next();
+ boolean hasbeenBuild = creationMenuFactory.populateMenu(menu, currentFolder, eObject, index);
+ if (hasbeenBuild) {
+ index++;
+ }
+ }
+ } else {
+ super.fill(menu, index);
+ }
+ }
+
+
+
+
+ /**
+ * getSelected eObject in the model explorer
+ *
+ * @return eObject or null
+ */
+ protected EObject getSelection() {
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ ISelection selection = selectionService.getSelection();
+
+ if (selection instanceof IStructuredSelection) {
+ Object selectedobject = ((IStructuredSelection) selection).getFirstElement();
+ EObject selectedEObject = EMFHelper.getEObject(selectedobject);
+ EObject editingDomainCitizen = selectedEObject;
+
+ if ((editingDomainCitizen instanceof EReference) && (selection instanceof ITreeSelection)) {
+ // The user selected a reference in the Advanced presentation. Infer the editing domain from the parent node, which is the reference owner
+ ITreeSelection treeSel = (ITreeSelection) selection;
+ TreePath[] paths = treeSel.getPathsFor(selectedobject);
+ if ((paths != null) && (paths.length > 0) && (paths[0].getSegmentCount() > 1)) {
+ editingDomainCitizen = EMFHelper.getEObject(paths[0].getSegment(paths[0].getSegmentCount() - 2));
+ }
+ }
+
+ try {
+ editingDomain = ServiceUtilsForEObject.getInstance().getService(org.eclipse.emf.transaction.TransactionalEditingDomain.class, editingDomainCitizen);
+ } catch (Exception ex) {
+ // If the service/service registry is not available, try to retrieve directly from the EObject
+ editingDomain = TransactionUtil.getEditingDomain(editingDomainCitizen);
+ }
+ return selectedEObject;
+ }
+ return null;
+ }
+}

Back to the top