Search in sources :

Example 1 with AbstractExplorerFileInfo

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Composite(org.eclipse.swt.widgets.Composite) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) SnapshotPanel(org.knime.workbench.explorer.view.dialogs.SnapshotPanel) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) CoreException(org.eclipse.core.runtime.CoreException) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractExplorerFileInfo(org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) RemoteExplorerFileStore(org.knime.workbench.explorer.filesystem.RemoteExplorerFileStore)

Example 2 with AbstractExplorerFileInfo

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);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) ContentObject(org.knime.workbench.explorer.view.ContentObject) Shell(org.eclipse.swt.widgets.Shell) SpaceResourceSelectionDialog(org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) AbstractExplorerFileInfo(org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo) Map(java.util.Map) Validator(org.knime.workbench.explorer.dialogs.Validator)

Example 3 with AbstractExplorerFileInfo

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);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) ContentObject(org.knime.workbench.explorer.view.ContentObject) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Shell(org.eclipse.swt.widgets.Shell) SpaceResourceSelectionDialog(org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) AbstractExplorerFileInfo(org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo) Map(java.util.Map) Validator(org.knime.workbench.explorer.dialogs.Validator)

Aggregations

AbstractExplorerFileInfo (org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo)3 AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Shell (org.eclipse.swt.widgets.Shell)2 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)2 SpaceResourceSelectionDialog (org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog)2 Validator (org.knime.workbench.explorer.dialogs.Validator)2 AbstractContentProvider (org.knime.workbench.explorer.view.AbstractContentProvider)2 ContentObject (org.knime.workbench.explorer.view.ContentObject)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Point (org.eclipse.draw2d.geometry.Point)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 Composite (org.eclipse.swt.widgets.Composite)1 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)1 LocalExplorerFileStore (org.knime.workbench.explorer.filesystem.LocalExplorerFileStore)1 RemoteExplorerFileStore (org.knime.workbench.explorer.filesystem.RemoteExplorerFileStore)1