org.eclipse.ui.navigator.CommonViewer Java Examples

The following examples show how to use org.eclipse.ui.navigator.CommonViewer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RefreshAction.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void run(IAction action) {
    if (navigator != null) {
        CommonViewer viewer = navigator.getCommonViewer();
        BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService());
        // provider.setRefreshRequested(true);

        Object[] expandedElements = viewer.getExpandedElements();
        Object input = viewer.getInput();
        if (provider.getChildren(input).length == 0) {
            viewer.setInput(null);
            if (input instanceof IWorkingSet || input instanceof IWorkspaceRoot) {
                viewer.setInput(input);
            } else {
                viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
            }
            viewer.refresh(true);
        } else {
            provider.reSetInput();
        }
        viewer.setExpandedElements(expandedElements);
    }
}
 
Example #2
Source File: GamaNavigator.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void handleDoubleClick(final DoubleClickEvent anEvent) {
	final IStructuredSelection selection = (IStructuredSelection) anEvent.getSelection();
	final Object element = selection.getFirstElement();
	if (element instanceof VirtualContent && ((VirtualContent<?>) element).handleDoubleClick()) {
		if (element instanceof Tag) {
			Tag t = (Tag) element;
			findControl.searchFor(t.getName());
			return;
		}
	} else {
		super.handleDoubleClick(anEvent);
	}
	if (element instanceof WrappedContainer || element instanceof TopLevelFolder) {
		final CommonViewer tree = getCommonViewer();
		if (tree.getExpandedState(element)) {
			final Object[] contents = ((VirtualContent<?>) element).getNavigatorChildren();
			if (contents.length > 0) {
				tree.reveal(contents[contents.length - 1]);
			}
		}
	}
}
 
Example #3
Source File: NavigatorCommonViewer.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void expandAll() {
	getControl().setRedraw(false);
	NavigatorContentProvider.FILE_CHILDREN_ENABLED = false;
	final IStructuredSelection currentSelection = (IStructuredSelection) getSelection();
	if (currentSelection == null || currentSelection.isEmpty()) {
		super.expandAll();
	} else {
		final Iterator<?> it = currentSelection.iterator();
		while (it.hasNext()) {
			final Object o = it.next();
			if (o instanceof TopLevelFolder) {
				expandToLevel(o, CommonViewer.ALL_LEVELS); // 2
			} else if (o instanceof IContainer) {
				expandToLevel(o, CommonViewer.ALL_LEVELS);
			}
		}

	}
	NavigatorContentProvider.FILE_CHILDREN_ENABLED = true;
	this.refresh(false);
	getControl().setRedraw(true);

}
 
Example #4
Source File: WorkingSetActionProvider.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void init(ICommonActionExtensionSite aSite) {
	viewer = (CommonViewer) aSite.getStructuredViewer();
	contentService = aSite.getContentService();
	filterService = (NavigatorFilterService) contentService.getFilterService();

	extensionStateModel = contentService.findStateModel(WorkingSetsContentProvider.EXTENSION_ID);

	workingSetActionGroup = new WorkingSetFilterActionGroup(aSite.getViewSite().getShell(), filterChangeListener);
	workingSetRootModeActionGroup = new WorkingSetRootModeActionGroup(viewer, extensionStateModel);

	topLevelModeListener = new IPropertyChangeListener() {
		public void propertyChange(PropertyChangeEvent event) {
			setWorkingSet(workingSet);
			viewer.getFrameList().reset();
		}
	};

	if (contentService.isActive(WorkingSetsContentProvider.EXTENSION_ID)) {
		managerChangeListener.listen();
		extensionStateModel.addPropertyChangeListener(topLevelModeListener);
	}

	contentService.getActivationService().addExtensionActivationListener(activationListener);
}
 
