Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2017-01-05 14:03:53 +0000
committerGerrit Code Review @ Eclipse.org2017-03-03 09:09:24 +0000
commit7a7d87b75c174e9a38a710aab101d74dd8456e14 (patch)
tree63234e0667c82257c6374b8dc9c3243fd80db3b5
parentc17bf6e6525851a6fdecee41c7e3a8b9dec59f86 (diff)
downloadorg.eclipse.papyrus-7a7d87b75c174e9a38a710aab101d74dd8456e14.tar.gz
org.eclipse.papyrus-7a7d87b75c174e9a38a710aab101d74dd8456e14.tar.xz
org.eclipse.papyrus-7a7d87b75c174e9a38a710aab101d74dd8456e14.zip
Bug 508175: [Table] NPE doing Invert Axis twice
https://bugs.eclipse.org/bugs/show_bug.cgi?id=508175 - Don't initialize the listeners for the table in properties view. Those ones don't need to be inverted, updated, ... Change-Id: I7e472b867c0f9d97c4c5c3d78ce52f5452e718ad Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.properties/src/org/eclipse/papyrus/infra/nattable/properties/modelelement/NatTableModelElement.java29
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java71
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java24
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableModelManagerFactory.java29
4 files changed, 109 insertions, 44 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 09f835c8bf4..acce95f2b98 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
@@ -10,7 +10,7 @@
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 323802
- * Nicolas FAUVERGUE (ALL4tEC) nicolas.fauvergue@all4tec.net - Bug 476618, 192891, 496905
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 476618, 192891, 496905, 508175
*
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.properties.modelelement;
@@ -130,7 +130,7 @@ public class NatTableModelElement extends EMFModelElement {
* a table manager created to get possible axis contents
*/
private INattableModelManager tableModelManager;
-
+
/**
* This allows to keep a reference to the table to manage (because the source must be modified when the edited object is not a table).
*
@@ -157,7 +157,8 @@ public class NatTableModelElement extends EMFModelElement {
* Add the listener
*/
private void init() {
- tableModelManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(getEditedTable(), new EObjectSelectionExtractor());
+ // The create nattable model manager for the properties view doesn't need some listeners of the table (invert axis and update cells map listener)
+ tableModelManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(getEditedTable(), new EObjectSelectionExtractor(), false);
this.interestingFeatures = new ArrayList<EStructuralFeature>();
interestingFeatures.add(NattablePackage.eINSTANCE.getTable_Prototype());
interestingFeatures.add(NattablePackage.eINSTANCE.getTable_Owner());
@@ -176,9 +177,9 @@ public class NatTableModelElement extends EMFModelElement {
interestingFeatures.add(NattablelabelproviderPackage.eINSTANCE.getObjectLabelProviderConfiguration_DisplayIcon());
interestingFeatures.add(NattablelabelproviderPackage.eINSTANCE.getObjectLabelProviderConfiguration_DisplayLabel());
- if(null != table){
+ if (null != table) {
this.tableListener = new AdapterImpl() {
-
+
/**
*
* @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
@@ -296,7 +297,7 @@ public class NatTableModelElement extends EMFModelElement {
final Event event = new Event();
final Iterator<IObservable> observableIterator = getObservables().values().iterator();
- while(observableIterator.hasNext()){
+ while (observableIterator.hasNext()) {
final IObservable current = observableIterator.next();
if (!current.isDisposed() && current instanceof Listener) {
((Listener) current).handleEvent(event);
@@ -314,7 +315,7 @@ public class NatTableModelElement extends EMFModelElement {
@Override
public void dispose() {
super.dispose();
- if(null != table){
+ if (null != table) {
table.eAdapters().remove(tableListener);
removeListeners();
table = null;
@@ -344,7 +345,7 @@ public class NatTableModelElement extends EMFModelElement {
@Override
protected IObservable doGetObservable(final String propertyPath) {
IObservable value = null;
-
+
Table table = getEditedTable();
// column header properties
if (Constants.LOCAL_COLUMN_HEADER_AXIS_CONFIGURATION_DISPLAY_FILTER.equals(propertyPath)) {
@@ -435,10 +436,10 @@ public class NatTableModelElement extends EMFModelElement {
} else if (Constants.COLUMN_PASTED_EOBJECT_AXIS_IDENTIFIER_FEATURE.equals(propertyPath)) {
value = new ColumnPasteEObjectAxisIdentifierObservableValue(table);
}
-
- else if(Constants.TABLE_LABEL.equals(propertyPath)){
- value = new TableLabelObservableValue(table);
- }
+
+ else if (Constants.TABLE_LABEL.equals(propertyPath)) {
+ value = new TableLabelObservableValue(table);
+ }
if (value != null) {
return value;
@@ -522,8 +523,8 @@ public class NatTableModelElement extends EMFModelElement {
} else if (Constants.COLUMN_PASTED_EOBJECT_AXIS_IDENTIFIER_FEATURE.equals(propertyPath)) {
res = new ColumnAxisIdentifierContentProvider(this.tableModelManager).getElements().length != 0;
}
-
- else if(Constants.TABLE_LABEL.equals(propertyPath)){
+
+ else if (Constants.TABLE_LABEL.equals(propertyPath)) {
res = true;
}
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
index 5aa01c44c8c..d316ec8d7f3 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java
@@ -9,7 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 476618, 504077, 496905
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 476618, 504077, 496905, 508175
* Nicolas Boulay (Esterel Technologies SAS) - Bug 497467
* Sebastien Bordes (Esterel Technologies SAS) - Bug 497738
*
@@ -255,6 +255,22 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
* the selection extrator
*/
public NattableModelManager(final Table rawModel, final ISelectionExtractor selectionExtractor) {
+ this(rawModel, selectionExtractor, true);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param rawModel
+ * The table model.
+ * @param selectionExtractor
+ * The selection extrator.
+ * @param initializeListeners
+ * boolean to determinate if the listeners have to be initialized or not (example: properties view doesn't it).
+ * @since 3.0
+ */
+ public NattableModelManager(final Table rawModel, final ISelectionExtractor selectionExtractor, final boolean initializeListeners) {
super(rawModel, selectionExtractor);
this.rowProvider = rawModel.getCurrentRowAxisProvider();
@@ -264,13 +280,34 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
this.cellsMap = HashBiMap.create();
- this.invertAxisListener = createInvertAxisListener();
+ init();
- if (this.invertAxisListener != null) {
- rawModel.eAdapters().add(this.invertAxisListener);
- }
+ // If needed, initialize the invert axis listener and the update of cells map.
+ // Other listeners can stay used in all cases.
+ // For example: The table reference for properties view, these listeners are not needed and can caught exception
+ if (initializeListeners) {
+ this.invertAxisListener = createInvertAxisListener();
- init();
+ if (this.invertAxisListener != null) {
+ rawModel.eAdapters().add(this.invertAxisListener);
+ }
+
+ tableCellsListener = new AdapterImpl() {
+
+ @Override
+ public void notifyChanged(final Notification msg) {
+ if (msg.getFeature() == NattablePackage.eINSTANCE.getTable_Cells()) {
+ updateCellMap(msg);
+ }
+ }
+ };
+ rawModel.eAdapters().add(tableCellsListener);
+
+ addListeners();
+ } else {
+ tableCellsListener = null;
+ invertAxisListener = null;
+ }
changeAxisProvider = new AdapterImpl() {
@@ -311,18 +348,6 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
};
rawModel.eAdapters().add(changeAxisProvider);
- tableCellsListener = new AdapterImpl() {
-
- @Override
- public void notifyChanged(final Notification msg) {
- if (msg.getFeature() == NattablePackage.eINSTANCE.getTable_Cells()) {
- updateCellMap(msg);
- }
- }
- };
- rawModel.eAdapters().add(tableCellsListener);
-
- addListeners();
}
/**
@@ -414,10 +439,12 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen
* remove required listener
*/
protected void removeListeners() {
- final EventList<?> rowsList = (EventList<?>) getRowElementsList();
- final EventList<?> columnsList = (EventList<?>) getColumnElementsList();
- rowsList.removeListEventListener(this.listEventListener);
- columnsList.removeListEventListener(this.listEventListener);
+ if (null != listEventListener) {
+ final EventList<?> rowsList = (EventList<?>) getRowElementsList();
+ final EventList<?> columnsList = (EventList<?>) getColumnElementsList();
+ rowsList.removeListEventListener(this.listEventListener);
+ columnsList.removeListEventListener(this.listEventListener);
+ }
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java
index 5bbb3629c83..be55f2a0e43 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/TreeNattableModelManager.java
@@ -9,6 +9,7 @@
* Contributors:
* CEA LIST - Initial API and implementation
* Dirk Fauth <dirk.fauth@googlemail.com> - Bug 488234
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 508175
*
*****************************************************************************/
@@ -147,10 +148,27 @@ public class TreeNattableModelManager extends NattableModelManager implements IT
* Constructor.
*
* @param rawModel
+ * The table model.
* @param selectionExtractor
+ * The selection extrator.
*/
public TreeNattableModelManager(Table rawModel, ISelectionExtractor selectionExtractor) {
- super(rawModel, selectionExtractor);
+ this(rawModel, selectionExtractor, true);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param rawModel
+ * The table model.
+ * @param selectionExtractor
+ * The selection extrator.
+ * @param initializeListeners
+ * Boolean to determinate if the listeners have to be initialized or not (example: properties view doesn't it).
+ * @since 3.0
+ */
+ public TreeNattableModelManager(final Table rawModel, final ISelectionExtractor selectionExtractor, final boolean initializeListeners) {
+ super(rawModel, selectionExtractor, initializeListeners);
Assert.isTrue(TableHelper.isTreeTable(rawModel));
// Manage the change axis provider adapter only for the column (row cannot manage refresh)
@@ -322,7 +340,7 @@ public class TreeNattableModelManager extends NattableModelManager implements IT
}
return nattable;
}
-
+
/**
* Get the width of the slider composite.
*
@@ -414,7 +432,7 @@ public class TreeNattableModelManager extends NattableModelManager implements IT
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
int width = ((ClientAreaAdapter) left.getClientAreaProvider()).getWidth();
- if(null != getRowHeaderLayerStack() && null != getRowHeaderLayerStack().getIndexRowHeaderLayer()){
+ if (null != getRowHeaderLayerStack() && null != getRowHeaderLayerStack().getIndexRowHeaderLayer()) {
width += getRowHeaderLayerStack().getIndexRowHeaderLayer().getWidth();
}
return new Point(width, scrollbarHeight);
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableModelManagerFactory.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableModelManagerFactory.java
index b9d40cb9b93..2c30cef5f39 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableModelManagerFactory.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableModelManagerFactory.java
@@ -8,6 +8,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 508175
*
*****************************************************************************/
@@ -34,15 +35,33 @@ public class NattableModelManagerFactory {
/**
*
* @param table
- * the table model
+ * The table model.
+ * @param selectionExtractor
+ * The selection extrator.
* @return
- * the INattableModelManager to use to manipulate the table
+ * the INattableModelManager to use to manipulate the table.
*/
- public INattableModelManager createNatTableModelManager(final Table table, ISelectionExtractor selectionExtractor) {
+ public INattableModelManager createNatTableModelManager(final Table table, final ISelectionExtractor selectionExtractor) {
+ return createNatTableModelManager(table, selectionExtractor, true);
+ }
+
+ /**
+ *
+ * @param table
+ * The table model.
+ * @param selectionExtractor
+ * The selection extrator.
+ * @param initializeListeners
+ * Boolean to determinate if the listeners have to be initialized or not (example: properties view doesn't it)
+ * @return
+ * the INattableModelManager to use to manipulate the table
+ * @since 3.0
+ */
+ public INattableModelManager createNatTableModelManager(final Table table, final ISelectionExtractor selectionExtractor, final boolean initializeListeners) {
if (TableHelper.isTreeTable(table)) {
- return new TreeNattableModelManager(table,selectionExtractor);
+ return new TreeNattableModelManager(table,selectionExtractor, initializeListeners);
}
- return new NattableModelManager(table, selectionExtractor);
+ return new NattableModelManager(table, selectionExtractor, initializeListeners);
}
}

Back to the top