Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2015-06-30 15:48:26 +0000
committervincent lorenzo2015-07-20 15:00:55 +0000
commit3dff38d5d1f72e4e60a58eff5bdd64bc6708beee (patch)
tree0983cda8f76bcbb141618baa27df3d260df29537
parenta4679ef2f640e89e6dee2cc2876ae8e4ade1b6b8 (diff)
downloadorg.eclipse.papyrus-3dff38d5d1f72e4e60a58eff5bdd64bc6708beee.tar.gz
org.eclipse.papyrus-3dff38d5d1f72e4e60a58eff5bdd64bc6708beee.tar.xz
org.eclipse.papyrus-3dff38d5d1f72e4e60a58eff5bdd64bc6708beee.zip
Bug 470796: [Table] Filter on integer value does not work for integer<0
https://bugs.eclipse.org/bugs/show_bug.cgi?id=470796 - Add the optional operator '-' for the integer comparator - Change the depath management only for the natural values (superior or equal to 0) - Add the data validator the JUnit tests only for the numerical tests Change-Id: Iec790eb9bdfab6b17ac8996c3df5726d3ca08895 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/CategoriesWizardUtils.java2
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java2
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypeUtils.java2
-rwxr-xr-xtests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AbstractFilterMatcherTest.java65
-rwxr-xr-xtests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/FilterNumericMatcherTest.java16
5 files changed, 61 insertions, 26 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/CategoriesWizardUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/CategoriesWizardUtils.java
index ac5ab6c79bd..6dc2b3b80e7 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/CategoriesWizardUtils.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/CategoriesWizardUtils.java
@@ -53,7 +53,7 @@ public class CategoriesWizardUtils {
public static final boolean isDepthItem(ITreeItemAxis axis) {
if (axis instanceof IdTreeItemAxis) {
String element = ((IdTreeItemAxis) axis).getElement();
- return TypeUtils.isIntegerValue(element);
+ return TypeUtils.isNaturalValue(element);
}
return false;
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java
index 6db7a1437ce..a95f4ab7c42 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/wizard/ConfigureTableCategoriesWizard.java
@@ -301,7 +301,7 @@ public class ConfigureTableCategoriesWizard extends AbstractTableWizard {
ITreeItemAxis axis = (ITreeItemAxis) arg0;
Object element = axis.getElement();
if (element instanceof String) {
- if (TypeUtils.isIntegerValue((String) element)) {
+ if (TypeUtils.isNaturalValue((String) element)) {
Integer value = Integer.parseInt((String) element);
int depth = value;
if (depth == 0 && axis.getChildren().isEmpty()) {
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypeUtils.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypeUtils.java
index a8c14b522c1..e3d63288b9a 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypeUtils.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypeUtils.java
@@ -52,7 +52,7 @@ public class TypeUtils {
*/
public static final boolean isIntegerValue(String str) {
/** the pattern that checks visual ids are valid integers */
- Pattern digit = Pattern.compile("\\d+"); //$NON-NLS-1$
+ Pattern digit = Pattern.compile("-?\\d+"); //$NON-NLS-1$
boolean result = false;
Matcher matcher = digit.matcher(str);
if (matcher != null) {
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AbstractFilterMatcherTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AbstractFilterMatcherTest.java
index 7a4e837272a..2c6660c8624 100755
--- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AbstractFilterMatcherTest.java
+++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/AbstractFilterMatcherTest.java
@@ -18,28 +18,19 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator;
+import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
import org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand;
-import org.eclipse.papyrus.commands.OpenDiagramCommand;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
-import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor;
+import org.eclipse.nebula.widgets.nattable.style.ConfigAttribute;
+import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.papyrus.infra.nattable.filter.FilterPreferences;
+import org.eclipse.papyrus.infra.nattable.layer.FilterRowDataLayer;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils;
-import org.eclipse.papyrus.junit.utils.EditorUtils;
import org.eclipse.papyrus.junit.utils.GenericUtils;
-import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
-import org.eclipse.papyrus.junit.utils.ProjectUtils;
import org.eclipse.papyrus.uml.nattable.generic.tests.Activator;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
import org.junit.AfterClass;
import org.junit.Assert;
import org.osgi.framework.Bundle;
@@ -122,6 +113,7 @@ public abstract class AbstractFilterMatcherTest extends AbstractGenericTableTest
}
/**
+ * Check filter without data validator.
*
* @param matchOn
* the filter value : the object on which we do the math
@@ -135,13 +127,56 @@ public abstract class AbstractFilterMatcherTest extends AbstractGenericTableTest
* the number of elements matching the filter
* @throws Exception
*/
- protected void checkFilter(Object matchOn, int columnPosition, int rowPosition, int nbElementsInTheTable, int nbMatchingElement) throws Exception {
+ protected void checkFilter(final Object matchOn, final int columnPosition, final int rowPosition, final int nbElementsInTheTable, final int nbMatchingElement) throws Exception {
+ checkFilter(matchOn, columnPosition, rowPosition, nbElementsInTheTable, nbMatchingElement, null);
+ }
+
+ /**
+ * Check filter with data validator.
+ *
+ * @param matchOn
+ * the filter value : the object on which we do the math
+ * @param columnPosition
+ * the position of the filtered column
+ * @param rowPosition
+ * the row position of the filter
+ * @param nbElementsInTheTable
+ * the initial number of elements in the table
+ * @param nbMatchingElement
+ * the number of elements matching the filter
+ * @throws Exception
+ */
+ protected void checkFilterWithDataValidator(final Object matchOn, final int columnPosition, final int rowPosition, final int nbElementsInTheTable, final int nbMatchingElement) throws Exception {
+ checkFilter(matchOn, columnPosition, rowPosition, nbElementsInTheTable, nbMatchingElement, EditConfigAttributes.DATA_VALIDATOR);
+ }
+
+ /**
+ *
+ * @param matchOn
+ * the filter value : the object on which we do the math
+ * @param columnPosition
+ * the position of the filtered column
+ * @param rowPosition
+ * the row position of the filter
+ * @param nbElementsInTheTable
+ * the initial number of elements in the table
+ * @param nbMatchingElement
+ * the number of elements matching the filter
+ * @param configAttribute The config attribute data validator.
+ * @throws Exception
+ */
+ protected void checkFilter(final Object matchOn, final int columnPosition, final int rowPosition, final int nbElementsInTheTable, final int nbMatchingElement, final ConfigAttribute<IDataValidator> configAttribute) throws Exception {
INattableModelManager manager = getTableManager();
List<Object> elements = manager.getRowElementsList();
Assert.assertEquals(nbElementsInTheTable, elements.size());
checkUnicityOfElements(elements);
NatTable natTable = getNatTable(manager);
+
+ if (null != configAttribute) {
+ final IDataValidator dataValidator = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + "0");
+ Assert.assertTrue("Validator doesn't manage the value to set", dataValidator.validate(columnPosition, rowPosition, matchOn)); ////$NON-NLS-1$
+ }
// 1. we apply the filter
natTable.getLayer().doCommand(new UpdateDataCommand(natTable.getLayer(), columnPosition, rowPosition, matchOn));
diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/FilterNumericMatcherTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/FilterNumericMatcherTest.java
index d5f62d9f978..c5c195d8912 100755
--- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/FilterNumericMatcherTest.java
+++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/tests/FilterNumericMatcherTest.java
@@ -42,41 +42,41 @@ public class FilterNumericMatcherTest extends AbstractFilterMatcherTest {
@Test
public void test1() throws Exception{
- checkFilter("1", 2, 2, nbElement, 1); //$NON-NLS-1$
+ checkFilterWithDataValidator("1", 2, 2, nbElement, 1); //$NON-NLS-1$
}
@Test
public void test2() throws Exception{
- checkFilter("-1", 2, 2, nbElement, 1); //$NON-NLS-1$
+ checkFilterWithDataValidator("-1", 2, 2, nbElement, 1); //$NON-NLS-1$
}
@Test
public void test3() throws Exception{
- checkFilter(">1", 2, 2, nbElement, 3); //$NON-NLS-1$
+ checkFilterWithDataValidator(">1", 2, 2, nbElement, 3); //$NON-NLS-1$
}
@Test
public void test4() throws Exception{
- checkFilter(">=1", 2, 2, nbElement, 4); //$NON-NLS-1$
+ checkFilterWithDataValidator(">=1", 2, 2, nbElement, 4); //$NON-NLS-1$
}
@Test
public void test5() throws Exception{
- checkFilter("<0", 2, 2, nbElement, 3); //$NON-NLS-1$
+ checkFilterWithDataValidator("<0", 2, 2, nbElement, 3); //$NON-NLS-1$
}
@Test
public void test6() throws Exception{
- checkFilter("<=0", 2, 2, nbElement, 4); //$NON-NLS-1$
+ checkFilterWithDataValidator("<=0", 2, 2, nbElement, 4); //$NON-NLS-1$
}
@Test
public void test7() throws Exception{
- checkFilter("=0", 2, 2, nbElement, 1); //$NON-NLS-1$
+ checkFilterWithDataValidator("=0", 2, 2, nbElement, 1); //$NON-NLS-1$
}
@Test
public void test8() throws Exception{
- checkFilter("<>0", 2, 2, nbElement, 7); //$NON-NLS-1$
+ checkFilterWithDataValidator("<>0", 2, 2, nbElement, 7); //$NON-NLS-1$
}
}

Back to the top