通过重载PSE粘贴命令,增加粘贴后处理

通过重载PSE粘贴命令,增加粘贴后处理:

1.1找到pse 粘贴命令的properties配置文件

在com.teamcenter.rac.tcapp13.0.0.jar的 com.teamcenter.rac.pse下的pse.properties中:


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Edit->Paste (pasteAction inherited from tc/common/actions)
pastePropertyAction=com.teamcenter.rac.pse.actions.PasteProperty
pastePropertyAction.COMMAND=pasteCommand
pasteCommand=com.teamcenter.rac.pse.commands.MoveToCommand
pasteBOMLineAsCommand=com.teamcenter.rac.pse.commands.PasteAsPSECommand
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

在自己的rcp项目中,添加com.teamcenter.rac.pse包,创建pse_user.properties文件:

# @<COPYRIGHT>@
# ==================================================
# Copyright 2010.
# Siemens Product Lifecycle Management Software Inc.
# All Rights Reserved.
# ==================================================
# @<COPYRIGHT>@

# File description:
# This properties file contains all keys pertaining to the PSE package.

pasteCommand=com.teamcenter.rac.pse.commands.ZLMoveToCommand
#pasteBOMLineAsCommand=com.teamcenter.rac.pse.commands.ZLPasteAsPSECommand

1.2新建命令,并集成原有命令

// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space

package com.teamcenter.rac.pse.commands;

import com.teamcenter.rac.aif.InterfaceAIFOperationExecutionListener;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.commands.paste.PasteCommand;
import com.teamcenter.rac.commands.paste.PasteDialog;
import com.teamcenter.rac.common.Activator;
import com.teamcenter.rac.kernel.*;
import com.teamcenter.rac.pse.commands.MoveToCommand;
import com.teamcenter.rac.pse.common.BOMLineMarkupNode;
import com.teamcenter.rac.pse.dialogs.BOMPasteDialog;
import com.teamcenter.rac.pse.operations.MoveToOperation;
import com.teamcenter.rac.services.IProgressCheckingService;
import com.teamcenter.rac.util.*;
import com.teamcenter.rac.util.log.TcLogger;

import java.awt.Frame;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.swt.widgets.Display;

