org.eclipse.jface.viewers.IBaseLabelProvider Java Examples

The following examples show how to use org.eclipse.jface.viewers.IBaseLabelProvider. 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: Tables.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Creates a default table viewer with the given properties. The properties are
 * also used to create columns where each column label is the respective
 * property of this column. The viewer is configured in the following way:
 * <ul>
 * <li>content provider = {@link ArrayContentProvider}
 * <li>lines and header are visible
 * <li>grid data with horizontal and vertical fill
 * 
 */
public static TableViewer createViewer(Composite parent, String[] properties,
		IBaseLabelProvider labelProvider) {
	TableViewer viewer = new TableViewer(parent,
			SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.MULTI);
	viewer.setContentProvider(new ArrayContentProvider());
	boolean hasColumns = properties != null && properties.length > 0;
	Table table = viewer.getTable();
	table.setLinesVisible(hasColumns);
	table.setHeaderVisible(hasColumns);
	if (hasColumns) {
		createColumns(viewer, properties, labelProvider);
	}
	if (labelProvider != null) {
		viewer.setLabelProvider(labelProvider);
	}
	GridData data = UI.gridData(table, true, true);
	data.minimumHeight = 120;
	// workaround for this bug:
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=215997
	Point p = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	data.heightHint = p.y < 120 ? 120 : p.y;
	return viewer;
}
 
Example #2
Source File: FileFolderSorter.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private String getLabel(final Viewer viewer, final Object e1) {
	String name1;
	if (viewer == null || !(viewer instanceof ContentViewer)) {
		name1 = e1.toString();
	} else {
		final IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
		if (prov instanceof ILabelProvider) {
			final ILabelProvider lprov = (ILabelProvider) prov;
			name1 = lprov.getText(e1);
		} else {
			name1 = e1.toString();
		}
	}
	if (name1 == null) {
		name1 = "";//$NON-NLS-1$
	}
	return name1;
}
 
Example #3
Source File: WizardUtils.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
public static IBaseLabelProvider getPostQualifiedLabelProvider() {
	return new DelegatingStyledCellLabelProvider(new JavaElementLabelProvider(
			JavaElementLabelProvider.SHOW_POST_QUALIFIED | JavaElementLabelProvider.SHOW_SMALL_ICONS)) {
		@Override
		protected StyledString getStyledText(Object element) {
			String nameWithQualifier = getStyledStringProvider().getStyledText(element).getString() + " ";
			int separatorIndex = nameWithQualifier.indexOf('-');

			if (separatorIndex == -1)
				return new StyledString(nameWithQualifier);

			StyledString name = new StyledString(nameWithQualifier.substring(0, separatorIndex));
			String qualifier = nameWithQualifier.substring(separatorIndex);
			return name.append(new StyledString(qualifier, StyledString.QUALIFIER_STYLER));
		};
	};
}
 
Example #4
Source File: JavaElementComparator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 #5
Source File: CPListElementSorter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int compare(Viewer viewer, Object e1, Object e2) {

       int cat1 = category(e1);
       int cat2 = category(e2);

       if (cat1 != cat2)
           return cat1 - cat2;

       if (cat1 == ATTRIBUTE || cat1 == CONTAINER_ENTRY) {
       	return 0; // do not sort attributes or container entries
       }

	if (viewer instanceof ContentViewer) {
		IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
           if (prov instanceof ILabelProvider) {
               ILabelProvider lprov = (ILabelProvider) prov;
               String name1 = lprov.getText(e1);
               String name2 = lprov.getText(e2);
               return getComparator().compare(name1, name2);
           }
	}
	return 0;
}
 
