All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jface.viewers.NamedHandleObjectLabelProvider Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2005, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.jface.viewers;

import org.eclipse.core.commands.common.NamedHandleObject;
import org.eclipse.core.commands.common.NotDefinedException;

/**
 * A label provider for instances of NamedHandlerObject, which
 * exposes the name as the label.
 *
 * @since 3.2
 */
public final class NamedHandleObjectLabelProvider extends LabelProvider {

	/**
	 * The text of the element is simply the name of the element if its a
	 * defined instance of NamedHandleObject. Otherwise, this
	 * method just returns null.
	 *
	 * @param element
	 *            The element for which the text should be retrieved; may be
	 *            null.
	 * @return the name of the handle object; null if there is no
	 *         name or if the element is not a named handle object.
	 */
	@Override
	public final String getText(final Object element) {
		if (element instanceof NamedHandleObject) {
			try {
				return ((NamedHandleObject) element).getName();
			} catch (final NotDefinedException e) {
				return null;
			}
		}

		return null;
	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy