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);
}
}
}
}
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);
}
}
}
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);
}
}
}
}
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();
}
});
}
}
}
}
}
}
Aggregations