Example #6
Source File: CContainerViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
protected void doUpdateCell(int index, CContainerCell cell, Object element, String[] properties) {
	IBaseLabelProvider prov = (IBaseLabelProvider) getLabelProvider();
	if(prov != null) {
		Color background = null;
		Color foreground = null;
		if(prov instanceof ITableColorProvider) {
			background = ((ITableColorProvider) prov).getBackground(element, index);
			foreground = ((ITableColorProvider) prov).getForeground(element, index);
		} else if(prov instanceof IColorProvider) {
			background = ((IColorProvider) prov).getBackground(element);
			foreground = ((IColorProvider) prov).getForeground(element);
		}
		if(background != null) cell.setCellBackground(background);
		if(foreground != null) cell.setCellForeground(foreground);
		
		// TODO doUpdateItem - set fonts...
	}
}
 
Example #7
Source File: CTableTreeViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
protected void doUpdateCell(int index, CContainerCell cell, Object element, String[] properties) {
	super.doUpdateCell(index, cell, element, properties);
	
	IBaseLabelProvider prov = (IBaseLabelProvider) getLabelProvider();
	if(prov != null) {
		CTableTreeCell cttc = (CTableTreeCell) cell;
		String text = null;
		if(prov instanceof ICContainerLabelProvider) {
			cttc.setImages(((ICContainerLabelProvider) prov).getColumnImages(element, index));
			text = ((ITableLabelProvider) prov).getColumnText(element, index);
		} else if(prov instanceof ITableLabelProvider) {
			cttc.setImage(((ITableLabelProvider) prov).getColumnImage(element, index));
			text = ((ITableLabelProvider) prov).getColumnText(element, index);
		} else if(prov instanceof ILabelProvider) {
			cttc.setImage(((ILabelProvider) prov).getImage(element));
			text = ((ILabelProvider) prov).getText(element);
		}
		if(text == null) text = ""; //$NON-NLS-1$
		cttc.setText(text);
	}
}
 
Example #8
Source File: SampleReportsSorter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public int compare( Viewer viewer, Object e1, Object e2 )
{
	IBaseLabelProvider provider = null;
	if ( viewer instanceof TreeViewer )
	{
		provider =( ( TreeViewer )viewer ).getLabelProvider( );
	}
	if ( provider != null && provider instanceof SampleReportsExplorerProvider )
	{
		if( ( ( SampleReportsExplorerProvider )provider ).getText( e1 ).equals( "Contribute Samples" ) ) //$NON-NLS-1$
		{
			return 1;
		}
		else if ( ( ( SampleReportsExplorerProvider )provider ).getText( e2 ).equals( "Contribute Samples" ) ) //$NON-NLS-1$
		{
			return -1;
		}
	}
	return 0;
}
 
Example #9
Source File: Trees.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
public static TreeViewer createViewer(
		Composite parent, String[] headers, IBaseLabelProvider label) {
	TreeViewer viewer = new TreeViewer(parent,
			SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.MULTI);
	Tree tree = viewer.getTree();
	boolean hasColumns = headers != null && headers.length > 0;
	tree.setLinesVisible(hasColumns);
	tree.setHeaderVisible(hasColumns);
	if (hasColumns) {
		createColumns(viewer, headers, label);
	}
	if (label != null) {
		viewer.setLabelProvider(label);
	}
	GridData data = UI.gridData(tree, true, true);
	data.minimumHeight = 120;
	Point p = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	data.heightHint = p.y < 120 ? 120 : p.y;
	return viewer;
}
 
Example #10
Source File: KeysPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private int compareColumn(final Viewer viewer, final Object a, final Object b, final int columnNumber) {
	// if (columnNumber == CATEGORY_COLUMN) {
	// return sortUser(a, b);
	// }
	IBaseLabelProvider baseLabel = ((TreeViewer) viewer).getLabelProvider();
	if (baseLabel instanceof ITableLabelProvider) {
		ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel;
		String e1p = tableProvider.getColumnText(a, columnNumber);
		String e2p = tableProvider.getColumnText(b, columnNumber);
		if (e1p != null && e2p != null) {
			return getComparator().compare(e1p, e2p);
		}
	}
	return 0;
}
 
Example #11
Source File: XViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setLabelProvider(IBaseLabelProvider labelProvider) {
   if (!(labelProvider instanceof IXViewerLabelProvider)) {
      throw new IllegalArgumentException(
         "Label Provider must extend XViewerLabelProvider or XViewerStyledTextLabelProvider"); //$NON-NLS-1$
   }
   super.setLabelProvider(labelProvider);
}
 
Example #12
Source File: XCheckFilteredTreeDialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public XCheckFilteredTreeDialog(String dialogTitle, String dialogMessage, PatternFilter patternFilter, IContentProvider contentProvider, IBaseLabelProvider labelProvider, ViewerSorter viewerSorter) {
   super(Display.getCurrent().getActiveShell(), dialogTitle, null, dialogMessage, MessageDialog.NONE, new String[] {
 	  XViewerText.get("button.ok"), XViewerText.get("button.cancel")}, 0); //$NON-NLS-1$ //$NON-NLS-2$
   this.contentProvider = contentProvider;
   this.labelProvider = labelProvider;
   this.patternFilter = patternFilter;
   this.viewerSorter = viewerSorter;
   setShellStyle(getShellStyle() | SWT.RESIZE);
}
 
Example #13
Source File: TimelineViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Set the label provider for this viewer. Optional the lable provider may implement {@link IColorProvider} and {@link IToolTipProvider}.
 *
 * @param labelProvider
 *            provider implementing {@link ITimelineLabelProvider}
 */
@Override
public void setLabelProvider(IBaseLabelProvider labelProvider) {
	if (!(labelProvider instanceof ITimelineLabelProvider))
		throw new IllegalArgumentException("Label provider needs to implement ITimelineLabelProvider");

	super.setLabelProvider(labelProvider);
}
 
Example #14
Source File: ColumnViewerComparator.java    From tm4e with 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 : ""); //$NON-NLS-1$ //$NON-NLS-2$
		return sortResult * fSortOrder;
	}

	return super.compare(viewer, e1, e2);
}
 
Example #15
Source File: ColumnViewerComparator.java    From tm4e with 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 #16
Source File: ListDialogSortableFiltered.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public ListDialogSortableFiltered(String dialogTitle, String dialogMessage, PatternFilter patternFilter, IContentProvider contentProvider, IBaseLabelProvider labelProvider, ViewerSorter viewerSorter) {
   super(Display.getCurrent().getActiveShell(), dialogTitle, null, dialogMessage, MessageDialog.NONE,
      new String[] {XViewerText.get("button.ok"), XViewerText.get("button.cancel")}, 0); //$NON-NLS-1$ //$NON-NLS-2$
   this.contentProvider = contentProvider;
   this.labelProvider = labelProvider;
   this.patternFilter = patternFilter;
   this.viewerSorter = viewerSorter;
   setShellStyle(getShellStyle() | SWT.RESIZE);
}
 
Example #17
Source File: SubtractOptionPart.java    From depan with Apache License 2.0 5 votes vote down vote up
public NodeListSourcesControl(Composite parent) {
  super(parent);
  listProvider = new ListContentProvider<IResource>(this);
  setContentProvider(listProvider);
  IBaseLabelProvider labelProvider = new PartLabelProvider();
  setLabelProvider(labelProvider );
}
 
Example #18
Source File: MonthCalendarViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void setLabelProvider(IBaseLabelProvider labelProvider) {
	if (!(labelProvider instanceof ILabelProvider)) {
		throw new IllegalArgumentException(
				"label provider must be of type ILabelProvider");
	}
	super.setLabelProvider(labelProvider);
}
 
Example #19
Source File: DQSettingsPage.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected IBaseLabelProvider getLabelProvider() {
	return new BaseLabelProvider() {
		@Override
		public String getText(Object o) {
			if (o instanceof NAHandling)
				return Labels.of((NAHandling) o);
			if (o instanceof AggregationType)
				return Labels.of((AggregationType) o);
			if (o instanceof RoundingMode)
				return Labels.of((RoundingMode) o);
			return super.getText(o);
		}
	};
}
 
