diff options
author | Nicolas FAUVERGUE | 2015-11-03 17:11:16 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-11-10 12:32:14 +0000 |
commit | 90ed56f77a2194776567adccfa34407afbc2460f (patch) | |
tree | 97e7f6142b6ff2ba14afff9839c8144a912543a4 | |
parent | ff0b88a56e4c8944b924fc9f20010a0c721343cb (diff) | |
download | org.eclipse.papyrus-90ed56f77a2194776567adccfa34407afbc2460f.tar.gz org.eclipse.papyrus-90ed56f77a2194776567adccfa34407afbc2460f.tar.xz org.eclipse.papyrus-90ed56f77a2194776567adccfa34407afbc2460f.zip |
Bug 481307: [Table] Insert is visible for cell Selection and Column
Header selection
https://bugs.eclipse.org/bugs/show_bug.cgi?id=481307
Manage the enable of the insert handler (to avoid possible insert when
the selection is not correct).
Change-Id: I66959d9e2d63a111eba76a683d5c07e60f8f988c
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
3 files changed, 35 insertions, 4 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java index b10d918f867..9b0bbba510d 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.viewers.ISelection; import org.eclipse.papyrus.infra.nattable.manager.InsertInNattableManager; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection; import org.eclipse.papyrus.infra.nattable.utils.AbstractPasteInsertInTableHandler; import org.eclipse.papyrus.infra.nattable.utils.CSVPasteHelper; @@ -79,4 +80,34 @@ public class InsertInTableHandler extends AbstractPasteInsertInTableHandler { } return result; } + + /** + * @see org.eclipse.papyrus.infra.nattable.handler.AbstractTableHandler#setEnabled(java.lang.Object) + * + * @param evaluationContext + */ + @Override + public void setEnabled(final Object evaluationContext) { + super.setEnabled(evaluationContext); + if(isEnabled()){ + // Recalculate if the enable is allowed because the user can select cells and try to insert by click on rows for example. + boolean canEnable = false; + final INattableModelManager currentNattableModelManager = getCurrentNattableModelManager(); + if(null != currentNattableModelManager){ + final ISelection currentSelection = ((NattableModelManager)currentNattableModelManager).getSelectionInTable(); + if(null == currentSelection){ + canEnable = true; + }else if (currentSelection instanceof TableStructuredSelection) { + TableSelectionWrapper tableSelectionWrapper = (TableSelectionWrapper) ((TableStructuredSelection) currentSelection).getAdapter(TableSelectionWrapper.class); + if(null != tableSelectionWrapper){ + if(tableSelectionWrapper.getSelectedCells().isEmpty() + || !tableSelectionWrapper.getFullySelectedRows().isEmpty() && tableSelectionWrapper.getFullySelectedColumns().isEmpty()){ + canEnable = true; + } + } + } + } + setBaseEnabled(canEnable); + } + } } diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailColumns_H1_H1_H1_MultiColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailColumns_H1_H1_H1_MultiColumns_Test.java index e99f876af11..e66642d8eef 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailColumns_H1_H1_H1_MultiColumns_Test.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailColumns_H1_H1_H1_MultiColumns_Test.java @@ -14,7 +14,7 @@ package org.eclipse.papyrus.uml.nattable.clazz.config.tests.insert; import org.eclipse.core.runtime.IStatus; -import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; import org.eclipse.papyrus.infra.nattable.messages.Messages; import org.junit.Assert; @@ -43,7 +43,7 @@ public class InsertRowsFailColumns_H1_H1_H1_MultiColumns_Test extends AbstractIn @Override public void manageSelection(final NattableModelManager manager) throws Exception { super.manageSelection(manager); - manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 11, true, false)); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 11, true, false)); } /** diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailRows_H1_H1_H1_MultiColumns_Test.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailRows_H1_H1_H1_MultiColumns_Test.java index 800c2c0b657..5abfd0f26d8 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailRows_H1_H1_H1_MultiColumns_Test.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/InsertRowsFailRows_H1_H1_H1_MultiColumns_Test.java @@ -14,7 +14,7 @@ package org.eclipse.papyrus.uml.nattable.clazz.config.tests.insert; import org.eclipse.core.runtime.IStatus; -import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; import org.eclipse.papyrus.infra.nattable.messages.Messages; import org.junit.Assert; @@ -43,7 +43,7 @@ public class InsertRowsFailRows_H1_H1_H1_MultiColumns_Test extends AbstractInser @Override public void manageSelection(final NattableModelManager manager) throws Exception { super.manageSelection(manager); - manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectColumnCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 10, true, false)); + manager.getBodyLayerStack().getSelectionLayer().doCommand(new SelectRowsCommand(manager.getBodyLayerStack().getSelectionLayer(), 0, 10, true, false)); } /** |