Getting PortObject and PortObjectSpec simultaneously in Node Dialog

Dear KNIME developers.
 
I'm actively working with KNIME SDK and I'm developing lot of custom nodes at the moment.
 
Currently I'm developing Node Dialog and I want to have access to input data table specs and input data itself.

Unfortunately, It's quite hard to get specs and input data together.

I've decided to open up source code and verify how It's possible to get both arrays of objects.

Base class NodeDialogPane has method which configures specs looks following:

    void callDerivedLoadSettingsFrom(final NodeSettingsRO settings,
            final PortObjectSpec[] specs, final PortObject[] data)
    throws NotConfigurableException {
        NodeContext.pushContext(m_nodeContext);
        try {
            loadSettingsFrom(settings, specs);
        } finally {
            NodeContext.removeLastContext();
        }
    }

Class DataAwareNodeDialogPane add ability to get data from input table. It extends previous one and looks following.

 void callDerivedLoadSettingsFrom(final NodeSettingsRO settings,
            final PortObjectSpec[] specs, final PortObject[] data)
            throws NotConfigurableException {
        boolean someDataAvailable = false;
        for (int i = 0; data != null && i < data.length; i++) {
            if (data[i] != null) {
                someDataAvailable = true;
            }
        }
        if (someDataAvailable) {
            loadSettingsFrom(settings, data);
        } else {
            loadSettingsFrom(settings, specs);
        }
    }

But It actually not really what I need. I would like to have something like

    void callDerivedLoadSettingsFrom(final NodeSettingsRO settings,
            final PortObjectSpec[] specs, final PortObject[] data)
            throws NotConfigurableException {
			
        loadSettingsFrom(settings, data);
        loadSettingsFrom(settings, specs);
    }

This code will load settings for date and specs.
    
But, unfortunately, I can't override this method because It has package modifier. Moreover, If I add in my project custom class with same package name (org.knime.core.node) and extend this method It won't help.

So, I have next question for all of you.

1. Is there any simple way how to get input table data and specs in Node Dialog simultaneously?
2. Is it possible to override callDerivedLoadSettingsFrom or Is there any possibility to make it at least protected in next KNIME releases?

Thanks in advance for your help.
 
Regards,
Roman

1 Like

Every PortObject gives you its spec. Just call getSpec() and then you have the desired information.

@thor Thank you for your hint. I've just resolved It by providing next code.

/**
     * {@inheritDoc}
     */
   @Override
   protected void loadSettingsFrom(final NodeSettingsRO settings,
            final PortObject[] input) throws NotConfigurableException {
   		
   		this.inputTable = input;
   		
   		final PortObjectSpec[] specs = new PortObjectSpec[input.length];
   		
   		for (int counter = 0; counter < input.length; ++counter) {
   			
   			specs[counter] = input[counter].getSpec();
   		}
   		
   		this.loadSettingsFrom(settings, specs);
   		
    }

Anyway, for me It's still unclear why do we need te send both PortObject[] and PortObjectSpec[] in callDerivedLoadSettingsFrom method. But, fortunately you'r hint was helpful.

Thanks again.