Example #5
Source File: TypeScriptContentOutlinePage.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public void createControl(Composite parent) {
	fOutlineViewer = new CommonViewer(OUTLINE_COMMON_NAVIGATOR_ID, parent, SWT.MULTI);
	// seems like common filters need to be explicitly added
	for (ViewerFilter filter : fOutlineViewer.getNavigatorContentService().getFilterService()
			.getVisibleFilters(true)) {
		this.fOutlineViewer.addFilter(filter);
	}

	Object[] listeners = fSelectionChangedListeners.getListeners();
	for (int i = 0; i < listeners.length; i++) {
		fSelectionChangedListeners.remove(listeners[i]);
		fOutlineViewer.addSelectionChangedListener((ISelectionChangedListener) listeners[i]);
	}

	listeners = fPostSelectionChangedListeners.getListeners();
	for (int i = 0; i < listeners.length; i++) {
		fPostSelectionChangedListeners.remove(listeners[i]);
		fOutlineViewer.addPostSelectionChangedListener((ISelectionChangedListener) listeners[i]);
	}

	fOutlineViewer.setUseHashlookup(true);

	IActionBars actionBars = getSite().getActionBars();
	registerToolbarActions(actionBars);
}
 
Example #6
Source File: WorkingSetActionProvider.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public void init(ICommonActionExtensionSite aSite) {
	viewer = (CommonViewer) aSite.getStructuredViewer();
	contentService = aSite.getContentService();
	filterService = (NavigatorFilterService) contentService.getFilterService();

	extensionStateModel = contentService.findStateModel(WorkingSetsContentProvider.EXTENSION_ID);

	workingSetActionGroup = new WorkingSetFilterActionGroup(aSite.getViewSite().getShell(), filterChangeListener);
	workingSetRootModeActionGroup = new WorkingSetRootModeActionGroup(viewer, extensionStateModel);

	topLevelModeListener = new IPropertyChangeListener() {
		public void propertyChange(PropertyChangeEvent event) {
			setWorkingSet(workingSet);
			viewer.getFrameList().reset();
		}
	};

	if (contentService.isActive(WorkingSetsContentProvider.EXTENSION_ID)) {
		managerChangeListener.listen();
		extensionStateModel.addPropertyChangeListener(topLevelModeListener);
	}

	contentService.getActivationService().addExtensionActivationListener(activationListener);
}
 
Example #7
Source File: ToolboxExplorerResourceListener.java    From tlaplus with MIT License 6 votes vote down vote up
public void resourceChanged(final IResourceChangeEvent event) {
	UIHelper.runUIAsync(new Runnable() {
		public void run() {
			ToolboxExplorer.refresh();
			// Expand the current spec and all its children
			final CommonViewer viewer = ToolboxExplorer.getViewer();
			// Event is only null when this Ctor calls us causing the
			// initial expanded state of a spec to be fully expanded.
			// Afterwards, the users expanded states is preserved.
			if (event == null && viewer != null) { // viewer might already be disposed which happens when the Toolbox shuts down.
				final Spec specLoaded = Activator.getSpecManager().getSpecLoaded();
				viewer.expandToLevel(specLoaded, ToolboxExplorer.DEFAULT_EXPAND_LEVEL);
			}
		}
	});
}
 
Example #8
Source File: GoUpAction.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void run(IAction action) {
    if (!action.isEnabled()) {
        return;
    }
    CommonViewer viewer = navigator.getCommonViewer();
    Object[] expandedElements = viewer.getVisibleExpandedElements();
    Object input = viewer.getInput();
    if (input instanceof BugGroup) {
        BugGroup group = (BugGroup) input;
        Object data = group.getParent();
        boolean needRefresh = data == null;
        if (needRefresh) {
            BugContentProvider.getProvider(navigator.getNavigatorContentService()).reSetInput();
        } else {
            viewer.setInput(data);
        }
        // viewer.setSelection(new StructuredSelection(input), true);
        // viewer.expandToLevel(input, 1);
        viewer.setExpandedElements(expandedElements);
    }
    action.setEnabled(isEnabled());
}
 
