org.geotools.process.function.ProcessFunction Java Examples

The following examples show how to use org.geotools.process.function.ProcessFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DistributedRenderer.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
List<List<LiteFeatureTypeStyle>> classifyByFeatureProduction(
    final List<LiteFeatureTypeStyle> lfts) {
  // strip off a distributed rendering render transform because that is
  // what is currently being processed
  final List<List<LiteFeatureTypeStyle>> retVal = super.classifyByFeatureProduction(lfts);
  for (final List<LiteFeatureTypeStyle> featureTypeStyles : retVal) {
    final LiteFeatureTypeStyle transformLfts = featureTypeStyles.get(0);
    // there doesn't seem to be an easy way to check if its a
    // distributed render transform so for now let's just not allow
    // other rendering transformations when distributed rendering is
    // employed and strip all transformations
    if (transformLfts.transformation instanceof ProcessFunction) {
      if ((((ProcessFunction) transformLfts.transformation).getName() != null)
          && ((ProcessFunction) transformLfts.transformation).getName().equals(
              DistributedRenderProcess.PROCESS_NAME)) {
        transformLfts.transformation = null;
      }
    }
  }
  return retVal;
}
 
Example #2
Source File: RenderTransformationDialogTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.rendertransformation.RenderTransformationDialog#RenderTransformationDialog(com.sldeditor.common.connection.GeoServerConnectionManagerInterface)}.
 */
@Test
public void testRenderTransformationDialog() {
    TestRenderTransformationDialog testObj = new TestRenderTransformationDialog(null);

    testObj.test_internal_showDialog(null);
    ProcessFunction actualResult = testObj.getTransformationProcessFunction();
    assertNull(actualResult);

    ProcessFunctionFactory factory = new ProcessFunctionFactory();
    FunctionName functionName = factory.getFunctionNames().get(0);
    testObj.testDisplayFunction(functionName.getName());

    actualResult = testObj.getTransformationProcessFunction();
    assertNotNull(actualResult);
    testObj.test_internal_showDialog(actualResult);
}
 
Example #3
Source File: BuiltInProcessFunction.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate parameter values.
 *
 * @param selectedProcessFunctionData the selected process function data
 * @param valueList the value list
 */
private void populateParameterValues(
        ProcessFunction selectedProcessFunctionData,
        List<ProcessFunctionParameterValue> valueList) {
    for (Expression parameter : selectedProcessFunctionData.getParameters()) {
        List<Expression> parameterList = ParameterFunctionUtils.getExpressionList(parameter);

        if ((parameterList != null) && !parameterList.isEmpty()) {
            Expression paramName = parameterList.get(0);

            ProcessFunctionParameterValue value =
                    findParameterValue(valueList, paramName.toString());

            if ((parameterList.size() > 1) && (value != null)) {
                Expression paramValue = parameterList.get(1);

                value.getObjectValue().setValue(paramValue);
                if (value.isOptional()) {
                    value.setIncluded(true);
                }
            }
        }
    }
}
 
Example #4
Source File: BuiltInProcessFunction.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extract parameters.
 *
 * @param functionName the function name
 * @param selectedProcessFunctionData the selected process function data
 * @return the list
 */
public List<ProcessFunctionParameterValue> extractParameters(
        FunctionName functionName, ProcessFunction selectedProcessFunctionData) {

    List<ProcessFunctionParameterValue> valueList = new ArrayList<>();

    // Populate the parameter definitions first.
    // This ensures if there is parameter data missing we
    // don't miss populating the parameter definition.
    if (functionName != null) {
        for (Parameter<?> parameter : functionName.getArguments()) {
            ProcessFunctionParameterValue value = new ProcessFunctionParameterValue();

            populateParameterDefinition(parameter, value);

            valueList.add(value);
        }
    }

    // Now populate any parameter values we have
    if (selectedProcessFunctionData != null) {
        populateParameterValues(selectedProcessFunctionData, valueList);
    }

    return valueList;
}
 
Example #5
Source File: FieldConfigTransformation.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show transformation dialog.
 *
 * @param existingProcessFunction the existing process function
 * @return the process function
 */
private ProcessFunction showTransformationDialog(ProcessFunction existingProcessFunction) {
    ProcessFunction localProcessFunction = null;
    RenderTransformationDialog dlg =
            new RenderTransformationDialog(GeoServerConnectionManager.getInstance());

    if (dlg.showDialog(existingProcessFunction)) {
        localProcessFunction = dlg.getTransformationProcessFunction();
    }

    return localProcessFunction;
}
 
