Java Code Examples for org.eclipse.jface.viewers.Viewer

The following examples show how to use org.eclipse.jface.viewers.Viewer. These examples are extracted from open source projects. 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
public KontaktAnzeigeTypViewerFilter(Viewer viewer){
	KontaktAnzeigeTypViewerFilter.viewer = viewer;
	
	PlatformUI.getPreferenceStore().setDefault(
		KontaktAnzeigeTypViewerFilter.class.getName() + ".showPatient", true);
	
	showPerson =
		PlatformUI.getPreferenceStore().getBoolean(
			KontaktAnzeigeTypViewerFilter.class.getName() + ".showPerson");
	showPatient =
		PlatformUI.getPreferenceStore().getBoolean(
			KontaktAnzeigeTypViewerFilter.class.getName() + ".showPatient");
	showOrganisation =
		PlatformUI.getPreferenceStore().getBoolean(
			KontaktAnzeigeTypViewerFilter.class.getName() + ".showOrganisation");
	showMandant =
		PlatformUI.getPreferenceStore().getBoolean(
			KontaktAnzeigeTypViewerFilter.class.getName() + ".showMandant");
	showAnwender =
		PlatformUI.getPreferenceStore().getBoolean(
			KontaktAnzeigeTypViewerFilter.class.getName() + ".showAnwender");
	showDeleted =
		PlatformUI.getPreferenceStore().getBoolean(
			KontaktAnzeigeTypViewerFilter.class.getName() + ".showDeleted");
}
 
