use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo in project knime-core by knime.
the class WorkflowEditor method saveBackToServer.
private void saveBackToServer() {
if (m_parentEditor != null) {
// parent does it if this is a metanode editor
m_parentEditor.saveBackToServer();
return;
}
assert m_origRemoteLocation != null : "No remote workflow";
AbstractExplorerFileStore remoteStore = ExplorerFileSystem.INSTANCE.getStore(m_origRemoteLocation);
AbstractExplorerFileInfo fetchInfo = remoteStore.fetchInfo();
if (fetchInfo.exists()) {
if (!fetchInfo.isModifiable()) {
MessageDialog.openError(getSite().getShell(), "Workflow not writable", "You don't have permissions to overwrite the workflow. Use \"Save As...\" in order to save it to " + "a different location.");
return;
}
boolean snapshotSupported = remoteStore.getContentProvider().supportsSnapshots();
final AtomicReference<SnapshotPanel> snapshotPanel = new AtomicReference<SnapshotPanel>(null);
MessageDialog dlg = new MessageDialog(getSite().getShell(), "Overwrite on server?", null, "The workflow\n\n\t" + remoteStore.getMountIDWithFullPath() + "\n\nalready exists on the server. Do you want to overwrite it?\n", MessageDialog.QUESTION, new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL }, 1) {
/**
* {@inheritDoc}
*/
@Override
protected Control createCustomArea(final Composite parent) {
if (snapshotSupported) {
snapshotPanel.set(new SnapshotPanel(parent, SWT.NONE));
snapshotPanel.get().setEnabled(true);
return snapshotPanel.get();
} else {
return null;
}
}
};
int dlgResult = dlg.open();
if (dlgResult != 1) {
return;
}
if ((snapshotPanel.get() != null) && (snapshotPanel.get().createSnapshot())) {
try {
((RemoteExplorerFileStore) remoteStore).createSnapshot(snapshotPanel.get().getComment());
} catch (CoreException e) {
String msg = "Unable to create snapshot before overwriting the workflow:\n" + e.getMessage() + "\n\nUpload was canceled.";
LOGGER.error("Unable to create snapshot before overwriting the workflow: " + e.getMessage() + " Upload was canceled.", e);
MessageDialog.openError(getSite().getShell(), "Server Error", msg);
return;
}
}
} else if (!remoteStore.getParent().fetchInfo().isModifiable()) {
MessageDialog.openError(getSite().getShell(), "Workflow not writable", "You don't have permissions to write into the workflow's parent folder. Use \"Save As...\" in order to" + " save it to a different location.");
return;
}
// selected a remote location: save + upload
if (isDirty()) {
saveTo(m_fileResource, new NullProgressMonitor(), true, null);
}
AbstractExplorerFileStore localFS = getFileStore(m_fileResource);
if ((localFS == null) || !(localFS instanceof LocalExplorerFileStore)) {
LOGGER.error("Unable to resolve current workflow location. Workflow not uploaded!");
return;
}
try {
m_workflowCanBeDeleted.acquire();
remoteStore.getContentProvider().performUploadAsync((LocalExplorerFileStore) localFS, (RemoteExplorerFileStore) remoteStore, /*deleteSource=*/
false, false, t -> m_workflowCanBeDeleted.release());
} catch (CoreException | InterruptedException e) {
String msg = "Failed to upload the workflow to its remote location\n(" + e.getMessage() + ")";
LOGGER.error(msg, e);
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Upload failed.", msg);
}
}
use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo in project knime-core by knime.
the class SaveAsMetaNodeTemplateAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
if (nodes.length < 1) {
return;
}
WorkflowManager wm = Wrapper.unwrapWFM(nodes[0].getNodeContainer());
List<String> validMountPointList = new ArrayList<String>();
// Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().findView(ID)
for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
AbstractContentProvider contentProvider = entry.getValue();
if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
validMountPointList.add(entry.getKey());
}
}
if (validMountPointList.isEmpty()) {
throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
}
String[] validMountPoints = validMountPointList.toArray(new String[0]);
final Shell shell = Display.getCurrent().getActiveShell();
ContentObject defSel = getDefaultSaveLocation(wm);
SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
dialog.setTitle("Save As Metanode Template");
dialog.setHeader("Select destination workflow group for metanode template");
dialog.setValidator(new Validator() {
@Override
public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
final AbstractExplorerFileInfo info = selection.fetchInfo();
if (info.isWorkflowGroup()) {
return null;
}
return "Only workflow groups can be selected as target.";
}
});
if (dialog.open() != Window.OK) {
return;
}
AbstractExplorerFileStore target = dialog.getSelection();
AbstractContentProvider contentProvider = target.getContentProvider();
contentProvider.saveMetaNodeTemplate(wm, target);
}
use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo in project knime-core by knime.
the class SaveAsSubNodeTemplateAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
if (nodes.length < 1) {
return;
}
SubNodeContainer snc = unwrap(nodes[0].getNodeContainer(), SubNodeContainer.class);
WorkflowManager wm = snc.getWorkflowManager();
List<String> validMountPointList = new ArrayList<String>();
for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
AbstractContentProvider contentProvider = entry.getValue();
if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
validMountPointList.add(entry.getKey());
}
}
if (validMountPointList.isEmpty()) {
throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
}
String[] validMountPoints = validMountPointList.toArray(new String[0]);
final Shell shell = Display.getCurrent().getActiveShell();
ContentObject defSel = getDefaultSaveLocation(wm);
SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
dialog.setTitle("Save As Wrapped Metanode Template");
dialog.setHeader("Select destination workflow group for Wrapped Metanode template");
dialog.setValidator(new Validator() {
@Override
public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
final AbstractExplorerFileInfo info = selection.fetchInfo();
if (info.isWorkflowGroup()) {
return null;
}
return "Only workflow groups can be selected as target.";
}
});
if (dialog.open() != Window.OK) {
return;
}
AbstractExplorerFileStore target = dialog.getSelection();
AbstractContentProvider contentProvider = target.getContentProvider();
contentProvider.saveSubNodeTemplate(snc, target);
}
Aggregations