Example #6
Source File: SymbolizerFilterVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Expression copy(Expression expression) {
	if (expression instanceof ProcessFunction) {
		ProcessFunction f = (ProcessFunction) expression;
		return (ProcessFunction) CommonFactoryFinder.getFilterFactory2()
				.function(
						f.getProcessName(),
						f.getParameters().toArray(
								new Expression[f.getParameters().size()]));

	} else {
		return super.copy(expression);
	}
}
 
Example #7
Source File: OptionalValueEditorTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #8
Source File: FieldConfigTransformationTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#populateField(org.geotools.process.function.ProcessFunction)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#populateField(java.lang.String)}.
 */
@Test
public void testPopulateFieldProcessFunction() {
    boolean valueOnly = true;
    TestFieldConfigTransformation field =
            new TestFieldConfigTransformation(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    "edit",
                    "clear");
    field.createUI();

    int undoListSize = UndoManager.getInstance().getUndoListSize();
    ProcessFunction processFunction = createProcessFunction();
    field.populateField(processFunction);
    field.transformationDialogResult(null);
    field.transformationDialogResult(processFunction);
    field.clearButtonPressed();
    assertEquals(undoListSize + 3, UndoManager.getInstance().getUndoListSize());

    // Suppress events
    field =
            new TestFieldConfigTransformation(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, true),
                    "edit",
                    "clear");
    field.createUI();

    undoListSize = UndoManager.getInstance().getUndoListSize();
    field.populateField(processFunction);
    field.transformationDialogResult(null);
    field.transformationDialogResult(processFunction);
    field.clearButtonPressed();

    assertEquals(undoListSize, UndoManager.getInstance().getUndoListSize());
}
 
Example #9
Source File: FieldConfigTransformationTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#populateExpression(java.lang.Object)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#generateExpression()}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.transform.FieldConfigTransformation#getProcessFunction()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;

    TestFieldConfigTransformation field =
            new TestFieldConfigTransformation(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    "edit",
                    "clear");
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);

    field.createUI();
    String expectedValue1 = "test string value";
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue1);
    actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);

    // Strings are ignored when calling populateExpression
    String expectedValue2 = "test string value as expression";
    field.populateExpression(expectedValue2);
    actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);

    // Create process function
    ProcessFunction processFunction = createProcessFunction();
    field.populateExpression((ProcessFunction) null);
    field.populateExpression(processFunction);

    actualExpression = field.callGenerateExpression();
    String expectedValue3 = ParameterFunctionUtils.getString(processFunction);
    String string = actualExpression.toString();
    assertTrue(expectedValue3.compareTo(string) != 0);
    assertEquals(processFunction, field.getProcessFunction());
}
 
Example #10
Source File: RenderTransformationDialog.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Internal show dialog.
 *
 * @param existingProcessFunction the existing process function
 */
protected void internalShowDialog(ProcessFunction existingProcessFunction) {
    this.existingProcessFunction = existingProcessFunction;
    if (existingProcessFunction != null) {
        displayFunction(existingProcessFunction.getName());
    }
}
 
Example #11
Source File: RenderTransformationDialog.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show dialog.
 *
 * @param existingProcessFunction the existing process function
 * @return true, if successful
 */
public boolean showDialog(ProcessFunction existingProcessFunction) {
    internalShowDialog(existingProcessFunction);
    setVisible(true);

    return okButtonPressed;
}
 
Example #12
Source File: FunctionTableModel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the expression.
 *
 * @param factory the factory
 * @return the expression
 */
public ProcessFunction getExpression(FunctionFactory factory) {
    if (factory == null) {
        return null;
    }

    List<Expression> overallParameterList = new ArrayList<>();

    for (ProcessFunctionParameterValue value : valueList) {
        List<Expression> parameterList = new ArrayList<>();
        parameterList.add(ff.literal(value.getName()));

        boolean setValue = true;
        if (value.isOptional()) {
            setValue = value.isIncluded();
        }

        if (setValue && (value.getObjectValue() != null)) {
            Expression expression = value.getObjectValue().getExpression();
            if (expression != null) {
                parameterList.add(expression);
            }
        }

        if (setValue) {
            Function function = factory.function(PARAMETER, parameterList, null);

            overallParameterList.add(function);
        }
    }

    if (this.selectedFunction.getFunctionName() == null) {
        return null;
    }
    Function processFunction =
            factory.function(
                    this.selectedFunction.getFunctionName(), overallParameterList, null);

    return (ProcessFunction) processFunction;
}
 
Example #13
Source File: SelectedProcessFunction.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the built in process function.
 *
 * @param builtInProcessFunction the builtInProcessFunction to set
 * @param existingProcessFunction the existing process function
 */
