Search in sources :

Example 1 with FunctionTableModel

use of com.sldeditor.rendertransformation.FunctionTableModel in project sldeditor by robward-scisys.

the class CheckBoxRendererTest method testCheckBoxRenderer.

/**
 * Test method for {@link
 * com.sldeditor.rendertransformation.CheckBoxRenderer#CheckBoxRenderer(com.sldeditor.rendertransformation.FunctionTableModel)}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void testCheckBoxRenderer() {
    JTable table = new JTable();
    FunctionTableModel model = new FunctionTableModel();
    assertNull(new CheckBoxRenderer(null).getTableCellRendererComponent(null, null, false, false, 0, 0));
    assertNull(new CheckBoxRenderer(null).getTableCellRendererComponent(table, null, false, false, 0, 0));
    assertNull(new CheckBoxRenderer(model).getTableCellRendererComponent(null, null, false, false, 0, 0));
    model.addNewValue(0);
    ProcessFunction processFunction = createProcessFunction();
    FunctionName name = new FunctionNameImpl("Test", parameter("cellSize", Double.class), new Parameter("outputBBOX", Number.class, null, null, false, 0, 100, null, null), parameter("outputWidth", Number.class), parameter("outputHeight", Number.class));
    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());
    model.populate(name, processFunction);
    CheckBoxRenderer obj = new CheckBoxRenderer(model);
    // Row - optional and not selected
    assertEquals(obj, obj.getTableCellRendererComponent(table, null, false, false, 0, 0));
    assertEquals(obj, obj.getTableCellRendererComponent(table, true, false, false, 0, 0));
    assertTrue(obj.isSelected());
    assertEquals(obj, obj.getTableCellRendererComponent(table, false, false, false, 0, 0));
    assertFalse(obj.isSelected());
    // Row - optional and selected
    assertEquals(obj, obj.getTableCellRendererComponent(table, null, true, false, 0, 0));
    assertEquals(obj, obj.getTableCellRendererComponent(table, true, true, false, 0, 0));
    assertTrue(obj.isSelected());
    assertEquals(obj, obj.getTableCellRendererComponent(table, false, true, false, 0, 0));
    assertFalse(obj.isSelected());
    // Row - required and not selected
    assertEquals(JLabel.class, obj.getTableCellRendererComponent(table, null, false, false, 1, 0).getClass());
    // Row - required and selected
    assertEquals(JLabel.class, obj.getTableCellRendererComponent(table, null, true, false, 1, 0).getClass());
}
Also used : ProcessFunction(org.geotools.process.function.ProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) JTable(javax.swing.JTable) Parameter(org.geotools.data.Parameter) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) CheckBoxRenderer(com.sldeditor.rendertransformation.CheckBoxRenderer) FunctionTableModel(com.sldeditor.rendertransformation.FunctionTableModel) Test(org.junit.jupiter.api.Test)

Example 2 with FunctionTableModel

use of com.sldeditor.rendertransformation.FunctionTableModel in project sldeditor by robward-scisys.

the class OptionalValueEditorTest method testGetCellEditorValue.

/**
 * Test method for {@link
 * com.sldeditor.rendertransformation.OptionalValueEditor#getCellEditorValue()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void testGetCellEditorValue() {
    FunctionTableModel model = new FunctionTableModel();
    model.addNewValue(0);
    ProcessFunction processFunction = createProcessFunction();
    FunctionName name = new FunctionNameImpl("Test", parameter("cellSize", Double.class), new Parameter("outputBBOX", Number.class, null, null, false, 0, 100, null, null), parameter("outputWidth", Number.class), parameter("outputHeight", Number.class));
    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());
    model.populate(name, processFunction);
    TestOptionalValueEditor obj = new TestOptionalValueEditor(model);
    assertNotNull(obj.getTableCellEditorComponent(null, null, false, 0, 0));
    assertNotNull(obj.getCellEditorValue());
    obj.setValue();
    assertNull(obj.getTableCellEditorComponent(null, null, false, 1, 0));
}
Also used : ProcessFunction(org.geotools.process.function.ProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) Parameter(org.geotools.data.Parameter) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) FunctionTableModel(com.sldeditor.rendertransformation.FunctionTableModel) Test(org.junit.jupiter.api.Test)

Example 3 with FunctionTableModel

use of com.sldeditor.rendertransformation.FunctionTableModel in project sldeditor by robward-scisys.

the class FunctionTableModelTest method testProcessBriefType.

/**
 * Test all the methods using a ProcessBriefType.
 *
 * <p>Not tested because it needs to interact with GeoServer to create a receive a remote custom
 * WPS function.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Disabled
@Test
void testProcessBriefType() {
    FunctionTableModel model = new FunctionTableModel();
    assertEquals(0, model.getRowCount());
    model.addNewValue(0);
    ProcessBriefType customFunction = createCustomFunction();
    FunctionName name = new FunctionNameImpl(new NameImpl("vec", "PointStacker"), parameter("cellSize", Double.class), new Parameter("outputBBOX", Number.class, null, null, false, 0, 100, null, null), parameter("outputWidth", Number.class), parameter("outputHeight", Number.class));
    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());
    model.populate(customFunction);
    assertEquals(3, model.getRowCount());
    assertEquals(4, model.getColumnCount());
    // Get value
    assertEquals("outputBBOX", model.getValueAt(0, 0));
    assertEquals(Number.class.getSimpleName(), model.getValueAt(0, 1));
    assertEquals(true, model.getValueAt(0, 2));
    assertEquals("env([wms_bbox])", model.getValueAt(0, 3));
    assertNull(model.getValueAt(0, 4));
    // Is editable
    assertFalse(model.isCellEditable(0, 0));
    assertFalse(model.isCellEditable(0, 1));
    assertTrue(model.isCellEditable(0, FunctionTableModel.getOptionalColumn()));
    assertFalse(model.isCellEditable(0, 3));
    assertFalse(model.isCellEditable(0, 4));
    // Set value
    model.setValueAt(true, 0, 2);
    assertTrue((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    model.setValueAt(false, 0, 2);
    assertFalse((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    // Get row
    assertNull(model.getValue(-1));
    assertNull(model.getValue(10));
    // Add a new value
    assertEquals(0, model.getNoOfOccurences(null));
    ProcessFunctionParameterValue value = model.getValue(0);
    assertEquals(1, model.getNoOfOccurences(value));
    model.addNewValue(0);
    assertEquals(4, model.getRowCount());
    assertEquals(2, model.getNoOfOccurences(value));
    // Remove value
    model.removeValue(3);
    assertEquals(3, model.getRowCount());
    // Get expression
    ProcessFunction actualFunction = model.getExpression(null);
    assertNull(actualFunction);
    model.setValueAt(true, 0, FunctionTableModel.getOptionalColumn());
    ProcessFunctionFactory factory = new ProcessFunctionFactory();
    actualFunction = model.getExpression(factory);
    assertNotNull(actualFunction);
    // Update expression
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Expression expression = ff.literal(4.2);
    model.update(expression, 0);
    model.update(null, 1);
}
Also used : FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) NameImpl(org.geotools.feature.NameImpl) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) ProcessBriefType(net.opengis.wps10.ProcessBriefType) FilterFactory(org.opengis.filter.FilterFactory) FunctionTableModel(com.sldeditor.rendertransformation.FunctionTableModel) ProcessFunction(org.geotools.process.function.ProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) Expression(org.opengis.filter.expression.Expression) Parameter(org.geotools.data.Parameter) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with FunctionTableModel

use of com.sldeditor.rendertransformation.FunctionTableModel in project sldeditor by robward-scisys.

the class FunctionTableModelTest method testProcessFunction.

/**
 * Test all the methods using a ProcessFunction
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void testProcessFunction() {
    FunctionTableModel model = new FunctionTableModel();
    assertEquals(0, model.getRowCount());
    model.addNewValue(0);
    ProcessFunction processFunction = createProcessFunction();
    FunctionName name = new FunctionNameImpl(new NameImpl("vec", "PointStacker"), parameter("cellSize", Double.class), new Parameter("outputBBOX", Number.class, null, null, false, 0, 100, null, null), parameter("outputWidth", Number.class), parameter("outputHeight", Number.class));
    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());
    model.populate(name, processFunction);
    assertEquals(3, model.getRowCount());
    assertEquals(4, model.getColumnCount());
    // Get value
    assertEquals("outputBBOX", model.getValueAt(0, 0));
    assertEquals(Number.class.getSimpleName(), model.getValueAt(0, 1));
    assertEquals(true, model.getValueAt(0, 2));
    assertEquals("env([wms_bbox])", model.getValueAt(0, 3));
    assertNull(model.getValueAt(0, 4));
    // Is editable
    assertFalse(model.isCellEditable(0, 0));
    assertFalse(model.isCellEditable(0, 1));
    assertTrue(model.isCellEditable(0, FunctionTableModel.getOptionalColumn()));
    assertFalse(model.isCellEditable(0, 3));
    assertFalse(model.isCellEditable(0, 4));
    // Set value
    model.setValueAt(true, 0, 2);
    assertTrue((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    model.setValueAt(false, 0, 2);
    assertFalse((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    // Get row
    assertNull(model.getValue(-1));
    assertNull(model.getValue(10));
    // Add a new value
    assertEquals(0, model.getNoOfOccurences(null));
    ProcessFunctionParameterValue value = model.getValue(0);
    assertEquals(1, model.getNoOfOccurences(value));
    model.addNewValue(0);
    assertEquals(4, model.getRowCount());
    assertEquals(2, model.getNoOfOccurences(value));
    // Remove value
    model.removeValue(3);
    assertEquals(3, model.getRowCount());
    // Get expression
    ProcessFunction actualFunction = model.getExpression(null);
    assertNull(actualFunction);
    model.setValueAt(true, 0, FunctionTableModel.getOptionalColumn());
    ProcessFunctionFactory factory = new ProcessFunctionFactory();
    actualFunction = model.getExpression(factory);
    assertNotNull(actualFunction);
    // Update expression
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Expression expression = ff.literal(4.2);
    model.update(expression, 0);
    model.update(null, 1);
}
Also used : ProcessFunction(org.geotools.process.function.ProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) NameImpl(org.geotools.feature.NameImpl) Expression(org.opengis.filter.expression.Expression) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) Parameter(org.geotools.data.Parameter) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) FilterFactory(org.opengis.filter.FilterFactory) FunctionTableModel(com.sldeditor.rendertransformation.FunctionTableModel) Test(org.junit.jupiter.api.Test)

Aggregations

FunctionTableModel (com.sldeditor.rendertransformation.FunctionTableModel)4 Parameter (org.geotools.data.Parameter)4 FunctionNameImpl (org.geotools.filter.capability.FunctionNameImpl)4 ProcessFunction (org.geotools.process.function.ProcessFunction)4 Test (org.junit.jupiter.api.Test)4 FunctionName (org.opengis.filter.capability.FunctionName)4 ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)2 NameImpl (org.geotools.feature.NameImpl)2 ProcessFunctionFactory (org.geotools.process.function.ProcessFunctionFactory)2 FilterFactory (org.opengis.filter.FilterFactory)2 Expression (org.opengis.filter.expression.Expression)2 CheckBoxRenderer (com.sldeditor.rendertransformation.CheckBoxRenderer)1 JTable (javax.swing.JTable)1 ProcessBriefType (net.opengis.wps10.ProcessBriefType)1 Disabled (org.junit.jupiter.api.Disabled)1