 package com.connor.erp.ProcessImport;
 
 import com.connor.erp.BomImport.BomTransferCommand;
 import com.connor.erp.ItemAddTransferSendToERP.SendToERPCommand;
 import com.connor.erp.toolkit.AimType;
 import com.teamcenter.rac.aif.AbstractAIFCommand;
 import com.teamcenter.rac.aif.AbstractAIFDialog;
 import com.teamcenter.rac.util.HyperLink;
 import com.teamcenter.rac.util.Utilities;
 import com.teamcenter.rac.util.VerticalLayout;
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.LayoutManager;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import javax.swing.JButton;
 import javax.swing.JFileChooser;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.filechooser.FileFilter;
 
 public class ValidateFailDialog extends AbstractAIFDialog {
   private static final long serialVersionUID = 1L;
   
   private JButton btnConfirm;
   
   private JButton btnReport;
   
   private String errorInfo;
   
   private String title;
   
   private String labelInfo;
   
   private boolean isVisibleErrorInfo = false;
   
   private JPanel parentPanel;
   
   private JPanel paneButton;
   
   private JPanel infoPanel;
   
   private JPanel detailPanel;
   
   private JPanel additionalInfoPanel;
   
   private HyperLink moreButton;
   
   private HyperLink lessButton;
   
   protected JScrollPane scroller;
   
/*  79 */   protected AbstractAIFCommand command = null;
   
/*  81 */   protected ProcessImportHandler handler = null;
   
   protected String dialogType;
   
   AimType aimType;
   
   public boolean isVisibleErrorInfo() {
/*  91 */     return this.isVisibleErrorInfo;
   }
   
   public void setVisibleErrorInfo(boolean isVisibleErrorInfo) {
/*  98 */     this.isVisibleErrorInfo = isVisibleErrorInfo;
   }
   
   public ValidateFailDialog(String perrorInfo, String ptitle) {
/* 102 */     super(false);
/* 103 */     this.errorInfo = perrorInfo;
/* 104 */     this.title = ptitle;
/* 105 */     initUI();
   }
   
   public ValidateFailDialog(String plabelInfo, String ptitle, String perrorInfo) {
/* 109 */     super(false);
/* 110 */     this.labelInfo = plabelInfo;
/* 111 */     this.title = ptitle;
/* 112 */     this.errorInfo = perrorInfo;
/* 113 */     initUI();
   }
   
   public ValidateFailDialog(String plabelInfo, String ptitle, String perrorInfo, ProcessImportHandler handler, String dialogType) {
/* 117 */     super(false);
/* 118 */     this.labelInfo = plabelInfo;
/* 119 */     this.title = ptitle;
/* 120 */     this.errorInfo = perrorInfo;
/* 121 */     this.handler = handler;
/* 122 */     this.dialogType = dialogType;
/* 123 */     initUI();
   }
   
   public ValidateFailDialog(String plabelInfo, String ptitle, String perrorInfo, AbstractAIFCommand command, String dialogType) {
/* 127 */     super(false);
/* 128 */     this.labelInfo = plabelInfo;
/* 129 */     this.title = ptitle;
/* 130 */     this.errorInfo = perrorInfo;
/* 131 */     this.command = command;
/* 132 */     this.dialogType = dialogType;
/* 133 */     initUI();
   }
   
   public ValidateFailDialog(String plabelInfo, String ptitle, String perrorInfo, AbstractAIFCommand command, String dialogType, AimType aimType) {
/* 137 */     super(false);
/* 138 */     this.labelInfo = plabelInfo;
/* 139 */     this.title = ptitle;
/* 140 */     this.errorInfo = perrorInfo;
/* 141 */     this.command = command;
/* 142 */     this.dialogType = dialogType;
/* 143 */     this.aimType = aimType;
/* 144 */     initUI();
   }
   
   public void initUI() {
/* 151 */     setTitle(this.title);
/* 152 */     this.parentPanel = new JPanel((LayoutManager)new VerticalLayout(4, 2, 2, 2, 2));
/* 153 */     this.moreButton = new HyperLink("更多...");
/* 154 */     this.moreButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent actionevent) {
/* 157 */             ValidateFailDialog.this.resizeDialog(-1);
/* 158 */             ValidateFailDialog.this.setShowDetails(true);
           }
         });
