Java Code Examples for org.eclipse.ui.model.IWorkbenchAdapter#getLabel()

The following examples show how to use org.eclipse.ui.model.IWorkbenchAdapter#getLabel() . 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: NodeStatsTableControl.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public String getColumnText(Object element, int columnIndex) {
  GraphNode node = getGraphNode(element);
  if (null != node) {
    switch (columnIndex) {
    case INDEX_NAME:
      return node.toString();
    case INDEX_RANK:
      return getRank(node);
    case INDEX_PREDS:
      return getPredecessorCount(node);
    case INDEX_SUCCS:
      return getSuccessorCount(node);
    }
  }
  IWorkbenchAdapter item = getWorkbenchAdapter(element);
  if (null != item) {
    switch (columnIndex) {
    case INDEX_NAME:
      return item.getLabel(element);
    }
  }
  return null;
}
 
Example 2
Source File: NodeDisplayTableControl.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public String getColumnText(Object element, int columnIndex) {
  GraphNode node = getGraphNode(element);
  if (null != node) {
    switch (columnIndex) {
    case INDEX_NAME:
      return node.toString();
    case INDEX_XPOS:
      return getXPos(node);
    case INDEX_YPOS:
      return getYPos(node);
    case INDEX_COLOR:
      return getColorName(node);
    case INDEX_SIZE:
      return getSizeName(node);
    }
  }
  IWorkbenchAdapter item = getWorkbenchAdapter(element);
  if (null != item) {
    switch (columnIndex) {
    case INDEX_NAME:
      return item.getLabel(element);
    }
  }
  return null;
}
 
Example 3
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 4
Source File: JavaSearchPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private SearchPatternData tryStructuredSelection(IStructuredSelection selection) {
	if (selection == null || selection.size() > 1)
		return null;

	Object o= selection.getFirstElement();
	SearchPatternData res= null;
	if (o instanceof IJavaElement) {
		res= determineInitValuesFrom((IJavaElement) o);
	} else if (o instanceof LogicalPackage) {
		LogicalPackage lp= (LogicalPackage)o;
		return new SearchPatternData(PACKAGE, REFERENCES, 0, fIsCaseSensitive, lp.getElementName(), null, getLastIncludeMask());
	} else if (o instanceof IAdaptable) {
		IJavaElement element= (IJavaElement) ((IAdaptable) o).getAdapter(IJavaElement.class);
		if (element != null) {
			res= determineInitValuesFrom(element);
		}
	}
	if (res == null && o instanceof IAdaptable) {
		IWorkbenchAdapter adapter= (IWorkbenchAdapter)((IAdaptable)o).getAdapter(IWorkbenchAdapter.class);
		if (adapter != null) {
			return new SearchPatternData(TYPE, REFERENCES, 0, fIsCaseSensitive, adapter.getLabel(o), null, getLastIncludeMask());
		}
	}
	return res;
}
 
Example 5
Source File: WorkbenchAdapter.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A convenience method for getting the label of an adaptable
 * object that responds to the IWorkbenchAdapter adapter interface.
 * Returns a toString() of the object if it is not adaptable
 */
public static String getElementLabel(IAdaptable a) {
	if (a == null) {
		return "";//$NON-NLS-1$
	}
	IWorkbenchAdapter adapter = (IWorkbenchAdapter)a.getAdapter(IWorkbenchAdapter.class);
	if (adapter != null) {
		return adapter.getLabel(a);
	} else {
		return a.toString();
	}
}
 
