Search in sources :

Example 11 with DataValue

use of org.knime.core.data.DataValue in project knime-core by knime.

the class ScatterProps method setSelectables.

/**
 * @param tSpec the data table spec
 * @param filterClass allowed classes
 */
public void setSelectables(final DataTableSpec tSpec, final Class<? extends DataValue>... filterClass) {
    List<Class<? extends DataValue>> filters = Arrays.asList(filterClass);
    // do nothing if the table spec has been already before
    if (m_tableSpec == tSpec) {
        return;
    }
    // else set the given table spec as the current
    m_tableSpec = tSpec;
    m_xCol.setEnabled(true);
    m_yCol.setEnabled(true);
    m_xAvailCol.clear();
    if (tSpec != null) {
        // put all column names of type double in the drop box
        List<DataColumnSpec> compatibleSpecs = new ArrayList<DataColumnSpec>();
        for (int i = 0; i < tSpec.getNumColumns(); i++) {
            // if we can get a number from that column: add it to the vector
            // check which columns are displayable
            DataType type = tSpec.getColumnSpec(i).getType();
            for (Class<? extends DataValue> cl : filters) {
                if (type.isCompatible(cl)) {
                    compatibleSpecs.add(tSpec.getColumnSpec(i));
                }
            }
        }
        for (DataColumnSpec compSpec : compatibleSpecs) {
            // check which columns are displayable
            if (Coordinate.createCoordinate(compSpec) != null) {
                m_xAvailCol.add(compSpec);
            }
        }
    }
    // store the old selection - in case it's still good
    DataColumnSpec xColSel = (DataColumnSpec) m_xCol.getSelectedItem();
    DataColumnSpec yColSel = (DataColumnSpec) m_yCol.getSelectedItem();
    // now set the (possibly empty) list
    m_xCol.setModel(new DefaultComboBoxModel(m_xAvailCol));
    m_yCol.setModel(new DefaultComboBoxModel(m_xAvailCol));
    // check if we can reuse the old selection
    if (xColSel != null && yColSel != null) {
        m_xCol.setSelectedItem(xColSel);
        m_yCol.setSelectedItem(yColSel);
    } else {
        // set default values if we dont have any selected values
        if ((xColSel == null) && (m_xAvailCol.size() > 0)) {
            m_xCol.setSelectedItem(m_xAvailCol.get(0));
        }
        if (yColSel == null) {
            if (m_xAvailCol.size() > 1) {
                m_yCol.setSelectedItem(m_xAvailCol.get(1));
            } else if (m_xAvailCol.size() > 0) {
                m_yCol.setSelectedItem(m_xAvailCol.get(0));
            }
        }
    }
    selectedXColChanged((DataColumnSpec) m_xCol.getSelectedItem());
    selectedYColChanged((DataColumnSpec) m_yCol.getSelectedItem());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataValue(org.knime.core.data.DataValue) ArrayList(java.util.ArrayList) DataType(org.knime.core.data.DataType) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 12 with DataValue

use of org.knime.core.data.DataValue in project knime-core by knime.

the class DataCellToJavaConverterRegistry method parseAnnotations.

/*
     * Parse @DataCellFactoryMethod and @DataValueAccessMethod annotations
     */
private void parseAnnotations() {
    final Collection<DataType> availableDataTypes = DataTypeRegistry.getInstance().availableDataTypes();
    final Set<Class<? extends DataValue>> processedValueClasses = new HashSet<>();
    for (final DataType dataType : availableDataTypes) {
        for (final Class<? extends DataValue> valueClass : dataType.getValueClasses()) {
            if (processedValueClasses.contains(valueClass)) {
                // already parsed this value class
                continue;
            }
            // get methods annotated with DataValueAccessMethod
            final Collection<Pair<Method, DataValueAccessMethod>> methodsWithAnnotation = ClassUtil.getMethodsWithAnnotation(valueClass, DataValueAccessMethod.class);
            // register a converter for every DataValueAccessMethod annotation
            for (final Pair<Method, DataValueAccessMethod> pair : methodsWithAnnotation) {
                parseAnnotation(valueClass, pair.getFirst(), pair.getSecond());
            }
            processedValueClasses.add(valueClass);
        }
    }
}
Also used : CollectionDataValue(org.knime.core.data.collection.CollectionDataValue) DataValue(org.knime.core.data.DataValue) DataValueAccessMethod(org.knime.core.data.convert.DataValueAccessMethod) DataType(org.knime.core.data.DataType) Method(java.lang.reflect.Method) DataValueAccessMethod(org.knime.core.data.convert.DataValueAccessMethod) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Pair(org.knime.core.util.Pair)

Example 13 with DataValue

use of org.knime.core.data.DataValue in project knime-core by knime.

the class BinByDictionaryConfiguration method loadSettingsDialog.

/**
 * Load settings in dialog.
 * @param settings To load from.
 * @param ins Input specs for initialization.
 * @throws NotConfigurableException if no appropriate columns in input.
 */
void loadSettingsDialog(final NodeSettingsRO settings, final DataTableSpec[] ins) throws NotConfigurableException {
    String valueColPort0 = null;
    String lowerBoundColPort1 = null;
    String upperBoundColPort1 = null;
    String labelColumnPort1 = null;
    // find default values in the table, try be smart and favor
    // date columns over int over double over ... etc.
    @SuppressWarnings("unchecked") Class<? extends DataValue>[] typeCandidates = new Class[] { DateAndTimeValue.class, IntValue.class, DoubleValue.class, LongValue.class, BoundedValue.class, DataValue.class };
    for (Class<? extends DataValue> valueClass : typeCandidates) {
        for (DataColumnSpec c : ins[0]) {
            if (c.getType().isCompatible(valueClass)) {
                valueColPort0 = c.getName();
                break;
            }
        }
        if (valueColPort0 == null) {
            // no such type in input, continue with next one
            continue;
        }
        for (int i = ins[1].getNumColumns(); --i >= 0; ) {
            DataColumnSpec c = ins[1].getColumnSpec(i);
            if (c.getType().isCompatible(valueClass)) {
                if (upperBoundColPort1 == null) {
                    upperBoundColPort1 = c.getName();
                } else if (lowerBoundColPort1 == null) {
                    lowerBoundColPort1 = c.getName();
                    break;
                }
            }
        }
        if (upperBoundColPort1 != null) {
            // and accept these columns as default
            break;
        }
    }
    if (valueColPort0 == null) {
        throw new NotConfigurableException("No value column in first input");
    }
    if (upperBoundColPort1 == null) {
        throw new NotConfigurableException("No reasonable column in second input");
    }
    m_valueColumnPort0 = settings.getString("valueColumnPort0", valueColPort0);
    m_lowerBoundColumnPort1 = settings.getString("lowerBoundColumnPort1", lowerBoundColPort1);
    m_lowerBoundInclusive = settings.getBoolean("lowerBoundInclusive", false);
    m_upperBoundColumnPort1 = settings.getString("upperBoundColumnPort1", upperBoundColPort1);
    m_upperBoundInclusive = settings.getBoolean("upperBoundInclusive", true);
    for (DataColumnSpec c : ins[1]) {
        if (labelColumnPort1 == null) {
            labelColumnPort1 = c.getName();
        } else if (c.getType().isCompatible(NominalValue.class)) {
            labelColumnPort1 = c.getName();
        }
    }
    m_labelColumnPort1 = settings.getString("labelColumnPort1", labelColumnPort1);
    if (!ins[0].containsName(m_valueColumnPort0)) {
        m_valueColumnPort0 = valueColPort0;
    }
    if (!ins[1].containsName(m_upperBoundColumnPort1)) {
        m_upperBoundColumnPort1 = upperBoundColPort1;
        m_lowerBoundColumnPort1 = lowerBoundColPort1;
    }
    if (!ins[1].containsName(m_labelColumnPort1)) {
        m_labelColumnPort1 = labelColumnPort1;
    }
    m_failIfNoRuleMatches = settings.getBoolean("failIfNoRuleMatches", false);
    m_useBinarySearch = settings.getBoolean("useBinarySearch", false);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataValue(org.knime.core.data.DataValue) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) NominalValue(org.knime.core.data.NominalValue) BoundedValue(org.knime.core.data.BoundedValue) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) IntValue(org.knime.core.data.IntValue)

