⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 artisttreelabelprovider.java

📁 eclise rcp 项目,是非常好的学习源码
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2007 Siemens AG
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Kai T鰀ter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.views.logical;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.siemens.ct.mp3m.model.logical.Album;
import com.siemens.ct.mp3m.model.logical.Artist;
import com.siemens.ct.mp3m.model.logical.Song;

/**
 * This class provides the labels for the ArtistTableTree application
 */
class ArtistTreeLabelProvider implements ITableLabelProvider {

	private Image artistImage;
	private Image albumImage;
	private Image songImage;

	/**
	 * Gets the image for the specified column
	 * 
	 * @param type
	 *            the Artist, Album or Song
	 * @param column
	 *            the column
	 * 
	 * @return Image
	 */
	public Image getColumnImage(Object type, int column) {
		// This does not work with column 0...
		if (type instanceof Song && column == 0) {
			if (songImage == null) {
				ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
						"com.siemens.ct.mp3m.ui.views.logical", "icons/song.gif");
				songImage = imageDescriptor.createImage();
			}
			return songImage;
		} else if (type instanceof Album && column == 0) {
			if (albumImage == null) {
				ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
						"com.siemens.ct.mp3m.ui.views.logical", "icons/cd.gif");
				albumImage = imageDescriptor.createImage();
			}
			return albumImage;
		} else if (type instanceof Artist && column == 0) {
			if (artistImage == null) {
				ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
						"com.siemens.ct.mp3m.ui.views.logical", "icons/artist.gif");
				artistImage = imageDescriptor.createImage();
			}
			return artistImage;
		}

		return null;
	}

	/**
	 * Gets the text for the specified column
	 * 
	 * @param type
	 *            the Artist, Album or Song
	 * @param column
	 *            the column
	 * 
	 * @return String
	 */
	public String getColumnText(Object type, int column) {
		if (type instanceof Artist && column == 0)
			return ((Artist) type).getName();
		else if (type instanceof Album && column == 0)
			return ((Album) type).getName();
		else if (type instanceof Song)
			if (column == 0) {
				return ((Song) type).getName();
			} else if (column == 1) {
				return ((Song) type).getTrack();
			} else if (column == 2) {
				return ((Song) type).getDuration();
			}

		return ""; //$NON-NLS-1$
	}

	public void addListener(ILabelProviderListener listener) {
	}

	public void dispose() {
		if (songImage != null) {
			songImage.dispose();
		}
	}

	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -