Java Code Examples for org.eclipse.jface.viewers.ILabelProvider#getText()

The following examples show how to use org.eclipse.jface.viewers.ILabelProvider#getText() . 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: 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 2
Source File: IndexViewLabelProvider.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public String getText(Object element)
{
	List<ILabelProvider> providers = this.getProcessors();
	String result = StringUtil.EMPTY;

	for (ILabelProvider provider : providers)
	{
		String text = provider.getText(element);

		if (!StringUtil.isEmpty(text))
		{
			result = text;
			break;
		}
	}

	return result;
}
 
Example 3
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 4
Source File: ServiceKarafRepositoryMavenSetting.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@Override
protected RepositoryPreferenceNode createKarafFolderNode(String id, ILabelProvider labelProvider, RepositoryNode node) {
    ServicesKarafRepositorySettingNode servicesKarafNode = null;

    if (labelProvider == null) {
        servicesKarafNode = new ServicesKarafRepositorySettingNode(id, node);
    } else {
        String label = labelProvider.getText(node);
        ImageDescriptor imageDesc = null;
        Image image = labelProvider.getImage(node);
        if (image != null) {
            imageDesc = ImageDescriptor.createFromImageData(image.getImageData());
        }
        servicesKarafNode = new ServicesKarafRepositorySettingNode(id, label, imageDesc, node);
    }
    return servicesKarafNode;

}
 
Example 5
Source File: RoutesKarafRepositoryMavenSetting.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@Override
protected RepositoryPreferenceNode createKarafFolderNode(String id, ILabelProvider labelProvider, RepositoryNode node) {
    RoutesKarafRepositorySettingNode routesKarafNode = null;

    if (labelProvider == null) {
        routesKarafNode = new RoutesKarafRepositorySettingNode(id, node);
    } else {
        String label = labelProvider.getText(node);
        ImageDescriptor imageDesc = null;
        Image image = labelProvider.getImage(node);
        if (image != null) {
            imageDesc = ImageDescriptor.createFromImageData(image.getImageData());
        }
        routesKarafNode = new RoutesKarafRepositorySettingNode(id, label, imageDesc, node);
    }
    return routesKarafNode;
}
 
Example 6
Source File: GlobalDescriptionLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getText(Object element) {
	if (element == null) {
		return Messages.GlobalDescriptionLabelProvider_0;
	} else {
		ILabelProvider descriptionLabelProvider = lookupDescriptionLabelProvider(element);
		if (descriptionLabelProvider != null) {
			return descriptionLabelProvider.getText(element);
		} else {
			return element.toString();
		}
	}
}
 
Example 7
Source File: GlobalDescriptionLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public StyledString getStyledText(Object element) {
	if (element == null) {
		return new StyledString(Messages.GlobalDescriptionLabelProvider_0);
	} else {
		ILabelProvider descriptionLabelProvider = lookupDescriptionLabelProvider(element);
		if (descriptionLabelProvider instanceof IStyledLabelProvider)
			return ((IStyledLabelProvider) descriptionLabelProvider).getStyledText(element);
		else if(descriptionLabelProvider != null) {
			return new StyledString(descriptionLabelProvider.getText(element));
		} else {
			return new StyledString(element.toString());
		}
	}
}
 
Example 8
Source File: AbstractLabelProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the label from the given eObject's {@link IResourceServiceProvider}.
 *
 * @param eObject
 *          the target object
 * @return the label for the given eObject
 */
private String getForeignObjectLabel(final EObject eObject) {
  IResourceServiceProvider serviceProvider = ((XtextResource) eObject.eResource()).getResourceServiceProvider();
  ILabelProvider labelProvider = serviceProvider.get(ILabelProvider.class);
  if (labelProvider != null) {
    return labelProvider.getText(eObject);
  }
  return null;
}
 
Example 9
Source File: AbstractInformationControl.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Recursively searches the first element in the tree which matches the current
 * filter pattern.
 * 
 * @param items
 *            tree root items
 * @return tree element
 */
private Object findFirstMatchToPattern(TreeItem[] items) {
	// Match the string pattern against labels
	ILabelProvider labelProvider = (ILabelProvider) treeViewer.getLabelProvider();
	// Process each item in the tree
	for (int i = 0; i < items.length; i++) {
		Object element = items[i].getData();
		// Return the first element if no pattern is set
		if (stringMatcher == null) {
			return element;
		}
		// Return the element if it matches the pattern
		if (element != null) {
			String label = labelProvider.getText(element);
			if (stringMatcher.match(label)) {
				return element;
			}
		}
		// Recursively check the elements children for a match
		element = findFirstMatchToPattern(items[i].getItems());
		// Return the child element match if found
		if (element != null) {
			return element;
		}
	}
	// No match found
	return null;
}
 
Example 10
Source File: CompositeOutlineLabelProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getText(Object element)
{
	if (element instanceof ILanguageNode)
	{
		String language = ((ILanguageNode) element).getLanguage();
		ILabelProvider provider = fProvidersByLanguage.get(language);
		if (provider != null)
		{
			return provider.getText(element);
		}
	}
	return getDefaultText(element);
}
 
Example 11
Source File: SearchLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected String getParticipantText(Object element) {
	ILabelProvider labelProvider= getLabelProvider(element);
	if (labelProvider != null)
		return labelProvider.getText(element);
	return ""; //$NON-NLS-1$

}
 
Example 12
Source File: SearchLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected StyledString getStyledParticipantText(Object element) {
	ILabelProvider labelProvider= getLabelProvider(element);
	if (labelProvider instanceof IStyledLabelProvider)
		return ((IStyledLabelProvider) labelProvider).getStyledText(element);
	if (labelProvider != null)
		return new StyledString(labelProvider.getText(element));
	return new StyledString();
}
 
Example 13
Source File: WorkingSetSorter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public int compare(Viewer viewer, Object e1, Object e2) {
	if(viewer instanceof StructuredViewer) {			
		 ILabelProvider labelProvider = (ILabelProvider) ((StructuredViewer)viewer).getLabelProvider();
		 String text1 = labelProvider.getText(e1);
		 String text2 = labelProvider.getText(e2);
		 if(text1 != null) {			
			 return text1.compareTo(text2);
		 }
	}
	return -1;
}
 
Example 14
Source File: WorkingSetSorter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public int compare(Viewer viewer, Object e1, Object e2) {
	if(viewer instanceof StructuredViewer) {			
		 ILabelProvider labelProvider = (ILabelProvider) ((StructuredViewer)viewer).getLabelProvider();
		 String text1 = labelProvider.getText(e1);
		 String text2 = labelProvider.getText(e2);
		 if(text1 != null) {			
			 return text1.compareTo(text2);
		 }
	}
	return -1;
}
 
Example 15
Source File: TableColumnSorter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected int doCompare(Viewer v, Object e1, Object e2) {
      Assert.isTrue(v == viewer);
      ILabelProvider labelProvider = (ILabelProvider) viewer.getLabelProvider(columnIndex);
	String t1 = labelProvider.getText(e1);
	String t2 = labelProvider.getText(e2);
	if (t1 == null) t1 = "";
	if (t2 == null) t2 = "";
	return t1.compareToIgnoreCase(t2);
}