01: /*******************************************************************************
02: * Copyright (c) 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jface.viewers;
11:
12: import org.eclipse.core.commands.common.NamedHandleObject;
13: import org.eclipse.core.commands.common.NotDefinedException;
14:
15: /**
16: * A label provider for instances of <code>NamedHandlerObject</code>, which
17: * exposes the name as the label.
18: *
19: * @since 3.2
20: */
21: public final class NamedHandleObjectLabelProvider extends LabelProvider {
22:
23: /**
24: * The text of the element is simply the name of the element if its a
25: * defined instance of <code>NamedHandleObject</code>. Otherwise, this
26: * method just returns <code>null</code>.
27: *
28: * @param element
29: * The element for which the text should be retrieved; may be
30: * <code>null</code>.
31: * @return the name of the handle object; <code>null</code> if there is no
32: * name or if the element is not a named handle object.
33: */
34: public final String getText(final Object element) {
35: if (element instanceof NamedHandleObject) {
36: try {
37: return ((NamedHandleObject) element).getName();
38: } catch (final NotDefinedException e) {
39: return null;
40: }
41: }
42:
43: return null;
44: }
45: }
|