Example #20
Source File: ILocalizedEnumLabelProvider.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static IBaseLabelProvider getInstance(){
	synchronized (LabelProvider.class) {
		if (instance == null) {
			instance = new ILocalizedEnumLabelProvider();
		}
		return instance;
	}
}
 
Example #21
Source File: LanguageCodesPreferencePage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int compareColumn(final Viewer viewer, final Object a, final Object b, final int columnNumber) {
	IBaseLabelProvider baseLabel = ((TreeViewer) viewer).getLabelProvider();
	if (baseLabel instanceof ITableLabelProvider) {
		ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel;
		String e1p = tableProvider.getColumnText(a, columnNumber);
		String e2p = tableProvider.getColumnText(b, columnNumber);
		if (e1p != null && e2p != null) {
			return getComparator().compare(e1p, e2p);
		}
	}
	return 0;
}
 
Example #22
Source File: KeysPreferencePage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private int compareColumn(final Viewer viewer, final Object a, final Object b, final int columnNumber) {
	// if (columnNumber == CATEGORY_COLUMN) {
	// return sortUser(a, b);
	// }
	IBaseLabelProvider baseLabel = ((TreeViewer) viewer).getLabelProvider();
	if (baseLabel instanceof ITableLabelProvider) {
		ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel;
		String e1p = tableProvider.getColumnText(a, columnNumber);
		String e2p = tableProvider.getColumnText(b, columnNumber);
		if (e1p != null && e2p != null) {
			return getComparator().compare(e1p, e2p);
		}
	}
	return 0;
}
 
Example #23
Source File: LanguageCodesPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int compareColumn(final Viewer viewer, final Object a, final Object b, final int columnNumber) {
	IBaseLabelProvider baseLabel = ((TreeViewer) viewer).getLabelProvider();
	if (baseLabel instanceof ITableLabelProvider) {
		ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel;
		String e1p = tableProvider.getColumnText(a, columnNumber);
		String e2p = tableProvider.getColumnText(b, columnNumber);
		if (e1p != null && e2p != null) {
			return getComparator().compare(e1p, e2p);
		}
	}
	return 0;
}
 
Example #24
Source File: KeysPreferencePage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private int compareColumn(final Viewer viewer, final Object a, final Object b, final int columnNumber) {
	// if (columnNumber == CATEGORY_COLUMN) {
	// return sortUser(a, b);
	// }
	IBaseLabelProvider baseLabel = ((TreeViewer) viewer).getLabelProvider();
	if (baseLabel instanceof ITableLabelProvider) {
		ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel;
		String e1p = tableProvider.getColumnText(a, columnNumber);
		String e2p = tableProvider.getColumnText(b, columnNumber);
		if (e1p != null && e2p != null) {
			return getComparator().compare(e1p, e2p);
		}
	}
	return 0;
}
 
Example #25
Source File: ConfigureRepositoriesDialog.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected IBaseLabelProvider getLabelProvider() {
	return new RepositoryConfigLabel();
}
 
Example #26
Source File: HistoryViewer.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected IBaseLabelProvider getLabelProvider() {
	return new HistoryLabel();
}
 
Example #27
Source File: ExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setLabelProvider(final IBaseLabelProvider labelProvider) {
    Assert.isTrue(labelProvider instanceof ExpressionLabelProvider);
    super.setLabelProvider(labelProvider);
}
 
Example #28
Source File: HistoryView.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected IBaseLabelProvider getLabelProvider() {
	return new ReferencesLabel();
}
 
Example #29
Source File: CloudPreferencePage.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected IBaseLabelProvider getLabelProvider() {
	return new LabelProvider();
}
 
Example #30
Source File: DefaultCallHierarchyViewPart.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected IBaseLabelProvider createLocationLabelProvider() {
	return locationLabelProvider;
}