Java Code Examples for org.eclipse.jface.viewers.AbstractTreeViewer#add()

The following examples show how to use org.eclipse.jface.viewers.AbstractTreeViewer#add() . 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: LevelTreeContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized void elementsChanged(Object[] updatedElements) {
	if (getSearchResult() == null)
		return;

	AbstractTreeViewer viewer= (AbstractTreeViewer) getPage().getViewer();

	Set<Object> toRemove= new HashSet<Object>();
	Set<Object> toUpdate= new HashSet<Object>();
	Map<Object, Set<Object>> toAdd= new HashMap<Object, Set<Object>>();
	for (int i= 0; i < updatedElements.length; i++) {
		if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0)
			insert(toAdd, toUpdate, updatedElements[i]);
		else
			remove(toRemove, toUpdate, updatedElements[i]);
	}

	viewer.remove(toRemove.toArray());
	for (Iterator<Object> iter= toAdd.keySet().iterator(); iter.hasNext();) {
		Object parent= iter.next();
		HashSet<Object> children= (HashSet<Object>) toAdd.get(parent);
		viewer.add(parent, children.toArray());
	}
	for (Iterator<Object> elementsToUpdate= toUpdate.iterator(); elementsToUpdate.hasNext();) {
		viewer.refresh(elementsToUpdate.next());
	}

}
 
Example 2
Source File: TypeScriptNavigatorContentProvider.java    From typescript.java with MIT License 4 votes vote down vote up
private void processChanged(final IIDETypeScriptProject tsProject, final ITypeScriptBuildPath oldBuildPath,
		final ITypeScriptBuildPath newBuildPath, Collection<Runnable> runnables) {
	// he widget may have been destroyed
	// by the time this is run. Check for this and do nothing if so.
	Control ctrl = viewer.getControl();
	if (ctrl == null || ctrl.isDisposed()) {
		return;
	}

	final IProject project = tsProject.getProject();
	Runnable addAndRemove = new Runnable() {
		public void run() {
			if (viewer instanceof AbstractTreeViewer) {
				AbstractTreeViewer treeViewer = (AbstractTreeViewer) viewer;
				// Disable redraw until the operation is finished so we
				// don't
				// get a flash of both the new and old item (in the case of
				// rename)
				// Only do this if we're both adding and removing files (the
				// rename case)
				/*
				 * if (hasRename) {
				 * treeViewer.getControl().setRedraw(false); }
				 */
				try {
					/*
					 * if (oldBuildPath != null) { treeViewer.remove(new
					 * Object[] { oldBuildPath }); } if (newBuildPath !=
					 * null && newBuildPath.getContainers().size() > 0) {
					 * treeViewer.add(project, new Object[] { newBuildPath
					 * }); }
					 */
					if (!hasBuildPath(newBuildPath)) {
						treeViewer.remove(project, new Object[] { tsProject });
					} else {
						if (!hasBuildPath(oldBuildPath)) {
							treeViewer.add(project, new Object[] { tsProject });
						} else {
							treeViewer.refresh(tsProject);
						}
					}
				} finally {
					/*
					 * if (hasRename) {
					 * treeViewer.getControl().setRedraw(true); }
					 */
				}
			} else {
				((StructuredViewer) viewer).refresh(project);
			}
		}

		private boolean hasBuildPath(final ITypeScriptBuildPath buildPath) {
			return buildPath != null && buildPath.hasRootContainers();
		}
	};
	runnables.add(addAndRemove);
}