Search in sources :

Example 51 with NotConfigurableException

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

the class OperatorSettingsButtonCellRenderer method openSettingsDialog.

private void openSettingsDialog() {
    final JTable table = m_rootPanel.getTable();
    final int row = table.convertRowIndexToModel(table.getEditingRow());
    fireEditingStopped();
    final AggregationMethod aggr = (AggregationMethod) m_rootPanel.getTableModel().getRow(row);
    if (!aggr.hasOptionalSettings()) {
        // the operator has no additional settings
        return;
    }
    // figure out the parent to be able to make the dialog modal
    Frame f = null;
    Container c = m_rootPanel.getComponentPanel().getParent();
    while (c != null) {
        if (c instanceof Frame) {
            f = (Frame) c;
            break;
        }
        c = c.getParent();
    }
    try {
        final AggregationParameterDialog dialog = new AggregationParameterDialog(f, aggr, m_rootPanel.getInputTableSpec());
        // center the dialog
        dialog.setLocationRelativeTo(c);
        dialog.pack();
        // show it
        dialog.setVisible(true);
    } catch (NotConfigurableException e) {
        // show the error message
        JOptionPane.showMessageDialog(m_rootPanel.getComponentPanel(), e.getMessage(), "Unable to open dialog", JOptionPane.ERROR_MESSAGE);
        return;
    }
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) NotConfigurableException(org.knime.core.node.NotConfigurableException) Frame(java.awt.Frame) Container(java.awt.Container) JTable(javax.swing.JTable)

Example 52 with NotConfigurableException

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

the class TreeEnsembleLearnerConfiguration method loadInDialog.

/**
 * Loads the settings.
 * Intended for the use in the NodeDialog
 *
 * @param settings
 * @param inSpec
 * @throws NotConfigurableException
 */
