org.eclipse.jface.viewers.ITableLabelProvider Java Examples

The following examples show how to use org.eclipse.jface.viewers.ITableLabelProvider. 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: 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 #2
Source File: SWTBotTimeGraphEntry.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Get the child entry of this entry with the given name
 *
 * @param name
 *            the name of the entry
 *
 * @return the child entry
 */
public SWTBotTimeGraphEntry getEntry(String name) {
    AtomicReference<ITimeGraphEntry> found = new AtomicReference<>();
    SWTBotUtils.waitUntil(timegraph -> {
        List<ITimeGraphEntry> entries = syncExec(new ListResult<ITimeGraphEntry>() {
            @Override
            public List<ITimeGraphEntry> run() {
                return Arrays.asList(timegraph.getExpandedElements());
            }
        });
        ITableLabelProvider labelProvider = timegraph.getLabelProvider();
        for (ITimeGraphEntry entry : entries) {
            if (fEntry.equals(entry.getParent())) {
                String label = labelProvider == null ? entry.getName() : labelProvider.getColumnText(entry, 0);
                if (name.equals(label)) {
                    found.set(entry);
                    return true;
                }
            }
        }
        return false;
    }, widget, () -> "Timed out waiting for time graph entry " + name);
    return new SWTBotTimeGraphEntry(widget, found.get());
}
 
Example #3
Source File: NodeDisplayTableControl.java    From depan with Apache License 2.0 6 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {
  if (INDEX_VISIBLE == colIndex) {
    return new BooleanVisibleSorter();
  }
  if (INDEX_XPOS == colIndex) {
    return new PositionSorter(true);
  }
  if (INDEX_YPOS == colIndex) {
    return new PositionSorter(false);
  }

  // By default, use an alphabetic sort over the column labels.
  ITableLabelProvider labelProvider =
      (ITableLabelProvider) propViewer.getLabelProvider();
  ViewerComparator result = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, colIndex));
  return result;
}
 
Example #4
Source File: MultiTreePatternFilter.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
    Object node = element;
    StructuredViewer structuredViewer = (StructuredViewer) viewer;
    ITableLabelProvider labelProvider = (ITableLabelProvider) structuredViewer.getLabelProvider();
    ITreeContentProvider treeContentProvider = (ITreeContentProvider) structuredViewer.getContentProvider();

    // Ensure the tree element and its parent(s) match the filter text
    for (Predicate<String> p : fPredicates) {
        // Retrieve tree element text and make verification. Text is at column 0
        String labelText = labelProvider.getColumnText(node, 0);
        if (labelText == null || !p.test(labelText)) {
            return false;
        }

        // Retrieve parent element
        node = treeContentProvider.getParent(node);
    }
    return true;
}
 
Example #5
Source File: NodeKindTableControl.java    From depan with Apache License 2.0 6 votes vote down vote up
private void setSortColumn(
    TableColumn column, int colIndex, int direction) {

  ITableLabelProvider labelProvider =
      (ITableLabelProvider) kindViewer.getLabelProvider();
  ViewerComparator sorter = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, colIndex));
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Table tableControl = (Table) kindViewer.getControl();
  kindViewer.setComparator(sorter);
  tableControl.setSortColumn(column);
  tableControl.setSortDirection(direction);
}
 
Example #6
Source File: NodeStatsTableControl.java    From depan with Apache License 2.0 6 votes vote down vote up
private ViewerComparator buildColumnSorter(int columnIndex) {
  switch (columnIndex) {
  case INDEX_ROOT:
    return new RootSorter();
  case INDEX_RANK:
    return new RankSorter();
  case INDEX_PREDS:
    return new PredecessorCountSorter();
  case INDEX_SUCCS:
    return new SuccessorCountSorter();
  }

  // By default, use an alphabetic sort over the column labels.
  ITableLabelProvider labelProvider =
      (ITableLabelProvider) propViewer.getLabelProvider();
  ViewerComparator result = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, columnIndex));
  return result;
}
 
Example #7
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 #8
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 #9
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 #10
Source File: RelationSetTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {
  if (INDEX_VISIBLE == colIndex) {
    return new BooleanViewSorter();
  }

  // By default, use an alphabetic sort over the column labels.
  ITableLabelProvider labelProvider =
      (ITableLabelProvider) relSetViewer.getLabelProvider();
  ViewerComparator result = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, colIndex));
  return result;
}
 
