/*!
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2002-2013 Pentaho Corporation.. All rights reserved.
*/
package org.pentaho.reporting.designer.extensions.pentaho.repository.util;
import java.awt.Component;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileType;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
public class RepositoryTreeCellRenderer extends DefaultTreeCellRenderer {
public RepositoryTreeCellRenderer() {
}
public Component getTreeCellRendererComponent( final JTree tree,
final Object value,
final boolean sel,
final boolean expanded,
final boolean leaf,
final int row,
final boolean hasFocus ) {
final JLabel component =
(JLabel) super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus );
if ( value instanceof FileObject ) {
final FileObject node = (FileObject) value;
try {
if ( leaf && ( node.getType() == FileType.FOLDER ) ) {
component.setIcon( getOpenIcon() );
}
} catch ( FileSystemException fse ) {
// ignore exception here
}
component.setText( node.getName().getBaseName() );
} else {
component.setText( "/" );
component.setIcon( getOpenIcon() );
}
return component;
}
}