teamcenter代碼創建特定對象頁面

第一個類

import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.widgets.Display;

import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.InterfaceAIFOperationExecutionListener;
import com.teamcenter.rac.aif.common.AIFDataBean;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.pse.AbstractPSEApplication;
import com.teamcenter.rac.ui.commands.create.bo.ITypeChangeSupport;
import com.teamcenter.rac.ui.commands.create.bo.NewBOOperation;
import com.teamcenter.rac.ui.commands.create.bo.NewBOWizard;
import com.teamcenter.rac.util.AdapterUtil;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.SWTUIUtilities;

public class CusBOWizard extends NewBOWizard implements IAdaptable, ITypeChangeSupport{
    public NewBOOperation newbooperation = null;
    public CusBOWizard(String arg0) {
        super("com.teamcenter.rac.ui.commands.create.bo.NewBOWizard");
        // TODO Auto-generated constructor stub
    }

    @Override
    public boolean performFinish() {
        // TODO Auto-generated method stub
        System.out.println("performFinish");
         performingOperation = true;
            getContainer().updateButtons();
            System.out.println("performFinish 1");
            List localList = getCreateInputs();
            Map localMap = getCustomPanelUserInput();
            NewBOOperation localNewBOOperation = getOperationClass();
            if (localNewBOOperation == null) {
              localNewBOOperation = new NewBOOperation(this, localList);
            }
            localNewBOOperation.setWizard(this);
            localNewBOOperation.setCreateInput(localList);
            if ((localMap != null) && (!localMap.isEmpty())) {
              localNewBOOperation.setCustomPanelUserInput(localMap);
            }
            AIFDataBean localAIFDataBean1 = new AIFDataBean();
            IWizardPage[] arrayOfIWizardPage;
            int j = (arrayOfIWizardPage = getPages()).length;
            for (int i = 0; i < j; i++)
            {
              IWizardPage localIWizardPage = arrayOfIWizardPage[i];
              AIFDataBean localAIFDataBean2 = (AIFDataBean)AdapterUtil.getAdapter(localIWizardPage, AIFDataBean.class);
              if (localAIFDataBean2 != null) {
                localAIFDataBean1.setProperty(localIWizardPage.getName(), localAIFDataBean2);
              }
            }
            localNewBOOperation.setOperatinDataForPages(localAIFDataBean1);
            localNewBOOperation.addOperationListener(new IC_OperationExecutionListener(null));
            localNewBOOperation.setUser(true);
            model.getSession().queueOperation(localNewBOOperation);
            System.out.println("no save");
        return true;
    }
    
    
    private class IC_OperationExecutionListener
    implements InterfaceAIFOperationExecutionListener
    {
        private IC_OperationExecutionListener() {
            super();
        }

        IC_OperationExecutionListener(IC_OperationExecutionListener icOperationExecutionListener) {
            this();
        }

    public void exceptionThrown(final Exception paramException)
    {
      if (paramException != null)
      {
        performingOperation = false;
        SWTUIUtilities.asyncExec(new Runnable()
        {
          public void run()
          {
            MessageBox.post(getShell(), paramException, false);
            if (getContainer() != null) {
              getContainer().updateButtons();
            }
          }
        });
      }
    }

    public void startOperation(String paramString) {}

    public void endOperation()
    {
      performingOperation = false;
      Display.getDefault().asyncExec(new Runnable()
      {
        public void run()
        {
          IWizardContainer localIWizardContainer = getContainer();
          if (localIWizardContainer != null) {
            localIWizardContainer.updateButtons();
          }
        }
      });
      postSuccessfulFinish();
    }
    }
}

 

第二個類

import java.awt.Frame;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.ICommandListener;
import com.teamcenter.rac.aif.ICommandListenerEvent;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.commands.newitem.NewItemCommand;
import com.teamcenter.rac.kernel.TCAccessControlService;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.pse.AbstractPSEApplication;
import com.teamcenter.rac.ui.commands.Messages;
import com.teamcenter.rac.ui.commands.create.bo.NewBOModel;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.UIUtilities;
import com.teamcenter.rac.util.wizard.extension.BaseExternalWizardDialog;

public class CreateRiskAction extends AbstractAIFAction {
    private AbstractAIFApplication app = null;
    private TCSession session = null;
    private String wizardId = "com.hh.th.createRisk.CusBOWizard";
    protected NewBOModel mBoModel;
    protected CusBOWizard bomWizard = null;
    private InterfaceAIFComponent targetObject = null;
    private TCComponentItemRevision targetRev = null;
    private TCComponentItem targetItem = null;

