 package com.connor.erp.materialquery.ViewStockOfERP;
 
 import com.teamcenter.rac.aif.AbstractAIFCommand;
 import com.teamcenter.rac.aif.AbstractAIFUIApplication;
 import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
 import com.teamcenter.rac.aifrcp.AIFUtility;
 import com.teamcenter.rac.kernel.TCComponentItem;
 import com.teamcenter.rac.kernel.TCComponentItemRevision;
 import com.teamcenter.rac.kernel.TCException;
 import com.teamcenter.rac.kernel.TCPreferenceService;
 import com.teamcenter.rac.kernel.TCSession;
 import com.teamcenter.rac.util.MessageBox;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 
 public class ViewStockOfERPHandler extends AbstractHandler {
   private static final String NHL_ERPQUERY_MENUAUTH = "NHL_ERPQuery_MenuAuth";
   
   private static final String NHL_ERPQUERY_INVENTORYITEM = "NHL_ERPQuery_InventoryItem";
   
   public Object execute(ExecutionEvent event) throws ExecutionException {
/*  51 */     AbstractAIFUIApplication application = AIFUtility.getCurrentApplication();
/*  52 */     TCSession session = (TCSession)application.getSession();
/*  53 */     if (application == null || application.getTargetComponent() == null) {
/*  54 */       MessageBox.post(application.getDesktop().getShell(), "请选中需要查询的物料！", "警告", 4);
/*  55 */       return null;
     } 
/*  57 */     String user_id = "";
     try {
/*  59 */       user_id = session.getUser().getProperty("user_id");
/*  60 */     } catch (TCException e1) {
/*  61 */       e1.printStackTrace();
     } 
/*  63 */     TCPreferenceService preferenceService = session.getPreferenceService();
/*  64 */     String[] users = preferenceService.getStringArray(4, "NHL_ERPQuery_MenuAuth");
/*  65 */     if (users != null && users.length > 0) {
/*  66 */       int roleLen = users.length;
/*  67 */       boolean hasRight = false;
/*  68 */       for (int i = 0; i < roleLen; i++) {
/*  69 */         if (user_id.equals(users[i].trim())) {
/*  70 */           hasRight = true;
           break;
         } 
       } 
/*  74 */       if (hasRight) {
/*  75 */         String[] itemTypes = preferenceService.getStringArray(4, "NHL_ERPQuery_InventoryItem");
/*  76 */         Vector<String> vecItemTypes = new Vector<String>();
/*  77 */         if (itemTypes != null && itemTypes.length > 0) {
/*  78 */           int itemTypesLen = itemTypes.length;
/*  79 */           for (int k = 0; k < itemTypesLen; k++)
/*  80 */             vecItemTypes.add(itemTypes[k].trim()); 
         } else {
/*  83 */           MessageBox.post(application.getDesktop().getShell(), "请配置首选项NHL_ERPQuery_InventoryItem！！", "警告", 4);
/*  84 */           return null;
         } 
/*  86 */         List<String> listItemId = new ArrayList<String>();
/*  87 */         InterfaceAIFComponent[] targetComponents = application.getTargetComponents();
/*  88 */         int targetComLen = targetComponents.length;
/*  89 */         for (int j = 0; j < targetComLen; j++) {
/*  90 */           if (targetComponents[j] instanceof TCComponentItemRevision) {
             try {
/*  92 */               if (vecItemTypes.contains(((TCComponentItemRevision)targetComponents[j]).getItem().getType())) {
                 try {
/*  94 */                   String item_id = targetComponents[j].getProperty("item_id");
/*  95 */                   if (!listItemId.contains(item_id))
/*  96 */                     listItemId.add(item_id); 
/*  98 */                 } catch (Exception e) {
/*  99 */                   e.printStackTrace();
                 } 
               } else {
/* 102 */                 MessageBox.post(application.getDesktop().getShell(), "请选中请选中首选项中存在的物料！！", "警告", 4);
/* 103 */                 return null;
               } 
/* 105 */             } catch (TCException e) {
/* 106 */               e.printStackTrace();
             } 
/* 108 */           } else if (targetComponents[j] instanceof TCComponentItem) {
/* 109 */             if (vecItemTypes.contains(((TCComponentItem)targetComponents[j]).getType())) {
               try {
/* 111 */                 String item_id = targetComponents[j].getProperty("item_id");
/* 112 */                 if (!listItemId.contains(item_id))
/* 113 */                   listItemId.add(item_id); 
/* 115 */               } catch (Exception e) {
/* 116 */                 e.printStackTrace();
               } 
             } else {
/* 119 */               MessageBox.post(application.getDesktop().getShell(), "请选中请选中首选项中存在的物料！！", "警告", 4);
/* 120 */               return null;
             } 
           } else {
/* 123 */             MessageBox.post(application.getDesktop().getShell(), "请选中查询的物料！！", "警告", 4);
/* 124 */             return null;
           } 
         } 
         try {
/* 128 */           AbstractAIFCommand command = new ViewStockOfERPCommand(session, application, listItemId);
/* 129 */           command.executeModal();
/* 130 */         } catch (Exception e) {
/* 131 */           e.printStackTrace();
         } 
       } else {
/* 134 */         MessageBox.post(application.getDesktop().getShell(), "你没有权限进行当前操作！！", "警告", 4);
/* 135 */         return null;
       } 
     } else {
/* 138 */       MessageBox.post(application.getDesktop().getShell(), "请配置首选项NHL_ERPQuery_MenuAuth！！", "警告", 4);
/* 139 */       return null;
     } 
/* 141 */     return null;
   }
 }
