diff options
author | Remi Schnekenburger | 2014-05-15 13:52:09 +0000 |
---|---|---|
committer | Remi Schnekenburger | 2014-05-15 14:19:58 +0000 |
commit | 276e37ac4d196fd156f58000e55b8b761c1cbe05 (patch) | |
tree | ce29c2da2c418dbe54c7ad43f909d7e4c931baa9 /plugins/views | |
parent | 00f57319e8bc382a82604780d8f1c52246b00267 (diff) | |
download | org.eclipse.papyrus-276e37ac4d196fd156f58000e55b8b761c1cbe05.tar.gz org.eclipse.papyrus-276e37ac4d196fd156f58000e55b8b761c1cbe05.tar.xz org.eclipse.papyrus-276e37ac4d196fd156f58000e55b8b761c1cbe05.zip |
434966: [Model Explorer] new child menu shall be updated before official
release
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434966
Change-Id: Iee4943ad614d7782180aa5300f3939fdd39bc241
Signed-off-by: Remi Schnekenburger <remi.schnekenburger@cea.fr>
Diffstat (limited to 'plugins/views')
-rw-r--r-- | plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java | 268 |
1 files changed, 134 insertions, 134 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java index a56189c6ab3..e50b6f5c982 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java @@ -1,134 +1,134 @@ -/*****************************************************************************
- * 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.views.modelexplorer.newchild;
-
-
-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.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) {
- 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) {
- //Nothing to do. We can't handle this case
- }
- return selectedEObject;
- }
- return null;
- }
-}
+/***************************************************************************** + * 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.views.modelexplorer.newchild; + + +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.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) { + 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) { + //Nothing to do. We can't handle this case + } + return selectedEObject; + } + return null; + } +} |