commit e85afb07027de2f7ddd402a4f3eb03859c1b6d21 Author: 李冬阳 Date: Fri Jan 5 18:36:00 2024 +0800 BOM装箱单批量填写代码上传 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..eb8f54c --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.connor.cust + + + + + + 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/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..bb29a1d --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=GBK diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ddd09d3 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Cust +Bundle-SymbolicName: com.connor.cust;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: com.connor.cust.Activator +Bundle-Vendor: CONNOR +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + com.teamcenter.rac.kernel;bundle-version="14000.3.0", + com.teamcenter.rac.aifrcp;bundle-version="14000.3.0", + com.teamcenter.rac.util;bundle-version="14000.3.0", + org.apache.poi;bundle-version="5.2.1", + TcSoaCoreRac;bundle-version="14000.3.0" +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Automatic-Module-Name: com.connor.cust +Bundle-ActivationPolicy: lazy diff --git a/bin/com/connor/cust/Activator.class b/bin/com/connor/cust/Activator.class new file mode 100644 index 0000000..cc1df45 Binary files /dev/null and b/bin/com/connor/cust/Activator.class differ diff --git a/bin/com/connor/cust/box/BoxReportHandler.class b/bin/com/connor/cust/box/BoxReportHandler.class new file mode 100644 index 0000000..90205c5 Binary files /dev/null and b/bin/com/connor/cust/box/BoxReportHandler.class differ diff --git a/bin/com/connor/cust/box/PlmLocale.class b/bin/com/connor/cust/box/PlmLocale.class new file mode 100644 index 0000000..e910da3 Binary files /dev/null and b/bin/com/connor/cust/box/PlmLocale.class differ diff --git a/bin/com/connor/cust/box/XYBOMDialog$1.class b/bin/com/connor/cust/box/XYBOMDialog$1.class new file mode 100644 index 0000000..c325007 Binary files /dev/null and b/bin/com/connor/cust/box/XYBOMDialog$1.class differ diff --git a/bin/com/connor/cust/box/XYBOMDialog$2.class b/bin/com/connor/cust/box/XYBOMDialog$2.class new file mode 100644 index 0000000..979d656 Binary files /dev/null and b/bin/com/connor/cust/box/XYBOMDialog$2.class differ diff --git a/bin/com/connor/cust/box/XYBOMDialog.class b/bin/com/connor/cust/box/XYBOMDialog.class new file mode 100644 index 0000000..052b19b Binary files /dev/null and b/bin/com/connor/cust/box/XYBOMDialog.class differ diff --git a/bin/com/connor/cust/box/XYBOMHandler.class b/bin/com/connor/cust/box/XYBOMHandler.class new file mode 100644 index 0000000..593c4b3 Binary files /dev/null and b/bin/com/connor/cust/box/XYBOMHandler.class differ diff --git a/bin/com/connor/cust/box/history_locale.properties b/bin/com/connor/cust/box/history_locale.properties new file mode 100644 index 0000000..9a06b5a --- /dev/null +++ b/bin/com/connor/cust/box/history_locale.properties @@ -0,0 +1,8 @@ +preferr=preferences error! +#XYBOM +ok=ok +err=Error: +cel=cancel +notbom= is not BOMLine! +setbox=Set Box +boxfinish=Box set finished! \ No newline at end of file diff --git a/bin/com/connor/cust/box/history_locale_zh_CN.properties b/bin/com/connor/cust/box/history_locale_zh_CN.properties new file mode 100644 index 0000000..4b66227 --- /dev/null +++ b/bin/com/connor/cust/box/history_locale_zh_CN.properties @@ -0,0 +1,10 @@ +preferr=\u9996\u9009\u9879\u914D\u7F6E\u4E0D\u6B63\u786E +#XYBOM +ok=\u786E\u5B9A +err=\u9519\u8BEF\uFF1A +cel=\u53D6\u6D88 +notbom= \u4E0D\u662FBOM\u884C\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 +setbox=\u8BBE\u7F6E\u88C5\u7BB1\u5355 +boxfinish=\u88C5\u7BB1\u5355\u8BBE\u7F6E\u5B8C\u6210\uFF01 +#BoxReport +nottop=\u9009\u4E2D\u5BF9\u8C61\u4E0D\u662FBOM\u9876\u5C42\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 \ No newline at end of file diff --git a/bin/com/connor/cust/util/SqlUtil.class b/bin/com/connor/cust/util/SqlUtil.class new file mode 100644 index 0000000..6c0eca0 Binary files /dev/null and b/bin/com/connor/cust/util/SqlUtil.class differ diff --git a/bin/com/connor/cust/util/TCUtil$1.class b/bin/com/connor/cust/util/TCUtil$1.class new file mode 100644 index 0000000..6afc74a Binary files /dev/null and b/bin/com/connor/cust/util/TCUtil$1.class differ diff --git a/bin/com/connor/cust/util/TCUtil.class b/bin/com/connor/cust/util/TCUtil.class new file mode 100644 index 0000000..ce5060b Binary files /dev/null and b/bin/com/connor/cust/util/TCUtil.class differ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..0d3d3a7 --- /dev/null +++ b/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/ diff --git a/icons/sample.png b/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/icons/sample.png differ diff --git a/icons/sample@2x.png b/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/icons/sample@2x.png differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..d47df30 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + <--> + + + + + + + + + + + + + + + + + + + diff --git a/src/com/connor/cust/Activator.java b/src/com/connor/cust/Activator.java new file mode 100644 index 0000000..eb5d138 --- /dev/null +++ b/src/com/connor/cust/Activator.java @@ -0,0 +1,44 @@ +package com.connor.cust; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "com.connor.cust"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/src/com/connor/cust/box/BoxReportHandler.java b/src/com/connor/cust/box/BoxReportHandler.java new file mode 100644 index 0000000..cbd974f --- /dev/null +++ b/src/com/connor/cust/box/BoxReportHandler.java @@ -0,0 +1,53 @@ +package com.connor.cust.box; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +/** + * : װ䵥 + * :2024-01-05 + * @author  + * + * ޸ ޸ ޸ + * 2019-01-24 XXXX + */ +public class BoxReportHandler extends AbstractHandler{ + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("BoxReportHandler"); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent target = app.getTargetComponent(); + if(target == null || !(target instanceof TCComponentBOMLine)) { + MessageBox.post(desktop, PlmLocale.getString("nottop"), "ERROR", MessageBox.ERROR);//ѡжBOM㣬ѡ + return null; + } + TCComponentBOMLine bom = (TCComponentBOMLine) target; + if(bom.parent() != null) { + MessageBox.post(desktop, PlmLocale.getString("nottop"), "ERROR", MessageBox.ERROR);//ѡжBOM㣬ѡ + return null; + } + String[] options = session.getPreferenceService().getStringValues("KWC_ReportTemplate_XYBOX"); + if(options == null || options.length < 2) { + MessageBox.post(desktop, "KWC_ReportTemplate_XYBOX" + PlmLocale.getString("preferr"), "ERROR", MessageBox.ERROR); + return null; + } +// new XYBOMDialog(session, targets); + } catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, PlmLocale.getString("err") + e.getMessage(), "ERROR", MessageBox.ERROR); + } + return null; + } +} diff --git a/src/com/connor/cust/box/PlmLocale.java b/src/com/connor/cust/box/PlmLocale.java new file mode 100644 index 0000000..f9314fd --- /dev/null +++ b/src/com/connor/cust/box/PlmLocale.java @@ -0,0 +1,29 @@ +package com.connor.cust.box; + +import com.teamcenter.rac.util.Registry; + +/** + * : ӢĻл + * :2019-02-26 + * @author + * + * ޸ ޸ ޸ + * 2019-01-24 XXXX + */ +public class PlmLocale { + + public static final Registry reg = Registry.getRegistry(PlmLocale.class); + + public static String getString(String title) { + if (isEmpty(title)) { + return ""; + } else { + String res = reg.getString(title); + return isEmpty(res) ? title : res; + } + } + + private static boolean isEmpty(String title) { + return title == null || "".equals(title.trim()); + } +} diff --git a/src/com/connor/cust/box/XYBOMDialog.java b/src/com/connor/cust/box/XYBOMDialog.java new file mode 100644 index 0000000..766d579 --- /dev/null +++ b/src/com/connor/cust/box/XYBOMDialog.java @@ -0,0 +1,105 @@ +package com.connor.cust.box; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; + +import com.connor.cust.util.TCUtil; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +/** + * : BOMװ䵥д + * :2024-01-04 + * @author  + * + * ޸ ޸ ޸ + * 2019-01-24 XXXX + */ +public class XYBOMDialog extends AbstractAIFDialog { + private static final long serialVersionUID = 1L; +// private TCSession session; + private JButton cancelBtn; + private JButton okBtn; + private JComboBox box; + + public XYBOMDialog(TCSession session, InterfaceAIFComponent[] targets) throws Exception { + super(AIFUtility.getActiveDesktop()); +// this.session = session; + setTitle(PlmLocale.getString("setbox")); + +// JLabel label1 = new JLabel("Դ"); +// add(label1); +// label1.setBounds(20, 20, 90, 23); + box = new JComboBox<>(); + box.setEditable(true); + box.addItem(""); + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); + TCComponentListOfValues[] lovs = lovType.find("KWC6_DTLOV_ZXBOX"); + if(lovs.length > 0) { + for(String s : TCUtil.getDynamicLOV(session, lovs[0])) { + box.addItem(s); + } + } + add(box); + box.setBounds(30, 20, 200, 23); + + okBtn = new JButton(PlmLocale.getString("ok")); + add(okBtn); + okBtn.setBounds(30, 100, 80, 23); + cancelBtn = new JButton(PlmLocale.getString("cel")); + add(cancelBtn); + cancelBtn.setBounds(150, 100, 80, 23); + add(new JLabel("")); + + addActionListener(session, targets); + + pack(); + setSize(new Dimension(350, 200)); + setDefaultLookAndFeelDecorated(true); + Dimension screen = getToolkit().getScreenSize(); + setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2); +// setAlwaysOnTop(true); + setVisible(true); + } + + private void addActionListener(TCSession session, InterfaceAIFComponent[] targets) { + okBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + String value = box.getSelectedItem().toString(); + TCUtil.setByPass(session, true); + for(InterfaceAIFComponent t : targets) { + ((TCComponentBOMLine)t).setProperty("XYBOX", value); + } + MessageBox.post(XYBOMDialog.this, PlmLocale.getString("boxfinish"), "INFO", MessageBox.INFORMATION);//װ䵥ɣ + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(XYBOMDialog.this, PlmLocale.getString("err") + e1.getMessage(), "ERROR", MessageBox.ERROR); + }finally { + try { + TCUtil.setByPass(session, false); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + }); + cancelBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + } +} \ No newline at end of file diff --git a/src/com/connor/cust/box/XYBOMHandler.java b/src/com/connor/cust/box/XYBOMHandler.java new file mode 100644 index 0000000..61c6302 --- /dev/null +++ b/src/com/connor/cust/box/XYBOMHandler.java @@ -0,0 +1,46 @@ +package com.connor.cust.box; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +/** + * : BOMװ䵥д + * :2024-01-04 + * @author  + * + * ޸ ޸ ޸ + * 2019-01-24 XXXX + */ +public class XYBOMHandler extends AbstractHandler{ + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("XYBOMHandler"); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent[] targets = app.getTargetComponents(); + for(InterfaceAIFComponent t : targets) { + if(!(t instanceof TCComponentBOMLine)) { + MessageBox.post(desktop, t + PlmLocale.getString("notbom"), "ERROR", MessageBox.ERROR);// BOMУѡ + return null; + } + } + + new XYBOMDialog(session, targets); + } catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, PlmLocale.getString("err") + e.getMessage(), "ERROR", MessageBox.ERROR); + } + return null; + } +} diff --git a/src/com/connor/cust/box/history_locale.properties b/src/com/connor/cust/box/history_locale.properties new file mode 100644 index 0000000..9a06b5a --- /dev/null +++ b/src/com/connor/cust/box/history_locale.properties @@ -0,0 +1,8 @@ +preferr=preferences error! +#XYBOM +ok=ok +err=Error: +cel=cancel +notbom= is not BOMLine! +setbox=Set Box +boxfinish=Box set finished! \ No newline at end of file diff --git a/src/com/connor/cust/box/history_locale_zh_CN.properties b/src/com/connor/cust/box/history_locale_zh_CN.properties new file mode 100644 index 0000000..4b66227 --- /dev/null +++ b/src/com/connor/cust/box/history_locale_zh_CN.properties @@ -0,0 +1,10 @@ +preferr=\u9996\u9009\u9879\u914D\u7F6E\u4E0D\u6B63\u786E +#XYBOM +ok=\u786E\u5B9A +err=\u9519\u8BEF\uFF1A +cel=\u53D6\u6D88 +notbom= \u4E0D\u662FBOM\u884C\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 +setbox=\u8BBE\u7F6E\u88C5\u7BB1\u5355 +boxfinish=\u88C5\u7BB1\u5355\u8BBE\u7F6E\u5B8C\u6210\uFF01 +#BoxReport +nottop=\u9009\u4E2D\u5BF9\u8C61\u4E0D\u662FBOM\u9876\u5C42\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 \ No newline at end of file diff --git a/src/com/connor/cust/util/SqlUtil.java b/src/com/connor/cust/util/SqlUtil.java new file mode 100644 index 0000000..f03b763 --- /dev/null +++ b/src/com/connor/cust/util/SqlUtil.java @@ -0,0 +1,684 @@ +package com.connor.cust.util; + +import java.io.Reader; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.Statement; +import java.sql.Timestamp; +import java.sql.Types; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +public class SqlUtil { + + public static Connection connection = null; + public static PreparedStatement ps = null; + public static ResultSet rs = null; +// public static Registry reg = Registry.getRegistry(SqlUtil.class); + public static int ORACLE = 1; + public static int SQLSERVER = 2; + +// public static Connection getConnection(int dbType) { +// if (dbType == ORACLE) { +// return getOracleConnection(); +// } else if (dbType == SQLSERVER) { +// return getSqlserverConnection(); +// } +// return null; +// } + + public static Date getDate(java.sql.Date date) { + if (date == null) { + return null; + } + return new Date(date.getTime()); + } + + /** + * ݿ + + public static Connection getSqlserverConnection() { + String driver = reg.getString("SQL.SQLSERVER.DRIVER"); + String url = reg.getString("SQL.SQLSERVER.URL"); + String user = reg.getString("SQL.SQLSERVER.USER"); + String password = reg.getString("SQL.SQLSERVER.PASSWORD"); + System.out.println("ݿϢ"); + System.out.println("DRIVER: " + driver); + System.out.println("URL: " + url); + System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + }*/ + + public static Connection getSqlserverConnection(String driver, String url, String user, String password) { +// String driver = reg.getString("SQL.SQLSERVER.DRIVER"); +// String url = reg.getString("SQL.SQLSERVER.URL"); +// String user = reg.getString("SQL.SQLSERVER.USER"); +// String password = reg.getString("SQL.SQLSERVER.PASSWORD"); + System.out.println("ݿϢ"); +// System.out.println("DRIVER: " + driver); +// System.out.println("URL: " + url); +// System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + } + + public static Connection getOracleConnection(String url, String user, String password) throws Exception { + String driver = "oracle.jdbc.driver.OracleDriver"; + System.out.println("ݿϢ"); + System.out.println("DRIVER: " + driver); + System.out.println("URL: " + url); + System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + // + Class.forName(driver); + // 1.getConnection()MySQLݿ⣡ + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + + return connection; + } + + /* + public static Connection getOracleConnection() { + // String driver = reg.getString("SQL.ORACLE.DRIVER"); + String url = reg.getString("SQL.ORACLE.URL"); + String user = reg.getString("SQL.ORACLE.USER"); + String password = reg.getString("SQL.ORACLE.PASSWORD"); +// if(prefs!=null&&prefs.length==5) { +// url = "jdbc:oracle:thin:@"+prefs[0]+":"+prefs[1]+":"+prefs[2]; +// user = prefs[3]; +// password = prefs[4]; +// } + return getOracleConnection(url, user, password); + }*/ + + /** + * ˽йnew󣬷ֹö + */ + private SqlUtil() { + } + + /** + * ƴSELECT + * + * @param tableName + * @param selectElement + * @param args + * @return + */ + public static String getSelectSql(String tableName, String[] selectElement, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT "); + if (selectElement != null) { + for (String element : selectElement) { + valuesSB.append(element).append(","); + } + valuesSB.delete(valuesSB.length() - 1, valuesSB.length()); + } + valuesSB.append(" FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴSELECT + * + * @param tableName + * @param args + * @return + */ + public static String getSelectSql(String tableName, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT * FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴӸ + * + * @param tableName + * @param args + * @param args2 + * @return + */ + public static String getUpdataSQL(String tableName, String[] args, String[] args2) { + StringBuffer updateSB = new StringBuffer("UPDATE "); + updateSB.append(tableName); + updateSB.append(" SET "); + // ƴӸ + for (int i = 0; i < args.length; i++) { + if (args[i].toUpperCase().equals("CREATED_DATE") || args[i].toUpperCase().equals("LAST_UPDATE_DATE")) { + updateSB.append(args[i]).append("=to_date(?,'yyyy-MM-dd HH24:mi:ss') ,"); + } else { + updateSB.append(args[i]).append("=? ,"); + } + } + updateSB.delete(updateSB.length() - 2, updateSB.length()); + ; + updateSB.append(" WHERE "); + for (int i = 0; i < args2.length; i++) { + updateSB.append(args2[i]).append("=? AND "); + } + updateSB.delete(updateSB.length() - 4, updateSB.length()); + return updateSB.toString(); + } + + /** + * ƴSQLinsert + * + * @param tableName + * @param args + * @return + */ + public static String getInsertSql(String tableName, String... args) { + StringBuffer insertSql = new StringBuffer("insert into "); + StringBuffer values = new StringBuffer("values("); + + if (tableName != null && args != null && args.length > 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < args.length; i++) { + insertSql.append(args[i]); + insertSql.append(", "); + if (args[i].toUpperCase().equals("LAST_UPDATE_DATE") || args[i].toUpperCase().equals("CREATED_DATE")) { + values.append("to_date(?,'yyyy-MM-dd HH24:mi:ss'), "); + } else { + values.append("?, "); + } + + } + } else { + return null; + } + insertSql.delete(insertSql.length() - 2, insertSql.length()); + values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * õݿ + * + * @param tableName + * @param args + * + * @param args2 + * + * @return ƴӺĴݿ + */ + public final static String GetCreateTableSQL(String tableName, String[] args, String[] args2) { + + if (args == null || args2 == null || args.length != args2.length) { + System.out.println("THE INPUT PRAGREMS IS ERROR"); + return null; + } + StringBuffer createSQL = new StringBuffer("create table "); + createSQL.append(tableName); + createSQL.append("("); + for (int i = 0; i < args.length; i++) { + createSQL.append(args[i] + " "); + createSQL.append(args2[i] + ", "); + } + createSQL.delete(createSQL.length() - 2, createSQL.length()); + createSQL.append(")"); + return createSQL.toString(); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql) throws Exception { + return getPs(sql, null); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(Object[] argments, String sql) throws Exception { + return getPs(sql, argments); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql, Object[] argments) throws Exception { + SqlUtil.ps = SqlUtil.connection.prepareStatement(sql); + if (argments != null) { + for (int i = 0; i < argments.length; i++) { + SqlUtil.ps.setObject(i + 1, argments[i]); + } + } + return SqlUtil.ps; + } + + /** + * + */ + public final static int write(String sql) { + return write(sql, null); + } + + /** + * + */ + public final static int write(Object[] argments, String sql) { + return write(sql, argments); + } + + /** + * + */ + public final static int write(String sql, Object[] argments) { + + return update(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql) { + return delete(sql, null); + } + + /** + * ɾ + */ + public final static int delete(Object[] argments, String sql) { + return delete(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql, Object[] argments) { + return update(sql, argments); + } + + /** + * ޸ + */ + public final static int update(String sql) { + return update(sql, null); + } + + /** + * ޸ + */ + public final static int update(String[] argments, String sql) { + return update(sql, argments); + } + + /** + * ޸(ɾնҪô˷˴쳣رճConnectionΪĶ) + */ + public final static int update(String sql, Object[] argments) { + int i = -1; + try { + i = SqlUtil.getPs(argments, sql).executeUpdate(); + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + return i; + } + + /** + * ѯ + */ + public final static ResultSet read(String sql) throws Exception { + return read(sql, null); + } + + /** + * ѯ + */ + public final static ResultSet read(Object[] argments, String sql) throws Exception { + return read(sql, argments); + } + + /** + * ѯ(вѯնҪô˷治쳣׳ɵߴfinallyͷԴ) + * + * @throws SQLException + */ + public final static ResultSet read(String sql, Object[] argments) throws Exception { + System.out.println("argments=" + argments.length); + return SqlUtil.rs = SqlUtil.getPs(argments, sql).executeQuery(); + } + + /** + * + */ + public final static boolean createTable(String sql) { + return go(sql, null); + } + + /** + * ɾ + */ + public final static boolean dropTable(String sql) { + return go(sql, null); + } + + /** + * ޸ı + */ + public final static boolean alterTable(String sql) { + return go(sql, null); + } + + /** + * ˷ִDDL(,޸ı,ɾ) + */ + private final static boolean go(String sql, Object[] argments) { + boolean flag = false; + try { + flag = SqlUtil.getPs(sql, argments).execute(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + if (flag) { + try { + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return flag; + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet) { + free(resultSet, null, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement) { + free(null, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Connection connection) { + free(null, null, connection); + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet, Statement statement) { + free(resultSet, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement, Connection connection) { + free(null, statement, connection); + } + + /** + * ͷԴ(Ĭϲ) + */ + public final static void free() { + free(SqlUtil.rs, SqlUtil.ps); + } + + /** + * ͷԴ(ȫͷ) + */ + public final static void freeAll() { + free(SqlUtil.rs, SqlUtil.ps, SqlUtil.connection); + } + + /** + * ͷԴ(ҲҪȫͷ) + */ + public final static void free(ResultSet resultSet, Statement statement, Connection connection) { + try { + if (resultSet != null) { + try { + resultSet.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + try { + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + if (connection != null) { + try { + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + public static ArrayList> getDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + ArrayList> vecData = new ArrayList>(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); +// System.out.println("columnTypes"+i+"=="+columnTypes[i]); + } + + while (rs.next()) { + HashMap dataTable = new HashMap(); + + for (int i = 0; i < columnNames.length; i++) { + Object value = null; + switch (columnTypes[i]) { + case Types.NVARCHAR: + case Types.VARCHAR: + value = rs.getString(columnNames[i]); + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(columnNames[i]); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(columnNames[i]); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(columnNames[i]); + break; + case Types.CLOB: + Clob clob = rs.getClob(columnNames[i]); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } + dataTable.put(columnNames[i], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + } + vecData.add(dataTable); + } + rs.close(); + statement.close(); + return vecData; + } + public static List getArrayDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + List vecData = new LinkedList<>(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); + } + + while (rs.next()) { + Object[] result = new Object[columnNames.length]; + + for (int i = 0; i < columnNames.length; i++) { + Object value = null; + switch (columnTypes[i]) { + case Types.VARCHAR: + value = rs.getString(columnNames[i]); + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(columnNames[i]); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(columnNames[i]); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(columnNames[i]); + break; + case Types.CLOB: + Clob clob = rs.getClob(columnNames[i]); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } +// dataTable.put(columnNames[i], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + result[i] = value; + } + vecData.add(result); + } + rs.close(); + statement.close(); + return vecData; + } +} diff --git a/src/com/connor/cust/util/TCUtil.java b/src/com/connor/cust/util/TCUtil.java new file mode 100644 index 0000000..08fbff1 --- /dev/null +++ b/src/com/connor/cust/util/TCUtil.java @@ -0,0 +1,490 @@ +package com.connor.cust.util; + +import java.awt.Frame; +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Vector; + +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JTable; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.filechooser.FileSystemView; + +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; + +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +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.TCComponentContextList; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentPseudoFolder; +import com.teamcenter.rac.kernel.TCComponentQuery; +import com.teamcenter.rac.kernel.TCComponentQueryType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCQueryClause; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +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; + +public class TCUtil { + public static final int MINWIDTH = 1280; + public static final int MINHEIGHT = 768; + + public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{ + TCComponentBOMWindow window = null; + TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + window = bomWinType.create(null); + return window; + } + + public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision) + throws Exception { + TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null); + window.save(); + return bomLine; + } + public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation) throws Exception { + TCComponentPseudoFolder pseudoFolder = null; + AIFComponentContext[] comps = parent.getChildren(); + if (comps != null && comps.length > 0 && comps[0] != null) { + for (int i = 0; i < comps.length; i++) { + TCComponent comp = (TCComponent) comps[i].getComponent(); + if (comp instanceof TCComponentPseudoFolder) { + if (comp.isTypeOf("PseudoFolder")) { +// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation()); + if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) { + pseudoFolder = (TCComponentPseudoFolder) comp; + break; + } + } + } + } + } + return pseudoFolder; + } + public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception { + if (revision != null) { + AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev"); + if (contexts != null && contexts.length > 0) { + InterfaceAIFComponent component = contexts[0].getComponent(); + if (component instanceof TCComponentForm) { + return (TCComponentForm) component; + } + } + } + return null; + } + + public static LinkedHashMap getlovValues(TCSession session, String lovName) throws TCException { + LinkedHashMap lovVal = new LinkedHashMap(); + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues"); + TCComponentListOfValues[] lovs = lovType.find(lovName); + if (lovs != null && lovs.length > 0) { + TCComponentListOfValues lov = lovs[0]; + ListOfValuesInfo lovInfo = lov.getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + // System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]); + lovVal.put(code[i], name[i]); + } + } + return lovVal; + } + return null; + } + + public static String getTableValue(JTable table, int row, int col){ + Object val = table.getValueAt(row, col); + if(val==null) + return ""; + else + return val.toString(); + } + /** + * ѯѯ + * @param session TCSession + * @param queryName ѯ + * @param aKey ѯĿ + * @param aVal ѯֵ + * @return ѯ + */ + public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + throw new Exception("δҵѯ " + queryName + "!"); + } + aKey = session.getTextService().getTextValues(aKey); +// for (int i = 0; i < aKey.length; i++) { +// System.out.println(aKey[i] + "===============" + aVal[i]); +// } + TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal); + return componentContextList.toTCComponentArray(); + } + /** + * ѯѯֲ֧ѯĬ + * @param session TCSession + * @param queryName ѯ + * @param Keys ѯĿ + * @param Vals ѯֵ + * @return ѯ + */ + public static TCComponent[] query(TCSession session, String queryName, Vector Keys, Vector Vals) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + System.out.println("δҵѯ" + queryName); + throw new Exception("Query:"+queryName+" cannot find"); + } + TCQueryClause[] qc = imancomponentquery.describe(); +// Map clauseMap = new HashMap<>(); + for(TCQueryClause c : qc) { + String key = c.getUserEntryNameDisplay(); + String value = c.getDefaultValue(); +// System.out.println(key + "==>" + c.getAttributeName()); + if(!value.trim().isEmpty() && !Keys.contains(key)) { + if(key.isEmpty()) + Keys.add(c.getAttributeName()); + else + Keys.add(key); + Vals.add(value); + } + } + int size = Keys.size(); + String[] keyA = new String[size]; + String[] valueA = new String[size]; + for(int i=0; i 0) { + Integer maxId = 0; + for (TCComponent comp : comps) { + String pid = comp.getProperty("item_id"); + System.out.println("pid:" + pid); + String pidSuffix = pid.substring(pid.length() - 3); + if (Integer.parseInt(pidSuffix) > maxId) { + maxId = Integer.parseInt(pidSuffix); + } + } + return String.format("%03d", maxId + 1); + } + return "001"; + } + + /** + * Excel·ѡ + * @return ѡExcel·ļ + */ + public static File saveExcelChooser() { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + Frame frame = new Frame(); + int returnVal = chooser.showSaveDialog(frame); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + System.out.println("saveExcelChooser1:" + path); + } + return dir; + } + + /** + * Excel·ѡָĬ· + * @param defaultFile Ĭ· + * @return ѡExcel·ļ + */ + public static File saveExcelChooser(String defaultFile) { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + chooser.setSelectedFile(new File(defaultFile)); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(new Frame()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + if(dir.exists()) + dir.delete(); +// System.out.println("saveExcelChooser1:" + dir.getPath()); + } + return dir; + } + + /** + * Excel·ѡָڣ + * @param defaultFile + * @return ѡExcel·ļ + */ + public static File saveExcelChooser(JDialog parent) { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(parent); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + System.out.println("saveExcelChooser1:" + path); + } + return dir; + } + + public static boolean contains(Object[] array, Object str) { + for(Object s : array) { +// System.out.println("contains:"+s+"="+str); + if(s.equals(str)) + return true; + } + return false; + } + + public static Map executeToMap(InputStream in){ + System.out.println("Read properties file"); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); + String line = null; + Map resultMap = new LinkedHashMap<>(16); + if (reader.ready()) { + while (null != (line = reader.readLine())) { + if (line.length() <= 0 || line.startsWith("#") || !line.contains("=")) { + continue; + } + resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1)); + } + } + in.close(); + reader.close(); + return resultMap; + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR); + } + return null; + } + + public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception { + String refType = null, objType = null, fileName = null; + fileName = file.getName().toLowerCase(); + if (fileName.endsWith("xls")) { + refType = "excel"; + objType = "MSExcel"; + } else if (fileName.endsWith("xlsx")) { + refType = "excel"; + objType = "MSExcelX"; + } + TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset"); + TCComponentDataset dataset = compType.create(datasetName, "description", objType); + dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType }); + return dataset; + } + + public static Vector getChildren(TCComponent parent, String relation, String name) throws Exception { + Vector result = new Vector<>(); + AIFComponentContext[] children; + if(relation==null || relation.isEmpty()) + children = parent.getChildren(); + else + children = parent.getChildren(relation); + for(AIFComponentContext c : children) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.getProperty("object_name").equals(name)) + result.add(comp); + } + return result; + } + /** + * ȡָϵӼnull + * @param parent + * @param relation ָϵ + * @return Ӽ + */ + public static AIFComponentContext[] getChildren(TCComponent parent, String relation) throws Exception { + AIFComponentContext[] fs = parent.getChildren(relation); + if(fs==null || fs.length==0) + return new AIFComponentContext[] { }; + if(fs.length>1) + return fs; + InterfaceAIFComponent fc = fs[0].getComponent(); + if(fc instanceof TCComponentPseudoFolder) + return fc.getChildren(); + return fs; + } + /** + * ΪTC + * @param TCComponent + * @param property ո + * @return ȷ˳ + */ + public static TCComponent[] TCsort(TCComponent[] TCComponent, String property) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for(TCComponent Component : TCComponent) { + try { + map.put(Component, Component.getProperty(property)); + } catch (Exception e) { + e.printStackTrace(); + } + } + // ͨArrayList캯map.entrySet()תlist + ArrayList> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { + return mapping1.getValue().compareTo(mapping2.getValue()); + } + }); + TCComponent = new TCComponent[count]; + int i=0; + for(Map.Entry mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + + public static String getStackTrace(Exception e) { + e.printStackTrace(); + StringBuilder rError = new StringBuilder(""+e.getMessage()); + for(StackTraceElement ste : e.getStackTrace()) { + rError.append("\n\t"+ste.toString()); + } +// System.out.println(rError.toString()); + return rError.toString(); + } + + /** + * ȡExcel + * @param sheet sheetҳ + * @param i к + * @return Excelж + */ + public static XSSFRow getRow(XSSFSheet sheet, int i) throws Exception { + XSSFRow row = sheet.getRow(i); + if(row==null) + row = sheet.createRow(i); + return row; + } + /** + * ȡExcelԪ + * @param row Ԫ + * @param i Ԫк + * @return ExcelԪ + */ + public static XSSFCell getCell(XSSFRow row, int col) throws Exception { + XSSFCell cell = row.getCell(col); + if(cell==null) + cell = row.createCell(col); + return cell; + } + + /** + * 򿪻ر· + * @param session TCSession + * @param open ΪtrueرΪfalse + */ + @SuppressWarnings("deprecation") + public static void setByPass(TCSession session, boolean open) throws Exception { + session.getUserService().call("setbypass", new Object[] { open ? "true" : "false" }); + } + /** + * ȡ̬LOVֵ + * @param session TCSession + * @param lov ָ̬LOV + * @return ̬LOVֵ + */ + public static String[] getDynamicLOV(TCSession session, TCComponentListOfValues lov) throws Exception { + Vector lovDisplayValueList = new Vector<>(); +// lovDisplayValueList.add(""); + Vector lovValueList = new Vector<>(); + LOVService lovService = LOVService.getService(session); + InitialLovData input = new InitialLovData(); + LovFilterData filter = new LovFilterData(); + filter.sortPropertyName = "object_name"; + filter.order = 1; + filter.numberToReturn = 100; + filter.maxResults = 100; + + 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()) { +// sb.append("UID:" + row.uid + ",key:" + key + "value:" + map.get(key)[0]); +// sb.append("\n"); + lovDisplayValueList.add(map.get(key)[0]); + lovValueList.add(realmap.get(key)[0]); + } + } +// System.out.println("StringBuffer:"+sb.toString()); + return lovDisplayValueList.toArray(new String[lovDisplayValueList.size()]); + } +}