use of org.knime.workbench.ui.navigator.actions.MoveWorkflowAction in project knime-core by knime.
the class WorkflowMoveDropListener method performDrop.
/**
* {@inheritDoc}
*/
@Override
public boolean performDrop(final Object data) {
Object t = getCurrentTarget();
IPath targetPath = null;
if ((t instanceof IResource) && !(t instanceof IWorkspaceRoot)) {
IResource r = (IResource) t;
if (!(r instanceof IFolder || r instanceof IProject)) {
return false;
} else {
// the target must not be a node
if (isNode(r)) {
return false;
}
}
targetPath = r.getFullPath();
} else if (t == null) {
// no drop target selected: drop it in the root.
targetPath = new Path("/");
}
if (data instanceof IResource[]) {
// move should only allow drops on groups
if (isWorkflow(ResourcesPlugin.getWorkspace().getRoot().findMember(targetPath))) {
return false;
}
// thats a move of workflows/groups inside the navigator
// (ResourceTransfer)
// elements to move are in a sorted map to move short paths first
TreeSet<IPath> moves = new TreeSet<IPath>(new Comparator<IPath>() {
public int compare(final IPath o1, final IPath o2) {
if (o1.segmentCount() < o2.segmentCount()) {
return -1;
}
if (o2.segmentCount() > o1.segmentCount()) {
return 1;
}
// returning 0 prevents items from being added!!!!
return o1.equals(o2) ? 0 : 1;
}
});
IResource[] selections = (IResource[]) data;
boolean showOpenFlowError = false;
for (IResource source : selections) {
// move only workflows and groups - ignore the rest.
if (source instanceof IFolder || source instanceof IProject) {
if (KnimeResourceUtil.isOpenedWorkflow(source)) {
// can't move currently open flows - fail
showOpenFlowError = true;
break;
}
if (isNode(source)) {
// ignore selected nodes
continue;
}
moves.add(source.getFullPath());
}
}
if (showOpenFlowError) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Open Workflow(s)", "Workflows currently opened in an editor can't " + "be moved\nPlease save and close the open " + "workflow editor(s) and try again.");
return false;
}
if (selections.length > 0 && moves.size() == 0) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Move Error", "Only workflows and workflow groups can be moved.");
return false;
}
for (IPath src : moves) {
// not existing paths (already moved ones) are ignored
new MoveWorkflowAction(src, targetPath).run();
}
getViewer().setSelection(new StructuredSelection(moves.iterator().next()), true);
}
if (data instanceof URI[]) {
// thats an import of a remote workflow in a zip archive file
// (RemoteFileTransfer)
URI[] uriData = (URI[]) data;
// we should accept drops on workflow groups only
IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(targetPath);
assert r != null;
assert (r instanceof IWorkspaceRoot) || KnimeResourceUtil.isWorkflowGroup(r) || KnimeResourceUtil.isWorkflow(r);
IPath newWF;
String wfSimplename = new Path(uriData[0].getPath()).lastSegment();
if (KnimeResourceUtil.isWorkflow(r)) {
// if dropped on a workflow we store it in the parent group
newWF = targetPath.removeLastSegments(1).append(wfSimplename);
} else {
// add the workflow name to the target path
newWF = targetPath.append(wfSimplename);
}
IResource newWFres = ResourcesPlugin.getWorkspace().getRoot().findMember(newWF);
if (newWFres != null) {
// ask if we are about to overwrite
String msg;
String[] labels;
int defaultIdx;
int dlgType;
assert KnimeResourceUtil.isWorkflow(newWFres);
IPath renamedFlow = createNewName(newWF);
if (!KnimeResourceUtil.isDirtyWorkflow(newWFres)) {
labels = new String[] { "Overwrite", "New Name", "Cancel" };
defaultIdx = 0;
msg = "The target workflow exists\n\t'" + newWF.toString() + "'.\n\nPlease select:\n" + "\n- \"Overwrite\" to replace the " + "existing with the downloaded flow\n" + "\n- \"New Name\" to save downloaded " + "flow with a new name '" + renamedFlow.lastSegment() + "'\n" + "\n- \"Cancel\" to abort the download of " + "the flow";
dlgType = MessageDialog.QUESTION;
} else {
labels = new String[] { "Discard and Overwrite", "New Name", "Cancel" };
defaultIdx = 1;
msg = "The target workflow exists\n\t'" + newWF.toString() + "'\n and is modified in an editor!\n\n" + "Please select:\n" + "\n- \"Discard and Overwrite\" to discard" + " your changes and replace the existing" + " flow with the downloaded one\n" + "\n- \"New Name\" to save downloaded " + "flow with a new name '" + renamedFlow.lastSegment() + "'\n" + "\n- \"Cancel\" to abort the download of " + "the flow";
dlgType = MessageDialog.WARNING;
}
MessageDialog md = new MessageDialog(Display.getDefault().getActiveShell(), "Confirm Overwrite", null, msg, dlgType, labels, defaultIdx);
int result = md.open();
if (result != 0 && result != 1) {
// do not overwrite and do not save with new name: Cancel.
return true;
}
if (result == 1) {
// save with new name
newWF = renamedFlow;
newWFres = ResourcesPlugin.getWorkspace().getRoot().findMember(newWF);
}
}
// let the target download the flow now
String[] fileNames = RemoteFileTransfer.getInstance().requestFileContent((URI[]) data);
if (fileNames.length != 1) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Drop Error", "Only one remote workflow can be dropped at a time.");
return false;
}
IResource wf = KnimeResourceUtil.importZipFileAsWorkflow(Display.getDefault().getActiveShell(), newWF, new File(fileNames[0]));
KnimeResourceUtil.revealInNavigator(wf, true);
return true;
}
// We support RemoteFileTransfer and ResourceTransfer only
return false;
}
use of org.knime.workbench.ui.navigator.actions.MoveWorkflowAction in project knime-core by knime.
the class KnimeResourceNavigator method fillContextMenu.
/**
* Fills the context menu with the actions contained in this group and its
* subgroups. Additionally the close project item is removed as not intended
* for the knime projects. Note: Projects which are closed in the default
* navigator are not shown in the knime navigator any more.
*
* @param menu the context menu
*/
@Override
public void fillContextMenu(final IMenuManager menu) {
// fill the menu
super.fillContextMenu(menu);
// remove the close project item
menu.remove(CloseResourceAction.ID);
// items do not have an id
for (IContributionItem item : menu.getItems()) {
if (item instanceof ActionContributionItem) {
ActionContributionItem aItem = (ActionContributionItem) item;
// remove the gointo item
if (aItem.getAction() instanceof GoIntoAction) {
menu.remove(aItem);
} else if (aItem.getAction() instanceof OpenInNewWindowAction) {
menu.remove(aItem);
} else if (aItem.getAction() instanceof CloseUnrelatedProjectsAction) {
menu.remove(aItem);
}
}
}
// move must be our own action (due to workflow locks)
if (menu.find(MoveResourceAction.ID) != null) {
menu.insertBefore(MoveResourceAction.ID, new MoveWorkflowAction(getTreeViewer()));
menu.remove(MoveResourceAction.ID);
}
// remove the default import export actions to store the own one
// that invokes the knime export wizard directly
menu.remove("import");
menu.insertBefore("export", new ImportKnimeWorkflowAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()));
menu.remove("export");
menu.insertAfter(ImportKnimeWorkflowAction.ID, new ExportKnimeWorkflowAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()));
String id = ImportKnimeWorkflowAction.ID;
// add an open action which is not listed as the project is normally
// not openable.
menu.insertBefore(id, new Separator());
menu.insertBefore(id, new OpenKnimeProjectAction(this));
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new EditMetaInfoAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
if (NodeExecutionJobManagerPool.getNumberOfJobManagersFactories() > 1) {
menu.insertAfter(ExportKnimeWorkflowAction.ID, new WFShowJobMgrViewAction());
}
menu.insertAfter(ExportKnimeWorkflowAction.ID, new ResetWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new CancelWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new ExecuteWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new ConfigureWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new OpenCredentialVariablesDialogAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new OpenWorkflowVariablesDialogAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
menu.insertBefore(RefreshAction.ID, new GroupMarker(KNIME_ADDITIONS));
menu.insertBefore(RefreshAction.ID, new Separator());
menu.insertBefore(id, new Separator());
// another bad workaround to replace the first "New" menu manager
// with the "Create New Workflow" action
// store all items, remove all, add the action and then
// add all but the first one
IContributionItem[] items = menu.getItems();
for (IContributionItem item : items) {
menu.remove(item);
}
menu.add(new NewKnimeWorkflowAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()));
menu.add(new CreateWorkflowGroupAction());
for (int i = 1; i < items.length; i++) {
menu.add(items[i]);
}
}
Aggregations