From e3820d2ee8a48f601723b437bb4f07f282846d0e Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Mon, 5 Dec 2016 17:33:23 +0100 Subject: Bug 506067: NullPointerException in AbstractPostActionIdsProvider.getElements https://bugs.eclipse.org/bugs/show_bug.cgi?id=506067 - Fix a NPE Change-Id: Iabe7346da22ac7631db2587cce9f3e97fe620882 Signed-off-by: Nicolas FAUVERGUE --- .../provider/AbstractPostActionIdsProvider.java | 214 +++++++++++---------- 1 file changed, 109 insertions(+), 105 deletions(-) (limited to 'plugins/infra') diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractPostActionIdsProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractPostActionIdsProvider.java index ea45d4a54fe..7305b9f36d4 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractPostActionIdsProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/provider/AbstractPostActionIdsProvider.java @@ -1,105 +1,109 @@ -/***************************************************************************** - * 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.emf.ecore.EClass; -import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationPackage; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; -import org.eclipse.papyrus.infra.nattable.paste.PastePostActionRegistry; -import org.eclipse.papyrus.infra.nattable.utils.AxisConfigurationUtils; -import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; - - -public abstract class AbstractPostActionIdsProvider implements IStaticContentProvider { - - /** - * true if we are editing column - */ - private final boolean isEditingColumn; - - /** - * the table manager - */ - private INattableModelManager tableManager; - - /** - * - * Constructor. - * - * @param tableManager - * the table manager - * @param isEditingColumn - * true if we are editing columns - */ - public AbstractPostActionIdsProvider(final INattableModelManager tableManager, final boolean isEditingColumn) { - this.tableManager = tableManager; - this.isEditingColumn = isEditingColumn; - } - - /** - * - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - * - */ - @Override - public void dispose() { - this.tableManager = null; - } - - /** - * - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - * - * @param inputElement - * @return - */ - @Override - public Object[] getElements(Object inputElement) { - final PasteEObjectConfiguration conf = (PasteEObjectConfiguration) AxisConfigurationUtils.getIAxisConfigurationUsedInTable(this.tableManager.getTable(), NattableaxisconfigurationPackage.eINSTANCE.getPasteEObjectConfiguration(), isEditingColumn); - if (conf != null && conf.getPastedElementId() != null) { - final EClass eClass = ElementTypeRegistry.getInstance().getType(conf.getPastedElementId()).getEClass(); - return PastePostActionRegistry.INSTANCE.getAvailablePostActionIds(this.tableManager, eClass).toArray(); - } - return new Object[0]; - } - - - /** - * - * @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 void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // nothing to do - } - - /** - * - * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements() - * - * @return - */ - @Override - public 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.properties.provider; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationPackage; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; +import org.eclipse.papyrus.infra.nattable.paste.PastePostActionRegistry; +import org.eclipse.papyrus.infra.nattable.utils.AxisConfigurationUtils; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; + + +public abstract class AbstractPostActionIdsProvider implements IStaticContentProvider { + + /** + * true if we are editing column + */ + private final boolean isEditingColumn; + + /** + * the table manager + */ + private INattableModelManager tableManager; + + /** + * + * Constructor. + * + * @param tableManager + * the table manager + * @param isEditingColumn + * true if we are editing columns + */ + public AbstractPostActionIdsProvider(final INattableModelManager tableManager, final boolean isEditingColumn) { + this.tableManager = tableManager; + this.isEditingColumn = isEditingColumn; + } + + /** + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + * + */ + @Override + public void dispose() { + this.tableManager = null; + } + + /** + * + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + * + * @param inputElement + * @return + */ + @Override + public Object[] getElements(Object inputElement) { + final PasteEObjectConfiguration conf = (PasteEObjectConfiguration) AxisConfigurationUtils.getIAxisConfigurationUsedInTable(this.tableManager.getTable(), NattableaxisconfigurationPackage.eINSTANCE.getPasteEObjectConfiguration(), isEditingColumn); + if (conf != null && conf.getPastedElementId() != null) { + final IElementType elementType = ElementTypeRegistry.getInstance().getType(conf.getPastedElementId()); + if(null != elementType){ + final EClass eClass = elementType.getEClass(); + return PastePostActionRegistry.INSTANCE.getAvailablePostActionIds(this.tableManager, eClass).toArray(); + } + } + return new Object[0]; + } + + + /** + * + * @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 void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // nothing to do + } + + /** + * + * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements() + * + * @return + */ + @Override + public Object[] getElements() { + return getElements(null); + } + +} -- cgit v1.2.3