Example #11
Source File: RelationDisplayTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {

    // By default, use an alphabetic sort over the column labels.
    ITableLabelProvider labelProvider =
        (ITableLabelProvider) propViewer.getLabelProvider();
    ViewerComparator result = new AlphabeticSorter(
        new LabelProviderToString(labelProvider, colIndex));
    return result;
  }
 
Example #12
Source File: EdgeDisplayTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {

    // By default, use an alphabetic sort over the column labels.
    ITableLabelProvider labelProvider =
        (ITableLabelProvider) propViewer.getLabelProvider();
    ViewerComparator result = new AlphabeticSorter(
        new LabelProviderToString(labelProvider, colIndex));
    return result;
  }
 
Example #13
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 #14
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 #15
Source File: TableEditor.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Overwrite this compare method if text comparison isn't what you need
 * @param TableViewer
 * @param e1
 * @param e2
 * @return
 */
protected int doCompare(Viewer TableViewer, Object e1, Object e2) {
	ITableLabelProvider lp = ((ITableLabelProvider) viewer
        .getLabelProvider());
        String t1 = lp.getColumnText(e1, index);
        String t2 = lp.getColumnText(e2, index);
        return t1.compareTo(t2);
}
 
Example #16
Source File: Viewers.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static <T> void sortByDouble(ColumnViewer viewer, ITableLabelProvider labelProvider, int... cols) {
	for (int col : cols) {
		LabelComparator<T> s = new LabelComparator<>(col, labelProvider);
		s.asNumbers = true;
		addComparator(viewer, s);
	}
}
 
Example #17
Source File: Viewers.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static <T> void sortByLabels(ColumnViewer viewer,
		ITableLabelProvider label) {
	if (viewer == null || label == null)
		return;
	Object[] props = viewer.getColumnProperties();
	if (props == null)
		return;
	for (int col = 0; col < props.length; col++) {
		LabelComparator<T> s = new LabelComparator<>(col, label);
		addComparator(viewer, s);
	}
}
 
Example #18
Source File: TimeGraphViewer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets the tree label provider used for the name space
 *
 * @param labelProvider the tree label provider
 * @since 2.3
 */
public void setTimeGraphLabelProvider(ITableLabelProvider labelProvider) {
    fLabelProvider = labelProvider;
    if (fTimeGraphCtrl != null) {
        fTimeGraphCtrl.setLabelProvider(labelProvider);
    }
}
 
Example #19
Source File: Viewers.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static <T> void sortByLabels(ColumnViewer viewer,
		ITableLabelProvider labelProvider, int... cols) {
	for (int col : cols) {
		LabelComparator<T> s = new LabelComparator<>(col, labelProvider);
		addComparator(viewer, s);
	}
}
 
Example #20
Source File: SWTBotTimeGraph.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the time graph entry at the specified path relative to the root.
 *
 * @param names
 *            the path of names
 * @return the time graph entry
 * @throws WidgetNotFoundException
 *             if the entry was not found.
 */
public SWTBotTimeGraphEntry getEntry(String... names) throws WidgetNotFoundException {
    AtomicReference<ITimeGraphEntry> parent = new AtomicReference<>();
    AtomicReference<String> missing = new AtomicReference<>();
    SWTBotUtils.waitUntil(timegraph -> {
        List<ITimeGraphEntry> entries = syncExec(new ListResult<ITimeGraphEntry>() {
            @Override
            public List<ITimeGraphEntry> run() {
                return Arrays.asList(timegraph.getExpandedElements());
            }
        });
        ITableLabelProvider labelProvider = timegraph.getLabelProvider();
        parent.set(null);
        for (String name : names) {
            boolean found = false;
            for (ITimeGraphEntry entry : entries) {
                String label = labelProvider == null ? entry.getName() : labelProvider.getColumnText(entry, 0);
                if (Objects.equals(entry.getParent(), parent.get()) && name.equals(label)) {
                    parent.set(entry);
                    found = true;
                    break;
                }
            }
            if (!found) {
                missing.set(name);
                return false;
            }
        }
        return true;
    }, widget, () -> "Timed out waiting for time graph entry " + missing.get() + " of parent " + parent.get());
    return new SWTBotTimeGraphEntry(widget, parent.get());
}
 
