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.
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.
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
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.
I tried it with
ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
but that is not what I want.
Regards,
Aymen
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
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
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
Thank you very much.
It works