/* 161 */     this.lessButton = new HyperLink("更少...");
/* 162 */     this.lessButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent actionevent) {
/* 165 */             ValidateFailDialog.this.setShowDetails(false);
           }
         });
/* 169 */     JLabel errorInfolabel = new JLabel("<html>" + this.errorInfo + "</html>");
/* 171 */     this.detailPanel = new JPanel();
/* 172 */     this.detailPanel.setVisible(false);
/* 179 */     if (this.labelInfo.equals("所要导入的数据在主组织中已经存在，请查看详细！")) {
/* 180 */       this.parentPanel.add("top.nobind", new JLabel("<html><font size=\"5\">验证失败！</font><br><font size=\"3\">" + this.labelInfo + "</font></html>"));
     } else {
/* 182 */       this.parentPanel.add("top.nobind", new JLabel("<html><font size=\"5\">" + this.labelInfo + "</font></html>"));
     } 
/* 186 */     this.parentPanel.add("top.nobind.right", (Component)this.moreButton);
/* 187 */     this.parentPanel.add("top.nobind.right", (Component)this.lessButton);
/* 188 */     this.scroller = new JScrollPane();
/* 189 */     this.infoPanel = new JPanel();
/* 190 */     this.scroller.getViewport().add(this.infoPanel);
/* 191 */     this.infoPanel.add(errorInfolabel);
/* 192 */     String s = Utilities.getCookie("ValidateFailDialog", getClass().getName() + "." + "ShowDetails", true);
/* 193 */     setShowDetails((s != null && s.equalsIgnoreCase("true")));
/* 194 */     this.parentPanel.add("unbound.bind.center.top", this.scroller);
/* 196 */     this.btnConfirm = new JButton("确认");
/* 197 */     this.btnConfirm.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
/* 201 */             ValidateFailDialog.this.dispose();
/* 202 */             if (!ValidateFailDialog.this.labelInfo.contains("排队"))
/* 203 */               if (ValidateFailDialog.this.command != null) {
/* 204 */                 if (ValidateFailDialog.this.command instanceof SendToERPCommand) {
/* 205 */                   if (ValidateFailDialog.this.dialogType.equals("task")) {
/* 206 */                     ((SendToERPCommand)ValidateFailDialog.this.command).postDialogForTask();
/* 207 */                   } else if (ValidateFailDialog.this.dialogType.equals("item")) {
/* 208 */                     ((SendToERPCommand)ValidateFailDialog.this.command).postDialogForItem();
/* 209 */                   } else if (ValidateFailDialog.this.dialogType.equals("process")) {
/* 210 */                     ((SendToERPCommand)ValidateFailDialog.this.command).postDialogForMeProcess();
                   } 
/* 212 */                 } else if (ValidateFailDialog.this.command instanceof BomTransferCommand) {
/* 213 */                   if (ValidateFailDialog.this.dialogType.equals("task")) {
/* 214 */                     ((BomTransferCommand)ValidateFailDialog.this.command).postDialogForTask(ValidateFailDialog.this.aimType);
/* 215 */                   } else if (ValidateFailDialog.this.dialogType.equals("bom")) {
/* 216 */                     ((BomTransferCommand)ValidateFailDialog.this.command).postDialogForBom(ValidateFailDialog.this.aimType);
                   } 
                 } 
/* 219 */               } else if (ValidateFailDialog.this.handler != null) {
/* 220 */                 if (ValidateFailDialog.this.dialogType.equals("task")) {
/* 221 */                   ValidateFailDialog.this.handler.postDialogForTask(true);
/* 222 */                 } else if (ValidateFailDialog.this.dialogType.equals("route")) {
/* 223 */                   ValidateFailDialog.this.handler.postDialogForRoute(true);
                 } 
               }  
           }
         });
