 package com.connor.erp.toolkit;
 
 import com.connor.erp.BomImport.BomTransferCommand;
 import com.connor.erp.ItemAddTransferSendToERP.SendToERPCommand;
 import com.connor.erp.ProcessImport.ProcessAddTransferToERP.ProcessAddTransferToERPCommand;
 import com.connor.erp.ProcessImport.ProcessChgTransferToERP.ProcessChgTransferToERPCommand;
 import com.teamcenter.rac.aif.AbstractAIFDialog;
 import com.teamcenter.rac.util.HyperLink;
 import com.teamcenter.rac.util.Separator;
 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 IsContinueDialog extends AbstractAIFDialog {
   private static final long serialVersionUID = 1L;
   
   private JButton btnConfirm;
   
   private JButton btnReport;
   
   private String errorInfo;
   
   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;
   
   private JScrollPane scroller;
   
/*  78 */   private BomTransferCommand bomCommand = null;
   
/*  80 */   private ProcessChgTransferToERPCommand processChgCommand = null;
   
/*  82 */   private ProcessAddTransferToERPCommand processAddCommand = null;
   
/*  84 */   private SendToERPCommand sendToERPCommand = null;
   
   private AimType aimType;
   
   private String callBack;
   
   public boolean isVisibleErrorInfo() {
/*  94 */     return this.isVisibleErrorInfo;
   }
   
   public void setVisibleErrorInfo(boolean isVisibleErrorInfo) {
/* 101 */     this.isVisibleErrorInfo = isVisibleErrorInfo;
   }
   
   public IsContinueDialog(BomTransferCommand bomCommand, String callBack, AimType aimType, String plabelInfo, String perrorInfo) {
/* 105 */     super(false);
/* 106 */     this.bomCommand = bomCommand;
/* 107 */     this.callBack = callBack;
/* 108 */     this.aimType = aimType;
/* 109 */     this.labelInfo = plabelInfo;
/* 110 */     this.errorInfo = perrorInfo;
/* 111 */     initUI();
   }
   
   public IsContinueDialog(BomTransferCommand bomCommand, AimType aimType, String plabelInfo, String perrorInfo) {
/* 116 */     super(false);
/* 117 */     this.bomCommand = bomCommand;
/* 118 */     this.aimType = aimType;
/* 119 */     this.labelInfo = plabelInfo;
/* 120 */     this.errorInfo = perrorInfo;
/* 121 */     initUI();
   }
   
   public IsContinueDialog(ProcessChgTransferToERPCommand processChgCommand, String plabelInfo, String perrorInfo) {
/* 125 */     super(false);
/* 126 */     this.processChgCommand = processChgCommand;
/* 127 */     this.labelInfo = plabelInfo;
/* 128 */     this.errorInfo = perrorInfo;
/* 129 */     initUI();
   }
   
   public IsContinueDialog(ProcessAddTransferToERPCommand processAddCommand, String plabelInfo, String perrorInfo) {
/* 133 */     super(false);
/* 134 */     this.processAddCommand = processAddCommand;
/* 135 */     this.labelInfo = plabelInfo;
/* 136 */     this.errorInfo = perrorInfo;
/* 137 */     initUI();
   }
   
   public IsContinueDialog(SendToERPCommand sendToERPCommand, String plabelInfo, String perrorInfo) {
/* 141 */     super(false);
/* 142 */     this.sendToERPCommand = sendToERPCommand;
/* 143 */     this.labelInfo = plabelInfo;
/* 144 */     this.errorInfo = perrorInfo;
/* 145 */     initUI();
   }
   
   public void initUI() {
/* 152 */     setTitle("是否继续");
/* 153 */     this.parentPanel = new JPanel((LayoutManager)new VerticalLayout(4, 2, 2, 2, 2));
/* 154 */     this.moreButton = new HyperLink("更多...");
/* 155 */     this.moreButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent actionevent) {
/* 158 */              resizeDialog(-1);
/* 159 */              setShowDetails(true);
           }
         });
/* 162 */     this.lessButton = new HyperLink("更少...");
/* 163 */     this.lessButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent actionevent) {
/* 166 */              setShowDetails(false);
           }
         });
