Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2015-05-21 12:34:00 +0000
committerVincent Lorenzo2015-05-21 14:55:47 +0000
commitc949fd24d3919c972b982879351fcb29341fb48c (patch)
treeab725b2158b0283cee793254f6807309cd8366c8 /plugins
parent81b3cb328915df1ceaa7216370c9e28b5d47d4cd (diff)
downloadorg.eclipse.papyrus-c949fd24d3919c972b982879351fcb29341fb48c.tar.gz
org.eclipse.papyrus-c949fd24d3919c972b982879351fcb29341fb48c.tar.xz
org.eclipse.papyrus-c949fd24d3919c972b982879351fcb29341fb48c.zip
466447: [TreeTable] Missing method to reload a (hierarchic) table
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml31
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java22
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/ReloadNattableWidgetInEditorHandler.java91
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.model/src/org/eclipse/papyrus/infra/nattable/model/factory/IAxisFactory.java2
4 files changed, 145 insertions, 1 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml
index ba38bc5aeab..0a36c08b5de 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml
@@ -258,4 +258,35 @@
strategy="org.eclipse.papyrus.infra.nattable.common.strategy.paste.TablePasteStrategy">
</strategy>
</extension>
+<extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.infra.nattable.category"
+ description="This command allow to reload the table widget"
+ id="org.eclipse.papyrus.infra.nattable.common.reload.table.editor.command"
+ name="Reload Table Widget">
+ </command>
+</extension>
+<extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <command
+ commandId="org.eclipse.papyrus.infra.nattable.common.reload.table.editor.command"
+ label="Reload Table Editor"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ </menuContribution>
+</extension>
+<extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.infra.nattable.common.handlers.ReloadNattableWidgetInEditorHandler"
+ commandId="org.eclipse.papyrus.infra.nattable.common.reload.table.editor.command">
+ </handler>
+</extension>
</plugin>
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
index 6f405baeeb5..77f99308d69 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
@@ -27,6 +27,7 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.preference.PreferenceStore;
+import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.papyrus.infra.core.editor.reload.IReloadContextProvider;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
@@ -61,7 +62,7 @@ public abstract class AbstractEMFNattableEditor extends EditorPart implements Na
/**
* the table manager
*/
- protected final INattableModelManager tableManager;
+ protected INattableModelManager tableManager;
/**
* the part name synchronizer
@@ -234,6 +235,25 @@ public abstract class AbstractEMFNattableEditor extends EditorPart implements Na
return super.getAdapter(adapter);
}
+ /**
+ * this method is used dispose the existing nattable widget and recreate a new one.
+ * It has been created to be able to reload a table when a bug broke the table after a user action.
+ *
+ * see bug 466447: [TreeTable] Missing method to reload a (hierarchic) table
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=466447
+ */
+ public void reloadNattableModelManager() {
+ Table rawModel = this.tableManager.getTable();
+ // we dispose the previous nattable widget
+ NatTable nattable = this.tableManager.getAdapter(NatTable.class);
+ Composite parent = nattable.getParent();
+ nattable.dispose();
+ this.tableManager.dispose();
+ this.tableManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(rawModel, new EObjectSelectionExtractor());
+ nattable = this.tableManager.createNattable(parent, SWT.NONE, getSite());
+ nattable.getParent().layout();
+ }
+
@Override
public void dispose() {
saveLocalPreferenceStoreValues();
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/ReloadNattableWidgetInEditorHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/ReloadNattableWidgetInEditorHandler.java
new file mode 100755
index 00000000000..4295d613ee8
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/handlers/ReloadNattableWidgetInEditorHandler.java
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.common.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.papyrus.infra.nattable.common.editor.AbstractEMFNattableEditor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ *
+ * @author VL222926
+ * This handler allows to the user to recreate the table in the editor. It is useful in case of broken table after a user action
+ */
+public class ReloadNattableWidgetInEditorHandler extends AbstractHandler {
+
+ /**
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ AbstractEMFNattableEditor nattableEditor = getNattableEditor(event);
+ if (nattableEditor != null) {
+ nattableEditor.reloadNattableModelManager();
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.nattable.handler.AbstractTableHandler#setEnabled(java.lang.Object)
+ *
+ * @param evaluationContext
+ */
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ if (evaluationContext instanceof IEvaluationContext) {
+ AbstractEMFNattableEditor editor = getNattableEditor(evaluationContext);
+ setBaseEnabled(editor != null);
+ } else {
+ setBaseEnabled(false);
+ }
+ }
+
+ /**
+ *
+ * @param event
+ *
+ * @return
+ * the nattable editor or <code>null</code> if not found
+ */
+ private AbstractEMFNattableEditor getNattableEditor(Object event) {
+ IEditorPart editor = null;
+ AbstractEMFNattableEditor nattableEditor = null;
+ if (event instanceof IEvaluationContext) {
+ Object part = HandlerUtil.getVariable(event, "activePart"); //$NON-NLS-1$
+ if(part instanceof IEditorPart){
+ editor = (IEditorPart) part;
+ }
+ } else if (event instanceof ExecutionEvent) {
+ editor = HandlerUtil.getActiveEditor((ExecutionEvent) event);
+ }
+
+ if (editor != null) {
+ if (editor instanceof AbstractEMFNattableEditor) {
+ nattableEditor = (AbstractEMFNattableEditor) editor;
+ } else {
+ nattableEditor = editor.getAdapter(AbstractEMFNattableEditor.class);
+ }
+ }
+ return nattableEditor;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.model/src/org/eclipse/papyrus/infra/nattable/model/factory/IAxisFactory.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.model/src/org/eclipse/papyrus/infra/nattable/model/factory/IAxisFactory.java
index d07d7d43fb2..47c64bdde80 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.model/src/org/eclipse/papyrus/infra/nattable/model/factory/IAxisFactory.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.model/src/org/eclipse/papyrus/infra/nattable/model/factory/IAxisFactory.java
@@ -89,11 +89,13 @@ public class IAxisFactory {
if(object instanceof String) {
FeatureIdAxis axis = NattableaxisFactory.eINSTANCE.createFeatureIdAxis();
axis.setElement((String)object);
+ axis.setAlias(alias);
return axis;
}
if(object instanceof EStructuralFeature) {
EStructuralFeatureAxis axis = NattableaxisFactory.eINSTANCE.createEStructuralFeatureAxis();
axis.setElement((EStructuralFeature)object);
+ axis.setAlias(alias);
return axis;
}
throw new UnsupportedOperationException(NLS.bind("The creation for {0} is not yet implemented", object)); //$NON-NLS-1$

Back to the top