• Agile Engineering Collaboration CustomAction


    package com.agile.cax.custom;

    import com.agile.api.*;
    import com.agile.cax.datatypes.*;
    import com.agile.cax.*;
    /**
     * This class implements methods, which are called during
     * CAXConnector Load and Save Actions. Please add your customizing
     * in a class implementing this interface and set your class as
     * an actionhandler inside the CAXClient.xml
     */
    public class CustomAction extends CAXAction implements ICAXAction {
     
     public CustomAction() {
      super();
     }

     public void setChangeValues__UNUSED(IChange change, IAglFields data) {
      try {
       IItem item = (IItem) getTools().getObject(data);
       if (item != null) {
        /* define the correct field ids here */
        Integer ItemCompanyField = new Integer("1111");
        /* or
         *
         * Integer ItemCompanyField= ItemConstants.ATT_TITLE_BLOCK_...
         * */
        Integer ChangeCompanyField=new Integer("1223");
        /* or
         *
         * Integer ChangeCompanyField= ChangeConstants.ATT_COVER_PAGE_...
         * */
        String company = item.getValue(ItemCompanyField).toString();
        /* or you can get the value from the given fields
         * eg if they were transmitted from CAD properties...
         *
         * String company=data.getByName("COMPANY").toString();
         */
       
        change.setValue(ChangeCompanyField, company);
       }
      } catch (Exception e) {
       e.printStackTrace(System.out);
      }
     }
     /**
      * called before creation of an Object. Modify the data here to
      * modify occurrence in interactive dialog and to define defaults for fields
      * @param IAglFields fields : list of name-value pairs
      * @throws Exception
      */
     public void checkCreateEntry__UNUSED(IAglFields fields) throws Exception {
      // **************************************************
      // **       Code added by John Loechli for Metaldyne
      // **  restrict Agile Number prefix to SPN, PRT, STN
      // **  sufix to .PRT, .DWG, .ASM, .FRM
      // **  body to 6 digits excludeing "000000"
      // **  if not valid continue Interactive     
      // **************************************************  
      Validator validate = new Validator(getClient(), getTools());
      String newNumber = fields.getByName("NUMBER").get_ValueToString();
      if ( !validate.checkNumberformat(newNumber) ) {
       throw new Exception("Invalid Format: "+validate.getErrMsg());
      }
      
       // **************************************************
       // **       End of Code added by John Loechli for Metaldyne
       // **************************************************          
     }
     /**
      * called before Save is executed. Modify the data here to
      * modify occurrence in dialog and to define defaults for fields
      * @param IAglTable table : table of objects
      * @throws Exception
      */
     private static String CAX_FIL_NAME="CAX_FIL_NAME";
     private static String SYMBILC_PART_ID="CAX_PART";
     public void saveDialogOK(IAglTable table) throws Exception {
      try {
       if (!getClient().getXMLConfig().getClientConfig().get("IntermaticDataLoad").toString().equalsIgnoreCase("ON")) { return ; }
           }  catch (Exception e) { return ;}
      String exception = "";
      try {
       IAglFieldsArray fc = table.get_FieldsArray();
       // cycle over all selected items
       for (int i=0; i< fc.size(); i++) {
        try {
         // get the current line
         IAglFields line = fc.get(i);
         // check the selection
         if (line.getByName("SAVE_FLAG") != null && line.getByName("SAVE_FLAG").get_ValueToString().equals("1") && (line.getByName("SAVED")==null || line.getByName("SAVED").get_ValueToString().equals("0")) ) {
          // object is selected for save
          String msg="";
          // get the part id to be assigned
          String PartID = line.getByName(SYMBILC_PART_ID).get_ValueToString();
          String CadFil = line.getByName(CAX_FIL_NAME).get_ValueToString();
          if (CadFil.length()!=0) {
           // check if a part with this ID exists
           if (PartID.length()==0) {
            System.out.println("Warning: no PartID ("+SYMBILC_PART_ID+") for "+CadFil+" found in Database!");             
           } else {
            IAgileObject part = getTools().getObject(ItemConstants.CLASS_ITEM_BASE_CLASS, PartID, "");
            if (part!=null) {
             // Item is found, check the subclass
             if (!getTools().isPart(part)) {
              msg = "Warning: Found Item "+PartID+" for "+CadFil+" is not a Part subclass instance!";
             }
            } else {
             msg = "Error: Part "+PartID+" for "+CadFil+" doesn't exist in Database!";
            }
            if (msg.length()>0) {
             System.out.println(msg);
             if (exception.length()==0) { exception = msg; } else { exception=exception+"\n"+msg; }
            } else {
             System.out.println("OK: Part "+PartID+" for "+CadFil+" found in Database!");      
            }       
           }       
          }
         }
        } catch (Exception ee) {
         System.out.println(ee);
         ee.printStackTrace(System.out);
        }
       }
        
      } catch (Exception e) {
       // the object already exists in agile, therefore no cax_new_number is given
       e.printStackTrace(System.out);
      }
      if (exception.length()>0) throw new RuntimeException(exception);
     }
     


    }

  • 相关阅读:
    2020毕业设计选用4412开发板,实战教程,小成果不放过
    学习嵌入式有决心4412再送免费教程
    iTOP4412开发板can测试工具使用文档
    iTOP4412Ubuntu系统源码ubuntu没有声音的解决办法
    修身养性,为人处事100条
    用X++实现有规律分割的长字符串,分别提取(如逗号隔开)
    自定义Dialog中对数组的取值
    Common实现任何Form定位查询转到当前Form种过滤符合条件的数据区域
    用X++得到当前用户是否有某Security Key的权限级别,完整Job演示
    获取table中的系统字段信息
  • 原文地址:https://www.cnblogs.com/leojun/p/1869497.html
Copyright © 2020-2023  润新知