package nc.pub.filesystem.newui;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Collection;

import nc.ui.pub.beans.ScaleSlider;
import nc.vo.pub.filesystem.FileTypeConst;
import nc.vo.pub.filesystem.NCFileNode;
import nc.vo.pub.filesystem.NCFileVO;
/**
 * 创建各种浏览方式的 panel 及显示数据
 * @author zhoujja
 *
 */
public class TestFileBrowseCreatePane {
	/**
	 * 缩略图显示
	 * @param parentpanel
	 */
	protected static void  createSmallImagePane(TestFileContentPanel parentpanel) {
		NCFileNode selnode =  parentpanel.selfoldernode;
		Collection<NCFileVO> ncfilevos  =null ;
		if(selnode==null||selnode.getFullPath().equalsIgnoreCase(parentpanel.rootDirStr)){
			ncfilevos = parentpanel.getTreenodefilecacheMap().get("root");
		}else{
			ncfilevos = parentpanel.getTreenodefilecacheMap().get(selnode.getFullPath());
		}
		ArrayList<NCFileVO> listimagefilevo = new ArrayList<NCFileVO>();
		//列出图片类型
		if(ncfilevos!=null)
		for(NCFileVO fvo:ncfilevos){
			if(fvo.getFiletype()!=null &&fvo.getFiletype().equals(FileTypeConst.IMAGE)){
				listimagefilevo.add(fvo);
			}
		}
		parentpanel.refreshStatuBar();
//		
		if(listimagefilevo==null||listimagefilevo.size()==0){
			if(parentpanel.PAGE_STATE==parentpanel.BROWSESMALLICON_STATE){
				parentpanel.getTablepanel().removeAll();
				parentpanel.getTablepanel().updateUI();
			}
//			MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("sftemp", "UploadURLAction-0005")/*提示*/, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseCreatePane-0000")/*未发现没有图片类型附件！*/);
			
			return ;
		}
		//新上传的附件，在树的节点中没存主键，从数据库获取主主键，按主键下载到本地
		FileBroseConst.setFileVOPK(listimagefilevo);
		
		parentpanel.getTablepanel().removeAll();
		parentpanel.getTablepanel().add(new TestSmallImageBrowsePanel(listimagefilevo,parentpanel),BorderLayout.CENTER);
		
		parentpanel.getTablepanel().updateUI();
		parentpanel.getScaleSliderPane().removeAll();
		parentpanel.getScaleSliderPane().updateUI();
	}
	/**
	 * 列表显示
	 * @param parentpanel
	 */
	protected static void  createListBrowsePane(TestFileContentPanel parentpanel){
		parentpanel.getTablepanel().removeAll();
//		
		NCFileVO[] arr_treevos;
		if(parentpanel.getPatchInfoTable().getCellEditor()!=null){
			parentpanel.getPatchInfoTable().getCellEditor().stopCellEditing();
		}
		if (parentpanel.selfoldernode==null||parentpanel.selfoldernode.getFullPath().equalsIgnoreCase(parentpanel.rootDirStr)) {
			if (parentpanel.getTreenodefilecacheMap().get("root") != null) {
				// 更新表
				arr_treevos = parentpanel.getTreenodefilecacheMap().get("root").toArray(
						new NCFileVO[0]);
				parentpanel.getfiletablemodel().clearTable();
				parentpanel.getfiletablemodel().addVO(arr_treevos);
				parentpanel.getfiletablemodel().refreshTable();
				parentpanel.getPatchInfoTable().repaint();
				if (parentpanel.getPatchInfoTable().getRowCount() > 0) {
					parentpanel.getPatchInfoTable().setRowSelectionInterval(0, 0);
				}
				
				// 更新状态栏(几个附件，大小)
				//refresh statusbar 
				parentpanel.refreshStatuBar();
				
			}else{
				
			}
		}
		else if (parentpanel.selfoldernode!=null&&parentpanel.getTreenodefilecacheMap().get(parentpanel.selfoldernode.getFullPath()) != null) {
			arr_treevos = parentpanel.getTreenodefilecacheMap().get(
					parentpanel.selfoldernode.getFullPath()).toArray(new NCFileVO[0]);
			parentpanel.getfiletablemodel().clearTable();
			parentpanel.getfiletablemodel().addVO(arr_treevos);
			parentpanel.getfiletablemodel().refreshTable();
			parentpanel.getPatchInfoTable().repaint();
			if (parentpanel.getPatchInfoTable().getRowCount() > 0) {
				parentpanel.getPatchInfoTable().setRowSelectionInterval(0, 0);
			}
			//refresh statusbar 
			// 更新状态栏(几个附件，大小)
			parentpanel.refreshStatuBar();
			
		}else{
			parentpanel.getfiletablemodel().clearTable();
			// 更新状态栏(几个附件，大小)
			//refresh statusbar 
			parentpanel.refreshStatuBar();
		}
		
		parentpanel.getTablepanel().add(parentpanel.getJstablepanel(),BorderLayout.CENTER);
		parentpanel.getTablepanel().updateUI();
		
		parentpanel.getScaleSliderPane().removeAll();
		parentpanel.getScaleSliderPane().updateUI();
	}
	/**
	 * 单张显示
	 * @param parentpanel
	 * @param scaleSlider
	 */
	protected static void  createSingleBrosePane(TestFileContentPanel parentpanel,ScaleSlider scaleSlider ){
		NCFileNode selnode =  parentpanel.selfoldernode;
		Collection<NCFileVO> ncfilevos  =null ;
		if(selnode==null||selnode.getFullPath().equalsIgnoreCase(parentpanel.rootDirStr)){
			ncfilevos = parentpanel.getTreenodefilecacheMap().get("root");
		}else{
			ncfilevos = parentpanel.getTreenodefilecacheMap().get(selnode.getFullPath());
		}
		ArrayList<NCFileVO> listimagefilevo = new ArrayList<NCFileVO>();
		//列出图片类型
		if(ncfilevos!=null)
		for(NCFileVO fvo:ncfilevos){
			if(fvo.getFiletype()!=null &&fvo.getFiletype().equals(FileTypeConst.IMAGE)){
				listimagefilevo.add(fvo);
			}
		}
//		
		parentpanel.refreshStatuBar();
		if(listimagefilevo==null||listimagefilevo.size()==0){
			if(parentpanel.PAGE_STATE==parentpanel.BROWSESINGLEICON_STATE){
				parentpanel.getTablepanel().removeAll();
				parentpanel.getTablepanel().updateUI();
			}
//			MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("sftemp", "UploadURLAction-0005")/*提示*/, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseCreatePane-0000")/*未发现没有图片类型附件！*/);			
			return ;
		}
		//新上传的附件，在树的节点中没存主键，从数据库获取主主键，按主键下载到本地
		FileBroseConst.setFileVOPK(listimagefilevo);
		parentpanel.getScaleSliderPane().removeAll();
		parentpanel.getScaleSliderPane().add(scaleSlider);
		parentpanel.getScaleSliderPane().updateUI();
		parentpanel.getTablepanel().removeAll();
		parentpanel.getTablepanel().add(new TestSingleImageBrowsePanel(listimagefilevo,parentpanel,scaleSlider));
		parentpanel.getTablepanel().repaint();
		parentpanel.getTablepanel().updateUI();
	}
	protected static void  createPPTBrowsePane(TestFileContentPanel parentpanel,ScaleSlider scaleSlider ){
		NCFileNode selnode =  parentpanel.selfoldernode;
		Collection<NCFileVO> ncfilevos  =null ;
		if(selnode==null||selnode.getFullPath().equalsIgnoreCase(parentpanel.rootDirStr)){
			ncfilevos = parentpanel.getTreenodefilecacheMap().get("root");
		}else{
			ncfilevos = parentpanel.getTreenodefilecacheMap().get(selnode.getFullPath());
		}
		ArrayList<NCFileVO> listimagefilevo = new ArrayList<NCFileVO>();
		//列出图片类型
		if(ncfilevos!=null)
		for(NCFileVO fvo:ncfilevos){
			if(fvo.getFiletype()!=null &&fvo.getFiletype().equals(FileTypeConst.IMAGE)){
				listimagefilevo.add(fvo);
			}
		}
//		
		parentpanel.refreshStatuBar();
		if(listimagefilevo==null||listimagefilevo.size()==0){
			if(parentpanel.PAGE_STATE==parentpanel.BROWSEPPTICON_STATE){
				parentpanel.getTablepanel().removeAll();
				parentpanel.getTablepanel().updateUI();
			}
//			MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("sftemp", "UploadURLAction-0005")/*提示*/, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseCreatePane-0000")/*未发现没有图片类型附件！*/);			
			return ;
		}
		
		//新上传的附件，在树的节点中没存主键，从数据库获取主主键，按主键下载到本地
		FileBroseConst.setFileVOPK(listimagefilevo);
		
		//动态生成主界面
		parentpanel.getScaleSliderPane().removeAll();
		parentpanel.getScaleSliderPane().add(scaleSlider);		
		parentpanel.getScaleSliderPane().updateUI();
		parentpanel.getTablepanel().removeAll();
		parentpanel.getTablepanel().add(new TestPPTBrosePanel(listimagefilevo,parentpanel,scaleSlider));
		
		parentpanel.getTablepanel().repaint();
		parentpanel.getTablepanel().updateUI();		

	}
}
