use of org.knime.core.node.util.filter.nominal.NominalValueFilterConfiguration in project knime-core by knime.
the class NominalValueRowFilterNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
if (specs.length == 0 || specs[0] == null) {
throw new NotConfigurableException("No incoming columns found. " + "Please connect the node with input table!");
}
// get selected column
m_selectedColumn = settings.getString(CFG_SELECTED_COL, "");
// clear old values
m_colAttributes.clear();
m_columns.removeAllElements();
// disable item state change listener while adding values
m_columnSelection.removeItemListener(this);
// fill the models
for (DataColumnSpec colSpec : specs[0]) {
if (colSpec.getType().isCompatible(NominalValue.class) && colSpec.getDomain().hasValues()) {
m_columns.addElement(colSpec.getName());
// create column - possible values mapping
m_colAttributes.put(colSpec.getName(), colSpec.getDomain().getValues());
}
}
// set selection
if (m_selectedColumn != null) {
m_columnSelection.setSelectedItem(m_selectedColumn);
// enable item change listener again
m_columnSelection.addItemListener(this);
} else {
m_columnSelection.addItemListener(this);
m_columnSelection.setSelectedIndex(-1);
m_columnSelection.setSelectedItem(m_columnSelection.getItemAt(0));
}
NominalValueFilterConfiguration config = new NominalValueFilterConfiguration(CFG_CONFIGROOTNAME);
Set<DataCell> domain = m_colAttributes.get(m_selectedColumn);
if (settings.containsKey(CFG_CONFIGROOTNAME)) {
config.loadConfigurationInDialog(settings, domain);
} else {
// backwards compatibility
String[] selectedAttributes = settings.getStringArray(CFG_SELECTED_ATTR, "");
Set<String> includedAttr = new HashSet<String>();
for (String s : selectedAttributes) {
includedAttr.add(s);
}
ArrayList<String> m_included = new ArrayList<String>();
ArrayList<String> m_excluded = new ArrayList<String>();
if (domain != null) {
for (DataCell dc : domain) {
// if possible value was in the settings...
if (includedAttr.contains(dc.toString())) {
// ... put it to included ...
m_included.add(dc.toString());
} else {
// ... else to excluded
m_excluded.add(dc.toString());
}
}
}
config.loadDefaults(m_included.toArray(new String[m_included.size()]), m_excluded.toArray(new String[m_excluded.size()]), EnforceOption.EnforceInclusion);
}
m_filterPanel.loadConfiguration(config, domain);
}
use of org.knime.core.node.util.filter.nominal.NominalValueFilterConfiguration in project knime-core by knime.
the class NominalValueRowFilterNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
String selectedColumn = (String) m_columnSelection.getSelectedItem();
CheckUtils.checkSettingNotNull(selectedColumn, "No nominal column selected (there is no nominal column in " + "the input or the upstream node is not executed)");
settings.addString(CFG_SELECTED_COL, selectedColumn);
NominalValueFilterConfiguration config = new NominalValueFilterConfiguration(CFG_CONFIGROOTNAME);
m_filterPanel.saveConfiguration(config);
config.saveConfiguration(settings);
}
use of org.knime.core.node.util.filter.nominal.NominalValueFilterConfiguration in project knime-core by knime.
the class NominalValueRowFilterNodeDialog method itemStateChanged.
/**
* {@inheritDoc}
*
* If the nominal column selection changes, include and exclude lists are
* cleared and all possible values of that column are put into the exclude
* list.
*/
@Override
public void itemStateChanged(final ItemEvent item) {
if (item.getStateChange() == ItemEvent.SELECTED) {
m_selectedColumn = (String) item.getItem();
ArrayList<String> names = new ArrayList<>();
if (m_colAttributes.get(m_selectedColumn) != null) {
for (DataCell dc : m_colAttributes.get(m_selectedColumn)) {
names.add(dc.toString());
}
}
String[] namesArray = names.toArray(new String[names.size()]);
NominalValueFilterConfiguration config = new NominalValueFilterConfiguration(CFG_CONFIGROOTNAME);
config.loadDefaults(null, namesArray, EnforceOption.EnforceInclusion);
m_filterPanel.loadConfiguration(config, namesArray);
}
}
Aggregations