Search in sources :

Example 51 with IViewReference

use of org.eclipse.ui.IViewReference in project linuxtools by eclipse.

the class PrepareChangelogKeyHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    IStructuredSelection tempResult = null;
    // try getting currently selected project
    IWorkbenchPage ref = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    if (part instanceof IEditorPart) {
        // If we are in an editor, check if the file being edited is an IResource
        // that belongs to a project in the workspace
        IEditorPart editorPart = (IEditorPart) part;
        IEditorInput input = editorPart.getEditorInput();
        IResource r = input.getAdapter(IResource.class);
        if (r != null) {
            // We have an IResource to work with, so create a selection we can use
            // in PrepareChangeLogAction
            tempResult = new StructuredSelection(r);
        }
    } else {
        // Otherwise, our view is not an editor, see if we have an IResource or something
        // that will lead us to an IResource
        ISelection selected = ref.getSelection();
        if (selected instanceof IStructuredSelection) {
            IResource r = null;
            IStructuredSelection iss = (IStructuredSelection) selected;
            Object o = ((IStructuredSelection) selected).getFirstElement();
            if (o instanceof ISynchronizeModelElement) {
                r = ((ISynchronizeModelElement) o).getResource();
            } else if (o instanceof IAdaptable) {
                r = ((IAdaptable) o).getAdapter(IResource.class);
            }
            if (r != null)
                tempResult = iss;
        }
    }
    if (tempResult == null) {
        // choice to fall back on.
        for (IViewReference view : ref.getViewReferences()) {
            if (view.getId().equals("org.eclipse.team.sync.views.SynchronizeView")) {
                // $NON-NLS-1$
                IViewPart v = view.getView(false);
                ISelection s = null;
                ISelectionProvider sp = v.getViewSite().getSelectionProvider();
                if (sp != null) {
                    s = sp.getSelection();
                }
                if (s instanceof IStructuredSelection) {
                    IStructuredSelection ss = (IStructuredSelection) s;
                    Object element = ss.getFirstElement();
                    IResource r = null;
                    if (element instanceof ISynchronizeModelElement) {
                        r = ((ISynchronizeModelElement) element).getResource();
                    } else if (element instanceof IAdaptable) {
                        r = ((IAdaptable) element).getAdapter(IResource.class);
                    }
                    if (r != null) {
                        tempResult = ss;
                    }
                }
            }
        }
    }
    // If we can't find the project directly, let the user know.
    if (tempResult == null) {
        // $NON-NLS-1$,
        MessageDialog.openInformation(// $NON-NLS-1$,
        getActiveWorkbenchShell(), // $NON-NLS-1$,
        Messages.getString("ChangeLog.PrepareChangeLog"), // $NON-NLS-1$
        Messages.getString("PrepareChangeLog.InfoNoProjectFound"));
        return null;
    }
    final IStructuredSelection result = tempResult;
    IAction exampleAction = new PrepareChangeLogAction() {

        @Override
        public void run() {
            setSelection(result);
            doRun();
        }
    };
    exampleAction.run();
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IViewPart(org.eclipse.ui.IViewPart) IAction(org.eclipse.jface.action.IAction) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IViewReference(org.eclipse.ui.IViewReference) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 52 with IViewReference

use of org.eclipse.ui.IViewReference in project linuxtools by eclipse.

the class AbstractStyledTextViewTest method testPerfView.

@Override
protected void testPerfView() {
    SWTWorkbenchBot bot = new SWTWorkbenchBot();
    Matcher<IViewReference> withPartName = withPartName(getViewId());
    SWTBotView view = bot.view(withPartName);
    assertNotNull(view);
    view.setFocus();
    SWTBotStyledText text = bot.styledText();
    assertNotNull(text);
    assertEquals(getExpectedText(), text.getText());
}
Also used : SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) SWTBotStyledText(org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText) IViewReference(org.eclipse.ui.IViewReference) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)

Example 53 with IViewReference

use of org.eclipse.ui.IViewReference 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 54 with IViewReference

use of org.eclipse.ui.IViewReference 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 55 with IViewReference

use of org.eclipse.ui.IViewReference 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)66 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)48 IViewPart (org.eclipse.ui.IViewPart)37 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)23 PartInitException (org.eclipse.ui.PartInitException)23 IFile (org.eclipse.core.resources.IFile)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)8 ArrayList (java.util.ArrayList)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)8 CubridViewPart (com.cubrid.common.ui.spi.part.CubridViewPart)7 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)7 IOException (java.io.IOException)6 IEditorInput (org.eclipse.ui.IEditorInput)6 IEditorReference (org.eclipse.ui.IEditorReference)6 HostNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode)4 ParseException (java.text.ParseException)4 IProject (org.eclipse.core.resources.IProject)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4