public void loadInDialog(final NodeSettingsRO settings, final DataTableSpec inSpec) throws NotConfigurableException {
    String defTargetColumn = null;
    String defFingerprintColumn = null;
    boolean hasAttributeColumns = false;
    // guess defaults:
    // traverse columns backwards; assign last (i.e. first-seen) appropriate
    // column as target, use any subsequent as valid learning attribute
    Class<? extends DataValue> targetClass = getRequiredTargetClass();
    for (int i = inSpec.getNumColumns() - 1; i >= 0; i--) {
        DataColumnSpec colSpec = inSpec.getColumnSpec(i);
        DataType colType = colSpec.getType();
        String colName = colSpec.getName();
        if (colType.isCompatible(BitVectorValue.class) || colType.isCompatible(ByteVectorValue.class)) {
            defFingerprintColumn = colName;
        } else if (colType.isCompatible(NominalValue.class) || colType.isCompatible(DoubleValue.class)) {
            if (colType.isCompatible(targetClass)) {
                if (defTargetColumn == null) {
                    // first categorical column
                    defTargetColumn = colName;
                } else {
                    hasAttributeColumns = true;
                }
            } else {
                hasAttributeColumns = true;
            }
        }
    }
    if (defTargetColumn == null) {
        throw new NotConfigurableException("No categorical data in input " + "(node not connected?) -- unable to configure.");
    }
    if (!hasAttributeColumns && defFingerprintColumn == null) {
        throw new NotConfigurableException("No appropriate learning column " + "in input (need to have at least one additional " + "numeric/categorical column, fingerprint data or byte vector data)");
    }
    // assign fields:
    m_targetColumn = settings.getString(KEY_TARGET_COLUMN, defTargetColumn);
    DataColumnSpec targetColSpec = inSpec.getColumnSpec(m_targetColumn);
    if (targetColSpec == null || !targetColSpec.getType().isCompatible(targetClass)) {
        m_targetColumn = defTargetColumn;
    }
    String hardCodedRootColumn = settings.getString(KEY_ROOT_COLUMN, null);
    if (inSpec.getColumnSpec(hardCodedRootColumn) == null) {
        m_hardCodedRootColumn = null;
    } else {
        m_hardCodedRootColumn = hardCodedRootColumn;
    }
    m_fingerprintColumn = settings.getString(KEY_FINGERPRINT_COLUMN, defFingerprintColumn);
    if (m_fingerprintColumn == null) {
    // null in node settings - leave it
    } else {
        DataColumnSpec fpColSpec = inSpec.getColumnSpec(m_fingerprintColumn);
        if (fpColSpec == null || !fpColSpec.getType().isCompatible(BitVectorValue.class)) {
            m_fingerprintColumn = defFingerprintColumn;
        }
    }
    m_includeColumns = settings.getStringArray(KEY_INCLUDE_COLUMNS, (String[]) null);
    m_includeAllColumns = settings.getBoolean(KEY_INCLUDE_ALL_COLUMNS, true);
    Long defSeed = System.currentTimeMillis();
    String seedS = settings.getString(KEY_SEED, Long.toString(defSeed));
    Long seed;
    if (seedS == null) {
        seed = null;
    } else {
        try {
            seed = Long.parseLong(seedS);
        } catch (NumberFormatException nfe) {
            seed = m_seed;
        }
    }
    m_seed = seed;
    m_maxLevels = settings.getInt(KEY_MAX_LEVELS, DEF_MAX_LEVEL);
    if (m_maxLevels != MAX_LEVEL_INFINITE && m_maxLevels <= 0) {
        m_maxLevels = DEF_MAX_LEVEL;
    }
    int minNodeSize = settings.getInt(KEY_MIN_NODE_SIZE, MIN_NODE_SIZE_UNDEFINED);
    int minChildSize = settings.getInt(KEY_MIN_CHILD_SIZE, MIN_CHILD_SIZE_UNDEFINED);
    try {
        setMinSizes(minNodeSize, minChildSize);
    } catch (InvalidSettingsException e) {
        m_minNodeSize = MIN_NODE_SIZE_UNDEFINED;
        m_minChildSize = MIN_CHILD_SIZE_UNDEFINED;
    }
    m_dataFractionPerTree = settings.getDouble(KEY_DATA_FRACTION, DEF_DATA_FRACTION);
    if (m_dataFractionPerTree <= 0.0 || m_dataFractionPerTree > 1.0) {
        m_dataFractionPerTree = DEF_DATA_FRACTION;
    }
    m_columnAbsoluteValue = settings.getInt(KEY_COLUMN_ABSOLUTE, DEF_COLUMN_ABSOLUTE);
    if (m_columnAbsoluteValue <= 0) {
        m_columnAbsoluteValue = DEF_COLUMN_ABSOLUTE;
    }
    m_isDataSelectionWithReplacement = settings.getBoolean(KEY_IS_DATA_SELECTION_WITH_REPLACEMENT, true);
    ColumnSamplingMode defColSamplingMode = DEF_COLUMN_SAMPLING_MODE;
    ColumnSamplingMode colSamplingMode = defColSamplingMode;
    String colSamplingModeS = settings.getString(KEY_COLUMN_SAMPLING_MODE, null);
    if (colSamplingModeS == null) {
        colSamplingMode = defColSamplingMode;
    } else {
        try {
            colSamplingMode = ColumnSamplingMode.valueOf(colSamplingModeS);
        } catch (Exception e) {
            colSamplingMode = defColSamplingMode;
        }
    }
    double colFracLinValue;
    switch(colSamplingMode) {
        case Linear:
            colFracLinValue = settings.getDouble(KEY_COLUMN_FRACTION_LINEAR, DEF_COLUMN_FRACTION);
            if (colFracLinValue <= 0.0 || colFracLinValue > 1.0) {
                colFracLinValue = DEF_COLUMN_FRACTION;
            }
            break;
        default:
            colFracLinValue = DEF_COLUMN_FRACTION;
    }
    m_columnSamplingMode = colSamplingMode;
    m_columnFractionLinearValue = colFracLinValue;
    m_isUseDifferentAttributesAtEachNode = settings.getBoolean(KEY_IS_USE_DIFFERENT_ATTRIBUTES_AT_EACH_NODE, true);
    m_nrModels = settings.getInt(KEY_NR_MODELS, DEF_NR_MODELS);
    if (m_nrModels <= 0) {
        m_nrModels = DEF_NR_MODELS;
    }
    SplitCriterion defSplitCriterion = SplitCriterion.InformationGainRatio;
    String splitCriterionS = settings.getString(KEY_SPLIT_CRITERION, defSplitCriterion.name());
    SplitCriterion splitCriterion;
    if (splitCriterionS == null) {
        splitCriterion = defSplitCriterion;
    } else {
        try {
            splitCriterion = SplitCriterion.valueOf(splitCriterionS);
        } catch (Exception e) {
            splitCriterion = defSplitCriterion;
        }
    }
    m_splitCriterion = splitCriterion;
    m_useAverageSplitPoints = settings.getBoolean(KEY_USE_AVERAGE_SPLIT_POINTS, DEF_AVERAGE_SPLIT_POINTS);
    if (m_fingerprintColumn != null) {
    // use fingerprint data, OK
    } else if (m_includeColumns != null && m_includeColumns.length > 0) {
    // some attributes set, OK
    } else if (m_includeAllColumns) {
    // use all appropriate columns, OK
    } else if (defFingerprintColumn != null) {
        // no valid columns but fingerprint column found - use it
        m_fingerprintColumn = defFingerprintColumn;
    } else {
        m_includeAllColumns = true;
    }
    m_ignoreColumnsWithoutDomain = settings.getBoolean(KEY_IGNORE_COLUMNS_WITHOUT_DOMAIN, true);
    m_nrHilitePatterns = settings.getInt(KEY_NR_HILITE_PATTERNS, -1);
    m_saveTargetDistributionInNodes = settings.getBoolean(KEY_SAVE_TARGET_DISTRIBUTION_IN_NODES, DEF_SAVE_TARGET_DISTRIBUTION_IN_NODES);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NotConfigurableException(org.knime.core.node.NotConfigurableException) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue)

