From c89fa60d018cc673e324c6de0c7f3cf8c6927d25 Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Wed, 11 Feb 2015 18:18:45 +0100 Subject: 458260: [Table 2] Formatting of typed elements in 'reference' cells https://bugs.eclipse.org/bugs/show_bug.cgi?id=458260 Change-Id: Ie36dd81e8e5b61dbbb7a6ff329a5a3be7da330ed Signed-off-by: Nicolas FAUVERGUE --- .../META-INF/MANIFEST.MF | 110 +++++----- .../provider/GenericCellLabelProvider.java | 243 +++++++++++++-------- .../provider/UMLTypedElementCellLabelProvider.java | 40 ++++ 3 files changed, 247 insertions(+), 146 deletions(-) create mode 100644 plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/UMLTypedElementCellLabelProvider.java 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 3adf716cb33..0df810bd327 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 @@ -1,55 +1,55 @@ -Manifest-Version: 1.0 -Require-Bundle: org.eclipse.papyrus.infra.widgets;bundle-version="1.0.2", - org.eclipse.core.runtime, - org.eclipse.emf.transaction, - org.eclipse.emf.ecore, - org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.7.0", - org.eclipse.emf.edit, - org.eclipse.papyrus.infra.core.log;bundle-version="1.0.2", - org.eclipse.swt, - org.eclipse.papyrus.infra.emf;bundle-version="1.0.2", - org.eclipse.papyrus.infra.core;bundle-version="1.0.2", - org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.2", - org.eclipse.papyrus.infra.nattable.model;bundle-version="1.0.2", - org.eclipse.papyrus.infra.tools;bundle-version="1.0.2", - org.eclipse.emf.edit.ui, - org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.2", - org.eclipse.nebula.widgets.nattable.core;bundle-version="[1.1.0, - 2.0.0)", - org.eclipse.core.expressions, - org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.2", - org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.0.2", - org.apache.commons.lang, - com.google.guava;bundle-version="11.0.0", - org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.2", - org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.2" -Export-Package: org.eclipse.papyrus.infra.nattable, - org.eclipse.papyrus.infra.nattable.celleditor, - org.eclipse.papyrus.infra.nattable.celleditor.config, - org.eclipse.papyrus.infra.nattable.command, - org.eclipse.papyrus.infra.nattable.configuration, - org.eclipse.papyrus.infra.nattable.dataprovider, - org.eclipse.papyrus.infra.nattable.handler, - org.eclipse.papyrus.infra.nattable.layerstack, - org.eclipse.papyrus.infra.nattable.listener, - org.eclipse.papyrus.infra.nattable.manager.axis, - org.eclipse.papyrus.infra.nattable.manager.cell, - org.eclipse.papyrus.infra.nattable.manager.table, - org.eclipse.papyrus.infra.nattable.messages, - org.eclipse.papyrus.infra.nattable.nattableconfiguration, - org.eclipse.papyrus.infra.nattable.painter, - org.eclipse.papyrus.infra.nattable.paste, - org.eclipse.papyrus.infra.nattable.preferences, - org.eclipse.papyrus.infra.nattable.provider, - org.eclipse.papyrus.infra.nattable.reorder, - org.eclipse.papyrus.infra.nattable.tester, - org.eclipse.papyrus.infra.nattable.utils, - org.eclipse.papyrus.infra.nattable.widget -Bundle-Vendor: %Bundle-Vendor -Bundle-ActivationPolicy: lazy -Bundle-Version: 1.0.2.qualifier -Bundle-Name: %Bundle-Name -Bundle-ManifestVersion: 2 -Bundle-Activator: org.eclipse.papyrus.infra.nattable.Activator -Bundle-SymbolicName: org.eclipse.papyrus.infra.nattable;singleton:=true -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Manifest-Version: 1.0 +Require-Bundle: org.eclipse.papyrus.infra.widgets;bundle-version="1.0.2", + org.eclipse.core.runtime, + org.eclipse.emf.transaction, + org.eclipse.emf.ecore, + org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.7.0", + org.eclipse.emf.edit, + org.eclipse.papyrus.infra.core.log;bundle-version="1.0.2", + org.eclipse.swt, + org.eclipse.papyrus.infra.emf;bundle-version="1.0.2", + org.eclipse.papyrus.infra.core;bundle-version="1.0.2", + org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.2", + org.eclipse.papyrus.infra.nattable.model;bundle-version="1.0.2", + org.eclipse.papyrus.infra.tools;bundle-version="1.0.2", + org.eclipse.emf.edit.ui, + org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.2", + org.eclipse.nebula.widgets.nattable.core;bundle-version="[1.1.0,2.0.0)", + org.eclipse.core.expressions, + org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.2", + org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.0.2", + org.apache.commons.lang, + com.google.guava;bundle-version="11.0.0", + org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.2", + org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.2", + org.eclipse.uml2.uml;bundle-version="5.0.1" +Export-Package: org.eclipse.papyrus.infra.nattable, + org.eclipse.papyrus.infra.nattable.celleditor, + org.eclipse.papyrus.infra.nattable.celleditor.config, + org.eclipse.papyrus.infra.nattable.command, + org.eclipse.papyrus.infra.nattable.configuration, + org.eclipse.papyrus.infra.nattable.dataprovider, + org.eclipse.papyrus.infra.nattable.handler, + org.eclipse.papyrus.infra.nattable.layerstack, + org.eclipse.papyrus.infra.nattable.listener, + org.eclipse.papyrus.infra.nattable.manager.axis, + org.eclipse.papyrus.infra.nattable.manager.cell, + org.eclipse.papyrus.infra.nattable.manager.table, + org.eclipse.papyrus.infra.nattable.messages, + org.eclipse.papyrus.infra.nattable.nattableconfiguration, + org.eclipse.papyrus.infra.nattable.painter, + org.eclipse.papyrus.infra.nattable.paste, + org.eclipse.papyrus.infra.nattable.preferences, + org.eclipse.papyrus.infra.nattable.provider, + org.eclipse.papyrus.infra.nattable.reorder, + org.eclipse.papyrus.infra.nattable.tester, + org.eclipse.papyrus.infra.nattable.utils, + org.eclipse.papyrus.infra.nattable.widget +Bundle-Vendor: %Bundle-Vendor +Bundle-ActivationPolicy: lazy +Bundle-Version: 1.0.2.qualifier +Bundle-Name: %Bundle-Name +Bundle-ManifestVersion: 2 +Bundle-Activator: org.eclipse.papyrus.infra.nattable.Activator +Bundle-SymbolicName: org.eclipse.papyrus.infra.nattable;singleton:=true +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/GenericCellLabelProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/GenericCellLabelProvider.java index dc0ec6f15fd..76dcb74290b 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/GenericCellLabelProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/GenericCellLabelProvider.java @@ -1,91 +1,152 @@ -/***************************************************************************** - * 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.provider; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; -import org.eclipse.papyrus.infra.nattable.utils.Constants; -import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderCellContextElementWrapper; -import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper; -import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; - -/** - * The generic label provider for the cells - * - * @author Vincent Lorenzo - * - */ -public class GenericCellLabelProvider extends AbstractNattableCellLabelProvider { - - /** - * Limit the number of displayed elements for collections - */ - public static final int MAX_DISPLAYED_ELEMENTS = 10; - - /** - * - * @see org.eclipse.papyrus.infra.nattable.provider.AbstractNattableCellLabelProvider#accept(java.lang.Object) - * - * @param element - * @return - * true if the element is an instance of {@link ILabelProviderContextElementWrapper} and if the cell represents an {@link EStructuralFeature} of an {@link EObject} - */ - @Override - public boolean accept(Object element) { - return element instanceof ILabelProviderCellContextElementWrapper; - } - - /** - * - * @see org.eclipse.papyrus.infra.nattable.provider.AbstractNattableCellLabelProvider#getText(java.lang.Object) - * - * @param element - * @return - */ - @Override - public String getText(Object element) { - final ILabelProviderCellContextElementWrapper contextElement = (ILabelProviderCellContextElementWrapper) element; - final IConfigRegistry registry = ((ILabelProviderContextElementWrapper) element).getConfigRegistry(); - Object value = contextElement.getObject(); - final StringBuffer label = new StringBuffer(); - final LabelProviderService service = getLabelProviderService(registry); - if (value instanceof Collection) { - Iterator iter = ((Collection) value).iterator(); - label.append(Constants.BEGIN_OF_COLLECTION); - int i = 1; - while (iter.hasNext()) { - if (i > MAX_DISPLAYED_ELEMENTS) { - label.append(Constants.BIG_COLLECTION); - break; - } - - Object current = iter.next(); - label.append(service.getLabelProvider(current).getText(current)); - if (iter.hasNext()) { - label.append(Constants.SEPARATOR); - } - i++; - } - - label.append(Constants.END_OF_COLLECTION); - } else { - label.append(service.getLabelProvider(value).getText(value)); - } - return label.toString(); - } -} +/***************************************************************************** + * 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 458260 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.nattable.provider; + +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; +import org.eclipse.papyrus.infra.nattable.utils.Constants; +import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderCellContextElementWrapper; +import org.eclipse.papyrus.infra.nattable.utils.ILabelProviderContextElementWrapper; +import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; + +/** + * The generic label provider for the cells + * + * @author Vincent Lorenzo + * + */ +public class GenericCellLabelProvider extends AbstractNattableCellLabelProvider { + + /** + * Limit the number of displayed elements for collections + */ + public static final int MAX_DISPLAYED_ELEMENTS = 10; + + /** + * + * @see org.eclipse.papyrus.infra.nattable.provider.AbstractNattableCellLabelProvider#accept(java.lang.Object) + * + * @param element + * @return + * true if the element is an instance of {@link ILabelProviderContextElementWrapper} and if the cell represents an {@link EStructuralFeature} of an {@link EObject} + */ + @Override + public boolean accept(Object element) { + return element instanceof ILabelProviderCellContextElementWrapper; + } + + /** + * + * @see org.eclipse.papyrus.infra.nattable.provider.AbstractNattableCellLabelProvider#getText(java.lang.Object) + * + * @param element + * @return + */ + @Override + public String getText(Object element) { + final ILabelProviderCellContextElementWrapper contextElement = (ILabelProviderCellContextElementWrapper) element; + final IConfigRegistry registry = ((ILabelProviderContextElementWrapper) element).getConfigRegistry(); + final Object value = contextElement.getObject(); + final LabelProviderService service = getLabelProviderService(registry); + return getText(service, value); + } + + /** + * Get the text for the value. + * + * @param service The label provider service. + * @param value The value to parse. + * @return The string representing the object. + */ + protected String getText(LabelProviderService service, Object value){ + final StringBuffer label = new StringBuffer(); + if (value instanceof Collection) { + label.append(getCollectionText(service, (Collection)value)); + } else { + label.append(service.getLabelProvider(value).getText(value)); + } + return label.toString(); + } + + /** + * This allow to manage if the hooks of collection will be displayed or not. + * + * @return false + */ + private boolean isDisplayCollectionHooks(){ + // This allow to manage if the hooks of collection will be displayed or not + // This will be managed by preference later + return false; + } + + /** + * This allow to manage if the big collection display will be added. + * + * @return false + */ + private boolean isDisplayBigCollection(){ + // This allow to manage if the big collection display will be added or not + // This will be managed by preference later + return false; + } + + /** + * Get the text for the collection object. + * + * @param service The label provider service. + * @param value The value to parse. + * @return The string representing the object. + */ + protected String getCollectionText(LabelProviderService service, Collection value){ + final StringBuffer label = new StringBuffer(); + Iterator iter = ((Collection) value).iterator(); + if(isDisplayCollectionHooks()) + label.append(Constants.BEGIN_OF_COLLECTION); + int i = 1; + while (iter.hasNext()) { + if (i > MAX_DISPLAYED_ELEMENTS) { + if(isDisplayBigCollection()) + label.append(Constants.BIG_COLLECTION); + break; + } + + Object current = iter.next(); + label.append(getElementText(service, current)); + if (iter.hasNext()) { + label.append(Constants.SEPARATOR); + } + i++; + } + + if(isDisplayCollectionHooks()) + label.append(Constants.END_OF_COLLECTION); + return label.toString(); + } + + /** + * Get the text for the element. + * + * @param service The label provider service. + * @param value The value to parse. + * @return The string representing the object. + */ + protected String getElementText(LabelProviderService service, Object value){ + return service.getLabelProvider(value).getText(value); + } +} \ No newline at end of file diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/UMLTypedElementCellLabelProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/UMLTypedElementCellLabelProvider.java new file mode 100644 index 00000000000..0e297a26e2a --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/UMLTypedElementCellLabelProvider.java @@ -0,0 +1,40 @@ +/***************************************************************************** + * 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 - Initial API and implementation & Bug 458260 + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.nattable.provider; + +import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; +import org.eclipse.uml2.uml.TypedElement; + +/** + * The cell label provider for the UML typed elements. + * + * @author Nicolas FAUVERGUE + */ +public class UMLTypedElementCellLabelProvider extends GenericCellLabelProvider{ + + /** + * @see org.eclipse.papyrus.infra.nattable.provider.GenericCellLabelProvider#getSingleText(org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService, java.lang.Object) + * + * Manage the typed element. + * {@inheritDoc} + */ + @Override + protected String getElementText(LabelProviderService service, Object value){ + if(value instanceof TypedElement){ + return ((TypedElement) value).getName(); + } + return super.getElementText(service, value); + } + +} -- cgit v1.2.3