Example 14 with DataValue

use of org.knime.core.data.DataValue in project knime-core by knime.

the class DataTypeNameRenderer method getListCellRendererComponent.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    /* Almost all has been copied from the super implementation */
    setComponentOrientation(list.getComponentOrientation());
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    if (value instanceof Class && DataValue.class.isAssignableFrom((Class) value)) {
        Class<? extends DataValue> type = (Class<? extends DataValue>) value;
        String s = type.getName();
        int dot = s.lastIndexOf('.');
        if (dot >= 0 && dot < s.length() - 1) {
            s = s.substring(dot + 1);
        }
        s = s.trim();
        UtilityFactory fac = DataType.getUtilityFor(type);
        Icon icon = fac.getIcon();
        setIcon(icon);
        setText(s);
    } else {
        if (value instanceof Icon) {
            setIcon((Icon) value);
            setText("");
        } else {
            setIcon(null);
            setText((value == null) ? "" : value.toString());
        }
    }
    setEnabled(list.isEnabled());
    setFont(list.getFont());
    setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
    return this;
}
Also used : UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) DataValue(org.knime.core.data.DataValue) Icon(javax.swing.Icon)

Example 15 with DataValue

use of org.knime.core.data.DataValue in project knime-core by knime.

the class RenameColumnSetting method configure.