Example #9
Source File: GroupByAction.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void run(IAction action) {
    if (navigator == null) {
        return;
    }
    Grouping grouping = getGrouping(action.getId());
    if (grouping == null) {
        return;
    }
    BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService());
    provider.setGrouping(grouping);
    CommonViewer viewer = navigator.getCommonViewer();
    Object[] expandedElements = viewer.getExpandedElements();
    provider.reSetInput();
    viewer.setExpandedElements(expandedElements);
}
 
Example #10
Source File: FilterBugsDialogAction.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void run(IAction action) {
    if (navigator == null) {
        return;
    }
    Set<BugPattern> filtered = FindbugsPlugin.getFilteredPatterns();
    Set<BugCode> filteredTypes = FindbugsPlugin.getFilteredPatternTypes();
    FilterBugsDialog dialog = new FilterBugsDialog(navigator.getSite().getShell(), filtered, filteredTypes);
    dialog.setTitle("Bug Filter Configuration");
    int result = dialog.open();
    if (result != Window.OK) {
        return;
    }
    String selectedIds = dialog.getSelectedIds();

    FindbugsPlugin.getDefault().getPreferenceStore().setValue(FindBugsConstants.LAST_USED_EXPORT_FILTER, selectedIds);

    BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService());
    provider.refreshFilters();
    CommonViewer viewer = navigator.getCommonViewer();
    Object[] expandedElements = viewer.getExpandedElements();
    viewer.refresh(true);
    viewer.setExpandedElements(expandedElements);
}
 
Example #11
Source File: OpenGroupDialogAction.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void run(IAction action) {
    if (navigator == null) {
        return;
    }
    BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService());
    List<GroupType> list = provider.getGrouping().asList();
    GroupSelectionDialog dialog = new GroupSelectionDialog(navigator.getSite().getShell(), list);
    dialog.setTitle("Bug Group Configuration");
    int result = dialog.open();
    if (result != Window.OK) {
        return;
    }
    Grouping grouping = Grouping.createFrom(dialog.getGroups());
    provider.setGrouping(grouping);
    CommonViewer viewer = navigator.getCommonViewer();
    Object[] expandedElements = viewer.getExpandedElements();
    provider.reSetInput();
    viewer.setExpandedElements(expandedElements);
}
 
Example #12
Source File: ViewHelper.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void toggleExpansion(Object element) {
	final Object obj = element == null ? CodewindManager.getManager() : element;
	Display.getDefault().asyncExec(new Runnable() {
           @Override
           public void run() {
			IViewPart view = getViewPart(CodewindExplorerView.VIEW_ID);
			if (view instanceof CommonNavigator) {
				CommonViewer viewer = ((CommonNavigator)view).getCommonViewer();
		
				if (!viewer.getExpandedState(obj)) {
					viewer.expandToLevel(obj, AbstractTreeViewer.ALL_LEVELS);
				} else {
					viewer.collapseToLevel(obj, AbstractTreeViewer.ALL_LEVELS);
				}
            }
			}
	});
}
 
Example #13
Source File: BugExplorerView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void markerSelected(IWorkbenchPart part, IMarker marker) {
    if (selectionInProgress) {
        return;
    }
    BugContentProvider provider = BugContentProvider.getProvider(getNavigatorContentService());
    CommonViewer commonViewer = getCommonViewer();
    if (marker == null) {
        commonViewer.setSelection(new StructuredSelection(), false);
    } else if (provider.isFiltered(marker)) {
        Object parent = provider.getParent(marker);
        if (parent != null) {
            commonViewer.setSelection(new StructuredSelection(parent), true);
        }
    } else {
        commonViewer.setSelection(new StructuredSelection(marker), true);
    }
}
 
Example #14
Source File: AbstractFileStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void refreshExplorerView() {
    Display.getDefault().asyncExec(() -> {
        if (PlatformUI.isWorkbenchRunning()
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
            IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                    .findView("org.bonitasoft.studio.application.project.explorer");
            if (viewPart != null) {
                CommonViewer viewer = viewPart.getAdapter(CommonViewer.class);
                if (viewer != null && !viewer.getTree().isDisposed()) {
                    viewer.refresh(true);
                }
            }
        }
    });
}
 