public class ZLMoveToCommand extends MoveToCommand
{
private IProgressCheckingService m_progressCheckingService;
TcLogger logger=TcLogger.getLogger(ZLMoveToCommand.class);


public ZLMoveToCommand()
{
logger.info("测试1ZLMoveToCommand");
}

public ZLMoveToCommand(InterfaceAIFComponent ainterfaceaifcomponent[], Boolean boolean1, Boolean boolean2)
{
super(ainterfaceaifcomponent, boolean1, boolean2);

logger.info("测试1ZLMoveToCommand2");


}

public ZLMoveToCommand(InterfaceAIFComponent ainterfaceaifcomponent[], String s, Boolean boolean1, Boolean boolean2)
{
super(ainterfaceaifcomponent, s, boolean1, boolean2);


logger.info("测试1ZLMoveToCommand3");


}

public ZLMoveToCommand(InterfaceAIFComponent ainterfaceaifcomponent[], String s, Boolean boolean1, Frame frame)
{
super(ainterfaceaifcomponent, s, boolean1, frame);


logger.info("测试1ZLMoveToCommand4");

}

public ZLMoveToCommand(TCComponent atccomponent[], InterfaceAIFComponent ainterfaceaifcomponent[], Boolean boolean1)
{
super(atccomponent, ainterfaceaifcomponent, boolean1);


logger.info("测试1ZLMoveToCommand5");


}

public ZLMoveToCommand(TCComponent atccomponent[], InterfaceAIFComponent ainterfaceaifcomponent[], Frame frame)
{
super(atccomponent, ainterfaceaifcomponent, frame);


logger.info("测试1ZLMoveToCommand6");

}

public ZLMoveToCommand(TCComponent atccomponent[], InterfaceAIFComponent ainterfaceaifcomponent[], String s, Frame frame)
{
super(atccomponent, ainterfaceaifcomponent, s, frame);


logger.info("测试1ZLMoveToCommand7");

}
public ZLMoveToCommand(InterfaceAIFComponent[] paramArrayOfInterfaceAIFComponent, Frame paramFrame, Boolean paramBoolean) {

super(paramArrayOfInterfaceAIFComponent,paramFrame,paramBoolean);
   this.parent = paramFrame;
   AIFComponentContext[] arrayOfAIFComponentContext = buildComponentContextFromClipboard(paramArrayOfInterfaceAIFComponent, null);
   if ((arrayOfAIFComponentContext != null) && (paramArrayOfInterfaceAIFComponent != null))
     try
    {
       InterfaceAIFComponent localInterfaceAIFComponent = arrayOfAIFComponentContext[0].getComponent();
       if ((paramArrayOfInterfaceAIFComponent.length == 1) && ((localInterfaceAIFComponent instanceof TCComponentBOMLine)) && ((paramArrayOfInterfaceAIFComponent[0] instanceof TCComponentBOMLine)) && (!((TCComponentBOMLine)localInterfaceAIFComponent).window().getRedliningMode()) && (((TCComponentBOMLine)localInterfaceAIFComponent).getPendingCut()) && (!((TCComponentBOMLine)paramArrayOfInterfaceAIFComponent[0]).getPendingCut()))
      {
         if (validForMoveTo(arrayOfAIFComponentContext))
        {
           TCComponentBOMLine[] arrayOfTCComponentBOMLine = new TCComponentBOMLine[arrayOfAIFComponentContext.length];
           for (int i = 0; i < arrayOfAIFComponentContext.length; i++)
             arrayOfTCComponentBOMLine[i] = ((TCComponentBOMLine)arrayOfAIFComponentContext[i].getComponent());
           TCComponentBOMWindow localTCComponentBOMWindow = arrayOfTCComponentBOMLine[0].window();
           MoveToOperation localMoveToOperation = new MoveToOperation((TCComponentBOMLine)paramArrayOfInterfaceAIFComponent[0], arrayOfTCComponentBOMLine);
           localMoveToOperation.addOperationListener(new InterfaceAIFOperationExecutionListener()
          {
             public void startOperation(String paramAnonymousString)
            {
            }

             public void endOperation()
            {
            }

             public void exceptionThrown(Exception paramAnonymousException)
            {
               MessageBox.post(ZLMoveToCommand.this.parent, paramAnonymousException, false);
            }
          });
           arrayOfTCComponentBOMLine[0].getSession().queueOperation(localMoveToOperation);
           localTCComponentBOMWindow.fireComponentChangeEvent();
        }
         return;
      }
       if (((localInterfaceAIFComponent instanceof TCComponentBOMLine)) && (((TCComponentBOMLine)localInterfaceAIFComponent).window().getRedliningMode()) && (((TCComponentBOMLine)localInterfaceAIFComponent).getPendingCut()) && (!doConfirmPost(Registry.getRegistry(this), "moveNodesAction.redline_warning.TITLE", "moveNodesAction.redline_warning.MESSAGE")))
         return;
       if ((paramArrayOfInterfaceAIFComponent.length > 1) && ((localInterfaceAIFComponent instanceof TCComponentBOMLine)) && (((TCComponentBOMLine)localInterfaceAIFComponent).getPendingCut()) && (!doConfirmPost(Registry.getRegistry(this), "moveNodesAction.redline_warning.TITLE", "moveNodesAction.multi_selection_warning.MESSAGE")))
         return;
    }
     catch (Exception localException)
    {
       MessageBox.post(this.parent, localException);
       return;
    }
   if ((arrayOfAIFComponentContext != null) && (this.parent != null))
  {
     String str = (String)arrayOfAIFComponentContext[0].getContext();
     if (hasVisibleAttributesOnRelation(str))
    {
       setRunnablePropsOnRelation(arrayOfAIFComponentContext);
    }
     else if ((paramArrayOfInterfaceAIFComponent != null) && ((paramArrayOfInterfaceAIFComponent[0] instanceof TCComponentBOMLine)))
    {
       if (this.m_progressCheckingService == null)
      {
//       Object obj = OSGIUtil.getService(Activator.getDefault(), IProgressCheckingService.class));
//         this.m_progressCheckingService = ((IProgressCheckingService) obj ;
      }
     
     
       if ((this.m_progressCheckingService != null) && (this.m_progressCheckingService.isProgressJobRunning()))
         return;
       
      // this.m_progressCheckingService.setProgressing(true);
       
       this.dlg = new ZLBOMPasteDialog(arrayOfAIFComponentContext, this.parent, paramBoolean.booleanValue());
       this.dlg.addPropertyChangeListener(this);
       setRunnable(this.dlg);
    }
     else
    {
       this.dlg = new PasteDialog(arrayOfAIFComponentContext, this.parent, paramBoolean.booleanValue());
       this.dlg.addPropertyChangeListener(this);
       setRunnable(this.dlg);
    }
  }
   else if (arrayOfAIFComponentContext != null)
  {
     setRunnable(new PasteCommand.PasteRunnable(arrayOfAIFComponentContext));
  }
   

logger.info("测试1ZLMoveToCommand8---执行了这里1");

}



protected boolean isValidComponent(Registry registry, InterfaceAIFComponent interfaceaifcomponent)
{
//logger.info("测试--执行这里了");
if (interfaceaifcomponent instanceof BOMLineMarkupNode)
{
MessageBox.post(parent, registry.getString("invalidPastingObject"), null, registry.getString("error.TITLE"), 1, true);
return false;
} else
{
return super.isValidComponent(registry, interfaceaifcomponent);
}
}



private boolean doConfirmPost(Registry registry, String s, String s1)
{
boolean flag = true;
if (Display.getCurrent() != null)
{
ConfirmDialog confirmdialog = new ConfirmDialog(null, registry.getString(s), registry.getString(s1));
confirmdialog.open();
if (!confirmdialog.isOkayClicked())
flag = false;
} else
if (ConfirmationDialog.post(parent, registry.getString(s), registry.getString(s1)) != 2)
flag = false;
return flag;
}
 @Override
 public void endOperation()
{
 super.endOperation();
}

}

