How to refresh Knime explorer ? How to get the absolute URL of the workflow ?

#1

Hi,

I want to refresh my knime explorer after exucuting my coded node. Does anyone know, how it works ?
I want to come out with the location of my workflow (by code). Any ideas ?

Thank you.

0 Likes

#2

Hi,

may I ask what your node is going to do?
It is a bad idea that the node triggers a refresh of the KNIME Explorer, especially as your node might run on KNIME Server.
I assume that you want to write a file directly into the workspace and show it in the explorer, is that right? In that case I would maybe use/support the knime://-URL scheme, where people can provide the path depending on the mount point (knime://knime.mountpoint/, knime://LOCAL/) or workflow (knime://knime.workflow/). This should be a better option as this scheme is independent of the workflow execution (server or Analytics Platform). For that you can use the helper class org.knime.core.util.FileUtil#getFileFromURL(URL).
If you have a look at our writer nodes you will notice that we also don’t refresh the explorer after execution and leave it up to the user.

However, if you really want to do it because of some reason you could do something like:

org.knime.workbench.explorer.ExplorerMountTable.getMountedContent().get("LOCAL").refresh();

Keep in mind that if something changes in the explorer (e.g. potential renaming of the mount id – even though it is fixed) that this might break your code.

Concerning your second question the path of your workflow at execution might not be the path of your workflow in KNIME Explorer. This is again dependent on where you execute the workflow - KNIME Server or Analytics Platform. However, you might overcome some of that using the knime://-URL.

Cheers,
Moritz

2 Likes

#3

Hi,
thank you for your reply.
Well guessed. Ok I will try it out with org.knime.core.util.FileUtil.getFileFromURL(URL).
Concerning the second question, I think it was badly asked. Actually what I want to come out with is the same result of what the explorer browser do. image
I tried it with

ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
but that is not what I want.

Regards,

Aymen

0 Likes

#4

Hi,

again, I think the best solution for that is actually the aforementioned FileUtil as you could use ‘knime://knime.workflow/’ and simply check the path of the returned file, which is equal to the current location (incl. name) of your workflow.

Cheers,
Moritz

0 Likes

#5

unfortunately it didn’t work out.
I tried it with

File workingDir1 = new File( “knime://knime.workflow/”);
System.out.println(org.knime.core.util.FileUtil.getFileFromURL(workingDir1.toURL()));

And I have got

C:\Users\myName\Desktop\eclipse-rcp-2018-12-R-win32-x86_64\eclipse\knime:\knime.workflow

Which is not true (correct loc is C:\Users\myName\runtime-KNIME\Repositories\mynewproject.git\workflows\xD)
Do you have any idea, why it didn´t work ?

Regards,

Aymen

0 Likes

#6

Hi,

you should do

org.knime.core.util.FileUtil.getFileFromURL(new URL(“knime://knime.workflow/”));

as new File(“knime://knime.workflow/”) uses the passed String as a path and simply appends it to the current path (hence why you get this weird output).

Cheers,
Moritz

3 Likes

#7

Thank you very much.
It works :smiley::smiley:

1 Like