Handling knime URLs with DialogComponentFileChooser

Hi,

how can I correctly handle the knime URLs like
knime://LOCAL/workflow_group/test.xlsx
knime://knime.mountpoint/workflow_group/test.xlsx
in combination with the DialogComponentFileChooser component?

is there a good example workflow to check how to handle these URLs? :slight_smile:
->I write out the file selected by the user. Normal system paths in the user input work just fine - but for the knime urls i am not quite sure.

Thanks in advance!

@ScottF not quite sure about your shift from KNIME Development → Knime Analytics Platform… isn’t the Development forum for questions regarding the development of own nodes? :thinking:
Sorry if i missed something - but to be clear this is a question regarding the implementation of my own node :slight_smile:

i meant example node - not workflow :see_no_evil:

My mistake then, sorry - I was trying to get you more exposure since I thought it was a workflow related question. I’ve moved it back.

1 Like

(but re-reading my questions it sure wasn’t that clear it was about node development - thanks for looking out! :slight_smile: )

Hi @AnotherFraudUser,

with the new filehandling framework that we have stabilized with KNIME 4.3 we no longer encourage the use of knime:// urls, instead we recommend using the new Path variable/ cell type to define locations to read from/ write to.

For this you would be using the DialogComponentWriterFileChoser for write targets or the sister class DialogComponentReaderFileChooser.

best,
Gabriel

1 Like

Hi @gab1one,

thank you so much for your help! :slight_smile:

what would be the correct implementation of these dialogs?
(I could not find any easy to follow example :see_no_evil:)

E.g. while using the Example NumberFormatter Node I would do the following:

NodeModel:

public class NumberFormatterNodeModel extends NodeModel {

protected NumberFormatterNodeModel() {

	super(1, 1);
}

private static final String filePath = "filepath";

private final SettingsModelWriterFileChooser m_filePathSettings = createWriterFileChooserSettingsModel();
static SettingsModelWriterFileChooser createWriterFileChooserSettingsModel() {
	return new SettingsModelWriterFileChooser(filePath, null, "File System Connection", FilterMode.FILE, FileOverwritePolicy.FAIL,
            EnumSet.of(FileOverwritePolicy.FAIL, FileOverwritePolicy.OVERWRITE), new String[] { ".xlsx", ".xls", ".xlsm" });
}

Node Dialog:

public class NumberFormatterNodeDialog extends DefaultNodeSettingsPane {

protected NumberFormatterNodeDialog() {
    super();

    SettingsModelWriterFileChooser writerFileChooserModel =  NumberFormatterNodeModel.createWriterFileChooserSettingsModel();
    FlowVariableModel writeFlow =
            createFlowVariableModel(writerFileChooserModel.getKeysForFSLocation(), FSLocationVariableType.INSTANCE);
    
    addDialogComponent(new DialogComponentWriterFileChooser(writerFileChooserModel, "filewriter", writeFlow, FilterMode.FILE));

However I could not get the portsConfig / PortsConfiguration working in the SettingsModelWriterFileChooser (null seems not to be allowed) :frowning:
How would I set the ports config in the above example?

I looked into the POI Excel Writer Node - but could not figure out how to apply it to the basic NumberFormatter example

Hi @AnotherFraudUser,

You need to use the ConfigurableNodeFactory class and setup your node to have a dynamic filehandling port.

Take a look at these nodes for some inspiration, they do relatively simple things:
https://bitbucket.org/KNIME/knime-base/src/master/org.knime.filehandling.utility.nodes/src/org/knime/filehandling/utility/nodes/

best,
Gabriel

1 Like

Hi @gab1one,

thanks again - this worked :slight_smile:
However I changed it afterwards to a “SettingsModelFileChooser2”
(it seemed more intuitive - and hopefully needs less project changes to support older KNIME Verions…)
As the FileChooserHelper does exactly what I wanted to do :+1:

    final SettingsModelFileChooser2 outputFilePathModel2 = TemplateXLSXNodeModel.createOutputFilePath2SettingsModel();

    final FlowVariableModel tplfvm = createFlowVariableModel(
            new String[]{outputFilePathModel2.getConfigName(), 
   SettingsModelFileChooser2.PATH_OR_URL_KEY},
            Type.STRING);
    
    addDialogComponent(new DialogComponentFileChooser2(0, outputFilePathModel2, "XLSoutput",         JFileChooser.SAVE_DIALOG,
            JFileChooser.FILES_ONLY, tplfvm));
    FileChooserHelper fileHelperOutput = new FileChooserHelper(m_fs, m_outputfilePath2, defaulttimeoutInSeconds * 1000);
	Path pathOutput = fileHelperOutput.getPathFromSettings();
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.