You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.7 KiB

package cn.net.connor.process.meopmodel;
import java.util.ArrayList;
import java.util.List;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.DeepCopyInfo;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOPLine;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.Registry;
import k.KDialogController;
import k.KOperation2;
import k.util.KUtil;
public class MeopModelDialogController extends KDialogController{
private TCComponentBOPLine targetLine;
protected List<MeopModelBean> meopModelBeans = new ArrayList<MeopModelBean>();
private MeopModelDialog dialog;
private TCComponentItemType itemType;
private static final Registry REG = Registry.getRegistry(MeopModelDialogController.class);
public MeopModelDialogController(AbstractAIFApplication app, TCComponentBOPLine meopLine) {
super(app);
this.targetLine = meopLine;
}
@Override
public boolean init() throws Exception {
this.dialog = (MeopModelDialog)aifDialog;
TCComponentBOMLine pLine = targetLine.parent();
AIFComponentContext[] cc = pLine.getChildren();
int len = KUtil.getLen(cc);
for(int i=0; i<len; i++) {
TCComponentBOPLine cLine = (TCComponentBOPLine) cc[i].getComponent();
MeopModelBean bean = MeopModelBean.parse(cLine);
if(bean==null) {
continue;
}
meopModelBeans.add(bean);
}
if(this.meopModelBeans.size()==0) {
throw new TCException(REG.getString("nomeopmodel.ERROR"));
}
try {
this.itemType = (TCComponentItemType) session.getTypeComponent(DesignModelOperation.TYPE_ITEM);
} catch (Exception e) {
e.printStackTrace();
}
if (this.itemType == null) {
throw new TCException("Type is not defined: " + DesignModelOperation.TYPE_ITEM);
}
return true;
}
public void doCreate() throws Exception{
int rowNum = dialog.table.getSelectedRow();
System.out.println("select row: "+rowNum);
if(rowNum<0) {
return;
}
dialog.disposeDialog();
new KOperation2(app, REG.getString("create.STATUS")) {
@Override
public boolean init() throws Exception {
return true;
}
@Override
public void execute() throws Exception {
MeopModelBean bean = (MeopModelBean) dialog.table.getValueAt(rowNum, 0);
TCComponentBOPLine meopLine = bean.getMeopLine();
List<TCComponentItemRevision> gxmxRevs = bean.getGxmxRevs();
System.out.println("template: "+meopLine+" -> "+gxmxRevs);
int cnt = gxmxRevs.size();
for(int i=0; i<cnt ; i++) {
session.setStatus(String.format("( %d / %d ) %s", i+1, cnt, REG.getString("gxmxsaveas.STATUS")));
TCComponentItemRevision rev = gxmxRevs.get(i);
System.out.println("copy "+rev);
String itemID = itemType.getNewID();
String revID = itemType.getNewRev(null);
String objectName = rev.getStringProperty("object_name");
List<DeepCopyInfo> deepCopyInfos = new ArrayList<DeepCopyInfo>();
List<TCComponent> datasets = KUtil.getChildComponents(rev, DesignModelOperation.TYPE_DATASET, DesignModelOperation.REL_REV_DATASET);
System.out.println(">> find datasets: "+datasets);
int dsCnt = datasets == null?0:datasets.size();
for(int j=0; j<dsCnt; j++) {
TCComponent ds = datasets.get(j);
DeepCopyInfo deepCopyInfo = new DeepCopyInfo(ds, DeepCopyInfo.COPY_NOT_ACTION, ds.getStringProperty("object_name")+" do not copy", DesignModelOperation.REL_REV_DATASET, false, false, false);
deepCopyInfos.add(deepCopyInfo);
}
TCComponentItem newItem = rev.saveAsItem(itemID, revID, objectName, "", false, deepCopyInfos.toArray(new DeepCopyInfo[] {}));
System.out.println(">> new Item: "+newItem);
newItem.refresh();
TCComponentItemRevision newRev = newItem.getLatestItemRevision();
System.out.println(">> new rev: " + newRev);
newRev.refresh();
for(int j=0; j<dsCnt; j++) {
TCComponentDataset ds = (TCComponentDataset) datasets.get(j);
TCComponentDataset newDataset = ds.saveAs(ds.getStringProperty("object_name"));
System.out.println(">> new dataset: " + newDataset);
newRev.add(DesignModelOperation.REL_REV_DATASET, newDataset);
}
newRev.refresh();
TCComponentBOMLine newLine = targetLine.add(newItem, newRev, null, false);
System.out.println(">> new line: " + newLine);
}
targetLine.refresh();
}
@Override
public void clearCache() throws Exception {
}
}.executeModeless();
}
}