ThFileContentPanel.java 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328
  1. package nc.pub.filesystem.newui;
  2. import nc.vo.arap.utils.StringUtil;
  3. import nc.vo.bd.defdoc.DefdocVO;
  4. import java.awt.BorderLayout;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Cursor;
  8. import java.awt.Dimension;
  9. import java.awt.FlowLayout;
  10. import java.awt.Graphics;
  11. import java.awt.Insets;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ItemEvent;
  15. import java.awt.event.ItemListener;
  16. import java.awt.event.KeyEvent;
  17. import java.awt.event.MouseEvent;
  18. import java.awt.event.MouseMotionAdapter;
  19. import java.io.File;
  20. import java.io.FileFilter;
  21. import java.io.FileOutputStream;
  22. import java.net.InetAddress;
  23. import java.net.URL;
  24. import java.net.UnknownHostException;
  25. import java.util.ArrayList;
  26. import java.util.Arrays;
  27. import java.util.Collection;
  28. import java.util.Enumeration;
  29. import java.util.EventObject;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.Map;
  33. import nc.itf.uap.IUAPQueryBS;
  34. import javax.swing.AbstractAction;
  35. import javax.swing.Action;
  36. import javax.swing.BorderFactory;
  37. import javax.swing.DefaultCellEditor;
  38. import javax.swing.ImageIcon;
  39. import javax.swing.JButton;
  40. import javax.swing.JCheckBox;
  41. import javax.swing.JComponent;
  42. import javax.swing.JFileChooser;
  43. import javax.swing.JLabel;
  44. import javax.swing.JOptionPane;
  45. import javax.swing.JPanel;
  46. import javax.swing.JPopupMenu;
  47. import javax.swing.JScrollPane;
  48. import javax.swing.JTable;
  49. import javax.swing.JTree;
  50. import javax.swing.KeyStroke;
  51. import javax.swing.SpringLayout;
  52. import javax.swing.SwingConstants;
  53. import javax.swing.border.AbstractBorder;
  54. import javax.swing.border.EmptyBorder;
  55. import javax.swing.border.LineBorder;
  56. import javax.swing.event.CellEditorListener;
  57. import javax.swing.event.MouseInputAdapter;
  58. import javax.swing.event.TreeSelectionEvent;
  59. import javax.swing.event.TreeSelectionListener;
  60. import javax.swing.table.TableCellRenderer;
  61. import javax.swing.table.TableColumn;
  62. import javax.swing.table.TableColumnModel;
  63. import javax.swing.tree.DefaultMutableTreeNode;
  64. import javax.swing.tree.DefaultTreeCellEditor;
  65. import javax.swing.tree.DefaultTreeModel;
  66. import javax.swing.tree.TreeNode;
  67. import javax.swing.tree.TreePath;
  68. import nc.ui.uif2.editor.BillForm;
  69. import nc.bs.framework.common.NCLocator;
  70. import nc.bs.framework.common.RuntimeEnv;
  71. import nc.bs.logging.Logger;
  72. import nc.bs.pub.filesystem.IFileSystemActionConst;
  73. import nc.bs.pub.filesystem.IFileSystemService;
  74. import nc.bs.pub.filesystem.IQueryFolderTreeNodeService;
  75. import nc.desktop.ui.WorkbenchEnvironment;
  76. import nc.funcnode.ui.ActionButton;
  77. import nc.funcnode.ui.FuncletMenuBar;
  78. import nc.funcnode.ui.action.AbstractNCAction;
  79. import nc.funcnode.ui.action.SeparatorAction;
  80. import nc.pub.filesystem.newui.control.ActionDelegate;
  81. import nc.pub.filesystem.newui.control.MenuAction;
  82. import nc.pub.filesystem.newui.control.MenuButton;
  83. import nc.pub.filesystem.newui.control.SeparatorButton;
  84. import nc.sfbase.client.ClientToolKit;
  85. import nc.ui.ml.NCLangRes;
  86. import nc.ui.pub.beans.ActionsBar;
  87. import nc.ui.pub.beans.MessageDialog;
  88. import nc.ui.pub.beans.ScaleSlider;
  89. import nc.ui.pub.beans.UIComboBox;
  90. import nc.ui.pub.beans.UIDialog;
  91. import nc.ui.pub.beans.UIPanel;
  92. import nc.ui.pub.beans.UISplitPane;
  93. import nc.ui.pub.beans.UITable;
  94. import nc.ui.pub.beans.UITree;
  95. import nc.ui.pub.beans.table.VOTableModel;
  96. import nc.ui.pub.bill.BillCardPanel;
  97. import nc.ui.pub.filesystem.FileManageServletClient;
  98. import nc.uitheme.ui.ThemeResourceCenter;
  99. import nc.vo.pub.BusinessException;
  100. import nc.vo.pub.ValueObject;
  101. import nc.vo.pub.filesystem.FileTypeConst;
  102. import nc.vo.pub.filesystem.ItemObj;
  103. import nc.vo.pub.filesystem.NCFileNode;
  104. import nc.vo.pub.filesystem.NCFileVO;
  105. import nc.vo.uap.rbac.FuncSubInfo;
  106. import nc.itf.bd.defdoc.IDefdocService;
  107. import nc.bs.framework.common.InvocationInfoProxy;
  108. import nc.jdbc.framework.processor.BeanListProcessor;
  109. public class ThFileContentPanel extends JPanel {
  110. /**
  111. *
  112. */
  113. private static final long serialVersionUID = 5442105336247254657L;
  114. //当前页面的状态
  115. public int PAGE_STATE=BROWSELISTTABLE_STATE;
  116. //列表浏览
  117. public static final int BROWSELISTTABLE_STATE =0;
  118. //ppt浏览
  119. public static final int BROWSEPPTICON_STATE =1;
  120. //单张浏览
  121. public static final int BROWSESINGLEICON_STATE =2;
  122. //缩略图浏览
  123. public static final int BROWSESMALLICON_STATE =3;
  124. protected BillForm editor_;
  125. private int colnumbtnpane =5 ;
  126. private int colnumbtnbrow =1;
  127. protected String rootDirStr = "dir1/dir2/ewei";
  128. //
  129. private String funcode ;
  130. public String getFuncode(){
  131. return funcode;
  132. }
  133. private FuncSubInfo funcsubinfo ;
  134. // IFuncRegisterQueryService.queryFunctionByCode
  135. public String getRootDirStr() {
  136. return rootDirStr;
  137. }
  138. protected NCFileNode rootNode;
  139. protected NCFileNode selfoldernode;
  140. /** 节点上的文件缓存 */
  141. private HashMap<String, Collection<NCFileVO>> treenodefilecacheMap = new HashMap<String, Collection<NCFileVO>>();
  142. private class SmallImageFileFilter implements FileFilter{
  143. @Override
  144. public boolean accept(File pathname) {
  145. int index =pathname.getName().lastIndexOf(".");
  146. if(pathname.isFile()
  147. &&index!=-1
  148. &&pathname.getName().substring(index+1).equalsIgnoreCase("jpg")
  149. ){
  150. return true;
  151. }else{
  152. return false ;
  153. }
  154. }
  155. }
  156. /** 节点上的文件缓存 */
  157. protected HashMap<String, Collection<NCFileVO>> getTreenodefilecacheMap() {
  158. return treenodefilecacheMap;
  159. }
  160. private List<ItemObj> itemlist ;
  161. public List<ItemObj> getItemlist(){
  162. if(itemlist==null){
  163. itemlist = new ArrayList<ItemObj>();
  164. }
  165. return itemlist;
  166. }
  167. public void showcombox(ArrayList<ItemObj>list){
  168. setItemlist(list);
  169. getComboxbilltype().addItems(list.toArray(new ItemObj[0]));
  170. getComboxbilltype().setVisible(true);
  171. getComboxbilltype().validate();
  172. }
  173. public void setItemlist( List<ItemObj> list){
  174. getItemlist().clear();
  175. getItemlist().addAll(list);
  176. }
  177. /** 节点大小缓存 */
  178. private HashMap<String, Long> treefileszieMap = new HashMap<String, Long>();
  179. // /** 构造器 */
  180. // public FileContentPanel(String fcode,String root) {
  181. // super();
  182. // funcode =fcode ;
  183. // rootDirStr = root ;
  184. // initUI();
  185. // }
  186. /** 构造器 */
  187. public ThFileContentPanel(FuncSubInfo pfuncsubinfo,String root) {
  188. super();
  189. this.funcsubinfo=pfuncsubinfo ;
  190. funcode =pfuncsubinfo.getFuncode() ;
  191. rootDirStr = root ;
  192. //设置权限
  193. setUIEnable();
  194. initUI();
  195. }
  196. public ThFileContentPanel(String root,BillForm editor) {
  197. super();
  198. rootDirStr = root ;
  199. editor_ = editor;
  200. //设置权限
  201. initUI();
  202. }
  203. /**
  204. *
  205. */
  206. private void setUIEnable() {
  207. if(funcsubinfo!=null){
  208. uploadenable =funcsubinfo.isValidButton(IFileSystemActionConst.UPLOAD);
  209. downloadenable =funcsubinfo.isValidButton(IFileSystemActionConst.DOWNLOAD);
  210. browseenable =funcsubinfo.isValidButton(IFileSystemActionConst.BROWSE);
  211. deleteenable =funcsubinfo.isValidButton(IFileSystemActionConst.DELETE);
  212. renameenable = funcsubinfo.isValidButton(IFileSystemActionConst.RENAME);
  213. }
  214. }
  215. private void initUI() {
  216. this.setLayout(new BorderLayout());
  217. // add(getToolbar(), BorderLayout.NORTH);
  218. add(getMenuBarContainer(), BorderLayout.NORTH);
  219. add(getSplitpanel(), BorderLayout.CENTER);
  220. add(getStatusbar(), BorderLayout.SOUTH);
  221. IQueryFolderTreeNodeService service = NCLocator
  222. .getInstance().lookup(
  223. IQueryFolderTreeNodeService.class);
  224. //add by ZTH 赋值rootNode
  225. try {
  226. NCFileNode node = service.getNCFileNodeTreeAndCreateAsNeed(
  227. rootDirStr, WorkbenchEnvironment.getInstance()
  228. .getLoginUser().getCuserid());
  229. rootNode = findNode(node, rootDirStr);
  230. } catch (BusinessException e) {
  231. // TODO 自动生成的 catch 块
  232. e.printStackTrace();
  233. }
  234. if(!StringUtil.isEmpty(rootDirStr)){
  235. // rootnode 放入缓存
  236. toCache(rootNode);
  237. //设置默认选中根节点
  238. TreePath path = new TreePath(rootNode);
  239. getPatchTree().setSelectionPath(path);
  240. }
  241. }
  242. /** 新建文件夹 action */
  243. private NewFolderAction newfolderaction;
  244. public NewFolderAction getNewfolderaction() {
  245. if (newfolderaction == null) {
  246. newfolderaction = new NewFolderAction();
  247. }
  248. return newfolderaction;
  249. }
  250. /** 重命名 action */
  251. private RenameFolderAction renamefolderaction;
  252. public RenameFolderAction getRenamefolderaction() {
  253. if (renamefolderaction == null) {
  254. renamefolderaction = new RenameFolderAction();
  255. }
  256. return renamefolderaction;
  257. }
  258. /** 删除文件夹(文件) action */
  259. private DelFolderAction delfolderaction;
  260. public DelFolderAction getDelfolderaction() {
  261. if (delfolderaction == null) {
  262. delfolderaction = new DelFolderAction();
  263. }
  264. return delfolderaction;
  265. }
  266. private JPanel statusbar;
  267. private UIPanel scaleSliderPane =null;
  268. UIPanel getScaleSliderPane(){
  269. if(scaleSliderPane == null){
  270. scaleSliderPane=new UIPanel();
  271. // scaleSlider.setPreferredSize(new Dimension(220,30));
  272. // scaleSlider.setBorder(new LineBorder(Color.RED));
  273. scaleSliderPane.setOpaque(false);
  274. }
  275. return scaleSliderPane ;
  276. }
  277. public JPanel getStatusbar() {
  278. if (statusbar == null) {
  279. statusbar = new JPanel();
  280. statusbar.setPreferredSize(new Dimension(0, 35));
  281. statusbar.setBorder(new LineBorder(Color.gray));
  282. statusbar.setBackground(FileColorConst.BOTTOMCOLOR);
  283. // FlowLayout mgr = new FlowLayout();
  284. // mgr.setAlignment(FlowLayout.LEFT);
  285. BorderLayout mgr = new BorderLayout();
  286. statusbar.setLayout(mgr);
  287. statusbar.add(getLblstatubar(),BorderLayout.WEST);
  288. statusbar.add(getScaleSliderPane(),BorderLayout.EAST);
  289. }
  290. return statusbar;
  291. }
  292. private JLabel lblstatubar;
  293. public JLabel getLblstatubar() {
  294. if (lblstatubar == null) {
  295. lblstatubar = new JLabel("");
  296. }
  297. return lblstatubar;
  298. }
  299. private class CMouseHandler extends MouseInputAdapter {
  300. @Override
  301. public void mouseReleased(MouseEvent e) {
  302. if (e.isPopupTrigger()) {
  303. showPopupMenu(e);
  304. }
  305. }
  306. }
  307. public void showPopupMenu(MouseEvent e) {
  308. //根节点不弹出
  309. ArrayList<TreePath> list = new ArrayList<TreePath>();
  310. TreePath tp = getPatchTree().getPathForLocation(e.getX(), e.getY());
  311. if (tp != null) {
  312. list.add(tp);
  313. }
  314. if (e.isControlDown()) {
  315. TreePath[] tps = getPatchTree().getSelectionPaths();
  316. if (tps != null && tps.length > 0) {
  317. list.addAll(Arrays.asList(tps));
  318. }
  319. }
  320. getPatchTree().setSelectionPaths(list.toArray(new TreePath[0]));
  321. if(tp!=null&&tp.getLastPathComponent().equals(rootNode)){
  322. return;
  323. }
  324. getTreepopMenu().show(getPatchTree(), e.getX(), e.getY());
  325. }
  326. /** 树的右键菜单 */
  327. private JPopupMenu treepopMenu;
  328. /** 树右键菜单 删除action*/
  329. private DelFolderPopupAction delfolderPopAction;
  330. /** 树右键菜单 删除action */
  331. public DelFolderPopupAction getDelfolderPopAction(){
  332. if(delfolderPopAction == null){
  333. delfolderPopAction = new DelFolderPopupAction();
  334. }
  335. return delfolderPopAction ;
  336. }
  337. /** 树右键菜单重命名action*/
  338. private RenameFolderPopupAction renamefolderPopAction ;
  339. /** 树右键菜单重命名action*/
  340. public RenameFolderPopupAction getRenamefolderPopAction(){
  341. if(renamefolderPopAction == null ){
  342. renamefolderPopAction =new RenameFolderPopupAction() ;
  343. }
  344. return renamefolderPopAction ;
  345. }
  346. /** 树右键菜单新建action*/
  347. private NewFolderPopupAction newfolderPopAction;
  348. /** 树右键菜单新建action*/
  349. public NewFolderPopupAction getNewfolderPopAction(){
  350. if(newfolderPopAction == null){
  351. newfolderPopAction = new NewFolderPopupAction();
  352. }
  353. return newfolderPopAction ;
  354. }
  355. /** 获取树右键菜单*/
  356. private JPopupMenu getTreepopMenu() {
  357. if (treepopMenu == null) {
  358. treepopMenu = new JPopupMenu();
  359. treepopMenu.add(getNewfolderPopAction());
  360. treepopMenu.addSeparator();
  361. treepopMenu.add(getDelfolderPopAction());
  362. treepopMenu.add(getRenamefolderPopAction());
  363. // treepopMenu.add(new NewFolderPopupAction());
  364. // treepopMenu.addSeparator();
  365. // popMenu.add(getUploadFileAction());
  366. // popMenu.add(getUpscan());
  367. // popMenu.add(getDownLoadFileAction());
  368. // popMenu.addSeparator();
  369. // popMenu.add(getRefreshAction());
  370. // popMenu.add(getShowFileInWebAction());
  371. }
  372. return treepopMenu;
  373. }
  374. /** 上传action */
  375. private ThUploadAction uploadAction = new ThUploadAction(ThFileContentPanel.this);//上传附件类
  376. /**ocr识别*/
  377. private ThOCRAction thocrAction = new ThOCRAction(ThFileContentPanel.this);//ocr识别
  378. /** 引用文档ation */
  379. private ThUploadRefAction uprefaction = new ThUploadRefAction(ThFileContentPanel.this);
  380. private ThUploadURLAction uploadurlaction = new ThUploadURLAction(ThFileContentPanel.this);
  381. private ActionButton btnupdateURL;
  382. /** 引用文档 --废弃了*/
  383. private JButton btnuploadrefcenter;
  384. public ActionButton getBtnupdateURL(){
  385. if(btnupdateURL==null){
  386. btnupdateURL = new ActionButton(uploadurlaction);
  387. }
  388. return btnupdateURL;
  389. }
  390. private JButton btnupload;
  391. private JButton btnocr;
  392. /* 2010-10-24 以下按照uif2 画button 工具栏***/
  393. ActionButton getupmenu(){
  394. if(btnupload==null){
  395. btnupload =new ActionButton(uploadAction);
  396. }
  397. return (ActionButton)btnupload;
  398. }
  399. ActionButton getocrmenu(){
  400. if(btnocr==null){
  401. btnocr =new ActionButton(thocrAction);
  402. }
  403. return (ActionButton)btnocr;
  404. }
  405. ActionButton getuprefmenu(){
  406. if(btnuploadrefcenter==null){
  407. btnuploadrefcenter =new ActionButton(uprefaction);
  408. }
  409. return (ActionButton)btnuploadrefcenter;
  410. }
  411. ActionButton getGpyimenu(){
  412. if(btngpy==null){
  413. btngpy =new ActionButton(gpyaction);
  414. }
  415. return (ActionButton)btngpy;
  416. }
  417. ActionButton getPastemenu(){
  418. if(btnpaste==null){
  419. btnpaste =new ActionButton(pasteaction);
  420. //快捷键测试
  421. btnpaste.registerKeyboardAction(pasteaction, KeyStroke.getKeyStroke(KeyEvent.VK_V,KeyEvent.CTRL_DOWN_MASK ), JComponent.WHEN_IN_FOCUSED_WINDOW);
  422. //快捷键测试
  423. btnpaste.setMnemonic(KeyEvent.VK_V);
  424. }
  425. return (ActionButton)btnpaste;
  426. }
  427. ThScanAttachAction scanattachaction ;
  428. public ThScanAttachAction getScanattachaction(){
  429. if(scanattachaction == null){
  430. scanattachaction =(new ThScanAttachAction(ThFileContentPanel.this));
  431. }
  432. return scanattachaction;
  433. }
  434. private ThScanAttachAction scanpptaction;
  435. public ThScanAttachAction getScanpptaction(){
  436. if(scanpptaction == null){
  437. scanpptaction = new ThScanAttachAction(ThFileContentPanel.this);
  438. }
  439. return scanpptaction;
  440. }
  441. private ThScanAttachAction scansingleaction;
  442. public ThScanAttachAction getScansingleaction(){
  443. if(scansingleaction == null){
  444. scansingleaction = new ThScanAttachAction(ThFileContentPanel.this);
  445. }
  446. return scansingleaction;
  447. }
  448. private ThScanAttachAction scansmallaction;
  449. public ThScanAttachAction getScansmallaction(){
  450. if(scansmallaction == null){
  451. scansmallaction = new ThScanAttachAction(ThFileContentPanel.this);
  452. }
  453. return scansmallaction;
  454. }
  455. MenuButton btnscanimage ;
  456. MenuButton getScangrpmenu(){
  457. if(btnscanimage==null){
  458. ActionDelegate pde = new ActionDelegate();
  459. pde.setAction(getBtnscanimage());
  460. ActionDelegate cde1 = new ActionDelegate();
  461. ActionDelegate cde2 = new ActionDelegate();
  462. ActionDelegate cde3 = new ActionDelegate();
  463. ActionDelegate cde4 = new ActionDelegate();
  464. cde1.setAction(getScanattachaction());
  465. cde2.setAction(getScanpptaction());
  466. cde3.setAction(getScansingleaction());
  467. cde4.setAction(getScansmallaction());
  468. pde.addChild(cde1);
  469. pde.addChild(cde2);
  470. pde.addChild(cde3);
  471. pde.addChild(cde4);
  472. btnscanimage =new MenuButton(pde);
  473. }
  474. return btnscanimage;
  475. }
  476. private static ImageIcon menuBarBGIcon = ThemeResourceCenter.getInstance().getImage("themeres/control/menu/menu_bg.png");
  477. private static ImageIcon menuBarBGFrameIcon = ThemeResourceCenter.getInstance().getImage("themeres/control/menu/menu_bg_frame.png");
  478. private JPanel menuBarContainer ;
  479. JPanel getMenuBarContainer() {
  480. if(menuBarContainer == null){
  481. menuBarContainer = new JPanel(){
  482. private static final long serialVersionUID = 7130908951757832647L;
  483. @Override
  484. protected void paintComponent(Graphics g) {
  485. super.paintComponent(g);
  486. Dimension size = getSize();
  487. if(menuBarBGIcon != null && menuBarBGFrameIcon != null){
  488. int frameW = menuBarBGFrameIcon.getIconWidth();
  489. g.drawImage(menuBarBGIcon.getImage(), frameW, 0, size.width-2*frameW, size.height, this);
  490. menuBarBGFrameIcon.paintIcon(this, g, 0, 0);
  491. menuBarBGFrameIcon.paintIcon(this, g, size.width - frameW, 0);
  492. }
  493. }
  494. };
  495. menuBarContainer.setOpaque(false);
  496. menuBarContainer.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
  497. menuBarContainer.setLayout(new BorderLayout());
  498. menuBarContainer.add(getBar(), BorderLayout.CENTER);
  499. menuBarContainer.add(getComboxbilltype(),BorderLayout.EAST);
  500. getBar().setOpaque(false);
  501. }
  502. return menuBarContainer;
  503. }
  504. private UIComboBox comboxbilltype;
  505. public UIComboBox getComboxbilltype(){
  506. if(comboxbilltype == null){
  507. comboxbilltype = new UIComboBox();
  508. comboxbilltype.setPreferredSize(new Dimension(140,18));
  509. comboxbilltype.setVisible(false);
  510. // comboxbilltype.addItem("某单据类型1");
  511. // comboxbilltype.addItem("某单据类型2222");
  512. comboxbilltype.setSize(140,18);
  513. comboxbilltype.addItemListener(new ItemListener(){
  514. @Override
  515. public void itemStateChanged(ItemEvent e) {
  516. if (e.getStateChange() != ItemEvent.SELECTED){
  517. return ;
  518. }else{
  519. //浏览状态
  520. PAGE_STATE=BROWSELISTTABLE_STATE;
  521. treenodefilecacheMap.clear();
  522. treefileszieMap.clear();
  523. treemodel=null;
  524. ItemObj item =(ItemObj) getComboxbilltype().getSelectedItem();
  525. rootDirStr =item.getRootname();
  526. treemodel=getTreemodel();
  527. getPatchTree().setModel(treemodel);
  528. getPatchTree().updateUI();
  529. getfiletablemodel().clearTable();
  530. // rootnode 放入缓存
  531. toCache(rootNode);
  532. }
  533. }
  534. });
  535. }
  536. return comboxbilltype;
  537. }
  538. FuncletMenuBar bar ;
  539. public FuncletMenuBar getBar(){
  540. if(bar==null){
  541. bar =new FuncletMenuBar();
  542. bar.setPreferredSize(new Dimension(0,30));
  543. bar.addMenuComp(getupmenu());//上传按钮添加 zth
  544. bar.addMenuComp(getocrmenu());//ocr按钮添加 zth
  545. // bar.addMenuComp(getPastemenu());
  546. // bar.addMenuComp(getuprefmenu());
  547. // bar.addMenuComp(getGpyimenu());
  548. // bar.addMenuComp(getBtnupdateURL());
  549. // ActionDelegate de =new ActionDelegate();
  550. // de.setAction(new SeparatorAction());
  551. // bar.addMenuComp(new SeparatorButton(de));
  552. // bar.setOpaque(false);
  553. // bar.addMenuComp(getScangrpmenu());//浏览
  554. }
  555. return bar;
  556. }
  557. /*2010-10-24 end 以下按照uif2 画button 工具栏***/
  558. // public JButton getBtnupload() {
  559. // if (btnupload == null) {
  560. // btnupload = new JButton("上传附件");
  561. // btnupload.addActionListener(uploadAction);
  562. // }
  563. // return btnupload;
  564. // }
  565. //
  566. // public JButton getBtnuploadrefcenter() {
  567. // if (btnuploadrefcenter == null) {
  568. // btnuploadrefcenter = new JButton("引用文档");
  569. // btnuploadrefcenter.addActionListener(uprefaction);
  570. // }
  571. // return btnuploadrefcenter;
  572. // }
  573. private ThGaopaiyiAction gpyaction = new ThGaopaiyiAction(ThFileContentPanel.this);
  574. private JButton btngpy;
  575. // public JButton getBtngpy() {
  576. // if (btngpy == null) {
  577. // btngpy = new JButton("高拍仪");
  578. // btngpy.addActionListener(gpyaction);
  579. // }
  580. // return btngpy;
  581. // }
  582. private ThPasteAttachAction pasteaction = new ThPasteAttachAction(
  583. ThFileContentPanel.this);
  584. private JButton btnpaste;
  585. // public JButton getBtnpaste() {
  586. // if (btnpaste == null) {
  587. // btnpaste = new JButton("粘贴附件");
  588. // btnpaste.addActionListener(pasteaction);
  589. // //快捷键测试
  590. // btnpaste.registerKeyboardAction(pasteaction, KeyStroke.getKeyStroke(KeyEvent.VK_V,KeyEvent.CTRL_DOWN_MASK ), JComponent.WHEN_IN_FOCUSED_WINDOW);
  591. // //快捷键测试
  592. // btnpaste.setMnemonic(KeyEvent.VK_V);
  593. //
  594. // }
  595. // return btnpaste;
  596. // }
  597. // private MenuAction browseaction ;
  598. // public MenuAction getBrowseaction(){
  599. // return browseaction;
  600. // }
  601. private MenuAction btnscanimageaction;
  602. public MenuAction getBtnscanimage() {
  603. if (btnscanimageaction == null) {
  604. btnscanimageaction = new MenuAction("brow",NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0000")/*浏览*/);
  605. btnscanimageaction.addChildAction(getScanattachaction());
  606. btnscanimageaction.addChildAction(getScanpptaction());
  607. btnscanimageaction.addChildAction(getScansingleaction());
  608. btnscanimageaction.addChildAction(getScansmallaction());
  609. }
  610. return btnscanimageaction;
  611. }
  612. // private JToolBar toolbar = null;
  613. //
  614. // public JToolBar getToolbar() {
  615. // if (toolbar == null) {
  616. // toolbar = new UIToolBar();
  617. // toolbar.setFloatable(false);
  618. // toolbar.add(getupmenu());
  619. // toolbar.add(getBtnuploadrefcenter());
  620. // toolbar.add(getBtngpy());
  621. // toolbar.add(getBtnpaste());
  622. // toolbar.add(getBtnscanimage());
  623. //
  624. // }
  625. // return toolbar;
  626. // }
  627. /**
  628. * 左树,右表分割
  629. */
  630. private UISplitPane splitpanel = null;
  631. private JPanel lefttreepanel;
  632. public JPanel getLefttreepanel() {
  633. if (lefttreepanel == null) {
  634. lefttreepanel = new JPanel();
  635. lefttreepanel.setBorder(new LineBorder(Color.gray));
  636. lefttreepanel.setLayout(new BorderLayout());
  637. lefttreepanel.setPreferredSize(new Dimension(235, 0));
  638. lefttreepanel.setMinimumSize(new Dimension(235,0));
  639. lefttreepanel.add(getTreetoolpanel(), BorderLayout.NORTH); //新增文件夹按钮 重命名 删除按钮
  640. lefttreepanel.add(getTreepane(), BorderLayout.CENTER);
  641. //
  642. }
  643. return lefttreepanel;
  644. }
  645. private JScrollPane treepane ;
  646. public JScrollPane getTreepane(){
  647. if(treepane == null ){
  648. treepane = new JScrollPane();
  649. treepane.setBorder(null);
  650. treepane.setName("treescrollpane");
  651. treepane.setViewportView(getPatchTree());
  652. }
  653. return treepane ;
  654. }
  655. // private JPanel treepanel ;
  656. // public JPanel getTreepanel(){
  657. // if(treepanel==null){
  658. // treepanel = new JPanel();
  659. // treepanel.setBorder(new LineBorder(Color.red));
  660. // treepanel.setPreferredSize(new Dimension(235, 0));
  661. // SpringLayout springlayout = new SpringLayout();
  662. // treepanel.setLayout(springlayout);
  663. // treepanel.add(getPatchTree());
  664. // springlayout.putConstraint(SpringLayout.WEST, getPatchTree(), 10, SpringLayout.WEST, treepanel);
  665. // springlayout.putConstraint(SpringLayout.NORTH, getPatchTree(), 5, SpringLayout.NORTH, treepanel);
  666. // springlayout.putConstraint(SpringLayout.EAST, getPatchTree(), 10, SpringLayout.EAST, treepanel);
  667. // }
  668. //
  669. // return treepanel ;
  670. // }
  671. private JPanel treetoolpanel;
  672. public JPanel getTreetoolpanel() {
  673. if (treetoolpanel == null) {
  674. treetoolpanel = new JPanel();
  675. treetoolpanel.setBorder(new BottomBorder(0,0,0,0));
  676. FlowLayout m = new FlowLayout();
  677. m.setAlignment(FlowLayout.RIGHT);
  678. treetoolpanel.setLayout(m);
  679. treetoolpanel.add(getTreetoolbar());
  680. }
  681. return treetoolpanel;
  682. }
  683. private ActionsBar treetoolbar;
  684. public ActionsBar getTreetoolbar() {
  685. if (treetoolbar == null) {
  686. treetoolbar = new ActionsBar();
  687. // treetoolbar.setBorder(new LineBorder(Color.gray));
  688. //
  689. treetoolbar.setMinimumSize(new Dimension(100,22));
  690. treetoolbar.addAction(getNewfolderaction());
  691. treetoolbar.addAction(getRenamefolderaction());
  692. treetoolbar.addAction(getDelfolderaction());
  693. // treetoolbar.add(new HyperButton("test1","test1"));
  694. }
  695. return treetoolbar;
  696. }
  697. private class NewFolderAction extends AbstractNCAction {
  698. private static final long serialVersionUID = -4636774835978670803L;
  699. public NewFolderAction() {
  700. this.putValue(AbstractNCAction.SMALL_ICON, ClientToolKit
  701. .loadImageIcon("themeroot/blue/themeres/ui/toolbaricons/add-child.png"));
  702. this.setTooltip(NCLangRes.getInstance().getStrByID("sftemp", "FileInputNameDialog-0000")/*新建文件夹*/);
  703. }
  704. @Override
  705. public void actionPerformed(ActionEvent e) {
  706. createfolder();
  707. }
  708. }
  709. private class NewFolderPopupAction extends AbstractNCAction {
  710. private static final long serialVersionUID = -4636774835978670803L;
  711. public NewFolderPopupAction() {
  712. this.putValue(AbstractAction.NAME, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0001")/*新建*/);
  713. this.putValue(Action.SHORT_DESCRIPTION, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0001")/*新建*/);
  714. }
  715. @Override
  716. public void actionPerformed(ActionEvent e) {
  717. createfolder();
  718. }
  719. }
  720. private class DelFolderPopupAction extends AbstractNCAction {
  721. private static final long serialVersionUID = -1L;
  722. public DelFolderPopupAction() {
  723. this.putValue(AbstractAction.NAME, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0002")/*删除*/);
  724. this.putValue(Action.SHORT_DESCRIPTION, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0002")/*删除*/);
  725. }
  726. @Override
  727. public void actionPerformed(ActionEvent e) {
  728. delfolder();
  729. }
  730. }
  731. private void createfolder() {
  732. if (rootNode == null) {
  733. return;
  734. }
  735. // //规定只能在根目录下 建文件夹
  736. // TreePath path = getPatchTree().getSelectionPath();
  737. //修改为只在根目录下
  738. TreePath path = new TreePath(rootNode.getPath()) ;
  739. NCFileNode node = (NCFileNode)path.getLastPathComponent();
  740. String str = null;
  741. FileInputNameDialog dialog = new FileInputNameDialog();
  742. if(dialog.showModal()==UIDialog.ID_OK){
  743. str = dialog.getFilename();
  744. }
  745. // String str = (String) MessageDialog.showInputDlg(FileContentPanel.this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000005")/*新建文件夹*/, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000006")/*请输入文件夹名称*/, "newfolder");
  746. if (str != null && str.trim().length() > 0) {
  747. try {
  748. if(CheckTheSameFolderName(node,str))
  749. {
  750. return;
  751. }
  752. IFileSystemService service = NCLocator.getInstance().lookup(IFileSystemService.class);
  753. NCFileNode newNode = service.createNewFileNode(node.getFullPath(), str, WorkbenchEnvironment.getInstance().getLoginUser().getCuserid());
  754. DefaultTreeModel model = getTreemodel();
  755. model.insertNodeInto(newNode, node, node.getChildCount());
  756. model.nodeStructureChanged(node);
  757. TreePath newPath = new TreePath(getTreePath(newNode));
  758. getPatchTree().setSelectionPath(newPath);
  759. getPatchTree().expandPath(newPath);
  760. getTreenodefilecacheMap().put(newNode.getFullPath(), new ArrayList<NCFileVO>());
  761. } catch (Exception ex) {
  762. Logger.error(ex.getMessage(), ex);
  763. MessageDialog.showErrorDlg(ThFileContentPanel.this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/, ex.getMessage());
  764. }
  765. }
  766. }
  767. private class RenameFolderPopupAction extends AbstractNCAction {
  768. private static final long serialVersionUID = -1L;
  769. public RenameFolderPopupAction() {
  770. this.putValue(AbstractAction.NAME, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0003")/*重命名*/);
  771. this.putValue(Action.SHORT_DESCRIPTION, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0003")/*重命名*/);
  772. }
  773. @Override
  774. public void actionPerformed(ActionEvent e) {
  775. renamefoder();
  776. }
  777. }
  778. private class DelFolderAction extends AbstractNCAction {
  779. private static final long serialVersionUID = 3273091047549713804L;
  780. public DelFolderAction() {
  781. this.putValue(AbstractNCAction.SMALL_ICON, ClientToolKit
  782. .loadImageIcon("themeroot/blue/themeres/ui/toolbaricons/delete.png"));
  783. this.setTooltip(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0002")/*删除*/);
  784. }
  785. @Override
  786. public void actionPerformed(ActionEvent e) {
  787. delfolder();
  788. }
  789. }
  790. private class RenameFolderAction extends AbstractNCAction {
  791. private static final long serialVersionUID = -132307984647892932L;
  792. public RenameFolderAction() {
  793. this.putValue(AbstractNCAction.SMALL_ICON, ClientToolKit
  794. .loadImageIcon("themeroot/blue/themeres/ui/toolbaricons/edit.png"));
  795. this.setTooltip(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0003")/*重命名*/);
  796. }
  797. @Override
  798. public void actionPerformed(ActionEvent e) {
  799. renamefoder();
  800. }
  801. }
  802. private void renamefoder() {
  803. TreePath treePath = getPatchTree().getSelectionPath();
  804. if (treePath == null) {
  805. return;
  806. }
  807. Object obj = treePath.getLastPathComponent();
  808. if (obj.equals(rootNode)) {
  809. MessageDialog.showErrorDlg(ThFileContentPanel.this,
  810. NCLangRes.getInstance().getStrByID("pc",
  811. "FileManageUI-000000")/* 错误 */, NCLangRes
  812. .getInstance().getStrByID("pc",
  813. "FileManageUI-000011")/* 不能对根节点重命名 */);
  814. return;
  815. }
  816. getPatchTree().getUI().startEditingAtPath(getPatchTree(), treePath);
  817. }
  818. public void delfolder() {
  819. if (rootNode == null) {
  820. return;
  821. }
  822. TreePath[] paths = getPatchTree().getSelectionPaths();
  823. if (paths == null || paths.length == 0)
  824. return;
  825. List<String> nodePathsList = new ArrayList<String>();
  826. List<DefaultMutableTreeNode> nodeList = new ArrayList<DefaultMutableTreeNode>();
  827. for (int i = 0; i < paths.length; i++) {
  828. NCFileNode node = (NCFileNode) paths[i].getLastPathComponent();
  829. //根节点 不能删除 ,删除就会出错
  830. if (node.equals(rootNode)) {
  831. MessageDialog.showOkCancelDlg(ThFileContentPanel.this, NCLangRes.getInstance().getStrByID("sftemp", "FilePatchAttrDialog-0012")/*错误*/,NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0016")/*根节点不能删除!*/);
  832. continue;
  833. }
  834. String nodePath = ((NCFileNode) node).getFullPath();
  835. nodePathsList.add(nodePath);
  836. nodeList.add(node);
  837. }
  838. if (nodePathsList.size() > 0) {
  839. try {
  840. IFileSystemService service = NCLocator.getInstance().lookup(IFileSystemService.class);
  841. StringBuilder sb = new StringBuilder(NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000019")+"\r\n");
  842. for (int i = 0; i < nodeList.size(); i++) {
  843. TreeNode[] nodes = getTreePath(nodeList.get(i));
  844. sb.append(convertTreePathToString(nodes)).append("\r\n");
  845. }
  846. if (MessageDialog.showOkCancelDlg(ThFileContentPanel.this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000007")/*删除确认框*/, sb.toString()) == MessageDialog.ID_OK) {
  847. DefaultTreeModel model = getTreemodel();
  848. for (int i = 0; i < nodeList.size(); i++) {
  849. DefaultMutableTreeNode tempNode = nodeList.get(i);
  850. TreeNode parent = tempNode.getParent();
  851. NCFileNode fn =(NCFileNode)tempNode;
  852. HashMap<String, NCFileVO> mapfilevo = fn.getFilemap();
  853. String path = fn.getFullPath();
  854. //清理客户端,"全部"下的删除文件
  855. for(NCFileVO fvo :mapfilevo.values()){
  856. getTreenodefilecacheMap().get("root").remove(fvo);
  857. }
  858. //清理客户端,本页的缓存map
  859. if(getTreenodefilecacheMap().containsKey(path)){
  860. getTreenodefilecacheMap().remove(path);
  861. }
  862. //改变树结构
  863. model.removeNodeFromParent(tempNode);
  864. if (parent != null) {
  865. model.nodeStructureChanged(parent);
  866. }
  867. }
  868. //清理缓存
  869. getfiletablemodel().clearTable();
  870. // for(String path :nodePathsList){
  871. //
  872. // }
  873. if(PAGE_STATE!=BROWSELISTTABLE_STATE){
  874. getTablepanel().removeAll();
  875. getTablepanel().updateUI();
  876. }
  877. service.deleteNCFileNodes(nodePathsList.toArray(new String[0]));
  878. }
  879. } catch (BusinessException ex) {
  880. Logger.error(ex.getMessage(), ex);
  881. }
  882. }
  883. }
  884. private class CTreeCellEditor extends DefaultTreeCellEditor {
  885. private NCFileNode node = null;
  886. public CTreeCellEditor(JTree tree) {
  887. super(tree, getFiletreerender());
  888. }
  889. @Override
  890. public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
  891. Component c = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
  892. if (value instanceof NCFileNode) {
  893. node = (NCFileNode) value;
  894. }
  895. return c ;
  896. }
  897. @Override
  898. public Object getCellEditorValue() {
  899. Object o = super.getCellEditorValue();
  900. if (o instanceof String && node != null) {
  901. String newValue = ((String) o).trim();
  902. String oldValue = node.getName();
  903. String oldPath = node.getFullPath();
  904. TreePath treePath = getPatchTree().getSelectionPath();
  905. if (treePath == null) {
  906. return oldValue;
  907. }
  908. Object obj = treePath.getLastPathComponent();
  909. if (obj.equals(rootNode)) {
  910. MessageDialog.showErrorDlg(ThFileContentPanel.this,
  911. NCLangRes.getInstance().getStrByID("pc",
  912. "FileManageUI-000000")/* 错误 */, NCLangRes
  913. .getInstance().getStrByID("pc",
  914. "FileManageUI-000011")/* 不能对根节点重命名 */);
  915. return oldValue;
  916. }
  917. node.setUserObject(newValue);
  918. String newPath = node.getFullPath();
  919. boolean b = false;
  920. try {
  921. if (newValue.indexOf("/") != -1 || newValue.indexOf("\\") != -1) {
  922. MessageDialog.showErrorDlg(ThFileContentPanel.this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000001")/*文件名中不能包含\\或/符号*/);
  923. return oldValue;
  924. }
  925. //如果去掉前后空格长度为0,返回原来值,提示文件名不能空
  926. if(newValue.trim().length()==0)
  927. {
  928. //MessageDialog.showErrorDlg(FileManageUI.this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/, "文件名不能为空");
  929. return oldValue;
  930. }
  931. if (!oldPath.equals(newPath)) {
  932. IFileSystemService service = NCLocator.getInstance().lookup(IFileSystemService.class);
  933. b = service.rename(oldPath, newPath);
  934. if (!b) {
  935. MessageDialog.showHintDlg(ThFileContentPanel.this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000002")/*提示*/, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000003")/*文件名重复*/);
  936. return oldValue;
  937. }else{
  938. //保存成功更新树缓存
  939. Collection<NCFileVO> c =getTreenodefilecacheMap().get(oldPath);
  940. getTreenodefilecacheMap().remove(oldPath);
  941. getTreenodefilecacheMap().put(newPath, c);
  942. }
  943. }
  944. } catch (BusinessException e) {
  945. Logger.error(e);
  946. }
  947. if (b) {
  948. return newValue;
  949. } else {
  950. return oldValue;
  951. }
  952. }
  953. return o;
  954. }
  955. @Override
  956. protected void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
  957. super.determineOffset(tree, value, isSelected, expanded, leaf, row);
  958. if (renderer != null) {
  959. editingIcon = ((JLabel) renderer.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, false)).getIcon();
  960. }
  961. }
  962. }
  963. /**
  964. * 左边附件树
  965. */
  966. private UITree patchtree = null;
  967. /**
  968. * 右边的附件详细信息
  969. */
  970. private UITable patchinfotable = null;
  971. /**
  972. * 左边树的model
  973. */
  974. private DefaultTreeModel treemodel = null;
  975. /**
  976. * 右边附件列表的model
  977. */
  978. private FileVOTableModel tablemodel = null;
  979. public UISplitPane getSplitpanel() {
  980. if (splitpanel == null) {
  981. splitpanel = new UISplitPane(UISplitPane.HORIZONTAL_SPLIT);
  982. // splitpanel.add(getLefttreepanel(), UISplitPane.LEFT);
  983. splitpanel.add(getTablepanel(), UISplitPane.RIGHT);//右边框
  984. splitpanel.setDividerSize(3);
  985. }
  986. return splitpanel;
  987. }
  988. protected JPanel tablepanel;
  989. public JPanel getTablepanel(){
  990. if(tablepanel== null){
  991. tablepanel = new JPanel();
  992. tablepanel.setLayout(new BorderLayout());
  993. tablepanel.setPreferredSize(new Dimension(500, 400));
  994. // CardLayout cardlayout = new CardLayout();
  995. // tablepanel.setLayout(cardlayout);
  996. tablepanel.add(getJstablepanel(),BorderLayout.CENTER);
  997. // tablepanel.add(getJstablepanel(),"card2");
  998. }
  999. return tablepanel;
  1000. }
  1001. private JScrollPane jstablepanel;
  1002. public JScrollPane getJstablepanel() {
  1003. if (jstablepanel == null) {
  1004. jstablepanel = new JScrollPane(getPatchInfoTable());
  1005. }
  1006. return jstablepanel;
  1007. }
  1008. @SuppressWarnings("unchecked")
  1009. protected class FileVOTableModel extends VOTableModel {
  1010. /**
  1011. *
  1012. */
  1013. private static final long serialVersionUID = -6001046311222516903L;
  1014. String[] columnnames = { "", NCLangRes.getInstance().getStrByID("sftemp", "FilePatchAttrDialog-0004")/*附件名*/, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0004")/*大小*/, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0005")/*描述*/, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0006")/*上传时间*/, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0007")/*操作*/ };
  1015. public FileVOTableModel(ValueObject[] vos) {
  1016. super(vos);
  1017. }
  1018. @Override
  1019. public String getColumnName(int col) {
  1020. //
  1021. return columnnames[col];
  1022. }
  1023. @Override
  1024. public int getColumnCount() {
  1025. return columnnames.length;
  1026. }
  1027. @Override
  1028. public Object getValueAt(int rowIndex, int columnIndex) {
  1029. Object o = this.getVO(rowIndex);
  1030. if (o instanceof NCFileVO) {
  1031. NCFileVO file = (NCFileVO) o;
  1032. if (columnIndex == 0) {
  1033. return rowIndex + 1;
  1034. } else if (columnIndex == 1) {
  1035. return file.getName();
  1036. } else if (columnIndex == 2) {
  1037. return FileManageStringFormat.formatFileSize(file
  1038. .getFileLen());
  1039. } else if (columnIndex == 3) {
  1040. return file.getFiledesc();
  1041. } else if (columnIndex == 4) {
  1042. return FileManageStringFormat.formatDateToString(file
  1043. .getTime());
  1044. } else if (columnIndex == 5) {
  1045. return "";
  1046. } else {
  1047. return "";
  1048. }
  1049. }
  1050. return "test";
  1051. }
  1052. @Override
  1053. public boolean isCellEditable(int row, int column) {
  1054. if (isColumnEditable(column)) {
  1055. return true;
  1056. } else {
  1057. return false;
  1058. }
  1059. }
  1060. @Override
  1061. public boolean isColumnEditable(int col) {
  1062. if (col == 1 || col == 5) {
  1063. return true;
  1064. }
  1065. return false;
  1066. }
  1067. public boolean isRowEditable(int row) {
  1068. return true;
  1069. }
  1070. @Override
  1071. public boolean isAndEditable() {
  1072. //
  1073. return true;
  1074. }
  1075. }
  1076. private FileManageTreeRenderer filetreerender;
  1077. public FileManageTreeRenderer getFiletreerender() {
  1078. if (filetreerender == null) {
  1079. filetreerender = new FileManageTreeRenderer();
  1080. }
  1081. return filetreerender;
  1082. }
  1083. private class MyFileTree extends UITree{
  1084. /**
  1085. *
  1086. */
  1087. private static final long serialVersionUID = -3022453623914006697L;
  1088. @Override
  1089. public boolean isPathEditable(TreePath path) {
  1090. if(path.getLastPathComponent().equals(rootNode)){
  1091. return false ;
  1092. }
  1093. return super.isPathEditable(path);
  1094. }
  1095. }
  1096. public UITree getPatchTree() {
  1097. if (patchtree == null) {
  1098. patchtree = new MyFileTree();
  1099. patchtree.setUI(new FileManageTreeUI());
  1100. patchtree.setRowHeight(28);
  1101. patchtree.setBorder(new EmptyBorder(5,10,0,10));
  1102. // patchtree.setBackground(FileManageUIConst.MCBOXTREEBG);
  1103. patchtree.setCellRenderer(getFiletreerender());
  1104. CTreeCellEditor ceditor = new CTreeCellEditor(patchtree);
  1105. patchtree.setCellEditor(ceditor);
  1106. patchtree.setModel(getTreemodel());
  1107. patchtree.setEditable(true);
  1108. patchtree.addMouseListener(new CMouseHandler());
  1109. patchtree.setRootVisible(true);
  1110. patchtree.setBounds(10,5,patchtree.getWidth()-20,patchtree.getHeight()-10);
  1111. patchtree.addTreeSelectionListener(new TreeSelectionListener() {
  1112. @Override
  1113. public void valueChanged(TreeSelectionEvent e) {
  1114. actionTree(e);
  1115. }
  1116. });
  1117. }
  1118. return patchtree;
  1119. }
  1120. private void actionTree(TreeSelectionEvent e) {
  1121. refreshUIbyClickTree();
  1122. }
  1123. private void refreshUIbyClickTree() {
  1124. if (getPatchTree().getSelectionPath() == null)
  1125. return;
  1126. selfoldernode = (NCFileNode) getPatchTree()
  1127. .getSelectionPath().getLastPathComponent();
  1128. if(selfoldernode.equals(rootNode)){
  1129. getDelfolderaction().setEnabled(false);
  1130. getRenamefolderaction().setEnabled(false);
  1131. }else{
  1132. getDelfolderaction().setEnabled(true);
  1133. getRenamefolderaction().setEnabled(true);
  1134. }
  1135. if(PAGE_STATE==BROWSELISTTABLE_STATE){
  1136. ThFileBrowseCreatePane.createListBrowsePane(ThFileContentPanel.this);
  1137. }else if(PAGE_STATE==BROWSEPPTICON_STATE){
  1138. ThFileBrowseCreatePane.createPPTBrowsePane(ThFileContentPanel.this, new ScaleSlider());
  1139. }else if(PAGE_STATE==BROWSESINGLEICON_STATE){
  1140. ThFileBrowseCreatePane.createSingleBrosePane(ThFileContentPanel.this, new ScaleSlider());
  1141. }else if(PAGE_STATE==BROWSESMALLICON_STATE){
  1142. ThFileBrowseCreatePane.createSmallImagePane(ThFileContentPanel.this);
  1143. }
  1144. }
  1145. /**
  1146. * 更新状态栏
  1147. */
  1148. protected void refreshStatuBar(){
  1149. //TODO (方法if else要重构)
  1150. if(selfoldernode== null ||selfoldernode.getFullPath().equals(rootDirStr)){
  1151. // 更新状态栏(几个附件,大小)
  1152. int filecount = getTreenodefilecacheMap().get("root").size();
  1153. Long filesize = 0l;
  1154. for (NCFileVO fvo : getTreenodefilecacheMap().get("root")) {
  1155. filesize += fvo.getFileLen();
  1156. }
  1157. if (filecount > 0 && filesize > 0) {
  1158. StringBuffer sb = new StringBuffer();
  1159. sb.append(filecount).append(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0008")/*个附件 :*/).append(" ");
  1160. sb.append(FileManageStringFormat.formatFileSize(filesize));
  1161. getLblstatubar().setText(sb.toString());
  1162. } else {
  1163. getLblstatubar().setText(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0009")/*附件信息*/);
  1164. }
  1165. }else{
  1166. // 更新状态栏
  1167. int filecount =0;
  1168. Long filesize = 0l;
  1169. if(getTreenodefilecacheMap().get(selfoldernode.getFullPath())!=null){
  1170. filecount = getTreenodefilecacheMap().get(selfoldernode.getFullPath()).size();
  1171. for (NCFileVO fvo : getTreenodefilecacheMap().get(selfoldernode.getFullPath())) {
  1172. filesize += fvo.getFileLen();
  1173. }
  1174. }
  1175. if (filecount > 0 && filesize > 0) {
  1176. StringBuffer sb = new StringBuffer();
  1177. sb.append(filecount).append(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0008")/*个附件 :*/).append(" ");
  1178. sb.append(FileManageStringFormat.formatFileSize(filesize));
  1179. getLblstatubar().setText(sb.toString());
  1180. } else {
  1181. getLblstatubar().setText(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0009")/*附件信息*/);
  1182. }
  1183. }
  1184. }
  1185. /**
  1186. * 树的model
  1187. *
  1188. * @return
  1189. */
  1190. protected DefaultTreeModel getTreemodel() {
  1191. if (treemodel == null) {
  1192. treemodel = new DefaultTreeModel(null);
  1193. treemodel.setAsksAllowsChildren(true);
  1194. try {
  1195. if (rootDirStr != null) {
  1196. IQueryFolderTreeNodeService service = NCLocator
  1197. .getInstance().lookup(
  1198. IQueryFolderTreeNodeService.class);
  1199. NCFileNode node = service.getNCFileNodeTreeAndCreateAsNeed(
  1200. rootDirStr, WorkbenchEnvironment.getInstance()
  1201. .getLoginUser().getCuserid());
  1202. rootNode = findNode(node, rootDirStr);
  1203. } else {
  1204. rootNode = null;
  1205. }
  1206. treemodel.setRoot(rootNode);
  1207. treemodel.nodeStructureChanged(rootNode);
  1208. } catch (BusinessException e) {
  1209. Logger.error(e);
  1210. }
  1211. }
  1212. return treemodel;
  1213. }
  1214. private void toCache(NCFileNode rootNode) {
  1215. if(rootNode==null){
  1216. return ;
  1217. }
  1218. Enumeration<NCFileNode> enumer = rootNode.breadthFirstEnumeration();
  1219. // NCFileNode retrNode = null;
  1220. while (enumer.hasMoreElements()) {
  1221. NCFileNode tempNode = (NCFileNode) enumer.nextElement();
  1222. getTreenodefilecacheMap().put(tempNode.getFullPath(),
  1223. tempNode.getFilemap().values());
  1224. }
  1225. // root 包含所有的文件
  1226. if (getTreenodefilecacheMap().get("root") == null) {
  1227. ArrayList<NCFileVO> arr = new ArrayList<NCFileVO>();
  1228. for (Collection<NCFileVO> cvo : getTreenodefilecacheMap().values()) {
  1229. arr.addAll(cvo);
  1230. }
  1231. getTreenodefilecacheMap().put("root", arr);
  1232. }
  1233. }
  1234. @SuppressWarnings("unchecked")
  1235. NCFileNode findNode(NCFileNode node, String path) {
  1236. Enumeration<NCFileNode> enumer = node.breadthFirstEnumeration();
  1237. NCFileNode retrNode = null;
  1238. while (enumer.hasMoreElements()) {
  1239. NCFileNode tempNode = (NCFileNode) enumer.nextElement();
  1240. if (tempNode.getFullPath().equals(path)) {
  1241. retrNode = tempNode;
  1242. // retrNode.setParent(null);
  1243. break;
  1244. }
  1245. }
  1246. return retrNode;
  1247. }
  1248. public UITable getPatchInfoTable() {
  1249. if (patchinfotable == null) {
  1250. patchinfotable = new UITable();
  1251. patchinfotable.setModel(getfiletablemodel());
  1252. patchinfotable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  1253. TableColumnModel colmodel = patchinfotable.getColumnModel();
  1254. TableColumn col0_rownum = colmodel.getColumn(0);
  1255. col0_rownum.setPreferredWidth(30);
  1256. col0_rownum.setCellRenderer(new RownumTableCellRender());
  1257. TableColumn col1_filename = colmodel.getColumn(1);
  1258. col1_filename.setCellRenderer(new BtnTableCellRender());
  1259. col1_filename
  1260. .setCellEditor(new BtnTableCellEditor(new JCheckBox()));
  1261. col1_filename.setPreferredWidth(93);
  1262. TableColumn col2 = colmodel.getColumn(2);
  1263. col2.setPreferredWidth(66);
  1264. TableColumn col4 = colmodel.getColumn(4);
  1265. col4.setPreferredWidth(120);
  1266. TableColumn btncol = colmodel.getColumn(5);
  1267. btncol.setCellRenderer(new BtnTableCellRender());
  1268. btncol.setCellEditor(new BtnTableCellEditor(new JCheckBox()));
  1269. btncol.setPreferredWidth(190);
  1270. patchinfotable.addMouseMotionListener( new FileMouseListener());
  1271. }
  1272. return patchinfotable;
  1273. }
  1274. private class FileMouseListener extends MouseMotionAdapter{
  1275. @Override
  1276. public void mouseMoved(MouseEvent e) {
  1277. int col =patchinfotable.columnAtPoint(e.getPoint());
  1278. if(col!=-1&&(col == colnumbtnpane ||col == colnumbtnbrow) ){
  1279. patchinfotable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  1280. }else{
  1281. patchinfotable.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  1282. }
  1283. }
  1284. }
  1285. private class RownumTableCellRender implements TableCellRenderer {
  1286. @Override
  1287. public Component getTableCellRendererComponent(JTable table,
  1288. Object value, boolean isSelected, boolean hasFocus, int row,
  1289. int column) {
  1290. JLabel label = new JLabel();
  1291. label.setText(String.valueOf(value));
  1292. label.setOpaque(true);
  1293. if(isSelected){
  1294. label.setBackground(table.getSelectionBackground());
  1295. }else{
  1296. label.setBackground(table.getTableHeader().getBackground());
  1297. }
  1298. label.setHorizontalAlignment(SwingConstants.CENTER);
  1299. return label;
  1300. }
  1301. }
  1302. public FileVOTableModel getfiletablemodel() {
  1303. if (tablemodel == null) {
  1304. tablemodel = new FileVOTableModel(null);
  1305. }
  1306. return tablemodel;
  1307. }
  1308. /**
  1309. * @param name
  1310. * @return 返回文件后缀名,包含"."
  1311. */
  1312. private String getFileType(String name) {
  1313. String type = null;
  1314. if (name != null && name.contains(".")) {
  1315. type = name.substring(name.lastIndexOf("."), name.length());
  1316. }
  1317. return type;
  1318. }
  1319. private class BtnPanel extends JPanel {
  1320. private static final long serialVersionUID = 5460160935253553438L;
  1321. HyperButton btndownload = new HyperButton(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0010")/*下载*/, "dowm");
  1322. HyperButton btnupfpload = new HyperButton(NCLangRes.getInstance().getStrByID("sftemp", "传发票"), "upfp");
  1323. HyperButton btnmove = new HyperButton(NCLangRes.getInstance().getStrByID("sftemp", "FileMoveDialog-0000")/*移动*/, "move");
  1324. HyperButton btneidt = new HyperButton(NCLangRes.getInstance().getStrByID("sftemp", "FilePatchAttrDialog-0010")/*编辑属性*/, "edit");
  1325. HyperButton btndelete = new HyperButton(NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0002")/*删除*/, "delete");
  1326. int rowindex;
  1327. // JButton test= new JButton("test");
  1328. public BtnPanel(int row) {
  1329. super();
  1330. rowindex = row;
  1331. SpringLayout layout = new SpringLayout();
  1332. this.setLayout(layout);
  1333. NCFileVO filevo = (NCFileVO) getfiletablemodel().getVO(row);
  1334. // btnbdownload.setOpaque(true);
  1335. // btnbdownload.setBackground(Color.red);
  1336. BtnPanel.this.setOpaque(true);
  1337. // BtnPanel.this.setBackground(Color.red);
  1338. BtnPanel.this.add(btndownload);
  1339. // BtnPanel.this.add(btnupfpload);
  1340. // BtnPanel.this.add(btnmove);
  1341. BtnPanel.this.add(btneidt);
  1342. BtnPanel.this.add(btndelete);
  1343. if(filevo!=null&&filevo.getFiletype()!=null&&filevo.getFiletype().equalsIgnoreCase(FileTypeConst.URL)){
  1344. // btndownload.setEnabled(false);
  1345. btndownload.setVisible(false);
  1346. }else{
  1347. // btndownload.setEnabled(true);
  1348. btndownload.setVisible(true);
  1349. }
  1350. // springlayout 控制按钮间距离 15
  1351. layout.putConstraint(SpringLayout.WEST, btndownload, 20,
  1352. SpringLayout.WEST, BtnPanel.this);
  1353. layout.putConstraint(SpringLayout.WEST, btneidt, 20,
  1354. SpringLayout.EAST, btndownload);
  1355. layout.putConstraint(SpringLayout.WEST, btndelete, 20,
  1356. SpringLayout.EAST, btneidt);
  1357. /*layout.putConstraint(SpringLayout.WEST, btndownload, 12,
  1358. SpringLayout.WEST, BtnPanel.this);
  1359. layout.putConstraint(SpringLayout.WEST, btnupfpload, 12,
  1360. SpringLayout.EAST, btndownload);
  1361. layout.putConstraint(SpringLayout.WEST, btneidt, 12,
  1362. SpringLayout.EAST, btnupfpload);
  1363. layout.putConstraint(SpringLayout.WEST, btndelete, 12,
  1364. SpringLayout.EAST, btneidt);*/
  1365. /* layout.putConstraint(SpringLayout.WEST, btndownload, 15,
  1366. SpringLayout.WEST, BtnPanel.this);
  1367. layout.putConstraint(SpringLayout.WEST, btnmove, 15,
  1368. SpringLayout.EAST, btndownload);
  1369. layout.putConstraint(SpringLayout.WEST, btneidt, 15,
  1370. SpringLayout.EAST, btnmove);
  1371. layout.putConstraint(SpringLayout.WEST, btndelete, 15,
  1372. SpringLayout.EAST, btneidt);*/
  1373. // layout.putConstraint(SpringLayout.WEST,test,15,SpringLayout.EAST,btndelete);
  1374. //处理权限
  1375. btndownload.setEnabled(downloadenable);
  1376. btndelete.setEnabled(deleteenable);
  1377. //注册事件
  1378. btndownload.addActionListener(new ActionListener() {
  1379. @Override
  1380. public void actionPerformed(ActionEvent e) {
  1381. downloadFile();
  1382. }
  1383. private void downloadFile() {
  1384. getPatchInfoTable().setRowSelectionInterval(rowindex,
  1385. rowindex);
  1386. int row = BtnPanel.this.rowindex;
  1387. if (row == -1) {
  1388. return;
  1389. }
  1390. NCFileVO filevo = (NCFileVO) getfiletablemodel().getVO(row);
  1391. String filepath = filevo.getFullPath();
  1392. if (filepath != null) {
  1393. String path = filevo.getFullPath();
  1394. String name = filevo.getName();
  1395. String defaultType = getFileType(name);
  1396. NCFileChooser chooser = new NCFileChooser();
  1397. // 设置默认选中文件
  1398. chooser.setSelectedFile(new File(name));
  1399. if (chooser.showSaveDialog(ThFileContentPanel.this) == JFileChooser.APPROVE_OPTION) {
  1400. File file = chooser.getSelectedFile();
  1401. // 如果选中文件无后缀名,添加默认后缀名
  1402. if (!file.getName().contains(".")
  1403. && defaultType != null) {
  1404. file = new File(file.getParent(), file
  1405. .getName()
  1406. + defaultType);
  1407. }
  1408. String dsName = WorkbenchEnvironment.getInstance()
  1409. .getLoginBusiCenter().getDataSourceName();
  1410. FileOutputStream fos = null;
  1411. try {
  1412. fos = new FileOutputStream(file);
  1413. FileManageServletClient.downloadFile(dsName,
  1414. path, fos);
  1415. } catch (Exception ex) {
  1416. Logger.error(ex.getMessage(), ex);
  1417. MessageDialog
  1418. .showErrorDlg(
  1419. ThFileContentPanel.this,
  1420. NCLangRes
  1421. .getInstance()
  1422. .getStrByID("pc",
  1423. "FileManageUI-000000")/* 错误 */,
  1424. ex.getMessage());
  1425. } finally {
  1426. try {
  1427. if (fos != null) {
  1428. fos.close();
  1429. }
  1430. } catch (Exception e2) {
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. });
  1437. btnupfpload.addActionListener(new ActionListener() {
  1438. @Override
  1439. public void actionPerformed(ActionEvent e) {
  1440. downloadFile();
  1441. }
  1442. private void downloadFile() {
  1443. getPatchInfoTable().setRowSelectionInterval(rowindex,
  1444. rowindex);
  1445. int row = BtnPanel.this.rowindex;
  1446. if (row == -1) {
  1447. return;
  1448. }
  1449. NCFileVO filevo = (NCFileVO) getfiletablemodel().getVO(row);
  1450. String filepath = filevo.getFullPath();
  1451. if (filepath != null) {
  1452. String path = filevo.getFullPath();
  1453. String name = filevo.getName();
  1454. String defaultType = getFileType(name);
  1455. File file = new File("C:\\Users\\Administrator\\Desktop\\附件迁移rrr.txt");
  1456. String dsName = WorkbenchEnvironment.getInstance()
  1457. .getLoginBusiCenter().getDataSourceName();
  1458. FileOutputStream fos = null;
  1459. try {
  1460. fos = new FileOutputStream(file);
  1461. FileManageServletClient.downloadFile(dsName,
  1462. path, fos);
  1463. MessageDialog.showHintDlg(ThFileContentPanel.this, "提示", "传发票系统成功!");
  1464. } catch (Exception ex) {
  1465. Logger.error(ex.getMessage(), ex);
  1466. MessageDialog
  1467. .showErrorDlg(
  1468. ThFileContentPanel.this,
  1469. NCLangRes
  1470. .getInstance()
  1471. .getStrByID("pc",
  1472. "FileManageUI-000000")/* 错误 */,
  1473. ex.getMessage());
  1474. } finally {
  1475. try {
  1476. if (fos != null) {
  1477. fos.close();
  1478. }
  1479. } catch (Exception e2) {
  1480. }
  1481. }
  1482. }
  1483. }
  1484. });
  1485. btneidt.addActionListener(new ActionListener() {
  1486. @Override
  1487. public void actionPerformed(ActionEvent e) {
  1488. getPatchInfoTable().setRowSelectionInterval(rowindex,
  1489. rowindex);
  1490. ThFilePatchAttrDialog dialog = new ThFilePatchAttrDialog(
  1491. ThFileContentPanel.this);
  1492. // dialog.setSize(525, 350);
  1493. dialog.showModal();
  1494. }
  1495. });
  1496. btndelete.addActionListener(new ActionListener() {
  1497. @Override
  1498. public void actionPerformed(ActionEvent e) {
  1499. getPatchInfoTable().setRowSelectionInterval(rowindex,
  1500. rowindex);
  1501. if (MessageDialog.showOkCancelDlg(ThFileContentPanel.this,
  1502. NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0011")/*确认删除*/,
  1503. NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0012")/*确定要删除文件?*/) == MessageDialog.ID_OK) {
  1504. int row = getPatchInfoTable().getSelectedRow();
  1505. NCFileVO filevo = (NCFileVO) getfiletablemodel().getVO(
  1506. row);
  1507. String filepath = filevo.getFullPath();
  1508. try {
  1509. // 删除文件
  1510. IFileSystemService service = NCLocator
  1511. .getInstance().lookup(
  1512. IFileSystemService.class);
  1513. service
  1514. .deleteNCFileNodes(new String[] { filepath });
  1515. // 刷新table
  1516. getfiletablemodel().removeVO(row);
  1517. getfiletablemodel().refreshTable();
  1518. // 树上的缓存清理
  1519. getTreenodefilecacheMap().get("root")
  1520. .remove(filevo);
  1521. getTreenodefilecacheMap().get(
  1522. filevo.getParentpath()).remove(filevo);
  1523. //// 更新状态栏(几个附件,大小)
  1524. refreshStatuBar();
  1525. } catch (BusinessException ex) {
  1526. Logger.error(ex.getMessage(), ex);
  1527. }
  1528. //删除home发票文件夹里的对应发票 add by ZTH
  1529. String deletefilepath = RuntimeEnv.getInstance().getNCHome()
  1530. +File.separator +"uploadfile" + File.separator+ filepath; // 文件保存的路径
  1531. File file = new File(deletefilepath);
  1532. if (file.delete()) {
  1533. MessageDialog.showHintDlg(ThFileContentPanel.this, "提示","删除成功!");
  1534. } else {
  1535. MessageDialog.showErrorDlg(ThFileContentPanel.this, "提示","删除操作失败。");
  1536. }
  1537. //由于删除太慢,改成自定义档案数据停用
  1538. String[] filname=filepath.split("/");
  1539. DefdocVO[] deletevos=QryDefdocvoInfo(filname[1]);
  1540. IDefdocService idefservice = NCLocator.getInstance().lookup(IDefdocService.class);
  1541. try {
  1542. // idefservice.deleteDefdocs(InvocationInfoProxy.getInstance().getGroupId(),deletevos);
  1543. DefdocVO defvo =deletevos[0];
  1544. defvo.setAttributeValue("enablestate", 3);//停用
  1545. idefservice.updateDefdocs(InvocationInfoProxy.getInstance().getGroupId(),deletevos);
  1546. } catch (BusinessException e1) {
  1547. // TODO 自动生成的 catch 块
  1548. e1.printStackTrace();
  1549. MessageDialog.showErrorDlg(ThFileContentPanel.this, "提示","停用OCR档案【"+filname[1]+"】:\n"+e1.getMessage());
  1550. }
  1551. }
  1552. }
  1553. });
  1554. btnmove.addActionListener(new ActionListener() {
  1555. @Override
  1556. public void actionPerformed(ActionEvent e) {
  1557. getPatchInfoTable().setRowSelectionInterval(rowindex,
  1558. rowindex);
  1559. ThFileMoveDialog fdlg = new ThFileMoveDialog(
  1560. ThFileContentPanel.this);
  1561. fdlg.showModal();
  1562. }
  1563. });
  1564. }
  1565. }
  1566. private DefdocVO[] QryDefdocvoInfo(String name){
  1567. String sql = "select * from bd_defdoc where nvl(dr, 0) = 0 and pk_defdoclist="
  1568. + "(select pk_defdoclist from bd_defdoclist where code='OCRTHNC' and nvl(dr,0)=0) and memo='" + name + "' ";
  1569. ArrayList<Object> arrayvos=null;
  1570. try {
  1571. IUAPQueryBS iuap= (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
  1572. arrayvos=(ArrayList<Object>) iuap.executeQuery(sql, new BeanListProcessor(DefdocVO.class));
  1573. } catch (BusinessException e) {
  1574. // TODO 自动生成的 catch 块
  1575. e.printStackTrace();
  1576. }
  1577. if (arrayvos==null) {
  1578. return new DefdocVO[0];
  1579. }else {
  1580. return arrayvos.toArray(new DefdocVO[0]);
  1581. }
  1582. }
  1583. private class BtnTableCellRender implements TableCellRenderer {
  1584. public BtnTableCellRender() {
  1585. // FileManageMainUI.this.btnpanel.setOpaque(true);
  1586. // FileManageMainUI.this.btnpanel.btndelete.setOpaque(true);
  1587. // FileManageMainUI.this.btnpanel.btneidt.setOpaque(true);
  1588. }
  1589. @Override
  1590. public Component getTableCellRendererComponent(JTable table,
  1591. Object value, boolean isSelected, boolean hasFocus, int row,
  1592. int column) {
  1593. // table.setRowSelectionInterval(row, row);
  1594. if (column == 5) {
  1595. BtnPanel bp =new BtnPanel(row);
  1596. bp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  1597. bp.setOpaque(true);
  1598. if(isSelected){
  1599. bp.setBackground(table.getSelectionBackground());
  1600. }
  1601. return bp;
  1602. } else if (column == 1) {
  1603. String strbtn = (value == null) ? "" : value.toString();
  1604. HyperButton btn1 = new HyperButton(strbtn, strbtn);
  1605. if(isSelected){
  1606. btn1.setOpaque(true);
  1607. btn1.setBackground(table.getSelectionBackground());
  1608. }
  1609. btn1.addActionListener(new ActionListener() {
  1610. @Override
  1611. public void actionPerformed(ActionEvent e) {
  1612. JOptionPane.showMessageDialog(null, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0013")/*预览*/);
  1613. }
  1614. });
  1615. return btn1;
  1616. }
  1617. return null;
  1618. }
  1619. }
  1620. private class BtnTableCellEditor extends DefaultCellEditor {
  1621. private static final long serialVersionUID = 103249569489177021L;
  1622. public BtnTableCellEditor(JCheckBox checkBox) {
  1623. super(checkBox);
  1624. }
  1625. JLabel label = new JLabel();
  1626. @Override
  1627. public Component getTableCellEditorComponent(JTable table,
  1628. Object value, boolean isSelected, int row, int column) {
  1629. table.setRowSelectionInterval(row, row);
  1630. if (column == 5) {
  1631. return new BtnPanel(row);
  1632. } else if (column == 1) {
  1633. String strbtn = (value == null) ? "" : value.toString();
  1634. // NCFileVO file = (NCFileVO) getfiletablemodel().getVO(
  1635. // row);
  1636. // file.getTime()
  1637. HyperButton btn1 = new HyperButton(strbtn, strbtn);
  1638. btn1.addActionListener(new ActionListener() {
  1639. @Override
  1640. public void actionPerformed(ActionEvent e) {
  1641. // JOptionPane.showMessageDialog(null, "预览");
  1642. int row = getPatchInfoTable().getSelectedRow();
  1643. NCFileVO file = (NCFileVO) getfiletablemodel().getVO(
  1644. row);
  1645. String dsName = WorkbenchEnvironment.getInstance()
  1646. .getLoginBusiCenter().getDataSourceName();
  1647. try {
  1648. //更新浏览次数(前台调用,是否该下载后台?)
  1649. IFileSystemService ser= NCLocator.getInstance().lookup(IFileSystemService.class);
  1650. ser.updateBrowseTimes(file.getFullPath());
  1651. //前台浏览次数+1
  1652. int size=0;
  1653. if(file.getScantimes()==Integer.MAX_VALUE){
  1654. size=file.getScantimes();
  1655. }else{
  1656. size=file.getScantimes()+1;
  1657. }
  1658. file.setScantimes(size);
  1659. //下载文件()
  1660. //如果URL直接打开
  1661. if(file.getFiletype()!=null&&file.getFiletype().equalsIgnoreCase(FileTypeConst.URL)){
  1662. //没必要在自己系统里判断自己附件安全,让加上就加上//TODO 捎个URL的DNS解析IP判断,不写了真没必要检查
  1663. URL url = new URL(file.getPk_doc());
  1664. List<String> list =null;
  1665. list = getHostNameIP();
  1666. //判断URL IP或者hostname,是否在本地IP list,或者 name list 中,
  1667. //不在本地提示再打开
  1668. if(!IsStrInListIgnoreCase( url.getHost(),list)){
  1669. if(MessageDialog.showOkCancelDlg(ThFileContentPanel.this,NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0018")/*警告*/,NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0017")/**/)== MessageDialog.ID_OK){
  1670. ClientToolKit.showDocument(new URL(file.getPk_doc()), "_blank");
  1671. }
  1672. }else{//本地直接打开
  1673. ClientToolKit.showDocument(new URL(file.getPk_doc()), "_blank");
  1674. }
  1675. }else{//如果文件下载打开
  1676. FileManageServletClient.showFileInWeb(dsName, file
  1677. .getFullPath(), file.getTime());
  1678. }
  1679. } catch (Exception e1) {
  1680. MessageDialog.showErrorDlg(ThFileContentPanel.this, NCLangRes.getInstance().getStrByID("sftemp", "PasteAttachAction-0001")/*错误*/, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0014")/*浏览错误请查看日志!*/);
  1681. Logger.error(e1);
  1682. }
  1683. }
  1684. });
  1685. return btn1;
  1686. } else {
  1687. label.setText((value == null) ? "" : value.toString());
  1688. return label;
  1689. }
  1690. }
  1691. @Override
  1692. public void addCellEditorListener(CellEditorListener l) {
  1693. // System.out.println("addCellEditorListener");
  1694. super.addCellEditorListener(l);
  1695. }
  1696. @Override
  1697. public void cancelCellEditing() {
  1698. // System.out.println("cancelCellEditing");
  1699. super.cancelCellEditing();
  1700. }
  1701. @Override
  1702. public Object getCellEditorValue() {
  1703. return "";
  1704. }
  1705. @Override
  1706. public boolean isCellEditable(EventObject anEvent) {
  1707. //
  1708. return super.isCellEditable(anEvent);
  1709. }
  1710. @Override
  1711. public void removeCellEditorListener(CellEditorListener l) {
  1712. //
  1713. super.removeCellEditorListener(l);
  1714. }
  1715. @Override
  1716. public boolean shouldSelectCell(EventObject anEvent) {
  1717. // System.out.println("cancelCellEditing");
  1718. return super.shouldSelectCell(anEvent);
  1719. }
  1720. @Override
  1721. public boolean stopCellEditing() {
  1722. //
  1723. return super.stopCellEditing();
  1724. }
  1725. }
  1726. public boolean CheckTheSameFileName(NCFileNode node ,String filename)
  1727. {
  1728. //加入 前台校验 ,判断是否存在同名 文件,同名不允许添加
  1729. String nodepath = node.getFullPath();
  1730. String combinepath =nodepath;
  1731. if(!nodepath.endsWith("/")){
  1732. combinepath=combinepath+"/";
  1733. }
  1734. Collection<NCFileVO> cltvo = getTreenodefilecacheMap().get(nodepath);
  1735. if(cltvo!=null){
  1736. for(NCFileVO filevo :cltvo){
  1737. if(filevo.getFullPath().equalsIgnoreCase(combinepath+filename)){
  1738. MessageDialog.showErrorDlg(this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0015", null, new String[]{filename})/*文件名{0}重复,不能该文件上传!*/);
  1739. return true;
  1740. }
  1741. }
  1742. }
  1743. return false;
  1744. }
  1745. /**
  1746. * 新建文件夹,文件夹改名时,检查重复
  1747. * @param node
  1748. * @param foldername
  1749. * @return
  1750. */
  1751. public boolean CheckTheSameFolderName(TreeNode node ,String foldername)
  1752. {
  1753. //加入 前台校验 ,判断是否存在同名 文件,同名不允许添加
  1754. for(int noden=0; noden<node.getChildCount();noden++)
  1755. {
  1756. TreeNode subnode =node.getChildAt(noden);
  1757. //如果选择node下有同名的node
  1758. if(foldername.trim().equalsIgnoreCase(subnode.toString().trim()))
  1759. {
  1760. MessageDialog.showErrorDlg(ThFileContentPanel.this, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/, NCLangRes.getInstance().getStrByID("sfbase", "FileManageUI-000000", null, new String[]{foldername})/*文件存在:{0}*/);
  1761. return true;
  1762. }
  1763. }
  1764. return false;
  1765. }
  1766. protected TreeNode[] getTreePath(TreeNode node) {
  1767. List<TreeNode> list = new ArrayList<TreeNode>();
  1768. TreeNode temp = node;
  1769. while (temp != null && !temp.equals(rootNode)) {
  1770. list.add(0, temp);
  1771. temp = temp.getParent();
  1772. }
  1773. list.add(0, rootNode);
  1774. return list.toArray(new TreeNode[0]);
  1775. }
  1776. private String convertTreePathToString(TreeNode[] nodes) {
  1777. StringBuilder sb = new StringBuilder();
  1778. int count = nodes == null ? 0 : nodes.length;
  1779. int index = 0;
  1780. // if (!getPatchTree().isRootVisible())
  1781. index = 1;
  1782. for (int i = index; i < count; i++) {
  1783. if (sb.length() > 0)
  1784. sb.append("/");
  1785. sb.append(nodes[i]);
  1786. }
  1787. return sb.toString();
  1788. }
  1789. /**
  1790. * 不管用何种方式上传后,刷新树和表
  1791. * @param parentfoldernode
  1792. * @param newaddfilevo
  1793. */
  1794. protected void nodeToFileVO(NCFileNode parentfoldernode, NCFileNode newaddfilevo) {
  1795. NCFileVO newfilevo = new NCFileVO();
  1796. String newpath = "";
  1797. if(parentfoldernode.getFullPath().endsWith("/")){
  1798. newpath=parentfoldernode.getFullPath();
  1799. }else{
  1800. newpath=parentfoldernode.getFullPath()+"/";
  1801. }
  1802. newfilevo.setPath(newpath+newaddfilevo.getFullPath());
  1803. newfilevo.setCreator(newaddfilevo.getCreator());
  1804. newfilevo.setTime(newaddfilevo.getTime());
  1805. newfilevo.setFileLen(newaddfilevo.getFileLen());
  1806. newfilevo.setFiletype(FileTypeConst.getFileTypeByFileName(newaddfilevo.getFullPath()));
  1807. //刷新界面
  1808. refreshUI(parentfoldernode, newfilevo);
  1809. }
  1810. protected void refreshUI(NCFileNode parentfoldernode, NCFileVO newfilevo) {
  1811. //加入树缓存
  1812. ArrayList<NCFileVO> arr = new ArrayList<NCFileVO>();
  1813. if(getTreenodefilecacheMap().get(parentfoldernode.getFullPath())!=null){
  1814. arr.addAll(getTreenodefilecacheMap().get(parentfoldernode.getFullPath()));
  1815. }
  1816. arr.add(newfilevo);
  1817. parentfoldernode.getFilemap().put(newfilevo.getFullPath(),newfilevo);
  1818. getTreenodefilecacheMap().put(parentfoldernode.getFullPath(),arr);
  1819. //如果不是根的话,选根时也能查看到,加入跟缓存
  1820. ArrayList<NCFileVO> arrroot = new ArrayList<NCFileVO>();
  1821. if(getTreenodefilecacheMap().get("root")!=null){
  1822. arrroot.addAll(getTreenodefilecacheMap().get("root"));
  1823. }
  1824. arrroot.add(newfilevo);
  1825. getTreenodefilecacheMap().put("root",arrroot);
  1826. if(!parentfoldernode.getFullPath().equalsIgnoreCase(rootDirStr)){
  1827. // ... 不是根的操作???
  1828. }else{
  1829. arr =(ArrayList<NCFileVO>) getTreenodefilecacheMap().get("root");
  1830. }
  1831. //刷新table
  1832. if(PAGE_STATE==BROWSELISTTABLE_STATE){
  1833. getfiletablemodel().clearTable();
  1834. getfiletablemodel().addVO(arr.toArray(new NCFileVO[0]));
  1835. }else{
  1836. refreshUIbyClickTree();
  1837. }
  1838. //状态栏
  1839. refreshStatuBar();
  1840. }
  1841. private class BottomBorder extends AbstractBorder{
  1842. private static final long serialVersionUID = 1L;
  1843. protected int left, right, top, bottom;
  1844. public BottomBorder(int top, int left, int bottom, int right) {
  1845. this.top = top;
  1846. this.right = right;
  1847. this.bottom = bottom;
  1848. this.left = left;
  1849. }
  1850. @Override
  1851. public void paintBorder(Component c, Graphics g, int x, int y,int width, int height) {
  1852. Color oldColor = g.getColor();
  1853. g.setColor(Color.gray);
  1854. g.drawLine(x, y+height-1, x+width, y+height-1);
  1855. g.setColor(oldColor);
  1856. // g.drawLine(0, height, width, height);
  1857. }
  1858. public Insets getBorderInsets(Component c) {
  1859. return getBorderInsets();
  1860. }
  1861. public Insets getBorderInsets(Component c, Insets insets) {
  1862. insets.left = left;
  1863. insets.top = top;
  1864. insets.right = right;
  1865. insets.bottom = bottom;
  1866. return insets;
  1867. }
  1868. public Insets getBorderInsets() {
  1869. return new Insets(top, left, bottom, right);
  1870. }
  1871. public boolean isBorderOpaque() { return true; }
  1872. }
  1873. /* begin 权限处理*/
  1874. private boolean uploadenable= true;
  1875. private boolean downloadenable = true;
  1876. private boolean deleteenable = true;
  1877. private boolean browseenable = true;
  1878. private boolean renameenable = true;
  1879. private boolean showenable = true;
  1880. /**
  1881. *
  1882. * @param validButton
  1883. */
  1884. public void setUploadFileEnable(boolean validButton) {
  1885. uploadenable=validButton ;
  1886. this.uploadAction.setEnabled(validButton);
  1887. this.uprefaction.setEnabled(validButton);
  1888. this.gpyaction.setEnabled(validButton);
  1889. this.pasteaction.setEnabled(validButton);
  1890. this.uploadurlaction.setEnabled(validButton);
  1891. }
  1892. public void setCreateNewFolderEnable(boolean validButton) {
  1893. this.getNewfolderaction().setEnabled(validButton);
  1894. this.getNewfolderPopAction().setEnabled(validButton);
  1895. }
  1896. public void setDeleteNodeEnable(boolean validButton) {
  1897. //对于文件夹操作
  1898. this.getDelfolderaction().setEnabled(validButton);
  1899. getDelfolderPopAction().setEnabled(validButton);
  1900. // 对于文件 删除怎么办
  1901. //1(对于文件)设置全局标志 表示 是否可删除??
  1902. //2(对于文件) 刷新table??
  1903. this.deleteenable = validButton ;
  1904. }
  1905. public void setDownloadFileEnable(boolean validButton) {
  1906. //1设置全局标志 表示 是否可删除??
  1907. //2 刷新table??
  1908. this.downloadenable = validButton;
  1909. }
  1910. public void setShowFileEnable(boolean validButton) {
  1911. //1设置全局标志 表示 是否可删除??
  1912. //2 刷新table??
  1913. showenable = validButton;
  1914. }
  1915. public void setRenameNodeEnable(boolean validButton) {
  1916. //
  1917. this.renameenable = validButton ;
  1918. this.getRenamefolderaction().setEnabled(validButton);
  1919. this.getRenamefolderPopAction().setEnabled(validButton);
  1920. this.getPatchTree().setEditable(validButton);
  1921. //1设置全局标志 表示 是否可删除?? 删除时判断提示
  1922. //2 刷新table??
  1923. }
  1924. /* end 权限处理*/
  1925. public void setBilltypeComBoxEnable(boolean validButton){
  1926. this.getComboxbilltype().setVisible(validButton);
  1927. }
  1928. /**
  1929. *
  1930. * @param map 显示名,根路径值
  1931. */
  1932. public void setBilltypeComBoxData(Map<String,String> map){
  1933. this.getComboxbilltype().removeAllItems();
  1934. for(String disname :map.keySet()){
  1935. ItemObj item = new ItemObj(disname,map.get(disname));
  1936. this.getComboxbilltype().addItem(item);
  1937. }
  1938. }
  1939. public List<String> getHostNameIP(){
  1940. List<String> list = new ArrayList<String>();
  1941. InetAddress addr;
  1942. String hostname =null ;
  1943. try {
  1944. addr = InetAddress.getLocalHost();
  1945. hostname= addr.getHostName();
  1946. } catch (UnknownHostException e) {
  1947. Logger.error(e);
  1948. }
  1949. list.add("127.0.0.1");
  1950. list.add("localhost");
  1951. if(hostname!=null){
  1952. list.add(hostname);
  1953. String [] arrip = getAllLocalHostIP(hostname);
  1954. if(arrip!=null){
  1955. list.addAll(Arrays.asList(arrip));
  1956. }
  1957. }
  1958. return list ;
  1959. }
  1960. public String[] getAllLocalHostIP(String hostName) {
  1961. String[] ret = null;
  1962. try {
  1963. if (hostName.length() > 0) {
  1964. InetAddress[] addrs = InetAddress.getAllByName(hostName);
  1965. if (addrs.length > 0) {
  1966. ret = new String[addrs.length];
  1967. for (int i = 0; i < addrs.length; i++) {
  1968. ret[i] = addrs[i].getHostAddress();
  1969. }
  1970. }
  1971. }
  1972. } catch (Exception ex) {
  1973. ret = null;
  1974. }
  1975. return ret;
  1976. }
  1977. public boolean IsStrInListIgnoreCase(String str,List<String> list){
  1978. boolean flag = false ;
  1979. if(str==null||list==null){
  1980. return flag ;
  1981. }
  1982. for(String s :list){
  1983. if(s.equalsIgnoreCase(str)){
  1984. flag = true ;
  1985. break ;
  1986. }
  1987. }
  1988. return flag ;
  1989. }
  1990. }