Example #21
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 #22
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 #23
Source File: ResourceEditDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public int compare( Viewer viewer, Object e1, Object e2 )
{
	String name1;
	String name2;

	if ( viewer == null || !( viewer instanceof ContentViewer ) )
	{
		if ( descent )
		{
			name1 = e2.toString( );
			name2 = e1.toString( );
		}
		else
		{
			name1 = e1.toString( );
			name2 = e2.toString( );
		}
	}
	else
	{
		IBaseLabelProvider prov = ( (ContentViewer) viewer ).getLabelProvider( );
		if ( prov instanceof ITableLabelProvider )
		{
			ITableLabelProvider lprov = (ITableLabelProvider) prov;
			if ( second )
			{
				if ( descent )
				{
					name1 = lprov.getColumnText( e2, 1 );
					name2 = lprov.getColumnText( e1, 1 );
				}
				else
				{
					name1 = lprov.getColumnText( e1, 1 );
					name2 = lprov.getColumnText( e2, 1 );
				}
			}
			else
			{
				if ( descent )
				{
					name1 = lprov.getColumnText( e2, 0 );
					name2 = lprov.getColumnText( e1, 0 );
				}
				else
				{
					name1 = lprov.getColumnText( e1, 0 );
					name2 = lprov.getColumnText( e2, 0 );
				}
			}
		}
		else
		{
			if ( descent )
			{
				name1 = e2.toString( );
				name2 = e1.toString( );
			}
			else
			{
				name1 = e1.toString( );
				name2 = e2.toString( );
			}
		}
	}
	if ( name1 == null )
	{
		name1 = ""; //$NON-NLS-1$
	}
	if ( name2 == null )
	{
		name2 = ""; //$NON-NLS-1$
	}

	return collator.compare( name1, name2 );
}
 
Example #24
Source File: TableDecoratingLabelProvider.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param provider
 * @param decorator
 */
public TableDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator){
	super(provider, decorator);
	this.provider = (ITableLabelProvider) provider;
	this.decorator = decorator;
}
 
Example #25
Source File: LabelComparator.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
LabelComparator(int column, ITableLabelProvider labelProvider) {
	super(column);
	this.provider = labelProvider;
}
 
Example #26
Source File: CodeAssistAdvancedConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void createSeparateViewer(Composite composite) {
	fSeparateViewer= CheckboxTableViewer.newCheckList(composite, SWT.SINGLE | SWT.BORDER);
	Table table= fSeparateViewer.getTable();
	table.setHeaderVisible(false);
	table.setLinesVisible(false);
	table.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false, 1, 1));

	TableColumn nameColumn= new TableColumn(table, SWT.NONE);
	nameColumn.setText(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_separate_table_category_column_title);
	nameColumn.setResizable(false);

	fSeparateViewer.setContentProvider(new ArrayContentProvider());

	ITableLabelProvider labelProvider= new SeparateTableLabelProvider();
	fSeparateViewer.setLabelProvider(labelProvider);
	fSeparateViewer.setInput(fModel.elements);

	final int ICON_AND_CHECKBOX_WITH= 50;
	final int HEADER_MARGIN= 20;
	int minNameWidth= computeWidth(table, nameColumn.getText()) + HEADER_MARGIN;
	for (int i= 0; i < fModel.elements.size(); i++) {
		minNameWidth= Math.max(minNameWidth, computeWidth(table, labelProvider.getColumnText(fModel.elements.get(i), 0)) + ICON_AND_CHECKBOX_WITH);
	}

	nameColumn.setWidth(minNameWidth);

	fSeparateViewer.addCheckStateListener(new ICheckStateListener() {
		public void checkStateChanged(CheckStateChangedEvent event) {
			boolean checked= event.getChecked();
			ModelElement element= (ModelElement) event.getElement();
			element.setSeparateCommand(checked);
		}
	});

	table.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			handleTableSelection();
		}
	});

}
 
Example #27
Source File: SvnWizardSwitchPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public TableDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator) {
	super(provider, decorator);
	this.provider = (ITableLabelProvider) provider;
    this.decorator = decorator;
}
 
Example #28
Source File: SvnWizardCompareMultipleResourcesWithBranchTagPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public TableDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator) {
	super(provider, decorator);
	this.provider = (ITableLabelProvider) provider;
    this.decorator = decorator;
}
 
Example #29
Source File: BranchTagWizardRepositoryPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public TableDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator) {
	super(provider, decorator);
	this.provider = (ITableLabelProvider) provider;
    this.decorator = decorator;
}
 
Example #30
Source File: NodeDisplayTableControl.java    From depan with Apache License 2.0 4 votes vote down vote up
public ITableLabelProvider getLabelProvider() {
  return (ITableLabelProvider) getTreeViewer().getLabelProvider();
}