public void setBuiltInProcessFunction(
        FunctionName builtInProcessFunction, ProcessFunction existingProcessFunction) {
    this.builtInProcessFunction = builtInProcessFunction;
    this.selectedProcessFunctionData = existingProcessFunction;
    this.selectedCustomFunction = null;
    this.builtInSelected = true;
}
 
Example #14
Source File: ParameterFunctionUtils.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the process function data as a string. Each parameter is on a new line.
 *
 * @param processFunction the process function
 * @return the string
 */
public static String getString(ProcessFunction processFunction) {
    StringBuilder sb = new StringBuilder();
    if (processFunction != null) {
        sb.append(processFunction.getFunctionName().toString());
        sb.append("(");
        int count = 0;
        for (Expression expression : processFunction.getParameters()) {
            if (count > 0) {
                sb.append(", ");
            }
            sb.append("\n  ");
            List<Expression> subParameterList = getExpressionList(expression);

            if ((subParameterList != null) && !subParameterList.isEmpty()) {
                if (subParameterList.size() == 1) {
                    sb.append(subParameterList.get(0).toString());
                    sb.append(PARAMETER_NOT_SET);
                } else if (subParameterList.size() == 2) {
                    sb.append(subParameterList.get(0).toString());
                    sb.append(":");
                    Expression expression2 = subParameterList.get(1);
                    if (expression2 != null) {
                        sb.append(expression2.toString());
                    } else {
                        sb.append(PARAMETER_NOT_SET);
                    }
                }
            }

            count++;
        }
        sb.append("\n)");
    }
    return sb.toString();
}
 
Example #15
Source File: FieldConfigTransformation.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate expression.
 *
 * @param objValue the obj value
 */
/*
 * (non-Javadoc)
 *
 * @see com.sldeditor.ui.detail.config.FieldConfigBase#populateExpression(java.lang.Object)
 */
@Override
public void populateExpression(Object objValue) {
    if (objValue instanceof ProcessFunction) {
        ProcessFunction localProcessFunction = (ProcessFunction) objValue;

        populateField(localProcessFunction);
    }
}
 
Example #16
Source File: FieldConfigTransformation.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate process function field.
 *
 * @param value the value
 */
@Override
public void populateField(ProcessFunction value) {
    processFunction = value;

    populateField(ParameterFunctionUtils.getString(processFunction));
}
 
Example #17
Source File: FieldConfigBase.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate process function.
 *
 * @param expression the expression
 */
private void populateProcessFunction(Expression expression) {
    ProcessFunction processExpression = (ProcessFunction) expression;

    Object objValue = processExpression;

    populateExpression(objValue);
}
 
Example #18
Source File: FieldConfigBase.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate.
 *
 * @param expression the expression
 */
public void populate(Expression expression) {
    if (attributeSelectionPanel != null) {
        attributeSelectionPanel.populateAttributeComboxBox(expression);
    }

    if (expression == null) {
        expressionType = ExpressionTypeEnum.E_VALUE;

        revertToDefaultValue();

        valueUpdated();
    } else {
        if (expression instanceof LiteralExpressionImpl) {
            populateLiteralExpression(expression);
        } else if (expression instanceof ConstantExpression) {
            populateConstantExpression(expression);
        } else if (expression instanceof NilExpression) {
            populateNilExpression();
        } else if (expression instanceof ProcessFunction) {
            populateProcessFunction(expression);
        } else if (expression instanceof AttributeExpressionImpl) {
            populateAttributeExpression(expression);
        } else if ((expression instanceof FunctionExpressionImpl)
                || (expression instanceof BinaryExpression)) {
            expressionType = ExpressionTypeEnum.E_EXPRESSION;

            if (attributeSelectionPanel != null) {
                attributeSelectionPanel.populate(expression);
            }

            setCachedExpression(expression);
        } else {
            expressionType = ExpressionTypeEnum.E_EXPRESSION;
        }
    }

    setValueFieldState();
}
 
Example #19
Source File: FieldConfigBaseTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigBase#populateField(java.lang.String)}.
 */