Example 2
/**
 * {@inheritDoc}
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if (element instanceof IMember) {
		IMember member= (IMember)element;
		try {
			String[] categories= member.getCategories();
			if (categories.length == 0)
				return !fFilterUncategorizedMembers;

			for (int i= 0; i < categories.length; i++) {
				if (!fFilteredCategories.contains(categories[i]))
					return true;
			}
			return false;
		} catch (JavaModelException e) {
			JavaPlugin.log(e);
		}
	}
	return true;
}
 
Example 3
Source Project: cmake4eclipse   Source File: DefinesViewer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
  CmakeDefine v1 = (CmakeDefine) e1;
  CmakeDefine v2 = (CmakeDefine) e2;
  int rc = 0;
  switch (sortColumn) {
  case 0:
    rc = v1.getName().compareTo(v2.getName());
    break;
  case 1:
    rc = v1.getType().name().compareTo(v2.getType().name());
    break;
  case 2:
    rc = v1.getValue().compareTo(v2.getValue());
    break;
  default:
    rc = 0;
  }
  // If descending order, flip the direction
  if (!ascending) {
    rc = -rc;
  }
  return rc;
}
 
Example 4
@Override
public int compare(Viewer viewer, Object e1, Object e2){
	IContact c1 = (IContact) e1;
	IContact c2 = (IContact) e2;
	
	switch (selectedSorter) {
	case SORT_BY_FIRSTNAME:
		if (c1.getDescription1() == null || c2.getDescription1() == null)
			return 0;
		return c1.getDescription1().compareToIgnoreCase(c2.getDescription1());
	case SORT_BY_FAMILYNAME:
		if (c1.getDescription2() == null || c2.getDescription2() == null)
			return 0;
		return c1.getDescription2().compareToIgnoreCase(c2.getDescription2());
	default:
		if (c1.getDescription2() == null || c2.getDescription2() == null)
			return 0;
		return c1.getDescription2().compareToIgnoreCase(c2.getDescription2());
	}
}
 
Example 5
@Override
public Viewer createDiffViewer(final Composite parent) {
    viewer = new DiffTreeViewer(parent, getCompareConfiguration());
    viewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(final OpenEvent event) {
            final IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            final DiffNode obj = (DiffNode) sel.getFirstElement();
            obj.setDontExpand(false);
        }
    });
    viewer.setFilters(getFilters());
    viewer.setLabelProvider(new DiffTreeLabelProvider());
    viewer.setContentProvider(new BonitaScriptRefactoringContentProvider());
    viewer.setInput(root);
    viewer.expandAll();

    return viewer;
}
 
Example 6
private String getNonJavaElementLabel(Viewer viewer, Object element) {
	// try to use the workbench adapter for non - java resources or if not available, use the viewers label provider
	if (element instanceof IResource) {
		return ((IResource) element).getName();
	}
	if (element instanceof IStorage) {
		return ((IStorage) element).getName();
	}
	if (element instanceof IAdaptable) {
		IWorkbenchAdapter adapter= (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class);
		if (adapter != null) {
			return adapter.getLabel(element);
		}
	}
	if (viewer instanceof ContentViewer) {
		IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
		if (prov instanceof ILabelProvider) {
			return ((ILabelProvider) prov).getText(element);
		}
	}
	return null;
}
 
Example 7
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
  int result = 0;

  if ((e1 instanceof FileSet) && (e2 instanceof FileSet)) {
    FileSet fileSet1 = (FileSet) e1;
    FileSet fileSet2 = (FileSet) e2;

    String name1 = fileSet1.getName();
    String name2 = fileSet2.getName();

    result = name1.compareTo(name2);
  }

  return result;
}
 
Example 8
Source Project: Pydev   Source File: PyExceptionListProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    if (newInput == this.newInput) {
        return;
    }

    // let go of the old info before getting the new info
    dispose();
    this.newInput = newInput;

    if (newInput == null) {
        return;
    }

    PyExceptionBreakPointManager instance = PyExceptionBreakPointManager.getInstance();
    List<String> list = instance.getBuiltinExceptions();
    list.addAll(instance.getUserConfiguredExceptions());

    elementsForCurrentInput = list.toArray(new String[0]);
}
 
Example 9
Source Project: birt   Source File: DataSetBasePage.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected boolean isLeafMatch( Viewer viewer, Object element )
{

	String text;
	if ( element instanceof DataSourceType )
	{
		return false;
	}
	else if ( element instanceof DataSourceHandle )
	{
		DataSourceHandle node = (DataSourceHandle) element;
		text = node.getName( );

		if ( wordMatches( text ) )
		{
			return true;
		}
	}
	return false;
}
 
Example 10
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if (element instanceof IPackageFragmentRoot) {
		IPackageFragmentRoot root= (IPackageFragmentRoot)element;
		if (root.isArchive()) {
			// don't filter out JARs contained in the project itself
			IResource resource= root.getResource();
			if (resource != null) {
				IProject jarProject= resource.getProject();
				IProject container= root.getJavaProject().getProject();
				return !container.equals(jarProject);
			}
		}
	}
	return true;
}
 
Example 11
protected void hijackCallHierarchy(final IViewPart view, final boolean revertToDefaults)
{
	try
	{
		Field f = view.getClass().getDeclaredField("fPagebook"); //$NON-NLS-1$
		f.setAccessible(true);
		PageBook pageBook = (PageBook) f.get(view);

		f = pageBook.getClass().getDeclaredField("currentPage"); //$NON-NLS-1$
		f.setAccessible(true);
		Control control = (Control) f.get(pageBook);
		if (control instanceof Label)
		{
			hookTheme(control, revertToDefaults);
			return;
		}

		Method m = view.getClass().getMethod("getViewer"); //$NON-NLS-1$
		TreeViewer treeViewer = (TreeViewer) m.invoke(view);
		hookTheme(treeViewer, revertToDefaults);

		m = view.getClass().getDeclaredMethod("getLocationViewer"); //$NON-NLS-1$
		if (m != null)
		{
			m.setAccessible(true);
			Viewer viewer = (Viewer) m.invoke(view);
			hookTheme(viewer, revertToDefaults);
		}
	}
	catch (Exception e)
	{
		// ignore
	}
}
 
Example 12
Source Project: Pydev   Source File: PythonNodeFilter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof PythonNode) {
        return false;
    }
    return true;
}
 
Example 13
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
	if (e1 instanceof IWorkingSet || e2 instanceof IWorkingSet)
		return 0;

	return super.compare(viewer, e1, e2);
}
 
Example 14
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	super.inputChanged(viewer, oldInput, newInput);
	fViewer= (TreeViewer)viewer;
	if (oldInput == null && newInput != null) {
		JavaCore.addElementChangedListener(this);
	} else if (oldInput != null && newInput == null) {
		JavaCore.removeElementChangedListener(this);
	}
	fInput= newInput;
}
 
Example 15
Source Project: elexis-3-core   Source File: BillingProposalView.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput){
	if (newInput instanceof List<?>) {
		currentContent = ((List<Konsultation>) newInput).parallelStream()
			.map(k -> new BillingInformation(this.viewer, k.getFall(), k))
			.collect(Collectors.toList());
	}
}
 
Example 16
@Override
public void inputChanged ( final Viewer viewer, final Object oldInput, final Object newInput )
{
    this.input = newInput;
    if ( viewer instanceof TreeViewer )
    {
        this.viewer = (TreeViewer)viewer;
    }
    else
    {
        this.viewer = null;
    }
}
 
Example 17
Source Project: Flashtool   Source File: TableSorter.java    License: GNU General Public License v3.0 5 votes vote down vote up
public TableSorter(TableViewer tableViewer) {
	this.tableViewer = tableViewer;
	addColumnSelectionListeners(tableViewer);
	tableViewer.setComparator(new ViewerComparator() {
		public int compare(Viewer viewer, Object e1, Object e2) {
			return compareElements(e1, e2);
		}
	});
}
 
Example 18
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	super.inputChanged(viewer, oldInput, newInput);

	if (newInput instanceof Collection) {
		// Get a template object from the collection
		Collection<?> col= (Collection<?>)newInput;
		if (!col.isEmpty())
			newInput= col.iterator().next();
		else
			newInput= null;
	}
	fInput= newInput;
}
 
Example 19
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
	if (element instanceof IFile) {
		if (fExcludes != null && fExcludes.contains(element)) {
			return false;
		}
		return isArchivePath(((IFile)element).getFullPath(), fAllowAllArchives);
	} else if (element instanceof IContainer) { // IProject, IFolder
		if (!fRecursive) {
			return true;
		}
		// ignore closed projects
		if (element instanceof IProject && !((IProject)element).isOpen())
			return false;
		try {
			IResource[] resources= ((IContainer)element).members();
			for (int i= 0; i < resources.length; i++) {
				// recursive! Only show containers that contain an archive
				if (select(viewer, parent, resources[i])) {
					return true;
				}
			}
		} catch (CoreException e) {
			JavaPlugin.log(e.getStatus());
		}
	}
	return false;
}
 
Example 20
Source Project: olca-app   Source File: Comparator.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
	LibraryRestriction l1 = (LibraryRestriction) o1;
	LibraryRestriction l2 = (LibraryRestriction) o2;
	if (l1.type == RestrictionType.FORBIDDEN && l2.type == RestrictionType.WARNING)
		return -1;
	if (l1.type == RestrictionType.WARNING && l2.type == RestrictionType.FORBIDDEN)
		return 1;
	return compare(viewer, l1.dataset, l2.dataset);
}
 
Example 21
Source Project: nebula   Source File: PShelfViewer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.jface.viewers.ContentViewer#labelProviderChanged()
 */