Example 6
Source File: StatusBarUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected String formatMessage(ISelection sel) {
	if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
		IStructuredSelection selection= (IStructuredSelection) sel;

		int nElements= selection.size();
		if (nElements > 1) {
			return Messages.format(JavaUIMessages.StatusBarUpdater_num_elements_selected, String.valueOf(nElements));
		} else {
			Object elem= selection.getFirstElement();
			if (elem instanceof IJavaElement) {
				return formatJavaElementMessage((IJavaElement) elem);
			} else if (elem instanceof IResource) {
				return formatResourceMessage((IResource) elem);
			} else if (elem instanceof PackageFragmentRootContainer) {
				PackageFragmentRootContainer container= (PackageFragmentRootContainer) elem;
				return container.getLabel() + JavaElementLabels.CONCAT_STRING + container.getJavaProject().getElementName();
			} else if (elem instanceof IJarEntryResource) {
				IJarEntryResource jarEntryResource= (IJarEntryResource) elem;
				StringBuffer buf= new StringBuffer(BasicElementLabels.getResourceName(jarEntryResource.getName()));
				buf.append(JavaElementLabels.CONCAT_STRING);
				IPath fullPath= jarEntryResource.getFullPath();
				if (fullPath.segmentCount() > 1) {
					buf.append(BasicElementLabels.getPathLabel(fullPath.removeLastSegments(1), false));
					buf.append(JavaElementLabels.CONCAT_STRING);
				}
				buf.append(JavaElementLabels.getElementLabel(jarEntryResource.getPackageFragmentRoot(), JavaElementLabels.ROOT_POST_QUALIFIED));
				return buf.toString();
			} else if (elem instanceof IAdaptable) {
				IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)elem).getAdapter(IWorkbenchAdapter.class);
				if (wbadapter != null) {
					return wbadapter.getLabel(elem);
				}
			}
		}
	}
	return "";  //$NON-NLS-1$
}
 
Example 7
Source File: NamePatternFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if (fMatchers.length == 0) {
		return true;
	}
	String matchName= null;
	if (element instanceof IJavaElement) {
		matchName= ((IJavaElement) element).getElementName();
	} else if (element instanceof IResource) {
		matchName= ((IResource) element).getName();
	} else if (element instanceof IStorage) {
		matchName= ((IStorage) element).getName();
	} else if (element instanceof IWorkingSet) {
		matchName= ((IWorkingSet) element).getLabel();
	} else if (element instanceof IAdaptable) {
		IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)element).getAdapter(IWorkbenchAdapter.class);
		if (wbadapter != null) {
			matchName= wbadapter.getLabel(element);
		}
	}
	if (matchName != null && matchName.length() > 0) {
		StringMatcher[] testMatchers= getMatchers();
		for (int i = 0; i < testMatchers.length; i++) {
			if (testMatchers[i].match(matchName))
				return false;
		}
		return true;
	}
	return true;
}
 
Example 8
Source File: WorkbenchLabelProvider.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public final String getText(Object element) {
	// query the element for its label
	IWorkbenchAdapter adapter = getAdapter(element);
	if (adapter == null) {
		return ""; //$NON-NLS-1$
	}
	String label = adapter.getLabel(element);

	// return the decorated label
	return decorateText(label, element);
}
 
Example 9
Source File: WorkbenchLabelProvider.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public final String getText(Object element) {
	// query the element for its label
	IWorkbenchAdapter adapter = getAdapter(element);
	if (adapter == null) {
		return ""; //$NON-NLS-1$
	}
	String label = adapter.getLabel(element);

	// return the decorated label
	return decorateText(label, element);
}
 
Example 10
Source File: CopiedWorkbenchLabelProvider.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String getText(Object element) {
    //query the element for its label
    IWorkbenchAdapter adapter = getAdapter(element);
    if (adapter == null) {
        return ""; //$NON-NLS-1$
    }
    String label = adapter.getLabel(element);

    //return the decorated label
    return decorateText(label, element);
}
 
Example 11
Source File: PythonBreakpointPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the name of the given element.
 *
 * @param element
 *            the element
 * @return the name of the element
 */
private String getName(IAdaptable element) {
    IWorkbenchAdapter adapter = element.getAdapter(IWorkbenchAdapter.class);
    if (adapter != null) {
        return adapter.getLabel(element);
    }
    return "";//$NON-NLS-1$
}