Example 53 with NotConfigurableException

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

the class ColorManager2NodeDialogPane method loadSettingsFrom.

/**
 * Updates this dialog by refreshing all components in the color tab. Inits the column name combo box and sets the
 * values for the default selected one.
 *
 * @param settings the settings to load
 * @param specs the input table specs
 * @throws NotConfigurableException if no column found for color selection
 * @see NodeDialogPane#loadSettingsFrom(NodeSettingsRO, DataTableSpec[])
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    // remove all columns
    m_columns.removeItemListener(this);
    m_columns.removeAllItems();
    // reset nominal and range panel
    m_nominal.removeAllElements();
    m_range.removeAllElements();
    // index of the last column with nominal values
    int hasNominals = -1;
    // index of the last column with numeric ranges defined
    int hasRanges = -1;
    // read settings and write into the map
    String target = settings.getString(ColorManager2NodeModel.SELECTED_COLUMN, null);
    // null = not specified, true = nominal, and false = range
    Boolean nominalSelected = null;
    try {
        nominalSelected = settings.getBoolean(ColorManager2NodeModel.IS_NOMINAL);
    } catch (InvalidSettingsException ise) {
        LOGGER.debug("Nominal/Range selection flag" + " not available.");
    }
    // find last columns for nominal values and numeric ranges defined
    for (int i = 0; i < specs[0].getNumColumns(); i++) {
        DataColumnSpec cspec = specs[0].getColumnSpec(i);
        DataColumnDomain domain = cspec.getDomain();
        // nominal values defined
        if (domain.hasValues()) {
            m_nominal.add(cspec.getName(), domain.getValues());
            // select last possible nominal column
            hasNominals = i;
        }
        // numeric ranges defined
        if (cspec.getType().isCompatible(DoubleValue.class)) {
            DataCell lower = domain.getLowerBound();
            DataCell upper = domain.getUpperBound();
            // lower and upper bound can be null
            m_range.add(cspec.getName(), lower, upper);
            if (hasRanges == -1) {
                // select first range column found
                hasRanges = i;
            }
        }
    }
    // check for not configurable: no column found
    if (hasNominals == -1 && hasRanges == -1) {
        throw new NotConfigurableException("Please provide input table" + " with at least one column with either nominal and/or" + " lower and upper bounds defined.");
    }
    // have possible values defined AND is not compatible with DoubleType
    if (target == null || !specs[0].containsName(target) || (!specs[0].getColumnSpec(target).getDomain().hasValues() && !specs[0].getColumnSpec(target).getType().isCompatible(DoubleValue.class))) {
        // select first nominal column if nothing could be selected
        if (hasNominals > -1) {
            target = specs[0].getColumnSpec(hasNominals).getName();
            nominalSelected = true;
        } else {
            // otherwise the first range column
            if (hasRanges > -1) {
                target = specs[0].getColumnSpec(hasRanges).getName();
                nominalSelected = false;
            } else {
                // 
                assert false : "Both, nominal and range column are not " + "available!";
            }
        }
    } else {
        // we have a valid target column
        boolean domValues = specs[0].getColumnSpec(target).getDomain().hasValues();
        // nothing selected before
        if (nominalSelected == null) {
            // select nominal, if possible values found
            nominalSelected = domValues;
        } else {
            // nominal! but no possible values
            if (nominalSelected && !domValues) {
                // use range column
                nominalSelected = false;
            }
        }
    }
    // nominal column selected
    if (hasNominals > -1) {
        m_nominal.loadSettings(settings, target);
        if (nominalSelected) {
            m_nominal.select(target);
            m_alphaPanel.setAlpha(m_nominal.getAlpha());
        }
    } else {
        m_nominal.select(null);
    }
    // numeric range column selected
    if (hasRanges > -1) {
        m_range.loadSettings(settings, target);
        if (!nominalSelected) {
            m_range.select(target);
            m_alphaPanel.setAlpha(m_range.getAlpha());
        }
    } else {
        m_range.select(null);
    }
    // add all columns
    int cols = specs[0].getNumColumns();
    for (int i = 0; i < cols; i++) {
        DataColumnSpec cspec = specs[0].getColumnSpec(i);
        m_columns.addItem(cspec);
        if (cspec.getName().equals(target)) {
            m_columns.setSelectedIndex(i);
        }
    }
    // inform about column change
    columnChanged(target, nominalSelected);
    // register column change listener
    m_columns.addItemListener(this);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataCell(org.knime.core.data.DataCell)

Example 54 with NotConfigurableException

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

the class RankNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    // Check input spec
    if (specs[0] == null || specs[0].getNumColumns() == 0) {
        throw new NotConfigurableException("No input table found or no columns found in input table! " + "Please connect the node first or check input table.");
    }
    final DataTableSpec spec = specs[0];
    // load settings models
    try {
        m_rankColsModel.loadSettingsFrom(settings);
        m_rankOrderModel.loadSettingsFrom(settings);
        m_groupColsModel.loadSettingsFrom(settings);
        m_rankMode.loadSettingsFrom(settings);
        m_rankOutColName.loadSettingsFrom(settings);
        m_retainRowOrder.loadSettingsFrom(settings);
        m_rankAsLong.loadSettingsFrom(settings);
    } catch (InvalidSettingsException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    m_rankTableModel.setRowCount(0);
    String[] rankColNames = m_rankColsModel.getStringArrayValue();
    String[] order = m_rankOrderModel.getStringArrayValue();
    m_rankCols.clear();
    for (int i = 0; i < rankColNames.length; i++) {
        DataColumnSpec colSpec = spec.getColumnSpec(rankColNames[i]);
        if (colSpec != null) {
            m_rankTableModel.addRow(new Object[] { colSpec, order[i] });
            m_rankCols.add(colSpec);
        }
    }
    m_groupTableModel.setRowCount(0);
    m_groupCols.clear();
    String[] groupColNames = m_groupColsModel.getStringArrayValue();
    for (int r = 0; r < groupColNames.length; r++) {
        DataColumnSpec colSpec = spec.getColumnSpec(groupColNames[r]);
        if (colSpec != null) {
            m_groupTableModel.addRow(new Object[] { colSpec });
            m_groupCols.add(colSpec);
        }
    }
    removeAllColSpecsFromAvailable();
    for (int i = 0; i < spec.getNumColumns(); i++) {
        DataColumnSpec colSpec = spec.getColumnSpec(i);
        if (m_rankCols.contains(colSpec)) {
            addItemRankColEditor(colSpec);
        } else if (m_groupCols.contains(colSpec)) {
            addItemGroupColEditor(colSpec);
        } else {
            addColSpec2Available(colSpec);
        }
    }
    // select rank mode:
    Enumeration<AbstractButton> radios = m_modusGroup.getElements();
    JRadioButton modus = (JRadioButton) radios.nextElement();
    while (!modus.getText().equals(m_rankMode.getStringValue())) {
        modus.setSelected(false);
        modus = (JRadioButton) radios.nextElement();
    }
    modus.setSelected(true);
    // set retain order checkbox
    m_retainOrderCheckBox.setSelected(m_retainRowOrder.getBooleanValue());
    // set rank out col name text field
    m_outColNameTextField.setText(m_rankOutColName.getStringValue());
    // set rank as long checkbox
    m_rankAsLongCheckBox.setSelected(m_rankAsLong.getBooleanValue());
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) AbstractButton(javax.swing.AbstractButton) JRadioButton(javax.swing.JRadioButton) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 55 with NotConfigurableException

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

the class TwoColumnProperties method update.

/**
 * Updates the selection boxes with the new
 * {@link org.knime.core.data.DataTableSpec} and selects the passed
 * indices.
 *
 * @param spec the new data table spec.
 * @param xPreSelect the x column index (-1 if unknown)
 * @param yPreSelect the y column (-1 if unknown)
 */
