use of org.knime.workbench.explorer.view.AbstractContentProvider.LinkType in project knime-core by knime.
the class ChangeSubNodeLinkAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
if (nodeParts.length < 1) {
return;
}
SubNodeContainer subNode = Wrapper.unwrap(nodeParts[0].getNodeContainer(), SubNodeContainer.class);
if (Role.Link.equals(subNode.getTemplateInformation().getRole())) {
WorkflowManager wfm = subNode.getParent();
URI targetURI = subNode.getTemplateInformation().getSourceURI();
LinkType linkType = LinkType.None;
try {
if (ResolverUtil.isMountpointRelativeURL(targetURI)) {
linkType = LinkType.MountpointRelative;
} else if (ResolverUtil.isWorkflowRelativeURL(targetURI)) {
linkType = LinkType.WorkflowRelative;
} else {
linkType = LinkType.Absolute;
}
} catch (IOException e) {
LOGGER.error("Unable to resolve current link to template " + targetURI + ": " + e.getMessage(), e);
return;
}
String msg = "This is a linked (read-only) Wrapped Metanode. Only the link type can be changed.\n";
msg += "Please select the new type of the link to the Wrapped Metanode template.\n";
msg += "(current type: " + linkType + ", current link: " + targetURI + ")\n";
msg += "The origin of the template will not be changed - just the way it is referenced.";
LinkPrompt dlg = new LinkPrompt(getEditor().getSite().getShell(), msg, linkType);
dlg.open();
if (dlg.getReturnCode() == Window.CANCEL) {
return;
}
LinkType newLinkType = dlg.getLinkType();
if (linkType.equals(newLinkType)) {
LOGGER.info("Link type not changes as selected type equals existing type " + targetURI);
return;
}
// as the workflow is local and the template in the same mountID, it should resolve to a file
URI newURI = null;
NodeContext.pushContext(subNode);
try {
File targetFile = ResolverUtil.resolveURItoLocalFile(targetURI);
LocalExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.fromLocalFile(targetFile);
newURI = AbstractContentProvider.createMetanodeLinkUri(subNode, targetfs, newLinkType);
} catch (IOException e) {
LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
return;
} catch (URISyntaxException e) {
LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
return;
} catch (CoreException e) {
LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
return;
} finally {
NodeContext.removeLastContext();
}
ChangeSubNodeLinkCommand cmd = new ChangeSubNodeLinkCommand(wfm, subNode, targetURI, newURI);
getCommandStack().execute(cmd);
} else {
throw new IllegalStateException("Can only change the type of a template link if the Wrapped Metanode is actually linked to a template - " + subNode + " is not.");
}
}
use of org.knime.workbench.explorer.view.AbstractContentProvider.LinkType in project knime-core by knime.
the class ChangeMetaNodeLinkAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
if (nodeParts.length < 1) {
return;
}
WorkflowManager metaNode = Wrapper.unwrapWFM(nodeParts[0].getNodeContainer());
if (Role.Link.equals(metaNode.getTemplateInformation().getRole())) {
WorkflowManager wfm = metaNode;
while (!wfm.isProject()) {
wfm = wfm.getParent();
}
URI targetURI = metaNode.getTemplateInformation().getSourceURI();
LinkType linkType = LinkType.None;
try {
if (ResolverUtil.isMountpointRelativeURL(targetURI)) {
linkType = LinkType.MountpointRelative;
} else if (ResolverUtil.isWorkflowRelativeURL(targetURI)) {
linkType = LinkType.WorkflowRelative;
} else {
linkType = LinkType.Absolute;
}
} catch (IOException e) {
LOGGER.error("Unable to resolve current link to template " + targetURI + ": " + e.getMessage(), e);
return;
}
String msg = "This is a linked (read-only) Metanode. Only the link type can be changed.\n";
msg += "Please select the new type of the link to the metanode template.\n";
msg += "(current type: " + linkType + ", current link: " + targetURI + ")\n";
msg += "The origin of the template will not be changed - just the way it is referenced.";
LinkPrompt dlg = new LinkPrompt(getEditor().getSite().getShell(), msg, linkType);
dlg.open();
if (dlg.getReturnCode() == Window.CANCEL) {
return;
}
LinkType newLinkType = dlg.getLinkType();
if (linkType.equals(newLinkType)) {
LOGGER.info("Link type not changes as selected type equals existing type " + targetURI);
return;
}
// as the workflow is local and the template in the same mountID, it should resolve to a file
URI newURI = null;
NodeContext.pushContext(metaNode);
try {
File targetFile = ResolverUtil.resolveURItoLocalFile(targetURI);
LocalExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.fromLocalFile(targetFile);
newURI = AbstractContentProvider.createMetanodeLinkUri(metaNode, targetfs, newLinkType);
} catch (IOException e) {
LOGGER.error("Unable to resolve metanode template URI " + targetURI + ": " + e.getMessage(), e);
return;
} catch (URISyntaxException e) {
LOGGER.error("Unable to resolve metanode template URI " + targetURI + ": " + e.getMessage(), e);
return;
} catch (CoreException e) {
LOGGER.error("Unable to resolve metanode template URI " + targetURI + ": " + e.getMessage(), e);
return;
} finally {
NodeContext.removeLastContext();
}
ChangeMetaNodeLinkCommand cmd = new ChangeMetaNodeLinkCommand(wfm, metaNode, targetURI, newURI);
getCommandStack().execute(cmd);
} else {
throw new IllegalStateException("Can only change the type of a template link if the metanode is actually linked to a template - " + metaNode + " is not.");
}
}
Aggregations