Search in sources :

Example 6 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator in project tdq-studio-se by Talend.

the class ResourceViewContentProvider method registerMergeRefListener.

/**
 * DOC sgandon Comment method "registerMergeRefListgener".
 */
private void registerMergeRefListener() {
    if (mergeRefListener == null) {
        mergeRefListener = new IPropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent event) {
                if (IRepositoryPrefConstants.MERGE_REFERENCE_PROJECT.equals(event.getProperty())) {
                    try {
                        ProxyRepositoryFactory.getInstance().initialize();
                    } catch (PersistenceException e) {
                        log.error(e, e);
                    }
                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    CommonNavigator findView = (CommonNavigator) activePage.findView(DQRespositoryView.ID);
                    if (findView != null) {
                        CommonViewer commonViewer = findView.getCommonViewer();
                        if (commonViewer != null) {
                            commonViewer.refresh();
                        }
                    }
                }
            }
        };
        // the merge only for DI repository,need to judge null for other product
        IRepositoryService repositoryService = CoreRuntimePlugin.getInstance().getRepositoryService();
        if (repositoryService != null) {
            IPreferenceStore preferenceStore = repositoryService.getRepositoryPreferenceStore();
            preferenceStore.addPropertyChangeListener(mergeRefListener);
        }
    }
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) CommonViewer(org.eclipse.ui.navigator.CommonViewer) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 7 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator in project titan.EclipsePlug-ins by eclipse.

the class LogFileContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement) {
    Object[] emptyResult = new Object[] {};
    if (!(parentElement instanceof IFile)) {
        return emptyResult;
    }
    final IFile logFile = (IFile) parentElement;
    if (!logFile.exists()) {
        return emptyResult;
    }
    String fileExtension = logFile.getFileExtension();
    if (fileExtension == null || !fileExtension.equals(Constants.LOG_EXTENSION)) {
        return emptyResult;
    }
    try {
        Object temp = logFile.getSessionProperty(Constants.EXTRACTION_RUNNING);
        if (temp != null && (Boolean) temp) {
            return emptyResult;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        TitanLogExceptionHandler.handleException(new UserException(e.getMessage()));
    }
    if (LogFileCacheHandler.hasLogFileChanged(logFile)) {
        handleLogFileChange(logFile);
        return emptyResult;
    }
    try {
        final TestCaseExtractor extractor = new TestCaseExtractor();
        extractor.extractTestCasesFromIndexedLogFile(logFile);
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IViewPart view = activePage.findView("org.eclipse.ui.navigator.ProjectExplorer");
                if (view instanceof CommonNavigator) {
                    CommonViewer viewer = ((CommonNavigator) view).getCommonViewer();
                    for (TestCase testCase : extractor.getTestCases()) {
                        viewer.expandToLevel(testCase, AbstractTreeViewer.ALL_LEVELS);
                        viewer.refresh(testCase, true);
                    }
                }
            }
        });
        return extractor.getTestCases().toArray();
    } catch (Exception e) {
        LogFileCacheHandler.clearCache(logFile);
        ErrorReporter.logExceptionStackTrace(e);
        return emptyResult;
    }
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) CommonViewer(org.eclipse.ui.navigator.CommonViewer) TestCaseExtractor(org.eclipse.titan.log.viewer.extractors.TestCaseExtractor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UserException(org.eclipse.titan.log.viewer.exceptions.UserException) CoreException(org.eclipse.core.runtime.CoreException) TestCase(org.eclipse.titan.log.viewer.parsers.data.TestCase) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UserException(org.eclipse.titan.log.viewer.exceptions.UserException)

Example 8 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator in project jbosstools-openshift by jbosstools.

the class OpenShiftUIUtils method getConnectionForExplorerSelection.

/**
 * Returns the connection for the given type and current selection in the OpenShift explorer.
 *
 * @param klass connection type
 * @return
 */
public static <T extends IConnection> T getConnectionForExplorerSelection(Class<T> klass) {
    ISelection selection = getOpenShiftExplorerSelection();
    if (selection != null && !selection.isEmpty()) {
        T result = UIUtils.getFirstElement(selection, klass);
        IViewPart part = getOpenShiftExplorer();
        if (result == null && selection instanceof IStructuredSelection && part instanceof CommonNavigator) {
            Object selected = ((IStructuredSelection) selection).getFirstElement();
            IContentProvider provider = ((CommonNavigator) part).getCommonViewer().getContentProvider();
            if (provider instanceof ITreeContentProvider) {
                ITreeContentProvider tree = (ITreeContentProvider) provider;
                while (selected != null && result == null) {
                    result = UIUtils.adapt(selected, klass);
                    selected = tree.getParent(selected);
                }
            }
        }
        return result;
    }
    return null;
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) IViewPart(org.eclipse.ui.IViewPart) IContentProvider(org.eclipse.jface.viewers.IContentProvider) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator in project linuxtools by eclipse.

the class EnableConnectionCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof CommonNavigator) {
        final CommonViewer viewer = ((CommonNavigator) activePart).getCommonViewer();
        final ITreeSelection selection = (ITreeSelection) viewer.getSelection();
        for (TreePath treePath : selection.getPaths()) {
            final IDockerConnection conn = (IDockerConnection) treePath.getLastSegment();
            if (!conn.isOpen()) {
                final Job openConnectionJob = new Job(CommandMessages.getFormattedString(// $NON-NLS-1$
                "command.enableconnection", conn.getUri())) {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        try {
                            conn.open(true);
                            Display.getDefault().asyncExec(() -> viewer.refresh(conn));
                        } catch (DockerException e) {
                            Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
                            "command.enableconnection.failure"), e);
                            return Status.CANCEL_STATUS;
                        }
                        return Status.OK_STATUS;
                    }
                };
                openConnectionJob.schedule();
            }
        }
    }
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) CommonViewer(org.eclipse.ui.navigator.CommonViewer) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 10 with CommonNavigator

use of org.eclipse.ui.navigator.CommonNavigator in project n4js by eclipse.

the class SelectAllProjectExplorerHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (null == activeWorkbenchWindow) {
        return null;
    }
    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
    if (null == activePage) {
        return null;
    }
    IWorkbenchPart activePart = activePage.getActivePart();
    if (!(activePart instanceof CommonNavigator)) {
        return null;
    }
    CommonNavigator navigator = (CommonNavigator) activePart;
    CommonViewer commonViewer = navigator.getCommonViewer();
    Tree navigatorTree = commonViewer.getTree();
    List<TreeItem> visibleItems = new ArrayList<>();
    collectChildren(navigatorTree.getItems(), visibleItems);
    List<Object> visibleData = visibleItems.stream().map(i -> i.getData()).collect(Collectors.toList());
    commonViewer.setSelection(new StructuredSelection(visibleData), false);
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Arrays(java.util.Arrays) CommonViewer(org.eclipse.ui.navigator.CommonViewer) PlatformUI(org.eclipse.ui.PlatformUI) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeItem(org.eclipse.swt.widgets.TreeItem) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) List(java.util.List) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Tree(org.eclipse.swt.widgets.Tree) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) AbstractHandler(org.eclipse.core.commands.AbstractHandler) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) CommonViewer(org.eclipse.ui.navigator.CommonViewer) TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Tree(org.eclipse.swt.widgets.Tree)

Aggregations

CommonNavigator (org.eclipse.ui.navigator.CommonNavigator)20 IViewPart (org.eclipse.ui.IViewPart)9 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 CommonViewer (org.eclipse.ui.navigator.CommonViewer)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)4 CoreException (org.eclipse.core.runtime.CoreException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 UserException (org.eclipse.titan.log.viewer.exceptions.UserException)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)2 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)2 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)2