/**
 * Called by configure in NodeModel to compute the new column spec.
 *
 * @param inSpec the original input spec (names must match)
 * @return the new column spec
 * @throws InvalidSettingsException if that fails
 */
public DataColumnSpec configure(final DataColumnSpec inSpec) throws InvalidSettingsException {
    String name = inSpec.getName();
    DataType oldType = inSpec.getType();
    if (!name.equals(m_name)) {
        throw new InvalidSettingsException("Column names don't match: \"" + m_name + "\" vs. \"" + name + "\"");
    }
    Set<Class<? extends DataValue>> possibleTypeSet = constructPossibleTypes(inSpec.getType());
    // no generics in array definition
    @SuppressWarnings("unchecked") Class<? extends DataValue>[] possibleTypes = possibleTypeSet.toArray(new Class[possibleTypeSet.size()]);
    if (getNewValueClassIndex() >= possibleTypes.length) {
        throw new InvalidSettingsException("Invalid type index: " + getNewValueClassIndex());
    }
    String newName = m_newColumnName == null ? m_name : m_newColumnName;
    Class<? extends DataValue> newVal = possibleTypes[getNewValueClassIndex()];
    boolean useToString = newVal.equals(StringValue.class) && // need to handled separately, bug #1939
    (DataType.getMissingCell().getType().equals(oldType) || !oldType.isCompatible(StringValue.class));
    DataColumnDomain newDomain;
    DataType newType;
    if (useToString) {
        newDomain = null;
        newType = StringCell.TYPE;
    } else {
        newDomain = inSpec.getDomain();
        Class<? extends DataValue> oldP = oldType.getPreferredValueClass();
        if (oldP.equals(newVal)) {
            newType = oldType;
        } else {
            newType = DataType.cloneChangePreferredValue(oldType, newVal);
        }
    }
    DataColumnSpecCreator creator = new DataColumnSpecCreator(inSpec);
    creator.setName(newName);
    creator.setType(newType);
    creator.setDomain(newDomain);
    return creator.createSpec();
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataValue(org.knime.core.data.DataValue) DataColumnDomain(org.knime.core.data.DataColumnDomain) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) StringValue(org.knime.core.data.StringValue)

Aggregations

DataValue (org.knime.core.data.DataValue)28 DataCell (org.knime.core.data.DataCell)9 DoubleValue (org.knime.core.data.DoubleValue)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 DataType (org.knime.core.data.DataType)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 StringCell (org.knime.core.data.def.StringCell)5 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4 DataRow (org.knime.core.data.DataRow)3 DefaultRow (org.knime.core.data.def.DefaultRow)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 FileInputStream (java.io.FileInputStream)2 JMenu (javax.swing.JMenu)2