1.3 将其中BOMPasteDialog更改为自己的ZLBOMPasteDialog:

package com.teamcenter.rac.pse.commands;

import java.awt.Frame;

import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.pse.dialogs.BOMPasteDialog;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.commands.paste.PasteDialog;
import com.teamcenter.rac.common.AbstractProgressDialog;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCExceptionPartial;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.pse.AbstractPSEApplication;
import com.teamcenter.rac.pse.common.BOMTreeTable;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.log.TcLogger;
import com.zoomlion.design.utils.SessionUtils;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

public class ZLBOMPasteDialog extends BOMPasteDialog {

TcLogger logger=TcLogger.getLogger(ZLMoveToCommand.class);
private AIFComponentContext ainterfaceaifcomponent[];
public ZLBOMPasteDialog(AIFComponentContext[] paramArrayOfAIFComponentContext, Frame paramFrame, boolean paramBoolean)
{
   super(paramArrayOfAIFComponentContext, paramFrame, paramBoolean);
   ainterfaceaifcomponent=paramArrayOfAIFComponentContext;
}
protected void processException(Exception paramException, int paramInt, TCComponent paramTCComponent, List<TCComponent> paramList)
{
   if ((paramException instanceof TCExceptionPartial))
  {
     TCExceptionPartial localTCExceptionPartial1 = (TCExceptionPartial)paramException;
     TCComponent[] arrayOfTCComponent = localTCExceptionPartial1.getAssociatedObjs();
     if (arrayOfTCComponent != null)
    {
       for (int i = 0; (i < this.chunk) && (paramInt + i < paramList.size()); i++)
      {
         int j = askIndex(paramTCComponent, (TCComponent)paramList.get(paramInt + i));
         setRowStatus(j, 2);
      }
       int[] arrayOfInt1 = localTCExceptionPartial1.getErrorSeverities();
       int[] arrayOfInt2 = localTCExceptionPartial1.getErrorCodes();
       String[] arrayOfString = localTCExceptionPartial1.getErrorStack();
       for (int k = 0; k < arrayOfTCComponent.length; k++)
      {
         if (arrayOfTCComponent[k] == null)
        {
           super.processException(paramException, paramInt, paramTCComponent, paramList);
           return;
        }
         int m = askIndex(paramTCComponent, arrayOfTCComponent[k]);
         final TCExceptionPartial localTCExceptionPartial2 = new TCExceptionPartial(new int[] { arrayOfInt1[k] }, new int[] { arrayOfInt2[k] }, new String[] { arrayOfString[k] });
         setNodeException(m, localTCExceptionPartial2);
         setRowStatus(m, 3);
         final JButton localJButton = getButton(m);
         SwingUtilities.invokeLater(new Runnable()
        {
           public void run()
          {
             localJButton.setToolTipText(localTCExceptionPartial2.toString());
             localJButton.addActionListener(new ZLBOMPasteDialog.IC_ErrorActionListener(localTCExceptionPartial2));
          }
        });
      }
       return;
    }
  }
   super.processException(paramException, paramInt, paramTCComponent, paramList);
   endPasting();
}

 protected boolean successfulCompletion()
{
   endPasting();
   //增加的粘贴后处理
   postPasteOccProperties(this.ainterfaceaifcomponent);
   
   return super.successfulCompletion();
}

 private void endPasting()
{
   AbstractAIFUIApplication localAbstractAIFUIApplication = AIFUtility.getCurrentApplication();
   if ((localAbstractAIFUIApplication instanceof AbstractPSEApplication))
  {
     BOMTreeTable localBOMTreeTable = ((AbstractPSEApplication)localAbstractAIFUIApplication).getViewableTreeTable();
     if (localBOMTreeTable != null)
       localBOMTreeTable.setPasting(false);
  }
}

 protected void doSleep()
{
}

 protected void doWaitUntilRun(AbstractProgressDialog.OperationWaiter paramOperationWaiter)
{
   try
  {
     String str = System.getProperty("java.version");
     double d = Double.parseDouble(str.substring(0, 3));
     if (d <= 1.7D)
       paramOperationWaiter.waitUntilRun();
  }
   catch (Exception localException)
  {
  }
}

 private class IC_ErrorActionListener
   implements ActionListener
{
   private final Exception m_ex;

   private IC_ErrorActionListener(Exception arg2)
  {
     this.m_ex = arg2;
  }

   public void actionPerformed(ActionEvent paramActionEvent)
  {
     MessageBox.post(this.m_ex);
  }
}
 
 protected void postPasteOccProperties( AIFComponentContext paramArrayOfInterfaceAIFComponent[]) {//原来的BOM行
 
InterfaceAIFComponent[] pComps = AIFUtility.getCurrentApplication().getTargetComponents();
AIFComponentContext[] soureComps=paramArrayOfInterfaceAIFComponent;
if (pComps != null && pComps.length == 1 && pComps[0] instanceof TCComponentBOMLine && soureComps != null
&& soureComps.length > 0 && soureComps[0].getComponent() instanceof TCComponentBOMLine) {
TCComponentBOMLine pBOMLine = (TCComponentBOMLine) pComps[0];
TCPreferenceService prefServices = SessionUtils.getSession().getPreferenceService();
try {
String[] cust_copy_occ_property_names =prefServices.getStringValues("cust_copy_occ_property_names");
if(cust_copy_occ_property_names==null || (cust_copy_occ_property_names!=null && cust_copy_occ_property_names.length==0)) {
cust_copy_occ_property_names= new String[] { "bl_occ_qn3_FSJ", "bl_occ_qn3_Acreage",
"bl_occ_qn3_Config_Base", "bl_occ_qn3_Config_Linkage", "bl_occ_qn3_Config_Seq",
"bl_occ_qn3_Config_Unit", "bl_occ_qn3_Config_Xmemo", "bl_occ_qn3_Config_priority",
"bl_occ_qn3_Fixed", "bl_occ_qn3_Unit", "bl_occ_qn3_hanliang", "bl_occ_qn3_thickness",
"bl_occ_qn3_detailRemark","bl_sequence_no" };//"bl_occ_seq_no"
}
try {
pBOMLine.refresh();
AIFComponentContext[] aifs = pBOMLine.getChildren();
for (AIFComponentContext aif : aifs) {
TCComponentBOMLine cBOMLine = (TCComponentBOMLine) aif.getComponent();
String t_item_id = cBOMLine.getProperty("bl_item_item_id");
for (AIFComponentContext compAifx : soureComps) {
try {
String s_item_id = compAifx.getComponent().getProperty("bl_item_item_id");
if (t_item_id.equals(s_item_id)) {
cBOMLine.setProperties(cust_copy_occ_property_names,  compAifx.getComponent().getProperties(cust_copy_occ_property_names));
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
}
}

} catch (TCException e) {
e.printStackTrace();
logger.error(e);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
}
}

}

1.4 dialog中通过runnable接口执行operation方法,在endoperation后,增加自己的代码

 //增加的粘贴后处理 
   postPasteOccProperties(this.ainterfaceaifcomponent);

导出插件包,清理缓存,重新注册运行。

posted @   张永全-PLM顾问  阅读(271)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示