KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > NamedHandleObjectLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jface.viewers;
13
14 import org.eclipse.core.commands.common.NamedHandleObject;
15 import org.eclipse.core.commands.common.NotDefinedException;
16
17 /**
18  * A label provider for instances of <code>NamedHandlerObject</code>, which
19  * exposes the name as the label.
20  *
21  * @since 3.2
22  */

23 public final class NamedHandleObjectLabelProvider extends LabelProvider {
24     
25     /**
26      * The text of the element is simply the name of the element if its a
27      * defined instance of <code>NamedHandleObject</code>. Otherwise, this
28      * method just returns <code>null</code>.
29      *
30      * @param element
31      * The element for which the text should be retrieved; may be
32      * <code>null</code>.
33      * @return the name of the handle object; <code>null</code> if there is no
34      * name or if the element is not a named handle object.
35      */

36     public final String JavaDoc getText(final Object JavaDoc element) {
37         if (element instanceof NamedHandleObject) {
38             try {
39                 return ((NamedHandleObject) element).getName();
40             } catch (final NotDefinedException e) {
41                 return null;
42             }
43         }
44
45         return null;
46     }
47 }
48
Popular Tags