Search in sources :

Example 1 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class ExpressionSubPanel method setUpEnvVarPanel.

/**
 * Sets the up env var panel.
 */
protected void setUpEnvVarPanel() {
    if (VendorOptionManager.getInstance().isAllowed(this.parent.getVendorOptionList(), EnvironmentVariableField.getVendorOption())) {
        panelEnvVar = new JPanel();
        FlowLayout fl_panelEnvVar = (FlowLayout) panelEnvVar.getLayout();
        fl_panelEnvVar.setAlignment(FlowLayout.LEFT);
        rdbtnEnvVar = new JRadioButton(ENVVAR);
        rdbtnEnvVar.setActionCommand(ENVVAR);
        buttonGroup.add(rdbtnEnvVar);
        panelEnvVar.add(rdbtnEnvVar);
        envVarField = new EnvironmentVariableField(new SubPanelUpdatedInterface() {

            @Override
            public void updateSymbol() {
                buttonGroup.setSelected(rdbtnEnvVar.getModel(), true);
                updateButtonState(true);
            }
        }, EnvironmentVariableManager.getInstance());
        panelEnvVar.add(envVarField);
        box.add(panelEnvVar);
    }
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JRadioButton(javax.swing.JRadioButton) SubPanelUpdatedInterface(com.sldeditor.ui.attribute.SubPanelUpdatedInterface) EnvironmentVariableField(com.sldeditor.filter.v2.envvar.EnvironmentVariableField)

Example 2 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class SLDEditorFileHandler method readSLDEditorFile.

/**
 * Read sld editor file.
 *
 * @param file the file
 * @return the SLD data
 */
private SLDDataInterface readSLDEditorFile(File file) {
    SLDDataInterface sldData = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(file);
        String sldFile = extractTextData(document, SLDEditorFileHandler.SLD_ELEMENT);
        DataSourcePropertiesInterface dataSourceProperties = DataSourceProperties.decodeXML(document, SLDEditorFileHandler.DATASOURCE_ELEMENT);
        List<VersionData> vendorOptionList = extractVendorOptionData(document, SLDEditorFileHandler.VENDOR_OPTION_ELEMENT);
        File f = new File(sldFile);
        String sldContents = readFile(f, Charset.defaultCharset());
        sldData = new SLDData(new StyleWrapper(sldFile), sldContents);
        sldData.setDataSourceProperties(dataSourceProperties);
        sldData.setVendorOptionList(vendorOptionList);
        List<DataSourceAttributeData> fieldList = null;
        sldData.setFieldList(fieldList);
        sldData.setSLDFile(f);
        sldData.setReadOnly(false);
        sldData.setSldEditorFile(file);
        List<EnvVar> envVarList = extractEnvironmentVariables(document, SLDEditorFileHandler.ENVVAR_ELEMENT);
        sldData.setEnvVarList(envVarList);
        LegendOptionData legendOption = LegendOptionData.decodeXML(document, SLDEditorFileHandler.LEGEND_OPTION_ELEMENT);
        sldData.setLegendOptions(legendOption);
    } catch (ParserConfigurationException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (SAXException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) IOException(java.io.IOException) Document(org.w3c.dom.Document) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) SAXException(org.xml.sax.SAXException) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StyleWrapper(com.sldeditor.common.data.StyleWrapper) VersionData(com.sldeditor.common.vendoroption.VersionData) EnvVar(com.sldeditor.filter.v2.envvar.EnvVar) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 3 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class SLDEditorFileHandler method extractEnvironmentVariables.

/**
 * Extract environment variables.
 *
 * @param document the document
 * @param envvarElement the environment variable element
 * @return the list
 */
private List<EnvVar> extractEnvironmentVariables(Document document, String elementName) {
    List<EnvVar> list = new ArrayList<EnvVar>();
    NodeList nodeList = document.getElementsByTagName(elementName);
    for (int index = 0; index < nodeList.getLength(); index++) {
        Element element = (Element) nodeList.item(index);
        Class<?> type = null;
        try {
            type = Class.forName(element.getAttribute(ENVVAR_TYPE_ATTRIBUTE));
        } catch (ClassNotFoundException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
        // Assume not predefined, will get sorted out later
        EnvVar envVar = new EnvVar(element.getAttribute(ENVVAR_NAME_ATTRIBUTE), type, false);
        if (element.hasAttribute(ENVVAR_VALUE_ATTRIBUTE)) {
            envVar.setValue(element.getAttribute(ENVVAR_VALUE_ATTRIBUTE));
        }
        list.add(envVar);
    }
    return list;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EnvVar(com.sldeditor.filter.v2.envvar.EnvVar)

Example 4 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class EnvVarDlg method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    JPanel buttonPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) buttonPanel.getLayout();
    flowLayout.setAlignment(FlowLayout.TRAILING);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    JButton btnOk = new JButton(Localisation.getString(EnvVarDlg.class, "common.ok"));
    btnOk.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            okButtonPressed = true;
            dataModel.updateEnvVarManager();
            setVisible(false);
        }
    });
    buttonPanel.add(btnOk);
    JButton btnCancel = new JButton(Localisation.getString(EnvVarDlg.class, "common.cancel"));
    btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            okButtonPressed = false;
            setVisible(false);
        }
    });
    buttonPanel.add(btnCancel);
    JPanel panel = new JPanel();
    getContentPane().add(panel, BorderLayout.CENTER);
    panel.setLayout(new BorderLayout(0, 0));
    table = new JTable();
    dataModel = new EnvVarModel(envVarMgr);
    table.setModel(dataModel);
    TableColumn column = table.getColumnModel().getColumn(1);
    JComboBox<Class<?>> typeComboBox = new JComboBox<Class<?>>();
    typeComboBox.setModel(new EnvVarComboBoxModel(envVarMgr));
    column.setCellEditor(new DefaultCellEditor(typeComboBox));
    JScrollPane scrollPane = new JScrollPane(table);
    panel.add(scrollPane, BorderLayout.CENTER);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            boolean enableRemoveButton = false;
            EnvVar envVar = dataModel.getEnvVar(table.getSelectedRow());
            if (envVar != null) {
                enableRemoveButton = !envVar.isPredefined();
            }
            btnRemove.setEnabled(enableRemoveButton);
        }
    });
    JPanel panelWMS = new JPanel();
    panel.add(panelWMS, BorderLayout.NORTH);
    panelWMS.setLayout(new BoxLayout(panelWMS, BoxLayout.X_AXIS));
    JButton btnDecode = new JButton(Localisation.getString(EnvVarDlg.class, "EnvVarDlg.decode"));
    btnDecode.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            URL url;
            try {
                url = new URL(textField.getText());
                Map<String, List<String>> parameterMap = splitQuery(url);
                if (parameterMap.containsKey(WMS_ENV_PARAMETER)) {
                    dataModel.addNew(parameterMap.get(WMS_ENV_PARAMETER));
                }
            } catch (MalformedURLException e1) {
                ConsoleManager.getInstance().exception(this, e1);
            } catch (UnsupportedEncodingException e1) {
                ConsoleManager.getInstance().exception(this, e1);
            }
        }
    });
    panelWMS.add(btnDecode);
    textField = new JTextField();
    panelWMS.add(textField);
    textField.setColumns(40);
    JPanel panel_1 = new JPanel();
    panel.add(panel_1, BorderLayout.SOUTH);
    JButton btnAdd = new JButton(Localisation.getString(EnvVarDlg.class, "EnvVarDlg.add"));
    btnAdd.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dataModel.addNewVariable();
            btnRemove.setEnabled(false);
        }
    });
    panel_1.add(btnAdd);
    btnRemove = new JButton(Localisation.getString(EnvVarDlg.class, "EnvVarDlg.remove"));
    btnRemove.setEnabled(false);
    btnRemove.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dataModel.removeEnvVar(table.getSelectedRow());
            btnRemove.setEnabled(false);
        }
    });
    panel_1.add(btnRemove);
}
Also used : JPanel(javax.swing.JPanel) MalformedURLException(java.net.MalformedURLException) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JTextField(javax.swing.JTextField) URL(java.net.URL) BorderLayout(java.awt.BorderLayout) EnvVar(com.sldeditor.filter.v2.envvar.EnvVar) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with EnvVar

use of com.sldeditor.filter.v2.envvar.EnvVar in project sldeditor by robward-scisys.

the class EnvVarModel method addNewVariable.

/**
 * Adds the new variable.
 */
public void addNewVariable() {
    EnvVar envVar = this.envMgr.addNewEnvVar("NewEnvVar", String.class, null);
    if (envVar != null) {
        dataList.add(envVar);
        this.fireTableDataChanged();
    }
}
Also used : EnvVar(com.sldeditor.filter.v2.envvar.EnvVar)

Aggregations

EnvVar (com.sldeditor.filter.v2.envvar.EnvVar)11 Test (org.junit.Test)4 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)2 VersionData (com.sldeditor.common.vendoroption.VersionData)2 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)2 LegendOptionData (com.sldeditor.ui.legend.option.LegendOptionData)2 FlowLayout (java.awt.FlowLayout)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JPanel (javax.swing.JPanel)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 EnvironmentVariableField (com.sldeditor.filter.v2.envvar.EnvironmentVariableField)1