protected void labelProviderChanged() {
	Assert.isNotNull(getLabelProvider());
	if (!(getLabelProvider() instanceof ILabelProvider))
		throw new IllegalArgumentException("Label provider must implement ILabelProvider" + ", got " + getLabelProvider() == null ? "null" : getLabelProvider().getClass().toString());

	if (pshelf != null) {
		PShelfItem[] shelfItems = pshelf.getItems();

		for (int i = 0; i < shelfItems.length; i++) {
			PShelfItem item = shelfItems[i];

			// re-query texts and images for pshelf items
			ILabelProvider lp = (ILabelProvider) getLabelProvider();
			item.setText(lp.getText(item.getData()));
			item.setImage(lp.getImage(item.getData()));

			// change provider for sub-viewers
			Viewer viewer = getViewerForItem(item);
			ContentViewer contentViewer = (ContentViewer) viewer;
			if (contentViewer != null)
				contentViewer.setLabelProvider(lp);
		}
	}

	// refresh in super impl
	super.labelProviderChanged();
}
 
Example 22
Source Project: elexis-3-core   Source File: TextTemplateFilter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element){
	if (searchTerm == null || searchTerm.length() == 0) {
		return true;
	}
	
	TextTemplate tt = (TextTemplate) element;
	String name = tt.getName().toLowerCase();
	if (name.matches(searchTerm)) {
		return true;
	}
	
	String desc = tt.getDescription().toLowerCase();
	if (desc.matches(searchTerm)) {
		return true;
	}
	
	String mime = tt.getMimeTypePrintname().toLowerCase();
	if (mime.matches(searchTerm)) {
		return true;
	}
	
	String mandant = tt.getMandantLabel().toLowerCase();
	if (mandant.matches(searchTerm)) {
		return true;
	}
	
	return false;
}
 
Example 23
Source Project: nebula   Source File: PShelfViewer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/** 
 * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean)
 */
protected void doUpdateItem(Widget item, Object element, boolean fullMap) {
	Viewer viewer = getViewerForItem(pshelf.getSelection());
	if (viewer instanceof StructuredViewer) {
		ReflectionUtils.callMethod(viewer, "doUpdateItem", item, element, fullMap);
	}
}
 
Example 24
@Override
public boolean select(Viewer viewer, Object parentElement, Object element){
	if (searchString == null)
		return true;
	IContact k = (IContact) element;
	
	if (searchString.startsWith("$")) {
		// Nothing to do here, we have a formula evaluation
		return true;
	} else if (searchString.startsWith("#")) {
		// direct patient number lookup
		if (k.isPatient()) {
			String patNr = k.getCode();
			if (patNr.toLowerCase().equalsIgnoreCase(searchString.substring(1).trim()))
				return true;
		}
	} else {
		String desc1 = (k.getDescription1() != null) ? k.getDescription1().toLowerCase() : "";
		String desc2 = (k.getDescription2() != null) ? k.getDescription2().toLowerCase() : "";
		
		String[] searchListComma = searchString.split(",");
		for (String string : searchListComma) {
			if (string.contains(" ")) {
				String searchA = desc1 + " " + desc2;
				String searchB = desc2 + " " + desc1;
				if (searchA.matches(".*" + string + ".*")
					|| searchB.matches(".*" + string + ".*"))
					return true;
			} else if (desc1.matches(".*" + string + ".*")
				|| desc2.matches(".*" + string + ".*")) {
				return true;
			}
		}
	}
	
	return false;
}
 
