Search in sources :

Example 1 with ProcessFunction

use of org.geotools.process.function.ProcessFunction in project sldeditor by robward-scisys.

the class FieldConfigTransformationTest method testGenerateExpression.

/**
 * 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;
    class TestFieldConfigTransformation extends FieldConfigTransformation {

        public TestFieldConfigTransformation(FieldConfigCommonData commonData, String editButtonText, String clearButtonText) {
            super(commonData, editButtonText, clearButtonText);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigTransformation field = new TestFieldConfigTransformation(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), "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
    String testData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<ogc:Function name=\"vec:PointStacker\">" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>data</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>cellSize</ogc:Literal>" + "  <ogc:Literal>30</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputBBOX</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_bbox</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputWidth</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_width</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>outputHeight</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_height</ogc:Literal>" + "  </ogc:Function>" + " </ogc:Function>" + "</ogc:Function>" + "</StyledLayerDescriptor>";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    ProcessFunction processFunction = null;
    try {
        builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(testData));
        Document doc = builder.parse(is);
        ExpressionDOMParser parser = new ExpressionDOMParser(CommonFactoryFinder.getFilterFactory2(null));
        processFunction = (ProcessFunction) parser.expression(doc.getDocumentElement().getFirstChild());
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    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());
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) FieldConfigTransformation(com.sldeditor.ui.detail.config.transform.FieldConfigTransformation) ProcessFunction(org.geotools.process.function.ProcessFunction) Expression(org.opengis.filter.expression.Expression) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StringReader(java.io.StringReader) ExpressionDOMParser(org.geotools.filter.ExpressionDOMParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 2 with ProcessFunction

use of org.geotools.process.function.ProcessFunction in project sldeditor by robward-scisys.

the class FieldConfigTransformation method createUI.

/**
 * Creates the ui.
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.config.FieldConfigBase#createUI()
     */
@Override
public void createUI() {
    if (textField == null) {
        final UndoActionInterface parentObj = this;
        int xPos = getXPos();
        int width = BasePanel.FIELD_PANEL_WIDTH - xPos - 20;
        int height = BasePanel.WIDGET_HEIGHT * (NO_OF_ROWS - 1);
        textField = new JTextArea();
        textField.setBounds(xPos, BasePanel.WIDGET_HEIGHT, width, height);
        textField.setEditable(false);
        JScrollPane scroll = new JScrollPane(textField);
        scroll.setBounds(xPos, BasePanel.WIDGET_HEIGHT, width, height);
        scroll.setAutoscrolls(true);
        FieldPanel fieldPanel = createFieldPanel(xPos, BasePanel.WIDGET_HEIGHT * NO_OF_ROWS, getLabel());
        fieldPanel.add(scroll);
        // 
        // Edit button
        // 
        final JButton buttonEdit = new JButton(editButtonText);
        buttonEdit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ProcessFunction expression = showTransformationDialog(processFunction);
                if (expression != null) {
                    ProcessFunction newValueObj = processFunction;
                    processFunction = expression;
                    textField.setText(ParameterFunctionUtils.getString(processFunction));
                    UndoManager.getInstance().addUndoEvent(new UndoEvent(parentObj, getFieldId(), oldValueObj, newValueObj));
                    valueUpdated();
                }
            }
        });
        buttonEdit.setBounds(xPos + BasePanel.WIDGET_X_START, 0, BasePanel.WIDGET_BUTTON_WIDTH, BasePanel.WIDGET_HEIGHT);
        fieldPanel.add(buttonEdit);
        // 
        // Clear button
        // 
        final JButton buttonClear = new JButton(clearButtonText);
        buttonClear.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                processFunction = null;
                textField.setText("");
                UndoManager.getInstance().addUndoEvent(new UndoEvent(parentObj, getFieldId(), oldValueObj, null));
                valueUpdated();
            }
        });
        buttonClear.setBounds((int) buttonEdit.getBounds().getMaxX() + 5, 0, BasePanel.WIDGET_BUTTON_WIDTH, BasePanel.WIDGET_HEIGHT);
        fieldPanel.add(buttonClear);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) ProcessFunction(org.geotools.process.function.ProcessFunction) UndoEvent(com.sldeditor.common.undo.UndoEvent) JTextArea(javax.swing.JTextArea) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) FieldPanel(com.sldeditor.ui.widgets.FieldPanel) UndoActionInterface(com.sldeditor.common.undo.UndoActionInterface)

Example 3 with ProcessFunction

use of org.geotools.process.function.ProcessFunction in project sldeditor by robward-scisys.

the class FieldConfigTransformation method populateExpression.

/**
 * 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 processFunction = (ProcessFunction) objValue;
        populateField(processFunction);
    }
}
Also used : ProcessFunction(org.geotools.process.function.ProcessFunction)

Example 4 with ProcessFunction

use of org.geotools.process.function.ProcessFunction in project sldeditor by robward-scisys.

the class FieldConfigTransformation method showTransformationDialog.

/**
 * Show transformation dialog.
 *
 * @param existingProcessFunction the existing process function
 * @return the process function
 */
private ProcessFunction showTransformationDialog(ProcessFunction existingProcessFunction) {
    ProcessFunction processFunction = null;
    RenderTransformationDialog dlg = new RenderTransformationDialog(GeoServerConnectionManager.getInstance());
    if (dlg.showDialog(existingProcessFunction)) {
        processFunction = dlg.getTransformationProcessFunction();
    }
    return processFunction;
}
Also used : ProcessFunction(org.geotools.process.function.ProcessFunction) RenderTransformationDialog(com.sldeditor.rendertransformation.RenderTransformationDialog)

Example 5 with ProcessFunction

use of org.geotools.process.function.ProcessFunction in project sldeditor by robward-scisys.

the class RenderTransformationDialogTest method testRenderTransformationDialog.

/**
 * 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);
}
Also used : ProcessFunction(org.geotools.process.function.ProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) Test(org.junit.Test)

Aggregations

ProcessFunction (org.geotools.process.function.ProcessFunction)9 IOException (java.io.IOException)3 Expression (org.opengis.filter.expression.Expression)3 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ExpressionDOMParser (org.geotools.filter.ExpressionDOMParser)2 ProcessFunctionFactory (org.geotools.process.function.ProcessFunctionFactory)2 Test (org.junit.Test)2 UndoActionInterface (com.sldeditor.common.undo.UndoActionInterface)1 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 BuiltInProcessFunction (com.sldeditor.rendertransformation.BuiltInProcessFunction)1 ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)1 RenderTransformationDialog (com.sldeditor.rendertransformation.RenderTransformationDialog)1 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)1 FieldConfigTransformation (com.sldeditor.ui.detail.config.transform.FieldConfigTransformation)1 FieldPanel (com.sldeditor.ui.widgets.FieldPanel)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1