diff options
author | Nicolas FAUVERGUE | 2015-12-10 11:29:02 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-02-02 15:16:10 +0000 |
commit | c8e552daf57bf096d2a97313f306dfba0c299271 (patch) | |
tree | 88d700d21fae7fa6d8acdc1ad5906e7b16e47640 /plugins/infra | |
parent | 226e836e3c1e00d8f84179959426ca36a9f12d7b (diff) | |
download | org.eclipse.papyrus-c8e552daf57bf096d2a97313f306dfba0c299271.tar.gz org.eclipse.papyrus-c8e552daf57bf096d2a97313f306dfba0c299271.tar.xz org.eclipse.papyrus-c8e552daf57bf096d2a97313f306dfba0c299271.zip |
Bug 455060: [Tree Table] Papyrus must provide a way to configure the
paste in the tree table
https://bugs.eclipse.org/bugs/show_bug.cgi?id=455060
Add the paste configurations manager page which allow to edit the paste
configurations.
For the depth 0 filled by user, the paste configuration must be managed
directly on the first depth item.
The containment feature are managed differently depending to the depth :
- Depth 0 : The context table structural features
- Other depths : All the structural features are proposed.
Change-Id: I19651b8d8ad5724c512ed9449ee1f45647a46b02
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins/infra')
20 files changed, 1445 insertions, 618 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java index 2e0a40d3f40..35c728c2f00 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java @@ -30,6 +30,13 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.papyrus.infra.emf.nattable.selection.EObjectSelectionExtractor; +import org.eclipse.papyrus.infra.nattable.contentprovider.ColumnAxisIdentifierContentProvider; +import org.eclipse.papyrus.infra.nattable.contentprovider.ColumnContainmentFeatureContentProvider; +import org.eclipse.papyrus.infra.nattable.contentprovider.ColumnElementTypeIdContentProvider; +import org.eclipse.papyrus.infra.nattable.contentprovider.ContextFeatureContentProvider; +import org.eclipse.papyrus.infra.nattable.contentprovider.RowAxisIdentifierContentProvider; +import org.eclipse.papyrus.infra.nattable.contentprovider.RowContainmentFeatureContentProvider; +import org.eclipse.papyrus.infra.nattable.contentprovider.RowElementTypeIdContentProvider; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.model.nattable.NattablePackage; import org.eclipse.papyrus.infra.nattable.model.nattable.Table; @@ -71,14 +78,7 @@ import org.eclipse.papyrus.infra.nattable.properties.observable.RowPasteEObjectE import org.eclipse.papyrus.infra.nattable.properties.observable.RowPasteObjectDetachedModeObservableValue; import org.eclipse.papyrus.infra.nattable.properties.observable.RowPasteObjectPostActionsObservableValue; import org.eclipse.papyrus.infra.nattable.properties.provider.AxisIdentifierLabelProvider; -import org.eclipse.papyrus.infra.nattable.properties.provider.ColumnAxisIdentifierContentProvider; -import org.eclipse.papyrus.infra.nattable.properties.provider.ColumnContainmentFeatureContentProvider; -import org.eclipse.papyrus.infra.nattable.properties.provider.ColumnElementTypeIdContentProvider; import org.eclipse.papyrus.infra.nattable.properties.provider.ColumnPostActionIdsProvider; -import org.eclipse.papyrus.infra.nattable.properties.provider.ContextFeatureContentProvider; -import org.eclipse.papyrus.infra.nattable.properties.provider.RowAxisIdentifierContentProvider; -import org.eclipse.papyrus.infra.nattable.properties.provider.RowContainmentFeatureContentProvider; -import org.eclipse.papyrus.infra.nattable.properties.provider.RowElementTypeIdContentProvider; import org.eclipse.papyrus.infra.nattable.properties.provider.RowPostActionIdsProvider; import org.eclipse.papyrus.infra.nattable.properties.utils.Constants; import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils; @@ -382,7 +382,7 @@ public class NatTableModelElement extends EMFModelElement { } else // feature row label property - if (Constants.ROW_FEATURE_LABEL_CONFIGURATION_DISPLAY_ICON.equals(propertyPath)) { + if (Constants.ROW_FEATURE_LABEL_CONFIGURATION_DISPLAY_ICON.equals(propertyPath)) { value = new RowFeatureLabelDisplayIconObservableValue(table); } else if (Constants.ROW_FEATURE_LABEL_CONFIGURATION_DISPLAY_LABEL.equals(propertyPath)) { value = new RowFeatureLabelDisplayLabelObservableValue(table); @@ -493,7 +493,7 @@ public class NatTableModelElement extends EMFModelElement { // paste row EObject else if (Constants.ROW_PASTED_EOBJECT_CONTAINMENT_FEATURE.equals(propertyPath)) { - res = new RowContainmentFeatureContentProvider(getEditedTable()).getElements().length != 0; + res = new RowContainmentFeatureContentProvider(getEditedTable(), getEditedTable().getContext().eClass()).getElements().length != 0; } else if (Constants.ROW_PASTED_EOBJECT_ID.equals(propertyPath)) { res = new RowElementTypeIdContentProvider(this.tableModelManager).getElements().length != 0; } else if (Constants.ROW_PASTED_OBJECT_DETACHED_MODE_FEATURE.equals(propertyPath)) { @@ -505,7 +505,7 @@ public class NatTableModelElement extends EMFModelElement { // paste column EObject } else if (Constants.COLUMN_PASTED_EOBJECT_CONTAINMENT_FEATURE.equals(propertyPath)) { - res = new ColumnContainmentFeatureContentProvider(getEditedTable()).getElements().length != 0; + res = new ColumnContainmentFeatureContentProvider(getEditedTable(), getEditedTable().getContext().eClass()).getElements().length != 0; } else if (Constants.COLUMN_PASTED_EOBJECT_ID.equals(propertyPath)) { res = new ColumnElementTypeIdContentProvider(this.tableModelManager).getElements().length != 0; } else if (Constants.COLUMN_PASTED_OBJECT_DETACHED_MODE_FEATURE.equals(propertyPath)) { @@ -534,9 +534,9 @@ public class NatTableModelElement extends EMFModelElement { Table table = getEditedTable(); provider = new ContextFeatureContentProvider(table, getRoot(table.getContext())); } else if (Constants.ROW_PASTED_EOBJECT_CONTAINMENT_FEATURE.equals(propertyPath)) { - provider = new RowContainmentFeatureContentProvider(getEditedTable()); + provider = new RowContainmentFeatureContentProvider(getEditedTable(), getEditedTable().getContext().eClass()); } else if (Constants.COLUMN_PASTED_EOBJECT_CONTAINMENT_FEATURE.equals(propertyPath)) { - provider = new ColumnContainmentFeatureContentProvider(getEditedTable()); + provider = new ColumnContainmentFeatureContentProvider(getEditedTable(), getEditedTable().getContext().eClass()); } else if (Constants.ROW_PASTED_EOBJECT_ID.equals(propertyPath)) { provider = new RowElementTypeIdContentProvider(this.tableModelManager); } else if (Constants.COLUMN_PASTED_EOBJECT_ID.equals(propertyPath)) { @@ -555,7 +555,7 @@ public class NatTableModelElement extends EMFModelElement { } return super.getContentProvider(propertyPath); } - + /** * * @see org.eclipse.papyrus.views.properties.modelelement.EMFModelElement#isUnique(java.lang.String) @@ -631,12 +631,12 @@ public class NatTableModelElement extends EMFModelElement { } }; } - + if (Constants.COLUMN_PASTED_EOBJECT_AXIS_IDENTIFIER_FEATURE.equals(propertyPath) || Constants.ROW_PASTED_EOBJECT_AXIS_IDENTIFIER_FEATURE.equals(propertyPath)) { provider = new AxisIdentifierLabelProvider(tableModelManager); } - - if(null == provider){ + + if (null == provider) { provider = super.getLabelProvider(propertyPath); } return provider; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ColumnContainmentFeatureContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ColumnContainmentFeatureContentProvider.java deleted file mode 100644 index 5ddf38f0645..00000000000 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ColumnContainmentFeatureContentProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2013 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.nattable.properties.provider;
-
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-
-/**
- *
- * @author VL222926
- *
- */
-public class ColumnContainmentFeatureContentProvider extends AbstractContainmentFeatureContentProvider {
-
-
- /**
- *
- * Constructor.
- *
- * @param table
- * the table used to get the available features
- */
- public ColumnContainmentFeatureContentProvider(final Table table) {
- super(table, true);
- }
-
-}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/RowContainmentFeatureContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/RowContainmentFeatureContentProvider.java deleted file mode 100644 index 5a7ac997eb3..00000000000 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/RowContainmentFeatureContentProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2013 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.nattable.properties.provider;
-
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-
-/**
- *
- * @author VL222926
- *
- */
-public class RowContainmentFeatureContentProvider extends AbstractContainmentFeatureContentProvider {
-
-
- /**
- *
- * Constructor.
- *
- * @param table
- * the table used to get the available features
- */
- public RowContainmentFeatureContentProvider(final Table table) {
- super(table, false);
- }
-
-}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF index c48e23c43e8..5dc9ea8714d 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/META-INF/MANIFEST.MF @@ -7,6 +7,7 @@ Export-Package: org.eclipse.papyrus.infra.nattable, org.eclipse.papyrus.infra.nattable.command, org.eclipse.papyrus.infra.nattable.comparator, org.eclipse.papyrus.infra.nattable.configuration, + org.eclipse.papyrus.infra.nattable.contentprovider, org.eclipse.papyrus.infra.nattable.converter, org.eclipse.papyrus.infra.nattable.copy, org.eclipse.papyrus.infra.nattable.dataprovider, @@ -70,7 +71,9 @@ Require-Bundle: org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0", org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.2.0", org.eclipse.papyrus.infra.services.decoration;bundle-version="1.2.0", org.eclipse.papyrus.infra.ui;bundle-version="1.2.0", - org.eclipse.papyrus.infra.ui.emf;bundle-version="1.2.0" + org.eclipse.papyrus.infra.ui.emf;bundle-version="1.2.0", + org.eclipse.papyrus.infra.viewpoints.configuration;bundle-version="1.2.0", + org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.2.0" Bundle-Vendor: %Bundle-Vendor Bundle-ActivationPolicy: lazy Bundle-Version: 1.2.0.qualifier diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractAxisIdentifierContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/AbstractAxisIdentifierContentProvider.java index 1b1b5093b66..c50cbec814a 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractAxisIdentifierContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/AbstractAxisIdentifierContentProvider.java @@ -10,7 +10,7 @@ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation * *****************************************************************************/ -package org.eclipse.papyrus.infra.nattable.properties.provider; +package org.eclipse.papyrus.infra.nattable.contentprovider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractContainmentFeatureContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/AbstractContainmentFeatureContentProvider.java index 962bc8a7f08..55aec87d2a7 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractContainmentFeatureContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/AbstractContainmentFeatureContentProvider.java @@ -1,159 +1,170 @@ -/*****************************************************************************
- * Copyright (c) 2013 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.nattable.properties.provider;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.emf.utils.ENamedElementComparator;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.EStructuralFeatureValueFillingConfiguration;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.IFillingConfiguration;
-import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils;
-import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
-
-/**
- * Abtract content provider for containement feature for the paste
- *
- * @author VL222926
- *
- */
-public abstract class AbstractContainmentFeatureContentProvider implements IStaticContentProvider {
-
- /**
- * the table manager
- */
- private Table table;
-
- private final boolean onColumn;
-
- /**
- *
- * Constructor.
- *
- * @param table
- * the table used to get the available features
- */
- public AbstractContainmentFeatureContentProvider(final Table table, final boolean onColumn) {
- this.table = table;
- this.onColumn = onColumn;
- }
-
- /**
- * @Override
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
- */
- @Override
- public Object[] getElements(Object inputElement) {
- final Collection<EStructuralFeature> allFeatures = table.getContext().eClass().getEAllStructuralFeatures();
- final Collection<EStructuralFeature> availableFeatures = new TreeSet<EStructuralFeature>(new ENamedElementComparator());
- for (EStructuralFeature eStructuralFeature : allFeatures) {
- if (eStructuralFeature instanceof EReference && ((EReference) eStructuralFeature).isContainment() && eStructuralFeature.isChangeable() && eStructuralFeature.isMany()) {
- availableFeatures.add(eStructuralFeature);
- }
- }
-
- final Collection<IFillingConfiguration> fillingConfigurations = FillingConfigurationUtils.getFillingConfigurationUsedInTable(table, onColumn);
- List<EStructuralFeature> listenFeatures = new ArrayList<EStructuralFeature>();
- for (final IFillingConfiguration current : fillingConfigurations) {
- if (current instanceof EStructuralFeatureValueFillingConfiguration) {
- listenFeatures.add(((EStructuralFeatureValueFillingConfiguration) current).getListenFeature());
- }
- }
-
- List<EClassifier> types = new ArrayList<EClassifier>();
- ListIterator<EStructuralFeature> iter = listenFeatures.listIterator();
- boolean hasFillingMode = listenFeatures.size() != 0;
- // the filling configuration can be done on a derived feature, that's why we must verify it!
- while (iter.hasNext()) {
- EStructuralFeature current = iter.next();
- if (current.isDerived() && !current.isChangeable() && !((EReference) current).isContainment()) {
- iter.remove();
- types.add(current.getEType());
- }
- }
-
- if (hasFillingMode) {
- // we look for features referenced by availabales feature and consistent with the filling feature
- Set<EStructuralFeature> bestFeatures = new HashSet<EStructuralFeature>();
- bestFeatures.addAll(listenFeatures);
- for (final EClassifier eClassifier : types) {
- for (final EStructuralFeature availableFeature : availableFeatures) {
- EClassifier currentEType = availableFeature.getEType();
- if (eClassifier instanceof EClass && currentEType instanceof EClass) {
- if (eClassifier == currentEType || ((EClass) eClassifier).isSuperTypeOf((EClass) currentEType)) {
- bestFeatures.add(availableFeature);
- }
- } else if (currentEType == eClassifier) {
- bestFeatures.add(availableFeature);
- }
- }
- }
- return bestFeatures.toArray();
- }
-
- if (listenFeatures.size() != 0) {
- availableFeatures.retainAll(listenFeatures);
- }
- return availableFeatures.toArray();
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- *
- */
- @Override
- public final void dispose() {
- this.table = null;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- *
- * @param viewer
- * @param oldInput
- * @param newInput
- */
- @Override
- public final void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements()
- *
- * @return
- */
- @Override
- public final Object[] getElements() {
- return getElements(null);
- }
-
-
-}
+/***************************************************************************** + * Copyright (c) 2013 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.nattable.contentprovider; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.ListIterator; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.infra.emf.utils.ENamedElementComparator; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.EStructuralFeatureValueFillingConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.IFillingConfiguration; +import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; + +/** + * Abtract content provider for containement feature for the paste + * + * @author VL222926 + * + */ +public abstract class AbstractContainmentFeatureContentProvider implements IStaticContentProvider { + + /** + * the table manager + */ + private Table table; + + /** + * Determinate if this is used as column. + */ + private final boolean onColumn; + + /** + * The {@link EClass} of the parent elements + */ + private List<EClass> eClasses; + + /** + * + * Constructor. + * + * @param table + * the table used to get the available features + * @param eClasses + * the {@link EClass} of the parent elements + * @param onColumn + * this determinate if this is used as column + */ + public AbstractContainmentFeatureContentProvider(final Table table, final List<EClass> eClasses, final boolean onColumn) { + this.table = table; + this.onColumn = onColumn; + this.eClasses = eClasses; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + @Override + public Object[] getElements(final Object inputElement) { + final Collection<EStructuralFeature> availableFeatures = new TreeSet<EStructuralFeature>(new ENamedElementComparator()); + + for(final EClass eClass : eClasses){ + final Collection<EStructuralFeature> allFeatures = eClass.getEAllStructuralFeatures(); + for (EStructuralFeature eStructuralFeature : allFeatures) { + if (eStructuralFeature instanceof EReference && ((EReference) eStructuralFeature).isContainment() && eStructuralFeature.isChangeable() && eStructuralFeature.isMany()) { + availableFeatures.add(eStructuralFeature); + } + } + } + + final Collection<IFillingConfiguration> fillingConfigurations = FillingConfigurationUtils.getFillingConfigurationUsedInTable(table, onColumn); + List<EStructuralFeature> listenFeatures = new ArrayList<EStructuralFeature>(); + for (final IFillingConfiguration current : fillingConfigurations) { + if (current instanceof EStructuralFeatureValueFillingConfiguration) { + listenFeatures.add(((EStructuralFeatureValueFillingConfiguration) current).getListenFeature()); + } + } + + List<EClassifier> types = new ArrayList<EClassifier>(); + ListIterator<EStructuralFeature> iter = listenFeatures.listIterator(); + boolean hasFillingMode = listenFeatures.size() != 0; + // the filling configuration can be done on a derived feature, that's why we must verify it! + while (iter.hasNext()) { + EStructuralFeature current = iter.next(); + if (current.isDerived() && !current.isChangeable() && !((EReference) current).isContainment()) { + iter.remove(); + types.add(current.getEType()); + } + } + + if (hasFillingMode) { + // we look for features referenced by availabales feature and consistent with the filling feature + Set<EStructuralFeature> bestFeatures = new HashSet<EStructuralFeature>(); + bestFeatures.addAll(listenFeatures); + for (final EClassifier eClassifier : types) { + for (final EStructuralFeature availableFeature : availableFeatures) { + EClassifier currentEType = availableFeature.getEType(); + if (eClassifier instanceof EClass && currentEType instanceof EClass) { + if (eClassifier == currentEType || ((EClass) eClassifier).isSuperTypeOf((EClass) currentEType)) { + bestFeatures.add(availableFeature); + } + } else if (currentEType == eClassifier) { + bestFeatures.add(availableFeature); + } + } + } + return bestFeatures.toArray(); + } + + if (listenFeatures.size() != 0) { + availableFeatures.retainAll(listenFeatures); + } + return availableFeatures.toArray(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + @Override + public final void dispose() { + this.table = null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + @Override + public final void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements() + */ + @Override + public final Object[] getElements() { + return getElements(null); + } + + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractElementTypeIdContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/AbstractElementTypeIdContentProvider.java index 32d11c7f8f2..e74a1013d6a 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractElementTypeIdContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/AbstractElementTypeIdContentProvider.java @@ -1,91 +1,91 @@ -/*****************************************************************************
- * Copyright (c) 2013 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.nattable.properties.provider;
-
-import java.util.Collection;
-
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.utils.CreatableEObjectAxisUtils;
-import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
-
-
-public abstract class AbstractElementTypeIdContentProvider implements IStaticContentProvider {
-
- /**
- * the allowed element
- */
- private Collection<String> allowedElements;
-
- /**
- *
- * Constructor.
- *
- * @param tableManager
- * the tableManager
- * @param onColumn
- * true if we are working on column
- */
- public AbstractElementTypeIdContentProvider(final INattableModelManager tableManager, final boolean onColumn) {
- this.allowedElements = CreatableEObjectAxisUtils.getCreatableElementIds(tableManager, onColumn);
- }
-
-
-
- /**
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
- */
- @Override
- public final Object[] getElements(Object inputElement) {
- return allowedElements.toArray();
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- *
- */
- @Override
- public final void dispose() {
- this.allowedElements.clear();
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- *
- * @param viewer
- * @param oldInput
- * @param newInput
- */
- @Override
- public final void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements()
- *
- * @return
- */
- @Override
- public final Object[] getElements() {
- return getElements(null);
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013 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.nattable.contentprovider; + +import java.util.Collection; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.utils.CreatableEObjectAxisUtils; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; + + +public abstract class AbstractElementTypeIdContentProvider implements IStaticContentProvider { + + /** + * the allowed element + */ + private Collection<String> allowedElements; + + /** + * + * Constructor. + * + * @param tableManager + * the tableManager + * @param onColumn + * true if we are working on column + */ + public AbstractElementTypeIdContentProvider(final INattableModelManager tableManager, final boolean onColumn) { + this.allowedElements = CreatableEObjectAxisUtils.getCreatableElementIds(tableManager, onColumn); + } + + + + /** + * + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + * + * @param inputElement + * @return + */ + @Override + public final Object[] getElements(Object inputElement) { + return allowedElements.toArray(); + } + + /** + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + * + */ + @Override + public final void dispose() { + this.allowedElements.clear(); + } + + /** + * + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + * + * @param viewer + * @param oldInput + * @param newInput + */ + @Override + public final void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + /** + * + * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements() + * + * @return + */ + @Override + public final Object[] getElements() { + return getElements(null); + } + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ColumnAxisIdentifierContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ColumnAxisIdentifierContentProvider.java index 535752e8be9..eea4f2c2111 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ColumnAxisIdentifierContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ColumnAxisIdentifierContentProvider.java @@ -10,7 +10,7 @@ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation * *****************************************************************************/ -package org.eclipse.papyrus.infra.nattable.properties.provider; +package org.eclipse.papyrus.infra.nattable.contentprovider; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ColumnContainmentFeatureContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ColumnContainmentFeatureContentProvider.java new file mode 100644 index 00000000000..b35a167b2a3 --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ColumnContainmentFeatureContentProvider.java @@ -0,0 +1,63 @@ +/***************************************************************************** + * Copyright (c) 2013 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 455060 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.nattable.contentprovider; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; + +/** + * The content provider for the column containment feature. + */ +public class ColumnContainmentFeatureContentProvider extends AbstractContainmentFeatureContentProvider { + + /** + * Constructor. + * + * @param table + * the table used to get the available features + * @deprecated + */ + public ColumnContainmentFeatureContentProvider(final Table table) { + this(table, table.getContext().eClass()); + } + + /** + * Constructor. + * + * @param table + * the table used to get the available features + * @param eClass + * the {@link EClass} of the parent element + */ + public ColumnContainmentFeatureContentProvider(final Table table, final EClass eClass) { + this(table, Collections.singletonList(eClass)); + } + + /** + * Constructor. + * + * @param table + * the table used to get the available features + * @param eClasses + * the {@link EClass} of the parent elements + */ + public ColumnContainmentFeatureContentProvider(final Table table, final List<EClass> eClasses) { + super(table, eClasses, true); + } + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ColumnElementTypeIdContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ColumnElementTypeIdContentProvider.java index b1f1dd7446f..2bf5a7a34bd 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ColumnElementTypeIdContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ColumnElementTypeIdContentProvider.java @@ -1,31 +1,31 @@ -/*****************************************************************************
- * Copyright (c) 2013 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.nattable.properties.provider;
-
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-
-
-public class ColumnElementTypeIdContentProvider extends AbstractElementTypeIdContentProvider {
-
- /**
- *
- * Constructor.
- *
- * @param tableManager
- */
- public ColumnElementTypeIdContentProvider(final INattableModelManager tableManager) {
- super(tableManager, true);
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013 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.nattable.contentprovider; + +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; + + +public class ColumnElementTypeIdContentProvider extends AbstractElementTypeIdContentProvider { + + /** + * + * Constructor. + * + * @param tableManager + */ + public ColumnElementTypeIdContentProvider(final INattableModelManager tableManager) { + super(tableManager, true); + } + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ContextFeatureContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ContextFeatureContentProvider.java index 6823bb13c13..ba9fa832213 100755 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/ContextFeatureContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/ContextFeatureContentProvider.java @@ -1,78 +1,78 @@ -/*****************************************************************************
- * Copyright (c) 2013 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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.properties.provider;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
-import org.eclipse.papyrus.infra.viewpoints.configuration.ui.ECoreModelContentProvider;
-import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
-import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
-import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
-import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
-
-/**
- * Represents a simple ECore model content provider for the selection of a table's root model element
- *
- * @author Laurent Wouters
- */
-public class ContextFeatureContentProvider extends ECoreModelContentProvider implements IStaticContentProvider, IHierarchicContentProvider {
- /**
- * The diagram
- */
- private Table table;
-
- /**
- * Initializes the provider with the given root
- *
- * @param diagram
- * The diagram for which a root model element is to be provided
- * @param root
- * The root object
- */
- public ContextFeatureContentProvider(Table table, EObject root) {
- super(root);
- this.table = table;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements()
- */
- @Override
- public Object[] getElements() {
- return getElements(null);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider#isValidValue(java.lang.Object)
- */
- @Override
- public boolean isValidValue(Object element) {
- if (element == null) {
- return false;
- }
- if (!(element instanceof EObject)) {
- return false;
- }
- ViewPrototype prototype = ViewPrototype.get((PapyrusView) table.getPrototype());
- if (prototype == null) {
- return false;
- }
- return PolicyChecker.getCurrent().canHaveNewView((EObject) element, table.getOwner(), prototype);
- }
-}
+/***************************************************************************** + * Copyright (c) 2013 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: + * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.nattable.contentprovider; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView; +import org.eclipse.papyrus.infra.viewpoints.configuration.ui.ECoreModelContentProvider; +import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker; +import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype; +import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; + +/** + * Represents a simple ECore model content provider for the selection of a table's root model element + * + * @author Laurent Wouters + */ +public class ContextFeatureContentProvider extends ECoreModelContentProvider implements IStaticContentProvider, IHierarchicContentProvider { + /** + * The diagram + */ + private Table table; + + /** + * Initializes the provider with the given root + * + * @param diagram + * The diagram for which a root model element is to be provided + * @param root + * The root object + */ + public ContextFeatureContentProvider(Table table, EObject root) { + super(root); + this.table = table; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements() + */ + @Override + public Object[] getElements() { + return getElements(null); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider#isValidValue(java.lang.Object) + */ + @Override + public boolean isValidValue(Object element) { + if (element == null) { + return false; + } + if (!(element instanceof EObject)) { + return false; + } + ViewPrototype prototype = ViewPrototype.get((PapyrusView) table.getPrototype()); + if (prototype == null) { + return false; + } + return PolicyChecker.getCurrent().canHaveNewView((EObject) element, table.getOwner(), prototype); + } +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/RowAxisIdentifierContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/RowAxisIdentifierContentProvider.java index 036f8ad26d5..9018976167a 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/RowAxisIdentifierContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/RowAxisIdentifierContentProvider.java @@ -10,7 +10,7 @@ * Nicolas FAUVERGUe (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation * *****************************************************************************/ -package org.eclipse.papyrus.infra.nattable.properties.provider; +package org.eclipse.papyrus.infra.nattable.contentprovider; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/RowContainmentFeatureContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/RowContainmentFeatureContentProvider.java new file mode 100644 index 00000000000..4baf01dbe3f --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/RowContainmentFeatureContentProvider.java @@ -0,0 +1,63 @@ +/***************************************************************************** + * Copyright (c) 2013 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 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 455060 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.nattable.contentprovider; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; + +/** + * The content provider for the row containment feature. + */ +public class RowContainmentFeatureContentProvider extends AbstractContainmentFeatureContentProvider { + + /** + * Constructor. + * + * @param table + * the table used to get the available features + * @deprecated + */ + public RowContainmentFeatureContentProvider(final Table table) { + this(table, table.getContext().eClass()); + } + + /** + * Constructor. + * + * @param table + * the table used to get the available features + * @param eClass + * the {@link EClass} of the parent element + */ + public RowContainmentFeatureContentProvider(final Table table, final EClass eClass) { + this(table, Collections.singletonList(eClass)); + } + + /** + * Constructor. + * + * @param table + * the table used to get the available features + * @param eClasses + * the {@link EClass} of the parent elements + */ + public RowContainmentFeatureContentProvider(final Table table, final List<EClass> eClasses) { + super(table, eClasses, false); + } + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/RowElementTypeIdContentProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/RowElementTypeIdContentProvider.java index e6e8d614061..9603c65b658 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/RowElementTypeIdContentProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/contentprovider/RowElementTypeIdContentProvider.java @@ -1,37 +1,37 @@ -/*****************************************************************************
- * Copyright (c) 2013 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.nattable.properties.provider;
-
-import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-
-/**
- *
- * @author VL222926
- *
- */
-public class RowElementTypeIdContentProvider extends AbstractElementTypeIdContentProvider {
-
- /**
- *
- * Constructor.
- *
- * @param tableManager
- * the table manager
- */
- public RowElementTypeIdContentProvider(final INattableModelManager tableManager) {
- super(tableManager, false);
- }
-
-
-}
+/***************************************************************************** + * Copyright (c) 2013 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.nattable.contentprovider; + +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; + +/** + * + * @author VL222926 + * + */ +public class RowElementTypeIdContentProvider extends AbstractElementTypeIdContentProvider { + + /** + * + * Constructor. + * + * @param tableManager + * the table manager + */ + public RowElementTypeIdContentProvider(final INattableModelManager tableManager) { + super(tableManager, false); + } + + +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java index 2eb46e23519..37f5ae8af10 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java @@ -136,6 +136,14 @@ public class Messages extends NLS { public static String AxisManagerFactory_TheClassCantBeInstanciated; public static String CompositeAxisManager_AddAxisCommand; + + public static String ConfigurePastePage_firstColumnTitle; + + public static String ConfigurePastePage_secondColumnTitle; + + public static String ConfigurePastePage_thirdColumnTitle; + + public static String ConfigurePastePage_fourthColumnTitle; public static String DeleteNatTableContextAdvice_DestroyNattableCommand; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties index d68ccbd2f3c..2be5059cc33 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties @@ -55,6 +55,10 @@ AxisManagerFactory_TheClassCantBeInstanciated=The class {0} can't be instanciate CellManagerFactory_CellManagerNotFound=Cell manager not found ChooseCategoriesSelectionWidget_EditAlias=Edit alias ChooseCategoriesSelectionWidget_EnterAliasToUseForTheCategory=Enter alias to use for the category +ConfigurePastePage_firstColumnTitle=Depth/Categorie +ConfigurePastePage_secondColumnTitle=Detached Mode +ConfigurePastePage_thirdColumnTitle=Pasted Element Id +ConfigurePastePage_fourthColumnTitle=Containment Feature CompositeAxisManager_AddAxisCommand=Add Axis Command DeleteNatTableContextAdvice_DestroyNattableCommand=Destroy NatTables command EditConfiguration_ConfigurationFactoryNotFound=I can't find config factory for {0} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java index 7d4b54e0848..cf8c050fce3 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java @@ -189,7 +189,11 @@ public class PasteInSelectionNattableCommandProvider extends AbstractPasteInSele for (int insertedElementIndex = createdElements.size() - 1; insertedElementIndex >= 0; insertedElementIndex--) { final InsertedElementInNattable currentInsertedElement = createdElements.get(insertedElementIndex); if (-1 != currentInsertedElement.getIndexInParent()) { - addCommand.append(MoveCommand.create(contextEditingDomain, currentInsertedElement.getContext(), currentInsertedElement.getContainementFeature(), currentInsertedElement.getCreatedElements(), currentInsertedElement.getIndexInParent())); + int addedIndex = 0; + for(Object createdElement : currentInsertedElement.getCreatedElements()){ + addCommand.append(MoveCommand.create(contextEditingDomain, currentInsertedElement.getContext(), currentInsertedElement.getContainementFeature(), createdElement, currentInsertedElement.getIndexInParent()+addedIndex)); + addedIndex++; + } } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java index d3e00595c7a..a23a3fa660f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java @@ -282,7 +282,11 @@ public class PasteInSelectionTreeNattableCommandProvider extends PasteInSelectio for (int insertedElementIndex = createdElements.size() - 1; insertedElementIndex >= 0; insertedElementIndex--) { final InsertedElementInNattable currentInsertedElement = createdElements.get(insertedElementIndex); if (-1 != currentInsertedElement.getIndexInParent()) { - addCommand.append(MoveCommand.create(contextEditingDomain, currentInsertedElement.getContext(), currentInsertedElement.getContainementFeature(), currentInsertedElement.getCreatedElements(), currentInsertedElement.getIndexInParent())); + int addedIndex = 0; + for(Object createdElement : currentInsertedElement.getCreatedElements()){ + addCommand.append(MoveCommand.create(contextEditingDomain, currentInsertedElement.getContext(), currentInsertedElement.getContainementFeature(), createdElement, currentInsertedElement.getIndexInParent()+addedIndex)); + addedIndex++; + } } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java index af292d11c77..860b905ef84 100755 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java @@ -8,6 +8,7 @@ * * Contributors: * CEA LIST - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.ne - Bug 455060 * *****************************************************************************/ @@ -22,15 +23,17 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EOperation; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EcorePackage; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.jface.dialogs.IPageChangedListener; +import org.eclipse.jface.dialogs.PageChangedEvent; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; import org.eclipse.osgi.util.NLS; @@ -41,7 +44,6 @@ import org.eclipse.papyrus.infra.nattable.model.factory.IAxisFactory; import org.eclipse.papyrus.infra.nattable.model.nattable.Table; 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.NattableaxisPackage; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AbstractHeaderAxisConfiguration; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerConfiguration; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation; @@ -59,7 +61,7 @@ import org.eclipse.papyrus.infra.nattable.utils.LabelProviderContextElementWrapp import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes; import org.eclipse.papyrus.infra.nattable.utils.StringComparator; import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils; -import org.eclipse.papyrus.infra.nattable.wizard.pages.ConfigurePasteForCategoriesWizardPage; +import org.eclipse.papyrus.infra.nattable.wizard.pages.ConfigurePastePage; import org.eclipse.papyrus.infra.nattable.wizard.pages.SelectCategoriesWizardPage; import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; import org.eclipse.papyrus.infra.tools.util.TypeUtils; @@ -71,10 +73,9 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; /** - * @author VL222926 - * This wizard allows to configure the categories to listen in the table And the paste action for each categories + * This wizard allows to configure the categories to listen in the table And the paste action for each categories */ -public class ConfigureTableCategoriesWizard extends AbstractTableWizard { +public class ConfigureTableCategoriesWizard extends AbstractTableWizard implements IPageChangedListener { /** * the page used to choose the categories @@ -84,7 +85,7 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { /** * the page used to configure the paste */ - private ConfigurePasteForCategoriesWizardPage pastePage; + private ConfigurePastePage pastePage; /** * the nattable model manager @@ -102,11 +103,12 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { private List<Object> initialSelection; /** - * * Constructor. * + * @param manager + * The nattable model manager. */ - public ConfigureTableCategoriesWizard(INattableModelManager manager) { + public ConfigureTableCategoriesWizard(final INattableModelManager manager) { this.manager = manager; this.natTable = (NatTable) ((IAdaptable) manager).getAdapter(NatTable.class); setWindowTitle("Configure Categories"); @@ -114,13 +116,14 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * Create the selector content provider. * * @param selector * the reference selector * @return - * the content provider to use for the selector + * the content provider to use for the selector */ - protected IStaticContentProvider createSelectorContentProvider(ReferenceSelector selector) { + protected IStaticContentProvider createSelectorContentProvider(final ReferenceSelector selector) { final IAxisManager editedAxisManager = this.manager.getColumnAxisManager(); IStaticContentProvider provider = editedAxisManager.createPossibleAxisContentProvider(true); Assert.isNotNull(provider); @@ -136,17 +139,17 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { @Override public boolean isValidValue(Object element) { // EMF dependency, must not be done here, it should be better with a new content provider service - return (element instanceof EReference && ((EReference) element).isMany() && element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations()) - || (element instanceof EOperation && ((EOperation)element).isMany()); + return element instanceof EReference && ((EReference) element).isMany() && element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations(); } }; } /** + * Create the reference selector. * * @return - * the created and initialized reference selector + * the created and initialized reference selector */ protected ReferenceSelector createReferenceSelector() { ReferenceSelector selector = new ReferenceSelector(false) { @@ -174,9 +177,10 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * This allows to create the first page corresponding to the categories selection. * * @return - * the page to use to select the categories to listen in the table + * the page to use to select the categories to listen in the table */ protected SelectCategoriesWizardPage createSelectCategoriesPage() { this.categoriesPage = new SelectCategoriesWizardPage(createReferenceSelector()); @@ -187,33 +191,35 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * This allows to create the second page corresponding to the paste configurations. * * @return - * the paste page used to configure the paste + * the paste page used to configure the paste */ - protected ConfigurePasteForCategoriesWizardPage createConfigurePastePage() { - this.pastePage = new ConfigurePasteForCategoriesWizardPage(createReferenceSelector()); + protected ConfigurePastePage createConfigurePastePage() { final LabelProviderService serv = this.natTable.getConfigRegistry().getConfigAttribute(NattableConfigAttributes.LABEL_PROVIDER_SERVICE_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.LABEL_PROVIDER_SERVICE_ID); - this.pastePage.setLabelProvider(new ITreeItemWrappedObjectLabelProvider(serv.getLabelProvider(), this.natTable)); - this.pastePage.setInitialElementSelections(this.initialSelection); + this.pastePage = new ConfigurePastePage("Paste Configuration", manager, new ITreeItemWrappedObjectLabelProvider(serv.getLabelProvider(), this.natTable), serv.getLabelProvider(), createSelectorContentProvider(null)); //$NON-NLS-1$ return this.pastePage; } /** + * {@inheritDoc} + * * @see org.eclipse.jface.wizard.Wizard#addPages() - * */ @Override public void addPages() { super.addPages(); addPage(createSelectCategoriesPage()); - // addPage(createConfigurePastePage()); + addPage(createConfigurePastePage()); + + // Add a listener to manage the page changing + final WizardDialog dialog = (WizardDialog) getContainer(); + dialog.addPageChangedListener(this); } /** - * * The label provider to use for the selected elements viewer - * */ private static class ITreeItemWrappedObjectLabelProvider implements ILabelProvider { @@ -222,17 +228,25 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { */ private ILabelProvider wrappedLabelprovider; + /** + * The nattable to manage. + */ private NatTable natTable; + /** + * The wrapper label provider context. + */ private LabelProviderContextElementWrapper wrapper; - + /** - * * Constructor. * * @param wrappedProvider + * The wrapped provider. + * @param natTable + * The nattable to manage. */ - public ITreeItemWrappedObjectLabelProvider(ILabelProvider wrappedProvider, NatTable natTable) { + public ITreeItemWrappedObjectLabelProvider(final ILabelProvider wrappedProvider, final NatTable natTable) { this.wrappedLabelprovider = wrappedProvider; this.natTable = natTable; wrapper = new LabelProviderContextElementWrapper(); @@ -240,18 +254,19 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * {@inheritDoc} + * * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) - * - * @param arg0 */ @Override - public void addListener(ILabelProviderListener arg0) { + public void addListener(final ILabelProviderListener arg0) { // nothing to do } /** + * {@inheritDoc} + * * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() - * */ @Override public void dispose() { @@ -259,49 +274,47 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * {@inheritDoc} + * * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) - * - * @param arg0 - * @param arg1 - * @return */ @Override - public boolean isLabelProperty(Object arg0, String arg1) { + public boolean isLabelProperty(final Object arg0, final String arg1) { return false; } /** + * {@inheritDoc} + * * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) - * - * @param arg0 */ @Override - public void removeListener(ILabelProviderListener arg0) { + public void removeListener(final ILabelProviderListener arg0) { // nothing to do } /** + * + * {@inheritDoc} + * * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) - * - * @param arg0 - * @return */ @Override - public Image getImage(Object arg0) { + public Image getImage(final Object arg0) { + Object current = arg0; if (arg0 instanceof ITreeItemAxis) { - arg0 = ((ITreeItemAxis) arg0).getElement(); + current = ((ITreeItemAxis) arg0).getElement(); } - return wrappedLabelprovider.getImage(arg0); + return wrappedLabelprovider.getImage(current); } /** + * {@inheritDoc} + * * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - * - * @param arg0 - * @return */ @Override - public String getText(Object arg0) { + public String getText(final Object arg0) { Assert.isTrue(arg0 instanceof ITreeItemAxis); ITreeItemAxis axis = (ITreeItemAxis) arg0; Object element = axis.getElement(); @@ -326,9 +339,10 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * This allows to create the initial selection corresponding to the table to edit. * * @return - * the initial selection to use in the wizard page + * the initial selection to use in the wizard page */ protected List<Object> createInitialSelection() { Table table = this.manager.getTable(); @@ -380,28 +394,36 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { /** + * {@inheritDoc} + * * @see org.eclipse.jface.wizard.Wizard#performFinish() - * - * @return */ @Override public boolean performFinish() { Table table = manager.getTable(); - List<ITreeItemAxis> configureCategoriesResult = new ArrayList<ITreeItemAxis>(); + final List<ITreeItemAxis> configureCategoriesResult = new ArrayList<ITreeItemAxis>(); + final Map<ITreeItemAxis, PasteEObjectConfiguration> pasteConfigurations = pastePage.getPasteConfigurations(); for (Object curr : initialSelection) { configureCategoriesResult.add((ITreeItemAxis) curr); } - Command cmd = getConfigureCategoriesCommand(configureCategoriesResult); - EditingDomain domain = TableEditingDomainUtils.getTableEditingDomain(table); + final Command cmd = getConfigureCategoriesCommand(configureCategoriesResult, pasteConfigurations); + final EditingDomain domain = TableEditingDomainUtils.getTableEditingDomain(table); domain.getCommandStack().execute(cmd); return true; } - private ILabelProviderConfiguration getLabelConfigurationForTreeFillingConfiguration(Table table, final IAxis axis) { + /** + * Get the label provider configuration for the tree filling configuration. + * + * @param table + * The table. + * @return The label provider configuration. + */ + private ILabelProviderConfiguration getLabelConfigurationForTreeFillingConfiguration(final Table table) { TableHeaderAxisConfiguration conf = (TableHeaderAxisConfiguration) HeaderAxisConfigurationManagementUtils.getRowAbstractHeaderAxisInTableConfiguration(table); for (IAxisConfiguration tmp : conf.getOwnedAxisConfigurations()) { if (tmp instanceof TreeFillingConfiguration) { - if(((TreeFillingConfiguration) tmp).getAxisUsedAsAxisProvider().eClass().equals(axis.eClass()) && null != ((TreeFillingConfiguration) tmp).getLabelProvider()){ + if (((TreeFillingConfiguration) tmp).getLabelProvider() != null) { return ((TreeFillingConfiguration) tmp).getLabelProvider(); } } @@ -409,15 +431,27 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { return null; } - private String getLabelProviderContextForTreeFillingConfiguration(Table table, final IAxis axis) { - if(axis.eClass().equals(NattableaxisPackage.eINSTANCE.getEOperationAxis()) || axis.eClass().equals(NattableaxisPackage.eINSTANCE.getEOperationTreeItemAxis())){ - return Constants.HEADER_LABEL_PROVIDER_TREE_FILLING_OPERATION_CONFIGURATION_CONTEXT; - } + /** + * Get the label provider context for the tree filling configuration. + * + * @param table + * The table. + * @return The label provider context as string. + */ + private String getLabelProviderContextForTreeFillingConfiguration(final Table table) { return Constants.HEADER_LABEL_PROVIDER_TREE_FILLING_FEATURE_CONFIGURATION_CONTEXT; } - - protected Command getConfigureCategoriesCommand(final List<ITreeItemAxis> userSelection) { + /** + * This allows to get the command that configure the categories. + * + * @param userSelection + * The list of tree item axis choosen by the user. + * @param pasteConfigurations + * The paste configurations by tree item axis modified by user. + * @return The command. + */ + protected Command getConfigureCategoriesCommand(final List<ITreeItemAxis> userSelection, final Map<ITreeItemAxis, PasteEObjectConfiguration> pasteConfigurations) { return new RecordingCommand(TableEditingDomainUtils.getTableEditingDomain(manager.getTable())) { @Override @@ -435,6 +469,10 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { int wantedDepth = Integer.valueOf((String) depthItem.getElement()); if (depthItem.getChildren().isEmpty()) { // we do nothing if there is no child, in standard usecase, it is only possible when wantedDepth==0; + + if (null != pasteConfigurations.get(depthItem)) { + createdPasteEObjectConfiguration.add(pasteConfigurations.get(depthItem)); + } continue; } @@ -443,38 +481,45 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { // 1. try to find existing conf TreeFillingConfiguration newConf = findExistingTreeFillingConfiguration(table, representation, wantedDepth, categoryItem.getElement()); - if (null == newConf || EMFHelper.isReadOnly(newConf)) { + if (null == newConf || EMFHelper.isReadOnly(newConf) || null != pasteConfigurations.get(categoryItem)) { PasteEObjectConfiguration copiedEObjectConfiguration = null; - if(null != newConf){ + if (null != pasteConfigurations.get(categoryItem)) { + copiedEObjectConfiguration = pasteConfigurations.get(categoryItem); + } else if (null != newConf) { PasteEObjectConfiguration existingPasteConfiguration = newConf.getPasteConfiguration(); copiedEObjectConfiguration = EcoreUtil.copy(existingPasteConfiguration); - if(null != copiedEObjectConfiguration){ - createdPasteEObjectConfiguration.add(copiedEObjectConfiguration); - } } + if (null != copiedEObjectConfiguration) { + createdPasteEObjectConfiguration.add(copiedEObjectConfiguration); + } + // we create new TreeFillingConfiguration newConf = NattableaxisconfigurationFactory.eINSTANCE.createTreeFillingConfiguration(); newConf.setDepth(wantedDepth); - IAxis axis = IAxisFactory.createAxisForTypedElement(categoryItem.getElement(), representation, categoryItem.getAlias()); + IAxis axis = IAxisFactory.createAxisForFeature(categoryItem.getElement(), representation, categoryItem.getAlias()); newConf.setAxisUsedAsAxisProvider(axis); - newConf.setLabelProvider(getLabelConfigurationForTreeFillingConfiguration(table, axis)); - newConf.setLabelProviderContext(getLabelProviderContextForTreeFillingConfiguration(table, axis)); + newConf.setLabelProvider(getLabelConfigurationForTreeFillingConfiguration(table)); + newConf.setLabelProviderContext(getLabelProviderContextForTreeFillingConfiguration(table)); // Manage the paste configuration newConf.setPasteConfiguration(copiedEObjectConfiguration); } else { - // update the alias if required - String oldAlias = newConf.getAxisUsedAsAxisProvider().getAlias(); - String newAlias = categoryItem.getAlias(); - if ((oldAlias != null && !oldAlias.equals(newAlias)) || (newAlias != null && !newAlias.equals(oldAlias))) { - newConf.getAxisUsedAsAxisProvider().setAlias(newAlias); + if (null != newConf) { + // update the alias if required + String oldAlias = newConf.getAxisUsedAsAxisProvider().getAlias(); + String newAlias = categoryItem.getAlias(); + if ((oldAlias != null && !oldAlias.equals(newAlias)) || (newAlias != null && !newAlias.equals(oldAlias))) { + newConf.getAxisUsedAsAxisProvider().setAlias(newAlias); + } + + if (null != newConf.getPasteConfiguration()) { + createdPasteEObjectConfiguration.add(newConf.getPasteConfiguration()); + } } } createdFillingConfiguration.add(newConf); - - // TODO : manage paste } } @@ -508,15 +553,20 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * This allows to find the exiting tree filling configuration corresponding to the properties in parameters. * * @param table + * The table. * @param representedAxisManager + * The axis manager. * @param depth + * The wanted depth. * @param representedObject - * @return + * The represented object to search. + * @return The corresponding tree filling configuration. */ // TODO : move me - public static final TreeFillingConfiguration findExistingTreeFillingConfiguration(Table table, AxisManagerRepresentation representedAxisManager, int depth, Object representedObject) { + public static final TreeFillingConfiguration findExistingTreeFillingConfiguration(final Table table, final AxisManagerRepresentation representedAxisManager, final int depth, final Object representedObject) { List<TreeFillingConfiguration> existingConf = FillingConfigurationUtils.getTreeFillingConfigurationForDepth(table, representedAxisManager, depth); for (TreeFillingConfiguration treeFillingConfiguration : existingConf) { if (treeFillingConfiguration.getAxisUsedAsAxisProvider().getElement().equals(representedObject)) { @@ -527,11 +577,12 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { } /** + * Get the axis manager representation for rows. * * @param table * the table * @return - * the axis manager representation for rows + * the axis manager representation for rows */ private static final List<AxisManagerRepresentation> getRowAxisManagerRepresentations(Table table) { AbstractHeaderAxisConfiguration tmp = HeaderAxisConfigurationManagementUtils.getRowAbstractHeaderAxisInTableConfiguration(table); @@ -540,6 +591,17 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard { return conf.getAxisManagers(); } - + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.IPageChangedListener#pageChanged(org.eclipse.jface.dialogs.PageChangedEvent) + */ + @Override + public void pageChanged(final PageChangedEvent event) { + if (event.getSelectedPage().equals(pastePage)) { + // If the changed page is the paste configurations page, set it the selection potentially modified in the previous page + this.pastePage.setInitialElementSelections(this.initialSelection); + } + } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/pages/ConfigurePastePage.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/pages/ConfigurePastePage.java index 3d3a183ef89..ef2e7b0dcad 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/pages/ConfigurePastePage.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/pages/ConfigurePastePage.java @@ -1,44 +1,723 @@ -/*****************************************************************************
- * Copyright (c) 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
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.nattable.wizard.pages;
-
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.widgets.Composite;
-
-/**
- * @author VL222926
- *
- */
-public class ConfigurePastePage extends WizardPage {
-
- /**
- * Constructor.
- *
- * @param pageName
- */
- public ConfigurePastePage(String pageName) {
- super(pageName);
- }
-
- /**
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- *
- * @param parent
- */
- @Override
- public void createControl(Composite parent) {
-
- }
-
-}
+/***************************************************************************** + * 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.infra.nattable.wizard.pages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.common.ui.celleditor.ExtendedComboBoxCellEditor; +import org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEditor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.layout.TreeColumnLayout; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnPixelData; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.papyrus.infra.nattable.contentprovider.RowContainmentFeatureContentProvider; +import org.eclipse.papyrus.infra.nattable.contentprovider.RowElementTypeIdContentProvider; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectTreeItemAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EStructuralFeatureAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdTreeItemAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AbstractHeaderAxisConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.IAxisConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration; +import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils; +import org.eclipse.papyrus.infra.nattable.utils.StringComparator; +import org.eclipse.papyrus.infra.nattable.wizard.CategoriesWizardUtils; +import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; +import org.eclipse.papyrus.infra.widgets.strategy.ProviderBasedBrowseStrategy; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; + +/** + * The page to manage the paste configurations. + */ +public class ConfigurePastePage extends WizardPage { + + /** + * The checked image. + */ + private static final Image CHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.infra.nattable.common", "icons/checked.gif"); //$NON-NLS-1$ //$NON-NLS-2$ + + /** + * The unchecked image. + */ + private static final Image UNCHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.infra.nattable.common", "icons/unchecked.gif"); //$NON-NLS-1$ //$NON-NLS-2$ + + /** + * The undefined value. + */ + private static String UNDEFINED = "<Undefined>"; //$NON-NLS-1$ + + + /** + * The nattable manager. + */ + protected INattableModelManager nattableManager = null; + + /** + * The tree viewer. + */ + protected TreeViewer treeViewer; + + /** + * the initial selection + */ + protected List<Object> initialSelection; + + /** + * The label provider for the initial selection. + */ + protected ILabelProvider treeItemWrappedLabelProvider; + + /** + * The label provider for the containmentFeature. + */ + protected ILabelProvider containmentFeatureLabelProvider; + + /** + * The content provider for the containmentFeature. + */ + protected IStaticContentProvider containmentFeatureContentProvider; + + /** + * The modified paste configurations by tree item axis. + */ + protected Map<ITreeItemAxis, PasteEObjectConfiguration> pasteConfigurations; + + /** + * Constructor. + * + * @param pageName + * The page name. + * @param nattableManager + * The nattable manager. + * @param treeItemWrappedLabelProvider + * The label provider for the initial selection. + * @param containmentFeatureLabelProvider + * The label provider for the containment feature tree viewer. + * @param containmentFeatureContentProvider + * The content provider for the containment feature tree viewer. + */ + public ConfigurePastePage(final String pageName, final INattableModelManager nattableManager, final ILabelProvider treeItemWrappedLabelProvider, final ILabelProvider containmentFeatureLabelProvider, + final IStaticContentProvider containmentFeatureContentProvider) { + super(pageName); + setTitle(pageName); + this.nattableManager = nattableManager; + this.pasteConfigurations = new HashMap<ITreeItemAxis, PasteEObjectConfiguration>(); + this.treeItemWrappedLabelProvider = treeItemWrappedLabelProvider; + this.containmentFeatureLabelProvider = containmentFeatureLabelProvider; + this.containmentFeatureContentProvider = containmentFeatureContentProvider; + } + + /** + * This allows to set the initial element selected and update the treeviewer if already done. + * + * @param arrayList + * The initial element selected. + */ + public void setInitialElementSelections(final List<Object> arrayList) { + this.initialSelection = arrayList; + if (null != treeViewer) { + treeViewer.setInput(this.initialSelection); + treeViewer.expandAll(); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControl(final Composite parent) { + // Create a parent composite for paste axis (for column and row) + final Composite treeViewerComposite = new Composite(parent, SWT.NONE); + GridLayout gridLayout = new GridLayout(1, true); + treeViewerComposite.setLayout(gridLayout); + + final Tree tree = new Tree(treeViewerComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + final TreeColumnLayout columnLayout = new TreeColumnLayout(); + treeViewerComposite.setLayout(columnLayout); + + treeViewer = new TreeViewer(tree); + + // Create the first column and manage its display by the label provider of the initial selection + final TreeViewerColumn firstViewerColumn = createTreeViewerColumn(treeViewer, Messages.ConfigurePastePage_firstColumnTitle); + firstViewerColumn.getColumn().setAlignment(SWT.CENTER); + columnLayout.setColumnData(firstViewerColumn.getColumn(), new ColumnPixelData(225)); + firstViewerColumn.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(final Object element) { + return treeItemWrappedLabelProvider.getText(element); + } + + @Override + public Image getImage(final Object element) { + return treeItemWrappedLabelProvider.getImage(element); + } + }); + + // Create the second viewer column and manage its display and edition + final TreeViewerColumn secondViewerColumn = createTreeViewerColumn(treeViewer, Messages.ConfigurePastePage_secondColumnTitle); + secondViewerColumn.getColumn().setAlignment(SWT.CENTER); + columnLayout.setColumnData(secondViewerColumn.getColumn(), new ColumnPixelData(75)); + secondViewerColumn.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(final Object element) { + return null; + } + + }); + secondViewerColumn.setEditingSupport(new EditingSupport(treeViewer) { + + @Override + protected void setValue(final Object element, final Object value) { + if (canEditPasteConfiguration(element)) { + final PasteEObjectConfiguration pasteConfiguration = getPasteConfigurationFromTreeItemAxis((ITreeItemAxis) element); + + if (null != pasteConfiguration) { + if (null == pasteConfigurations.get(element)) { + pasteConfigurations.put((ITreeItemAxis) element, EcoreUtil.copy(pasteConfiguration)); + } + pasteConfigurations.get(element).setDetachedMode((Boolean) value); + } + treeViewer.refresh(); + } + } + + @Override + protected Object getValue(final Object element) { + return getDetachedMode(element); + } + + @Override + protected CellEditor getCellEditor(final Object element) { + return new CheckboxCellEditor(tree, SWT.CHECK | SWT.READ_ONLY); + } + + @Override + protected boolean canEdit(final Object element) { + return canEditPasteConfiguration(element); + } + }); + + // Create the third viewer column and manage its display and edition + final TreeViewerColumn thirdViewerColumn = createTreeViewerColumn(treeViewer, Messages.ConfigurePastePage_thirdColumnTitle); + thirdViewerColumn.getColumn().setAlignment(SWT.CENTER); + columnLayout.setColumnData(thirdViewerColumn.getColumn(), new ColumnPixelData(230)); + thirdViewerColumn.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(final Object element) { + // Must the managed in the paint item listener of the table (because we don't want to center values) + return null; + } + }); + thirdViewerColumn.setEditingSupport(new EditingSupport(treeViewer) { + + @Override + protected void setValue(final Object element, final Object value) { + if (canEditPasteConfiguration(element)) { + final PasteEObjectConfiguration pasteConfiguration = getPasteConfigurationFromTreeItemAxis((ITreeItemAxis) element); + + if (null != pasteConfiguration) { + if (null == pasteConfigurations.get(element)) { + pasteConfigurations.put((ITreeItemAxis) element, EcoreUtil.copy(pasteConfiguration)); + } + pasteConfigurations.get(element).setPastedElementId((String) value); + } + treeViewer.refresh(); + } + } + + @Override + protected Object getValue(final Object element) { + return getPastedElementId(element); + } + + @Override + protected CellEditor getCellEditor(final Object element) { + return new ExtendedComboBoxCellEditor(tree, Arrays.asList(new RowElementTypeIdContentProvider(nattableManager).getElements()), new LabelProvider(), SWT.READ_ONLY); + } + + @Override + protected boolean canEdit(final Object element) { + return canEditPasteConfiguration(element); + } + }); + + // Create the fourth viewer column and manage its display and edition + final TreeViewerColumn fourthViewerColumn = createTreeViewerColumn(treeViewer, Messages.ConfigurePastePage_fourthColumnTitle); + fourthViewerColumn.getColumn().setAlignment(SWT.CENTER); + columnLayout.setColumnData(fourthViewerColumn.getColumn(), new ColumnPixelData(200)); + fourthViewerColumn.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(final Object element) { + // Must the managed in the paint item listener of the table (because we don't want to center values) + return null; + } + + @Override + public Image getImage(final Object element) { + EStructuralFeature containmentFeature = getContainmentFeature(element); + if (null != containmentFeature) { + return containmentFeatureLabelProvider.getImage(containmentFeature); + } + return null; + } + }); + fourthViewerColumn.setEditingSupport(new EditingSupport(treeViewer) { + + @Override + protected void setValue(final Object element, final Object value) { + if (value instanceof EStructuralFeature) { + if (canEditPasteConfiguration(element)) { + final PasteEObjectConfiguration pasteConfiguration = getPasteConfigurationFromTreeItemAxis((ITreeItemAxis) element); + + if (null != pasteConfiguration) { + if (null == pasteConfigurations.get(element)) { + pasteConfigurations.put((ITreeItemAxis) element, EcoreUtil.copy(pasteConfiguration)); + } + pasteConfigurations.get(element).setPasteElementContainementFeature((EStructuralFeature) value); + } + treeViewer.refresh(); + } + } + } + + @Override + protected Object getValue(final Object element) { + return getContainmentFeatureAsString(element); + } + + @Override + protected CellEditor getCellEditor(final Object element) { + // Create a dialog for the containment feature selection + return new ExtendedDialogCellEditor(tree, new LabelProvider()) { + /** + * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control) + * + * @param cellEditorWindow + * @return + */ + @Override + protected Object openDialogBox(final Control cellEditorWindow) { + final TreeSelectorDialog dialog = new TreeSelectorDialog(cellEditorWindow.getShell()) { + @Override + protected void initViewerAndProvider() { + super.initViewerAndProvider(); + // Set a comparator to sort the tree viewer + getViewer().setComparator(new ViewerComparator(new StringComparator()));// should always be string element + } + }; + dialog.setTitle(Messages.ConfigurePastePage_fourthColumnTitle); + + ITreeContentProvider treeContentProvider = null; + if ((element instanceof IdTreeItemAxis && ((IdTreeItemAxis) element).getChildren().isEmpty() && 0 == Integer.parseInt(((IdTreeItemAxis) element).getElement())) + || (element instanceof ITreeItemAxis && ((ITreeItemAxis) element).getParent() instanceof IdTreeItemAxis && 0 == Integer.parseInt(((IdTreeItemAxis) ((ITreeItemAxis) element).getParent()).getElement()))) { + treeContentProvider = new EncapsulatedContentProvider(new RowContainmentFeatureContentProvider(nattableManager.getTable(), nattableManager.getTable().getContext().eClass())); + } else { + treeContentProvider = new ProviderBasedBrowseStrategy(new EncapsulatedContentProvider(containmentFeatureContentProvider)); + } + + dialog.setContentProvider(treeContentProvider); + dialog.setLabelProvider(containmentFeatureLabelProvider); + + if (dialog.open() == Window.OK) { + Object[] result = dialog.getResult(); + if (result.length == 0) { + return null; + } + + if (result[0] instanceof EObject) { + return result[0]; + } + } + return null; + } + }; + } + + @Override + protected boolean canEdit(final Object element) { + return canEditPasteConfiguration(element); + } + }); + + // The content provider of the initial selection + treeViewer.setContentProvider(new ITreeItemContentProvider() { + + @Override + public boolean hasChildren(final Object parent) { + if (parent instanceof ITreeItemAxis && CategoriesWizardUtils.isCategoryItem((ITreeItemAxis) parent)) { + return false; + } + return super.hasChildren(parent); + } + }); + + // Redefine the paint item listener to manage custom display in tree table + tree.addListener(SWT.PaintItem, new Listener() { + + @Override + public void handleEvent(Event event) { + TreeItem item = (TreeItem) event.item; + + if (event.index == 1) { + // Manage the CHECKED and UNCHECKED images and center it in the column + Image trailingImage = null; + + if (item.getData() instanceof ITreeItemAxis) { + if (canEditPasteConfiguration(item.getData())) { + final PasteEObjectConfiguration pasteConfiguration = getPasteConfigurationFromTreeItemAxis((ITreeItemAxis) item.getData()); + + if (null != pasteConfiguration) { + trailingImage = pasteConfiguration.isDetachedMode() ? CHECKED : UNCHECKED; + } + } + } + + if (trailingImage != null) { + // Calculate the center position + int itemWidth = tree.getColumn(event.index).getWidth(); + int imageWidth = trailingImage.getBounds().width; + int x = event.x + (itemWidth - imageWidth) / 2; + int itemHeight = tree.getItemHeight(); + int imageHeight = trailingImage.getBounds().height; + int y = event.y + (itemHeight - imageHeight) / 2; + + // Draw the image + event.gc.drawImage(trailingImage, x, y); + } + } else if (event.index == 2 || event.index == 3) { + // Manage the non-center text of the third and fourth columns + String text = null; + + // Get the needed value to display + if (2 == event.index) { + Object result = getPastedElementId(item.getData()); + text = null != result ? (String) result : ""; //$NON-NLS-1$ + } else if (3 == event.index) { + text = getContainmentFeatureAsString(item.getData()); + } + + final Image image = item.getImage(event.index); + + // Calculate the neede position of the text + int x = event.x + 2; + int yOffset = 0; + if (event.index == 1) { + Point size = event.gc.textExtent(text); + yOffset = Math.max(0, (event.height - size.y) / 2); + } + int y = event.y + yOffset; + + if (null != image) { + x += image.getBounds().width + 2; + } + + // Draw the text + event.gc.drawText(text, x, y, true); + } + } + }); + + setControl(treeViewerComposite); + } + + /** + * This allows to check the element to display and modify. This must be a structural feature tree axis or the id tree axis when the depath is 0 and filled by user; + * + * @param element + * The element to check. + * @return <code>true</code> if the element can be displayed and modified, <code>false</code> otherwise + */ + protected boolean canEditPasteConfiguration(final Object element) { + return (element instanceof IdTreeItemAxis && ((IdTreeItemAxis) element).getChildren().isEmpty() && 0 == Integer.parseInt(((IdTreeItemAxis) element).getElement())) + || (element instanceof EStructuralFeatureAxis && element instanceof ITreeItemAxis); + } + + /** + * Get the detached mode value. + * + * @param element + * The element. + * @return The boolean value or <code>null</code>. + */ + protected Object getDetachedMode(final Object element) { + Object result = null; + if (canEditPasteConfiguration(element)) { + final PasteEObjectConfiguration pasteConfiguration = getPasteConfigurationFromTreeItemAxis((ITreeItemAxis) element); + + if (null != pasteConfiguration) { + result = pasteConfiguration.isDetachedMode(); + } + } + return result; + } + + /** + * Get the pasted element id value. + * + * @param element + * The element. + * @return The string value or <code>null</code>. + */ + protected Object getPastedElementId(final Object element) { + Object result = null; + if (canEditPasteConfiguration(element)) { + final PasteEObjectConfiguration pasteConfiguration = getPasteConfigurationFromTreeItemAxis((ITreeItemAxis) element); + + if (null != pasteConfiguration) { + String pastedElementId = pasteConfiguration.getPastedElementId(); + if (null == pastedElementId || pastedElementId.isEmpty()) { + pastedElementId = UNDEFINED; + } + result = pastedElementId; + } + } + return result; + } + + /** + * Get the containment feature value. + * + * @param element + * The element. + * @return The string value of structural feature or <code>null</code>. + */ + protected EStructuralFeature getContainmentFeature(final Object element) { + EStructuralFeature result = null; + if (canEditPasteConfiguration(element)) { + final PasteEObjectConfiguration pasteConfiguration = getPasteConfigurationFromTreeItemAxis((ITreeItemAxis) element); + + if (null != pasteConfiguration) { + final EStructuralFeature pasteElementContainementFeature = pasteConfiguration.getPasteElementContainementFeature(); + if (null != pasteElementContainementFeature) { + result = pasteElementContainementFeature; + } + } + } + return result; + } + + /** + * Get the containment feature value. + * + * @param element + * The element. + * @return The string value of structural feature or <code>null</code>. + */ + protected String getContainmentFeatureAsString(final Object element) { + String result = ""; //$NON-NLS-1$ + if (canEditPasteConfiguration(element)) { + final EStructuralFeature containmentFeature = getContainmentFeature(element); + if (null != containmentFeature) { + result = containmentFeature.getName(); + } else { + result = UNDEFINED; + } + } + return result; + } + + /** + * This allows to create a tree viewer column in the tree viewer. + * + * @param viewer + * the tree viewer. + * @param title + * The title of the column. + * @return The created tree viewer column. + */ + protected TreeViewerColumn createTreeViewerColumn(final TreeViewer viewer, final String title) { + final TreeViewerColumn viewerColumn = new TreeViewerColumn(viewer, SWT.NONE); + final TreeColumn column = viewerColumn.getColumn(); + column.setText(title); + column.setResizable(true); + column.setMoveable(false); + return viewerColumn; + } + + /** + * This allows to get the paste configuration corresponding to a tree item axis. + * + * @param treeItemAxis + * The tree item axis + * @return The paste configuration corresponding to the tree item axis. + */ + protected PasteEObjectConfiguration getPasteConfigurationFromTreeItemAxis(final ITreeItemAxis treeItemAxis) { + PasteEObjectConfiguration pasteConfiguration = null; + // Check if the paste configuration of the tree item to modify was already modified and use it + if (null != pasteConfigurations.get(treeItemAxis)) { + pasteConfiguration = pasteConfigurations.get(treeItemAxis); + } else { + // The paste configuration was never used for this moment, get it from the tree item axis + pasteConfiguration = getChildrenPasteConfiguration(treeItemAxis); + if (null == pasteConfiguration) { + // The tree item axis doesn't contain the paste configuration, get it from the nattable configuration + int depth = -1; + boolean hasNoTreeFillingFirstDepth = false; + String category = null; + + // Check if the first depth contains a structural feature, else manage the paste configuration for the first level + if (treeItemAxis instanceof EStructuralFeatureAxis && treeItemAxis.getParent() instanceof IdTreeItemAxis) { + depth = Integer.parseInt(((IdTreeItemAxis) treeItemAxis.getParent()).getElement()); + category = ((EStructuralFeatureAxis) treeItemAxis).getElement().getName(); + } else if (treeItemAxis instanceof IdTreeItemAxis) { + depth = Integer.parseInt(((IdTreeItemAxis) treeItemAxis).getElement()); + hasNoTreeFillingFirstDepth = true; + } + + if (-1 != depth) { + pasteConfiguration = getPasteConfigurationsFor(nattableManager.getTable(), depth, category, hasNoTreeFillingFirstDepth); + } + } + } + + if (null == pasteConfiguration) { + pasteConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createPasteEObjectConfiguration(); + } + return pasteConfiguration; + } + + /** + * Get the child tree item axis of a tree item axis corresponding to a paste configuration. + * + * @param treeItemAxis + * the tree item axis. + * @return The paste configuration or <code>null</code>. + */ + protected PasteEObjectConfiguration getChildrenPasteConfiguration(final ITreeItemAxis treeItemAxis) { + PasteEObjectConfiguration result = null; + + if (!treeItemAxis.getChildren().isEmpty()) { + for (ITreeItemAxis childItemAxis : treeItemAxis.getChildren()) { + if (childItemAxis instanceof EObjectTreeItemAxis && childItemAxis.getElement() instanceof PasteEObjectConfiguration) { + result = (PasteEObjectConfiguration) childItemAxis.getElement(); + } + } + } + + return result; + } + + /** + * Get the paste configuration from the table. + * + * @param table + * The table. + * @param depth + * The depath to search. + * @param categoryName + * The category name is necessary (can be <code>nulll</code>). + * @param hasNoTreeFillingFirstDepth + * <code>true</code> if no tree filling configuration for depath 0, <code>false</code> otherwise. + * @return The found paste configuration. + */ + protected PasteEObjectConfiguration getPasteConfigurationsFor(final Table table, final int depth, final String categoryName, final boolean hasNoTreeFillingFirstDepth) { + PasteEObjectConfiguration result = null; + // The first depth has no tree filling configuration + if (hasNoTreeFillingFirstDepth) { + AbstractHeaderAxisConfiguration conf = table.getLocalRowHeaderAxisConfiguration(); + if (conf == null) { + conf = table.getTableConfiguration().getRowHeaderAxisConfiguration(); + } + final List<TreeFillingConfiguration> filling = FillingConfigurationUtils.getAllTreeFillingConfigurationForDepth(table, depth); + final List<IAxisConfiguration> referencedPasteConf = new ArrayList<IAxisConfiguration>(); + for (final TreeFillingConfiguration tmp : filling) { + if (tmp.getPasteConfiguration() != null) { + referencedPasteConf.add(tmp.getPasteConfiguration()); + } + } + final Iterator<IAxisConfiguration> axisConfIterator = conf.getOwnedAxisConfigurations().iterator(); + while (null == result && axisConfIterator.hasNext()) { + final IAxisConfiguration axisConf = axisConfIterator.next(); + if (axisConf instanceof PasteEObjectConfiguration && !referencedPasteConf.contains(axisConf)) { + result = (PasteEObjectConfiguration) axisConf; + } + } + } else { + // Iterate on existing tree filling to find the correct one + final Iterator<TreeFillingConfiguration> treeFillingConfIterator = FillingConfigurationUtils.getAllTreeFillingConfiguration(table).iterator(); + while (null == result && treeFillingConfIterator.hasNext()) { + final TreeFillingConfiguration curr = treeFillingConfIterator.next(); + if (curr.getDepth() == depth) { + if (null == categoryName || categoryName.isEmpty()) { + result = curr.getPasteConfiguration(); + } else { + String featureName = curr.getAxisUsedAsAxisProvider().getAlias(); + if (featureName == null || featureName.isEmpty()) { + final Object element = curr.getAxisUsedAsAxisProvider().getElement(); + if (element instanceof EStructuralFeature) { + featureName = ((EStructuralFeature) element).getName(); + } + } + if (categoryName.equals(featureName)) { + result = curr.getPasteConfiguration(); + } + } + } + } + } + return result; + } + + /** + * Get the paste configurations modified by tree item axis. + * + * @return The map of paste configurations modified by tree item axis. + */ + public Map<ITreeItemAxis, PasteEObjectConfiguration> getPasteConfigurations() { + return pasteConfigurations; + } +} |