📄 artisttreecontentprovider.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 java.util.List;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import com.siemens.ct.mp3m.model.logical.Album;
import com.siemens.ct.mp3m.model.logical.Artist;
import com.siemens.ct.mp3m.model.logical.Artists;
import com.siemens.ct.mp3m.model.logical.Song;
import com.siemens.ct.mp3m.model.physical.MusicFolders;
import com.siemens.ct.mp3m.model.physical.MusicFoldersChangeListener;
/**
* This class provides the content for the TableTreeViewer in ArtistTableTree
*/
class ArtistTreeContentProvider implements ITreeContentProvider, MusicFoldersChangeListener {
/**
*
*/
private final LogicalView view;
private final Object[] EMPTY = new Object[] {};
public ArtistTreeContentProvider(LogicalView view) {
this.view = view;
MusicFolders.addChangeListener(this);
}
/**
* Gets the children for Artist or Album
*
* @param parent
* the team or Artist
*
* @return Object[]
*/
public Object[] getChildren(Object parent) {
if (parent instanceof Artist) {
return ((Artist) parent).getAlbums().toArray();
} else if (parent instanceof Album) {
return ((Album) parent).getSongs().toArray();
}
// Titles have no children
return EMPTY;
}
/**
* Gets the parent artist for an Album
*
* @param child
* the Album
*
* @return Object
*/
public Object getParent(Object child) {
if (child instanceof Song) {
return ((Song) child).getAlbum();
} else if (child instanceof Album) {
return ((Album) child).getArtist();
}
return null;
}
/**
* Gets whether this team or Artist has children
*
* @param arg0
* the team or Artist
*
* @return boolean
*/
public boolean hasChildren(Object arg0) {
return getChildren(arg0).length > 0;
}
/**
* Gets the elements for the table
*
* @param arg0
* the model
*
* @return Object[]
*/
public Object[] getElements(Object arg0) {
// Returns all the teams in the model
return Artists.getArtists();
}
/**
* Disposes any resources
*/
public void dispose() {
// We don't create any resources, so we don't dispose any
}
/**
* Called when the input changes
*
* @param arg0
* the parent viewer
* @param arg1
* the old input
* @param arg2
* the new input
*/
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// Nothing to do
}
@SuppressWarnings("deprecation")
public void musicFoldersChanged(List<String> folders) {
if (this.view.treeViewer != null) {
/*
Table table = this.view.ttv.getTableTree().getTable();
// Expand everything
this.view.ttv.expandAll();
// Pack the columns
for (int i = 0, n = table.getColumnCount(); i < n; i++) {
table.getColumn(i).pack();
}
*/
this.view.treeViewer.refresh();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -