commit 678ec7bf8d5d069c14d3a21551dbc598f2142203 Author: lijh Date: Tue Mar 10 15:42:47 2026 +0800 first commit diff --git a/DBOM转EBOM规格书.doc b/DBOM转EBOM规格书.doc new file mode 100644 index 0000000..96f562c Binary files /dev/null and b/DBOM转EBOM规格书.doc differ diff --git a/com.connor.process.rar b/com.connor.process.rar new file mode 100644 index 0000000..27c5962 Binary files /dev/null and b/com.connor.process.rar differ diff --git a/com.connor.process/.classpath b/com.connor.process/.classpath new file mode 100644 index 0000000..f3b6114 --- /dev/null +++ b/com.connor.process/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/com.connor.process/.project b/com.connor.process/.project new file mode 100644 index 0000000..ab7f13a --- /dev/null +++ b/com.connor.process/.project @@ -0,0 +1,28 @@ + + + com.connor.process + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/com.connor.process/.settings/org.eclipse.jdt.core.prefs b/com.connor.process/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9f6ece8 --- /dev/null +++ b/com.connor.process/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/com.connor.process/META-INF/MANIFEST.MF b/com.connor.process/META-INF/MANIFEST.MF new file mode 100644 index 0000000..bcd5f97 --- /dev/null +++ b/com.connor.process/META-INF/MANIFEST.MF @@ -0,0 +1,36 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Process +Bundle-SymbolicName: com.connor.process;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: CONNOR +Require-Bundle: org.eclipse.ui.forms;bundle-version="3.7.400", + org.eclipse.ui, + org.eclipse.core.runtime;bundle-version="3.15.100", + com.teamcenter.rac.common;bundle-version="12000.2.0", + com.teamcenter.rac.external;bundle-version="12000.2.0", + com.teamcenter.rac.workflow.processdesigner;bundle-version="12000.2.0", + com.teamcenter.rac.util;bundle-version="12000.2.0", + com.teamcenter.rac.aifrcp;bundle-version="12000.2.0", + com.teamcenter.rac.neva;bundle-version="2.0.0", + com.teamcenter.rac.kernel;bundle-version="12000.2.0", + TcSoaCoreRac;bundle-version="12000.2.0" +Automatic-Module-Name: com.connor.ld.process +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: ., + lib/swingx-1.6.1.jar, + lib/cn.net.connor.std.aifrcp_13000.1.0.jar, + lib/cn.net.connor.std.fx_13000.1.0.jar, + lib/cn.net.connor.std.gdtex_13000.1.0.jar +Export-Package: cn.net.connor.std.aifrcp, + cn.net.connor.std.aifrcp.util, + cn.net.connor.std.aifrcp.xml, + cn.net.connor.std.fx, + cn.net.connor.std.gdtex, + com.connor.process.commands, + com.connor.tcm.outfile.bean, + com.connor.tcm.outfile.createMaterial, + com.connor.tcm.outfile.dbom2ebom, + com.connor.tcm.outfile.projectFolder, + com.connor.tcm.outfile.util, + org.jdesktop.swingx.table diff --git a/com.connor.process/bin/.gitignore b/com.connor.process/bin/.gitignore new file mode 100644 index 0000000..c2d9872 --- /dev/null +++ b/com.connor.process/bin/.gitignore @@ -0,0 +1 @@ +/com/ diff --git a/com.connor.process/build.properties b/com.connor.process/build.properties new file mode 100644 index 0000000..8fea873 --- /dev/null +++ b/com.connor.process/build.properties @@ -0,0 +1,9 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + lib/swingx-1.6.1.jar,\ + lib/cn.net.connor.std.aifrcp_13000.1.0.jar,\ + lib/cn.net.connor.std.fx_13000.1.0.jar,\ + lib/cn.net.connor.std.gdtex_13000.1.0.jar +source.. = src/ diff --git a/com.connor.process/icons/sample.png b/com.connor.process/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/com.connor.process/icons/sample.png differ diff --git a/com.connor.process/icons/sample@2x.png b/com.connor.process/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/com.connor.process/icons/sample@2x.png differ diff --git a/com.connor.process/lib/cn.net.connor.std.aifrcp_13000.1.0.jar b/com.connor.process/lib/cn.net.connor.std.aifrcp_13000.1.0.jar new file mode 100644 index 0000000..4a41442 Binary files /dev/null and b/com.connor.process/lib/cn.net.connor.std.aifrcp_13000.1.0.jar differ diff --git a/com.connor.process/lib/cn.net.connor.std.fx_13000.1.0.jar b/com.connor.process/lib/cn.net.connor.std.fx_13000.1.0.jar new file mode 100644 index 0000000..3a0354a Binary files /dev/null and b/com.connor.process/lib/cn.net.connor.std.fx_13000.1.0.jar differ diff --git a/com.connor.process/lib/cn.net.connor.std.gdtex_13000.1.0.jar b/com.connor.process/lib/cn.net.connor.std.gdtex_13000.1.0.jar new file mode 100644 index 0000000..b0ccaa7 Binary files /dev/null and b/com.connor.process/lib/cn.net.connor.std.gdtex_13000.1.0.jar differ diff --git a/com.connor.process/lib/swingx-1.6.1.jar b/com.connor.process/lib/swingx-1.6.1.jar new file mode 100644 index 0000000..b0bcc87 Binary files /dev/null and b/com.connor.process/lib/swingx-1.6.1.jar differ diff --git a/com.connor.process/plugin.xml b/com.connor.process/plugin.xml new file mode 100644 index 0000000..d663d66 --- /dev/null +++ b/com.connor.process/plugin.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/com.connor.process/src/com/connor/process/commands/NewProcessCommand.java b/com.connor.process/src/com/connor/process/commands/NewProcessCommand.java new file mode 100644 index 0000000..aa14983 --- /dev/null +++ b/com.connor.process/src/com/connor/process/commands/NewProcessCommand.java @@ -0,0 +1,52 @@ +package com.connor.process.commands; + +import org.jacorb.idl.runtime.int_token; + +import com.connor.tcm.outfile.createMaterial.NewProcessDialog; +import com.connor.tcm.outfile.createMaterial.NewProcessDialogController; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AbstractAIFSession; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +import cn.net.connor.std.aifrcp.KCommand; + + +public class NewProcessCommand extends KCommand{ + + public NewProcessCommand(AbstractAIFApplication app, String commandId, String actionInfo) { + super(app, commandId, actionInfo); + System.out.println("NewProcessCommand"); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent targetComponent = app.getTargetComponent(); + + if(targetComponent == null) { + MessageBox.post("ѡͼֽ", "ʾ ", MessageBox.INFORMATION); + return ; + } + String type = targetComponent.getType(); + + String[] types = session.getPreferenceService().getStringValues("LB_Design_type"); + + if(types == null || types.length == 0) { + MessageBox.post("ȷ LB_Design_type ѡ", "ʾ ", MessageBox.INFORMATION); + return ; + } + boolean juedge = false; + for (int i = 0; i < types.length; i++) { + if(types[i].equals(type)) { + juedge = true; + } + } + + if(!juedge) { + MessageBox.post("ѡʹϴܵͼֽ汾", "ʾ ", MessageBox.INFORMATION); + return ; + } + + this.setRunnable(new NewProcessDialog(new NewProcessDialogController(app))); + } + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/bean/NodeBean.java b/com.connor.process/src/com/connor/tcm/outfile/bean/NodeBean.java new file mode 100644 index 0000000..caa994a --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/bean/NodeBean.java @@ -0,0 +1,73 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.connor.tcm.outfile.bean; + +import java.util.Random; + +/** + * + * @author vearn + */ +public class NodeBean { + + private String dbom;//ID + private String ebom;// + private String ebomId;// + private String ebomDesc;// + private String num;// + private String label;// + private String refreshStatus;//״̬ + private String parentString;//Ӧڵ + + public String getDbom() { + return dbom; + } + public void setDbom(String dbom) { + this.dbom = dbom; + } + public String getEbom() { + return ebom; + } + public void setEbom(String ebom) { + this.ebom = ebom; + } + public String getEbomId() { + return ebomId; + } + public void setEbomId(String ebomId) { + this.ebomId = ebomId; + } + public String getLabel() { + return label; + } + public void setLabel(String label) { + this.label = label; + } + public String getRefreshStatus() { + return refreshStatus; + } + public void setRefreshStatus(String refreshStatus) { + this.refreshStatus = refreshStatus; + } + public String getParentString() { + return parentString; + } + public void setParentString(String parentString) { + this.parentString = parentString; + } + public String getNum() { + return num; + } + public void setNum(String num) { + this.num = num; + } + public String getEbomDesc() { + return ebomDesc; + } + public void setEbomDesc(String ebomDesc) { + this.ebomDesc = ebomDesc; + } + +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/CjwlCommand.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/CjwlCommand.java new file mode 100644 index 0000000..2695585 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/CjwlCommand.java @@ -0,0 +1,50 @@ +package com.connor.tcm.outfile.createMaterial; + +import org.jacorb.idl.runtime.int_token; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AbstractAIFSession; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +import cn.net.connor.std.aifrcp.KCommand; + + +public class CjwlCommand extends KCommand{ + + public CjwlCommand(AbstractAIFApplication app, String commandId, String actionInfo) { + super(app, commandId, actionInfo); + System.out.println("NewProcessCommand"); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent targetComponent = app.getTargetComponent(); + + if(targetComponent == null) { + MessageBox.post("ѡͼֽ", "ʾ ", MessageBox.INFORMATION); + return ; + } + String type = targetComponent.getType(); + + String[] types = session.getPreferenceService().getStringValues("LB_Design_type"); + + if(types == null || types.length == 0) { + MessageBox.post("ȷ LB_Design_type ѡ", "ʾ ", MessageBox.INFORMATION); + return ; + } + boolean juedge = false; + for (int i = 0; i < types.length; i++) { + if(types[i].equals(type)) { + juedge = true; + } + } + + if(!juedge) { + MessageBox.post("ѡʹϴܵͼֽ汾", "ʾ ", MessageBox.INFORMATION); + return ; + } + + this.setRunnable(new NewProcessDialog(new NewProcessDialogController(app))); + } + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessDialog.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessDialog.java new file mode 100644 index 0000000..618e6f8 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessDialog.java @@ -0,0 +1,111 @@ +package com.connor.tcm.outfile.createMaterial; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import com.teamcenter.rac.util.MessageBox; + +import cn.net.connor.std.aifrcp.KDialog; +import cn.net.connor.std.aifrcp.KDialogController; +import cn.net.connor.std.aifrcp.util.KUtil; + +@SuppressWarnings("serial") +public class NewProcessDialog extends KDialog { + + private JButton b_ok; + private JButton b_cel; + private NewProcessDialogController controller; + + public NewProcessDialog(KDialogController controller) { + super(controller); + this.controller = (NewProcessDialogController) controller; + } + + private void setCompEnabled(boolean enabled) { + b_ok.setEnabled(enabled); + b_cel.setEnabled(enabled); + } + + @Override + protected void addListeners() { + b_cel.addActionListener(e -> disposeDialog()); + + b_ok.addActionListener(e -> { + new Thread(() -> { + setCompEnabled(false); + try { + controller.doCreate(); + disposeDialog(); + } catch (Exception ex) { + ex.printStackTrace(); + MessageBox.post(NewProcessDialog.this, ex); + } finally { + setCompEnabled(true); + } + }).start(); + }); + } + + @Override + protected void initUI() { + setTitle(""); + setPreferredSize(new Dimension(700, 600)); + setMinimumSize(new Dimension(700, 600)); + setLayout(new BorderLayout()); + add(BorderLayout.CENTER, initItemPanel()); + add(BorderLayout.SOUTH, initBtnPanel()); + } + + private Component initBtnPanel() { + JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 5)); + b_ok = new JButton("ȷ"); + b_cel = new JButton("ȡ"); + panel.add(b_ok); + panel.add(b_cel); + return panel; + } + + private Component initItemPanel() { + List comps = controller.itemComps; + JPanel wrapper = new JPanel(new BorderLayout()); + wrapper.setBorder(BorderFactory.createTitledBorder( + BorderFactory.createEmptyBorder(30, 5, 5, 5), "")); + + JPanel panel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(4, 0, 4, 25); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.weightx = 1.0; + + int rowIndex = 0; + for (PrefComponent comp : comps) { + if (comp.isInvisible()) continue; + gbc.gridx = 0; + gbc.gridy = rowIndex++; + panel.add(comp.getPanel(), gbc); + } + + gbc.gridy = rowIndex; + gbc.weighty = 1.0; + panel.add(new JLabel(""), gbc); + + JScrollPane scroll = new JScrollPane(panel); + scroll.setBorder(null); + wrapper.add(BorderLayout.CENTER, scroll); + return wrapper; + } +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessDialogController.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessDialogController.java new file mode 100644 index 0000000..e145047 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessDialogController.java @@ -0,0 +1,372 @@ +package com.connor.tcm.outfile.createMaterial; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.connor.tcm.outfile.util.MethodUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.SoaUtil; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemRevisionType; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.Registry; +import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse; + +import cn.net.connor.std.aifrcp.KDialogController; +import cn.net.connor.std.aifrcp.util.KUtil; + + + +public class NewProcessDialogController extends KDialogController { + private PrefComponent objectTypeComp; + private NewProcessDialog dialog; + private TCComponentItemRevision targetRev; + public static final String PREF_GROUP_SPLITTER = "---"; + protected List itemComps = new ArrayList(); + + protected int procCols = 2; + protected int itemCols = 2; + private Map symbolCompMap = new HashMap(); + public static final String FLAG_TYPE_SYMBOL = "[PROC_TYPE]"; + + public NewProcessDialogController(AbstractAIFApplication app) { + super(); + } + + @Override + public boolean init() throws Exception { + this.dialog = (NewProcessDialog) aifDialog; + InterfaceAIFComponent comp = app.getTargetComponent(); + if (comp == null || !(comp instanceof TCComponentItemRevision)) { + throw new Exception("ѡ"); + } + this.targetRev = (TCComponentItemRevision) comp; + String revType = this.targetRev.getType(); + System.out.println("Select Rev: " + this.targetRev + "| " + revType); + String[] prefVals = KUtil.getPrefVals(session, "LB_Wl_Create"); + int len = KUtil.getLen(prefVals); + if (len == 0) { + + throw new TCException("ѡLB_Wl_Create"); + } + + List compList = itemComps; + for (int i = 0; i < len; i++) { + String pref = prefVals[i]; + if (pref.length() == 1 && Character.isDigit(pref.charAt(0))) { + if (compList == itemComps) { + int col = pref.charAt(0) - '0'; + if (col > 0) { + System.out.println("Reset Item Col: " + col); + itemCols = col; + } + } + continue; + } + + PrefComponent prefComp = new PrefComponent(pref, this.targetRev); + if (prefComp.init(session)) { + //߼ + + + if ("object_type".equals(prefComp.propConfig)) { + this.objectTypeComp = prefComp; + } + + if ("rev.object_name".equals(prefComp.propConfig) || "item.object_name".equals(prefComp.propConfig)) { + prefComp.textField.setText(targetRev.getStringProperty("object_name")); + } + + if ("item_id".equals(prefComp.propConfig)) { + prefComp.textField.setText(targetRev.getStringProperty("item_id")); + } + + + compList.add(prefComp); + } else { + System.out.println("Error Config: " + pref); + } + } + if (itemComps.size() == 0) { + throw new TCException("ȷѡLB_Wl_Create"); + } + + + + + + for (PrefComponent c : itemComps) { + if (c.textField != null && c.getValue() != null && c.getValue().contains(FLAG_TYPE_SYMBOL)) { + this.symbolCompMap.put(c, c.getValue()); + c.textField.setText(c.getValue().replace(FLAG_TYPE_SYMBOL, "")); + } + } + + + + + + /* + * for (int i = 0; i < itemComps.size(); i++) { PrefComponent prefParent = + * itemComps.get(i); if (prefParent.isLovParent) { for (int j = 0; j < + * itemComps.size(); j++) { PrefComponent prefChild = itemComps.get(j); if + * (prefParent.lovName.equals(prefChild.lovName) && prefChild.isLovChild) { + * prefParent.comboBox.addActionListener(new ActionListener() { + * + * @Override public void actionPerformed(ActionEvent e) { String + * selectedProvince = (String) prefParent.bigJtf.getText(); if (selectedProvince + * != null) { List cities = prefParent.listLov.get(selectedProvince); + * + * // Ӽؼ prefChild.comboBox.removeAllItems(); + * prefChild.opHashMap.clear(); prefChild.lovDisRealMap.clear(); + * prefChild.list.clear(); + * + * if (cities != null && !cities.isEmpty()) { for (String city : cities) { + * OptionItem optionItem = new OptionItem(city, ""); + * prefChild.comboBox.addItem(optionItem); prefChild.opHashMap.put(city, + * optionItem); prefChild.lovDisRealMap.put(city, city); + * prefChild.list.add(city); } // ؼԶѡκ + * prefChild.comboBox.setSelectedIndex(-1); } else { // ûʱҲȷѡ + * prefChild.comboBox.setSelectedIndex(-1); } } else { + * prefChild.comboBox.removeAllItems(); prefChild.comboBox.setSelectedIndex(-1); + * // ȷѡ } } }); } } } } + */ + + return true; + } + + public void doCreate() throws Exception { + + if (this.objectTypeComp == null) { + throw new Exception(""); + } + String type = this.objectTypeComp.getValue(); + System.out.println("Select Type: " + type); + if (KUtil.isEmpty(type)) { + throw new Exception("ѡ"); + } + + + + + String relName = objectTypeComp.bigJtf.getText(); + System.out.println("Create Relation: " + relName); + String archiveRelation = ""; + if(KUtil.isEmpty(relName)) { + throw new Exception("Ϊ"); + } + int ind = relName.indexOf('-'); + if (ind > 0) { + archiveRelation = relName.substring(ind + 1); + relName = relName.substring(0, ind); + } + + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent(type); + if (itemType == null) { + throw new Exception("ϵͳδҵ"+ type); + } + String checkRequire = checkRequire(); + + + if (!checkRequire.equals("")) { + + throw new Exception("дѡ"+ checkRequire); + } + + String checkCombox = checkCombox(); + + + + +System.out.println("checkCombox==="+checkCombox); + + if (!checkCombox.equals("")) { + + throw new Exception(checkCombox); + } + + String uom = ""; + + boolean addedToNewRev = false; + try { + MethodUtil.openByPass(session); + TCComponentItemRevisionType revType = itemType.getItemRevisionType(); + String revTypeName = revType.getName(); + String itemMasterTypeName = type + " Master"; + String revMasterTypeName = revTypeName + " Master"; + if (session.getTypeComponent(itemMasterTypeName) == null) { + itemMasterTypeName = type + "Master"; + } + if (session.getTypeComponent(revMasterTypeName) == null) { + revMasterTypeName = revTypeName + "Master"; + } + System.out.println("Revision Type: " + type); + System.out.println("Item Master Type: " + itemMasterTypeName); + System.out.println("Revision Master Type: " + revMasterTypeName); + Map revPropMap = new HashMap<>(); + Map revMasterPropMap = new HashMap<>(); + Map itemPropMap = new HashMap<>(); + Map itemMasterPropMap = new HashMap<>(); + + + //߼ + for (PrefComponent prefComponent : itemComps) { + if(prefComponent.title.equals("ϱ")) { + System.out.println("ϱ==="+prefComponent.getValue()); + revPropMap.put("lb5_wlbm", prefComponent.getValue()); + } + + if(prefComponent.title.equals("λ")) { + uom = prefComponent.getValue(); + } + } + if(relName != null && !relName.isEmpty()) { + revPropMap.put("lb5_wllx", relName); + } + + + + for (PrefComponent prefComponent : itemComps) { + KUtil.initPropMap(prefComponent.propConfig, prefComponent.getValue(), itemPropMap, itemMasterPropMap, revPropMap, revMasterPropMap); + } + + CreateInput revMasterInput = new CreateInput(); + revMasterInput.boName = revMasterTypeName; + revMasterInput.stringProps = revMasterPropMap; + if ("NHL8_AssemblyPro".equals(type) && "NHL8_VirtualPart".equals(targetRev.getItem().getType())) { + System.out.println(">> set nhl8_isFcheck = true"); + System.out.println(">> set nhl8_isfPass = true"); + revMasterInput.boolProps = new HashMap<>(); + revMasterInput.boolProps.put("nhl8_isFcheck", true); + revMasterInput.boolProps.put("nhl8_isfPass", true); + } + CreateInput itemMasterInput = new CreateInput(); + itemMasterInput.boName = itemMasterTypeName; + itemMasterInput.stringProps = itemMasterPropMap; + CreateInput revInput = new CreateInput(); + revInput.boName = revTypeName; + revInput.stringProps = revPropMap; + Map revMasterInfoMap = new HashMap<>(); + revMasterInfoMap.put("IMAN_master_form_rev", new CreateInput[] { revMasterInput }); + revInput.compoundCreateInput = revMasterInfoMap; + // create rev + CreateInput itemInput = new CreateInput(); + itemInput.boName = type; + itemInput.stringProps = itemPropMap; + Map revInfoMap = new HashMap<>(); + revInfoMap.put("revision", new CreateInput[] { revInput }); + revInfoMap.put("IMAN_master_form", new CreateInput[] { itemMasterInput }); + itemInput.compoundCreateInput = revInfoMap; + // create info + CreateIn cI = new CreateIn(); + cI.clientId = "CreateItem"; + cI.data = itemInput; + // service + DataManagementService service = DataManagementService.getService(session); + // create + CreateResponse resp = service.createObjects(new CreateIn[] { cI }); + SoaUtil.checkPartialErrors(resp.serviceData); + CreateOut[] cOs = resp.output; + TCComponentItem newItem = null; + if (cOs.length > 0) { + for (TCComponent s : cOs[0].objects) { + if (s instanceof TCComponentItem) { + newItem = (TCComponentItem) s; + } + } + } + System.out.println("New Item: " + newItem); + if (newItem == null) { + throw new Exception("쳣"); + } + + if(uom != null && !uom.isEmpty()) { + newItem.setProperty("uom_tag", uom); + } + + + newItem.refresh(); + TCComponentItemRevision newRev = newItem.getLatestItemRevision(); + + + + + System.out.println("New Rev: " + newRev); + //ProcessUtil.switchToPrecise(session, newRev); + addedToNewRev = false; + if (newRev != null) { + try { + newRev.add("TC_Is_Represented_By", this.targetRev); + newRev.refresh(); + try { + this.targetRev.add("representation_for", newRev); + this.targetRev.refresh(); + } catch (Exception e) { + // TODO: handle exception + } + addedToNewRev = true; + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post( e.getMessage(), "", MessageBox.ERROR); + } + } + if (!addedToNewRev) { + TCComponentFolder folder = session.getUser().getNewStuffFolder(); + folder.add("contents", newItem); + folder.refresh(); + } + MessageBox.post( addedToNewRev ? "ɹ" :"ɣ浽NewStuffļ", "", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post( e.getMessage(), "", MessageBox.ERROR); + } finally { + MethodUtil.closeByPass(session); + } + } + + private String checkRequire() { + List requireTitles = new ArrayList(); + for (PrefComponent prefComponent : itemComps) { + if (!prefComponent.checkRequire()) { + requireTitles.add(prefComponent.title.replace(" ", "").replace(":", "").replace(":", "").replace("", "")); + } + } + + if (requireTitles.size() > 0) { + //MessageBox.post( String.format(REG.getString("requireprop.INFO1"), requireTitles.toString()), "", MessageBox.WARNING); + return requireTitles.toString(); + } + return ""; + } + + private String checkCombox() { + List requireTitles = new ArrayList(); + for (PrefComponent prefComponent : itemComps) { + if (!prefComponent.checkCombox()) { + requireTitles.add(prefComponent.title+"ѡֵ!"); + } + } + + if (requireTitles.size() > 0) { + //MessageBox.post( String.format(REG.getString("requireprop.INFO1"), requireTitles.toString()), "", MessageBox.WARNING); + return requireTitles.toString(); + } + return ""; + } + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessHandler.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessHandler.java new file mode 100644 index 0000000..52bca9f --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/NewProcessHandler.java @@ -0,0 +1,52 @@ +package com.connor.tcm.outfile.createMaterial; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + + +public class NewProcessHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent targetComponent = app.getTargetComponent(); + + if(targetComponent == null) { + MessageBox.post("ѡͼֽ", "ʾ ", MessageBox.INFORMATION); + return null; + } + String type = targetComponent.getType(); + + String[] types = session.getPreferenceService().getStringValues("LB_Design_type"); + + if(types == null || types.length == 0) { + MessageBox.post("ȷ LB_Design_type ѡ", "ʾ ", MessageBox.INFORMATION); + return null; + } + boolean juedge = false; + for (int i = 0; i < types.length; i++) { + if(types[i].equals(type)) { + juedge = true; + } + } + + if(!juedge) { + MessageBox.post("ѡʹϴܵͼֽ汾", "ʾ ", MessageBox.INFORMATION); + return null; + } + new NewProcessDialog(new NewProcessDialogController(app)); + + return null; + } + + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/OptionItem.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/OptionItem.java new file mode 100644 index 0000000..bd6eb3e --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/OptionItem.java @@ -0,0 +1,20 @@ +package com.connor.tcm.outfile.createMaterial; + + +public class OptionItem { + private String value; + private String description; + + public OptionItem(String value, String description) { + this.value = value; + this.description = description; + } + + public String getValue() { return value; } + public String getDescription() { return description; } + + @Override + public String toString() { + return value; + } +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/PrefComponent.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/PrefComponent.java new file mode 100644 index 0000000..6d5be2c --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/PrefComponent.java @@ -0,0 +1,843 @@ +package com.connor.tcm.outfile.createMaterial; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Vector; + +import javax.swing.BorderFactory; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentUnitOfMeasure; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.treetable.SwingTextContextActivator; +import com.teamcenter.rac.util.Registry; +import com.teamcenter.rac.util.iTextArea; +import com.teamcenter.rac.util.iTextField; + +import com.teamcenter.services.rac.core.LOVService; +import com.teamcenter.services.rac.core._2013_05.LOV.InitialLovData; +import com.teamcenter.services.rac.core._2013_05.LOV.LOVSearchResults; +import com.teamcenter.services.rac.core._2013_05.LOV.LOVValueRow; +import com.teamcenter.services.rac.core._2013_05.LOV.LovFilterData; +import com.teamcenter.soa.client.model.LovValue; + +import cn.net.connor.std.aifrcp.util.KUtil; + + +public class PrefComponent { + + private static final int INPUT_FIELD_WIDTH = 200; // + private static final int INPUT_FIELD_HEIGHT = 30; + private static final int TEXT_AREA_ROWS = 5; + private static final int TEXT_AREA_COLS = 38; // Լ 300px + + + + + public boolean isLovParent = false; + public boolean isLovChild = false; + + + public String lovName; + + public JTextField bigJtf; + public static final String REQUIRE = "*"; + public static final String READONLY = "#"; + public static final String INVISIBLE = "@"; + public static final String TEXTAREA = "$"; + public boolean isTextArea = false; + public JPanel panel; + public String configStr; + public boolean require = false; + public boolean readonly = false; + public boolean invisible = false; + public String title; + public String propConfig; + public String fromPropConfig; + + public String[] lov; + public String[] displayLov; + public String[] descriptions; + public iTextField textField; + private iTextArea textArea; + public JComboBox comboBox; + public ArrayList list = new ArrayList(); + private int textLength = -1; + public TCComponentItemRevision rev; + public HashMap opHashMap = new HashMap(); + public HashMap lovDisRealMap = new HashMap(); + public PrefComponent(String pref, TCComponentItemRevision targetRev) { + this.configStr = pref; + this.rev = targetRev; + } + + public boolean init(TCSession session) throws Exception{ + System.out.println("configStr==="+configStr); + if (KUtil.isEmpty(configStr)) { + return false; + } + if (configStr.startsWith(REQUIRE)) { + configStr = configStr.substring(1); + this.require = true; + } + if (configStr.startsWith(READONLY)) { + configStr = configStr.substring(1); + this.readonly = true; + } + if(configStr.startsWith(INVISIBLE)) { + configStr = configStr.substring(1); + this.invisible = true; + } + if (configStr.startsWith(TEXTAREA)) { + configStr = configStr.substring(1); + this.isTextArea = true; + } + String[] split = configStr.split("=", -1); + int len = KUtil.getLen(split); + if (len > 0) { + this.title = split[0]; + } + if (len > 1) { + this.propConfig = split[1]; + } + if (len > 2) { + this.fromPropConfig = split[2]; + } + if (len > 3 && !KUtil.isEmpty(split[3])) { + this.lov = split[3].split(";"); + } + if (len > 4 && !KUtil.isEmpty(split[4])) { + try { + this.textLength = Integer.parseInt(split[4].trim()); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (KUtil.isEmpty(title)) { + return false; + } + if (lov!=null && lov.length > 1) { + + String[] lovValues = lov; + int lovCnt = KUtil.getLen(lovValues); + this.lov = new String[lovCnt]; + this.displayLov = new String[lovCnt]; + descriptions = new String[lovCnt]; + for (int i = 0; i < lovCnt; i++) { + + String[] split2 = lovValues[i].split(":"); + if(split2 != null && split2.length == 2) { + + String realValue = split2[0]; + String disValue = split2[1]; + lov[i] = realValue; + displayLov[i] = disValue; + descriptions[i] = ""; + lovDisRealMap.put(displayLov[i], lov[i]); + } + } + + } else if(lov!=null && lov.length==1) {//TODO + lovName = lov[0]; + if(lov[0].contains("^A")) { + lovName = lovName.split("\\^")[0]; + isLovParent = true; + + +// TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); +// TCComponentListOfValues[] lovs = lovType.find(lov[0]); +// if(lovs==null || lovs.length==0) { +// throw new Exception(String.format(REG.getString("lovnotfound.ERROR1"), lov[0])); +// } +// displayLov = getDynamicLOV(lovs[0]); + + //TODO + + + TCComponentListOfValues lovComp = KUtil.getLov(session, lovName); + + if (lovComp == null) { + throw new Exception("δҵ"+lovName); + } + + + initLovTree(lovComp,session); + System.out.println("lovList==="+listLov.toString()); + + + + List vals = lovComp.getListOfValues().getValues(); + int lovCnt = vals == null ? 0 : vals.size(); + +// +// Map lovTWO = getLovTWO(session,lov[0]); +// +// System.out.println("lovTWO======"+lovTWO.toString()); +// +// Map lovTh = getLovThreeRealValue(session,lov[0]); +// +// System.out.println("lovTh======"+lovTh.toString()); + + + initLovTree(lovComp,session); + System.out.println("lovList==="+list.toString()); + + + ListOfValuesInfo listOfValues = lovComp.getListOfValues(); + System.out.println("lovCnt=="+lovCnt); + if (lovCnt>0) { + descriptions = listOfValues.getDispDescription();//lov + System.out.println("getListOfValues:"+lovName+lovCnt); + this.lov = new String[lovCnt]; + this.displayLov = new String[lovCnt]; + for (int i = 0; i < lovCnt; i++) { + LovValue lovValue = vals.get(i); + String realValue = lovValue.getValue() == null ? "" : lovValue.getValue().toString(); + String disValue = lovValue.getDisplayValue(); + lov[i] = realValue; + displayLov[i] = disValue; + lovDisRealMap.put(displayLov[i], lov[i]); + } + }else { + System.out.println("getDynamicLOV:"+lovName); + String[] lovValues = getDynamicLOV(lovComp); + + lovCnt = KUtil.getLen(lovValues); + this.lov = new String[lovCnt]; + this.displayLov = new String[lovCnt]; + for (int i = 0; i < lovCnt; i++) { + String realValue = lovValues[i]; + String disValue = lovValues[i]; + lov[i] = realValue; + displayLov[i] = disValue; + lovDisRealMap.put(displayLov[i], lov[i]); + } + } + + + }else if(lovName.contains("^B")) { + lovName = lovName.split("\\^")[0]; + isLovChild = true; + }else { +// TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); +// TCComponentListOfValues[] lovs = lovType.find(lov[0]); +// if(lovs==null || lovs.length==0) { +// throw new Exception(String.format(REG.getString("lovnotfound.ERROR1"), lov[0])); +// } +// displayLov = getDynamicLOV(lovs[0]); + lovName = lov[0]; + //TODO + TCComponentListOfValues lovComp = KUtil.getLov(session, lovName); + if (lovComp == null) { + throw new Exception("δҵ"+lovName); + } + List vals = lovComp.getListOfValues().getValues(); + int lovCnt = vals == null ? 0 : vals.size(); + +// +// Map lovTWO = getLovTWO(session,lovName); +// +// System.out.println("lovTWO======"+lovTWO.toString()); +// +// Map lovTh = getLovThreeRealValue(session,lovName); +// +// System.out.println("lovTh======"+lovTh.toString()); + + + //initLovTree(lovComp,session); + //System.out.println("lovList==="+list.toString()); + + + + + + ListOfValuesInfo listOfValues = lovComp.getListOfValues(); + + + +// Object[] objectValues = listOfValues.getListOfValues();//.getStringListOfValues(); +// +// +// for (int j = 0; j < objectValues.length; j++) { +// if(objectValues[j] instanceof TCComponentUnitOfMeasure) +// { +// TCComponentUnitOfMeasure componentUnitOfMeasure = (TCComponentUnitOfMeasure) objectValues[j]; +// valuesList[j] = componentUnitOfMeasure.toDisplayString(); +// } +// String disPlayv = info.getDisplayableValue(valuesList[j]); +// disValuesList[j] = disPlayv; +// +// } +// + + + System.out.println("lovCnt=="+lovCnt); + if (lovCnt>0) { + descriptions = listOfValues.getDispDescription();//lov + System.out.println("getListOfValues:"+lovName+lovCnt); + this.lov = new String[lovCnt]; + this.displayLov = new String[lovCnt]; + for (int i = 0; i < lovCnt; i++) { + LovValue lovValue = vals.get(i); + String realValue = lovValue.getValue() == null ? "" : lovValue.getValue().toString(); + String disValue = lovValue.getDisplayValue(); + lov[i] = realValue; + displayLov[i] = disValue; + lovDisRealMap.put(displayLov[i], lov[i]); + } + }else { + System.out.println("getDynamicLOV:"+lovName); + String[] lovValues = getDynamicLOV(lovComp); + lovCnt = KUtil.getLen(lovValues); + this.lov = new String[lovCnt]; + this.displayLov = new String[lovCnt]; + for (int i = 0; i < lovCnt; i++) { + String realValue = lovValues[i]; + String disValue = lovValues[i]; + lov[i] = realValue; + displayLov[i] = disValue; + lovDisRealMap.put(displayLov[i], lov[i]); + } + } + + System.out.println("lovDisRealMap==="+lovDisRealMap.toString()); + } + + + + } else { + displayLov = lov; + } + initPanel(); + initComponent(); + return true; + } + + private void initComponent() throws Exception{ + if(readonly) { + if(textField!=null) { + textField.setEditable(false); + } + if (textArea != null) { + textArea.setEditable(false); + } + if(comboBox!=null) { + comboBox.setEditable(false); + comboBox.setEnabled(false); + } + } + if(require) { + if(textField!=null) { + textField.setRequired(true); + } + if (textArea != null) { + textArea.setRequired(true); + } + } + if(rev!=null&&!KUtil.isEmpty(fromPropConfig)) { + String value = getConfigPropValue(rev,fromPropConfig); + System.out.println(">> Load Property: "+fromPropConfig+" = "+value); + if(textField!=null) { + textField.setText(value); + } + if(comboBox!=null) { + comboBox.setSelectedItem(value); + } + } + } + + public static String getConfigPropValue(TCComponentItemRevision rev, String propConfigStr) throws Exception { + if (rev == null || KUtil.isEmpty(propConfigStr)) { + return ""; + } + StringBuilder res = new StringBuilder(); + String[] propConfigSplit = propConfigStr.split("\\+"); + int len = KUtil.getLen(propConfigSplit); + for (int i = 0; i < len; i++) { + String propConfig = propConfigSplit[i]; + String propFrom = null, propName = null; + String[] split = propConfig.split("\\."); + if (KUtil.getLen(split) == 2) { + propFrom = split[0].trim().toUpperCase(); + propName = split[1].trim(); + } + if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) { + res.append(propConfig); + continue; + } + TCComponent target = null; + if ("ITEM".equals(propFrom)) { + target = rev.getItem(); + } else if ("REV".equals(propFrom)) { + target = rev; + } else if ("IRELA".equals(propFrom)) { + TCComponent[] targets = rev.getRelatedComponents("Ac5_Processroute_Irela"); + int targetCnt = KUtil.getLen(targets); + for(int k=0;k optionItem : opHashMap.entrySet()) { + * comboBox.addItem(optionItem); } }else { if (item.contains(key)) { OptionItem + * optionItem = opHashMap.get(item); + * + * comboBox.addItem(optionItem); } } + * + * } bigJtf.setText(key); } } + * + * public void keyPressed(KeyEvent e) {} }); + * + * + * //iComboBox iComboBox = new iComboBox(); bigJtf.addFocusListener(new + * FocusAdapter() { public void focusGained(FocusEvent param1FocusEvent) { + * SwingTextContextActivator.instance().activateContext(); } + * + * public void focusLost(FocusEvent param1FocusEvent) { + * super.focusLost(param1FocusEvent); + * SwingTextContextActivator.instance().deactivateContext(); } }); + */ + + + + + + + + KUtil.addCol(panel, comboBox, gbc, 1, 1); + + + + + }else { + int len = KUtil.getLen(displayLov); + + // label + String labelText = "" + title; + if (len > 0 && require) { + labelText += "*"; + } + labelText += ""; + JLabel label = new JLabel(labelText); + + // === ʼУlabel ǵһ === + KUtil.newRow(panel, label, gbc, 1); + + // === ؼͬһ === + if (len > 0) { + comboBox = new JComboBox(); + comboBox.setRenderer(new TwoColumnRenderer()); + comboBox.insertItemAt(null, 0); + comboBox.setSelectedIndex(0); + comboBox.setEditable(true); + comboBox.setPreferredSize(new Dimension(INPUT_FIELD_WIDTH, INPUT_FIELD_HEIGHT)); + comboBox.setMaximumSize(new Dimension(INPUT_FIELD_WIDTH, INPUT_FIELD_HEIGHT * 2)); // ֹ + + for (int i = 0; i < len; i++) { + OptionItem optionItem = new OptionItem(displayLov[i], descriptions[i]); + comboBox.addItem(optionItem); + opHashMap.put(displayLov[i], optionItem); + list.add(displayLov[i]); + } + + this.bigJtf = ((JTextField)this.comboBox.getEditor().getEditorComponent()); + bigJtf.setEditable(false); + /* + * this.bigJtf = ((JTextField) this.comboBox.getEditor().getEditorComponent()); + * bigJtf.setPreferredSize(new Dimension(INPUT_FIELD_WIDTH - 20, + * INPUT_FIELD_HEIGHT - 4)); // Сһ this.bigJtf.addKeyListener(new + * KeyListener() { public void keyTyped(KeyEvent e) {} + * + * public void keyReleased(KeyEvent e) { Object obj = e.getSource(); + * + * if ((e.getKeyCode() == 10) && (obj == bigJtf)) { String key = + * bigJtf.getText(); comboBox.removeAllItems(); // + * System.out.println("key==="+key); // + * System.out.println("opHashMap==="+opHashMap.toString()); for (String item : + * list) { System.out.println("item==="+item); if(item.isEmpty()) { for + * (Entry optionItem : opHashMap.entrySet()) { + * comboBox.addItem(optionItem); } }else { if (item.contains(key)) { OptionItem + * optionItem = opHashMap.get(item); + * + * comboBox.addItem(optionItem); } } + * + * } bigJtf.setText(key); } } + * + * public void keyPressed(KeyEvent e) {} }); + * + * + * //iComboBox iComboBox = new iComboBox(); bigJtf.addFocusListener(new + * FocusAdapter() { public void focusGained(FocusEvent param1FocusEvent) { + * SwingTextContextActivator.instance().activateContext(); } + * + * public void focusLost(FocusEvent param1FocusEvent) { + * super.focusLost(param1FocusEvent); + * SwingTextContextActivator.instance().deactivateContext(); } }); + */ + + + + + + + + KUtil.addCol(panel, comboBox, gbc, 1, 1); + + } else { + if (isTextArea) { + textArea = new iTextArea(TEXT_AREA_ROWS, TEXT_AREA_COLS); + textArea.setBorder(BorderFactory.createLineBorder(Color.GRAY)); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + + // ؼ preferredSize ƥؼ + textArea.setPreferredSize(new Dimension(INPUT_FIELD_WIDTH, + TEXT_AREA_ROWS * INPUT_FIELD_HEIGHT + 10)); // ߾ + + textArea.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + SwingTextContextActivator.instance().activateContext(); + } + public void focusLost(FocusEvent e) { + super.focusLost(e); + SwingTextContextActivator.instance().deactivateContext(); + } + }); + // textArea ռݿؼλã1У + KUtil.addCol(panel, textArea, gbc, 1, 1); + + } else { + textField = new iTextField(textLength > 0 ? textLength : 30); + textField.setPreferredSize(new Dimension(INPUT_FIELD_WIDTH, INPUT_FIELD_HEIGHT)); + KUtil.addCol(panel, textField, gbc, 1, 1); + } + + // Ҫⰴť initMEPropPanel е߼ڴ + // 磺 + // if ("some_prop".equals(propConfig)) { + // KUtil.addCol(panel, new JButton("..."), gbc, 1, 0); + // } + } + + // ѡ textLength > 0 ҪռλͨҪ + // if (textLength > 0 && !isTextArea) { + // KUtil.addCol(panel, new JLabel(""), gbc, 1, 1); + // } + } + + + + + + } + + + + + + public Component getPanel() { + return panel; + } + + public boolean isInvisible() { + return invisible; + } + + public String getValue() { + String value = null; + if(textField!=null) { + value = textField.getText(); + } else if (textArea != null) { + value = textArea.getText(); + } else if(comboBox!=null) { + String text = bigJtf.getText(); + value = lovDisRealMap.get(text); + } + //System.out.println("value==="+value); + return value; + } + + public boolean checkRequire() { + if(!require) { + return true; + } + String val = getValue(); + return val!=null&&!"".equals(val); + } + + public boolean checkCombox() { + if(comboBox!=null) { + String selectedItem = bigJtf.getText(); + System.out.println("selectedItem=="+selectedItem); + if(selectedItem.isEmpty()) { + return true; + } + for (Entry optionItem : opHashMap.entrySet()) { + OptionItem value = optionItem.getValue(); + if(value.getValue().equals(selectedItem)) { + return true; + } + } + }else { + return true; + } + return false; + } + + public String[] getDynamicLOV(TCComponentListOfValues lov) throws Exception { + Vector lovDisplayValueList = new Vector<>(); + Vector lovDescValueList = new Vector<>(); +// lovDisplayValueList.add(""); +// Vector lovValueList = new Vector<>(); + LOVService lovService = LOVService.getService((TCSession) AIFUtility.getCurrentApplication().getSession()); + InitialLovData input = new InitialLovData(); + LovFilterData filter = new LovFilterData(); + filter.sortPropertyName = "object_name"; + filter.order = 1; + filter.numberToReturn = 1000; + filter.maxResults = 1000; + + input.lov = lov; + input.filterData = filter; + LOVSearchResults result = lovService.getInitialLOVValues(input); +// StringBuffer sb = new StringBuffer(); +// sb.append(">>"); + for (LOVValueRow row : result.lovValues) { + Map map = row.propDisplayValues; +// Map realmap = row.propInternalValues; + for (String key : map.keySet()) { + + + if(key.equals("object_desc")) { + + String[] v = map.get(key); + + lovDescValueList.add(v[0]); + } + + if(!key.equals("object_name")) + continue; +// sb.append("UID:" + row.uid + ",key:" + key + "value:" + map.get(key)[0]); +// sb.append("\n"); + String[] v = map.get(key); + lovDisplayValueList.add(v[0]); +// lovValueList.add(realmap.get(key)[0]); +// System.out.println("key:"+key+"=="+v.length+">>"+v[0]); + } + } +// System.out.println("StringBuffer:"+sb.toString()); + descriptions = lovDescValueList.toArray(new String[lovDescValueList.size()]); + return lovDisplayValueList.toArray(new String[lovDisplayValueList.size()]); + } + + + + + public LinkedHashMap> listLov = new LinkedHashMap>(); + + private void initLovTree(TCComponentListOfValues lov,TCSession session) { + + if (lov != null) { + try { + ListOfValuesInfo info = lov.getListOfValues(); + + + + + + + String[] valuesList = info.getStringListOfValues(); + System.out.println("initLovTree"); + + if(valuesList != null && valuesList.length != 0) { + System.out.println("valuesList======"+valuesList.length); + for (String v : valuesList) { + String disPlayv = info.getDisplayableValue(v); + + ArrayList childLov = new ArrayList(); + TCComponentListOfValues cLov = lov + .getListOfFilterOfValue(v); + AIFComponentContext[] children = lov.getChildren(); + if(children.length > 0) { + InterfaceAIFComponent component = children[0].getComponent(); + String type = component.getType(); + } + System.out.println("cLov======"+cLov); + if(cLov != null) { + String lovName = cLov.toString(); + TCComponentListOfValues lov111 = TCComponentListOfValuesType.findLOVByName(lovName); + if ("Fnd0ListOfValuesDynamic".equals(lov111.getProperty("lov_type"))) { + System.out.println("̬lovName=" + lovName); + LOVService lovService = LOVService.getService(session); + InitialLovData input = new InitialLovData(); + LovFilterData filter = new LovFilterData(); + if ("LD6_TecDoc_TypeLOV".equals(lovName)) { + filter.sortPropertyName = "fnd0StringValues"; // lovĺֵ̨ + } else { + filter.sortPropertyName = "object_name"; // lovĺֵ̨ + } + + filter.order = 1; + filter.numberToReturn = 2000; + filter.maxResults = 2000; + + input.lov = lov111; + input.filterData = filter; + LOVSearchResults result = lovService.getInitialLOVValues(input); + // System.out.println("111==="+result.toString()); + + for (LOVValueRow row : result.lovValues) { + Map map = row.propDisplayValues; + Map realmap = row.propInternalValues; +// for (String key : map.keySet()) { +// System.out.println("key=" + key + ",value=" + map.get(key)[0]); +// } +// for (String key : realmap.keySet()) { +// System.out.println("key2=" + key + ",value2=" + map.get(key)[0]); +// } + String disval = ""; + String val = ""; + String key1 = "object_name";// ʵֵ ʾֵһ + if ("LD6_TecDoc_TypeLOV".equals(lovName)) { + key1 = "fnd0StringValues"; // lovĺֵ̨ + } + // String key2 = "object_desc";// ʾֵڶ + if (map.containsKey(key1)) { + val = realmap.get(key1)[0]; + disval = map.get(key1)[0]; + } + if (!val.equals("")) { + childLov.add(disval); + } + + } + listLov.put(disPlayv, childLov); + }else { + List vals = lov111.getListOfValues().getValues(); + //descriptions = listOfValues.getDispDescription();//lov + System.out.println("vals===="+vals.size()); + for (int i = 0; i < vals.size(); i++) { + LovValue lovValue = vals.get(i); + String realValue = lovValue.getValue() == null ? "" : lovValue.getValue().toString(); + //String disValue = lovValue.getDisplayValue(); + childLov.add(realValue); + } + + listLov.put(disPlayv, childLov); + } + } + + } + } + + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + + } + + + + + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/ProcessUtil.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/ProcessUtil.java new file mode 100644 index 0000000..56fe8e9 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/ProcessUtil.java @@ -0,0 +1,67 @@ +package com.connor.tcm.outfile.createMaterial; + +import java.text.DecimalFormat; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; + +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOPWindowType; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; + +import cn.net.connor.std.aifrcp.util.KUtil; + +public class ProcessUtil { + + public static final String PREF_DB_CONN = "Connor_DBConn_Oracle_TC"; + public static DecimalFormat DF = new DecimalFormat("#.##########################################"); + public static final String PREF_MEOP_ITEMTYPE = "Connor_AVIC_MEOP_Types"; + public static final String PREF_MEPROCESS_ITEMTYPE = "Connor_AVIC_MEProcess_Types"; + + public static boolean isMEOP(TCSession session, String itemTypeName) throws Exception { + if (KUtil.isEmpty(itemTypeName)) { + return false; + } + String[] types = KUtil.getPrefVals(session, PREF_MEOP_ITEMTYPE); + return KUtil.inArray(itemTypeName, types) >= 0; + } + + public static boolean isMEProcess(TCSession session, String itemTypeName) throws Exception { + if (KUtil.isEmpty(itemTypeName)) { + return false; + } + String[] types = KUtil.getPrefVals(session, PREF_MEPROCESS_ITEMTYPE); + return KUtil.inArray(itemTypeName, types) >= 0; + } + + public static void errorSWT(Shell shell, String message, String title) { + showDialog(shell, message, title, SWT.ICON_ERROR); + } + + public static void showDialog(Shell shell, String message, String title, int type) { + org.eclipse.swt.widgets.MessageBox dialog = new org.eclipse.swt.widgets.MessageBox(shell, SWT.OK | type); + dialog.setText(title); + dialog.setMessage(message); + dialog.open(); + } + + @SuppressWarnings("deprecation") + public static void switchToPrecise(TCSession session, TCComponentItemRevision rev) throws Exception { + // 切换到精确bom + System.out.println("Switch to Precise: " + rev); + TCComponentBOPWindowType bopWindowType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow"); + TCComponentBOMWindow bopWindow = bopWindowType.create(null); + TCComponentBOMLine bopLine = bopWindow.setWindowTopLine(rev.getItem(), rev, null, null); + bopWindow.lock(); + try { + bopLine.setPrecision(true); + bopWindow.save(); + } finally { + bopWindow.unlock(); + bopWindow.close(); + } + } + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/createMaterial/TwoColumnRenderer.java b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/TwoColumnRenderer.java new file mode 100644 index 0000000..c5350cc --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/createMaterial/TwoColumnRenderer.java @@ -0,0 +1,43 @@ +package com.connor.tcm.outfile.createMaterial; + + +import javax.swing.*; +import java.awt.*; + +public class TwoColumnRenderer implements ListCellRenderer { + + private final JLabel label = new JLabel(); + + @Override + public Component getListCellRendererComponent( + JList list, + OptionItem value, + int index, + boolean isSelected, + boolean cellHasFocus) { + + // ñ룩 + if (isSelected) { + label.setBackground(list.getSelectionBackground()); + } else { + label.setBackground(list.getBackground()); + } + label.setOpaque(true); + label.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5)); + + // HTML ݣȫɫ setForeground + if (value == null) { + label.setText("ѡ..."); + } else { + String html = String.format( + "%s  %s", + value.getValue(), + value.getDescription() + ); + label.setText(html); + } + + + return label; + } +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomCommand.java b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomCommand.java new file mode 100644 index 0000000..b5e6c6f --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomCommand.java @@ -0,0 +1,276 @@ +package com.connor.tcm.outfile.dbom2ebom; + +import java.util.ArrayList; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import com.connor.tcm.outfile.bean.NodeBean; +import com.teamcenter.rac.aif.AbstractAIFCommand; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class DbomTransitionToEbomCommand extends AbstractAIFCommand { + + private InterfaceAIFComponent comp; + private TCSession session; + private TCComponentBOMLine bomLine = null; + static ArrayList preList = new ArrayList(); + + public DbomTransitionToEbomCommand(InterfaceAIFComponent comp, TCSession session) { + // TODO Auto-generated constructor stub + this.comp = comp; + this.session = session; + } + + @Override + public void executeModal() throws Exception { + // TODO Auto-generated method stub +// TCComponentType compType = session.getTypeComponent("ML8_Washing"); +// String[] allProperties=compType.getPropertyNames();//ȡ + //TCProperty[] allProperties=compType.getPropertyNames();//ȡ + + //ȡѡеĶ + if(!(comp instanceof TCComponentBOMLine)) + { + MessageBox.post("ڽṹѡBOMLine", "", MessageBox.ERROR); + return; + } + //System.out.println("11111111111"); + bomLine = (TCComponentBOMLine) comp; + + //ж϶ + TCComponentItem item = bomLine.getItem(); + boolean isTypeof=false; + String[] prefValues = session.getPreferenceService().getStringValues("Connor_DBOM_Type"); //Connor_DBOM_Type + System.out.println("prefValuse"+prefValues.toString()); + for(String pref : prefValues) { + if(pref.equals(item.getType())) { + isTypeof = true; + } + } + + if(!isTypeof) { + MessageBox.post("ѡConnor_DBOM_TypeѡõĶ","ʾ",2); + return; + } + System.out.println(item.getType()); +// if(!item.getType().equals("ML8_Design")) +// { +// MessageBox.post("ѡƶ", "", MessageBox.ERROR); +// return; +// } + //final List> bomPropertyList = this.getBomPropertys(session, bomLine); + + + String[] prefValueParts = session.getPreferenceService().getStringValues("Connor_DBOM_PartType"); + for (String string : prefValueParts) { + preList.add(string); + } + + final DefaultMutableTreeTableNode node = this.getBomPropertyToNode(session, bomLine); + + + new Thread() { + @Override + public void run() { + DbomTransitionToEbomDialog dialog = new DbomTransitionToEbomDialog( + comp, session,node,preList); + } + }.start(); + super.executeModal(); + } + + /** + * ȡBOM + * @throws TCException + */ + public static DefaultMutableTreeTableNode getBomPropertyToNode(TCSession session, TCComponentBOMLine topBomLine) throws TCException { + // TODO Auto-generated method stub + + NodeBean nodeBean = new NodeBean(); + + //String ss = subline.getStringProperty("bl_indented_title"); + //ID + nodeBean.setDbom(""); + nodeBean.setEbom(""); + nodeBean.setEbomId(""); + nodeBean.setNum(""); + nodeBean.setLabel(""); + nodeBean.setRefreshStatus(""); + nodeBean.setParentString(""); + + DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(nodeBean); + //ȡBOM + try { + //getRepresentationPropertysToNode(topBomLine, rootNode, ""); + getBomPropertysToNode(topBomLine, rootNode, ""); + return rootNode; + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + return null; + } + /*** + * ȡʾµĶ + * @param bomLine + * @param rootNode + * @param parentID + * @throws TCException + */ + public static void getRepresentationPropertysToNode(TCComponentBOMLine bomLine, DefaultMutableTreeTableNode rootNode,String parentID,String quantity) throws TCException + { + TCComponentItemRevision itemRevision = bomLine.getItemRevision(); + //ˢ±ʾϵ + //TCComponent referenceProperty = itemRevision.getReferenceProperty("representation_for"); + //referenceProperty.refresh(); + //ȡʾϵµĶ + itemRevision.refresh(); + TCComponent[] tcComponents = itemRevision.getReferenceListProperty("representation_for"); + for (TCComponent tcComponent : tcComponents) { + + TCProperty refreshStatusProperty = tcComponent.getTCProperty("release_status_list"); + TCComponent[] refreshStatus = refreshStatusProperty.getReferenceValueArray(); + TCProperty processProperty = tcComponent.getTCProperty("process_stage_list"); + TCComponent[] processStage = processProperty.getReferenceValueArray(); + + NodeBean nodeBean = new NodeBean(); + + nodeBean.setDbom(""); + nodeBean.setEbom(tcComponent.getStringProperty("object_string")); + nodeBean.setEbomId(tcComponent.getStringProperty("item_id")); + nodeBean.setEbomDesc(tcComponent.getStringProperty("object_desc"));// + nodeBean.setNum(quantity); + nodeBean.setLabel("0"); + if(refreshStatus.length > 0) + { + StringBuffer stringBuffer = new StringBuffer(); + //ӷ״̬ + for (int i = 0; i < refreshStatus.length; i++) { + stringBuffer.append(refreshStatus[i].toString()); + if(i < refreshStatus.length - 1) + { + stringBuffer.append(","); + } + } + nodeBean.setRefreshStatus(stringBuffer.toString()); + } + else if(processStage.length > 0) + { + nodeBean.setRefreshStatus(""); + } + else + { + nodeBean.setRefreshStatus(""); + } + nodeBean.setParentString(itemRevision.getStringProperty("object_string")); + + DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(nodeBean); + rootNode.add(node); + + if(tcComponents.length == 1) + { + if(getTopRefresh(node)) + { + nodeBean.setLabel("0"); + } + else + { + nodeBean.setLabel("1"); + } + } + } + } + /*** + * жϼǷѡѷ + * @param node + * @return + */ + private static boolean getTopRefresh(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && childBean.getRefreshStatus().indexOf("") >= 0) + { + //MessageBox.post("ϲ["+childBean.getEbom()+"]ѹѡͲ㲻ѡ", "", MessageBox.ERROR); + return true; + } + else + { + return getTopRefresh(childNode); + } + } + } + } + + return result; + } + + + /** + * ȡBOMϢ + * @param bomLine + * @param bomPropertyList + * @param parentID + */ + public static void getBomPropertysToNode(TCComponentBOMLine bomLine, DefaultMutableTreeTableNode rootNode,String parentID) + { + try { + + NodeBean nodeBean = new NodeBean(); + System.out.println(bomLine.getStringProperty("bl_item_object_type")); + + nodeBean.setDbom(bomLine.getStringProperty("bl_item_object_string")); + nodeBean.setNum(bomLine.getStringProperty("bl_quantity")); + nodeBean.setEbom(""); + nodeBean.setEbomId(""); + if(preList.contains(bomLine.getStringProperty("bl_item_object_type"))) { + nodeBean.setLabel("0"); + }else { + nodeBean.setLabel(""); + } + + nodeBean.setRefreshStatus(""); + nodeBean.setParentString(""); + + DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(nodeBean); + rootNode.add(node); + + + getRepresentationPropertysToNode(bomLine, node,bomLine.getStringProperty("bl_item_item_id"),bomLine.getStringProperty("bl_quantity")); + + if(bomLine.getChildren().length > 0) + { + AIFComponentContext aif[] = bomLine.getChildren(); + for (int i = 0; i < aif.length; i++) + { + TCComponentBOMLine subline = (TCComponentBOMLine) aif[i] + .getComponent(); + + getBomPropertysToNode(subline, node,bomLine.getStringProperty("bl_item_item_id")); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomDialog.java b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomDialog.java new file mode 100644 index 0000000..61ed711 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomDialog.java @@ -0,0 +1,715 @@ +package com.connor.tcm.outfile.dbom2ebom; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.table.DefaultTableModel; +import javax.swing.tree.TreePath; + +import org.jdesktop.swingx.decorator.HighlighterFactory; +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import com.connor.tcm.outfile.bean.NodeBean; +import com.connor.tcm.outfile.util.Adapter; +import com.connor.tcm.outfile.util.MethodUtil; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +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.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +//import com.teamcenter.soa.exceptions.NotLoadedException; + +public class DbomTransitionToEbomDialog extends AbstractAIFDialog implements +ActionListener, MouseListener { + + private TCSession session; + private InterfaceAIFComponent comp; + //private InterfaceAIFComponent comp;//ȡѡеĶ + + private List isNotEditableRow = new ArrayList(); + //private TCComponentBOMLine bomLine; + private DefaultMutableTreeTableNode node; + + private String[] header = new String[] { "DBOM", "EBOM","ѡ", "EBOMID", "","","״̬","Ӧڵ"}; + + private JPanel titlePanel; + private JLabel titleLabel; + private JTreeTable table; + private JTreeTableModel map; + + private JPanel rootPanel; + private JButton okButton; + private JButton celButton; + private JButton refreshButton; + private ArrayList preList; + + public DbomTransitionToEbomDialog(InterfaceAIFComponent comp,TCSession session, + DefaultMutableTreeTableNode node,ArrayList preList) { + // TODO Auto-generated constructor stub + super(false); + this.session = session; + this.comp = comp; + this.node = node; + this.preList = preList; + init(); + } + + private void init() { + // TODO Auto-generated method stub + this.setTitle("DBOMתEBOM"); + this.setPreferredSize(new Dimension(800,600)); + // ʼⲿֿؼ + this.titlePanel = new JPanel(); + this.titleLabel = new JLabel("DBOMתEBOM"); + this.titleLabel.setFont(new Font("", 1, 18)); + this.titlePanel.add(titleLabel); + + JPanel panel = new JPanel(); + panel.add(this.titlePanel,BorderLayout.NORTH); + + this.table = getJTreeTable(null, null, header, null); + + this.table.addMouseListener(this); + Adapter adapter = new Adapter(table); + + this.rootPanel = new JPanel(new FlowLayout()); + this.okButton = new JButton("ȷ"); + this.celButton = new JButton("ȡ"); + this.refreshButton = new JButton("ˢ"); + + this.rootPanel.add(okButton); + this.rootPanel.add(celButton); + this.rootPanel.add(refreshButton); + //this.rootPanel.add(celValueButton); + + // + this.createActionEvent(); + this.setLayout(new BorderLayout()); + // this.add(centerPanel, BorderLayout.NORTH); + this.add(panel, BorderLayout.NORTH); + this.add(new JScrollPane(this.table), BorderLayout.CENTER); + // dialog.add(tablePanel, BorderLayout.CENTER); + this.add(rootPanel, BorderLayout.SOUTH); + //this.setAlwaysOnTop(true); + this.pack(); + this.setLocationRelativeTo(null); + this.show(); + } + + //Ӽ + public void createActionEvent() { + this.okButton.addActionListener(this); + this.celButton.addActionListener(this); + this.refreshButton.addActionListener(this); + //this.celValueButton.addActionListener(this); + } + + //Jtableͨ÷ + public JTreeTable getJTreeTable(JTreeTable partsTable, DefaultTableModel dtm, + Object[] titleNames, Object[][] values) { + int simpleLen = 100; + int totleLen = 1500; + if (partsTable == null) { + this.map = new JTreeTableModel(this.node); + this.map.setIsNotEditableRow(this.isNotEditableRow); + //map.setColumnIdentifiers(titleNames); + + partsTable = new JTreeTable(map); + partsTable.setIsNotEditableRow(this.isNotEditableRow); + partsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + // partsTable.setRowHeight(1, 50); + // partsTable.setRowHeight(2, 100); + partsTable.setRowHeight(30); + partsTable.expandAll(); // չȫڵ + // +// partsTable.HiddenCell(0); + + partsTable.getColumnModel().getColumn(0).setPreferredWidth(188); // õһп + partsTable.getColumnModel().getColumn(1).setPreferredWidth(150); // õڶп + partsTable.getColumnModel().getColumn(2).setPreferredWidth(55); // õп + + partsTable.setHighlighters(HighlighterFactory.createSimpleStriping()); + + if (simpleLen * titleNames.length >= totleLen) { + for (int i = 0; i < titleNames.length; i++) { + partsTable.getColumnModel().getColumn(i) + .setPreferredWidth(simpleLen); + } + partsTable.setAutoResizeMode(0); + } else { + partsTable.setAutoResizeMode(1); + } + } + return partsTable; + } + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + if(e.getClickCount() == 2) + { + TreePath treePath = table.getPathForLocation(e.getX(),e.getY()); + if (treePath != null) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) treePath.getLastPathComponent(); + NodeBean nodeBean = (NodeBean) node.getUserObject(); + String itemId = nodeBean.getDbom(); + if(itemId != null && !itemId.isEmpty()) + { + try { + //ȡ + TCComponentItemType itemType = (TCComponentItemType) this.session.getTypeComponent("Item"); + TCComponentItem item = itemType.find(itemId.split("-")[0]); + + com.teamcenter.rac.common.Activator + .getDefault() + .openPerspective( + "com.teamcenter.rac.ui.perspectives.navigatorPerspective"); + com.teamcenter.rac.common.Activator + .getDefault() + .openComponents( + "com.teamcenter.rac.ui.perspectives.navigatorPerspective", + new InterfaceAIFComponent[] { item }); + } catch (Exception e2) { + // TODO: handle exception + e2.printStackTrace(); + } + } + } + } + else if (e.getClickCount() > 0) + { + // ѡ + int selectColumn = table.getTableHeader().columnAtPoint(e.getPoint()); + + if(selectColumn != 2) + { + return; + } + + TreePath treePath = table.getPathForLocation(e.getX(),e.getY()); + if (treePath != null) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) treePath.getLastPathComponent(); + NodeBean nodeBean = (NodeBean) node.getUserObject(); + + if(getTopRefresh(node)) + { + MessageBox.post("ϲѹѡͲ㲻ѡ", "", MessageBox.ERROR); + return; + } + + if(getTopProcessRefresh(node)) + { + MessageBox.post("ϲѹѡеͲ㲻ѡ", "", MessageBox.ERROR); + return; + } + + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + NodeBean rootNodeBean = (NodeBean) rootNode.getUserObject(); + + + if(!rootNodeBean.getDbom().equals("") && !getTop(node) && nodeBean.getLabel().equals("0") ) + { + MessageBox.post("ϲδѡ²㲻ѡ", "", MessageBox.ERROR); + return; + } + } + + + try { + TCComponentItemType itemType = (TCComponentItemType) session + .getTypeComponent("Item"); + + if(nodeBean.getLabel().equals("0")) + { + //жͬһǷѹѡ + if(parentNode != null) + { + for (int i = 0; i < parentNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) parentNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && !childBean.getEbom().isEmpty() && !nodeBean.getEbom().isEmpty()) + { + MessageBox.post("ͬһ㼶ֻѡһ", "", MessageBox.ERROR); + return; + } + } + + } + + nodeBean.setLabel("1"); + //isHaveBom(node, nodeBean.getEbomId(), "1", itemType); + } + else if(nodeBean.getLabel().equals("1")) + { + nodeBean.setLabel("0"); + //isHaveBom(node, nodeBean.getEbomId(), "0", itemType); + } + Robot robot = new Robot(); + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + } catch (Exception e2) { + // TODO: handle exception + e2.printStackTrace(); + } + } + } + } + + /*** + * жϼǷѡ + * @param node + * @return + * @throws TCException + */ + private void isHaveBom(DefaultMutableTreeTableNode node,String parentID,String status,TCComponentItemType itemType) throws TCException + { + TCComponentItem item = itemType.find(parentID); + TCComponentItemRevision itemRevision = item.getLatestItemRevision(); + + TCComponent[] tcComponents = itemRevision.getReferenceListProperty("view"); + if(tcComponents.length > 0) + { + for (int ii = 0; ii < node.getParent().getChildCount(); ii++) { + DefaultMutableTreeTableNode tableNode = (DefaultMutableTreeTableNode)node.getParent().getChildAt(ii); + + if(tableNode.getChildCount() > 0) + { + for (int i = 0; i < tcComponents.length; i++) { + TCComponent childBomLine = tcComponents[i]; + List haveItemID = new ArrayList(); + for (int j = 0; j < tableNode.getChildCount(); j++) { + String childItemId = childBomLine.getStringProperty("item_id"); + NodeBean childNodeBean = (NodeBean) tableNode.getChildAt(j).getUserObject(); + if(childItemId.equals(childNodeBean.getEbomId()) && !haveItemID.contains(childNodeBean.getEbomId())) + { + haveItemID.add(childNodeBean.getEbomId()); + childNodeBean.setLabel(status); + isHaveBom((DefaultMutableTreeTableNode)(tableNode.getChildAt(j)), childNodeBean.getEbomId(), status, itemType); + } + } + } + } + } + } + } + + /*** + * жϼǷѡ + * @param node + * @return + */ + private boolean getTop(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && !childBean.getEbom().isEmpty()) + { + //MessageBox.post("ϲ["+childBean.getEbom()+"]ѹѡͲ㲻ѡ", "", MessageBox.ERROR); + return true; + } + } + } + } + + return result; + } + + /*** + * жϼǷѡѷ + * @param node + * @return + */ + private boolean getTopRefresh(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && !childBean.getRefreshStatus().equals("Է") && !childBean.getRefreshStatus().isEmpty()) + { + result = true; + break; + } + else + { + if(getTopRefresh(childNode)) + { + result = true; + break; + } + } + } + } + } + + return result; + } + + /*** + * жϼǷѡж + * @param node + * @return + */ + private boolean getTopProcessRefresh(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && childBean.getRefreshStatus().equals("")) + { + result = true; + break; + } + else + { + if(getTopProcessRefresh(childNode)) + { + result = true; + break; + } + } + } + } + } + + return result; + } + + @Override + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + Object source = e.getSource(); + if (source.equals(this.okButton)) + { + //ȡѡеEBOM + try { + MethodUtil.openByPass(session); + TCComponentItemType itemType = (TCComponentItemType) session + .getTypeComponent("Item"); + this.adaptiveVariants((DefaultMutableTreeTableNode)(this.node.getChildAt(0)), itemType,true); + MethodUtil.closeByPass(session); + MessageBox.post("תɹ", "ɹ", MessageBox.INFORMATION); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + else if(source.equals(this.refreshButton)) + { + this.dispose(); + try { + DbomTransitionToEbomCommand command = new DbomTransitionToEbomCommand(comp,session); + command.executeModal(); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + else + { + this.dispose(); + } + } + + TCComponentBOMLine resultTopline = null; + /** + * ´BOM + * + * @param topItem + * @throws TCException + */ + private void adaptiveVariants(DefaultMutableTreeTableNode tableNode,TCComponentItemType itemType,boolean ifCreate) throws TCException + { + TCComponentItem topItem = null; + //idͬʱ + LinkedHashMap countMap = new LinkedHashMap(); + ArrayList itemList = new ArrayList(); + Map itemNumMap = new HashMap(); + for (int i = 0; i < tableNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) tableNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && !childBean.getEbom().isEmpty()) + { + topItem = itemType.find(childBean.getEbomId()); + for (int j = 0; j < tableNode.getChildCount(); j++) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) tableNode.getChildAt(j); + if(ifCreate) { + NodeBean childBean2 = (NodeBean) node.getUserObject(); + String dbom = childBean2.getDbom(); + if(!dbom.isEmpty()) { + String id = ""; + if(dbom.contains("-")) { + id = dbom.substring(0, dbom.indexOf("-")); + }else { + id = dbom; + } + TCComponentItem createItem = itemType.find(id); + if(childBean2.getLabel().equals("1") && preList.contains(createItem.getType())) { + System.out.println("child id material ===>"+id); + System.out.println("parent id EBOM ===>"+childBean.getEbomId()); + String num = childBean2.getNum(); + if(num == null || num.isEmpty() || num.equals("0")) { + num = "1"; + } + if(countMap.containsKey(createItem.getLatestItemRevision())) { + Integer integer = countMap.get(createItem.getLatestItemRevision()); + countMap.put(createItem.getLatestItemRevision(), Integer.parseInt(num) + integer); + }else { + countMap.put(createItem.getLatestItemRevision(), Integer.parseInt(num)); + } + } + } + } + for (int k = 0; k < node.getChildCount(); k++) { + DefaultMutableTreeTableNode childTableNode = (DefaultMutableTreeTableNode) node.getChildAt(k); + NodeBean childNodeBean = (NodeBean) childTableNode.getUserObject(); + if(childNodeBean.getLabel().equals("1")) + { + TCComponentItem item = null; + if(childNodeBean.getEbomId() == null || childNodeBean.getEbomId().isEmpty()) { + String dbom = childNodeBean.getDbom(); + String id = ""; + if(dbom.contains("-")) { + id = dbom.substring(0, dbom.indexOf("-")); + }else { + id = dbom; + } + item = itemType.find(id); + }else { + item = itemType.find(childNodeBean.getEbomId()); + } + if(preList.contains(item.getType())){ + continue; + } + String num = childNodeBean.getNum(); + if(num == null || num.isEmpty() || num.equals("0")) { + num = "1"; + } + if(countMap.containsKey(item.getLatestItemRevision())) { + Integer integer = countMap.get(item.getLatestItemRevision()); + countMap.put(item.getLatestItemRevision(), Integer.parseInt(num) + integer); + }else { + countMap.put(item.getLatestItemRevision(), Integer.parseInt(num)); + } + itemList.add(item.getLatestItemRevision()); + itemNumMap.put(item.getStringProperty("item_id"), childNodeBean.getNum()); + if(childNodeBean.getRefreshStatus().equals("Է") || childNodeBean.getRefreshStatus().equals("")) + { + adaptiveVariants((DefaultMutableTreeTableNode)(childTableNode.getParent()), itemType,true); + } + } + + } + } + } + } + if(topItem != null) + { + resultTopline = null; + this.recreateBom(topItem.getLatestItemRevision(), itemList, true,countMap); + if(resultTopline != null) + { + resultTopline.lock(); + //BOM + for (int j = 0; j < resultTopline.getChildren().length; j++) { + TCComponentBOMLine bomLine = (TCComponentBOMLine) resultTopline.getChildren()[j].getComponent(); + if(countMap.containsKey(bomLine.getItemRevision())) { + bomLine.setStringProperty("bl_quantity", String.valueOf(countMap.get(bomLine.getItemRevision()))); + } + if(itemNumMap.keySet().contains((bomLine.getStringProperty("bl_item_item_id")))) + { + String quantity = itemNumMap.get(bomLine.getStringProperty("bl_item_item_id")); + if(quantity == null || quantity.isEmpty() || quantity.equals("0")) + { + String uom = ""; + try { + uom = bomLine.getPropertyDisplayableValue("bl_uom"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("λ++++++++++++++++"+uom); + if(uom.equals("ÿ")) + { + continue; + } + quantity = "1.00"; + } + System.out.println("++++++++++++++++"+quantity); + if(quantity.indexOf(".") > 0) + { + Double bomNum = Double.parseDouble(quantity); + bomLine.setStringProperty("bl_quantity", bomNum.toString()); + } + else + { + Integer bomNum = Integer.parseInt(quantity); + bomLine.setStringProperty("bl_quantity", bomNum.toString()); + } + //bomLine.setStringProperty("bl_quantity", itemNumMap.get(bomLine.getStringProperty("bl_item_item_id"))); + } + + } + resultTopline.save(); + resultTopline.unlock(); + resultTopline.refresh(); + if(resultTopline.getBOMView() != null) + { + resultTopline.getBOMView().save(); + resultTopline.getBOMView().refresh(); + } + } + } + } + + /** + * ´BOM + * + * @param item + * @param itemlists + * @throws TCException + */ + public void recreateBom(TCComponentItemRevision topItemRev,ArrayList itemRevisionlists, + boolean isDelete,HashMap countMap) + throws TCException { + TCComponentBOMWindow bomWindow = null; + try { + TCComponentBOMWindowType bomWindowType = (TCComponentBOMWindowType) session + .getTypeComponent("BOMWindow"); + bomWindow = bomWindowType.create(null); + TCComponentBOMLine topline = bomWindow.setWindowTopLine(topItemRev.getItem(), + topItemRev, null, null); + resultTopline = topline; + bomWindow.lock(); + topline.lock(); + if (isDelete) { + if (topline.hasChildren()) { + AIFComponentContext[] childrens = topline.getChildren(); + for (AIFComponentContext children : childrens) { + ((TCComponentBOMLine) children.getComponent()).cut(); + } + } + } +// for (TCComponentItemRevision n_itemRevision : itemRevisionlists) { +// if(n_itemRevision != null) +// { +// boolean isHave = false; +// if(!isDelete) +// { +// for (AIFComponentContext children : topline.getChildren()) { +// if(n_itemRevision.getStringProperty("item_id").compareTo(children.getComponent().getProperty("bl_child_id")) == 0) +// { +// isHave = true; +// } +// } +// } +// if(!isHave) +// { +// topline.add(n_itemRevision.getItem(), n_itemRevision, null, false, ""); +// } +// } +// } + Set> entrySet = countMap.entrySet(); + for (Entry entry : entrySet) { + topline.add(entry.getKey().getItem(), entry.getKey(), null, false, ""); + } + topline.save(); + topline.unlock(); + topline.refresh(); + if(topline.getBOMView() != null) + { + topline.getBOMView().save(); + topline.getBOMView().refresh(); + } + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + bomWindow.save(); + bomWindow.unlock(); + bomWindow.refresh(); + } + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomHandler.java b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomHandler.java new file mode 100644 index 0000000..06ca031 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/DbomTransitionToEbomHandler.java @@ -0,0 +1,30 @@ +package com.connor.tcm.outfile.dbom2ebom; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; + + +public class DbomTransitionToEbomHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + try { + DbomTransitionToEbomCommand command = new DbomTransitionToEbomCommand(app.getTargetComponent(),session); + command.executeModal(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/JTreeTable.java b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/JTreeTable.java new file mode 100644 index 0000000..d9a9119 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/JTreeTable.java @@ -0,0 +1,85 @@ +package com.connor.tcm.outfile.dbom2ebom; + +import java.awt.event.MouseEvent; +import java.util.List; + +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; + +import org.jdesktop.swingx.JXTreeTable; + +public class JTreeTable extends JXTreeTable { + + + private List isNotEditableRow; + //CheckBoxCellEditor checkBoxCellEditor = new CheckBoxCellEditor(this); + TableCellCheckboxRenderer checkboxRenderer = new TableCellCheckboxRenderer(this); + + public List getIsNotEditableRow() { + return isNotEditableRow; + } + + public void setIsNotEditableRow(List isNotEditableRow) { + this.isNotEditableRow = isNotEditableRow; + } + + public JTreeTable(JTreeTableModel testTreeTableModel) { + // TODO Auto-generated constructor stub + super(testTreeTableModel); + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + // TODO Auto-generated method stub + return true;//super.isCellEditable(arg0, arg1); + } + + @Override + public TableCellEditor getCellEditor(int row, int column) { + // TODO Auto-generated method stub + //if(isNotEditableRow.contains(row) && column == 2) + + + return cellEditor; + //return super.getCellEditor(row, column); + } + + public String getToolTipText(MouseEvent e) { + int row = this.rowAtPoint(e.getPoint()); + int col = this.columnAtPoint(e.getPoint()); + String tiptextString = null; + if (row > -1 && col > -1) { + Object value = this.getValueAt(row, col); + if (null != value && !"".equals(value)) + tiptextString = value.toString();// ʾԪ + } + return tiptextString; + } + + @Override + public TableCellRenderer getCellRenderer(int row, int column) { + // TODO Auto-generated method stub + if(this.getValueAt(row, 2) != null && (this.getValueAt(row, 2).toString().equals("0") || this.getValueAt(row, 2).toString().equals("1")) && column == 2) + { + return checkboxRenderer; + } + else + { + return super.getCellRenderer(row, column); + } + } + + // + public void HiddenCell(int column) { + TableColumn tc = this.getTableHeader().getColumnModel() + .getColumn(column); + tc.setMaxWidth(0); + tc.setPreferredWidth(0); + tc.setWidth(0); + tc.setMinWidth(0); + this.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0); + this.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0); + } + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/JTreeTableModel.java b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/JTreeTableModel.java new file mode 100644 index 0000000..e9055bd --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/JTreeTableModel.java @@ -0,0 +1,119 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.connor.tcm.outfile.dbom2ebom; + +import java.util.List; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; +import org.jdesktop.swingx.treetable.DefaultTreeTableModel; +import org.jdesktop.swingx.treetable.TreeTableNode; + +import com.connor.tcm.outfile.bean.NodeBean; + +/** + * + * @author vearn + */ +public class JTreeTableModel extends DefaultTreeTableModel { + + private String[] _names = { "DBOM", "EBOM","ѡ", "EBOMID", "","","״̬","Ӧڵ"}; + + + private List isNotEditableRow; + + + + public JTreeTableModel(TreeTableNode node) { + super(node); + } + + + public List getIsNotEditableRow() { + return isNotEditableRow; + } + + public void setIsNotEditableRow(List isNotEditableRow) { + this.isNotEditableRow = isNotEditableRow; + } + + /** + * е + */ + @Override + public int getColumnCount() { + return _names.length; + } + + /** + * ͷʾ + */ + @Override + public String getColumnName(int column) { + return _names[column]; + } + + /** + * ڵԪʾObject + */ + @Override + public Object getValueAt(Object node, int column) { + Object value = null; + if (node instanceof DefaultMutableTreeTableNode) { + DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node; + Object o = mutableNode.getUserObject(); + if (o != null && o instanceof NodeBean) { + NodeBean bean = (NodeBean) o; + switch (column) { + case 0: + value = bean.getDbom(); + break; + case 1: + value = bean.getEbom(); + break; + case 2: + value = bean.getLabel(); + break; + case 3: + value = bean.getEbomId(); + break; + case 4: + value = bean.getEbomDesc(); + break; + case 5: + value = bean.getNum(); + break; + case 6: + value = bean.getRefreshStatus(); + break; + case 7: + value = bean.getParentString(); + break; + } + } + } + return value; + } + + /** + * еԪ񶼲ܱ༭ + * + * @param the node (i.e. row) for which editing is to be determined + * @param the column for which editing is to be determined + * @return false + */ + @Override + public boolean isCellEditable(Object node, int column) { + //if(column == 5) + //{ + return true; + //} + //else + //{ + // return false; + //} + } + + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/TableCellCheckboxRenderer.java b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/TableCellCheckboxRenderer.java new file mode 100644 index 0000000..9ea500a --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/TableCellCheckboxRenderer.java @@ -0,0 +1,71 @@ +package com.connor.tcm.outfile.dbom2ebom; + +import java.awt.Component; +import java.util.List; + +import javax.swing.JCheckBox; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.EventListenerList; +import javax.swing.table.TableCellRenderer; + + +public class TableCellCheckboxRenderer extends JCheckBox implements + TableCellRenderer { + private List processRows; + protected EventListenerList listenerList = new EventListenerList(); + protected ChangeEvent changeEvent = new ChangeEvent(this); + //private TestTreeTableModel tableModel; + + public List getProcessRows() { + return processRows; + } + + public void setProcessRows(List processRows) { + this.processRows = processRows; + + } + + public TableCellCheckboxRenderer(final JTreeTable table) { + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + // TODO Auto-generated method stub + this.setHorizontalAlignment(SwingConstants.CENTER);// ͷǩ + this.setBorderPainted(true); + + if(value != null) + { +// if(value.toString().equals("1")) +// { +// if(table.getColumnName(column).equals("") && hasFocus) +// { +// if(table.getValueAt(row, column + 1).toString().equals("1")) +// { +// table.setValueAt(0, row, column + 1); +// } +// } +// else if(table.getColumnName(column).equals("ɾ") && hasFocus) +// { +// if(table.getValueAt(row, column - 1).toString().equals("1")) +// { +// table.setValueAt(0, row, column - 1); +// } +// } +// } +// if(value.toString().equals("1")) +// { +// System.out.println(value.toString().equals("1") + "===="); +// } + this.setSelected(value.toString().equals("1")); + } + else + { + this.setSelected(false); + } + return this; + } +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/Test.java b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/Test.java new file mode 100644 index 0000000..ca890f8 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/dbom2ebom/Test.java @@ -0,0 +1,8 @@ +package com.connor.tcm.outfile.dbom2ebom; + +public class Test { + public static void main(String[] args) { + String s = "11111112-32222222-4444"; + System.out.println(s.substring(0, s.indexOf("-"))); + } +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/projectFolder/ProjectFolderDialog.java b/com.connor.process/src/com/connor/tcm/outfile/projectFolder/ProjectFolderDialog.java new file mode 100644 index 0000000..eb34f3a --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/projectFolder/ProjectFolderDialog.java @@ -0,0 +1,342 @@ +package com.connor.tcm.outfile.projectFolder; + +import javax.swing.*; + +import com.connor.tcm.outfile.util.MethodUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.ServiceData; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentFolderType; +import com.teamcenter.rac.kernel.TCComponentProject; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class ProjectFolderDialog extends JFrame { + + // UI + private JLabel leftLabel; + private JList leftList; + private JLabel rightLabel; + private JList rightList; + private JTextField newFolderName; + private JButton startButton; + private JButton cancelButton; + private static TCSession session; + private AbstractAIFApplication app; + private LinkedHashMap folderUidMap = new LinkedHashMap(); + private LinkedHashMap projectMap = new LinkedHashMap(); + public ProjectFolderDialog(TCSession session,AbstractAIFApplication app) throws Exception { + this.session = session; + this.app = app; + setTitle("Ŀϼ"); + setSize(800, 500); // Ŵ󴰿 + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setLocationRelativeTo(null); // ʾ + + initUI(); + } + + private void initUI() throws Exception { + setLayout(new BorderLayout()); + + String[] folderUid = session.getPreferenceService().getStringValues("LB_ProjectFolder_template"); + for (int i = 0; i < folderUid.length; i++) { + String[] split = folderUid[i].split("="); + TCComponent uidComponent = session.stringToComponent(split[1]); + if(uidComponent instanceof TCComponentFolder) { + folderUidMap.put(split[0], (TCComponentFolder)uidComponent); + } + } + + if(folderUidMap.size() == 0) { + MessageBox.post("ȷ LB_ProjectFolder_template ѡ", "ʾ ", MessageBox.INFORMATION); + return; + } + + System.out.println("folderUidMap=="+folderUidMap.toString()); + String userId = session.getUser().getUserId(); + TCComponent[] search = session.search("ûĿ", new String[] { "ID" }, new String[] { userId }); + System.out.println("search====="+search.length); + for (int i = 0; i < search.length; i++) { + if(search[i] instanceof TCComponentProject) { + TCComponentProject project = (TCComponentProject)search[i]; + projectMap.put(project.getStringProperty("object_string"), project); + } + } + if(projectMap.size() == 0) { + MessageBox.post("ûδѯĿ", "ʾ ", MessageBox.INFORMATION); + return; + } + + // 壺вţ޿϶ + JPanel topPanel = new JPanel(new GridLayout(1, 2)); + //topPanel.setBorder(BorderFactory.createTitledBorder("ѡҪƵļ")); + + // + JPanel leftPanel = new JPanel(new BorderLayout()); + leftLabel = new JLabel("Ŀļ"); + leftLabel.setFont(new Font("", Font.PLAIN, 12)); + leftPanel.add(leftLabel, BorderLayout.NORTH); + + + DefaultListModel leftModel = new DefaultListModel<>(); + + for (Entry tcComponent : folderUidMap.entrySet()) { + leftModel.addElement(tcComponent.getKey()); + } + + + leftList = new JList<>(leftModel); + leftList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + leftList.setSelectedIndex(0); + leftList.setBackground(Color.WHITE); + leftList.setSelectionBackground(Color.BLUE); + leftList.setSelectionForeground(Color.WHITE); + leftPanel.add(new JScrollPane(leftList), BorderLayout.CENTER); + + // Ҳ + JPanel rightPanel = new JPanel(new BorderLayout()); + rightLabel = new JLabel("ָĿ"); + rightLabel.setFont(new Font("", Font.PLAIN, 12)); + rightPanel.add(rightLabel, BorderLayout.NORTH); + + + DefaultListModel rightModel = new DefaultListModel<>(); + for (Entry tcComponent : projectMap.entrySet()) { + rightModel.addElement(tcComponent.getKey()); + } + rightList = new JList<>(rightModel); + rightList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + rightList.setSelectedIndex(5); // Ĭѡ "PRO-00001-Ŀ1" + rightList.setBackground(Color.WHITE); + rightList.setSelectionBackground(Color.BLUE); + rightList.setSelectionForeground(Color.WHITE); + rightPanel.add(new JScrollPane(rightList), BorderLayout.CENTER); + + topPanel.add(leftPanel); + topPanel.add(rightPanel); + + add(topPanel, BorderLayout.CENTER); // ģ¿հ + + // ײͰť + JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + bottomPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + JLabel nameLabel = new JLabel(" ´ļ:"); + newFolderName = new JTextField(""); + newFolderName.setPreferredSize(new Dimension(350, 25)); + + startButton = new JButton("ʼ"); + cancelButton = new JButton("ȡ "); + + bottomPanel.add(nameLabel); + bottomPanel.add(newFolderName); + bottomPanel.add(startButton); + bottomPanel.add(cancelButton); + + add(bottomPanel, BorderLayout.SOUTH); + + // ¼ + startButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String selectedProject = rightList.getSelectedValue(); + if (selectedProject == null) { + MessageBox.post("ѡһĿĿ", "ʾ ", MessageBox.INFORMATION); + return; + } + + + String selectedFolder = leftList.getSelectedValue(); + if (selectedFolder == null) { + MessageBox.post("ѡһĿļ", "ʾ ", MessageBox.INFORMATION); + return; + } + + + + TCComponentFolder tcComponentFolder = folderUidMap.get(selectedFolder); + //TCComponentFolderType topComponentFolderType = tcComponentFolder.getTypeComponent(); + try { + MethodUtil.openByPass(session); + TCComponentFolder lastTopParentFolder = null; + String text = newFolderName.getText(); + if(text != null && !text.isEmpty()) { + lastTopParentFolder = tcComponentFolder.saveAs(text); + }else { + lastTopParentFolder = tcComponentFolder.saveAs(tcComponentFolder.getStringProperty("object_name")); + } + + TCComponent[] relateds = lastTopParentFolder.getRelatedComponents("contents"); + lastTopParentFolder.cutOperation("contents", relateds); + lastTopParentFolder.refresh(); + + + //TCComponentFolder lastTopParentFolder = createFolderBySOA(topComponentFolderType.getTypeName(), tcComponentFolder.getStringProperty("object_name")); + createFolderStruct(tcComponentFolder,lastTopParentFolder,true); + TCComponentProject tcComponentProject = projectMap.get(selectedProject); + System.out.println("lastTopParentFolder==="+lastTopParentFolder.getUid()); + + + + + tcComponentProject.assignToProject(new TCComponent[] {lastTopParentFolder}); + + InterfaceAIFComponent targetComponent = app.getTargetComponent(); + if(targetComponent instanceof TCComponentFolder) { + ((TCComponentFolder) targetComponent).add("contents", lastTopParentFolder); + } + + MethodUtil.closeByPass(session); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }finally { + try { + MethodUtil.closeByPass(session); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + + + + MessageBox.post("ɹ", "ʾ ", MessageBox.INFORMATION); + dispose(); // رմ + } + }); + + cancelButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); // رմ + } + }); + } + + private void createFolderStruct(TCComponentFolder childFolder,TCComponentFolder parentFolder,boolean ifTop) throws Exception { + AIFComponentContext[] children = childFolder.getChildren(); + if(ifTop) { + for (int i = 0; i < children.length; i++) { + InterfaceAIFComponent component = children[i].getComponent(); + if(component instanceof TCComponentFolder) { + TCComponentFolder childTcComponentFolder = (TCComponentFolder)component; + createFolderStruct(childTcComponentFolder,parentFolder,false); + } + + } + } + else { + TCComponentFolder folder = childFolder.saveAs(childFolder.getStringProperty("object_name")); + TCComponent[] relateds = folder.getRelatedComponents("contents"); + folder.cutOperation("contents", relateds); + folder.refresh(); + parentFolder.add("contents", folder); + for (int i = 0; i < children.length; i++) { + InterfaceAIFComponent component = children[i].getComponent(); + if(component instanceof TCComponentFolder) { + TCComponentFolder childTcComponentFolder = (TCComponentFolder)component; + createFolderStruct(childTcComponentFolder,folder,false); + } + + } + } + + } +// private void createFolderStruct(TCComponentFolder childFolder,TCComponentFolder parentFolder, +// TCComponentFolderType folderType,boolean ifTop) throws Exception { +// AIFComponentContext[] children = childFolder.getChildren(); +// if(ifTop) { +// for (int i = 0; i < parentFolder.getChildrenCount(); i++) { +// InterfaceAIFComponent component = children[i].getComponent(); +// if(component instanceof TCComponentFolder) { +// TCComponentFolder childTcComponentFolder = (TCComponentFolder)component; +// TCComponentFolderType typeComponent = childTcComponentFolder.getTypeComponent(); +// createFolderStruct(childTcComponentFolder,parentFolder,typeComponent,false); +// } +// +// } +// } +// else { +// TCComponentFolder folder = createFolderBySOA(folderType.getTypeName(), childFolder.getStringProperty("object_name")); +// parentFolder.add("contents", folder); +// for (int i = 0; i < childFolder.getChildrenCount(); i++) { +// InterfaceAIFComponent component = children[i].getComponent(); +// if(component instanceof TCComponentFolder) { +// TCComponentFolder childTcComponentFolder = (TCComponentFolder)component; +// TCComponentFolderType typeComponent = childTcComponentFolder.getTypeComponent(); +// createFolderStruct(childTcComponentFolder,folder,typeComponent,false); +// } +// +// } +// } +// +// } + + + public static TCComponentFolder createFolderBySOA(String folderTypeName, String folderName) throws Exception { + if (folderTypeName.isEmpty()) { + return null; + } + CreateInput itemInput = new CreateInput(); + itemInput.boName = folderTypeName; + Map itemPropMap = new HashMap<>(); + itemPropMap.put("object_name", folderName); + itemInput.stringProps = itemPropMap; + // create info + CreateIn cI = new CreateIn(); + cI.clientId = "CreateFolder"; + cI.data = itemInput; + // service + DataManagementService service = DataManagementService.getService(session); + // create + CreateResponse resp = service.createObjects(new CreateIn[] { cI }); + throwServiceDataError(resp.serviceData); + CreateOut[] cOs = resp.output; + if (cOs.length > 0) { + for (TCComponent s : cOs[0].objects) { + if (s instanceof TCComponentFolder) { + return (TCComponentFolder) s; + } + } + } + return null; + } + + + public static void throwServiceDataError(ServiceData serviceData) throws Exception { + if (serviceData.sizeOfPartialErrors() > 0) { + StringBuilder errInfo = new StringBuilder(); + for (int i = 0; i < serviceData.sizeOfPartialErrors(); i++) { + for (String msg : serviceData.getPartialError(i).getMessages()) { + errInfo.append(msg + "\n"); + } + } + // System.out.println(errInfo.toString()); + throw new Exception(errInfo.toString()); + } + } + + + public static void main(String[] args) { + + } +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/projectFolder/ProjectFolderHandler.java b/com.connor.process/src/com/connor/tcm/outfile/projectFolder/ProjectFolderHandler.java new file mode 100644 index 0000000..16bb318 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/projectFolder/ProjectFolderHandler.java @@ -0,0 +1,29 @@ +package com.connor.tcm.outfile.projectFolder; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; + + +public class ProjectFolderHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + try { + new ProjectFolderDialog(session,app).setVisible(true); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + +} diff --git a/com.connor.process/src/com/connor/tcm/outfile/util/Adapter.java b/com.connor.process/src/com/connor/tcm/outfile/util/Adapter.java new file mode 100644 index 0000000..d6aa02e --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/util/Adapter.java @@ -0,0 +1,299 @@ +package com.connor.tcm.outfile.util; + +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.KeyStroke; + +/** + * Adapter ʵ JTables еĸճ 幦ܡ õļݸʽ Excel õļʽݡṩ + * ֵ֧ JTables Excel Ļ + */ +public class Adapter implements ActionListener { + private String rowstring, value; + private Clipboard system; + private StringSelection stsel; + private JTable jTable1; + private List> selectValue = new ArrayList>(); + + /** + * Excel JTable ɣ ʵ JTable ϵĸճ ܣ䵱 + */ + + public Adapter(JTable myJTable) { + jTable1 = myJTable; + KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, + ActionEvent.CTRL_MASK, false); + + // ȷưûԶ޸ + // ʵϵĸƹܡ + KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, + ActionEvent.CTRL_MASK, false); + + // ȷճûԶ޸ + // ʵϵĸƹܡ + + jTable1.registerKeyboardAction(this, "Copy", copy, + JComponent.WHEN_FOCUSED); + + jTable1.registerKeyboardAction(this, "Paste", paste, + JComponent.WHEN_FOCUSED); + + system = Toolkit.getDefaultToolkit().getSystemClipboard(); + } + + /** + * ͼĹ + */ + public JTable getJTable() { + return jTable1; + } + + public void setJTable(JTable jTable1) { + this.jTable1 = jTable1; + } + + /** + * Ǽʵֵİϼַ ˴ƺճ ActionCommands ڵԪѡѡЧ + * Ҵ˺ƶ޷ִС ճķǽѡݵϽ JTable ĵǰѡݵĵһԪض롣 + */ + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().compareTo("Copy") == 0) { + StringBuffer sbf = new StringBuffer(); + + selectValue.clear(); + // ȷǽѡ˵Ԫ + // ڿ + int numcols = jTable1.getSelectedColumnCount(); + int numrows = jTable1.getSelectedRowCount(); + int[] rowsselected = jTable1.getSelectedRows(); + int[] colsselected = jTable1.getSelectedColumns(); + +// if (!((numrows - 1 == rowsselected[rowsselected.length - 1] +// - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1] +// - colsselected[0] && numcols == colsselected.length))) { +// JOptionPane.showMessageDialog(null, "Invalid Copy Selection", +// "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE); +// +// return; +// } + + for (int i=0;i= 0) + { + sbf.append("\""); + sbf.append(jTable1.getValueAt(rowsselected[i],colsselected[j])); + sbf.append("\""); + } + else if(jTable1.getValueAt(rowsselected[i],colsselected[j]) == null) + { + sbf.append(""); + } + else + { + sbf.append(jTable1.getValueAt(rowsselected[i],colsselected[j])); + } + if (j= 0) + { + sb.append(values[i].replace("\n", " $")); + } + else + { + sb.append(values[i]); + } + //System.out.println(i+s[i]); + } + System.out.println("sb======"+sb.toString()); + String copyValue = sb.toString(); + String[] st1=copyValue.split("\\$"); //new StringTokenizer(sb.toString(),"$".toString()); + + + + int[] rows = jTable1.getSelectedRows(); + int[] columns = jTable1.getSelectedColumns(); + int startRow = rows[0]; + int startCol = columns[0]; + if(rows.length ==1 ) + { + for(int i=0;i= 0) + { + String[] cellValue = rowstring.split("\t"); + for(int j=0;j= 0) + { + String[] cellValue = rowstring.split("\t"); + for (int k = 0; k < cellValue.length; k++) { + value=(String)cellValue[k]; + System.out.println("value============"+value); + jTable1.setValueAt(value.trim(),rows[i],startCol+k); + System.out.println("Putting "+ value+"atrow="+startRow+i+"column="+startCol+k); + } + } + else + { + jTable1.setValueAt(rowstring.trim(),rows[i],startCol); + } + //} + //} + } + } + else //дѡ + { + for(int i=0;i= 0) + { + String[] cellValue = rowstring.split("\t"); + for(int j=0;j st1.length) + { + for (int i = 0; i < rows.length; i++) { + for (int j = 0; j < columns.length; j++) { + rowstring=st1[(i+st1.length)%st1.length]; + System.out.println("rowstring============"+rowstring); + if(rowstring.indexOf("\t") >= 0) + { + String[] cellValue = rowstring.split("\t"); + for (int k = 0; k < cellValue.length; k++) { + value=(String)cellValue[(j+cellValue.length)%cellValue.length]; + System.out.println("value============"+value); + jTable1.setValueAt(value.trim(),rows[i],columns[j]); + System.out.println("Putting "+ value+"atrow="+startRow+i+"column="+startCol+k); + } + } + else + { + jTable1.setValueAt(rowstring.trim(),rows[i],columns[j]); + } + } + } + } + else + { + for (int i = 0; i < st1.length; i++) { + for (int j = 0; j < columns.length; j++) { + rowstring=st1[(i+st1.length)%st1.length]; + System.out.println("rowstring============"+rowstring); + if(rowstring.indexOf("\t") >= 0) + { + String[] cellValue = rowstring.split("\t"); + for (int k = 0; k < cellValue.length; k++) { + value=(String)cellValue[(j+cellValue.length)%cellValue.length]; + System.out.println("value============"+value); + jTable1.setValueAt(value.trim(),startRow+i,columns[j]); + System.out.println("Putting "+ value+"atrow="+startRow+i+"column="+startCol+k); + } + } + else + { + jTable1.setValueAt(rowstring.trim(),startRow+i,columns[j]); + } + } + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + } + } +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/util/JAutoCompleteComboBox.java b/com.connor.process/src/com/connor/tcm/outfile/util/JAutoCompleteComboBox.java new file mode 100644 index 0000000..9ceef68 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/util/JAutoCompleteComboBox.java @@ -0,0 +1,171 @@ +package com.connor.tcm.outfile.util; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.List; +import java.util.Vector; + +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JTextField; + +@SuppressWarnings({ "serial", "rawtypes", "unchecked" }) +public class JAutoCompleteComboBox extends JComboBox { + private AutoCompleter completer; + private String propName; + + public JAutoCompleteComboBox() { + super(); + addCompleter(); + } + + public JAutoCompleteComboBox(ComboBoxModel cm) { + super(cm); + addCompleter(); + } + + public JAutoCompleteComboBox(Object[] items) { + super(items); + addCompleter(); + } + + public JAutoCompleteComboBox(List v) { + super((Vector) v); + addCompleter(); + } + + + + public String getPropName() { + return propName; + } + + public void setPropName(String propName) { + this.propName = propName; + } + + private void addCompleter() { + setEditable(true); + completer = new AutoCompleter(this); + } + + public void autoComplete(String str) { + this.completer.autoComplete(str, str.length()); + } + + public String getText() { + return ((JTextField) getEditor().getEditorComponent()).getText(); + } + + public void setText(String text) { + ((JTextField) getEditor().getEditorComponent()).setText(text); + } + + public boolean containsItem(String itemString) { + for (int i = 0; i < this.getModel().getSize(); i++) { + String _item = " " + this.getModel().getElementAt(i); + if (_item.equals(itemString)) + return true; + } + return false; + } + +} + +@SuppressWarnings({"rawtypes"}) +class AutoCompleter implements KeyListener, ItemListener { + + private JComboBox owner = null; + private JTextField editor = null; + + private ComboBoxModel model = null; + + public AutoCompleter(JComboBox comboBox) { + owner = comboBox; + editor = (JTextField) comboBox.getEditor().getEditorComponent(); + editor.addKeyListener(this); + model = comboBox.getModel(); + owner.addItemListener(this); + } + + public void keyTyped(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + } + + @SuppressWarnings("unused") + public void keyReleased(KeyEvent e) { + char ch = e.getKeyChar(); + // if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch) + // || ch == KeyEvent.VK_DELETE) + // return; + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + int caretPosition = editor.getCaretPosition(); + String str = editor.getText(); + if (str.length() == 0) + return; + autoComplete(str, caretPosition); + } + } + + @SuppressWarnings({ "unchecked", "unused" }) + protected void autoComplete(String strf, int caretPosition) { + Object[] opts; + opts = getMatchingOptions(strf.substring(0, caretPosition)); + if (owner != null) { + model = new DefaultComboBoxModel(opts); + owner.setModel(model); + } + if (opts.length > 0) { + String str = opts[0].toString(); + editor.setCaretPosition(caretPosition); + if (owner != null) { + try { + owner.showPopup(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } + + @SuppressWarnings("unchecked") + protected Object[] getMatchingOptions(String str) { + List v = new Vector(); + List v1 = new Vector(); + // v.add(str); + for (int k = 0; k < model.getSize(); k++) { + Object itemObj = model.getElementAt(k); + if (itemObj != null) { + String item = itemObj.toString().toLowerCase(); + if (item.indexOf((str.toLowerCase())) > -1) + v.add(model.getElementAt(k)); + else + v1.add(model.getElementAt(k)); + } else + v1.add(model.getElementAt(k)); + } + for (int i = 0; i < v1.size(); i++) { + v.add(v1.get(i)); + } + // if (v.isEmpty()) + return v.toArray(); + } + + public void itemStateChanged(ItemEvent event) { + if (event.getStateChange() == ItemEvent.SELECTED) { + int caretPosition = editor.getCaretPosition(); + if (caretPosition != -1) { + try { + editor.moveCaretPosition(caretPosition); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/com.connor.process/src/com/connor/tcm/outfile/util/MethodUtil.java b/com.connor.process/src/com/connor/tcm/outfile/util/MethodUtil.java new file mode 100644 index 0000000..f67ff10 --- /dev/null +++ b/com.connor.process/src/com/connor/tcm/outfile/util/MethodUtil.java @@ -0,0 +1,868 @@ +package com.connor.tcm.outfile.util; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +import javax.swing.JOptionPane; + + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCClassificationService; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentProcess; +import com.teamcenter.rac.kernel.TCComponentProcessType; +import com.teamcenter.rac.kernel.TCComponentTaskTemplate; +import com.teamcenter.rac.kernel.TCComponentTaskTemplateType; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.kernel.ics.ICSKeyLov; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.kernel.ics.ICSPropertyDescription; +import com.teamcenter.rac.kernel.ics.ICSSearchResult; +import com.teamcenter.rac.util.MessageBox; +//import com.teamcenter.services.rac.core.DataManagementService; + +//import net.sf.json.JSONArray; +//import net.sf.json.JSONObject; + +public class MethodUtil { + + private static final String SEP1 = ","; + + /** + * ͬBOM + * + * @param session session + * @param process ̶ + * @param processUser ڵ㸺ѡֵ + * @param arctic + * @throws TCException + */ + public static void sendBom(TCSession session, TCComponentItemRevision itemRevision) throws TCException { + + TCUserService userservice = session.getUserService(); + + Object[] obj = new Object[1]; + obj[0] = itemRevision; + userservice.call("Super_Bom_Appent_Data", obj); + } + + /** + * ݹȡID + * + * @param oldItemID ɵID + * @return µID + */ + public static String getRuleItemID(TCSession session, String oldItemID) { + // String[] oldItemIDs = oldItemID.split("-"); + DecimalFormat df = new DecimalFormat("000"); + // String newID = oldItemIDs[0] + "-" + oldItemIDs[1] + "-001"; + String newID = oldItemID + "-001"; + // String idTemp = + TCComponentItemType tccomponentitemtype; + try { + tccomponentitemtype = (TCComponentItemType) (session.getTypeComponent("Item")); + + tccomponentitemtype.getNewID(); + int i = 1; + while (tccomponentitemtype.find(newID) != null) { + i++; + // newID = oldItemIDs[0] + "-" + oldItemIDs[1] + "-"+ df.format(i); + newID = oldItemID + "-" + df.format(i); + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return newID; + } + + /** + * ListתString + * + * @param list :ҪתList + * @return Stringתַ + */ + public static String ListToString(List list) { + + StringBuffer sb = new StringBuffer(); + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i) == null || list.get(i) == "") { + continue; + } + // ֵlistԼ + if (list.get(i) instanceof List) { + sb.append(ListToString((List) list.get(i))); + sb.append(SEP1); + } else { + sb.append(list.get(i)); + sb.append(SEP1); + } + } + } + return sb.toString(); + } + +// // ȡlovֵ +// public static String getGroupLov(TCSession session, String lovName, String key) { +// try { +// // ȡlov +// TCComponentListOfValues rtlistOfValues = TCLOVUtil.findLOVByName(session, "TM2_GROUP"); +// ListOfValuesInfo rtlistOfValuesInfo = rtlistOfValues.getListOfValues(); +// String[] groupName = rtlistOfValuesInfo.getStringListOfValues(); +// String[] groupDisplayName = rtlistOfValuesInfo.getLOVDisplayValues(); +// for (int i = 0; i < groupName.length; i++) { +// if (groupName[i].equals(key)) { +// return groupDisplayName[i]; +// } +// +// } +// } catch (TCException e) { +// MessageBox.post("ȡLOVϵϵͳԱ", "", MessageBox.ERROR); +// e.printStackTrace(); +// } +// return ""; +// } + + /** + * ȡģļ + * @param session session + * @param fileName ļ + * @param Filetype ļ + * @return + */ + public static File getFile(TCSession session,String fileName,String Filetype) { + // TODO Auto-generated method stub + try { + TCPreferenceService service = session.getPreferenceService(); + String[] modelFiles = service.getStringValues("ML_Doc_Teamplate"); + if (modelFiles == null) + { + System.out.println("δҵѡ"); + return null; + } + String itemId = ""; + for (int i = 0; i < modelFiles.length; i++) { + if(modelFiles[i].split(":")[0].equals(fileName)) + { + itemId = modelFiles[i].split(":")[1]; + } + } + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent("Item"); + TCComponentItem fileItem = itemType.find(itemId); + TCComponentDataset dat = null; + TCComponentItemRevision fileItemLastRev = getLastItemRevision(fileItem); + TCComponent[] comps = fileItemLastRev.getReferenceListProperty("IMAN_specification"); + System.out.println("count =" + comps == null ? "null" + : comps.length); + // TC_Attachesϵµж + for (TCComponent compt : comps) { + // ȡ + String type = compt.getType(); + System.out.println(" TYPE = " + type); + // ж + if (type.equals(type)) { + dat = (TCComponentDataset)compt; + } + } + TCComponentTcFile[] tcFile = dat.getTcFiles(); + if(tcFile != null && tcFile.length == 0) + { + System.out.println("δҵļ"); + } + else + { + return tcFile[0].getFmsFile(); + } + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + return null; + } + + /** + * ȡµѷİ汾 + * + * @param item + * @return + */ + public static TCComponentItemRevision getLastItemRevision(TCComponentItem item) { + // TODO Auto-generated method stub + try { + TCComponentItemRevision[] items = item.getReleasedItemRevisions(); + int revId = 0; + TCComponentItemRevision itemRevision = null; + for (int i = 0; i < items.length; i++) { + String revisionId = items[i].getStringProperty("item_revision_id"); + if (letterToNumber(revisionId) >= revId) { + itemRevision = items[i]; + revId = letterToNumber(revisionId); + } + } + return itemRevision; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + // ĸת A-Z 1-26 + public static int letterToNumber(String letter) { + int length = letter.length(); + int num = 0; + int number = 0; + for (int i = 0; i < length; i++) { + char ch = letter.charAt(length - i - 1); + num = (int) (ch - 'A' + 1); + num *= Math.pow(26, i); + number += num; + } + return number; + } + + /** + * LOVƻȡLOV + * + * @param tcsession + * @param s + * @return + */ + + + /** + * LOV KeyȡLOVֵ + * + * @param tcsession + * @param s + * @return + */ + public static String findLovValueByKey(TCSession tcsession, String s, String key) { + TCComponentListOfValues tccomponentlistofvalues = null; + String resultValue = null; + try { + TCComponentListOfValuesType tccomponentlistofvaluestype = (TCComponentListOfValuesType) tcsession + .getTypeComponent("ListOfValues"); + TCComponentListOfValues atccomponentlistofvalues[] = tccomponentlistofvaluestype.find(s); + if (atccomponentlistofvalues != null && atccomponentlistofvalues.length > 0) { + tccomponentlistofvalues = atccomponentlistofvalues[0]; + + ListOfValuesInfo rtlistOfValuesInfo = tccomponentlistofvalues.getListOfValues(); + + String[] groupName = rtlistOfValuesInfo.getStringListOfValues(); + String[] groupDisplayName = rtlistOfValuesInfo.getLOVDisplayValues(); + + for (int i = 0; i < groupName.length; i++) { + // resultMap.put(groupDisplayName[i],groupName[i]); + if (groupName[i].equals(key)) { + resultValue = groupDisplayName[i]; + } + } + } + } catch (TCException tcexception) { + tccomponentlistofvalues = null; + } + return resultValue; + } + + /** + * ̸ָ + * + * @param session session + * @param process ̶ + * @param processUser ڵ㸺ѡֵ + * @param arctic + * @throws TCException + */ + public static void setProcess(TCSession session, TCComponentProcess process, String processUser, String arctic) + throws TCException { + + TCUserService userservice = session.getUserService(); + + Object[] obj = new Object[3]; + obj[0] = process; + obj[1] = processUser; + obj[2] = arctic; + userservice.call("DMU_Review_Process", obj); + } + + /** + * ָӦԸ̸ + * + * @param session session + * @param process ̶ + * @param processUser ڵ㸺 + * @param arctic + * @throws TCException + */ + public static void setRemodelProcess(TCSession session, TCComponentProcess process, String processUser, + String arctic) throws TCException { + + TCUserService userservice = session.getUserService(); + + Object[] obj = new Object[3]; + obj[0] = process; + obj[1] = processUser; + obj[2] = arctic; + userservice.call("Create_Remodel_Process", obj); + } + + /** + * ȡֵѡ + * + * @param prefName + * @return + */ + public static String getPrefStr(String prefName) { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCPreferenceService service = session.getPreferenceService(); + String str = service.getString(TCPreferenceService.TC_preference_site, prefName); + if (str == null) { + str = new String(""); + } + return str; + } + + /*** + * ȡѡ + * + * @param session Ự + * @param preferenceName ѡ + * @return + */ + public static String[] getPreferenceValues(String preferenceName) { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + if (preferenceName == null || session == null) { + System.out.println(""); + return null; + } + String[] values = null; + TCPreferenceService service = session.getPreferenceService(); + values = service.getStringArray(TCPreferenceService.TC_preference_site, preferenceName); + String[] resultValues = new String[values.length]; + for (int i = 0; i < values.length; i++) { + if (values[i].indexOf("\\n") >= 0) { + resultValues[i] = values[i].replace("\\n", "\n"); + } else { + resultValues[i] = values[i]; + } + } + return resultValues; + } + + /*** + * ȡѡ + * + * @param session Ự + * @param preferenceName ѡ + * @return + */ + public static String getPreferenceValue(String preferenceName) { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + if (preferenceName == null || session == null) { + System.out.println(""); + return null; + } + TCPreferenceService service = session.getPreferenceService(); + return service.getString(TCPreferenceService.TC_preference_site, preferenceName); + } + + public static void setByPass(boolean val,TCSession session) { + try { + TCUserService userservice = session.getUserService(); + userservice.call(val ? "CONNOR_open_bypass" : "CONNOR_close_bypass", new Object[] { "" }); + System.out.println(val ? "Open Bypass" : "Close Bypass"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void openByPass(TCSession session) throws TCException { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[1]; + obj[0] = ""; + userservice.call("Supor_open_bypass", obj); + } + + public static void closeByPass(TCSession session) throws TCException { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[1]; + obj[0] = ""; + userservice.call("Supor_close_bypass", obj); + } + public static void setProperty(TCSession session,TCComponent[] items,String propname,String propvalue) throws TCException { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[3]; + obj[0] = items; + obj[1] = propname; + obj[2] = propvalue; + userservice.call("connor_set_prop_value", obj); + } + + /*** + * Ͷ󵽷ࣨͨwebService + * + * @param codeRemark ID + * @param rev 汾 + * @param propList + */ + + + /*** + * ӷƳͨwebService + * + * @param codeRemark UID + */ + + + /*** + * @param matnr Ϻ + * @param ddlx + * @param type жʷ + * @return طid + */ + public static String getClassficationId(String matnr, String ddlx, String type) { + // String classId = "jlcs01010101"; + String classId = ""; + if (ddlx.equals("") || ddlx.equals("KD")) { + String[] values = getPreferenceValues("JL_number_to_className"); + String className = null; + + for (String s : values) { + String[] split = s.split("="); + if (split[0].equals(matnr)) { + className = split[1]; + break; + } + } + String[] values2 = getPreferenceValues("JL_name_to_id"); + // split[1]--ʷsplit[2]-- split[3]-- + for (String t : values2) { + String[] split = t.split("="); + if (split[0].equals(className)) { + if (type.equals("ʷ")) { + classId = split[1]; + } else if (type.equals("ж")) { + classId = split[2]; + } else if (type.equals("")) { + classId = split[3]; + } + } + } + } else if (ddlx.equals("")) { + classId = "jlcs01010201"; + String name = matnr.substring(0, 2) + ""; + String[] values = getPreferenceValues("JL_name_to_id"); + for (String t : values) { + String[] split = t.split("="); + if (split[0].equals(name)) { + if (type.equals("ʷ")) { + classId = split[1]; + } else if (type.equals("ж")) { + classId = split[2]; + } else if (type.equals("")) { + classId = split[3]; + } + } + } + } + + return classId; + } + + /** + * ȡLOVʾֵ + * + * @param icsD + * @return + */ + public static String getClassDisplayableValue(String value, ICSPropertyDescription icsD) { + String result = ""; + ICSKeyLov lov1 = icsD.getFormat().getKeyLov(); + if (lov1 != null) { + String[] keys = lov1.getKeys(); + for (String key : keys) { + if (value.equals(key)) { + result = lov1.getValueOfKey(key); + return result; + } + } + } + return result; + } + + public static boolean isDouble(String value) { + try { + Double.parseDouble(value); + return true; + } catch (Exception e) { + // TODO: handle exception + return false; + } + } + + /*** + * жǷȨ + * + * @param session session + * @param value ѡ + * @param userId ûID + * @return + */ + public static boolean havePrivilege(TCSession session, String commandName, String userId) { + TCPreferenceService service = session.getPreferenceService(); + + String[] values = service.getStringArray(TCPreferenceService.TC_preference_site, "JL_User_Rights"); + if (values == null || values.length == 0) { + MessageBox.post("ѡȨޣϵԱ", "", MessageBox.ERROR); + return false; + } + for (String value : values) { + // value = commandName + "" + userId + String[] split = value.split(""); + if (split[0].equals(commandName)) { + if (split.length == 1) { + return true; + } else { + if (split[1].indexOf(userId) >= 0) { + return true; + } else { + return false; + } + } + } + } + return false; + } + + public static int getCount(String mainStr, String subStr) { + int minLength = mainStr.length(); + int subLength = subStr.length(); + int count = 0; + int index = 0; + + if (minLength >= subLength) { + while ((index = mainStr.indexOf(subStr, index)) != -1) { + count++; + index += subLength; + } + return count; + } + return 0; + } + + /** + * + * + * @param session + * @param item İ汾 + * @param fileName ݼ + * @param tcResource ļ· + * @param isDelete Ƿɾļ + * @param isReplace Ƿɾԭݼ + */ + public static void setExcelToItem(TCSession session, TCComponentItemRevision item,String fileName, String tcResource, + boolean isDelete,boolean isReplace) { + try { + String as1[] = { tcResource };// ļ· + String as2[] = { "excel" }; + String as3[] = { "MSExcelX" }; + String as4[] = { "Plain" }; + TCComponentDatasetType tccomponentDatasetType = (TCComponentDatasetType) session + .getTypeComponent("Dataset"); + TCComponentDataset tccomponentDataset = tccomponentDatasetType.create(fileName, "excel", "MSExcelX"); + tccomponentDataset.setFiles(as1, as3, as4, as2); + //ǷQ + if(isReplace) + { + AIFComponentContext[] zyzdsChildrens = item.getChildren(); + TCComponentItemRevision zyzdsRev = item; + for (AIFComponentContext zyzdsChildren : zyzdsChildrens) { + if ("MSExcelX".equals(zyzdsChildren.getComponent().getType())) { + TCComponentDataset dateSet = (TCComponentDataset) zyzdsChildren.getComponent(); + zyzdsRev.remove("IMAN_specification", dateSet); + dateSet.delete(); + } + } + } + item.add("IMAN_specification", tccomponentDataset); + if (isDelete) { + new File(tcResource).delete(); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static Object getTCPropertyValue(TCComponent item,String propertyName) + { + Object result = ""; + + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + if(tcProperty == null) + { + System.out.println("δȡԣ"+propertyName); + return result; + } + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + result = tcProperty.getDoubleValue(); + break; + case TCProperty.PROP_int: + result = tcProperty.getIntValue(); + break; + case TCProperty.PROP_string: + result = tcProperty.getStringValue(); + break; + case TCProperty.PROP_date: + result = tcProperty.getDateValue(); + break; + default: + break; + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return result; + } + public static void setTCPropertyValue(TCComponent item,String propertyName,Object value) + { + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + if(value instanceof Double) + { + tcProperty.setDoubleValue((double) value); + } + else + { + tcProperty.setDoubleValue(Double.parseDouble(value.toString())); + } + break; + case TCProperty.PROP_int: + if(value instanceof Integer) + { + tcProperty.setDoubleValue((int) value); + } + else + { + tcProperty.setDoubleValue(Integer.parseInt(value.toString())); + } + break; + case TCProperty.PROP_string: + tcProperty.setStringValue(value.toString()); + break; + case TCProperty.PROP_date: + if(value instanceof Date) + { + tcProperty.setDateValue((Date) value); + } + else + { + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-M-dd HH:mm"); + tcProperty.setDateValue(sdf.parse(value.toString())); + } + break; + default: + break; + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** + * ȡѡȡITEMĿϢ + * + * @param itemList + * @return + */ + + + /** + * ȡŵļ + * + * @param item + * @param name + * @return + */ + public static TCComponentFolder getParentFolder(TCComponentItem item, + String name) { + TCComponentFolder folder = null; + try { + AIFComponentContext[] comtexts = item.whereReferenced(); + if (comtexts != null) { + for (int i = 0; i < comtexts.length; i++) { + if (comtexts[i].getComponent() instanceof TCComponentFolder) { + String nameT = ((TCComponentFolder) comtexts[i] + .getComponent()) + .getStringProperty("object_name"); + if (name.equals("ͼֽ") && nameT.equals("ͼֽ")) { + folder = (TCComponentFolder) comtexts[i] + .getComponent(); + } + else if(nameT.equals(name)) + { + folder = (TCComponentFolder) comtexts[i] + .getComponent(); + } + } + } + } + } catch (TCException e) { + e.printStackTrace(); + } + return folder; + } + + /** + * ˵вҪʾԵ + * + * @param session + * @return + */ + + + /** + * ͨSOAITEM + * + * @param session + * Ự + * @param itemID + * ID + * @param itemRev + * İ汾 + * @param itemType + * + * @param itemName + * + * @param itemDesc + * + * @param unit + * ĵλ + * @param itemPropMap + * ITEM + * @param itemRevPropMap + * İ汾 + * @param itemRevMasterPropMap + * İ汾 + */ + + + public static void CreateProcess(TCSession session,TCComponent target,String processName) throws TCException { + try { + TCComponentProcessType processType = (TCComponentProcessType) session.getTypeComponent("Job"); + TCComponentTaskTemplateType taskTemplateType = (TCComponentTaskTemplateType) session.getTypeComponent("EPMTaskTemplate"); + TCComponentTaskTemplate taskTemplate = taskTemplateType.find(processName, TCComponentTaskTemplate.PROCESS_TEMPLATE_TYPE); + if (taskTemplate == null) { + return; + } + // һ ơģ塢Ŀ󡢸 + String name = target.getProperty("object_string"); + processType.create(processName + "" + name, "", taskTemplate, new TCComponent[] { target }, new int[] { 1 }); + } catch (TCException e) { + e.printStackTrace(); + throw e; + } + } + + public static void CreateProcess(TCSession session,TCComponent[] targets,int[] type,String processName) throws TCException { + try { + TCComponentProcessType processType = (TCComponentProcessType) session.getTypeComponent("Job"); + TCComponentTaskTemplateType taskTemplateType = (TCComponentTaskTemplateType) session.getTypeComponent("EPMTaskTemplate"); + TCComponentTaskTemplate taskTemplate = taskTemplateType.find(processName, TCComponentTaskTemplate.PROCESS_TEMPLATE_TYPE); + if (taskTemplate == null) { + return; + } + // һ ơģ塢Ŀ󡢸 + String name = targets[0].getProperty("object_string"); + processType.create(processName + "" + name, "", taskTemplate, targets, type); + } catch (TCException e) { + e.printStackTrace(); + throw e; + } + } + + + + + /** + * ȡEXCEL + * + * @param File excel_file + * @return List صϢ + * @throws IOException + * @throws FileNotFoundException + */ + + + + + /** + * ȡEXCEL + * + * @param File excel_file + * @return List صϢ + * @throws IOException + * @throws FileNotFoundException + */ + + + + + /** + * ȡEXCEL + * + * @param File excel_file + * @return List صϢ + * @throws IOException + * @throws FileNotFoundException + */ + + +}