Package com.simonepezzano.hshare.providers

Source Code of com.simonepezzano.hshare.providers.TreeFilesLabelProvider

package com.simonepezzano.hshare.providers;

import java.io.File;

import org.dom4j.Attribute;
import org.dom4j.Element;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.program.Program;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import com.simonepezzano.hshare.HFiles;
import com.simonepezzano.hshare.Statics;

/**
* The label provider for the tree displaying the shares
* @author Simone Pezzano
*
*/
public class TreeFilesLabelProvider implements ITableLabelProvider {
  public static final int COLUMN_NAME = 0;
  public static final int COLUMN_SIZE = 1;
  public static final int COLUMN_AKA = 2;
  public static final int COLUMN_COMMENT = 3;
  private Image imgFolder;
  private Image imgFile;
  public TreeFilesLabelProvider(){
    imgFolder = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
    imgFile = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
  }
 
  public Image getColumnImage(Object element, int columnIndex) {
    Element e = ((Element)element);
    if(columnIndex == 0){
      if(Statics.isADir(e))
        return imgFolder;
      int lastDotPos = new File(e.getStringValue()).getName().lastIndexOf('.');
        if (lastDotPos == -1||lastDotPos==0)
          return imgFile;
        Program program = Program.findProgram(e.getStringValue().substring(lastDotPos + 1));
        if(program==null)
          return imgFile;
        return new Image(PlatformUI.getWorkbench().getDisplay(),program.getImageData());
       
    }
    return null;
  }

  public String getColumnText(Object element, int columnIndex) {
    Element el = ((Element)element);
    switch(columnIndex){
      case COLUMN_NAME:
                if(el.getName().equals("dir"))
                  return el.attributeValue("path");
                return el.getStringValue();
      case COLUMN_SIZE:
                if(el.getName().equals("dir"))
                  return String.valueOf(el.elements().size())+" items";
                return Statics.getSize(HFiles.getInstance().getFileByElement(el));
      case COLUMN_AKA:
                Attribute aka = el.attribute("aka");
                if(aka != null)
                  return aka.getStringValue();
                return "";
      case COLUMN_COMMENT:
                Attribute comm = el.attribute("comment");
                if(comm != null)
                  return comm.getStringValue();
                return "";
      default: return "";
         
    }
  }

  public void addListener(ILabelProviderListener listener) {
    // TODO Auto-generated method stub

  }

  public void dispose() {
    // TODO Auto-generated method stub

  }

  public boolean isLabelProperty(Object element, String property) {
    // TODO Auto-generated method stub
    return false;
  }

  public void removeListener(ILabelProviderListener listener) {
    // TODO Auto-generated method stub

  }

}
TOP

Related Classes of com.simonepezzano.hshare.providers.TreeFilesLabelProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.