    public CreateRiskAction(AbstractAIFApplication arg0, Frame arg1, String arg2) {
        super(arg0, arg1, arg2);
        // TODO Auto-generated constructor stub
        this.app = arg0;
        this.session = (TCSession) this.app.getSession();
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub

        InterfaceAIFComponent aifComponent = this.app.getTargetComponent();
        if (aifComponent == null) {
            MessageBox.post(AIFUtility.getActiveDesktop(), "請選擇bom行", "提示",
                    MessageBox.INFORMATION);
            return;
        }

        TCAccessControlService accessControlService = session
                .getTCAccessControlService();
        boolean isWrite = false;
        try {
            isWrite = accessControlService.checkUsersPrivilege(
                    this.session.getUser(), (TCComponent) aifComponent,
                    TCAccessControlService.WRITE);
        } catch (TCException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        if (!isWrite) {
            MessageBox.post(AIFUtility.getActiveDesktop(), "當前用戶對選擇的bom行無寫權限",
                    "提示", MessageBox.INFORMATION);
            return;
        }

        mBoModel = new NewBOModel(this);
        bomWizard = new CusBOWizard(wizardId);

        mBoModel.setSession(session);
        mBoModel.reInitializeTransientData();
        mBoModel.setRevisionFlag(true);
        mBoModel.setBOType("TH8_RiskChildren");

        AIFDesktop aifdesktop = AIFUtility.getActiveDesktop();
        final Shell shell = aifdesktop.getShell();
        InterfaceAIFComponent[] selectedCmps = app.getTargetComponents();
        StructuredSelection mCurrentSelection = new StructuredSelection(
                selectedCmps);

        bomWizard.setBOModel(mBoModel);
        bomWizard.setShell(shell);
        bomWizard.setParentFrame(AIFUtility.getActiveDesktop());
        bomWizard.setTargetArray(selectedCmps);
        bomWizard.setCurrentSelection(mCurrentSelection);
        bomWizard.setWindowTitle(getWizardTitle());
        bomWizard.setRevisionFlag(true);
        bomWizard.setDefaultType("TH8_RiskChildren");

        Display display = Display.getDefault();
        display.asyncExec(new Runnable() {

            @Override
            public void run() {

                Shell localShell = UIUtilities.getCurrentModalShell();
                BaseExternalWizardDialog dialog = new BaseExternalWizardDialog(
                        shell, bomWizard);
                dialog.create();
                bomWizard.retrievePersistedDialogSettings(dialog);
                bomWizard.setWizardDialog(dialog);
                UIUtilities.setCurrentModalShell(dialog.getShell());

                bomWizard
                        .addPropertyChangeListener(new IPropertyChangeListener() {
                            @Override
                            public void propertyChange(PropertyChangeEvent event) {
                                System.out
                                        .println("hello newitem addPropertyChangeListener");
                            }
                        });
                IWizardPage currentPage = dialog.getCurrentPage();
                System.out.println("currentPage == "+currentPage);
                if (currentPage.getName().endsWith("BOTypePage")) {
                    dialog.showPage(dialog.getCurrentPage().getNextPage());
                }
                dialog.setBlockOnOpen(true);

                dialog.open();
                dialog = null;
                mBoModel = null;
                UIUtilities.setCurrentModalShell(localShell);
            }
        });

        // NewItemCommand cmd = new
        // NewItemCommand(AIFUtility.getActiveDesktop().getFrame(),
        // app,"TH8_RiskChildren",null,false);
        // try {
        // cmd.executeModal();
        // } catch (Exception e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
        //
        // cmd.addCommandListener(new ICommandListener() {
        //
        // @Override
        // public void commandStarting(ICommandListenerEvent
        // paramICommandListenerEvent) {
        // // TODO Auto-generated method stub
        // System.out.println("commandStarting");
        // }
        //
        // @Override
        // public void commandDone(ICommandListenerEvent
        // paramICommandListenerEvent) {
        // // TODO Auto-generated method stub
        // System.out.println("commandDone");
        // AbstractPSEApplication pseapp = (AbstractPSEApplication) app;
        // pseapp.saveBOM();
        // }
        // });

    }

    public String getWizardTitle() {
        return Messages.getString("wizard.TITLE");
    }

}
 

第三個類:

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;

public class CreateRiskHandler extends AbstractHandler {

    private AbstractAIFUIApplication app = null;
    @Override
    public Object execute(ExecutionEvent arg0) throws ExecutionException {
        // TODO Auto-generated method stub
        app = AIFUtility.getCurrentApplication();
        CreateRiskAction action = new CreateRiskAction(app,null,"");
        new Thread(action).start();
        return null;
    }

}
 

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章