Example #15
Source File: ViewHelper.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void expandConnection(CodewindConnection connection) {
	if (connection == null) {
		return;
	}
	List<CodewindApplication> apps = connection.getApps();
	if (!apps.isEmpty()) {
		Display.getDefault().asyncExec(new Runnable() {
            @Override
            public void run() {
				IViewPart view = getViewPart(CodewindExplorerView.VIEW_ID);
				if (view instanceof CommonNavigator) {
					CommonViewer viewer = ((CommonNavigator)view).getCommonViewer();
			
					if (!viewer.getExpandedState(connection)) {
						viewer.expandToLevel(AbstractTreeViewer.ALL_LEVELS);
					}
	            }
 			}
		});
	}
}
 
Example #16
Source File: PythonLinkHelper.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tries to find a match for the element in the given root passed. If found returns true.
 * 
 * @param infosSearched: a memo to know which infos were already searched to prevent searching many times in
 * the same place.
 */
private IStructuredSelection findMatchInTreeNodeRoot(File element, CommonViewer commonViewer,
        InterpreterInfoTreeNodeRoot treeNodeRoot, Set<IInterpreterInfo> infosSearched) {
    if (infosSearched.contains(treeNodeRoot.interpreterInfo)) {
        return null;
    }
    infosSearched.add(treeNodeRoot.interpreterInfo);

    List<TreeNode> nodesOrderedForFileSearch = treeNodeRoot.getNodesOrderedForFileSearch();
    for (TreeNode node : nodesOrderedForFileSearch) {
        PythonpathTreeNode match = findMatch(node, element);
        if (match != null) {
            return new StructuredSelection(match);
        }
    }
    return null;
}
 
Example #17
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Refreshes the content *under* the given element.
 */
public static void refresh(INavigationElement<?> element) {
	CommonViewer viewer = getNavigationViewer();
	if (viewer == null || element == null)
		return;
	element.update();
	Object[] oldExpansion = viewer.getExpandedElements();
	viewer.refresh(element);
	updateLabels(viewer, element);
	if (oldExpansion == null)
		return;
	setRefreshedExpansion(viewer, oldExpansion);
}
 
Example #18
Source File: NonEssentialElementsFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private synchronized void initStateModel(Viewer viewer) {
	if (!isStateModelInitialized) {
		if (viewer instanceof CommonViewer) {

			CommonViewer commonViewer = (CommonViewer) viewer;
			fContentService = commonViewer.getNavigatorContentService();
			fStateModel = fContentService.findStateModel(JAVA_EXTENSION_ID);

			isStateModelInitialized = true;
		}
	}
}
 
Example #19
Source File: ResourceToItemsMapper.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public ResourceToItemsMapper(CommonViewer viewer) {
	_resourceToItem = new HashMap();
	_reuseLists = new Stack();

	_commonViewer = viewer;
	viewer.setMapper(this);
}
 
Example #20
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Expands the elements in the viewer that have the same content as in the
 * elements of the <code>oldExpansion</code> array.
 */
private static void setRefreshedExpansion(CommonViewer viewer,
		Object[] oldExpansion) {
	List<INavigationElement<?>> newExpanded = new ArrayList<>();
	for (Object expandedElem : oldExpansion) {
		if (!(expandedElem instanceof INavigationElement))
			continue;
		INavigationElement<?> oldElem = (INavigationElement<?>) expandedElem;
		INavigationElement<?> newElem = findElement(oldElem.getContent());
		if (newElem != null)
			newExpanded.add(newElem);
	}
	viewer.setExpandedElements(newExpanded.toArray());
}
 
Example #21
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void updateLabels(CommonViewer viewer,
		INavigationElement<?> element) {
	TreeItem item = findItem(viewer, element);
	if (item == null)
		return;
	do {
		viewer.doUpdateItem(item);
		item = item.getParentItem();
	} while (item != null);
}
 