/* 170 */     JLabel errorInfolabel = new JLabel("<html>" + this.errorInfo + "</html>");
/* 172 */     this.detailPanel = new JPanel();
/* 173 */     this.detailPanel.setVisible(false);
/* 174 */     this.parentPanel.add("top.nobind.left", new JLabel("验证所选对象结果"));
/* 175 */     this.parentPanel.add("top.bind", (Component)new Separator());
/* 176 */     this.parentPanel.add("top.bind", new JLabel("<html>" + this.labelInfo + "</html>"));
/* 177 */     this.parentPanel.add("top.bind", (Component)new Separator());
/* 178 */     this.parentPanel.add("top.nobind.right", (Component)this.moreButton);
/* 179 */     this.parentPanel.add("top.nobind.right", (Component)this.lessButton);
/* 180 */     this.scroller = new JScrollPane();
/* 181 */     this.infoPanel = new JPanel();
/* 182 */     this.scroller.getViewport().add(this.infoPanel);
/* 183 */     this.infoPanel.add(errorInfolabel);
/* 184 */     String s = Utilities.getCookie("ValidateFailDialog", getClass().getName() + "." + "ShowDetails", true);
/* 185 */     setShowDetails((s != null && s.equalsIgnoreCase("true")));
/* 186 */     this.parentPanel.add("unbound.bind.center.top", this.scroller);
/* 188 */     this.btnConfirm = new JButton("是");
/* 189 */     this.btnConfirm.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
/* 193 */              dispose();
/* 194 */             if ( bomCommand != null) {
/* 195 */               if ( callBack != null) {
/* 196 */                 if ("loadDataForPrivilege1".equals( callBack)) {
/* 197 */                    bomCommand.loadDataForPrivilege1( aimType);
/* 198 */                 } else if ("loadData1".equals( callBack)) {
/* 199 */                    bomCommand.loadData1( aimType);
	                 } 
	               } else {
	/* 202 */                  bomCommand.postDialog2( aimType);
	               } 
/* 204 */             } else if ( processChgCommand != null) {
/* 205 */                processChgCommand.postDialog2();
/* 206 */             } else if ( processAddCommand != null) {
/* 207 */                processAddCommand.postDialog2();
/* 208 */             } else if ( sendToERPCommand != null) {
/* 209 */                sendToERPCommand.postDialog();
             } 
           }
         });
/* 215 */     this.btnReport = new JButton("否");
/* 216 */     this.btnReport.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
/* 220 */              dispose();
           }
         });