Example 25
Source Project: tm4e   Source File: ColumnViewerComparator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public int compare(Viewer viewer, Object e1, Object e2) {

	if (viewer instanceof TableViewer) {
		IBaseLabelProvider baseLabel = ((TableViewer) viewer).getLabelProvider();

		String left = ((ITableLabelProvider) baseLabel).getColumnText(e1, fSortColumn);
		String right = ((ITableLabelProvider) baseLabel).getColumnText(e2, fSortColumn);
		int sortResult = getComparator().compare(left != null ? left : "", right != null ? right : "");
		return sortResult * fSortOrder;
	}

	return super.compare(viewer, e1, e2);
}
 
Example 26
Source Project: olca-app   Source File: EmptyCategoryFilter.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private boolean passesFilters(Viewer viewer, ViewerFilter[] filters,
		ModelElement element) {
	for (ViewerFilter filter : filters)
		if (!filter.select(viewer, element.getParent(), element))
			return false;
	return true;
}
 
Example 27
Source Project: olca-app   Source File: NavigationComparator.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
	if (e1 == null || e2 == null)
		return 0;
	if (!Objects.equals(e1.getClass(), e2.getClass()))
		return compareByType(e1, e2);
	if (e1 instanceof GroupElement && e2 instanceof GroupElement)
		return 0;
	if (e1 instanceof ModelTypeElement && e2 instanceof ModelTypeElement)
		return compare((ModelTypeElement) e1, (ModelTypeElement) e2);

	// the scripting folder should be always the last element in the tree
	if (!(e1 instanceof ScriptElement) && e2 instanceof ScriptElement)
		return -1;
	if (e1 instanceof ScriptElement && !(e2 instanceof ScriptElement))
		return 1;
	if (e1 instanceof ScriptElement) {
		var f1 = ((ScriptElement) e1).getContent();
		var f2 = ((ScriptElement) e2).getContent();
		if (f1.isDirectory() && !f2.isDirectory())
			return -1;
		if (!f1.isDirectory() && f2.isDirectory())
			return 1;
		return Strings.compare(f1.getName(), f2.getName());
	}

	String name1 = getLabel(viewer, e1);
	String name2 = getLabel(viewer, e2);

	// TODO: document why this here makes sense: (?)
	// probably the status suffix when the database is
	// connected to a repository?
	if (e1 instanceof DatabaseElement && name1.contains(" "))
		name1 = name1.substring(0, name1.indexOf(" "));
	if (e2 instanceof DatabaseElement && name2.contains(" "))
		name2 = name2.substring(0, name2.indexOf(" "));

	return getComparator().compare(name1, name2);
}
 
Example 28
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
	boolean isContainer= element instanceof IContainer;
	if (!isContainer && element instanceof IJavaElement) {
		int type= ((IJavaElement)element).getElementType();
		isContainer= type == IJavaElement.JAVA_MODEL
					|| type == IJavaElement.JAVA_PROJECT
					|| type == IJavaElement.PACKAGE_FRAGMENT
					|| type ==IJavaElement.PACKAGE_FRAGMENT_ROOT;
	}
	return (fFilterContainers && !isContainer) || (!fFilterContainers && isContainer);
}
 
Example 29
/**
 * (non-Javadoc)
 * 
 * @see org.eclipse.ui.dialogs.PatternFilter#isLeafMatch(org.eclipse.jface.viewers.Viewer,
 *      java.lang.Object)
 */
protected boolean isLeafMatch(Viewer viewer, Object element) {
	if (filterCategories) {
		final ParameterizedCommand cmd = getCommand(element);
		try {
			if (cmd != null
					&& cmd.getCommand().getCategory() == uncategorized) {
				return false;
			}
		} catch (NotDefinedException e) {
			return false;
		}
	}
	return super.isLeafMatch(viewer, element);
}
 
Example 30
@Override
public void run ()
{
    if ( activeEditorPart instanceof IViewerProvider )
    {
        Viewer viewer = ( (IViewerProvider)activeEditorPart ).getViewer ();
        if ( viewer != null )
        {
            viewer.refresh ();
        }
    }
}