Example #22
Source File: WorkingSetsContentProvider.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(ICommonContentExtensionSite aConfig) {
	NavigatorContentService cs = (NavigatorContentService) aConfig.getService();
	viewer = (CommonViewer) cs.getViewer();
	projectExplorer = viewer.getCommonNavigator();
	
	extensionStateModel = aConfig.getExtensionStateModel();
	extensionStateModel.addPropertyChangeListener(rootModeListener);
	updateRootMode();
	
}
 
Example #23
Source File: ResourceToItemsMapper.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public ResourceToItemsMapper(CommonViewer viewer) {
	_resourceToItem = new HashMap();
	_reuseLists = new Stack();

	_commonViewer = viewer;
	viewer.setMapper(this);
}
 
Example #24
Source File: WorkingSetsContentProvider.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(ICommonContentExtensionSite aConfig) {
	NavigatorContentService cs = (NavigatorContentService) aConfig.getService();
	viewer = (CommonViewer) cs.getViewer();
	projectExplorer = viewer.getCommonNavigator();
	
	extensionStateModel = aConfig.getExtensionStateModel();
	extensionStateModel.addPropertyChangeListener(rootModeListener);
	updateRootMode();
	
}
 
Example #25
Source File: TopLevelProjectsOrWorkingSetChoice.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Starts listening to property changes related to which should be the top-level elements to be shown.
 */
public void init(ICommonContentExtensionSite aConfig, CommonViewer viewer) {
    //if it had something, dispose of its association!
    this.dispose();
    try {
        extensionStateModel = viewer.getNavigatorContentService().findStateModel(
                WorkingSetsContentProvider.EXTENSION_ID);

        extensionStateModel.addPropertyChangeListener(rootModeListener);
    } catch (Exception e) {
        Log.log(e);
    }
    updateRootMode();
}
 
Example #26
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Refresh the navigation view if it is available.
 */
public static void refresh() {
	CommonViewer viewer = getNavigationViewer();
	NavigationRoot root = getNavigationRoot();
	if (viewer == null || root == null)
		return;
	Object[] oldExpansion = viewer.getExpandedElements();
	root.update();
	viewer.refresh();
	setRefreshedExpansion(viewer, oldExpansion);
}
 
Example #27
Source File: BonitaProjectExplorer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected CommonViewer createCommonViewerObject(Composite aParent) {
    CommonViewer commonViewer = new PackageExplorerProblemTreeViewer(getViewSite().getId(), aParent,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    commonViewer.getTree().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
            "org.bonitasoft.studio.application.projectExplorerTree");
    commonViewer.addFilter(UIDArtifactFilters.filterUIDArtifactChildren());
    return commonViewer;
}
 
Example #28
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static CommonViewer getNavigationViewer() {
	CommonViewer viewer = null;
	Navigator instance = getInstance();
	if (instance != null) {
		viewer = instance.getCommonViewer();
	}
	return viewer;
}
 
Example #29
Source File: PydevPackageExplorer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Overridden to create our viewer and not the superclass CommonViewer.
 * 
 * (Unfortunately, the superclass does a little more than creating it, so, we have to do those operations here 
 * too -- that's why we have to keep the memento object in the init method).
 */
@Override
protected CommonViewer createCommonViewer(Composite aParent) {
    //super.createCommonViewer(aParent); -- don't even call the super class
    CommonViewer aViewer = new PydevCommonViewer(getViewSite().getId(), aParent, SWT.MULTI | SWT.H_SCROLL
            | SWT.V_SCROLL, this);
    initListeners(aViewer);

    //commented: we do that only after the part is completely created (because otherwise the state is reverted later)
    //aViewer.getNavigatorContentService().restoreState(memento);

    return aViewer;
}
 
Example #30
Source File: NavigatorContentProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void inputChanged(final Viewer v, final Object oldInput, final Object newInput) {
	final CommonViewer viewer = (CommonViewer) v;
	final ResourceManager mapper = new ResourceManager(this, viewer);
	getInstance().resetVirtualFolders(mapper);
	getWorkspace().addResourceChangeListener(mapper, POST_CHANGE | PRE_DELETE);
	super.inputChanged(viewer, oldInput, newInput);
}