/* 225 */     this.paneButton = new JPanel();
/* 226 */     this.paneButton.add(this.btnConfirm);
/* 227 */     this.paneButton.add(this.btnReport);
/* 228 */     this.parentPanel.add("bottom.bind.center.top", this.paneButton);
/* 229 */     getContentPane().setLayout(new BorderLayout());
/* 230 */     getContentPane().add("Center", this.parentPanel);
   }
   
   private void resizeDialog(int i) {
/* 234 */     if (i != 0) {
/* 235 */       Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
/* 236 */       this.infoPanel.revalidate();
/* 237 */       Rectangle rectangle = this.scroller.getViewport().getBounds();
/* 238 */       Rectangle rectangle1 = getBounds();
/* 239 */       Rectangle rectangle2 = null;
/* 240 */       if (rectangle.height <= 0)
/* 241 */         rectangle2 = rectangle1; 
/* 242 */       rectangle.height = this.infoPanel.getHeight();
/* 243 */       this.scroller.getViewport().setBounds(rectangle);
/* 244 */       this.scroller.setBounds(rectangle);
/* 245 */       this.scroller.setPreferredSize(new Dimension(rectangle.width, rectangle.height));
/* 246 */       rectangle.height += i;
/* 247 */       if (rectangle2 != null)
/* 248 */         i = rectangle.height; 
/* 249 */       rectangle1.height += i;
/* 250 */       int j = 0;
/* 251 */       if (this.additionalInfoPanel != null)
/* 252 */         j = (this.additionalInfoPanel.getSize()).height; 
/* 253 */       if (rectangle1.height < rectangle.height + j + 50)
/* 254 */         rectangle1.height = rectangle.height + j + 50; 
/* 255 */       if (rectangle1.height > (int)(0.75D * dimension.getHeight()))
/* 256 */         rectangle1.height = (int)(0.75D * dimension.getHeight()); 
/* 257 */       setBounds(rectangle1);
/* 258 */       validate();
/* 259 */       repaint();
     } 
   }
   
   public void setShowDetails(boolean flag) {
/* 264 */     this.scroller.setVisible(flag);
/* 265 */     if (flag) {
/* 266 */       this.moreButton.setVisible(false);
/* 267 */       this.lessButton.setVisible(true);
     } else {
/* 269 */       this.moreButton.setVisible(true);
/* 270 */       this.lessButton.setVisible(false);
     } 
/* 272 */     validate();
/* 273 */     repaint();
/* 274 */     String s = getClass().getName();
/* 275 */     if (isShowing())
/* 276 */       Utilities.setCookie("ValidateFailDialog", true, s + "." + "ShowDetails", String.valueOf(flag)); 
   }
   
   private void createTxt() {
/* 284 */     JFileChooser jfc = new JFileChooser();
/* 285 */     ExampleFileFilter filter = new ExampleFileFilter();
/* 286 */     filter.addExtension("txt");
/* 287 */     filter.setDescription("txt File");
/* 288 */     jfc.setFileFilter(filter);
/* 289 */     int ret = jfc.showSaveDialog(null);
/* 291 */     if (ret == 0) {
/* 292 */       File file = jfc.getSelectedFile();
/* 293 */       String fname = jfc.getName(file);
/* 294 */       if (!fname.endsWith(".log") && !fname.endsWith(".LOG") && 
/* 295 */         !fname.endsWith(".txt") && !fname.endsWith(".TXT"))
/* 296 */         fname = fname.concat(".txt"); 
/* 299 */       file = jfc.getCurrentDirectory();
/* 300 */       String saveFilePath = file.getPath().concat(File.separator).concat(fname);
/* 301 */       file = new File(saveFilePath);
/* 302 */       FileWriter fw = null;
       try {
/* 304 */         fw = new FileWriter(file);
/* 305 */       } catch (IOException e) {
/* 306 */         e.printStackTrace();
       } 
/* 308 */       String newStr = this.errorInfo.replace("<br>", "\r\n");
       try {
/* 310 */         fw.write(newStr);
/* 311 */         fw.flush();
/* 312 */         fw.close();
/* 313 */       } catch (IOException e) {
/* 314 */         e.printStackTrace();
       } 
     } 
   }
   
   public class ExampleFileFilter extends FileFilter {
/* 320 */     private Hashtable<String, ExampleFileFilter> filters = null;
     
/* 321 */     private String description = null;
     
/* 322 */     private String fullDescription = null;
     
     private boolean useExtensionsInDescription = true;
     
     public ExampleFileFilter() {
/* 332 */       this.filters = new Hashtable<String, ExampleFileFilter>();
     }
     
     public ExampleFileFilter(String extension) {
/* 342 */       this(extension, (String)null);
     }
     
     public ExampleFileFilter(String extension, String description) {
/* 355 */       this();
/* 356 */       if (extension != null)
/* 357 */         addExtension(extension); 
/* 358 */       if (description != null)
/* 359 */         setDescription(description); 
     }
     
     public ExampleFileFilter(String[] filters) {
/* 371 */       this(filters, (String)null);
     }
     
     public ExampleFileFilter(String[] filters, String description) {
/* 384 */       this();
/* 385 */       for (int i = 0; i < filters.length; i++)
/* 387 */         addExtension(filters[i]); 
/* 389 */       if (description != null)
/* 390 */         setDescription(description); 
     }
     
     public boolean accept(File f) {
/* 403 */       if (f != null) {
/* 404 */         if (f.isDirectory())
/* 405 */           return true; 
/* 407 */         String extension = getExtension(f);
/* 408 */         if (extension != null && this.filters.get(getExtension(f)) != null)
/* 409 */           return true; 
       } 
/* 413 */       return false;
     }
     
     public String getExtension(File f) {
/* 423 */       if (f != null) {
/* 424 */         String filename = f.getName();
/* 425 */         int i = filename.lastIndexOf('.');
/* 426 */         if (i > 0 && i < filename.length() - 1)
/* 427 */           return filename.substring(i + 1).toLowerCase(); 
       } 
/* 431 */       return null;
     }
     
     public void addExtension(String extension) {
/* 446 */       if (this.filters == null)
/* 447 */         this.filters = new Hashtable<String, ExampleFileFilter>(5); 
/* 449 */       this.filters.put(extension.toLowerCase(), this);
/* 450 */       this.fullDescription = null;
     }
     
     public String getDescription() {
/* 463 */       if (this.fullDescription == null)
/* 464 */         if (this.description == null || isExtensionListInDescription()) {
/* 465 */           this.fullDescription = (this.description == null) ? "(" : (String.valueOf(this.description) + 
/* 466 */             " (");
/* 468 */           Enumeration<String> extensions = this.filters.keys();
/* 469 */           if (extensions != null) {
/* 470 */             this.fullDescription = String.valueOf(this.fullDescription) + "." + (String)extensions.nextElement();
/* 471 */             while (extensions.hasMoreElements())
/* 472 */               this
/* 473 */                 .fullDescription = String.valueOf(this.fullDescription) + ", ." + (String)extensions.nextElement(); 
           } 
/* 476 */           this.fullDescription = String.valueOf(this.fullDescription) + ")";
         } else {
/* 478 */           this.fullDescription = this.description;
         }  
/* 481 */       return this.fullDescription;
     }
     
     public void setDescription(String description) {
/* 493 */       this.description = description;
/* 494 */       this.fullDescription = null;
     }
     
     public void setExtensionListInDescription(boolean b) {
/* 509 */       this.useExtensionsInDescription = b;
/* 510 */       this.fullDescription = null;
     }
     
     public boolean isExtensionListInDescription() {
/* 525 */       return this.useExtensionsInDescription;
     }
   }
 }
