diff options
author | Nicolas FAUVERGUE | 2015-08-04 09:19:20 +0000 |
---|---|---|
committer | vincent lorenzo | 2015-10-08 10:27:38 +0000 |
commit | 242cbe4aed69d78142ed739fb7a9ed17963004a5 (patch) | |
tree | b22027c156b78b62602568db43c803130a7fa887 | |
parent | 69d1338903d59a69741a79037ec331c6cde246de (diff) | |
download | org.eclipse.papyrus-242cbe4aed69d78142ed739fb7a9ed17963004a5.tar.gz org.eclipse.papyrus-242cbe4aed69d78142ed739fb7a9ed17963004a5.tar.xz org.eclipse.papyrus-242cbe4aed69d78142ed739fb7a9ed17963004a5.zip |
Bug 469289: [Table] feature columns are created after each added element
https://bugs.eclipse.org/bugs/show_bug.cgi?id=469289
Manage the managed object list to compare the object already added.
Add the JUNit tests of this bug.
Change-Id: I7a1d0e35943377146a3b02774c5602fd90048695
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
11 files changed, 1237 insertions, 940 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectAxisManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectAxisManager.java index 16351e513c4..f2318f2571c 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectAxisManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectAxisManager.java @@ -1,168 +1,169 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.emf.nattable.manager.axis;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-
-/**
- *
- * This manager is a master manager, that's to say, it doesn't listen the contents of the others managers.
- * This manager modify the model for each changes on axis (so each axis is stored)
- *
- */
-public class EObjectAxisManager extends AbstractAxisManager {
-
- // /**
- // *
- // * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
- // *
- // * @param axis
- // * @return
- // */
- // public boolean canDestroyAxisElement(final IAxis axis) {
- // final EObject object = (EObject)axis.getElement();
- // return !EMFHelper.isReadOnly(object);
- // }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer)
- *
- * @param axisPosition
- * @return
- */
- @Override
- public boolean canDestroyAxisElement(Integer axisPosition) {
- final Object current = getElements().get(axisPosition);
- if (current instanceof EObjectAxis) {
- return !EMFHelper.isReadOnly(((EObjectAxis) current).getElement());
- }
- return false;
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * the editing domain
- * @param objectToAdd
- * the object to add to this axis
- * @return
- * the command to create the required axis in the model
- */
- @Override
- public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final Collection<IAxis> toAdd = new ArrayList<IAxis>();
- for (final Object object : objectToAdd) {
- if (isAllowedContents(object) && !isAlreadyManaged(object)) {
- final EObjectAxis horizontalAxis = NattableaxisFactory.eINSTANCE.createEObjectAxis();
- horizontalAxis.setElement((EObject) object);
- horizontalAxis.setManager(this.representedAxisManager);
- toAdd.add(horizontalAxis);
- }
- }
- if (!toAdd.isEmpty()) {
- return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd);
- }
- return null;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(TransactionalEditingDomain, java.lang.Integer)
- *
- * @param domain
- * @param axisPosition
- * @return
- */
- @Override
- public Command getDestroyAxisElementCommand(final TransactionalEditingDomain domain, final Integer axisPosition) {
- final Object current = getElements().get(axisPosition);
- if (current instanceof EObjectAxis) {
- final EObject element = ((EObjectAxis) current).getElement();
- final DestroyElementRequest request = new DestroyElementRequest(getContextEditingDomain(), element, false);
- final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(element);
- return new GMFtoEMFCommandWrapper(provider.getEditCommand(request));
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
- *
- * @param axis
- * @return
- */
- @Override
- public String getElementAxisName(final IAxis axis) {
- throw new UnsupportedOperationException();
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isAllowedContents(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAllowedContents(Object object) {
- return object instanceof EObject;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ISubAxisManager#isDynamic()
- *
- * @return
- */
- @Override
- public boolean isDynamic() {
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave()
- *
- * @return
- */
- @Override
- public boolean isSlave() {
- return false;
- }
-
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.emf.nattable.manager.axis; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; + +/** + * + * This manager is a master manager, that's to say, it doesn't listen the contents of the others managers. + * This manager modify the model for each changes on axis (so each axis is stored) + * + */ +public class EObjectAxisManager extends AbstractAxisManager { + + // /** + // * + // * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis) + // * + // * @param axis + // * @return + // */ + // public boolean canDestroyAxisElement(final IAxis axis) { + // final EObject object = (EObject)axis.getElement(); + // return !EMFHelper.isReadOnly(object); + // } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer) + * + * @param axisPosition + * @return + */ + @Override + public boolean canDestroyAxisElement(Integer axisPosition) { + final Object current = getElements().get(axisPosition); + if (current instanceof EObjectAxis) { + return !EMFHelper.isReadOnly(((EObjectAxis) current).getElement()); + } + return false; + } + + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * the editing domain + * @param objectToAdd + * the object to add to this axis + * @return + * the command to create the required axis in the model + */ + @Override + public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) { + final Collection<IAxis> toAdd = new ArrayList<IAxis>(); + for (final Object object : objectToAdd) { + if (isAllowedContents(object) && !isAlreadyManaged(object)) { + final EObjectAxis horizontalAxis = NattableaxisFactory.eINSTANCE.createEObjectAxis(); + horizontalAxis.setElement((EObject) object); + horizontalAxis.setManager(this.representedAxisManager); + toAdd.add(horizontalAxis); + managedObject.add(object); + } + } + if (!toAdd.isEmpty()) { + return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd); + } + return null; + } + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(TransactionalEditingDomain, java.lang.Integer) + * + * @param domain + * @param axisPosition + * @return + */ + @Override + public Command getDestroyAxisElementCommand(final TransactionalEditingDomain domain, final Integer axisPosition) { + final Object current = getElements().get(axisPosition); + if (current instanceof EObjectAxis) { + final EObject element = ((EObjectAxis) current).getElement(); + final DestroyElementRequest request = new DestroyElementRequest(getContextEditingDomain(), element, false); + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(element); + return new GMFtoEMFCommandWrapper(provider.getEditCommand(request)); + } + return null; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis) + * + * @param axis + * @return + */ + @Override + public String getElementAxisName(final IAxis axis) { + throw new UnsupportedOperationException(); + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isAllowedContents(java.lang.Object) + * + * @param object + * @return + */ + @Override + public boolean isAllowedContents(Object object) { + return object instanceof EObject; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.ISubAxisManager#isDynamic() + * + * @return + */ + @Override + public boolean isDynamic() { + return false; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave() + * + * @return + */ + @Override + public boolean isSlave() { + return false; + } + + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java index 6f0b7d95be6..56cda5f076f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java @@ -1,168 +1,168 @@ -/*****************************************************************************
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.emf.nattable.manager.axis;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
-import org.eclipse.papyrus.infra.core.sashwindows.di.Window;
-import org.eclipse.papyrus.infra.nattable.dataprovider.HierarchicalRowLabelHeaderDataProvider;
-import org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList;
-import org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManagerForEventList;
-import org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisManagerForEventList;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
-import org.eclipse.papyrus.infra.nattable.tree.ITreeItemAxisHelper;
-
-//import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
-
-/**
- *
- * @author VL222926
- * Class used to managed hierarchical axis
- */
-public class EObjectTreeAxisManagerForEventList extends AbstractTreeAxisManagerForEventList implements IAxisManagerForEventList, ITreeItemAxisManagerForEventList {
-
-
-
- /**
- * NOT IN THE API, only here to do the dev about the display of the category (intermediate level displayed filling configuration
- *
- */
- public static final boolean DISPLAY_CATEOGORY = HierarchicalRowLabelHeaderDataProvider.DISPLAY_CATEOGORY;
-
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getAddAxisCommand(TransactionalEditingDomain domain, Collection<Object> objectToAdd) {
- final Collection<IAxis> toAdd = new ArrayList<IAxis>();
- for (final Object object : objectToAdd) {
- if (isAllowedContents(object, null, null, 0) && !isAlreadyManaged(object)) {
- final EObjectAxis horizontalAxis = NattableaxisFactory.eINSTANCE.createEObjectTreeItemAxis();
- horizontalAxis.setElement((EObject) object);
- horizontalAxis.setManager(this.representedAxisManager);
- toAdd.add(horizontalAxis);
- }
- }
- if (!toAdd.isEmpty()) {
- return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd);
- }
- return null;
- }
-
-
-
- /**
- * @param objectToTest
- * @param depth
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisManagerForEventList#isAllowedContents(java.lang.Object, Object, TreeFillingConfiguration, int)
- *
- * @return
- */
- @Override
- public boolean isAllowedContents(Object objectToTest, Object semanticParent, TreeFillingConfiguration conf, int depth) {
- if (objectToTest instanceof EObject) {
- return true;
- }
- return false;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList#isAllowedContents(java.lang.Object)
- *
- * @param object
- * @return
- * @deprecated
- */
- @Override
- public boolean isAllowedContents(Object object) {
- return object instanceof EObject;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList#createITreeItemAxis(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis, java.lang.Object)
- *
- * @param parentAxis
- * @param objectToAdd
- * @return
- */
- protected ITreeItemAxis createITreeItemAxis(ITreeItemAxis parentAxis, Object objectToAdd) {
- return ITreeItemAxisHelper.createITreeItemAxis(getTableEditingDomain(), parentAxis, objectToAdd, this.representedAxisManager);
- }
-
-
- /**
- *
- * @param notification
- * a notification
- * @return
- * <code>true</code> if the notification must be ignored
- */
- protected boolean ignoreEvent(final Notification notification) {
- boolean res = super.ignoreEvent(notification);
- if (res) {
- return res;
- }
- Object notifier = notification.getNotifier();
- Object feature = notification.getFeature();
- if (feature == null) {
- return true;
- }
- if (notifier instanceof PageRef || notifier instanceof Window) {
- return true;
- }
-
-
- // I am not sure of the end of this method
- // List<EStructuralFeature> listenFeature = new ArrayList<EStructuralFeature>();
- // List<TreeFillingConfiguration> confs = FillingConfigurationUtils.getTreeFillingConfiguration(getTable(), representedAxisManager);
- // boolean derivedFeature = false;
- // for (TreeFillingConfiguration conf : confs) {
- // IAxis axis = conf.getAxisUsedAsAxisProvider();
- // if (axis instanceof EStructuralFeatureAxis) {
- // EStructuralFeature f = (EStructuralFeature) axis.getElement();
- // derivedFeature = derivedFeature || f.isDerived();
- // if (derivedFeature) {
- // return false;
- // }
- // }
- // }
- // if (listenFeature.contains(feature)) {
- // return false;
- // }
- //
- // if (confs.size() == listenFeature.size()) {
- // return false;
- // }
- // return true;
- return false;
- }
-}
+/***************************************************************************** + * 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: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.emf.nattable.manager.axis; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef; +import org.eclipse.papyrus.infra.core.sashwindows.di.Window; +import org.eclipse.papyrus.infra.nattable.dataprovider.HierarchicalRowLabelHeaderDataProvider; +import org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList; +import org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManagerForEventList; +import org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisManagerForEventList; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage; +import org.eclipse.papyrus.infra.nattable.tree.ITreeItemAxisHelper; + +//import org.eclipse.nebula.widgets.nattable.ui.NatEventData; + +/** + * + * @author VL222926 + * Class used to managed hierarchical axis + */ +public class EObjectTreeAxisManagerForEventList extends AbstractTreeAxisManagerForEventList implements IAxisManagerForEventList, ITreeItemAxisManagerForEventList { + + + + /** + * NOT IN THE API, only here to do the dev about the display of the category (intermediate level displayed filling configuration + * + */ + public static final boolean DISPLAY_CATEOGORY = HierarchicalRowLabelHeaderDataProvider.DISPLAY_CATEOGORY; + + + /** + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param objectToAdd + * @return + */ + @Override + public Command getAddAxisCommand(TransactionalEditingDomain domain, Collection<Object> objectToAdd) { + final Collection<IAxis> toAdd = new ArrayList<IAxis>(); + for (final Object object : objectToAdd) { + if (isAllowedContents(object, null, null, 0) && !isAlreadyManaged(object)) { + final EObjectAxis horizontalAxis = NattableaxisFactory.eINSTANCE.createEObjectTreeItemAxis(); + horizontalAxis.setElement((EObject) object); + horizontalAxis.setManager(this.representedAxisManager); + toAdd.add(horizontalAxis); + } + } + if (!toAdd.isEmpty()) { + return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd); + } + return null; + } + + + + /** + * @param objectToTest + * @param depth + * @see org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisManagerForEventList#isAllowedContents(java.lang.Object, Object, TreeFillingConfiguration, int) + * + * @return + */ + @Override + public boolean isAllowedContents(Object objectToTest, Object semanticParent, TreeFillingConfiguration conf, int depth) { + if (objectToTest instanceof EObject) { + return true; + } + return false; + } + + /** + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList#isAllowedContents(java.lang.Object) + * + * @param object + * @return + * @deprecated + */ + @Override + public boolean isAllowedContents(Object object) { + return object instanceof EObject; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList#createITreeItemAxis(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis, java.lang.Object) + * + * @param parentAxis + * @param objectToAdd + * @return + */ + protected ITreeItemAxis createITreeItemAxis(ITreeItemAxis parentAxis, Object objectToAdd) { + return ITreeItemAxisHelper.createITreeItemAxis(getTableEditingDomain(), parentAxis, objectToAdd, this.representedAxisManager); + } + + + /** + * + * @param notification + * a notification + * @return + * <code>true</code> if the notification must be ignored + */ + protected boolean ignoreEvent(final Notification notification) { + boolean res = super.ignoreEvent(notification); + if (res) { + return res; + } + Object notifier = notification.getNotifier(); + Object feature = notification.getFeature(); + if (feature == null) { + return true; + } + if (notifier instanceof PageRef || notifier instanceof Window) { + return true; + } + + + // I am not sure of the end of this method + // List<EStructuralFeature> listenFeature = new ArrayList<EStructuralFeature>(); + // List<TreeFillingConfiguration> confs = FillingConfigurationUtils.getTreeFillingConfiguration(getTable(), representedAxisManager); + // boolean derivedFeature = false; + // for (TreeFillingConfiguration conf : confs) { + // IAxis axis = conf.getAxisUsedAsAxisProvider(); + // if (axis instanceof EStructuralFeatureAxis) { + // EStructuralFeature f = (EStructuralFeature) axis.getElement(); + // derivedFeature = derivedFeature || f.isDerived(); + // if (derivedFeature) { + // return false; + // } + // } + // } + // if (listenFeature.contains(feature)) { + // return false; + // } + // + // if (confs.size() == listenFeature.size()) { + // return false; + // } + // return true; + return false; + } +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EOperationAxisManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EOperationAxisManager.java index 40818f14b1b..90902021e1a 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EOperationAxisManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EOperationAxisManager.java @@ -1,174 +1,175 @@ -/*****************************************************************************
- * Copyright (c) 2015 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
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.emf.nattable.manager.axis;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.UnexecutableCommand;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EOperationAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
-
-/**
- * @author Céline JANSSENS
- *
- */
-public class EOperationAxisManager extends EObjectAxisManager {
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canBeSavedAsConfig()
- *
- * @return
- */
- @Override
- public boolean canBeSavedAsConfig() {
- return true;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer)
- *
- * @param axisPosition
- * @return
- */
- @Override
- public boolean canDestroyAxisElement(Integer axisPosition) {
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canEditAxisHeader()
- *
- * @return
- */
- @Override
- public boolean canEditAxisHeader() {
- return true;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final Collection<IAxis> toAdd = new ArrayList<IAxis>();
- for (final Object current : objectToAdd) {
- if (isAllowedContents(current) && !isAlreadyManaged(current)) {
- final EOperationAxis newAxis = NattableaxisFactory.eINSTANCE.createEOperationAxis();
- newAxis.setElement((EOperation) current);
- newAxis.setManager(this.representedAxisManager);
- toAdd.add(newAxis);
- }
- }
- if (!toAdd.isEmpty()) {
- return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd);
- }
- return null;
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final Set<Object> features = new HashSet<Object>();
- for (final Object current : objectToAdd) {
- if (current instanceof EObject) {
- features.addAll(((EObject) current).eClass().getEAllStructuralFeatures());
- }
- }
- features.removeAll(getElements());
- if (!features.isEmpty()) {
- return getAddAxisCommand(domain, features);
- }
- return null;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.Integer)
- *
- * @param domain
- * @param axisPosition
- * @return
- */
- @Override
- public Command getDestroyAxisElementCommand(final TransactionalEditingDomain domain, final Integer axisPosition) {
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
- *
- * @param axis
- * @return
- */
- @Override
- public String getElementAxisName(IAxis axis) {
- if (axis instanceof EOperationAxis) {
- return ((EOperationAxis) axis).getElement().getName();
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAllowedContents(Object object) {
- return object instanceof EOperation;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave()
- *
- * @return
- */
- @Override
- public boolean isSlave() {
- return true;
- }
-}
+/***************************************************************************** + * Copyright (c) 2015 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 + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.emf.nattable.manager.axis; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.UnexecutableCommand; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EOperation; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EOperationAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage; + +/** + * @author Céline JANSSENS + * + */ +public class EOperationAxisManager extends EObjectAxisManager { + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canBeSavedAsConfig() + * + * @return + */ + @Override + public boolean canBeSavedAsConfig() { + return true; + } + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer) + * + * @param axisPosition + * @return + */ + @Override + public boolean canDestroyAxisElement(Integer axisPosition) { + return false; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canEditAxisHeader() + * + * @return + */ + @Override + public boolean canEditAxisHeader() { + return true; + } + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param objectToAdd + * @return + */ + @Override + public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) { + final Collection<IAxis> toAdd = new ArrayList<IAxis>(); + for (final Object current : objectToAdd) { + if (isAllowedContents(current) && !isAlreadyManaged(current)) { + final EOperationAxis newAxis = NattableaxisFactory.eINSTANCE.createEOperationAxis(); + newAxis.setElement((EOperation) current); + newAxis.setManager(this.representedAxisManager); + toAdd.add(newAxis); + managedObject.add(current); + } + } + if (!toAdd.isEmpty()) { + return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd); + } + return null; + } + + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param objectToAdd + * @return + */ + @Override + public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) { + final Set<Object> features = new HashSet<Object>(); + for (final Object current : objectToAdd) { + if (current instanceof EObject) { + features.addAll(((EObject) current).eClass().getEAllStructuralFeatures()); + } + } + features.removeAll(getElements()); + if (!features.isEmpty()) { + return getAddAxisCommand(domain, features); + } + return null; + } + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.Integer) + * + * @param domain + * @param axisPosition + * @return + */ + @Override + public Command getDestroyAxisElementCommand(final TransactionalEditingDomain domain, final Integer axisPosition) { + return UnexecutableCommand.INSTANCE; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis) + * + * @param axis + * @return + */ + @Override + public String getElementAxisName(IAxis axis) { + if (axis instanceof EOperationAxis) { + return ((EOperationAxis) axis).getElement().getName(); + } + return null; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object) + * + * @param object + * @return + */ + @Override + public boolean isAllowedContents(Object object) { + return object instanceof EOperation; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave() + * + * @return + */ + @Override + public boolean isSlave() { + return true; + } +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EStructuralFeatureAxisManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EStructuralFeatureAxisManager.java index c31c519b7c8..64f0955b33e 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EStructuralFeatureAxisManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EStructuralFeatureAxisManager.java @@ -1,193 +1,194 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.emf.nattable.manager.axis;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.UnexecutableCommand;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EStructuralFeatureAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
-
-/**
- * the axis manager for EStructuralFeature
- *
- * @author Vincent Lorenzo
- *
- */
-public class EStructuralFeatureAxisManager extends EObjectAxisManager {
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canBeSavedAsConfig()
- *
- * @return
- */
- @Override
- public boolean canBeSavedAsConfig() {
- return true;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer)
- *
- * @param axisPosition
- * @return
- */
- @Override
- public boolean canDestroyAxisElement(Integer axisPosition) {
- return false;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canEditAxisHeader()
- *
- * @return
- */
- @Override
- public boolean canEditAxisHeader() {
- return true;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final Collection<IAxis> toAdd = new ArrayList<IAxis>();
- for (final Object current : objectToAdd) {
- if (isAllowedContents(current) && !isAlreadyManaged(current)) {
- final EStructuralFeatureAxis newAxis = NattableaxisFactory.eINSTANCE.createEStructuralFeatureAxis();
- newAxis.setElement((EStructuralFeature) current);
- newAxis.setManager(this.representedAxisManager);
- toAdd.add(newAxis);
- }
- }
- if (!toAdd.isEmpty()) {
- return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd);
- }
- return null;
- }
-
- /**
- * calculus of the contents of the axis
- */
-
- public Collection<Object> getAllPossibleAxis() {
- Set<Object> objects = new HashSet<Object>();
- for (final Object current : getAllManagedAxis()) {
- EClass eClass = (EClass) current;
- EPackage ePackage = eClass.getEPackage();
- if (!eClass.getEStructuralFeatures().isEmpty()) {
- objects.add(ePackage);
- }
- }
- return objects;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final Set<Object> features = new HashSet<Object>();
- for (final Object current : objectToAdd) {
- if (current instanceof EObject) {
- features.addAll(((EObject) current).eClass().getEAllStructuralFeatures());
- }
- }
- features.removeAll(getElements());
- if (!features.isEmpty()) {
- return getAddAxisCommand(domain, features);
- }
- return null;
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.Integer)
- *
- * @param domain
- * @param axisPosition
- * @return
- */
- @Override
- public Command getDestroyAxisElementCommand(final TransactionalEditingDomain domain, final Integer axisPosition) {
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis)
- *
- * @param axis
- * @return
- */
- @Override
- public String getElementAxisName(IAxis axis) {
- if (axis instanceof EStructuralFeatureAxis) {
- return ((EStructuralFeatureAxis) axis).getElement().getName();
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAllowedContents(Object object) {
- return object instanceof EStructuralFeature;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave()
- *
- * @return
- */
- @Override
- public boolean isSlave() {
- return true;
- }
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.emf.nattable.manager.axis; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.UnexecutableCommand; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EStructuralFeatureAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage; + +/** + * the axis manager for EStructuralFeature + * + * @author Vincent Lorenzo + * + */ +public class EStructuralFeatureAxisManager extends EObjectAxisManager { + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canBeSavedAsConfig() + * + * @return + */ + @Override + public boolean canBeSavedAsConfig() { + return true; + } + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canDestroyAxisElement(java.lang.Integer) + * + * @param axisPosition + * @return + */ + @Override + public boolean canDestroyAxisElement(Integer axisPosition) { + return false; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#canEditAxisHeader() + * + * @return + */ + @Override + public boolean canEditAxisHeader() { + return true; + } + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param objectToAdd + * @return + */ + @Override + public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) { + final Collection<IAxis> toAdd = new ArrayList<IAxis>(); + for (final Object current : objectToAdd) { + if (isAllowedContents(current) && !isAlreadyManaged(current)) { + final EStructuralFeatureAxis newAxis = NattableaxisFactory.eINSTANCE.createEStructuralFeatureAxis(); + newAxis.setElement((EStructuralFeature) current); + newAxis.setManager(this.representedAxisManager); + toAdd.add(newAxis); + managedObject.add(current); + } + } + if (!toAdd.isEmpty()) { + return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd); + } + return null; + } + + /** + * calculus of the contents of the axis + */ + + public Collection<Object> getAllPossibleAxis() { + Set<Object> objects = new HashSet<Object>(); + for (final Object current : getAllManagedAxis()) { + EClass eClass = (EClass) current; + EPackage ePackage = eClass.getEPackage(); + if (!eClass.getEStructuralFeatures().isEmpty()) { + objects.add(ePackage); + } + } + return objects; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param objectToAdd + * @return + */ + @Override + public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) { + final Set<Object> features = new HashSet<Object>(); + for (final Object current : objectToAdd) { + if (current instanceof EObject) { + features.addAll(((EObject) current).eClass().getEAllStructuralFeatures()); + } + } + features.removeAll(getElements()); + if (!features.isEmpty()) { + return getAddAxisCommand(domain, features); + } + return null; + } + + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisElementCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.Integer) + * + * @param domain + * @param axisPosition + * @return + */ + @Override + public Command getDestroyAxisElementCommand(final TransactionalEditingDomain domain, final Integer axisPosition) { + return UnexecutableCommand.INSTANCE; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getElementAxisName(org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis) + * + * @param axis + * @return + */ + @Override + public String getElementAxisName(IAxis axis) { + if (axis instanceof EStructuralFeatureAxis) { + return ((EStructuralFeatureAxis) axis).getElement().getName(); + } + return null; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#isAllowedContents(java.lang.Object) + * + * @param object + * @return + */ + @Override + public boolean isAllowedContents(Object object) { + return object instanceof EStructuralFeature; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#isSlave() + * + * @return + */ + @Override + public boolean isSlave() { + return true; + } +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java index ba3ac9d785c..d8a673e9f62 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractAxisManager.java @@ -9,6 +9,7 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 469289 * *****************************************************************************/ package org.eclipse.papyrus.infra.nattable.manager.axis; @@ -96,7 +97,7 @@ public abstract class AbstractAxisManager implements IAxisManager { /** * * @return - * a new managed object list + * a new managed object list */ protected List<Object> createManagedObjectList() { return new ArrayList<Object>(); @@ -348,15 +349,16 @@ public abstract class AbstractAxisManager implements IAxisManager { } /** + * This allows to check if the object is already managed. * * @param object * an object * @return - * <code>true</code> if the object is already displayed + * <code>true</code> if the object is already displayed, <code>false</code> otherwise. */ @Override public boolean isAlreadyManaged(final Object object) { - return getElements().contains(object); + return managedObject.contains(object); } /** @@ -415,7 +417,7 @@ public abstract class AbstractAxisManager implements IAxisManager { /** * * @return - * the context of the managed table + * the context of the managed table */ protected final EObject getTableContext() { return this.tableContext; @@ -445,7 +447,7 @@ public abstract class AbstractAxisManager implements IAxisManager { */ protected TransactionalEditingDomain getTableEditingDomain() {// Duplicated from NatTableModelManager ServicesRegistry registry = null; - if(null != getTableManager() && null != getTableManager().getTable() && null != getTableManager().getTable().eResource()){ + if (null != getTableManager() && null != getTableManager().getTable() && null != getTableManager().getTable().eResource()) { try { registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(getTableManager().getTable()); return registry.getService(TransactionalEditingDomain.class); @@ -620,7 +622,7 @@ public abstract class AbstractAxisManager implements IAxisManager { * @param axisPositions * axis positions * @return - * the elements located at these axis position + * the elements located at these axis position */ protected List<Object> getElements(final List<Integer> axisPositions) { final List<Object> elements = getElements(); @@ -652,7 +654,7 @@ public abstract class AbstractAxisManager implements IAxisManager { /** * * @return - * the list owning the elements displayed on the managed axis + * the list owning the elements displayed on the managed axis */ protected final List<Object> getElements() { if (isUsedAsColumnManager()) { diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypePropertyAxisManager.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypePropertyAxisManager.java index bf5587ca83e..31f9dca550f 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypePropertyAxisManager.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/UMLStereotypePropertyAxisManager.java @@ -1,230 +1,234 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.nattable.manager.axis;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.nattable.manager.axis.IIdAxisManager;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage;
-import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider;
-import org.eclipse.papyrus.uml.nattable.provider.UMLStereotypeRestrictedPropertyContentProvider;
-import org.eclipse.papyrus.uml.nattable.utils.Constants;
-import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
-import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-
-/**
- * This axis manager provides the axis for properties of stereotypes
- *
- * @author Vincent Lorenzo
- *
- */
-public class UMLStereotypePropertyAxisManager extends UMLFeatureAxisManager implements IIdAxisManager {
-
- /**
- *
- * @see org.eclipse.papyrus.uml.nattable.manager.axis.UMLFeatureAxisManager#isAllowedContents(java.lang.Object)
- *
- * @param object
- * @return
- */
- @Override
- public boolean isAllowedContents(Object object) {
- boolean result = false;
- if (object instanceof Property) {
- final Property prop = (Property) object;
- Element owner = prop.getOwner();
- if (owner instanceof Stereotype) {
- while(owner.getOwner() instanceof Package && !result){
- owner = owner.getOwner();
- result = owner instanceof Profile;
- }
- if (result) {
- result = EMFHelper.isReadOnly(prop);
- }
- }
- }
- return result;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final Set<Stereotype> appliedStereotypes = new HashSet<Stereotype>();
- for (final Object current : objectToAdd) {
- if (current instanceof Element) {
- appliedStereotypes.addAll(((Element) current).getAppliedStereotypes());
- }
- }
- final Set<Object> propertiesToAdd = new HashSet<Object>();
-
- for (final Stereotype stereotype : appliedStereotypes) {
- propertiesToAdd.addAll(StereotypeUtil.getAllStereotypePropertiesWithoutBaseProperties(stereotype));
- }
- if (!propertiesToAdd.isEmpty()) {
- return getAddAxisCommand(domain, propertiesToAdd);
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param objectToAdd
- * @return
- */
- @Override
- public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) {
- final List<String> allPropertyQN = new ArrayList<String>();
- for (Object object : objectToAdd) {
- if (isAllowedContents(object)) {
- allPropertyQN.add(Constants.PROPERTY_OF_STEREOTYPE_PREFIX + ((NamedElement) object).getQualifiedName());
- }
- }
- allPropertyQN.removeAll(getElements());
- if (!allPropertyQN.isEmpty()) {
- final Collection<IAxis> toAdd = new ArrayList<IAxis>();
- for (String propQN : allPropertyQN) {
- final IdAxis newAxis = NattableaxisFactory.eINSTANCE.createFeatureIdAxis();
- newAxis.setElement(propQN);
- newAxis.setManager(this.representedAxisManager);
- toAdd.add(newAxis);
- }
- return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd);
- }
- return null;
- }
-
-
- /**
- * return the content provider for the stereotypes properties
- */
- @Override
- public IRestrictedContentProvider createPossibleAxisContentProvider(boolean isRestricted) {
- return new UMLStereotypeRestrictedPropertyContentProvider(this, isRestricted);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.nattable.manager.axis.UMLFeatureAxisManager#getAllPossibleAxis()
- *
- * @return
- */
- @Override
- public Collection<Object> getAllPossibleAxis() {
- return getRootProfiles();
- }
-
- /**
- *
- * @return
- * the list of the root profiles availables in the model
- */
- private Collection<Object> getRootProfiles() {
- EObject context = ((INattableModelManager) getTableManager()).getTable().getContext();
- assert context instanceof Element;
-
- final List<Profile> allAppliedProfiles = ((Element) context).getNearestPackage().getAllAppliedProfiles();
- final Collection<Object> profiles = new HashSet<Object>();
- for (Profile profile : allAppliedProfiles) {
- EObject rootContainer = EcoreUtil.getRootContainer(profile);
- profiles.add(rootContainer);
- }
- return profiles;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisCommand(TransactionalEditingDomain, java.util.Collection)
- *
- * @param domain
- * @param umlProperties
- * the UML Property for which we want destroy axis
- * @return
- */
- @Override
- public Command getDestroyAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> umlProperties) {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getRepresentedContentProvider());
- final CompositeCommand compositeCommand = new CompositeCommand("Destroy IAxis Command"); //$NON-NLS-1$
- final List<String> propIdToDestroy = new ArrayList<String>();
- for (final Object current : umlProperties) {
- if (current instanceof Property && ((Property) current).eContainer() instanceof Stereotype) {
- propIdToDestroy.add(Constants.PROPERTY_OF_STEREOTYPE_PREFIX + ((NamedElement) current).getQualifiedName());
- }
- }
-
- for (final IAxis current : getRepresentedContentProvider().getAxis()) {
- if (current instanceof IdAxis) {
- String propId = AxisUtils.getPropertyId(current);
- if (propIdToDestroy.contains(propId)) {
- DestroyElementRequest request = new DestroyElementRequest(domain, current, false);
- compositeCommand.add(provider.getEditCommand(request));
- }
- }
- }
-
- if (!compositeCommand.isEmpty()) {
- return new GMFtoEMFCommandWrapper(compositeCommand);
- }
- return null;
- }
-
- /**
- *
- * @param path
- * @return
- */
- @Override
- public Object resolvedPath(final String path) {
- if (path.startsWith(Constants.PROPERTY_OF_STEREOTYPE_PREFIX)) {
- return UMLTableUtils.getRealStereotypeProperty(getTableContext(), path);
- }
- return null;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.nattable.manager.axis; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.nattable.manager.axis.IIdAxisManager; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage; +import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; +import org.eclipse.papyrus.uml.nattable.provider.UMLStereotypeRestrictedPropertyContentProvider; +import org.eclipse.papyrus.uml.nattable.utils.Constants; +import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils; +import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * This axis manager provides the axis for properties of stereotypes + * + * @author Vincent Lorenzo + * + */ +public class UMLStereotypePropertyAxisManager extends UMLFeatureAxisManager implements IIdAxisManager { + + /** + * + * @see org.eclipse.papyrus.uml.nattable.manager.axis.UMLFeatureAxisManager#isAllowedContents(java.lang.Object) + * + * @param object + * @return + */ + @Override + public boolean isAllowedContents(Object object) { + boolean result = false; + if (object instanceof Property) { + final Property prop = (Property) object; + Element owner = prop.getOwner(); + if (owner instanceof Stereotype) { + while(owner.getOwner() instanceof Package && !result){ + owner = owner.getOwner(); + result = owner instanceof Profile; + } + if (result) { + result = EMFHelper.isReadOnly(prop); + } + } + } + return result; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getComplementaryAddAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param objectToAdd + * @return + */ + @Override + public Command getComplementaryAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) { + final Set<Stereotype> appliedStereotypes = new HashSet<Stereotype>(); + for (final Object current : objectToAdd) { + if (current instanceof Element) { + appliedStereotypes.addAll(((Element) current).getAppliedStereotypes()); + } + } + final Set<Object> propertiesToAdd = new HashSet<Object>(); + + for (final Stereotype stereotype : appliedStereotypes) { + propertiesToAdd.addAll(StereotypeUtil.getAllStereotypePropertiesWithoutBaseProperties(stereotype)); + } + if (!propertiesToAdd.isEmpty()) { + return getAddAxisCommand(domain, propertiesToAdd); + } + return null; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param objectToAdd + * @return + */ + @Override + public Command getAddAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> objectToAdd) { + final List<String> allPropertyQN = new ArrayList<String>(); + for (Object object : objectToAdd) { + if (isAllowedContents(object)) { + allPropertyQN.add(Constants.PROPERTY_OF_STEREOTYPE_PREFIX + ((NamedElement) object).getQualifiedName()); + } + } + allPropertyQN.removeAll(getElements()); + if (!allPropertyQN.isEmpty()) { + final Collection<IAxis> toAdd = new ArrayList<IAxis>(); + for (String propQN : allPropertyQN) { + final IdAxis newAxis = NattableaxisFactory.eINSTANCE.createFeatureIdAxis(); + newAxis.setElement(propQN); + newAxis.setManager(this.representedAxisManager); + toAdd.add(newAxis); + managedObject.add(propQN); + } + + if(!toAdd.isEmpty()){ + return AddCommand.create(domain, getRepresentedContentProvider(), NattableaxisproviderPackage.eINSTANCE.getAxisProvider_Axis(), toAdd); + } + } + return null; + } + + + /** + * return the content provider for the stereotypes properties + */ + @Override + public IRestrictedContentProvider createPossibleAxisContentProvider(boolean isRestricted) { + return new UMLStereotypeRestrictedPropertyContentProvider(this, isRestricted); + } + + /** + * + * @see org.eclipse.papyrus.uml.nattable.manager.axis.UMLFeatureAxisManager#getAllPossibleAxis() + * + * @return + */ + @Override + public Collection<Object> getAllPossibleAxis() { + return getRootProfiles(); + } + + /** + * + * @return + * the list of the root profiles availables in the model + */ + private Collection<Object> getRootProfiles() { + EObject context = ((INattableModelManager) getTableManager()).getTable().getContext(); + assert context instanceof Element; + + final List<Profile> allAppliedProfiles = ((Element) context).getNearestPackage().getAllAppliedProfiles(); + final Collection<Object> profiles = new HashSet<Object>(); + for (Profile profile : allAppliedProfiles) { + EObject rootContainer = EcoreUtil.getRootContainer(profile); + profiles.add(rootContainer); + } + return profiles; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManager#getDestroyAxisCommand(TransactionalEditingDomain, java.util.Collection) + * + * @param domain + * @param umlProperties + * the UML Property for which we want destroy axis + * @return + */ + @Override + public Command getDestroyAxisCommand(final TransactionalEditingDomain domain, final Collection<Object> umlProperties) { + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getRepresentedContentProvider()); + final CompositeCommand compositeCommand = new CompositeCommand("Destroy IAxis Command"); //$NON-NLS-1$ + final List<String> propIdToDestroy = new ArrayList<String>(); + for (final Object current : umlProperties) { + if (current instanceof Property && ((Property) current).eContainer() instanceof Stereotype) { + propIdToDestroy.add(Constants.PROPERTY_OF_STEREOTYPE_PREFIX + ((NamedElement) current).getQualifiedName()); + } + } + + for (final IAxis current : getRepresentedContentProvider().getAxis()) { + if (current instanceof IdAxis) { + String propId = AxisUtils.getPropertyId(current); + if (propIdToDestroy.contains(propId)) { + DestroyElementRequest request = new DestroyElementRequest(domain, current, false); + compositeCommand.add(provider.getEditCommand(request)); + } + } + } + + if (!compositeCommand.isEmpty()) { + return new GMFtoEMFCommandWrapper(compositeCommand); + } + return null; + } + + /** + * + * @param path + * @return + */ + @Override + public Object resolvedPath(final String path) { + if (path.startsWith(Constants.PROPERTY_OF_STEREOTYPE_PREFIX)) { + return UMLTableUtils.getRealStereotypeProperty(getTableContext(), path); + } + return null; + } + +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.di b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.di new file mode 100644 index 00000000000..bf9abab340f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.di @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.notation b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.notation new file mode 100644 index 00000000000..853ea03a885 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.notation @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<nattable:Table xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:configuration="http://www.eclipse.org/papyrus/infra/viewpoints/configuration" xmlns:nattable="http://www.eclipse.org/papyrus/nattable/model" xmlns:nattableaxisprovider="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider" xmlns:nattableconfiguration="http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model#//nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration http://www.eclipse.org/papyrus/nattable/model#//nattableconfiguration" xmi:id="_PRZJwEzEEeW93Jjse9krAA" name="GenericTable0" currentRowAxisProvider="_PRZJwkzEEeW93Jjse9krAA" currentColumnAxisProvider="_PRZJwUzEEeW93Jjse9krAA"> + <context xmi:type="uml:Model" href="AddElementsOnConnectedTableTest.uml#_K-ZqkEzEEeW93Jjse9krAA"/> + <owner xmi:type="uml:Model" href="AddElementsOnConnectedTableTest.uml#_K-ZqkEzEEeW93Jjse9krAA"/> + <prototype xmi:type="configuration:PapyrusSyncTable" href="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/builtin/default.configuration#_7wNb2NxhEeOqHvRyiN87hA"/> + <tableConfiguration xmi:type="nattableconfiguration:TableConfiguration" href="platform:/plugin/org.eclipse.papyrus.uml.nattable.generic.config/configs/generic.nattableconfiguration#/"/> + <columnAxisProvidersHistory xmi:type="nattableaxisprovider:SlaveObjectAxisProvider" xmi:id="_PRZJwUzEEeW93Jjse9krAA" description="This axis provider provides available columns according to the rows of the table (features of the object displayed on the other axis)" name="UML Feature axis provider"/> + <rowAxisProvidersHistory xmi:type="nattableaxisprovider:MasterObjectAxisProvider" xmi:id="_PRZJwkzEEeW93Jjse9krAA" description="This axis provider contains the object dropped by the user into the table" name="DroppedElementAxisProvider"/> +</nattable:Table> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.uml b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.uml new file mode 100644 index 00000000000..2cf98cfd2f1 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/resources/bugs/bug469289/AddElementsOnConnectedTableTest.uml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_K-ZqkEzEEeW93Jjse9krAA" name="RootElement"/> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/bugs/AddElementsOnConnectedTableTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/bugs/AddElementsOnConnectedTableTest.java new file mode 100644 index 00000000000..6509064d363 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/bugs/AddElementsOnConnectedTableTest.java @@ -0,0 +1,273 @@ +/***************************************************************************** + * Copyright (c) 2015 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: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.nattable.generic.tests.bugs; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.IHandler; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.tools.util.EclipseCommandUtils; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.TableUtils; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.junit.utils.rules.ShowView; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.uml2.uml.Model; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +/** + * This allows to test the adding object to connected table (features are created as columns table). + */ +@PluginResource("resources/bugs/bug469289/AddElementsOnConnectedTableTest.di") +@ShowView(value = "org.eclipse.papyrus.views.modelexplorer.modelexplorer") +public class AddElementsOnConnectedTableTest extends AbstractPapyrusTest { + + /** + * The table name. + */ + private static final String TABLE_NAME = "GenericTable0"; //$NON-NLS-1$ + + /** + * The number of class features. + */ + private static final int NB_CLASS_FEATURES = 51; + + /** + * The number of interface features. + */ + private static final int NB_INTERFACE_FEATURES = 6; + + /** + * The number of empty axis (equals to 0). + */ + private static final int NB_EMPTY_AXIS = 0; + + /** + * The command id for the class creation. + */ + private static final String CREATE_CLASS_COMMAND = "org.eclipse.papyrus.uml.service.types.ClassCreateCommand"; //$NON-NLS-1$ + + /** + * The command id for the interface creation. + */ + private static final String CREATE_INTERFACE_COMMAND = "org.eclipse.papyrus.uml.service.types.InterfaceCreateCommand"; //$NON-NLS-1$ + + + /** + * The papyrus fixture. + */ + @Rule + public final PapyrusEditorFixture fixture = new PapyrusEditorFixture(); + + + /** + * Constructor. + */ + public AddElementsOnConnectedTableTest() { + super(); + } + + /** + * This allows to test add of elements in table . + * + * @throws Exception + * The exception + */ + @Test + public void testAddElements() throws Exception { + final Model model = (Model) fixture.getModel(); + Assert.assertNotNull("RootModel is null", model); //$NON-NLS-1$ + + // Get the table and open it + Table mainTable = TableUtils.getNotationFirstTable(fixture.getModelSet(), TABLE_NAME); + fixture.getPageManager().openPage(mainTable); + fixture.flushDisplayEvents(); + IEditorPart part = fixture.getEditor().getActiveEditor(); + Assert.assertTrue("The part must be a nattable editor", part instanceof NatTableEditor); //$NON-NLS-1$ + NatTableEditor editor = (NatTableEditor) part; + INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Check that the table is empty + List<?> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must be empty", NB_EMPTY_AXIS, rowElements.size()); //$NON-NLS-1$ + List<?> columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must be empty", NB_EMPTY_AXIS, columnElements.size()); //$NON-NLS-1$ + + // Get the command service + final ICommandService commandService = EclipseCommandUtils.getCommandService(); + Assert.assertNotNull(commandService); + + + // Create a class + createClassElement(commandService); + + // Check the rows and columns size + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the created class", 1, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class structural features", NB_CLASS_FEATURES, columnElements.size()); //$NON-NLS-1$ + + // Undo the creation of the class + editingDomain.getCommandStack().undo(); + fixture.flushDisplayEvents(); + + // check that the table is empty with the class deletion + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must be empty", NB_EMPTY_AXIS, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must be empty", NB_EMPTY_AXIS, columnElements.size()); //$NON-NLS-1$ + + // Redo the creation of the class + editingDomain.getCommandStack().redo(); + fixture.flushDisplayEvents(); + + // Check the rows and columns size + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the created class", 1, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class structural features", NB_CLASS_FEATURES, columnElements.size()); //$NON-NLS-1$ + + + // Create an other class + createClassElement(commandService); + + // Check the rows and columns size + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the created class and the existing class", 2, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class structural features (without doubloon)", NB_CLASS_FEATURES, columnElements.size()); //$NON-NLS-1$ + + // Undo the creation of the class + editingDomain.getCommandStack().undo(); + fixture.flushDisplayEvents(); + + // check that the table is empty with the class deletion + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the existing class", 1, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class structural features", NB_CLASS_FEATURES, columnElements.size()); //$NON-NLS-1$ + + // Redo the creation of the class + editingDomain.getCommandStack().redo(); + fixture.flushDisplayEvents(); + + // Check the rows and columns size + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the created class and the existing class", 2, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class structural features (without doubloon)", NB_CLASS_FEATURES, columnElements.size()); //$NON-NLS-1$ + + + // Create an interface + createInterfaceElement(commandService); + + // Check the rows and columns size + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the created interface and the existing classes", 3, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class and interface structural features (without doubloon)", NB_CLASS_FEATURES + NB_INTERFACE_FEATURES, columnElements.size()); //$NON-NLS-1$ + + // Undo the creation of the class + editingDomain.getCommandStack().undo(); + fixture.flushDisplayEvents(); + + // check that the table is empty with the class deletion + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the created class and the existing class", 2, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class structural features (without doubloon)", NB_CLASS_FEATURES, columnElements.size()); //$NON-NLS-1$ + + // Redo the creation of the class + editingDomain.getCommandStack().redo(); + fixture.flushDisplayEvents(); + + // Check the rows and columns size + rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The rows must contain the created interface and the existing classes", 3, rowElements.size()); //$NON-NLS-1$ + columnElements = currentManager.getColumnElementsList(); + Assert.assertEquals("The columns must contain the class and interface structural features (without doubloon)", NB_CLASS_FEATURES + NB_INTERFACE_FEATURES, columnElements.size()); //$NON-NLS-1$ + } + + /** + * This allow to create a class element in the table from the contextual menu. + * + * @param commandService + * The command service. + * @throws Exception + * The exception. + */ + private void createClassElement(final ICommandService commandService) throws Exception { + final EObject createdObject = getcreatedElement(commandService, CREATE_CLASS_COMMAND); + Assert.assertTrue("The created object must be a class", createdObject instanceof org.eclipse.uml2.uml.Class); //$NON-NLS-1$ + } + + /** + * This allow to create an interface element in the table from the contextual menu. + * + * @param commandService + * The command service. + * @throws Exception + * The exception. + */ + private void createInterfaceElement(final ICommandService commandService) throws Exception { + final EObject createdObject = getcreatedElement(commandService, CREATE_INTERFACE_COMMAND); + Assert.assertTrue("The created object must be an interface", createdObject instanceof org.eclipse.uml2.uml.Interface); //$NON-NLS-1$ + } + + /** + * Get the command from the command id an return its created element. + * + * @param commandService + * The command service. + * @param commandId + * The command is. + * @return The created element. + * @throws Exception + * The exception. + */ + protected EObject getcreatedElement(final ICommandService commandService, final String commandId) throws Exception { + // Get the command and the handler + final Command cmd = commandService.getCommand(commandId); + IHandler handler = cmd.getHandler(); + Assert.assertTrue("The command handler must be enabled for the creation", handler.isEnabled()); //$NON-NLS-1$ + + // Execute the command with the correct parameter and check its result + final ExecutionEvent event = new ExecutionEvent(cmd, Collections.EMPTY_MAP, null, null); + Object res = cmd.executeWithChecks(event); + fixture.flushDisplayEvents(); + Assert.assertTrue("Result of creation command must be a list", res instanceof List); //$NON-NLS-1$ + final List<?> resList = (List<?>) res; + Assert.assertEquals("Only one list must be created", 1, resList.size()); //$NON-NLS-1$ + Assert.assertTrue("The first object of the list must be the list of created elements", resList.get(0) instanceof List); //$NON-NLS-1$ + final List<?> createdClasses = (List<?>) resList.get(0); + Assert.assertEquals("Only one element must be created", 1, createdClasses.size()); //$NON-NLS-1$ + Assert.assertTrue("The created object must be an Element", createdClasses.get(0) instanceof org.eclipse.uml2.uml.Element); //$NON-NLS-1$ + return (EObject) createdClasses.get(0); + } +} diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java index 55240328df0..ab19410c99b 100755 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AllTests.java @@ -14,6 +14,7 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.generic.tests.tests; +import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AddElementsOnConnectedTableTest; import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AxisChangeIndexWithConfigurationTest; import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AxisChangeIndexWithoutConfigurationTest; import org.eclipse.papyrus.uml.nattable.generic.tests.bugs.InvertedAxisChangeIndexWithConfigurationTest; @@ -29,6 +30,7 @@ import org.junit.runners.Suite.SuiteClasses; InvertAxisGenericTableTest.class, EditAxisGenericTableTest.class, OpenAndDeleteTest.class, + AddElementsOnConnectedTableTest.class, Bug458492_Edition_Enumeration.class, AxisChangeIndexWithConfigurationTest.class, AxisChangeIndexWithoutConfigurationTest.class, |