public void update(final DataTableSpec spec, final int xPreSelect, final int yPreSelect) {
    try {
        m_xSelector.update(spec, spec.getColumnSpec(xPreSelect).getName(), true);
        m_ySelector.update(spec, spec.getColumnSpec(yPreSelect).getName(), true);
    } catch (NotConfigurableException e) {
        LOGGER.warn(e.getMessage(), e);
    }
    DataColumnSpec x = (DataColumnSpec) m_xSelector.getSelectedItem();
    DataColumnSpec y = (DataColumnSpec) m_ySelector.getSelectedItem();
    updateRangeSpinner(x, y);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Aggregations

NotConfigurableException (org.knime.core.node.NotConfigurableException)79 DataColumnSpec (org.knime.core.data.DataColumnSpec)35 DataTableSpec (org.knime.core.data.DataTableSpec)35 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)31 DataColumnSpecFilterConfiguration (org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration)8 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)5 DataType (org.knime.core.data.DataType)5 NominalValue (org.knime.core.data.NominalValue)5 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)5 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 Container (java.awt.Container)3 Frame (java.awt.Frame)3 GridBagConstraints (java.awt.GridBagConstraints)3 ActionListener (java.awt.event.ActionListener)3 ItemListener (java.awt.event.ItemListener)3 AbstractButton (javax.swing.AbstractButton)3 DefaultListModel (javax.swing.DefaultListModel)3 LinkedHashMap (java.util.LinkedHashMap)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2