use of org.knime.workbench.explorer.view.dialogs.SnapshotPanel 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.view.dialogs.SnapshotPanel in project knime-core by knime.
the class WorkflowEditor method getNewLocation.
/**
* For SaveAs...
* @param currentLocation
* @param allowRemoteLocation local and remote mount points are added to the selection dialog
* @return new (different!) URI or null if user canceled. Caller should create a snapshot if told so.
*/
private OverwriteAndMergeInfo getNewLocation(final URI currentLocation, final boolean allowRemoteLocation) {
final AbstractExplorerFileStore currentStore = getFileStore(currentLocation);
AbstractExplorerFileStore currentParent = null;
if (currentStore != null) {
currentParent = currentStore.getParent();
}
String currentName = new Path(currentLocation.getPath()).lastSegment();
List<String> selIDs = new LinkedList<String>();
for (String id : ExplorerMountTable.getAllVisibleMountIDs()) {
AbstractContentProvider provider = ExplorerMountTable.getMountPoint(id).getProvider();
if (!provider.isRemote() || (allowRemoteLocation && provider.isWritable())) {
selIDs.add(id);
}
}
ContentObject preSel = ContentObject.forFile(currentParent);
if (isTempRemoteWorkflowEditor()) {
AbstractExplorerFileStore remoteStore = null;
try {
remoteStore = ExplorerFileSystem.INSTANCE.getStore(m_origRemoteLocation);
} catch (IllegalArgumentException e) {
/* don't preselect on unknown original location */
}
if (remoteStore != null) {
preSel = ContentObject.forFile(remoteStore);
} else {
preSel = null;
}
}
OverwriteAndMergeInfo result = null;
while (result == null) {
// keep the selection dialog open until we get a useful result
final SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(getSite().getShell(), selIDs.toArray(new String[selIDs.size()]), preSel);
SaveAsValidator validator = new SaveAsValidator(dialog, currentStore);
String defName = currentName + " - Copy";
if (!isTempRemoteWorkflowEditor()) {
if (currentParent != null) {
try {
Set<String> childs = new HashSet<String>(Arrays.asList(currentParent.childNames(EFS.NONE, null)));
defName = guessNewWorkflowNameOnSaveAs(childs, currentName);
} catch (CoreException e1) {
// keep the simple default
}
}
} else {
defName = currentName;
if (defName.endsWith("." + KNIMEConstants.KNIME_WORKFLOW_FILE_EXTENSION)) {
defName = defName.substring(0, defName.length() - KNIMEConstants.KNIME_WORKFLOW_FILE_EXTENSION.length() - 1);
}
}
dialog.setTitle("Save to new Location");
dialog.setDescription("Select the new destination workflow group for the workflow.");
dialog.setValidator(validator);
// Setup the name field of the dialog
dialog.setNameFieldEnabled(true);
dialog.setNameFieldDefaultValue(defName);
final AtomicBoolean proceed = new AtomicBoolean(false);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
proceed.set(dialog.open() == Window.OK);
}
});
if (!proceed.get()) {
return null;
}
AbstractExplorerFileStore newLocation = dialog.getSelection();
if (newLocation.fetchInfo().isWorkflowGroup()) {
newLocation = newLocation.getChild(dialog.getNameFieldValue());
} else {
// in case they have selected a flow but changed the name in the name field afterwards
newLocation = newLocation.getParent().getChild(dialog.getNameFieldValue());
}
assert !newLocation.fetchInfo().exists() || newLocation.fetchInfo().isWorkflow();
if (newLocation.fetchInfo().exists()) {
// confirm overwrite (with snapshot?)
final AtomicBoolean snapshotSupported = new AtomicBoolean(false);
final AtomicReference<SnapshotPanel> snapshotPanel = new AtomicReference<SnapshotPanel>(null);
if (newLocation.getContentProvider().supportsSnapshots() && (newLocation instanceof RemoteExplorerFileStore)) {
snapshotSupported.set(true);
}
MessageDialog dlg = new MessageDialog(getSite().getShell(), "Confirm SaveAs Overwrite", null, "The selected destination\n\n\t" + newLocation.getMountIDWithFullPath() + "\n\nalready exists. Do you want to overwrite?\n", MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 1) {
/**
* {@inheritDoc}
*/
@Override
protected Control createCustomArea(final Composite parent) {
if (snapshotSupported.get()) {
snapshotPanel.set(new SnapshotPanel(parent, SWT.NONE));
snapshotPanel.get().setEnabled(true);
return snapshotPanel.get();
} else {
return null;
}
}
};
int dlgResult = dlg.open();
if (dlgResult == 2) /* CANCEL */
{
return null;
}
if (dlgResult == 0) {
/* YES (= please overwrite) */
if (snapshotPanel.get() != null) {
SnapshotPanel snapPanel = snapshotPanel.get();
result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, true, snapPanel.createSnapshot(), snapPanel.getComment());
} else {
result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, true, false, "");
}
} else {
/* NO, don't overwrite: continue while loop asking for a different location */
preSel = ContentObject.forFile(newLocation);
currentName = newLocation.getName();
}
} else {
result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, false, false, "");
}
}
/* end of while (result != null) keep the target selection dialog open */
return result;
}
Aggregations