Search in sources :

Example 31 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class BoxPlotNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    try {
        File f = new File(nodeInternDir, FILE_NAME);
        FileInputStream fis = new FileInputStream(f);
        NodeSettingsRO settings = NodeSettings.loadFromXML(fis);
        m_statistics = new LinkedHashMap<DataColumnSpec, double[]>();
        m_mildOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        m_extremeOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        int nrOfCols = settings.getInt(CFG_NR_COLS);
        for (int i = 0; i < nrOfCols; i++) {
            NodeSettings subSetting = (NodeSettings) settings.getConfig(CFG_COL + i);
            DataColumnSpec spec = DataColumnSpec.load(subSetting);
            double[] stats = settings.getDoubleArray(CFG_STATS + spec.getName());
            m_statistics.put(spec, stats);
            loadOutliers(settings, spec);
        }
        File data = new File(nodeInternDir, ARRAY_FILE);
        ContainerTable table = DataContainer.readFromZip(data);
        m_array = new DefaultDataArray(table, 1, 2, exec);
    } catch (Exception e) {
        LOGGER.warn(e);
        throw new IOException(e.getMessage());
    }
}
Also used : RowKey(org.knime.core.data.RowKey) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) NodeSettings(org.knime.core.node.NodeSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 32 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class BinnerNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    DataTableSpec spec = (DataTableSpec) specs[0];
    // numeric columns' settings
    m_intervals.clear();
    m_numMdl.removeAllElements();
    for (int i = 0; i < spec.getNumColumns(); i++) {
        DataColumnSpec cspec = spec.getColumnSpec(i);
        if (cspec.getType().isCompatible(DoubleValue.class)) {
            m_numMdl.addElement(cspec);
        }
    }
    String[] columns = settings.getStringArray(BinnerNodeModel.NUMERIC_COLUMNS, (String[]) null);
    // if numeric columns in settings, select first
    if (columns != null && columns.length > 0) {
        for (int i = 0; i < columns.length; i++) {
            if (!spec.containsName(columns[i])) {
                continue;
            }
            DataTableSpec dataspec = (DataTableSpec) specs[0];
            DataType type = dataspec.getColumnSpec(columns[i]).getType();
            if (!type.isCompatible(DoubleValue.class)) {
                continue;
            }
            NodeSettingsRO col;
            try {
                col = settings.getNodeSettings(columns[i].toString());
            } catch (InvalidSettingsException ise) {
                LOGGER.warn("NodeSettings not available for column: " + columns[i]);
                continue;
            }
            String appendedColumn = null;
            if (settings.containsKey(columns[i].toString() + BinnerNodeModel.IS_APPENDED)) {
                appendedColumn = settings.getString(columns[i].toString() + BinnerNodeModel.IS_APPENDED, null);
            }
            IntervalPanel p = new IntervalPanel(columns[i], appendedColumn, m_numList, type);
            m_intervals.put(columns[i], p);
            for (String binId : col.keySet()) {
                NumericBin theBin = null;
                try {
                    theBin = new NumericBin(col.getNodeSettings(binId));
                } catch (InvalidSettingsException ise) {
                    LOGGER.warn("NodeSettings not available for " + "interval bin: " + binId);
                    continue;
                }
                String binName = theBin.getBinName();
                boolean leftOpen = theBin.isLeftOpen();
                double left = theBin.getLeftValue();
                boolean rightOpen = theBin.isRightOpen();
                double right = theBin.getRightValue();
                IntervalItemPanel item = new IntervalItemPanel(p, leftOpen, left, rightOpen, right, binName, type);
                p.addIntervalItem(item);
            }
            DataColumnSpec cspec = spec.getColumnSpec(columns[i]);
            // select column and scroll to position
            m_numList.setSelectedValue(cspec, true);
        }
    }
    getPanel().validate();
    getPanel().repaint();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 33 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class BinnerNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    StringBuffer sb = new StringBuffer();
    String[] columns = settings.getStringArray(NUMERIC_COLUMNS, new String[0]);
    if (columns == null) {
        sb.append("Numeric column array can't be 'null'\n");
    } else {
        for (int i = 0; i < columns.length; i++) {
            // appended or replaced
            settings.getString(columns[i].toString() + IS_APPENDED, null);
            double old = Double.NEGATIVE_INFINITY;
            if (columns[i] == null) {
                sb.append("Column can't be 'null': " + i + "\n");
                continue;
            }
            NodeSettingsRO set = settings.getNodeSettings(columns[i].toString());
            for (String binKey : set.keySet()) {
                NodeSettingsRO bin = set.getNodeSettings(binKey);
                NumericBin theBin = null;
                try {
                    theBin = new NumericBin(bin);
                } catch (InvalidSettingsException ise) {
                    sb.append(columns[i] + ": " + ise.getMessage() + "\n");
                    continue;
                }
                String binName = theBin.getBinName();
                double l = theBin.getLeftValue();
                if (l != old) {
                    sb.append(columns[i] + ": " + binName + " check interval: " + "left=" + l + ",oldright=" + old + "\n");
                }
                double r = theBin.getRightValue();
                boolean lOpen = theBin.isLeftOpen();
                boolean rOpen = theBin.isRightOpen();
                if (r < l) {
                    sb.append(columns[i] + ": " + binName + " check interval: " + "left=" + l + ",right=" + r + "\n");
                } else {
                    if (r == l && !(!lOpen && !rOpen)) {
                        sb.append(columns[i] + ": " + binName + " check borders: " + "left=" + l + ",right=" + r + "\n");
                    }
                }
                old = r;
            }
            if (old != Double.POSITIVE_INFINITY) {
                sb.append(columns[i] + ": check last right interval value=" + old + "\n");
            }
        }
    }
    if (sb.length() > 0) {
        throw new InvalidSettingsException(sb.toString());
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 34 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class DropPane method loadSettingsFrom.

/**
 * @param settings
 * @param specs
 * @throws InvalidSettingsException
 * @throws NotConfigurableException
 */
@Override
public void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws InvalidSettingsException, NotConfigurableException {
    m_loading = true;
    NodeSettingsRO ns = settings.getNodeSettings(CFGKEY_DROPPANE + getPosition());
    m_dialog.loadSettingsFrom(ns, specs);
    m_loading = false;
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 35 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class TypePane method loadSettingsFrom.

/**
 * @param settings
 * @param specs
 * @throws InvalidSettingsException
 * @throws NotConfigurableException
 */
@Override
public void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws InvalidSettingsException, NotConfigurableException {
    NodeSettingsRO ns = settings.getNodeSettings(CFGKEY_DROPPANE + getPosition());
    m_dialog.loadSettingsFrom(ns, specs);
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Aggregations

NodeSettingsRO (org.knime.core.node.NodeSettingsRO)208 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 File (java.io.File)49 FileInputStream (java.io.FileInputStream)47 IOException (java.io.IOException)43 InputStream (java.io.InputStream)22 LinkedHashMap (java.util.LinkedHashMap)20 NodeSettings (org.knime.core.node.NodeSettings)20 BufferedInputStream (java.io.BufferedInputStream)19 ArrayList (java.util.ArrayList)16 GZIPInputStream (java.util.zip.GZIPInputStream)15 DataTableSpec (org.knime.core.data.DataTableSpec)14 Map (java.util.Map)11 ReferencedFile (org.knime.core.internal.ReferencedFile)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)10 HashMap (java.util.HashMap)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 RowKey (org.knime.core.data.RowKey)9 DataType (org.knime.core.data.DataType)8 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)8