Search in sources :

Example 1 with ComponentMetadataBuilder

use of org.knime.core.node.workflow.ComponentMetadata.ComponentMetadataBuilder in project knime-core by knime.

the class SubNodeContainer method loadLegacyPortNamesAndDescriptionsFromInOutNodes.

@SuppressWarnings("deprecation")
private void loadLegacyPortNamesAndDescriptionsFromInOutNodes() {
    LoadVersion loadVersion = getWorkflowManager().getLoadVersion();
    if ((m_metadata == null || m_metadata == ComponentMetadata.NONE) && loadVersion != null && loadVersion.isOlderThan(LoadVersion.V4010)) {
        // take node description from virtual input node
        ComponentMetadataBuilder builder = ComponentMetadata.builder();
        builder.description(getVirtualInNodeModel().getSubNodeDescription());
        String[] inPortNames;
        String[] inPortDescriptions;
        String[] outPortNames;
        String[] outPortDescriptions;
        // take port descriptions from virtual input node
        inPortNames = getVirtualInNodeModel().getPortNames();
        inPortDescriptions = getVirtualInNodeModel().getPortDescriptions();
        for (int i = 0; i < inPortNames.length; i++) {
            builder.addInPortNameAndDescription(inPortNames[i], inPortDescriptions[i]);
        }
        // take port descriptions from virtual output node
        outPortNames = getVirtualOutNodeModel().getPortNames();
        outPortDescriptions = getVirtualOutNodeModel().getPortDescriptions();
        for (int i = 0; i < outPortNames.length; i++) {
            builder.addOutPortNameAndDescription(outPortNames[i], outPortDescriptions[i]);
        }
        m_metadata = builder.build();
    }
}
Also used : ComponentMetadataBuilder(org.knime.core.node.workflow.ComponentMetadata.ComponentMetadataBuilder) LoadVersion(org.knime.core.util.LoadVersion)

Example 2 with ComponentMetadataBuilder

use of org.knime.core.node.workflow.ComponentMetadata.ComponentMetadataBuilder in project knime-core by knime.

the class SubNodeContainer method syncNrPortsWithMetadata.

private void syncNrPortsWithMetadata() {
    /* sync number of port names/descriptions with the actual ports number -> fill or cut-off */
    int nrInPorts = getNrInPorts() - 1;
    ComponentMetadataBuilder builder = null;
    if (m_metadata.getInPortNames().isPresent() && m_metadata.getInPortNames().get().length != nrInPorts) {
        String[] portNames = m_metadata.getInPortNames().get();
        int orgLength = portNames.length;
        String[] portDescriptions = m_metadata.getInPortDescriptions().get();
        portNames = Arrays.copyOf(portNames, nrInPorts);
        portDescriptions = Arrays.copyOf(portDescriptions, nrInPorts);
        for (int i = orgLength; i < nrInPorts; i++) {
            portNames[i] = "Port " + (i + 1);
            portDescriptions[i] = "";
        }
        builder = getOrCreate(builder);
        builder.clearInPorts();
        for (int i = 0; i < portNames.length; i++) {
            builder.addInPortNameAndDescription(portNames[i], portDescriptions[i]);
        }
    }
    int nrOutPorts = getNrOutPorts() - 1;
    if (m_metadata.getOutPortNames().isPresent() && m_metadata.getOutPortNames().get().length != nrOutPorts) {
        String[] portNames = m_metadata.getOutPortNames().get();
        int orgLength = portNames.length;
        String[] portDescriptions = m_metadata.getOutPortDescriptions().get();
        portNames = Arrays.copyOf(portNames, nrOutPorts);
        portDescriptions = Arrays.copyOf(portDescriptions, nrOutPorts);
        for (int i = orgLength; i < nrOutPorts; i++) {
            portNames[i] = "Port " + (i + 1);
            portDescriptions[i] = "";
        }
        builder = getOrCreate(builder);
        builder.clearOutPorts();
        for (int i = 0; i < portNames.length; i++) {
            builder.addOutPortNameAndDescription(portNames[i], portDescriptions[i]);
        }
    }
    if (builder != null) {
        m_metadata = builder.build();
    }
}
Also used : ComponentMetadataBuilder(org.knime.core.node.workflow.ComponentMetadata.ComponentMetadataBuilder)

Aggregations

ComponentMetadataBuilder (org.knime.core.node.workflow.ComponentMetadata.ComponentMetadataBuilder)2 LoadVersion (org.knime.core.util.LoadVersion)1