@Test
public void testPopulateFieldString() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field =
            new TestFieldConfigBase(
                    new FieldConfigCommonData(
                            String.class, expectedFieldId, expectedLabel, false, false));

    field.populateField("");
    field.setTestValue(expectedFieldId, "");

    field.populateField(42);
    field.setTestValue(expectedFieldId, 42);
    assertEquals(0, field.getIntValue());

    field.populateField(3.142);
    field.setTestValue(expectedFieldId, 3.142);
    assertTrue(Math.abs(field.getDoubleValue()) < 0.0001);

    field.populateField(ZonedDateTime.now());
    field.populateField((ReferencedEnvelope) null);
    field.setTestValue(expectedFieldId, (ReferencedEnvelope) null);
    field.populateField((Id) null);
    field.populateField((TimePeriod) null);
    field.populateField((ProcessFunction) null);
    assertNull(field.getProcessFunction());

    field.populateField(true);
    field.setTestValue(expectedFieldId, true);
    assertEquals(false, field.getBooleanValue());

    field.populateField((ColorMap) null);
    field.setTestValue(expectedFieldId, (ColorMap) null);
    assertNull(field.getColourMap());

    field.populateField((List<FeatureTypeConstraint>) null);
    field.setTestValue(expectedFieldId, (List<FeatureTypeConstraint>) null);
    assertNull(field.getFeatureTypeConstraint());

    field.populateField((Font) null);
    assertNull(field.getFont());

    field.setTestValue(expectedFieldId, (Expression) null);

    assertNull(field.getEnumValue());
}
 
Example #20
Source File: DistributedRenderCallback.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Layer beforeLayer(final WMSMapContent mapContent, final Layer layer) {
  // sanity check the style
  if ((layer instanceof FeatureLayer)
      && (layer.getStyle() != null)
      && (layer.getStyle().featureTypeStyles() != null)
      && !layer.getStyle().featureTypeStyles().isEmpty()) {

    final Style layerStyle = layer.getStyle();
    final FeatureTypeStyle style = layerStyle.featureTypeStyles().get(0);
    // check if their is a DistributedRender rendering
    // transformation
    if ((style instanceof ProcessFunction)
        && (style.getTransformation() != null)
        && (((ProcessFunction) style.getTransformation()).getName() != null)
        && ((ProcessFunction) style.getTransformation()).getName().equals(
            DistributedRenderProcess.PROCESS_NAME)) {
      // if their is a DistributedRender transformation, we need
      // to provide more information that can only be found
      final DuplicatingStyleVisitor cloner = new DuplicatingStyleVisitor();
      layerStyle.accept(cloner);
      layer.getQuery().getHints().put(
          DistributedRenderProcess.OPTIONS,
          new DistributedRenderOptions(wms, mapContent, layerStyle));
      // now that the options with the distributed render style
      // have been set the original style will be used with
      // distributed rendering

      // now, replace the style with a direct raster symbolizer,
      // so the GridCoverage result of the distributed rendering
      // process is directly rendered to the map in place of the
      // original style

      final Style directRasterStyle = (Style) cloner.getCopy();
      directRasterStyle.featureTypeStyles().clear();
      Processors.addProcessFactory(new InternalProcessFactory());
      directRasterStyle.featureTypeStyles().add(
          getDirectRasterStyle(
              layer.getFeatureSource().getSchema().getGeometryDescriptor().getLocalName(),
              DistributedRenderProcessUtils.getRenderingProcess()));
      ((FeatureLayer) layer).setStyle(directRasterStyle);
    }
  }
  return layer;
}
 
Example #21
Source File: FunctionTableModelTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #22
Source File: FunctionTableModelTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/** 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);
}
 
Example #23
Source File: CheckBoxRendererTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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());
}
 
Example #24
Source File: FieldConfigPopulate.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the process function, overridden if necessary.
 *
 * @return the process function
 */
@Override
public ProcessFunction getProcessFunction() {
    // Do nothing
    return null;
}
 
Example #25
Source File: FieldConfigTransformation.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Transformation dialog result.
 *
 * @param expression the expression
 */
protected void transformationDialogResult(ProcessFunction expression) {
    if (expression != null) {
        populateField(expression);
    }
}
 
Example #26
Source File: FieldConfigTransformationTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void transformationDialogResult(ProcessFunction expression) {
    super.transformationDialogResult(expression);
}
 
Example #27
Source File: RenderTransformationDialog.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the transformation process function.
 *
 * @return the transformation expression
 */
public ProcessFunction getTransformationProcessFunction() {
    return functionParameterTableModel.getExpression(factory);
}
 
Example #28
Source File: FieldConfigTransformation.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the process function, overridden if necessary.
 *
 * @return the process function
 */
@Override
public ProcessFunction getProcessFunction() {
    return processFunction;
}
 
Example #29
Source File: RenderTransformationDialogTest.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Test internal show dialog.
 *
 * @param existingProcessFunction the existing process function
 */
public void test_internal_showDialog(ProcessFunction existingProcessFunction) {
    internalShowDialog(existingProcessFunction);
}
 
Example #30
Source File: FieldConfigValuePopulateInterface.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Populate field.
 *
 * @param value the value
 */
public void populateField(ProcessFunction value);