Search in sources :

Example 1 with ExplorerView

use of org.knime.workbench.explorer.view.ExplorerView in project knime-core by knime.

the class RevealSubNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    List<NodeID> candidateList = new ArrayList<NodeID>();
    List<AbstractExplorerFileStore> templates = new ArrayList<AbstractExplorerFileStore>();
    for (NodeContainerEditPart p : nodes) {
        Object model = p.getModel();
        if (wraps(model, SubNodeContainer.class)) {
            NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
            try {
                SubNodeContainer snc = unwrap((UI) model, SubNodeContainer.class);
                MetaNodeTemplateInformation i = snc.getTemplateInformation();
                if (Role.Link.equals(i.getRole())) {
                    candidateList.add(snc.getID());
                    AbstractExplorerFileStore template = ExplorerFileSystem.INSTANCE.getStore(i.getSourceURI());
                    if (template != null) {
                        templates.add(template);
                    }
                }
            } finally {
                NodeContext.removeLastContext();
            }
        }
    }
    List<Object> treeObjects = ContentDelegator.getTreeObjectList(templates);
    if (treeObjects != null && treeObjects.size() > 0) {
        IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
        for (IViewReference view : views) {
            if (ExplorerView.ID.equals(view.getId())) {
                ExplorerView explorerView = (ExplorerView) view.getView(true);
                explorerView.getViewer().setSelection(new StructuredSelection(treeObjects), true);
            }
        }
    }
}
Also used : ExplorerView(org.knime.workbench.explorer.view.ExplorerView) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IViewReference(org.eclipse.ui.IViewReference) NodeID(org.knime.core.node.workflow.NodeID) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 2 with ExplorerView

use of org.knime.workbench.explorer.view.ExplorerView 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 3 with ExplorerView

use of org.knime.workbench.explorer.view.ExplorerView in project knime-core by knime.

the class RevealMetaNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    List<NodeID> candidateList = new ArrayList<NodeID>();
    List<AbstractExplorerFileStore> templates = new ArrayList<AbstractExplorerFileStore>();
    for (NodeContainerEditPart p : nodes) {
        Object model = p.getModel();
        if (model instanceof WorkflowManagerUI) {
            NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
            try {
                WorkflowManager wm = Wrapper.unwrapWFM((UI) model);
                MetaNodeTemplateInformation i = wm.getTemplateInformation();
                if (Role.Link.equals(i.getRole())) {
                    candidateList.add(wm.getID());
                    AbstractExplorerFileStore template = ExplorerFileSystem.INSTANCE.getStore(i.getSourceURI());
                    if (template != null) {
                        templates.add(template);
                    }
                }
            } finally {
                NodeContext.removeLastContext();
            }
        }
    }
    List<Object> treeObjects = ContentDelegator.getTreeObjectList(templates);
    if (treeObjects != null && treeObjects.size() > 0) {
        IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
        for (IViewReference view : views) {
            if (ExplorerView.ID.equals(view.getId())) {
                ExplorerView explorerView = (ExplorerView) view.getView(true);
                explorerView.getViewer().setSelection(new StructuredSelection(treeObjects), true);
            }
        }
    }
}
Also used : ExplorerView(org.knime.workbench.explorer.view.ExplorerView) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IViewReference(org.eclipse.ui.IViewReference) NodeID(org.knime.core.node.workflow.NodeID) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 4 with ExplorerView

use of org.knime.workbench.explorer.view.ExplorerView in project knime-core by knime.

the class ExampleWorkflowExtractor method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    Location loc = Platform.getInstallLocation();
    if (loc == null) {
        NodeLogger.getLogger(getClass()).error("Cannot detect KNIME installation directory");
        return;
    } else if (!loc.getURL().getProtocol().equals("file")) {
        NodeLogger.getLogger(getClass()).error("KNIME installation directory is not local");
        return;
    }
    String path = loc.getURL().getPath();
    if (Platform.OS_WIN32.equals(Platform.getOS()) && path.matches("^/[a-zA-Z]:/.*")) {
        // Windows path with drive letter => remove first slash
        path = path.substring(1);
    }
    Path initialWorkspace = Paths.get(path, "knime-workspace.zip");
    if (!Files.exists(initialWorkspace)) {
        NodeLogger.getLogger(getClass()).warn(initialWorkspace.toAbsolutePath() + " not found in installation directory, not creating inital workspace");
        return;
    }
    File workspace = KNIMEPath.getWorkspaceDirPath();
    try (ZipInputStream is = new ZipInputStream(Files.newInputStream(initialWorkspace))) {
        FileUtil.unzip(is, workspace, 0);
    } catch (IOException ex) {
        NodeLogger.getLogger(getClass()).error("Could not extract example workflows: " + ex.getMessage(), ex);
    }
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            for (IViewReference ref : page.getViewReferences()) {
                if (ExplorerView.ID.equals(ref.getId())) {
                    final ExplorerView explorer = (ExplorerView) ref.getView(true);
                    final TreeViewer viewer = explorer.getViewer();
                    if (viewer.getControl() != null && viewer.getControl().getDisplay() != null) {
                        viewer.getControl().getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                viewer.refresh();
                                viewer.expandAll();
                            }
                        });
                    }
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) KNIMEPath(org.knime.core.internal.KNIMEPath) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ExplorerView(org.knime.workbench.explorer.view.ExplorerView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) Location(org.eclipse.osgi.service.datalocation.Location)

Aggregations

IViewReference (org.eclipse.ui.IViewReference)4 ExplorerView (org.knime.workbench.explorer.view.ExplorerView)4 AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)3 ArrayList (java.util.ArrayList)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)2 NodeID (org.knime.core.node.workflow.NodeID)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ZipInputStream (java.util.zip.ZipInputStream)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 IWizardPage (org.eclipse.jface.wizard.IWizardPage)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Location (org.eclipse.osgi.service.datalocation.Location)1 Shell (org.eclipse.swt.widgets.Shell)1 KNIMEPath (org.knime.core.internal.KNIMEPath)1