Search in sources :

Example 11 with AbstractExplorerFileStore

use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore 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 12 with AbstractExplorerFileStore

use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.

the class SaveAsSubNodeTemplateAction method getDefaultSaveLocation.

private ContentObject getDefaultSaveLocation(final WorkflowManager arg) {
    final NodeID id = arg.getID();
    URI uri = DisconnectSubNodeLinkCommand.RECENTLY_USED_URIS.get(id);
    if (uri == null || !ExplorerFileSystem.SCHEME.equals(uri.getScheme())) {
        return null;
    }
    final AbstractExplorerFileStore oldTemplateFileStore = ExplorerFileSystem.INSTANCE.getStore(uri);
    final AbstractExplorerFileStore parent = oldTemplateFileStore == null ? null : oldTemplateFileStore.getParent();
    if (parent != null) {
        return ContentObject.forFile(parent);
    }
    return null;
}
Also used : AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) NodeID(org.knime.core.node.workflow.NodeID) URI(java.net.URI)

Example 13 with AbstractExplorerFileStore

use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore 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)

Example 14 with AbstractExplorerFileStore

use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.

the class IntroPage method newWorkflow.

private void newWorkflow() {
    ExplorerView explorerView = null;
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            for (IViewReference ref : page.getViewReferences()) {
                if (ExplorerView.ID.equals(ref.getId())) {
                    explorerView = (ExplorerView) ref.getPart(true);
                    break;
                }
            }
        }
    }
    Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    NewWorkflowWizard newWiz = new NewWorkflowWizard();
    newWiz.init(PlatformUI.getWorkbench(), null);
    WizardDialog dialog = new WizardDialog(shell, newWiz);
    dialog.create();
    dialog.getShell().setText("Create new workflow");
    dialog.getShell().setSize(Math.max(470, dialog.getShell().getSize().x), 350);
    int ok = dialog.open();
    if ((ok == Window.OK) && (explorerView != null)) {
        // update the tree
        IWizardPage currentPage = dialog.getCurrentPage();
        if (currentPage instanceof NewWorkflowWizardPage) {
            NewWorkflowWizardPage nwwp = (NewWorkflowWizardPage) currentPage;
            AbstractExplorerFileStore file = nwwp.getNewFile();
            Object p = ContentDelegator.getTreeObjectFor(file.getParent());
            explorerView.setNextSelection(file);
            explorerView.getViewer().refresh(p);
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) ExplorerView(org.knime.workbench.explorer.view.ExplorerView) NewWorkflowWizardPage(org.knime.workbench.explorer.view.actions.NewWorkflowWizardPage) NewWorkflowWizard(org.knime.workbench.explorer.view.actions.NewWorkflowWizard) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IWizardPage(org.eclipse.jface.wizard.IWizardPage) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 15 with AbstractExplorerFileStore

use of org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore in project knime-core by knime.

the class WorkflowEditor method dispose.

/**
 * Deregisters all listeners when the editor is disposed.
 *
 * @see org.eclipse.ui.IWorkbenchPart#dispose()
 */
@Override
public void dispose() {
    NodeLogger.getLogger(WorkflowEditor.class).debug("Disposing editor...");
    if (m_zoomWheelListener != null) {
        m_zoomWheelListener.dispose();
    }
    if (m_fileResource != null && m_manager != null) {
        // disposed is also called when workflow load fails or is canceled
        ProjectWorkflowMap.unregisterClientFrom(m_fileResource, this);
        // removes the workflow from memory
        ProjectWorkflowMap.remove(m_fileResource);
        if (isTempRemoteWorkflowEditor()) {
            // after the workflow is deleted we can delete the temp location
            final AbstractExplorerFileStore flowLoc = getFileStore(m_fileResource);
            if (flowLoc != null) {
                new Thread(() -> {
                    try {
                        m_workflowCanBeDeleted.acquire();
                        File d = flowLoc.toLocalFile();
                        if (d != null && d.exists()) {
                            FileUtils.deleteDirectory(d.getParentFile());
                        }
                    } catch (CoreException | IOException | InterruptedException e) {
                        LOGGER.warn("Error during deletion of temporary workflow location: " + e.getMessage(), e);
                    }
                }, "Delete temporary copy of " + m_origRemoteLocation).start();
            }
        }
    }
    final ReferencedFile autoSaveDirectory;
    if (m_manager != null && m_parentEditor == null && m_fileResource != null) {
        autoSaveDirectory = Wrapper.unwrapWFMOptional(m_manager).map(wfm -> wfm.getAutoSaveDirectory()).orElse(null);
    } else {
        autoSaveDirectory = null;
    }
    // remember that this editor has been closed
    m_closed = true;
    for (IEditorPart child : getSubEditors()) {
        child.getEditorSite().getPage().closeEditor(child, false);
    }
    NodeProvider.INSTANCE.removeListener(this);
    getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this);
    if (m_parentEditor != null && m_manager != null) {
        // Store the editor settings with the metanode
        if (getWorkflowManagerUI().isDirty()) {
            // doesn't persist settings to disk
            saveEditorSettingsToWorkflowManager();
        }
        // bug fix 2051: Possible memory leak related to sub-flow editor.
        // metanode editors were still referenced by the EditorHistory
        IWorkbench workbench = PlatformUI.getWorkbench();
        if (workbench instanceof Workbench) {
            EditorHistory hist = ((Workbench) workbench).getEditorHistory();
            WorkflowManagerInput wfmInput = new WorkflowManagerInput(m_manager, m_parentEditor);
            hist.remove(wfmInput);
        }
    }
    if (m_autoSaveJob != null) {
        m_autoSaveJob.cancel();
        m_autoSaveJob = null;
    }
    // unregisters wfm listeners
    setWorkflowManager(null);
    if (autoSaveDirectory != null) {
        KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Runnable() {

            @Override
            public void run() {
                LOGGER.debugWithFormat("Deleting auto-saved copy (\"%s\")...", autoSaveDirectory);
                try {
                    FileUtils.deleteDirectory(autoSaveDirectory.getFile());
                } catch (IOException e) {
                    LOGGER.error(String.format("Failed to delete auto-saved copy of workflow (folder \"%s\"): %s", autoSaveDirectory, e.getMessage()), e);
                }
            }
        });
    }
    getCommandStack().removeCommandStackListener(this);
    IPreferenceStore prefStore = KNIMEUIPlugin.getDefault().getPreferenceStore();
    prefStore.removePropertyChangeListener(this);
    super.dispose();
}
Also used : Workbench(org.eclipse.ui.internal.Workbench) IWorkbench(org.eclipse.ui.IWorkbench) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) IWorkbench(org.eclipse.ui.IWorkbench) EditorHistory(org.eclipse.ui.internal.EditorHistory) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Aggregations

AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)19 URI (java.net.URI)6 AbstractContentProvider (org.knime.workbench.explorer.view.AbstractContentProvider)6 CoreException (org.eclipse.core.runtime.CoreException)5 LocalExplorerFileStore (org.knime.workbench.explorer.filesystem.LocalExplorerFileStore)5 ArrayList (java.util.ArrayList)4 Shell (org.eclipse.swt.widgets.Shell)4 NodeID (org.knime.core.node.workflow.NodeID)4 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)4 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)4 ContentObject (org.knime.workbench.explorer.view.ContentObject)4 File (java.io.File)3 IOException (java.io.IOException)3 ReferencedFile (org.knime.core.internal.ReferencedFile)3 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)3 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)3 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)3 SpaceResourceSelectionDialog (org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog)3 AbstractExplorerFileInfo (org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo)3 RemoteExplorerFileStore (org.knime.workbench.explorer.filesystem.RemoteExplorerFileStore)3