/* 230 */     this.btnReport = new JButton("生成TXT报告");
/* 231 */     this.btnReport.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
/* 235 */             ValidateFailDialog.this.createTxt();
           }
         });
/* 240 */     this.paneButton = new JPanel();
/* 241 */     this.paneButton.add(this.btnConfirm);
/* 242 */     this.paneButton.add(this.btnReport);
/* 243 */     this.parentPanel.add("bottom.bind.center.top", this.paneButton);
/* 244 */     getContentPane().setLayout(new BorderLayout());
/* 245 */     getContentPane().add("Center", this.parentPanel);
   }
   
   private void resizeDialog(int i) {
/* 249 */     if (i != 0) {
/* 250 */       Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
/* 251 */       this.infoPanel.revalidate();
/* 252 */       Rectangle rectangle = this.scroller.getViewport().getBounds();
/* 253 */       Rectangle rectangle1 = getBounds();
/* 254 */       Rectangle rectangle2 = null;
/* 255 */       if (rectangle.height <= 0)
/* 256 */         rectangle2 = rectangle1; 
/* 257 */       rectangle.height = this.infoPanel.getHeight();
/* 258 */       this.scroller.getViewport().setBounds(rectangle);
/* 259 */       this.scroller.setBounds(rectangle);
/* 260 */       this.scroller.setPreferredSize(new Dimension(rectangle.width, rectangle.height));
/* 261 */       rectangle.height += i;
/* 262 */       if (rectangle2 != null)
/* 263 */         i = rectangle.height; 
/* 264 */       rectangle1.height += i;
/* 265 */       int j = 0;
/* 266 */       if (this.additionalInfoPanel != null)
/* 267 */         j = (this.additionalInfoPanel.getSize()).height; 
/* 268 */       if (rectangle1.height < rectangle.height + j + 50)
/* 269 */         rectangle1.height = rectangle.height + j + 50; 
/* 270 */       if (rectangle1.height > (int)(0.75D * dimension.getHeight()))
/* 271 */         rectangle1.height = (int)(0.75D * dimension.getHeight()); 
/* 272 */       setBounds(rectangle1);
/* 273 */       validate();
/* 274 */       repaint();
     } 
   }
   
   public void setShowDetails(boolean flag) {
/* 279 */     this.scroller.setVisible(flag);
/* 280 */     if (flag) {
/* 281 */       this.moreButton.setVisible(false);
/* 282 */       this.lessButton.setVisible(true);
     } else {
/* 284 */       this.moreButton.setVisible(true);
/* 285 */       this.lessButton.setVisible(false);
     } 
/* 287 */     validate();
/* 288 */     repaint();
/* 289 */     String s = getClass().getName();
/* 290 */     if (isShowing())
/* 291 */       Utilities.setCookie("ValidateFailDialog", true, s + "." + "ShowDetails", String.valueOf(flag)); 
   }
   
   private void createTxt() {
/* 299 */     JFileChooser jfc = new JFileChooser();
/* 300 */     ExampleFileFilter filter = new ExampleFileFilter();
/* 301 */     filter.addExtension("txt");
/* 302 */     filter.setDescription("txt File");
/* 303 */     jfc.setFileFilter(filter);
/* 304 */     int ret = jfc.showSaveDialog(null);
/* 306 */     if (ret == 0) {
/* 307 */       File file = jfc.getSelectedFile();
/* 308 */       String fname = jfc.getName(file);
/* 309 */       if (!fname.endsWith(".log") && !fname.endsWith(".LOG") && 
/* 310 */         !fname.endsWith(".txt") && !fname.endsWith(".TXT"))
/* 311 */         fname = fname.concat(".txt"); 
/* 314 */       file = jfc.getCurrentDirectory();
/* 315 */       String saveFilePath = file.getPath().concat(File.separator).concat(fname);
/* 316 */       file = new File(saveFilePath);
/* 317 */       FileWriter fw = null;
       try {
/* 319 */         fw = new FileWriter(file);
/* 320 */       } catch (IOException e) {
/* 321 */         e.printStackTrace();
         return;
       } 
/* 324 */       String newStr = this.errorInfo.replace("<br>", "\r\n");
       try {
/* 326 */         fw.write(newStr);
/* 327 */         fw.flush();
/* 328 */         fw.close();
/* 329 */       } catch (IOException e) {
/* 330 */         e.printStackTrace();
       } 
     } 
   }
   
   public class ExampleFileFilter extends FileFilter {
/* 336 */     private Hashtable<String, ExampleFileFilter> filters = null;
     
/* 337 */     private String description = null;
     
/* 338 */     private String fullDescription = null;
     
     private boolean useExtensionsInDescription = true;
     
     public ExampleFileFilter() {
/* 348 */       this.filters = new Hashtable<String, ExampleFileFilter>();
     }
     
     public ExampleFileFilter(String extension) {
/* 358 */       this(extension, (String)null);
     }
     
     public ExampleFileFilter(String extension, String description) {
/* 371 */       this();
/* 372 */       if (extension != null)
/* 373 */         addExtension(extension); 
/* 374 */       if (description != null)
/* 375 */         setDescription(description); 
     }
     
     public ExampleFileFilter(String[] filters) {
/* 387 */       this(filters, (String)null);
     }
     
     public ExampleFileFilter(String[] filters, String description) {
/* 400 */       this();
/* 401 */       for (int i = 0; i < filters.length; i++)
/* 403 */         addExtension(filters[i]); 
/* 405 */       if (description != null)
/* 406 */         setDescription(description); 
     }
     
     public boolean accept(File f) {
/* 419 */       if (f != null) {
/* 420 */         if (f.isDirectory())
/* 421 */           return true; 
/* 423 */         String extension = getExtension(f);
/* 424 */         if (extension != null && this.filters.get(getExtension(f)) != null)
/* 425 */           return true; 
       } 
/* 429 */       return false;
     }
     
     public String getExtension(File f) {
/* 439 */       if (f != null) {
/* 440 */         String filename = f.getName();
/* 441 */         int i = filename.lastIndexOf('.');
/* 442 */         if (i > 0 && i < filename.length() - 1)
/* 443 */           return filename.substring(i + 1).toLowerCase(); 
       } 
/* 447 */       return null;
     }
     
     public void addExtension(String extension) {
/* 462 */       if (this.filters == null)
/* 463 */         this.filters = new Hashtable<String, ExampleFileFilter>(5); 
/* 465 */       this.filters.put(extension.toLowerCase(), this);
/* 466 */       this.fullDescription = null;
     }
     
     public String getDescription() {
/* 479 */       if (this.fullDescription == null)
/* 480 */         if (this.description == null || isExtensionListInDescription()) {
/* 481 */           this.fullDescription = (this.description == null) ? "(" : (String.valueOf(this.description) + 
/* 482 */             " (");
/* 484 */           Enumeration<String> extensions = this.filters.keys();
/* 485 */           if (extensions != null) {
/* 486 */             this.fullDescription = String.valueOf(this.fullDescription) + "." + (String)extensions.nextElement();
/* 487 */             while (extensions.hasMoreElements())
/* 488 */               this
/* 489 */                 .fullDescription = String.valueOf(this.fullDescription) + ", ." + (String)extensions.nextElement(); 
           } 
/* 492 */           this.fullDescription = String.valueOf(this.fullDescription) + ")";
         } else {
/* 494 */           this.fullDescription = this.description;
         }  
/* 497 */       return this.fullDescription;
     }
     
     public void setDescription(String description) {
/* 509 */       this.description = description;
/* 510 */       this.fullDescription = null;
     }
     
     public void setExtensionListInDescription(boolean b) {
/* 525 */       this.useExtensionsInDescription = b;
/* 526 */       this.fullDescription = null;
     }
     
     public boolean isExtensionListInDescription() {
/* 541 */       return this.useExtensionsInDescription;
     }
   }
 }

