commit 02deffd445f509a8aa08c5434f9e2ad2add4e001 Author: xiongcz Date: Fri Jun 6 11:56:18 2025 +0800 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..cccf87c --- /dev/null +++ b/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml new file mode 100644 index 0000000..7dc1249 --- /dev/null +++ b/.idea/git_toolbox_blame.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..385999e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..c5c2ccb --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + TCImportHistoryDatas + + + + + + 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..8067c69 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Tue May 18 15:00:24 CST 2010 +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..bf2ede6 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Tue May 18 15:00:09 CST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..87c107d --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,239 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: TCImportHistoryDatas Plug-in +Bundle-SymbolicName: TCImportHistoryDatas;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: tcimporthistorydatas.Activator +Require-Bundle: org.eclipse.ui;bundle-version="3.8.0", + org.eclipse.core.runtime;bundle-version="3.8.0", + com.teamcenter.rac.kernel;bundle-version="8000.3.0", + com.teamcenter.rac.tcapps;bundle-version="8000.3.0", + com.teamcenter.rac.util;bundle-version="8000.3.0", + com.teamcenter.rac.aifrcp;bundle-version="8000.3.0", + com.teamcenter.rac.common;bundle-version="8000.3.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Export-Package: com.connor.dev.imp, + com.connor.dev.imp.bom, + com.connor.dev.imp.ob, + com.connor.dev.imp.re, + com.connor.dev.imp.solution.handler, + com.connor.dev.imp.toolkit, + common, + common.log, + jxl, + jxl.biff, + jxl.biff.drawing, + jxl.biff.formula, + jxl.demo, + jxl.format, + jxl.read.biff, + jxl.write, + jxl.write.biff, + org.apache.log4j, + org.apache.log4j.chainsaw, + org.apache.log4j.config, + org.apache.log4j.helpers, + org.apache.log4j.jdbc, + org.apache.log4j.jmx, + org.apache.log4j.lf5, + org.apache.log4j.lf5.util, + org.apache.log4j.lf5.viewer, + org.apache.log4j.lf5.viewer.categoryexplorer, + org.apache.log4j.lf5.viewer.configure, + org.apache.log4j.net, + org.apache.log4j.nt, + org.apache.log4j.or, + org.apache.log4j.or.sax, + org.apache.log4j.spi, + org.apache.log4j.varia, + org.apache.log4j.xml, + org.apache.poi, + org.apache.poi.common.usermodel, + org.apache.poi.ddf, + org.apache.poi.dev, + org.apache.poi.extractor, + org.apache.poi.hpsf, + org.apache.poi.hpsf.examples, + org.apache.poi.hpsf.extractor, + org.apache.poi.hpsf.wellknown, + org.apache.poi.hslf.examples, + org.apache.poi.hsmf.examples, + org.apache.poi.hssf, + org.apache.poi.hssf.dev, + org.apache.poi.hssf.eventmodel, + org.apache.poi.hssf.eventusermodel, + org.apache.poi.hssf.eventusermodel.dummyrecord, + org.apache.poi.hssf.eventusermodel.examples, + org.apache.poi.hssf.extractor, + org.apache.poi.hssf.model, + org.apache.poi.hssf.record, + org.apache.poi.hssf.record.aggregates, + org.apache.poi.hssf.record.cf, + org.apache.poi.hssf.record.chart, + org.apache.poi.hssf.record.common, + org.apache.poi.hssf.record.constant, + org.apache.poi.hssf.record.cont, + org.apache.poi.hssf.record.crypto, + org.apache.poi.hssf.record.formula, + org.apache.poi.hssf.record.formula.atp, + org.apache.poi.hssf.record.formula.eval, + org.apache.poi.hssf.record.formula.function, + org.apache.poi.hssf.record.formula.functions, + org.apache.poi.hssf.record.formula.udf, + org.apache.poi.hssf.record.pivottable, + org.apache.poi.hssf.usermodel, + org.apache.poi.hssf.usermodel.examples, + org.apache.poi.hssf.util, + org.apache.poi.hssf.view, + org.apache.poi.hssf.view.brush, + org.apache.poi.hwpf, + org.apache.poi.openxml4j.exceptions, + org.apache.poi.openxml4j.opc, + org.apache.poi.openxml4j.opc.internal, + org.apache.poi.openxml4j.opc.internal.marshallers, + org.apache.poi.openxml4j.opc.internal.signature, + org.apache.poi.openxml4j.opc.internal.unmarshallers, + org.apache.poi.openxml4j.opc.signature, + org.apache.poi.openxml4j.util, + org.apache.poi.poifs.common, + org.apache.poi.poifs.crypt, + org.apache.poi.poifs.dev, + org.apache.poi.poifs.eventfilesystem, + org.apache.poi.poifs.filesystem, + org.apache.poi.poifs.poibrowser, + org.apache.poi.poifs.property, + org.apache.poi.poifs.storage, + org.apache.poi.ss, + org.apache.poi.ss.examples, + org.apache.poi.ss.examples.html, + org.apache.poi.ss.extractor, + org.apache.poi.ss.format, + org.apache.poi.ss.formula, + org.apache.poi.ss.formula.eval, + org.apache.poi.ss.formula.eval.forked, + org.apache.poi.ss.usermodel, + org.apache.poi.ss.util, + org.apache.poi.util, + org.apache.poi.xslf, + org.apache.poi.xslf.extractor, + org.apache.poi.xslf.usermodel, + org.apache.poi.xssf.dev, + org.apache.poi.xssf.eventusermodel, + org.apache.poi.xssf.eventusermodel.examples, + org.apache.poi.xssf.extractor, + org.apache.poi.xssf.model, + org.apache.poi.xssf.usermodel, + org.apache.poi.xssf.usermodel.examples, + org.apache.poi.xssf.usermodel.extensions, + org.apache.poi.xssf.usermodel.helpers, + org.apache.poi.xssf.util, + org.apache.poi.xwpf.extractor, + org.apache.poi.xwpf.model, + org.apache.poi.xwpf.usermodel, + org.apache.xmlbeans, + org.apache.xmlbeans.impl.common, + org.apache.xmlbeans.impl.config, + org.apache.xmlbeans.impl.inst2xsd, + org.apache.xmlbeans.impl.inst2xsd.util, + org.apache.xmlbeans.impl.jam, + org.apache.xmlbeans.impl.jam.annotation, + org.apache.xmlbeans.impl.jam.internal, + org.apache.xmlbeans.impl.jam.internal.classrefs, + org.apache.xmlbeans.impl.jam.internal.elements, + org.apache.xmlbeans.impl.jam.internal.javadoc, + org.apache.xmlbeans.impl.jam.internal.parser, + org.apache.xmlbeans.impl.jam.internal.reflect, + org.apache.xmlbeans.impl.jam.mutable, + org.apache.xmlbeans.impl.jam.provider, + org.apache.xmlbeans.impl.jam.visitor, + org.apache.xmlbeans.impl.jam.xml, + org.apache.xmlbeans.impl.piccolo.io, + org.apache.xmlbeans.impl.piccolo.util, + org.apache.xmlbeans.impl.piccolo.xml, + org.apache.xmlbeans.impl.regex, + org.apache.xmlbeans.impl.richParser, + org.apache.xmlbeans.impl.schema, + org.apache.xmlbeans.impl.soap, + org.apache.xmlbeans.impl.store, + org.apache.xmlbeans.impl.tool, + org.apache.xmlbeans.impl.util, + org.apache.xmlbeans.impl.validator, + org.apache.xmlbeans.impl.values, + org.apache.xmlbeans.impl.xb.ltgfmt, + org.apache.xmlbeans.impl.xb.ltgfmt.impl, + org.apache.xmlbeans.impl.xb.substwsdl, + org.apache.xmlbeans.impl.xb.substwsdl.impl, + org.apache.xmlbeans.impl.xb.xmlconfig, + org.apache.xmlbeans.impl.xb.xmlconfig.impl, + org.apache.xmlbeans.impl.xb.xmlschema, + org.apache.xmlbeans.impl.xb.xmlschema.impl, + org.apache.xmlbeans.impl.xb.xsdownload, + org.apache.xmlbeans.impl.xb.xsdownload.impl, + org.apache.xmlbeans.impl.xb.xsdschema, + org.apache.xmlbeans.impl.xb.xsdschema.impl, + org.apache.xmlbeans.impl.xsd2inst, + org.apache.xmlbeans.soap, + org.apache.xmlbeans.xml.stream, + org.apache.xmlbeans.xml.stream.events, + org.apache.xmlbeans.xml.stream.utils, + org.dom4j, + org.dom4j.bean, + org.dom4j.datatype, + org.dom4j.dom, + org.dom4j.dtd, + org.dom4j.io, + org.dom4j.jaxb, + org.dom4j.rule, + org.dom4j.rule.pattern, + org.dom4j.swing, + org.dom4j.tree, + org.dom4j.util, + org.dom4j.xpath, + org.dom4j.xpp, + org.openxmlformats.schemas.drawingml.x2006.main, + org.openxmlformats.schemas.drawingml.x2006.main.impl, + org.openxmlformats.schemas.drawingml.x2006.picture, + org.openxmlformats.schemas.drawingml.x2006.picture.impl, + org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing, + org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.impl, + org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing, + org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.impl, + org.openxmlformats.schemas.officeDocument.x2006.customProperties, + org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl, + org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes, + org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes.impl, + org.openxmlformats.schemas.officeDocument.x2006.extendedProperties, + org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl, + org.openxmlformats.schemas.officeDocument.x2006.relationships, + org.openxmlformats.schemas.officeDocument.x2006.relationships.impl, + org.openxmlformats.schemas.presentationml.x2006.main, + org.openxmlformats.schemas.presentationml.x2006.main.impl, + org.openxmlformats.schemas.spreadsheetml.x2006.main, + org.openxmlformats.schemas.spreadsheetml.x2006.main.impl, + org.openxmlformats.schemas.wordprocessingml.x2006.main, + org.openxmlformats.schemas.wordprocessingml.x2006.main.impl, + org.w3c.dom, + repackage, + schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707, + schemaorg_apache_xmlbeans.system.sXMLCONFIG, + schemaorg_apache_xmlbeans.system.sXMLLANG, + schemaorg_apache_xmlbeans.system.sXMLSCHEMA, + schemaorg_apache_xmlbeans.system.sXMLTOOLS, + schemasMicrosoftComOfficeExcel, + schemasMicrosoftComOfficeExcel.impl, + schemasMicrosoftComOfficeOffice, + schemasMicrosoftComOfficeOffice.impl, + schemasMicrosoftComVml, + schemasMicrosoftComVml.impl, + tcimporthistorydatas +Bundle-ClassPath: jxl.jar, + ., + log4j.jar, + poi-3.7-20101029.jar, + poi-examples-3.7-20101029.jar, + poi-ooxml-3.7-20101029.jar, + poi-ooxml-schemas-3.7-20101029.jar, + xmlbeans-2.3.0.jar, + dom4j-1.6.1.jar, + ojdbc6.jar diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..d0c0538 --- /dev/null +++ b/build.properties @@ -0,0 +1,14 @@ +source.. = src/ +output.. = classes/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + jxl.jar,\ + log4j.jar,\ + poi-3.7-20101029.jar,\ + poi-examples-3.7-20101029.jar,\ + poi-ooxml-3.7-20101029.jar,\ + poi-ooxml-schemas-3.7-20101029.jar,\ + xmlbeans-2.3.0.jar,\ + dom4j-1.6.1.jar,\ + ojdbc6.jar diff --git a/classes/com/connor/dev/imp/AbstractImportCommand$1.class b/classes/com/connor/dev/imp/AbstractImportCommand$1.class new file mode 100644 index 0000000..d4d21c2 Binary files /dev/null and b/classes/com/connor/dev/imp/AbstractImportCommand$1.class differ diff --git a/classes/com/connor/dev/imp/AbstractImportCommand.class b/classes/com/connor/dev/imp/AbstractImportCommand.class new file mode 100644 index 0000000..ae1acdc Binary files /dev/null and b/classes/com/connor/dev/imp/AbstractImportCommand.class differ diff --git a/classes/com/connor/dev/imp/AbstractImportDialog$1.class b/classes/com/connor/dev/imp/AbstractImportDialog$1.class new file mode 100644 index 0000000..ff059c6 Binary files /dev/null and b/classes/com/connor/dev/imp/AbstractImportDialog$1.class differ diff --git a/classes/com/connor/dev/imp/AbstractImportDialog.class b/classes/com/connor/dev/imp/AbstractImportDialog.class new file mode 100644 index 0000000..559ad26 Binary files /dev/null and b/classes/com/connor/dev/imp/AbstractImportDialog.class differ diff --git a/classes/com/connor/dev/imp/AbstractImportForProEDialog$1.class b/classes/com/connor/dev/imp/AbstractImportForProEDialog$1.class new file mode 100644 index 0000000..d754d8f Binary files /dev/null and b/classes/com/connor/dev/imp/AbstractImportForProEDialog$1.class differ diff --git a/classes/com/connor/dev/imp/AbstractImportForProEDialog.class b/classes/com/connor/dev/imp/AbstractImportForProEDialog.class new file mode 100644 index 0000000..5e0a2a6 Binary files /dev/null and b/classes/com/connor/dev/imp/AbstractImportForProEDialog.class differ diff --git a/classes/com/connor/dev/imp/DataBaseControl.class b/classes/com/connor/dev/imp/DataBaseControl.class new file mode 100644 index 0000000..339c385 Binary files /dev/null and b/classes/com/connor/dev/imp/DataBaseControl.class differ diff --git a/classes/com/connor/dev/imp/ImportFlex.class b/classes/com/connor/dev/imp/ImportFlex.class new file mode 100644 index 0000000..cd8edc2 Binary files /dev/null and b/classes/com/connor/dev/imp/ImportFlex.class differ diff --git a/classes/com/connor/dev/imp/ImportForProEFlex.class b/classes/com/connor/dev/imp/ImportForProEFlex.class new file mode 100644 index 0000000..83a978b Binary files /dev/null and b/classes/com/connor/dev/imp/ImportForProEFlex.class differ diff --git a/classes/com/connor/dev/imp/ImportSettings.class b/classes/com/connor/dev/imp/ImportSettings.class new file mode 100644 index 0000000..f8875e2 Binary files /dev/null and b/classes/com/connor/dev/imp/ImportSettings.class differ diff --git a/classes/com/connor/dev/imp/MappingAttribute.class b/classes/com/connor/dev/imp/MappingAttribute.class new file mode 100644 index 0000000..6e09284 Binary files /dev/null and b/classes/com/connor/dev/imp/MappingAttribute.class differ diff --git a/classes/com/connor/dev/imp/bom/BomsImportSettings.class b/classes/com/connor/dev/imp/bom/BomsImportSettings.class new file mode 100644 index 0000000..8b95508 Binary files /dev/null and b/classes/com/connor/dev/imp/bom/BomsImportSettings.class differ diff --git a/classes/com/connor/dev/imp/bom/ImportBomsCommand.class b/classes/com/connor/dev/imp/bom/ImportBomsCommand.class new file mode 100644 index 0000000..ed73075 Binary files /dev/null and b/classes/com/connor/dev/imp/bom/ImportBomsCommand.class differ diff --git a/classes/com/connor/dev/imp/bom/ImportBomsDialog.class b/classes/com/connor/dev/imp/bom/ImportBomsDialog.class new file mode 100644 index 0000000..fd3d1da Binary files /dev/null and b/classes/com/connor/dev/imp/bom/ImportBomsDialog.class differ diff --git a/classes/com/connor/dev/imp/bom/ImportBomsForProECommand.class b/classes/com/connor/dev/imp/bom/ImportBomsForProECommand.class new file mode 100644 index 0000000..14c586f Binary files /dev/null and b/classes/com/connor/dev/imp/bom/ImportBomsForProECommand.class differ diff --git a/classes/com/connor/dev/imp/bom/ImportBomsForProEDialog.class b/classes/com/connor/dev/imp/bom/ImportBomsForProEDialog.class new file mode 100644 index 0000000..22a5c13 Binary files /dev/null and b/classes/com/connor/dev/imp/bom/ImportBomsForProEDialog.class differ diff --git a/classes/com/connor/dev/imp/images/add.gif b/classes/com/connor/dev/imp/images/add.gif new file mode 100644 index 0000000..d66053c Binary files /dev/null and b/classes/com/connor/dev/imp/images/add.gif differ diff --git a/classes/com/connor/dev/imp/images/add_16.png b/classes/com/connor/dev/imp/images/add_16.png new file mode 100644 index 0000000..bc58bd7 Binary files /dev/null and b/classes/com/connor/dev/imp/images/add_16.png differ diff --git a/classes/com/connor/dev/imp/images/apply_16.png b/classes/com/connor/dev/imp/images/apply_16.png new file mode 100644 index 0000000..19f71f8 Binary files /dev/null and b/classes/com/connor/dev/imp/images/apply_16.png differ diff --git a/classes/com/connor/dev/imp/images/cancel_16.png b/classes/com/connor/dev/imp/images/cancel_16.png new file mode 100644 index 0000000..7186b3d Binary files /dev/null and b/classes/com/connor/dev/imp/images/cancel_16.png differ diff --git a/classes/com/connor/dev/imp/images/cancel_all_16.png b/classes/com/connor/dev/imp/images/cancel_all_16.png new file mode 100644 index 0000000..b43470e Binary files /dev/null and b/classes/com/connor/dev/imp/images/cancel_all_16.png differ diff --git a/classes/com/connor/dev/imp/images/excel_16.png b/classes/com/connor/dev/imp/images/excel_16.png new file mode 100644 index 0000000..f2d45cc Binary files /dev/null and b/classes/com/connor/dev/imp/images/excel_16.png differ diff --git a/classes/com/connor/dev/imp/images/import_16.png b/classes/com/connor/dev/imp/images/import_16.png new file mode 100644 index 0000000..9bc3b90 Binary files /dev/null and b/classes/com/connor/dev/imp/images/import_16.png differ diff --git a/classes/com/connor/dev/imp/images/open.gif b/classes/com/connor/dev/imp/images/open.gif new file mode 100644 index 0000000..7a1658c Binary files /dev/null and b/classes/com/connor/dev/imp/images/open.gif differ diff --git a/classes/com/connor/dev/imp/images/open_16.png b/classes/com/connor/dev/imp/images/open_16.png new file mode 100644 index 0000000..79f8d61 Binary files /dev/null and b/classes/com/connor/dev/imp/images/open_16.png differ diff --git a/classes/com/connor/dev/imp/images/refresh.GIF b/classes/com/connor/dev/imp/images/refresh.GIF new file mode 100644 index 0000000..7df56bb Binary files /dev/null and b/classes/com/connor/dev/imp/images/refresh.GIF differ diff --git a/classes/com/connor/dev/imp/images/refresh_16.png b/classes/com/connor/dev/imp/images/refresh_16.png new file mode 100644 index 0000000..e2798c0 Binary files /dev/null and b/classes/com/connor/dev/imp/images/refresh_16.png differ diff --git a/classes/com/connor/dev/imp/images/remove.gif b/classes/com/connor/dev/imp/images/remove.gif new file mode 100644 index 0000000..e0ced49 Binary files /dev/null and b/classes/com/connor/dev/imp/images/remove.gif differ diff --git a/classes/com/connor/dev/imp/images/remove_16.png b/classes/com/connor/dev/imp/images/remove_16.png new file mode 100644 index 0000000..4ff8845 Binary files /dev/null and b/classes/com/connor/dev/imp/images/remove_16.png differ diff --git a/classes/com/connor/dev/imp/images/save.gif b/classes/com/connor/dev/imp/images/save.gif new file mode 100644 index 0000000..e6ff1c4 Binary files /dev/null and b/classes/com/connor/dev/imp/images/save.gif differ diff --git a/classes/com/connor/dev/imp/images/save_16.png b/classes/com/connor/dev/imp/images/save_16.png new file mode 100644 index 0000000..57e15d9 Binary files /dev/null and b/classes/com/connor/dev/imp/images/save_16.png differ diff --git a/classes/com/connor/dev/imp/images/yes.gif b/classes/com/connor/dev/imp/images/yes.gif new file mode 100644 index 0000000..e6ee93d Binary files /dev/null and b/classes/com/connor/dev/imp/images/yes.gif differ diff --git a/classes/com/connor/dev/imp/ob/ImportObjectsCommand.class b/classes/com/connor/dev/imp/ob/ImportObjectsCommand.class new file mode 100644 index 0000000..9a37d3b Binary files /dev/null and b/classes/com/connor/dev/imp/ob/ImportObjectsCommand.class differ diff --git a/classes/com/connor/dev/imp/ob/ImportObjectsDialog.class b/classes/com/connor/dev/imp/ob/ImportObjectsDialog.class new file mode 100644 index 0000000..971c725 Binary files /dev/null and b/classes/com/connor/dev/imp/ob/ImportObjectsDialog.class differ diff --git a/classes/com/connor/dev/imp/ob/MappingButton.class b/classes/com/connor/dev/imp/ob/MappingButton.class new file mode 100644 index 0000000..5d165ee Binary files /dev/null and b/classes/com/connor/dev/imp/ob/MappingButton.class differ diff --git a/classes/com/connor/dev/imp/ob/ObjectsImportSettings.class b/classes/com/connor/dev/imp/ob/ObjectsImportSettings.class new file mode 100644 index 0000000..63599fe Binary files /dev/null and b/classes/com/connor/dev/imp/ob/ObjectsImportSettings.class differ diff --git a/classes/com/connor/dev/imp/ob/StaticEnum.class b/classes/com/connor/dev/imp/ob/StaticEnum.class new file mode 100644 index 0000000..3297c49 Binary files /dev/null and b/classes/com/connor/dev/imp/ob/StaticEnum.class differ diff --git a/classes/com/connor/dev/imp/project/ImportProjectAction.class b/classes/com/connor/dev/imp/project/ImportProjectAction.class new file mode 100644 index 0000000..a2a160c Binary files /dev/null and b/classes/com/connor/dev/imp/project/ImportProjectAction.class differ diff --git a/classes/com/connor/dev/imp/project/ImportProjectDialog$1.class b/classes/com/connor/dev/imp/project/ImportProjectDialog$1.class new file mode 100644 index 0000000..0211be2 Binary files /dev/null and b/classes/com/connor/dev/imp/project/ImportProjectDialog$1.class differ diff --git a/classes/com/connor/dev/imp/project/ImportProjectDialog$2.class b/classes/com/connor/dev/imp/project/ImportProjectDialog$2.class new file mode 100644 index 0000000..1fd32ea Binary files /dev/null and b/classes/com/connor/dev/imp/project/ImportProjectDialog$2.class differ diff --git a/classes/com/connor/dev/imp/project/ImportProjectDialog$3.class b/classes/com/connor/dev/imp/project/ImportProjectDialog$3.class new file mode 100644 index 0000000..6168282 Binary files /dev/null and b/classes/com/connor/dev/imp/project/ImportProjectDialog$3.class differ diff --git a/classes/com/connor/dev/imp/project/ImportProjectDialog.class b/classes/com/connor/dev/imp/project/ImportProjectDialog.class new file mode 100644 index 0000000..09e0b0f Binary files /dev/null and b/classes/com/connor/dev/imp/project/ImportProjectDialog.class differ diff --git a/classes/com/connor/dev/imp/re/ImportRelationsCommand.class b/classes/com/connor/dev/imp/re/ImportRelationsCommand.class new file mode 100644 index 0000000..9ab2bc1 Binary files /dev/null and b/classes/com/connor/dev/imp/re/ImportRelationsCommand.class differ diff --git a/classes/com/connor/dev/imp/re/ImportRelationsDialog.class b/classes/com/connor/dev/imp/re/ImportRelationsDialog.class new file mode 100644 index 0000000..e76f9d6 Binary files /dev/null and b/classes/com/connor/dev/imp/re/ImportRelationsDialog.class differ diff --git a/classes/com/connor/dev/imp/re/RelationsImportSettings.class b/classes/com/connor/dev/imp/re/RelationsImportSettings.class new file mode 100644 index 0000000..a37adc4 Binary files /dev/null and b/classes/com/connor/dev/imp/re/RelationsImportSettings.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportBOMsForProEHandler.class b/classes/com/connor/dev/imp/solution/handler/ImportBOMsForProEHandler.class new file mode 100644 index 0000000..749bb4d Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportBOMsForProEHandler.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportBOMsHandler.class b/classes/com/connor/dev/imp/solution/handler/ImportBOMsHandler.class new file mode 100644 index 0000000..e471450 Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportBOMsHandler.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportClassificationAction.class b/classes/com/connor/dev/imp/solution/handler/ImportClassificationAction.class new file mode 100644 index 0000000..5741140 Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportClassificationAction.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog$1.class b/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog$1.class new file mode 100644 index 0000000..5b5b53d Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog$1.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog$2.class b/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog$2.class new file mode 100644 index 0000000..17578b7 Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog$2.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog.class b/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog.class new file mode 100644 index 0000000..19ef99e Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportClassificationDialog.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportClassificationHandler.class b/classes/com/connor/dev/imp/solution/handler/ImportClassificationHandler.class new file mode 100644 index 0000000..8673ecc Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportClassificationHandler.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportObjectsHandler.class b/classes/com/connor/dev/imp/solution/handler/ImportObjectsHandler.class new file mode 100644 index 0000000..7539a4f Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportObjectsHandler.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportProjectHandler.class b/classes/com/connor/dev/imp/solution/handler/ImportProjectHandler.class new file mode 100644 index 0000000..9eee6fa Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportProjectHandler.class differ diff --git a/classes/com/connor/dev/imp/solution/handler/ImportRelationHandler.class b/classes/com/connor/dev/imp/solution/handler/ImportRelationHandler.class new file mode 100644 index 0000000..30d3daa Binary files /dev/null and b/classes/com/connor/dev/imp/solution/handler/ImportRelationHandler.class differ diff --git a/classes/com/connor/dev/imp/toolkit/JXLExcelParser.class b/classes/com/connor/dev/imp/toolkit/JXLExcelParser.class new file mode 100644 index 0000000..fc51d16 Binary files /dev/null and b/classes/com/connor/dev/imp/toolkit/JXLExcelParser.class differ diff --git a/classes/com/connor/dev/imp/toolkit/Logger.class b/classes/com/connor/dev/imp/toolkit/Logger.class new file mode 100644 index 0000000..8dfb2d0 Binary files /dev/null and b/classes/com/connor/dev/imp/toolkit/Logger.class differ diff --git a/classes/com/connor/dev/imp/toolkit/POIExcelParser.class b/classes/com/connor/dev/imp/toolkit/POIExcelParser.class new file mode 100644 index 0000000..372b40a Binary files /dev/null and b/classes/com/connor/dev/imp/toolkit/POIExcelParser.class differ diff --git a/classes/com/connor/dev/imp/toolkit/POIExcelUtil.class b/classes/com/connor/dev/imp/toolkit/POIExcelUtil.class new file mode 100644 index 0000000..a91c3bc Binary files /dev/null and b/classes/com/connor/dev/imp/toolkit/POIExcelUtil.class differ diff --git a/classes/com/connor/dev/imp/toolkit/ProgressReporter.class b/classes/com/connor/dev/imp/toolkit/ProgressReporter.class new file mode 100644 index 0000000..e775226 Binary files /dev/null and b/classes/com/connor/dev/imp/toolkit/ProgressReporter.class differ diff --git a/classes/com/connor/dev/imp/toolkit/SearchUtility.class b/classes/com/connor/dev/imp/toolkit/SearchUtility.class new file mode 100644 index 0000000..ef1dd92 Binary files /dev/null and b/classes/com/connor/dev/imp/toolkit/SearchUtility.class differ diff --git a/classes/com/connor/dev/test/ImporttestHandler.class b/classes/com/connor/dev/test/ImporttestHandler.class new file mode 100644 index 0000000..edbde8e Binary files /dev/null and b/classes/com/connor/dev/test/ImporttestHandler.class differ diff --git a/classes/tcimporthistorydatas/Activator.class b/classes/tcimporthistorydatas/Activator.class new file mode 100644 index 0000000..bd5817a Binary files /dev/null and b/classes/tcimporthistorydatas/Activator.class differ diff --git a/dom4j-1.6.1.jar b/dom4j-1.6.1.jar new file mode 100644 index 0000000..c8c4dbb Binary files /dev/null and b/dom4j-1.6.1.jar differ diff --git a/jxl.jar b/jxl.jar new file mode 100644 index 0000000..b210c06 Binary files /dev/null and b/jxl.jar differ diff --git a/log4j.jar b/log4j.jar new file mode 100644 index 0000000..be4a917 Binary files /dev/null and b/log4j.jar differ diff --git a/ojdbc6.jar b/ojdbc6.jar new file mode 100644 index 0000000..ec3d6f1 Binary files /dev/null and b/ojdbc6.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..288e39c --- /dev/null +++ b/plugin.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/poi-3.7-20101029.jar b/poi-3.7-20101029.jar new file mode 100644 index 0000000..a08d953 Binary files /dev/null and b/poi-3.7-20101029.jar differ diff --git a/poi-examples-3.7-20101029.jar b/poi-examples-3.7-20101029.jar new file mode 100644 index 0000000..914243d Binary files /dev/null and b/poi-examples-3.7-20101029.jar differ diff --git a/poi-ooxml-3.7-20101029.jar b/poi-ooxml-3.7-20101029.jar new file mode 100644 index 0000000..5f36eb4 Binary files /dev/null and b/poi-ooxml-3.7-20101029.jar differ diff --git a/poi-ooxml-schemas-3.7-20101029.jar b/poi-ooxml-schemas-3.7-20101029.jar new file mode 100644 index 0000000..82282b5 Binary files /dev/null and b/poi-ooxml-schemas-3.7-20101029.jar differ diff --git a/src/com/connor/dev/imp/AbstractImportCommand.java b/src/com/connor/dev/imp/AbstractImportCommand.java new file mode 100644 index 0000000..59d551b --- /dev/null +++ b/src/com/connor/dev/imp/AbstractImportCommand.java @@ -0,0 +1,77 @@ +package com.connor.dev.imp; + +import com.connor.dev.imp.ob.ImportObjectsCommand; +import com.connor.dev.imp.toolkit.ProgressReporter; +import com.teamcenter.rac.aif.AbstractAIFCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public abstract class AbstractImportCommand extends AbstractAIFCommand { + protected TCSession session; + protected boolean isExec; + + public AbstractImportCommand(AbstractAIFUIApplication application, + boolean isExec) { + this.session = (TCSession) application.getSession(); + this.isExec = isExec; + processImporting(); + } + + public AbstractImportCommand(AbstractAIFUIApplication application) { + this.session = (TCSession) application.getSession(); + + processImporting(); + } + + private void processImporting() { + + InterfaceAIFComponent targetCom = null; + if (isExec) { + try { + targetCom = this.session.getUser().getNewStuffFolder(); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + targetCom = AIFUtility.getCurrentApplication() + + .getTargetComponent(); + } + // ѡ빦ǰѡijļ + if (this instanceof ImportObjectsCommand) { + if (!(targetCom instanceof TCComponentFolder)) { + MessageBox msg = new MessageBox("ʧ", + "ʾ:\nѡļУȻִе룡\n", "ִд", 1, true); + msg.setVisible(true); + return; + } + } + + final ProgressReporter reporter = new ProgressReporter(); + reporter.reportProgressMessage("ڳʼ,Ժ..."); + new Thread(reporter).start(); + new Thread(new Runnable() { + public void run() { + while (!reporter.isRequestCanceling()) { + reporter.setProgressPercent(reporter.getProgess() + 5); + + try { + Thread.sleep(500); + } catch (InterruptedException e) { + continue; + } + } + } + }).start(); + importHistoryDatas(); + reporter.requestCanceling(); + } + + protected abstract void importHistoryDatas(); +} diff --git a/src/com/connor/dev/imp/AbstractImportDialog.java b/src/com/connor/dev/imp/AbstractImportDialog.java new file mode 100644 index 0000000..c0a4395 --- /dev/null +++ b/src/com/connor/dev/imp/AbstractImportDialog.java @@ -0,0 +1,783 @@ +package com.connor.dev.imp; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import jxl.Cell; +import jxl.Sheet; +import jxl.Workbook; +import jxl.read.biff.BiffException; + +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.connor.dev.imp.ob.StaticEnum; +import com.connor.dev.imp.toolkit.ProgressReporter; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.common.TCUtilities; +import com.teamcenter.rac.common.create.DisplayTypeInfo; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.util.AIFImageIcon; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; + +public abstract class AbstractImportDialog extends AbstractAIFDialog implements + ActionListener, ChangeListener, ListSelectionListener { + private static final long serialVersionUID = 1L; + private JTextField filePathField; + public JButton browse; + // private JTextField logPathField; + protected JTextField dateFormatField; + // protected JTextField arraySepField; + protected JList excelList; + + protected DefaultListModel excelListModel; + + protected JList[] propertiesList; + + protected JList[] mappingList; + + protected DefaultListModel[] propertiesListModels; + + protected DefaultListModel[] mappingListModels; + + protected JTabbedPane rightPane; + + public JButton add; + + public JButton remove; + + public JButton execute; + public JButton unlock; + public JButton save; + public JButton open; + protected TCSession session; + protected JFileChooser chooser; + protected File importFile; + private ProgressReporter reporter; + + protected int locationTemp = -2;// · + protected int typeIndex = -2;// + protected int relIndex = -2;// ϵ + + public String exportFilePath; + public String settingFilePath; + public boolean isExec = false; + + public AbstractImportDialog(TCSession session, String title, boolean modal, + String exportFilePath, String settingFilePath, boolean isExec) { + + this(session, title, modal); + this.isExec = isExec; + this.exportFilePath = exportFilePath; + this.settingFilePath = settingFilePath; + StaticEnum.isExec = true; + } + + public AbstractImportDialog(TCSession session, String title, boolean modal) { + super(modal); + this.session = session; + chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setMultiSelectionEnabled(false); + StaticEnum.isExec = false; + setTitle(title); + // setResizable(false); + setLayout(new BorderLayout()); + initializeUI(); + setComponentsTextProperty(); + addUIComponents(); + registerActionComponents(); + } + + protected void initializeUI() { + filePathField = new JTextField(30); + filePathField.setEditable(false); + + browse = new JButton(); + + // logPathField = new JTextField(30); + + dateFormatField = new JTextField(30); + // arraySepField = new JTextField(5); + + excelListModel = new DefaultListModel(); + excelList = new JList(excelListModel); + excelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + rightPane = new JTabbedPane(); + + System.out.println("this.getClass().getSimpleName()===" + + this.getClass().getSimpleName()); + if (this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + add = new JButton(AIFImageIcon.getImageIcon(this, + "images/cancel_16.png")); + add.setEnabled(false); + remove = new JButton(AIFImageIcon.getImageIcon(this, + "images/cancel_all_16.png")); + remove.setEnabled(false); + // remove.setVisible(false); + } else { + add = new JButton(AIFImageIcon.getImageIcon(this, + "images/add_16.png")); + add.setEnabled(false); + + remove = new JButton(AIFImageIcon.getImageIcon(this, + "images/remove_16.png")); + remove.setEnabled(false); + } + execute = new JButton(AIFImageIcon.getImageIcon(this, + "images/import_16.png")); + execute.setEnabled(false); + + unlock = new JButton(AIFImageIcon.getImageIcon(this, + "images/apply_16.png")); + + save = new JButton( + AIFImageIcon.getImageIcon(this, "images/save_16.png")); + + open = new JButton( + AIFImageIcon.getImageIcon(this, "images/open_16.png")); + + reporter = new ProgressReporter(); + } + + /** + * browse->open->unlock->execute + */ + protected void setComponentsTextProperty() { + browse.setText("..."); + execute.setToolTipText("ִе"); + unlock.setToolTipText(""); + save.setToolTipText(""); + open.setToolTipText(""); + + if (this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + add.setToolTipText(""); + remove.setToolTipText(""); + } else { + add.setToolTipText("ӳ"); + remove.setToolTipText("Ƴӳ"); + } + + dateFormatField.setText("yyyy-MM-dd HH:mm:ss"); + dateFormatField.setToolTipText("ڸʽ,ִСд"); + + // doPurgeComponentProperties(""); + } + + protected void registerActionComponents() { + add.addActionListener(this); + remove.addActionListener(this); + rightPane.addChangeListener(this); + + execute.addActionListener(this); + unlock.addActionListener(this); + save.addActionListener(this); + open.addActionListener(this); + browse.addActionListener(this); + + for (int i = 0; i < propertiesList.length; i++) { + propertiesList[i].addListSelectionListener(this); + mappingList[i].addListSelectionListener(this); + } + + excelList.addListSelectionListener(this); + } + + protected void addUIComponents() { + JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + topPanel.add(new JLabel("ļ")); + topPanel.add(filePathField); + topPanel.add(browse); + // topPanel.add(new JLabel("־ļ")); + // topPanel.add(logPathField); + + JPanel raPanel = new JPanel(new FlowLayout()); + raPanel.add(add); + raPanel.add(remove); + + JPanel rightPanel = new JPanel(new BorderLayout()); + rightPanel.add(rightPane, BorderLayout.CENTER); + rightPanel.add(raPanel, BorderLayout.SOUTH); + + JSplitPane centerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + centerPanel.setDividerLocation(120); + centerPanel.setContinuousLayout(true); + centerPanel.setLeftComponent(new JScrollPane(excelList)); + + addTabbedPaneComponents(); + + centerPanel.setRightComponent(rightPanel); + + JPanel bottomPanel = new JPanel(new FlowLayout()); + bottomPanel.add(execute); + bottomPanel.add(unlock); + bottomPanel.add(save); + bottomPanel.add(open); + + add(topPanel, BorderLayout.NORTH); + add(centerPanel, BorderLayout.CENTER); + add(bottomPanel, BorderLayout.SOUTH); + } + + protected abstract void addTabbedPaneComponents(); + + protected JPanel getParameterPanel() { + JPanel p = new JPanel(new PropertyLayout()); + p.add("1.1.right.top.preferred.preferred", new JLabel("ڸʽ:")); + p.add("1.2.left.top.preferred.preferred", dateFormatField); + // p.add("2.1.right.top.preferred.preferred", new JLabel("ݷָ:")); + // p.add("2.2.left.top.preferred.preferred", arraySepField); + + return p; + } + + protected String[] getTCComponentProperties(String name) { + String[] properties = null; + try { + TCTypeService typeService = session.getTypeService(); + TCComponentType typeComponent = typeService.getTypeComponent(name); + properties = typeComponent.getPropertyNames(); + } catch (TCException e) { + e.printStackTrace(); + } + + return properties; + } + + protected void populateTypeChoices(String name, JComboBox box) { + try { + TCTypeService service = session.getTypeService(); + TCComponentType[] items = service.getTypes(name); + if (items != null) { + for (int i = 0; i < items.length; i++) { + String item = items[i].toString(); + + if ("EngChange".equalsIgnoreCase(item)) { + continue; + } + // System.out.println(items[i].toString()); + box.addItem(items[i].toString()); + + // TCComponentItemType + // TCComponentType[] sub = items[i].isTypeOf(s); + System.out.println("d"); + // AIFComponentContext[] aifcs = items[i].getChildren(); + // for (AIFComponentContext aifc : aifcs) + // { + // InterfaceAIFComponent com = aifc.getComponent(); + // System.out.println(com.getClass()); + // } + } + } + } catch (TCException e) { + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see + * javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event + * .ListSelectionEvent) + */ + public void valueChanged(ListSelectionEvent listselectionevent) { + checkMappingsEditable(); + } + + protected void checkMappingsEditable() { + int index = rightPane.getSelectedIndex(); + if (index < propertiesList.length) { + add.setEnabled(excelList.getSelectedIndex() != -1 + && propertiesList[index].getSelectedIndex() != -1); + remove.setEnabled(mappingList[index].getSelectedIndex() != -1); + } else { + if (this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + add.setEnabled(true); + remove.setEnabled(true); + } else { + add.setEnabled(false); + remove.setEnabled(false); + } + } + } + + protected void doPurgeComponentProperties(String name) { + for (int i = 0; i < propertiesList.length - 1; i++) { + propertiesListModels[i].removeAllElements(); + mappingListModels[i].removeAllElements(); + } + } + + protected void doPurgeComponentProperties2(String name) { + for (int i = 0; i < propertiesList.length - 1; i++) { + propertiesListModels[i].removeAllElements(); + mappingListModels[i].removeAllElements(); + } + } + + /* + * (non-Javadoc) + * + * @see + * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent ae) { + + if (ae.getSource() == add) { + if (!this.getClass().getSimpleName() + .equals("ImportRelationsDialog")) { + String excel = excelList.getSelectedValue().toString(); + int index = excelList.getSelectedIndex(); + String prop = propertiesList[rightPane.getSelectedIndex()] + .getSelectedValue().toString(); + + MappingAttribute ma = new MappingAttribute(index, excel, prop); + if (rightPane.getSelectedIndex() == 3) { + // TODO ⴦ · + if (!mappingListModels[rightPane.getSelectedIndex()] + .contains(ma)) { + mappingListModels[rightPane.getSelectedIndex()] + .addElement(ma); + System.out.println("ADD_MSG = >>" + index + "/" + excel + + "/" + prop); + if (prop.equals("·")) { + locationTemp = index; + } + } else if (!prop.equals("·")) {// ֻһ·ȴж + mappingListModels[rightPane.getSelectedIndex()] + .addElement(ma); + } + } else if (rightPane.getSelectedIndex() == 0) { + // TODO ͵⴦ + if (!mappingListModels[rightPane.getSelectedIndex()] + .contains(ma)) { + mappingListModels[rightPane.getSelectedIndex()] + .addElement(ma); + System.out.println("ADD_MSG = >>" + index + "/" + excel + + "/" + prop); + if (prop.equals("")) { + typeIndex = index; + } + } + } else { + // TODO 洦 + if (!mappingListModels[rightPane.getSelectedIndex()] + .contains(ma)) { + mappingListModels[rightPane.getSelectedIndex()] + .addElement(ma); + } + } + + } + } else if (ae.getSource() == remove) { + if (!this.getClass().getSimpleName() + .equals("ImportRelationsDialog")) { + // · + if (rightPane.getSelectedIndex() == 3) { + int temp_index = ((MappingAttribute) mappingListModels[rightPane + .getSelectedIndex()].get(mappingList[rightPane + .getSelectedIndex()].getSelectedIndex())) + .getColumnIndex(); + if (temp_index == locationTemp) { + locationTemp = -2; + System.out.println("Ƴ·"); + } + + } else if (rightPane.getSelectedIndex() == 0) { + int temp_index = ((MappingAttribute) mappingListModels[rightPane + .getSelectedIndex()].get(mappingList[rightPane + .getSelectedIndex()].getSelectedIndex())) + .getColumnIndex(); + if (temp_index == typeIndex) { + typeIndex = -2; + System.out.println("Ƴ"); + } + } + mappingListModels[rightPane.getSelectedIndex()] + .remove(mappingList[rightPane.getSelectedIndex()] + .getSelectedIndex()); + + } + } else if (ae.getSource() == execute) { + executeImport(); + } else if (ae.getSource() == unlock) { + excelList.setEnabled(true); + for (int i = 0; i < propertiesList.length; i++) { + propertiesList[i].setEnabled(true); + mappingList[i].setEnabled(true); + } + } else if (ae.getSource() == open) { + if (filePathField.getText().trim().length() == 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ѡҪļ", "", 1); + } else { + openImportSettings(); + } + } else if (ae.getSource() == save) { + saveImportSettings(); + } else if (ae.getSource() == browse) { + selectImportFile(); + } + } + + /** + * ѡļ + * + */ + private void selectImportFile() { + excelListModel.removeAllElements(); + + if (this.isExec) { + importFile = new File(this.exportFilePath);// chooser.getSelectedFile(); + if (importFile != null) { + + if (importFile.exists() && importFile.isFile()) { + if (importFile.getAbsolutePath().endsWith(".xls")) { + try { + Workbook workbook = Workbook + .getWorkbook(importFile); + Sheet sheet = workbook.getSheet(0); + Cell[] row = sheet.getRow(0); + for (int i = 0; i < row.length; i++) { + if (row[i].getContents().trim().equals("")) { + excelListModel.addElement("(Ϊ)"); + } else { + excelListModel.addElement(row[i] + .getContents()); + } + } + workbook.close(); + filePathField.setText(importFile.getAbsolutePath()); + execute.setEnabled(true); + + return; + } catch (BiffException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } else if (importFile.getAbsolutePath().endsWith(".xlsx")) { + try { + org.apache.poi.ss.usermodel.Workbook workbook = new XSSFWorkbook( + new FileInputStream(importFile)); + org.apache.poi.ss.usermodel.Sheet sheet = workbook + .getSheetAt(0); + Row row = sheet.getRow(0); + for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { + if (!row.getCell(i).getStringCellValue().trim() + .equals("")) { + excelListModel.addElement(row.getCell(i) + .getStringCellValue()); + } + // else { + // excelListModel.addElement("(Ϊ)"); + // } + } + filePathField.setText(importFile.getAbsolutePath()); + execute.setEnabled(true); + + return; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + } else { + + if (chooser.showOpenDialog(null) == 0) { + + importFile = chooser.getSelectedFile(); + if (importFile != null) { + + if (importFile.exists() && importFile.isFile()) { + if (importFile.getAbsolutePath().endsWith(".xls")) { + try { + Workbook workbook = Workbook + .getWorkbook(importFile); + Sheet sheet = workbook.getSheet(0); + Cell[] row = sheet.getRow(0); + for (int i = 0; i < row.length; i++) { + if (row[i].getContents().trim().equals("")) { + excelListModel.addElement("(Ϊ)"); + } else { + excelListModel.addElement(row[i] + .getContents()); + } + } + workbook.close(); + filePathField.setText(importFile + .getAbsolutePath()); + execute.setEnabled(true); + + return; + } catch (BiffException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } else if (importFile.getAbsolutePath().endsWith( + ".xlsx")) { + try { + org.apache.poi.ss.usermodel.Workbook workbook = new XSSFWorkbook( + new FileInputStream(importFile)); + org.apache.poi.ss.usermodel.Sheet sheet = workbook + .getSheetAt(0); + Row row = sheet.getRow(0); + for (int i = 0; i < row + .getPhysicalNumberOfCells(); i++) { + if (!row.getCell(i).getStringCellValue() + .trim().equals("")) { + excelListModel.addElement(row + .getCell(i) + .getStringCellValue()); + } + // else { + // excelListModel.addElement("(Ϊ)"); + // } + } + filePathField.setText(importFile + .getAbsolutePath()); + execute.setEnabled(true); + + return; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + } + + } + + execute.setEnabled(false); + } + + private void executeImport() { + if (checkNecessaryCondition()) { + setVisible(false); + + reporter.reportProgressMessage("ڵ,Ժ..."); + new Thread(reporter).start(); + + new Thread() { + public void run() { + try { + // callUserServices(session, "1", "ORIGIN_set_bypass"); + ImportFlex flex = new ImportFlex(session, reporter); + // ˴Ӷݼ·Ĵ + flex.locationIndex = locationTemp; + // ˴ӶԶ͵⴦ + flex.typeIndex = typeIndex; + + flex.runImporting(generateImportSettings(), new File( + filePathField.getText())); + // callUserServices(session, "1", + // "ORIGIN_close_bypass"); + reporter.requestCanceling(); + dispose(); + if (flex.logpath.equals("")) { + MessageBox.post(AIFDesktop.getActiveDesktop() + .getShell(), "ݵɣ\n\nɹ : " + + flex.success + "\nʧ : " + flex.fail, + "", MessageBox.INFORMATION); + } else { + MessageBox.post(AIFDesktop.getActiveDesktop() + .getShell(), "ݵɣ\n\nɹ : " + + flex.success + "\nʧ : " + flex.fail + + "\n־·" + flex.logpath, "", + MessageBox.ERROR); + } + + } catch (Throwable e) { + e.printStackTrace(); + + reporter.requestCanceling(); + MessageBox.post(AIFDesktop.getActiveDesktop() + .getShell(), "ʧ", "", 1); + setVisible(true); + } + } + }.start(); + } + } + + protected boolean checkNecessaryCondition() { + return true; + } + + protected abstract void openImportSettings(); + + protected abstract void saveImportSettings(); + + public abstract ImportSettings generateImportSettings(); + + protected void populateItemTypes(JComboBox box) { + // BaseClassInput[] abaseclassinput = new + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput[4]; + // for (int i = 0; i < 4; i++) + // abaseclassinput[i] = new + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput(); + // + // abaseclassinput[0].baseClass = "Item"; + // abaseclassinput[0].exclusionTypes = new String[] {}; + // abaseclassinput[1].baseClass = "MEProcess"; + // abaseclassinput[2].baseClass = "MEOP"; + // abaseclassinput[3].baseClass = "MEWorkarea"; + // + // com.teamcenter.services.rac.core._2007_06.DataManagement.GetAvailableTypesResponse + // getavailabletypesresponse + // = TCUtilities + // .getDisplayableTypeNames(session, abaseclassinput); + // Map map = getavailabletypesresponse.inputClassToTypes; + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput + // abaseclassinput1[] = abaseclassinput; + // int j = abaseclassinput1.length; + // for (int k = 0; k < j; k++) + // { + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput + // baseclassinput = abaseclassinput1[k]; + // com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo + // aavailabletypeinfo[] = + // (com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo[]) + // map + // .get(baseclassinput.baseClass); + // com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo + // aavailabletypeinfo1[] = + // aavailabletypeinfo; + // int l = aavailabletypeinfo1.length; + // for (int i1 = 0; i1 < l; i1++) + // { + // com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo + // availabletypeinfo = + // aavailabletypeinfo1[i1]; + // box.addItem(availabletypeinfo.type); + // } + // + // } + // + // if (getavailabletypesresponse.serviceData.sizeOfPartialErrors() > 0) + // { + // TCException tcexception = + // SoaUtil.checkPartialErrorsNoThrow(getavailabletypesresponse.serviceData); + // MessageBox.post(Utilities.getParentFrame(this), tcexception); + // } + + String[] types = new String[] { "Item", "MEProcess", "MEOP", + + "CompanyLocation", "CompanyContact" }; + + List datas = new ArrayList(); + + Map> map = new HashMap>( + types.length); + for (String string : types) { + map.put(string, new ArrayList()); + } + if (map != null && map.size() > 0) { + Map> map1 = TCUtilities + .getDisplayableTypeNamesWithHierarchyInfo(session, map); + if (map1 != null && !map1.isEmpty()) { + Iterator>> iterator = map1 + .entrySet().iterator(); + do { + if (!iterator.hasNext()) + break; + Entry> entry = iterator + .next(); + List list = entry.getValue(); + if (list != null && !list.isEmpty()) { + Iterator iterator1 = list.iterator(); + while (iterator1.hasNext()) { + DisplayTypeInfo displaytypeinfo = (DisplayTypeInfo) iterator1 + .next(); + if (!datas.contains(displaytypeinfo.getTypeName())) + datas.add(displaytypeinfo.getTypeName()); + } + } + } while (true); + } + } + Collections.sort(datas); + + box.setModel(new DefaultComboBoxModel(datas.toArray(new String[datas + .size()]))); + + } + + public static void main(String[] args) { + org.apache.poi.ss.usermodel.Workbook workbook; + try { + workbook = new XSSFWorkbook( + new FileInputStream( + "C:\\Users\\Administrator.SD-20101212HAVL\\Desktop\\123.xlsx")); + org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0); + System.out.println(sheet.getPhysicalNumberOfRows()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static Object callUserServices(TCSession session, Object target, + String str_userServiceName) { + Object[] obj = new Object[1]; + obj[0] = target; + Object robj = null; + try { + robj = session.getUserService().call(str_userServiceName, obj); + return robj; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/src/com/connor/dev/imp/AbstractImportForProEDialog.java b/src/com/connor/dev/imp/AbstractImportForProEDialog.java new file mode 100644 index 0000000..f1979f4 --- /dev/null +++ b/src/com/connor/dev/imp/AbstractImportForProEDialog.java @@ -0,0 +1,587 @@ +package com.connor.dev.imp; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import jxl.Cell; +import jxl.Sheet; +import jxl.Workbook; +import jxl.read.biff.BiffException; + +import com.connor.dev.imp.toolkit.ProgressReporter; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.common.TCUtilities; +import com.teamcenter.rac.common.create.DisplayTypeInfo; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.util.AIFImageIcon; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; + +public abstract class AbstractImportForProEDialog extends AbstractAIFDialog implements ActionListener, ChangeListener, ListSelectionListener { + private static final long serialVersionUID = 1L; + + private JTextField filePathField; + + private JButton browse; + + // private JTextField logPathField; + + protected JTextField dateFormatField; + + // protected JTextField arraySepField; + + protected JList excelList; + + protected DefaultListModel excelListModel; + + protected JList[] propertiesList; + + protected JList[] mappingList; + + protected DefaultListModel[] propertiesListModels; + + protected DefaultListModel[] mappingListModels; + + protected JTabbedPane rightPane; + + protected JButton add; + + protected JButton remove; + + protected JButton execute; + + protected JButton unlock; + + protected JButton save; + + protected JButton open; + + protected TCSession session; + + protected JFileChooser chooser; + + protected File importFile; + + private ProgressReporter reporter; + + public AbstractImportForProEDialog(TCSession session, String title, boolean modal) { + super(modal); + + this.session = session; + chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setMultiSelectionEnabled(false); + + setTitle(title); + // setResizable(false); + setLayout(new BorderLayout()); + + initializeUI(); + setComponentsTextProperty(); + addUIComponents(); + registerActionComponents(); + } + + protected void initializeUI() { + filePathField = new JTextField(30); + filePathField.setEditable(false); + + browse = new JButton(); + + // logPathField = new JTextField(30); + + dateFormatField = new JTextField(30); + // arraySepField = new JTextField(5); + + excelListModel = new DefaultListModel(); + excelList = new JList(excelListModel); + excelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + rightPane = new JTabbedPane(); + + System.out.println("this.getClass().getSimpleName()===" + this.getClass().getSimpleName()); + if (this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + add = new JButton(AIFImageIcon.getImageIcon(this, "images/cancel_16.png")); + add.setEnabled(false); + remove = new JButton(AIFImageIcon.getImageIcon(this, "images/cancel_all_16.png")); + remove.setEnabled(false); + // remove.setVisible(false); + } else { + add = new JButton(AIFImageIcon.getImageIcon(this, "images/add_16.png")); + add.setEnabled(false); + + remove = new JButton(AIFImageIcon.getImageIcon(this, "images/remove_16.png")); + remove.setEnabled(false); + } + execute = new JButton(AIFImageIcon.getImageIcon(this, "images/import_16.png")); + execute.setEnabled(false); + + unlock = new JButton(AIFImageIcon.getImageIcon(this, "images/apply_16.png")); + + save = new JButton(AIFImageIcon.getImageIcon(this, "images/save_16.png")); + + open = new JButton(AIFImageIcon.getImageIcon(this, "images/open_16.png")); + + reporter = new ProgressReporter(); + } + + protected void setComponentsTextProperty() { + browse.setText("..."); + execute.setToolTipText("ִе"); + unlock.setToolTipText(""); + save.setToolTipText(""); + open.setToolTipText(""); + + if (this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + add.setToolTipText(""); + remove.setToolTipText(""); + }else + { + add.setToolTipText("ӳ"); + remove.setToolTipText("Ƴӳ"); + } + + + dateFormatField.setText("yyyy-MM-dd HH:mm:ss"); + dateFormatField.setToolTipText("ڸʽ,ִСд
    " + "
  • y
  • " + "
  • M
  • " + "
  • d
  • " + "
  • " + "
  • m
  • " + "
  • s
  • " + "
"); + + // doPurgeComponentProperties(""); + } + + protected void registerActionComponents() { + add.addActionListener(this); + remove.addActionListener(this); + rightPane.addChangeListener(this); + + execute.addActionListener(this); + unlock.addActionListener(this); + save.addActionListener(this); + open.addActionListener(this); + browse.addActionListener(this); + + for (int i = 0; i < propertiesList.length; i++) { + propertiesList[i].addListSelectionListener(this); + mappingList[i].addListSelectionListener(this); + } + + excelList.addListSelectionListener(this); + } + + protected void addUIComponents() { + JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + topPanel.add(new JLabel("ļ")); + topPanel.add(filePathField); + topPanel.add(browse); + // topPanel.add(new JLabel("־ļ")); + // topPanel.add(logPathField); + + JPanel raPanel = new JPanel(new FlowLayout()); + raPanel.add(add); + raPanel.add(remove); + + JPanel rightPanel = new JPanel(new BorderLayout()); + rightPanel.add(rightPane, BorderLayout.CENTER); + rightPanel.add(raPanel, BorderLayout.SOUTH); + + JSplitPane centerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + centerPanel.setDividerLocation(120); + centerPanel.setContinuousLayout(true); + centerPanel.setLeftComponent(new JScrollPane(excelList)); + + addTabbedPaneComponents(); + + centerPanel.setRightComponent(rightPanel); + + JPanel bottomPanel = new JPanel(new FlowLayout()); + bottomPanel.add(execute); + bottomPanel.add(unlock); + bottomPanel.add(save); + bottomPanel.add(open); + + add(topPanel, BorderLayout.NORTH); + add(centerPanel, BorderLayout.CENTER); + add(bottomPanel, BorderLayout.SOUTH); + } + + protected abstract void addTabbedPaneComponents(); + + protected JPanel getParameterPanel() { + JPanel p = new JPanel(new PropertyLayout()); + p.add("1.1.right.top.preferred.preferred", new JLabel("ڸʽ:")); + p.add("1.2.left.top.preferred.preferred", dateFormatField); + // p.add("2.1.right.top.preferred.preferred", new JLabel("ݷָ:")); + // p.add("2.2.left.top.preferred.preferred", arraySepField); + + return p; + } + + protected String[] getTCComponentProperties(String name) { + String[] properties = null; + try { + TCTypeService typeService = session.getTypeService(); + TCComponentType typeComponent = typeService.getTypeComponent(name); + properties = typeComponent.getPropertyNames(); + } catch (TCException e) { + e.printStackTrace(); + } + + return properties; + } + + protected void populateTypeChoices(String name, JComboBox box) { + try { + TCTypeService service = session.getTypeService(); + TCComponentType[] items = service.getTypes(name); + if (items != null) { + for (int i = 0; i < items.length; i++) { + String item = items[i].toString(); + + if ("EngChange".equalsIgnoreCase(item)) { + continue; + } + // System.out.println(items[i].toString()); + box.addItem(items[i].toString()); + + // TCComponentItemType + // TCComponentType[] sub = items[i].isTypeOf(s); + System.out.println("d"); + // AIFComponentContext[] aifcs = items[i].getChildren(); + // for (AIFComponentContext aifc : aifcs) + // { + // InterfaceAIFComponent com = aifc.getComponent(); + // System.out.println(com.getClass()); + // } + } + } + } catch (TCException e) { + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * @see + * javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event + * .ListSelectionEvent) + */ + public void valueChanged(ListSelectionEvent listselectionevent) { + checkMappingsEditable(); + } + + protected void checkMappingsEditable() { + int index = rightPane.getSelectedIndex(); + if (index < propertiesList.length) { + add.setEnabled(excelList.getSelectedIndex() != -1 && propertiesList[index].getSelectedIndex() != -1); + remove.setEnabled(mappingList[index].getSelectedIndex() != -1); + } else { + if (this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + add.setEnabled(true); + remove.setEnabled(true); + } else { + add.setEnabled(false); + remove.setEnabled(false); + } + } + } + + protected void doPurgeComponentProperties(String name) { + for (int i = 0; i < propertiesList.length - 1; i++) { + propertiesListModels[i].removeAllElements(); + mappingListModels[i].removeAllElements(); + } + } + + /* + * (non-Javadoc) + * @see + * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent ae) { + + if (ae.getSource() == add) { + if (!this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + String excel = excelList.getSelectedValue().toString(); + int index = excelList.getSelectedIndex(); + String prop = propertiesList[rightPane.getSelectedIndex()].getSelectedValue().toString(); + + MappingAttribute ma = new MappingAttribute(index, excel, prop); + if (!mappingListModels[rightPane.getSelectedIndex()].contains(ma)) { + mappingListModels[rightPane.getSelectedIndex()].addElement(ma); + } + } + } else if (ae.getSource() == remove) { + if (!this.getClass().getSimpleName().equals("ImportRelationsDialog")) { + mappingListModels[rightPane.getSelectedIndex()].remove(mappingList[rightPane.getSelectedIndex()].getSelectedIndex()); + } + } else if (ae.getSource() == execute) { + executeImport(); + } else if (ae.getSource() == unlock) { + excelList.setEnabled(true); + for (int i = 0; i < propertiesList.length; i++) { + propertiesList[i].setEnabled(true); + mappingList[i].setEnabled(true); + } + } else if (ae.getSource() == open) { + if (filePathField.getText().trim().length() == 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ѡҪļ", "", 1); + } else { + openImportSettings(); + } + } else if (ae.getSource() == save) { + saveImportSettings(); + } else if (ae.getSource() == browse) { + selectImportFile(); + } + } + + private void selectImportFile() { + excelListModel.removeAllElements(); + + if (chooser.showOpenDialog(null) == 0) { + importFile = chooser.getSelectedFile(); + if (importFile != null) { + + if(importFile.exists()&&importFile.isFile()){ + if(importFile.getAbsolutePath().endsWith(".xls")){ + try { + Workbook workbook = Workbook.getWorkbook(importFile); + Sheet sheet = workbook.getSheet(0); + Cell[] row = sheet.getRow(0); + for (int i = 0; i < row.length; i++) { + if (row[i].getContents().trim().equals("")) { + excelListModel.addElement("(Ϊ)"); + } else { + excelListModel.addElement(row[i].getContents()); + } + } + workbook.close(); + filePathField.setText(importFile.getAbsolutePath()); + execute.setEnabled(true); + + return; + } catch (BiffException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + }else if(importFile.getAbsolutePath().endsWith(".xlsx")){ + try { + org.apache.poi.ss.usermodel.Workbook workbook = new XSSFWorkbook(new FileInputStream(importFile)); + org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0); + Row row = sheet.getRow(0); + for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { + if (!row.getCell(i).getStringCellValue().trim().equals("")) { + excelListModel.addElement(row.getCell(i).getStringCellValue()); + } +// else { +// excelListModel.addElement("(Ϊ)"); +// } + } + filePathField.setText(importFile.getAbsolutePath()); + execute.setEnabled(true); + + return; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + } + + execute.setEnabled(false); + } + + private void executeImport() { + if (checkNecessaryCondition()) { + setVisible(false); + + reporter.reportProgressMessage("ڵ,Ժ..."); + new Thread(reporter).start(); + + new Thread() { + public void run() { + try { +// callUserServices(session, "1", "ORIGIN_set_bypass"); + ImportForProEFlex flex = new ImportForProEFlex(session, reporter); + flex.runImporting(generateImportSettings(), new File(filePathField.getText())); +// callUserServices(session, "1", "ORIGIN_close_bypass"); + reporter.requestCanceling(); + dispose(); + if( flex.logpath.equals("")){ + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ݵɣ\n\nɹ : " + flex.success + "\nʧ : " + flex.fail , "", MessageBox.INFORMATION); + }else{ + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ݵɣ\n\nɹ : " + flex.success + "\nʧ : " + flex.fail + "\n־·" + flex.logpath, "", MessageBox.ERROR); + } + + } catch (Throwable e) { + e.printStackTrace(); + + reporter.requestCanceling(); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧ", "", 1); + setVisible(true); + } + } + }.start(); + } + } + + protected boolean checkNecessaryCondition() { + return true; + } + + protected abstract void openImportSettings(); + + protected abstract void saveImportSettings(); + + public abstract ImportSettings generateImportSettings(); + + protected void populateItemTypes(JComboBox box) { + // BaseClassInput[] abaseclassinput = new + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput[4]; + // for (int i = 0; i < 4; i++) + // abaseclassinput[i] = new + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput(); + // + // abaseclassinput[0].baseClass = "Item"; + // abaseclassinput[0].exclusionTypes = new String[] {}; + // abaseclassinput[1].baseClass = "MEProcess"; + // abaseclassinput[2].baseClass = "MEOP"; + // abaseclassinput[3].baseClass = "MEWorkarea"; + // + // com.teamcenter.services.rac.core._2007_06.DataManagement.GetAvailableTypesResponse + // getavailabletypesresponse + // = TCUtilities + // .getDisplayableTypeNames(session, abaseclassinput); + // Map map = getavailabletypesresponse.inputClassToTypes; + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput + // abaseclassinput1[] = abaseclassinput; + // int j = abaseclassinput1.length; + // for (int k = 0; k < j; k++) + // { + // com.teamcenter.services.rac.core._2007_06.DataManagement.BaseClassInput + // baseclassinput = abaseclassinput1[k]; + // com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo + // aavailabletypeinfo[] = + // (com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo[]) + // map + // .get(baseclassinput.baseClass); + // com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo + // aavailabletypeinfo1[] = + // aavailabletypeinfo; + // int l = aavailabletypeinfo1.length; + // for (int i1 = 0; i1 < l; i1++) + // { + // com.teamcenter.services.rac.core._2007_06.DataManagement.AvailableTypeInfo + // availabletypeinfo = + // aavailabletypeinfo1[i1]; + // box.addItem(availabletypeinfo.type); + // } + // + // } + // + // if (getavailabletypesresponse.serviceData.sizeOfPartialErrors() > 0) + // { + // TCException tcexception = + // SoaUtil.checkPartialErrorsNoThrow(getavailabletypesresponse.serviceData); + // MessageBox.post(Utilities.getParentFrame(this), tcexception); + // } + + String[] types = new String[] { "Item", "MEProcess", "MEOP" }; + + List datas = new ArrayList(); + + Map> map = new HashMap>(types.length); + for (String string : types) { + map.put(string, new ArrayList()); + } + if (map != null && map.size() > 0) { + Map> map1 = TCUtilities.getDisplayableTypeNamesWithHierarchyInfo(session, map); + if (map1 != null && !map1.isEmpty()) { + Iterator>> iterator = map1.entrySet().iterator(); + do { + if (!iterator.hasNext()) + break; + Entry> entry = iterator.next(); + List list = entry.getValue(); + if (list != null && !list.isEmpty()) { + Iterator iterator1 = list.iterator(); + while (iterator1.hasNext()) { + DisplayTypeInfo displaytypeinfo = (DisplayTypeInfo) iterator1.next(); + datas.add(displaytypeinfo.getTypeName()); + } + } + } while (true); + } + } + + Collections.sort(datas); + + box.setModel(new DefaultComboBoxModel(datas.toArray(new String[datas.size()]))); + } + + public static void main(String[] args){ + org.apache.poi.ss.usermodel.Workbook workbook; + try { + workbook = new XSSFWorkbook(new FileInputStream("C:\\Users\\Administrator.SD-20101212HAVL\\Desktop\\123.xlsx")); + org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0); + System.out.println(sheet.getPhysicalNumberOfRows()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static Object callUserServices(TCSession session ,Object target,String str_userServiceName) { + Object[] obj = new Object[1]; + obj[0] = target; + Object robj=null; + try { + robj =session.getUserService().call(str_userServiceName, obj); + return robj; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/src/com/connor/dev/imp/DataBaseControl.java b/src/com/connor/dev/imp/DataBaseControl.java new file mode 100644 index 0000000..8ad7465 --- /dev/null +++ b/src/com/connor/dev/imp/DataBaseControl.java @@ -0,0 +1,414 @@ +package com.connor.dev.imp; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class DataBaseControl { + + /** ************************ݿ:*********************************** */ + /** + * kelsen .... + */ + Connection conn; + + ResultSet rs; + + PreparedStatement pstmt; + + Statement stmt; + + String strSQLQuery; + + public String str_Information = ""; + + private String strDriver = "oracle.jdbc.driver.OracleDriver"; + private String strUrl = ""; + private String strUserName = ""; + private String strPassword = ""; + + /** + * + */ + public DataBaseControl(String strDriver, String strUrl, String strUserName, + String strPassword) { + // this.strDriver ="oracle.jdbc.driver.OracleDriver";// + // this.strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:tc";//· + // this.strUserName = "infodba";//ݿû + // this.strPassword = "infodba";//ݿ + + + this.strDriver = strDriver; // "oracle.jdbc.driver.OracleDriver";// + this.strUrl = strUrl; // "jdbc:oracle:thin:@127.0.0.1:1521:tceng";//· + this.strUserName = strUserName; // "infodba";//ݿû + this.strPassword = strPassword; // "infodba";//ݿ + + // + try { + Class.forName(strDriver);// ͨڴ + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + // try { + // Class.forName("org.objectweb.rmijdbc.Driver").newInstance(); + // } catch (InstantiationException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (IllegalAccessException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (ClassNotFoundException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + } + + /** + * + */ + public DataBaseControl(TCSession session) { + + String[] stringArray = session.getPreferenceService().getStringValues("ERP_JDBC_Conn"); + if (stringArray != null && stringArray.length == 3) { + strUrl = "jdbc:oracle:thin:@" + stringArray[0]; + strUserName = stringArray[1]; + strPassword = stringArray[2]; + } else { + MessageBox.post("δERP_JDBC_Connѡ޷Ϣ!", "", + MessageBox.ERROR); + } + + // + try { + Class.forName(strDriver);// ͨڴ + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + + } + + /** + * + * + * @param strSQLQuery + */ + public void dbModify(String strSQLQuery) { + + openDataBase(); + + try { + stmt = conn.createStatement(); + stmt.executeUpdate(strSQLQuery); + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + + closeDataBase(); + } + + /** + * ѯ + * + * @param strSQLQuery + * @return + */ + public ResultSet dbQuery(String strSQLQuery) { + ResultSet rs_result = null; + if (conn == null) + openDataBase(); + try { + stmt = conn.createStatement(); + rs_result = stmt.executeQuery(strSQLQuery); + + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + return rs_result; + } + + /** + * ѯ2 + * + * @param strSQLQuery + * @return + */ + public ResultSet dbQuery2(String strSQLQuery, Object[] strs) { + ResultSet rs_result = null; + if (conn == null) + openDataBase(); + try { + // stmt = conn.createStatement(); + PreparedStatement ps = conn.prepareStatement(strSQLQuery); + for (int i = 0; i < strs.length; i++) { + ps.setObject(i + 1, strs[i]); + } + rs_result = ps.executeQuery(); + + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + return rs_result; + } + + /** + * 2 + * + * @param strSQLQuery + */ + public void dbModify2(String strSQLQuery, Object[] strs) { + + openDataBase(); + + try { + // stmt = conn.createStatement(); + PreparedStatement ps = conn.prepareStatement(strSQLQuery); + for (int i = 0; i < strs.length; i++) { + ps.setObject(i + 1, strs[i]); + } + ps.executeUpdate(); + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + + closeDataBase(); + } + + /** + * + * + */ + public void openDataBase() { + try { + // this.strUrl="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.29)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=tcprod)))"; + if (conn == null || conn.isClosed()) + conn = DriverManager.getConnection(strUrl, strUserName, + strPassword); + } catch (SQLException sqle) { + sqle.printStackTrace(); + MessageBox.post("ݿӴ" + sqle.getMessage(), "", 1); + } + } + + /** + * رݿ + * + */ + public void closeDataBase() { + try { + if (rs != null) { + try { + rs.close(); + } catch (SQLException sqlec) { + sqlec.printStackTrace(); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException sqlec) { + sqlec.printStackTrace(); + } + } + if (conn != null && !conn.isClosed()) { + try { + conn.close(); + } catch (SQLException sqlecon) { + sqlecon.printStackTrace(); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 䴫ݿвѯ ѯõĽÿһ¼װһHashMap,keyԱֶ + * ѯ¼VectorжٸHasnMapԪ + * + * @param strSQLQuery + * @return + * @author xuk + */ + public Vector orgQuery(String strSQLQuery) { + openDataBase(); + Vector v_result = new Vector(); + try { + ResultSet rs_get = dbQuery(strSQLQuery); + // System.out.println("RS_GET:"+rs_get); + if (rs_get != null) { + ResultSetMetaData metaData = rs_get.getMetaData(); + + int i_ColumnCount = metaData.getColumnCount(); + // System.out.println("i_ColumnCount:"+i_ColumnCount); + while (rs_get.next()) { + // System.out.println("BJZJ2"+rs_get.getString("BJZJ2"));; + HashMap hm_unit = new HashMap(); + for (int i = 1; i <= i_ColumnCount; i++) { + hm_unit.put(metaData.getColumnName(i), + rs_get.getString(i)); + // System.out.println("metaData.getColumnName(i):"+metaData.getColumnName(i)); + // System.out.println("rs_get.getString(i):"+rs_get.getString(i)); + } + v_result.add(hm_unit); + } + } else { + str_Information = "" + strSQLQuery + "" + "ѯĽΪ\n"; + } + } catch (Exception e) { + e.printStackTrace(); + } + return v_result; + } + + + /** + * ÿ + * @param tabalename + * @param pzid ϱ + * @return + * @throws Exception + */ + public String getKc(String tabalename, String pzid) throws Exception { + openDataBase(); + String query = "select * from " + tabalename + " where IMG01= ?"; // DSASX.PE_IMG_V + // ѯidݿе + System.out.println("query="+query); + System.out.println("pzid="+pzid); + ResultSet rs = dbQuery2(query, new Object[] { pzid }); + String IMG10 = ""; + if (rs!=null) { + if (rs.next()) { + String IMG01 = rs.getString(1);// ϱ + IMG10 = rs.getString(2);// + System.out.println("ѯ"+IMG01+":"+IMG10); + } + }else { + IMG10="δҵӦϢ"; + } + + + closeDataBase(); + + return IMG10; + + } + + + + /** + * ÷Ⱥ + * @param tabalename + * @return + * @throws Exception + */ + public Map getFQM(String tabalename) { + Map map=new HashMap(); + try { + openDataBase(); + String query = "SELECT IMZ01,IMZ02 FROM " + tabalename + " ORDER BY IMZ01"; // DSASX.PE_IMZ_V + // ѯidݿе + System.out.println("query="+query); + ResultSet rs = dbQuery(query); + if (rs!=null) { + while (rs.next()) { + String IMZ01 = rs.getString(1);// Ⱥ + String IMZ02 = rs.getString(2);// Ⱥ + System.out.println("ѯȺ"+IMZ01+"----"+IMZ02); + map.put(IMZ01, IMZ02); + } + } + closeDataBase(); + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + }finally { + closeDataBase(); + } + + return map; + + } + + /** + * óɱȺ + * @param tabalename + * @return + * @throws Exception + */ + public Map getCBFQM(String tabalename) { + Map map=new HashMap(); + try { + openDataBase(); + String query = "SELECT AZF01 ,AZF03 FROM " + tabalename + " ORDER BY AZF01"; // DSASX.PE_AZF_V + // ѯidݿе + System.out.println("query="+query); + ResultSet rs = dbQuery(query); + if (rs!=null) { + while (rs.next()) { + String AZF01 = rs.getString(1);// Ⱥ + String AZF03 = rs.getString(2);// Ⱥ + System.out.println("ѯɱȺ"+AZF01+"----"+AZF03); + map.put(AZF01, AZF03); + } + } + closeDataBase(); + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + }finally { + closeDataBase(); + } + + return map; + + } + + + /** + * + * + * @param args + */ + public static void main(String args[]) { + try { + + String str_DataBaseDriver = "oracle.jdbc.driver.OracleDriver"; + String str_URL = "jdbc:oracle:thin:@localhost:1521:tc8"; + String str_UserName = "infodba"; + String str_Password = "infodba"; + DataBaseControl dbc = new DataBaseControl(str_DataBaseDriver, + str_URL, str_UserName, str_Password); + // dbc.openDataBase(); + System.out.println("ӳɹ"); + // dbc.stmt = dbc.conn.createStatement(); + // String sql = "select * from PLM_LSH"; + // Vector rs_result = dbc.orgQuery(sql); + // for (int i = 0; i < rs_result.size(); i++) { + // HashMap map = (HashMap) + // rs_result.get(i); + // + // for (Map.Entry entry: map.entrySet()) { + // System.out.println(entry.getKey()+"---"+entry.getValue()); + // } + // } + + // dbc.closeDataBase(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/connor/dev/imp/ImportFlex.java b/src/com/connor/dev/imp/ImportFlex.java new file mode 100644 index 0000000..695a7b2 --- /dev/null +++ b/src/com/connor/dev/imp/ImportFlex.java @@ -0,0 +1,3713 @@ +package com.connor.dev.imp; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.connor.dev.imp.bom.BomsImportSettings; +import com.connor.dev.imp.ob.ObjectsImportSettings; +import com.connor.dev.imp.ob.StaticEnum; +import com.connor.dev.imp.re.RelationsImportSettings; +import com.connor.dev.imp.toolkit.JXLExcelParser; +import com.connor.dev.imp.toolkit.POIExcelParser; +import com.connor.dev.imp.toolkit.ProgressReporter; +import com.connor.dev.imp.toolkit.SearchUtility; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.commands.delete.DeleteOperation; +import com.teamcenter.rac.kernel.NamedReferenceContext; +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.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetDefinition; +import com.teamcenter.rac.kernel.TCComponentDatasetDefinitionType; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentIdContext; +import com.teamcenter.rac.kernel.TCComponentIdContextRuleType; +import com.teamcenter.rac.kernel.TCComponentIdentifier; +import com.teamcenter.rac.kernel.TCComponentIdentifierType; +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.TCComponentProject; +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.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.util.MessageBox; + +public class ImportFlex { + /** + * Logger for this class + */ + private static final Logger logger = Logger.getLogger(ImportFlex.class); + + private TCComponentFolder folder; + + private TCTypeService service; + + private TCComponentType uom; + private TCComponentItemType itemType; + private TCComponentDatasetType datasetType; + + private TCComponentDatasetDefinitionType dsdefType; + private TCComponentBOMWindowType winType; + + public int success = 0; + + public int fail = 0; + + public int k = 1;// ݼ汾 + + public String logpath = "";// ־· + + public String systitem = ""; + public String relation = "IMAN_specification"; + public String searchName = "__Item_Revision_name_ID_and_rev"; + String[] keys = new String[] { " ID", "汾" }; + String[] keys1 = new String[] { " ID" }; + + private TCSession session; + private ProgressReporter reporter; + private TCUserService userservice; + // ·м¼ + public int locationIndex = -2; + // Ŀм¼ + public int projectIndex = -2; + // ͵м¼ + public int typeIndex = -2; + // ѡĴ + private static final String typePreference = "Connor_History_Type_Mapping"; + private HashMap typeMapTemp; + + // Ӽ¼ҪBOMĶ + private HashMap hasBOMMap; + + /** + * Creates a new instance of ImportFlex. + * + * @param session + * @param reporter + * @throws TCException + */ + public ImportFlex(TCSession session, ProgressReporter reporter) throws TCException { + this.session = session; + this.reporter = reporter; + this.userservice = session.getUserService(); + this.hasBOMMap = new HashMap(); + logger.debug("ʼʼImportFlex"); + service = session.getTypeService(); + uom = service.getTypeComponent("UnitOfMeasure"); + itemType = (TCComponentItemType) service.getTypeComponent("Item"); + datasetType = (TCComponentDatasetType) service.getTypeComponent("Dataset"); + dsdefType = (TCComponentDatasetDefinitionType) service.getTypeComponent("DatasetType"); + winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow"); + if (AIFUtility.getCurrentApplication().getTargetComponent() instanceof TCComponentFolder) { + + folder = (TCComponentFolder) AIFUtility.getCurrentApplication().getTargetComponent(); + + } else if (StaticEnum.isExec) { + + folder = session.getUser().getNewStuffFolder(); + + } + // ¼͵ƥMAP + typeMapTemp = new HashMap(); + getObjTypeTem(); + + logger.debug("ImportFlexʼ"); + } + + /** + * ͨѡȡҪԶĶ + */ + public void getObjTypeTem() { + try { + TCPreferenceService prefService = session.getPreferenceService(); + String values[] = prefService.getStringArray(TCPreferenceService.TC_preference_site, typePreference); + if (values == null) { + return; + } + for (String value : values) { + if (value.contains("=")) { + String tempValues[] = value.split("="); + if (tempValues.length == 2) { + typeMapTemp.put(tempValues[0], tempValues[1]); + } + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * runImporting:(ʵݵ ) + * + * @param settings ݵѡ + * @param input 趨ļ + * @since CodingExample Ver 1.1 + */ + public void runImporting(ImportSettings settings, File input) { + + System.out.println("I AM 1"); + systitem = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()); + success = 0; + fail = 0; + System.out.println("Ҫļ·Ϊ" + input.getAbsolutePath()); + if (input.getAbsolutePath().endsWith(".xls")) { + try { + setByPass(true); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + //MessageBox.post("Ȩʧ", "", MessageBox.ERROR); + } + if (settings instanceof ObjectsImportSettings) { + System.out.println("ҪΪ"); + ObjectsImportSettings ois = (ObjectsImportSettings) settings; + importObjectsByJxl(ois, input); + System.out.println(""); + } else if (settings instanceof BomsImportSettings) { + System.out.println("ҪΪBOM"); + BomsImportSettings bis = (BomsImportSettings) settings; + importBomsByJxl(bis, input); + System.out.println("BOM"); + } else { + System.out.println("ҪΪϵ"); + RelationsImportSettings ris = (RelationsImportSettings) settings; + importRelationsByJxl(ris, input); + System.out.println("ϵ"); + } + try { + setByPass(false); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + //MessageBox.post("رȨʧ", "", MessageBox.ERROR); + } + + } else if (input.getAbsolutePath().endsWith(".xlsx")) { + try { + setByPass(true); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + //MessageBox.post("Ȩʧ", "", MessageBox.ERROR); + } + if (settings instanceof ObjectsImportSettings) { + System.out.println("ҪΪ"); + ObjectsImportSettings ois = (ObjectsImportSettings) settings; + importObjectsByPoi(ois, input); + System.out.println(""); + } else if (settings instanceof BomsImportSettings) { + System.out.println("ҪΪBOM"); + BomsImportSettings bis = (BomsImportSettings) settings; + importBomsByPoi(bis, input); + System.out.println("BOM"); + } else { + System.out.println("ҪΪϵ"); + RelationsImportSettings ris = (RelationsImportSettings) settings; + importRelationsByPoi(ris, input); + System.out.println("ϵ"); + } + try { + setByPass(false); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + //MessageBox.post("رȨʧ", "", MessageBox.ERROR); + } + } + + System.out.println("I AM 2"); + } + + /** + * ϵ + * + * @param ris + * @param input + */ + private void importRelationsByJxl(RelationsImportSettings ris, File input) { + String[] values = this.session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, + "Connor_Item_Option"); + // List valuesList = Arrays.asList(values); + System.out.println("ϵ뿪ʼ"); + try { + setByPass(true); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + //MessageBox.post("Ȩʧ", "", MessageBox.ERROR); + return; + } + if (ris.getCurrentItemID() == null || ris.getRelativeItemID() == null) { + MessageBox.post("ѡǰĿIDӦϵִе", "", 1); + return; + } + + int currentIndex = ris.getCurrentItemID().getColumnIndex(); + System.out.println("ǰӦΪ" + currentIndex); + int relativeIndex = ris.getRelativeItemID().getColumnIndex(); + System.out.println("ĿӦΪ" + relativeIndex); + String relation = ris.getRelation(); + String propertyName = ""; + if (relation.equals("")) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + } + int propertyIndex = -2; + if (ris.getProperty() != null) { + propertyIndex = ris.getProperty().getColumnIndex(); + } + try { + System.out.println("ʼʼexcelļ"); + JXLExcelParser parser = new JXLExcelParser(input, 0, ris.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String currentID = line.get(currentIndex).trim(); + String relativeID = line.get(relativeIndex).trim(); + if (propertyIndex != -2) { + propertyName = line.get(propertyIndex).trim(); + } + + // if ((propertyName == null) || (propertyName.length() == 0) || + // (relation == null) || (relation.length() == 0)) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + // } + if (currentID.equals("") || relativeID.equals("")) { + System.out.println("excel " + parser.startRow + "IDĿIDΪ,е"); + StringBufferDemo("excel " + parser.startRow + "IDĿIDΪ,е", "ϵ"); + fail++; + continue; + } + + System.out.println("ʼҵǰ"); + TCComponentItem currentItem = itemType.find(currentID); + if (currentItem == null) { + System.out.println("桿excel " + parser.startRow + "[" + currentID + "],е"); + StringBufferDemo("桿excel " + parser.startRow + "[" + currentID + "],е", "ϵ"); + fail++; + continue; + } + System.out.println("ǰ"); + System.out.println("ʼĿ"); + TCComponentItem relativeItem = itemType.find(relativeID); + if (relativeItem == null) { + System.out.println("桿excel " + parser.startRow + "Ŀ[" + relativeID + "],е"); + StringBufferDemo("桿excel " + parser.startRow + "Ŀ[" + relativeID + "],е", "ϵ"); + fail++; + continue; + } + + System.out.println("Ŀ"); + + String currentRevision = null; + if (ris.getCurrentItemRevision() != null) { + currentRevision = line.get(ris.getCurrentItemRevision().getColumnIndex()); + } + + String relativeRevision = null; + if (ris.getRelativeItemRevision() != null) { + relativeRevision = line.get(ris.getRelativeItemRevision().getColumnIndex()); + } + if (relation.equals("")) { + if (propertyName != "") { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + propertyName); + } else { + System.out.println("桿excel " + parser.startRow + "ûָϵ,е"); + StringBufferDemo("桿excel " + parser.startRow + "ûָϵ,е", "ϵ"); + fail++; + continue; + } + } else { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + relation); + } + } + } catch (Exception e) { + logger.error("ϵʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + try { + setByPass(false); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + //MessageBox.post("رȨʧ", "", MessageBox.ERROR); + return; + } + } + + private void importRelationsByPoi(RelationsImportSettings ris, File input) { + System.out.println("ϵ뿪ʼ"); + + if (ris.getCurrentItemID() == null || ris.getRelativeItemID() == null) { + MessageBox.post("ѡǰĿIDӦϵִе", "", 1); + return; + } + + int currentIndex = ris.getCurrentItemID().getColumnIndex(); + System.out.println("ǰӦΪ" + currentIndex); + int relativeIndex = ris.getRelativeItemID().getColumnIndex(); + System.out.println("ĿӦΪ" + relativeIndex); + + String relation = ris.getRelation(); + String propertyName = ""; + if (relation.equals("")) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + } + int propertyIndex = -2; + if (ris.getProperty() != null) { + propertyIndex = ris.getProperty().getColumnIndex(); + } + try { + System.out.println("ʼʼexcelļ"); + POIExcelParser parser = new POIExcelParser(input, 0, ris.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String currentID = line.get(currentIndex).trim(); + String relativeID = line.get(relativeIndex).trim(); + if (propertyIndex != -2) { + propertyName = line.get(propertyIndex).trim(); + } + + // if ((propertyName == null) || (propertyName.length() == 0) || + // (relation == null) || (relation.length() == 0)) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + // } + if (currentID.equals("") || relativeID.equals("")) { + System.out.println("桿excel " + parser.startRow + "IDĿIDΪ,е"); + System.out.println("ǰIDĿIDΪգд"); + StringBufferDemo("桿excel " + parser.startRow + "IDĿIDΪ,е", "ϵ"); + fail++; + continue; + } + System.out.println("ʼҵǰ"); + TCComponentItem currentItem = itemType.find(currentID); + if (currentItem == null) { + System.out.println("桿excel " + parser.startRow + ",е"); + StringBufferDemo("桿excel " + parser.startRow + "Ŀ,е", "ϵ"); + fail++; + continue; + } + System.out.println("ǰ"); + System.out.println("ʼĿ"); + TCComponentItem relativeItem = itemType.find(relativeID); + if (relativeItem == null) { + System.out.println("桿excel " + parser.startRow + "Ŀ,е"); + StringBufferDemo("桿excel " + parser.startRow + "Ŀ,е", "ϵ"); + fail++; + continue; + } + System.out.println("Ŀ"); + + String currentRevision = null; + if (ris.getCurrentItemRevision() != null) { + currentRevision = line.get(ris.getCurrentItemRevision().getColumnIndex()); + } + + String relativeRevision = null; + if (ris.getRelativeItemRevision() != null) { + relativeRevision = line.get(ris.getRelativeItemRevision().getColumnIndex()); + } + if (relation.equals("")) { + if (propertyName != "") { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + propertyName); + } + } else { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + relation); + } + } + } catch (Exception e) { + logger.error("ϵʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + } + + private void establishRelation(int row, TCComponentItem currentItem, TCComponentItem relativeItem, + String currentRevision, String relativeRevision, String relation) throws Exception { + TCComponent parent = currentItem; + TCComponent child = relativeItem; + System.out.println("relation====" + relation); + TCComponentItemRevision revision = null; + if ((currentRevision == null) || (currentRevision.trim().isEmpty())) { + + // continue; + // revision = currentItem.getLatestItemRevision(); + } else { + + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, keys, + new String[] { currentItem.getProperty("item_id"), currentRevision }); + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + } + + if (revision == null) { + System.out.println("ID" + currentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĵǰİ汾\r\n"); + StringBufferDemo("ID" + currentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĵǰİ汾\r\n", "ϵ"); + fail++; + + return; + } + + System.out.println("ָĵǰ汾ɹ"); + + parent = revision; + } + + TCComponentItemRevision re = null; + if (relativeRevision == null) { + System.out.println("ûָĿ İ汾"); + // re = relativeItem.getLatestItemRevision(); + } else { + System.out.println("ʼĿ汾"); + + // InterfaceAIFComponent[] coms = + // SearchUtility.searchComponentsCollection(session, + // "originSearchItemRevision", new String[] { "ItemID", "Revision" + // }, new String[] { relativeItem.getProperty("item_id"), + // relativeRevision }); + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, keys, + new String[] { relativeItem.getProperty("item_id"), relativeRevision }); + if (coms != null && coms.length > 0) { + re = (TCComponentItemRevision) coms[0]; + } + + if (re == null) { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָĿİ汾"); + StringBufferDemo("ID" + relativeItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĿİ汾\r\n", "ϵ"); + fail++; + System.out.println("ָĿİ汾"); + return; + } + + System.out.println("ָĿ汾ɹ"); + + child = re; + } + + boolean find = false; + System.out.println("鵱ǰǷѾָϵĿ"); + if (parent.getTCProperty(relation) == null) { + System.out.println("ID" + relativeItem.getProperty("item_id") + ". ʧܡexcel " + row + "ûҵϵ[" + + relation + "]\r\n"); + StringBufferDemo("ID" + relativeItem.getProperty("item_id") + ". ʧܡexcel " + row + "ûҵϵ[" + + relation + "]\r\n", "ϵ"); + fail++; + return; + } + + AIFComponentContext[] contexts = parent.getRelated(relation); + if (contexts != null) { + System.out.println("contexts != null"); + for (int j = 0; j < contexts.length; j++) { + InterfaceAIFComponent iac = contexts[j].getComponent(); + if (iac.equals(child)) { + + find = true; + + break; + + } + } + } + try { + if (!find) { + System.out.println("ûҵ"); + parent.add(relation, child); + System.out.println(""); + } else { + System.out.println("ɹexcel " + row + "еɹ"); + System.out.println("Ѿڣд"); + } + } catch (Exception e) { + StringBufferDemo("ID" + relativeItem.getProperty("item_id") + ". ʧܡexcel " + row + "" + + e.getMessage() + "\r\n", "ϵ"); + fail++; + e.printStackTrace(); + + } + success++; + } + + private void importBomsByJxl(BomsImportSettings bis, File input) { + System.out.println("BOM뿪ʼ"); + if (bis.getParentMapping() == null || bis.getChildMapping() == null) { + MessageBox.post("ѡװװIDִе", "", 1); + + return; + } + + int parentIndex = bis.getParentMapping().getColumnIndex(); + System.out.println("װӦΪ" + parentIndex); + int childIndex = bis.getChildMapping().getColumnIndex(); + System.out.println("ӼװӦΪ" + childIndex); + + try { + System.out.println("ʼʼexcelļ"); + JXLExcelParser parser = new JXLExcelParser(input, 0, bis.getColumns(), 1); + + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + StringBuffer buffer = new StringBuffer(); + // StringBuffer noacl_buffer = new StringBuffer(); + List set = new ArrayList(); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("֤ " + parser.startRow + " "); + String parentID = line.get(parentIndex); + if (parentID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(parentID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + parentID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(parentID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + parentID); + continue; + } + } + } + + String childID = line.get(childIndex); + if (childID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(childID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + childID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(childID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + childID); + continue; + } + } + } + } + + if (buffer.length() > 1) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ǰBOMкϣֱǣ\n" + buffer.toString() + "\n\n봴Ϻٽе", "", 1); + return; + } + // if(noacl_buffer.length()>1) + // { + // MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + // "ǰBOMк޶Ȩϣֱǣ\n" + noacl_buffer.toString() + + // "\n\n봴Ϻٽе", "", 1); + // return; + // } + + parser = new JXLExcelParser(input, 0, bis.getColumns(), 1); + while ((line = parser.parseLine()) != null) { + try { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String parentID = line.get(parentIndex); + TCComponentItem parentItem = null; + System.out.println("ʼҸװӦ "); + if (parentID.trim().length() > 0) { + parentItem = itemType.find(parentID); + } + if (parentItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "иװڣе"); + StringBufferDemo( + "ID" + parentID + ". ʧܡexcel " + parser.startRow + "иװڣе\r\n", + "ʷݵBOM"); + System.out.println("װ"); + fail++; + continue; + } + System.out.println("ҵװӦ "); + + String childID = line.get(childIndex); + System.out.println("ʼӼװӦ "); + TCComponentItem childItem = null; + if (childID.trim().length() > 0) { + childItem = itemType.find(childID); + } + if (childItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "װڣе"); + StringBufferDemo( + "ID" + childID + ". ʧܡexcel " + parser.startRow + "װڣе\r\n", + "ʷݵBOM"); + System.out.println("װ"); + fail++; + continue; + } + System.out.println("ҵӼװӦ "); + + String parantRevision = null; + if (bis.getParentRevMapping() != null) { + parantRevision = line.get(bis.getParentRevMapping().getColumnIndex()); + } + + String childRevision = null; + if (bis.getChildRevMapping() != null) { + childRevision = line.get(bis.getChildRevMapping().getColumnIndex()); + } + + MappingAttribute[] atts = bis.getBomLineMapping(); + Map properties = new HashMap(); + for (int i = 0; i < atts.length; i++) { + properties.put(atts[i].getTcAttribute(), line.get(atts[i].getColumnIndex())); + } + System.out.println("parentItem:" + parentItem); + System.out.println("childItem:" + childItem); + System.out.println("childRevision:" + childRevision); + System.out.println("parentRevision:" + parantRevision); + establishBomStructrue(parser.startRow, parentItem, childItem, parantRevision, childRevision, + properties); + } catch (Exception e) { + System.out.println("ʧܡexcel " + parser.startRow + "BOMʧ"); + StringBufferDemo("ʧܡexcel " + parser.startRow + "BOMʧ\r\n", "ʷݵBOM"); + e.printStackTrace(); + fail++; + continue; + } + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + } + + private void importBomsByPoi(BomsImportSettings bis, File input) { + System.out.println("BOM뿪ʼ"); + if (bis.getParentMapping() == null || bis.getChildMapping() == null) { + MessageBox.post("ѡװװIDִе", "", 1); + + return; + } + + int parentIndex = bis.getParentMapping().getColumnIndex(); + System.out.println("װӦΪ" + parentIndex); + int childIndex = bis.getChildMapping().getColumnIndex(); + System.out.println("ӼװӦΪ" + childIndex); + + try { + System.out.println("ʼʼexcelļ"); + POIExcelParser parser = new POIExcelParser(input, 0, bis.getColumns(), 1); + + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + StringBuffer buffer = new StringBuffer(); + List set = new ArrayList(); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("֤ " + parser.startRow + " "); + String parentID = line.get(parentIndex); + if (parentID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(parentID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + parentID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(parentID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + parentID); + continue; + } + } + } + + String childID = line.get(childIndex); + if (childID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(childID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + childID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(childID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + childID); + continue; + } + } + } + } + + if (buffer.length() > 1) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ǰBOMкϣֱǣ\n" + buffer.toString() + "\n\n봴Ϻٽе", "", 1); + return; + } + + parser = new POIExcelParser(input, 0, bis.getColumns(), 1); + while ((line = parser.parseLine()) != null) { + try { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String parentID = line.get(parentIndex); + TCComponentItem parentItem = null; + System.out.println("ʼҸװӦ "); + if (parentID.trim().length() > 0) { + parentItem = itemType.find(parentID); + } + if (parentItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "иװڣе"); + System.out.println("װ"); + StringBufferDemo("ʧܡexcel " + parser.startRow + "иװڣе", "ʷݵBOM"); + fail++; + continue; + } + System.out.println("ҵװӦ "); + + String childID = line.get(childIndex); + System.out.println("ʼӼװӦ "); + TCComponentItem childItem = null; + if (childID.trim().length() > 0) { + childItem = itemType.find(childID); + } + if (childItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "װڣе"); + System.out.println("װ"); + StringBufferDemo("ʧܡexcel " + parser.startRow + "иװڣе", "ʷݵBOM"); + fail++; + continue; + } + System.out.println("ҵӼװӦ "); + + String parantRevision = null; + if (bis.getParentRevMapping() != null) { + parantRevision = line.get(bis.getParentRevMapping().getColumnIndex()); + } + + String childRevision = null; + if (bis.getChildRevMapping() != null) { + childRevision = line.get(bis.getChildRevMapping().getColumnIndex()); + } + + MappingAttribute[] atts = bis.getBomLineMapping(); + Map properties = new HashMap(); + for (int i = 0; i < atts.length; i++) { + properties.put(atts[i].getTcAttribute(), line.get(atts[i].getColumnIndex())); + } + + establishBomStructrue2(parser.startRow, parentItem, childItem, parantRevision, childRevision, + properties); + } catch (Exception e) { + System.out.println("ʧܡexcel " + parser.startRow + "BOMʧ"); + StringBufferDemo("ʧܡexcel " + parser.startRow + "BOMʧ", "ʷݵBOM"); + e.printStackTrace(); + fail++; + continue; + } + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + } + + + + /** + * cbom + * @param row + * @param parentItem + * @param childItem + * @param parantRevision + * @param childRevision + * @param properties + * @throws Exception + */ + private void establishBomStructrue2(int row, TCComponentItem parentItem, TCComponentItem childItem, + String parantRevision, String childRevision, Map properties) throws Exception { + + TCComponentItemRevision revision = parentItem.getLatestItemRevision(); + if (parantRevision != null && !parantRevision.trim().equals("")) { + String revid = revision.getProperty("item_revision_id"); + if (!revid.equals(parantRevision.trim())) { + System.out.println("ָװİ汾"); + + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, keys, + new String[] { parentItem.getProperty("item_id"), parantRevision }); + System.out.println(parentItem.getProperty("item_id") + " | " + parantRevision); + + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + + } + } + } + TCComponentItemRevision re = childItem.getLatestItemRevision(); + if (childRevision != null && !childRevision.trim().equals("")) { + String revid = re.getProperty("item_revision_id"); + if (!revid.equals(childRevision.trim())) { + System.out.println("ָӼİ汾"); + + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, keys, + new String[] { parentItem.getProperty("item_id"), childRevision }); + System.out.println(parentItem.getProperty("item_id") + " | " + childRevision); + + if (coms != null && coms.length > 0) { + re = (TCComponentItemRevision) coms[0]; + + } + } + } + + + if (revision != null&&re!=null) { + String propstr=""; + + for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();) { + String key = iterator.next(); + String value = properties.get(key); + if (value!=null&&!value.equals("")) { + String strleng= key+"&="+value; + if (!propstr.equals("")) { + propstr=propstr+"&#"+strleng; + }else { + propstr=strleng; + } + } + + } + + if (userservice == null) { + userservice = this.session.getUserService(); + } + Object[] obj = new Object[3]; + obj[0] = revision; + obj[1] = new TCComponent[] {re}; + obj[2] = new String[] {propstr}; + String[] strs = (String[])userservice.call("Connor_Creat_Bom", obj); + if (strs!=null&&strs.length>0) { + if (!strs[0].equals("ɹ")) { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: "+strs[0]+"!"); + StringBufferDemo("ID" + parentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: BOM"+strs[0]+"!\r\n", "ʷݵBOM"); + System.out.println(":"+strs[0]); + fail++; + + }else { + success++; + System.out.println("ɹexcel " + row + "еɹ"); + } + + + + }else { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: BOMδسɹϢ!"); + StringBufferDemo("ID" + parentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: BOMδسɹϢ!\r\n", "ʷݵBOM"); + System.out.println("BOMδسɹϢ"); + fail++; + } + + } else { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָĸװӼİ汾"); + StringBufferDemo("ID" + parentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĸװӼİ汾\r\n", "ʷݵBOM"); + System.out.println("ûҵָָ汾"); + fail++; + } + } + + + + + @SuppressWarnings("static-access") + private void establishBomStructrue(int row, TCComponentItem parentItem, TCComponentItem childItem, + String parantRevision, String childRevision, Map properties) throws Exception { + TCComponentItemRevision revision = null; + if (parantRevision == null || parantRevision.trim().equals("")) { + System.out.println("ûָװİ汾ʹ°汾"); + // revision = parentItem.getLatestItemRevision(); + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, + + new String[] { " ID" }, new String[] { parentItem.getProperty("item_id") }); + + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[coms.length - 1]; + } + } else { + System.out.println("ָװİ汾"); + + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, keys, + new String[] { parentItem.getProperty("item_id"), parantRevision }); + System.out.println(parentItem.getProperty("item_id") + " | " + parantRevision); + System.out.println("222222222222222222222"); + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + System.out.println("3333333333333333333333"); + } else { + System.out.println("111111111111111111111"); + } + } + if (revision != null) { + + TCComponentBOMWindow window = winType.create(null); + window.lock(); + + System.out.println("ָװİ汾ɹ"); + TCComponentBOMLine line = window.setWindowTopLine(parentItem, revision, null, null); + + // TCComponentBOMWindow win = winType.create(null); + // win.lock(); + + TCComponentItemRevision re = null; + if (childRevision == null || childRevision.trim().equals("")) { + System.out.println("ûָӼװİ汾ʹ°汾"); + // re = childItem.getLatestItemRevision(); + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, keys1, + new String[] { childItem.getProperty("item_id") }); + + if (coms != null && coms.length > 0) { + re = (TCComponentItemRevision) coms[coms.length - 1]; + } + } else { + System.out.println("ָӼװİ汾"); + + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, keys, + new String[] { childItem.getProperty("item_id"), childRevision }); + + if (coms != null && coms.length > 0) { + re = (TCComponentItemRevision) coms[0]; + } + } + System.out.println("childRevision = " + childRevision + ":: Ӽre = " + re); + + if (re != null) { + System.out.println("ָӼװİ汾ɹ"); + + System.out.println("жDzѾṹ"); + boolean find = false; + TCComponentBOMLine childLine = null; + TCComponent[] tccomponents = re.whereUsed(re.WHERE_USED_ALL); + if (tccomponents != null && tccomponents.length > 0) { + for (int j = 0; j < tccomponents.length; j++) { + if (tccomponents[j] instanceof TCComponentItemRevision) { + TCComponentItemRevision itemrevision = (TCComponentItemRevision) tccomponents[j]; + if (itemrevision.equals(line.getItemRevision())) { + find = true; + System.out.println("桿excel " + row + "BOMѾе"); + break; + } + } + } + } + + // жǷӽڵ + TCComponent[] b_existBOM = re.getRelatedComponents("structure_revisions"); + if (b_existBOM.length > 0) { + // BOM,¼ + System.out.println("BOM"); + String tempitemid = re.getProperty("item_id"); + System.out.println("BOM:" + tempitemid); + if (!hasBOMMap.containsKey(tempitemid)) + hasBOMMap.put(tempitemid, re); + } + + if (!find) { + System.out.println("ûдṹ"); + if (hasBOMMap.containsKey(line.getProperty("bl_item_item_id"))) { + System.out.println("벻Ҫ"); + System.out.println("桿excelе" + row + "BOMʧ,øBOMѴBOMṹ,е"); + StringBufferDemo("桿excelе" + row + "BOMʧ,øBOMѴBOMṹ,е,赼ɾBOMͼٽе", + "ʷݵBOM"); + fail++; + + } else { + childLine = line.add(childItem, re, null, false, ""); + // String newswquence = + // childLine.getProperty("bl_sequence_no"); + // System.out.println("õIJұΪ:"+newswquence); + // int quantity_num = -9999; + for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();) { + String key = iterator.next(); + String value = properties.get(key); + // System.out.println(key + " : " + value); + try { + // if(key.equals("bl_quantity")) + // { + // quantity_num = Integer.valueOf(value); + // System.out.println("תΪint:"+quantity_num); + // } + // else + // { + // System.out.println("濪ʼתλ"); + if (key.equals("bl_ref_designator") && (!value.contains("-"))) { + System.out.println("λԽתvalue=" + value); + value = change(value, row); + System.out.println("λתvalue=" + value); + } + System.out.println("key=" + key + " value=" + value); + if (value.contains("\\.") && key.equals("bl_quantity")) { + try { + double d = Double.parseDouble(value); + childLine.setDoubleProperty(key, d); + } catch (Exception e) { + System.out.println( + "ʧܡexcel " + row + "еʧܣԭ: װ " + key + " ȷ´"); + StringBufferDemo( + "ID" + childItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: װ " + key + " ȷ´\r\n", + "ʷݵBOM"); + fail++; + // win.close(); + window.save(); + window.unlock(); + window.close(); + return; + } + } else { + childLine.setProperty(key, value); + } + + // } + } catch (TCException e) { + System.out + .println("ʧܡexcel " + row + "еʧܣԭ: װ " + key + " ȷ´"); + StringBufferDemo("ID" + childItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: װ " + key + " ȷ´\r\n", "ʷݵBOM"); + fail++; + // win.close(); + window.save(); + window.unlock(); + window.close(); + return; + } + } + childLine.pack(); + childLine.save(); + System.out.println("ṹ"); + } + + } + + success++; + System.out.println("ɹexcel " + row + "еɹ"); + } else { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָװİ汾"); + StringBufferDemo("ID" + childItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָװİ汾\r\n", "ʷݵBOM"); + System.out.println("ָװİ汾"); + fail++; + } + line.save(); + window.save(); + window.unlock(); + window.close(); + } else { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָĸװİ汾"); + StringBufferDemo("ID" + parentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĸװİ汾\r\n", "ʷݵBOM"); + System.out.println("ûҵָָ汾"); + fail++; + } + } + + public boolean isStrNum(String str) { + + try { + Integer.parseInt(str); + return true; + } catch (NumberFormatException e) { + return false; + } + + } + + // λתɴ- + public String change(String ss, int row) { + // TODO Auto-generated method stub + String newstr = ""; + List keylist = new ArrayList(); + Map> map = new HashMap>(); + + String left = ""; + + ss = ss.replaceAll("", ","); + ss = ss.replaceAll(" ", ""); + + String[] strs = ss.split(","); + if (strs != null && strs.length > 0) { + + for (String str : strs) { + try { + str = str.trim(); + if (str.length() > 0) + for (int i = 1; i < str.length(); i++) { + if (isStrNum(str.substring(i, str.length()))) { + left = str.substring(0, i); + if (!keylist.contains(left)) { + keylist.add(left); + } + break; + } + } + } catch (NumberFormatException e) { + System.out.println(str + "쳣޷ת" + e.getMessage()); + System.out.println("ʧܡexcel " + row + "λſܵʧܣԭ:λ쳣"); + try { + StringBufferDemo("ʧܡexcel " + row + "λſܵʧܣԭ:λ쳣", "ʷݵBOM"); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("ָװİ汾"); + fail++; + } + + } + for (String keystr : keylist) { + List list = new ArrayList(); + for (String str : strs) { + try { + str = str.trim(); + if (str.length() > 0) + for (int i = 1; i < str.length(); i++) { + if (isStrNum(str.substring(i, str.length()))) { + left = str.substring(0, i); + if (keystr.equals(left)) { + int in = Integer.parseInt(str.substring(i, str.length())); + list.add(in); + } + break; + } + } + } catch (NumberFormatException e) { + System.out.println(str + "쳣޷ת" + e.getMessage()); + System.out.println("ʧܡexcel " + row + "λſܵʧܣԭ:λ쳣"); + try { + StringBufferDemo("ʧܡexcel " + row + "λſܵʧܣԭ:λ쳣", "ʷݵBOM"); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("ָװİ汾"); + fail++; + } + + } + + Collections.sort(list);// + + map.put(keystr, list); + + } + + } + if (map != null) { + for (String keystr : keylist) { + if (!newstr.equals("")) { + newstr = newstr + ","; + } + List list = map.get(keystr); + if (list != null && list.size() > 0) + for (int i = 0; i < list.size(); i++) { + if (i == list.size() - 1) { + newstr = newstr + keystr + list.get(i); + break; + } + if (list.get(i) + 1 == list.get(i + 1)) { + if (!newstr.endsWith("-") || newstr.equals("")) { + newstr = newstr + keystr + list.get(i) + "-"; + } + + } else { + if (newstr.endsWith("-")) { + newstr = newstr + keystr + list.get(i) + ","; + } else { + newstr = newstr + keystr + list.get(i) + ","; + } + } + + } + } + + } + System.out.println(ss); + System.out.println(newstr); + if (newstr.equals("")) { + System.out.println("[" + ss + "]ת,ֱӸֵ"); + return ss; + } + return newstr; + + } + + private void importObjectsByJxl(ObjectsImportSettings ois, File input) { + + System.out.println("뿪ʼ"); + + try { + TCComponent[] uoms = uom.extent(); + Map uomMap = new HashMap(); + if (uoms != null) { + for (int i = 0; i < uoms.length; i++) { + uomMap.put(uoms[i].toString(), uoms[i]); + } + } + + int uomIndex = -1; + int idIndex = -1; + int nameIndex = -1; + boolean isthroughParent = ois.isSelectParent(); + + MappingAttribute[] items = ois.getItemMapping(); + MappingAttribute[] revisions = ois.getRevMapping(); + MappingAttribute[] forms = ois.getRevFormMapping(); + MappingAttribute[] datasetMap = ois.getDatasetMapping(); + + for (int i = 0; i < datasetMap.length; i++) { + if ("·".equals(datasetMap[i].getTcAttribute()) && "·".equals(datasetMap[i].getColumnTitle())) { + this.locationIndex = datasetMap[i].getColumnIndex(); + System.out.println(">>·Ӧ" + locationIndex); + } else { + System.out.println(">>ûҵ·" + locationIndex); + } + + } + + for (int i = 0; i < items.length; i++) { + if ("Ŀ".equals(items[i].getTcAttribute())) { + this.projectIndex = items[i].getColumnIndex(); + System.out.println(">>ĿӦ" + projectIndex); + } else { + System.out.println(">>ûҵĿ" + projectIndex); + } + + } + + for (int i = 0; i < items.length; i++) { + if ("item_id".equals(items[i].getTcAttribute())) { + idIndex = items[i].getColumnIndex(); + System.out.println("IDӦ" + idIndex); + continue; + } + if ("uom_tag".equals(items[i].getTcAttribute())) { + uomIndex = items[i].getColumnIndex(); + System.out.println("λӦΪ" + uomIndex); + } + if ("object_name".equals(items[i].getTcAttribute())) { + nameIndex = items[i].getColumnIndex(); + System.out.println("ӦΪ" + nameIndex); + } + + if ("".equals(items[i].getTcAttribute()) && "".equals(items[i].getColumnTitle())) { + this.typeIndex = items[i].getColumnIndex(); + System.out.println(">>Ӧ" + typeIndex); + } else { + System.out.println(">>ûҵ" + typeIndex); + } + + } + + if (idIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡIDӦУɵ", "", 1); + return; + } + + if (nameIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡӦУɵ", "", 1); + return; + } + + int itemRevIndex = -1; + for (int i = 0; i < revisions.length; i++) { + if ("item_revision_id".equals(revisions[i].getTcAttribute())) { + itemRevIndex = revisions[i].getColumnIndex(); + System.out.println("汾ӦΪ" + itemRevIndex); + } + } + + JXLExcelParser parser = new JXLExcelParser(input, 0, ois.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + String id = ""; + String rev = ""; + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + try { + String lastid = id; + id = line.get(idIndex); + if (id.length() > 0) { + TCComponent uomCom = null; + if (uomIndex >= 0) { + String uom = line.get(uomIndex); + if (uom.length() > 0) { + uomCom = uomMap.get(uom); + + if (uomCom == null) { + try { + if (line.get(nameIndex).equals("")) { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: ָĵλûϵͳж\r\n", "ʷݵ"); + } else { + StringBufferDemo( + "ID" + id + ",ƣ" + line.get(nameIndex) + ". ʧܡexcel " + + parser.startRow + "еʧ,ԭ: ָĵλûϵͳж\r\n", + "ʷݵ"); + } + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ָĵλûϵͳж."); + fail++; + continue; + } + } + } + + String lastRev = rev; + if (itemRevIndex > 0) { + rev = line.get(itemRevIndex); + } + // ---жǷһεİ汾 zyn + if (!lastid.equals("")) { + if (lastid.equals(id)) { + if (!lastRev.equals("")) { + if (!lastRev.equals(rev)) { + k = 1; + } + } + } else { + k = 1; + } + } + TCComponentItem item = null; + item = itemType.find(id); + TCComponentItemRevision revision = null; + + List ps = new ArrayList(); + boolean refresh = false; + if (item == null) { + String name = line.get(nameIndex); + if (name.equals("")) { + try { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: ĵΪΪֵ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + // жǷͨѡ࣬Զ + if (typeIndex == -2) { + item = itemType.create(id, rev, ois.getItemType(), name, "", uomCom); + } else { + String typeTemp1 = line.get(typeIndex); + String typeTemp = typeMapTemp.get(typeTemp1); + if (typeTemp != null && typeTemp.length() > 0) { + TCTypeService typeService = session.getTypeService(); + TCComponentType type = typeService.getTypeComponent(typeTemp); + if (type == null) { + try { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: Ҳ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡexcel " + parser.startRow + "½ʧ,ԭ: Ҳ"); + continue; + } + item = itemType.create(id, rev, typeTemp, name, "", uomCom); + } else { + try { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: Ҳ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡexcel " + parser.startRow + "½ʧ,ԭ: Ҳ"); + continue; + } + } + // item = itemType.create(id, rev, + // ois.getItemType(), name, "", uomCom); + + revision = item.getLatestItemRevision(); + folder.add("contents", item); + System.out.println("ɹ "); + } else { + refresh = true; + System.out.println("ѾϵͳУҪ"); + StringBufferDemo( + "ID" + id + ". excel " + parser.startRow + "еʧ,ԭ: Ѿ\r\n", + "ʷݵ"); + // continue; + } + + if (revision == null) { + InterfaceAIFComponent[] coms = null; + System.out.println("ָ汾 - " + rev); + coms = SearchUtility.searchComponentsCollection(session, searchName, keys, + new String[] { id, rev }); + System.out.println("coms===" + coms); + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + } + } + System.out.println("revision==" + revision); + if (revision == null && !rev.equals("")) { + refresh = false; + System.out.println("Ѿ,ָİ汾,ڽ޶ָ汾"); + revision = item.getLatestItemRevision().saveAs(rev, item.getProperty("object_name"), "", + true, null, null); + TCComponent[] datasets = revision.getTCProperty(relation).getReferenceValueArray(); + for (int i = 0; i < datasets.length; i++) { + if (datasets[i] instanceof TCComponentDataset) { + revision.remove(relation, datasets[i]);// Ƴǰݼ--dfhm + // by + // zyn + // 2011/08/11 + } + } + System.out.println("޶ָ汾ɹ"); + } + if (revision == null) { + revision = item.getLatestItemRevision(); + } + if ((refresh && ois.isExistedRefreshed()) || !refresh) { + String name = line.get(nameIndex); + if (name.equals("")) { + try { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "иʧ,ԭ: ĵΪΪֵ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + StringBufferDemo("ʧܡexcel " + parser.startRow + "иʧ,ԭ: ĵΪΪֵ", + "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + "иʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + if (uomCom != null) { + try { + item.setReferenceProperty("uom_tag", uomCom); + } catch (Exception e) { + StringBufferDemo( + "ID" + id + ",ƣ" + line.get(nameIndex) + ". ʧܡexcel " + + parser.startRow + "иʧ,ԭ: ĵλ޸,ǷѾBOM\r\n", + "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + + "иʧ,ԭ: ĵλ޸,ǷѾBOM"); + fail++; + // continue; + } + } + System.out.println("ϵ"); + ps.clear(); + TCComponentIdentifierType altype = (TCComponentIdentifierType) session.getTypeService() + .getTypeComponent("Identifier"); + TCComponentIdContextRuleType tccomponentidcontextruletype = (TCComponentIdContextRuleType) session + .getTypeComponent("IdContextRule"); + TCComponentIdContext[] context; + context = tccomponentidcontextruletype.getAliasContexts(); + for (int i = 0; i < items.length; i++) { + if (items[i].equals("uom_tag") || items[i].equals("object_name")) { + continue; + } + if (items[i].getTcAttribute().equals("IMAN_aliasid")) { + TCComponentIdentifier alid = altype.createAliasIdentifier("WX3_AAA"); + alid.setReferenceProperty("idcontext", context[0]); + alid.setProperty("idfr_id", line.get(items[i].getColumnIndex())); + alid.setProperty("object_name", "wx"); + alid.setProperty("object_desc", ""); + alid.save(); + item.add("IMAN_aliasid", alid); + continue; + } + TCProperty property = item.getTCProperty(items[i].getTcAttribute()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + if (property.getPropertyName().equals("item_id")) { + continue; + } + setTCProperty(property, line.get(items[i].getColumnIndex())); + ps.add(property); + } + } + item.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("ϵԳɹɸ "); + System.out.println("´汾ϵ"); + revision.setProperty("object_name", item.getProperty("object_name")); + ps.clear(); + for (int i = 0; i < revisions.length; i++) { + TCProperty property = revision.getTCProperty(revisions[i].getTcAttribute()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + logger.debug(" - " + property.getPropertyName()); + String propertyName = property.getName(); + String relatedItemType = null; + if (propertyName.equals("MnfBrandOAttr")) { + relatedItemType = "MnfBrandObj"; + } else if (propertyName.equals("MnfCategoryOAttr")) { + relatedItemType = "MnfCategoryObj"; + } else if (propertyName.equals("MnfProdLineOAttr")) { + relatedItemType = "MnfProdLineObj"; + } else if (propertyName.equals("MnfSeasonOAttr")) { + relatedItemType = "MnfSeasonObj"; + } else if (propertyName.equals("MnfSeriesOAttr")) { + relatedItemType = "MnfSeriesObj"; + } else if (propertyName.equals("MnfStyleOAttr")) { + relatedItemType = "MnfStyleObj"; + } else if (propertyName.equals("MnfMaterialBOAttr")) { + relatedItemType = "MnfMaterialBType"; + } else if (propertyName.equals("MnfMaterialSOAttr")) { + relatedItemType = "MnfMaterialSType"; + } + if (relatedItemType != null) { + logger.debug("ֺͨͲҶӦItem"); + InterfaceAIFComponent[] cs = SearchUtility.searchComponentsCollection(session, + "ConnorItemSearch", new String[] { "Name1", "Type1" }, + new String[] { line.get(revisions[i].getColumnIndex()), + relatedItemType + "Revision" }); + if (cs != null && cs.length > 0) { + System.out.println("DDD " + revisions[i].getColumnIndex()); + logger.debug("ҵΪ" + line.get(revisions[i].getColumnIndex()) + ",Ϊ" + + relatedItemType + "Ķ"); + if (cs[0] instanceof TCComponentItemRevision) { + TCComponentItemRevision tcc = (TCComponentItemRevision) cs[0]; + property.setPropertyData(tcc); + } + } else { + try { + StringBufferDemo("ID" + id + ",ƣ" + line.get(nameIndex) + + ". ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.println("ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ"); + fail++; + continue; + } + } else { + logger.debug("relatedItemType = " + relatedItemType); + setTCProperty(property, line.get(revisions[i].getColumnIndex())); + } + ps.add(property); + } + } + revision.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("´ϵԳɹ "); + + TCComponentForm form = getItemRevisionMasterForm(revision); + if (form != null) { + System.out.println("ȡ汾Formɹ,ʼ"); + ps.clear(); + //2021/11/10ϰ˷lovж + String zlb=""; + String flb=""; + for (int i = 0; i < forms.length; i++) { + if (forms[i].getTcAttribute().equals("lb2_cpxzlb")) { + zlb=line.get(forms[i].getColumnIndex()); + continue; + } + if (forms[i].getTcAttribute().equals("lb2_cpxflb")) { + flb=line.get(forms[i].getColumnIndex()); + continue; + } + TCProperty property = form.getTCProperty(forms[i].getTcAttribute()); + if (property != null && property.getDescriptor().isModifiable()) { + + setTCProperty(property, line.get(forms[i].getColumnIndex())); + ps.add(property); + } + } + form.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + form.save(); + if(!zlb.equals("")) { + String zlbzsz=""; + String flbzsz=""; + System.out.println("ʼülov"+zlb+"----"+flb); + TCProperty tcProperty = form.getTCProperty("lb2_cpxzlb"); + TCComponentListOfValues lov = tcProperty.getLOV(); + String[] strs1 = lov.getListOfValues().getStringListOfValues(); + if (strs1!=null) { + TCComponentListOfValues lov2=null; + for (int i = 0; i < strs1.length; i++) { + String a1 = lov.getListOfValues().getDisplayableValue(strs1[i]);//ʾֵ + if (zlb.equals(a1)) { + zlbzsz=strs1[i]; + lov2=lov.getListOfFilterOfValue(strs1[i]); + break; + } + } + if (lov2!=null) { + String[] strs2 = lov2.getListOfValues().getStringListOfValues(); + if (strs2!=null) { + for (int i = 0; i < strs2.length; i++) { + String a2 = lov2.getListOfValues().getDisplayableValue(strs2[i]);//ʾֵ + if (flb.equals(a2)) { + flbzsz=strs2[i]; + break; + } + } + + } + } + } + if (!zlbzsz.equals("")) { + System.out.println(":"+zlbzsz); + form.setStringProperty("lb2_cpxzlb", zlbzsz); + } + if (!flbzsz.equals("")) { + System.out.println("÷:"+flbzsz); + form.setStringProperty("lb2_cpxflb", flbzsz); + } + } + } else { + System.out.println("ȡ汾Formʧ"); + } + MappingAttribute[] datasets = ois.getDatasetMapping(); + System.out.println("汾ݼ, " + datasets.length + "Ҫ"); + ps.clear(); + + // ʼݼ2017.11.8 + String allFilePath = ""; + String allFilePaths[] = null; + if (locationIndex != -2) { + allFilePath = line.get(locationIndex); + if (allFilePath.contains(";")) { + allFilePaths = allFilePath.split(";"); + } else if (allFilePath.contains("")) { + allFilePaths = allFilePath.split(""); + } else { + allFilePaths = new String[] { allFilePath }; + } + System.out.println("⴦ļ" + allFilePaths.length + ""); + } else { + System.out.println("⴦"); + } + int filePathIndex = 0; + for (int i = 0; i < datasets.length; i++) { + System.out.println("dataset:" + datasets[i].getColumnIndex()); + System.out.println("dataset2:" + datasets[i].getColumnTitle()); + try { + String filePath = null; + if (locationIndex != -2) { + if (datasets[i].getColumnIndex() == locationIndex) { + continue; + } + String fileName = line.get(datasets[i].getColumnIndex()); + if (fileName.trim().equals("")) { + System.out.println("⴦ݼΪ"); + continue; + } + + if (filePathIndex < allFilePaths.length) { + filePath = allFilePaths[filePathIndex]; + } else { + System.out.println("⴦ǿļļ飡"); + continue; + } + filePathIndex++; + logger.debug("ʼ" + (filePathIndex) + ""); + } else { + filePath = line.get(datasets[i].getColumnIndex()); + logger.debug("ʼ" + (i + 1) + ""); + } + if (filePath.trim().length() > 0) { + System.out.println("ݼ·Ϊ" + filePath); + String ds = datasets[i].getTcAttribute(); + // String sep = ois.getArraySeparator(); + // filePathԡ||ͱʾҳɶݼԡ;ͱʾһݼӶ + String[] files = filePath.split("\\|\\|"); + List> fis = new ArrayList>(); + for (int j = 0; j < files.length; j++) { + String filepath = files[j].trim(); + if (filepath.contains(";")) { + String[] filepaths = filepath.split(";"); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + // Ҫ + StringBufferDemo("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·\r\n", "ʷݵ"); + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + fis.add(list); + } else if (filepath.contains("")) { + String[] filepaths = filepath.split(""); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + System.out.println("ļ·Ϊ" + file); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + // Ҫ + StringBufferDemo("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·\n\r", "ʷݵ"); + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + fis.add(list); + } else { + System.out.println("files[" + j + "] = " + files[j]); + File file = new File(files[j].trim()); + if (file.exists()) { + List list = new ArrayList(); + list.add(file.getAbsolutePath()); + fis.add(list); + } else { + // Ҫ + StringBufferDemo("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·\n\r", "ʷݵ"); + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + } + + if (fis.size() > 0) { + String did = line.get(datasets[i].getColumnIndex()); + if (did.contains(".") && did.contains("\\")) { + did = did.substring(did.lastIndexOf("\\") + 1, did.lastIndexOf(".")); + } + // String did = + // revision.getProperty("item_id"); + // did = did + "/" + + // revision.getProperty("item_revision_id"); + + System.out.println("ɵݼidΪ" + did); + String[] refs = guessDatasetReferenceNames(ds, files); + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + StringBufferDemo("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨\n\r", + "ʷݵ"); + logger.error("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨"); + System.out + .println("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨"); + fail++; + continue; + } + } + System.out.println("ȡϵͳָļӦݼõֳɹ"); + if (fis.size() == 1) { + List listString = fis.get(0); + AIFComponentContext[] cc = revision.getChildren(relation); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getStringProperty("object_name").equals(did)) { + listComponent.add(cc[j]); + } + } + } + if (listComponent.size() > 0) { + if (listComponent.size() > 1) { + for (int k = 0; k < listComponent.size() - 1; k++) { + DeleteOperation deleteOperation = new DeleteOperation( + listComponent.get(k)); + session.queueOperation(deleteOperation); + listComponent.remove(k); + k--; + } + if (listComponent.get(0) + .getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent + .get(0).getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } + } + } else { + if (listComponent.get(0) + .getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent + .get(0).getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } + } + } + } else { + System.out.println("ָID͵ݼѾڣ½"); + System.out.println("ds &&&&&&&&&&&&&&&&&& " + ds); + TCComponentDataset tcd = datasetType.create(did, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(tcd, new File(listString.get(l)), + tcd.getType(), refs[0]); + + } + System.out.println(" "); + + revision.add(relation, tcd); + System.out.println("ҵ汾"); + } + } else { + AIFComponentContext[] cc = revision.getChildren(relation); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent.add(cc[j]); + } + } + } + for (int k = 0; k < listComponent.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation( + listComponent.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println("fis.size()================= " + fis.size()); + for (int count = 0; count < fis.size(); count++) { + List filePathCount = fis.get(count); + TCComponentDataset tcd = null; + String filepath = filePathCount.get(0); + + String datasetName = did; + // String datasetName = + // did+filepath.substring(filepath.lastIndexOf("-"),filepath.lastIndexOf(".")); + tcd = datasetType.create(datasetName, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < filePathCount.size(); l++) { + importFilesOperation(tcd, new File(filePathCount.get(l)), + tcd.getType(), refs[0]); + + } + System.out.println(" "); + revision.add(relation, tcd); + System.out.println("ҵ汾"); + } + } + } else { + System.out.println("ûݼҪ"); + } + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("桿excel " + parser.startRow + "йݼ" + + datasets[i].getTcAttribute() + "ʧ"); + continue; + } + } + + // Ŀָ + if (item != null) { + String projectname = ""; + if (projectIndex != -2) { + projectname = line.get(projectIndex); + System.out.println("Ŀ=" + projectIndex); + if (projectname != null && !"".equals(projectname.trim())) { + System.out.println("ĿID=" + projectname); + TCComponentProject pro = qeary(projectname); + if (pro != null) { + pro.assignToProject(new TCComponent[] { item }); + System.out.println("ָɳɹ"); + } else { + StringBufferDemo("ʧܡѯĿ:δ鵽ĿID[" + projectname + "]\n\r", + "ʷݵ"); + fail++; + System.out.println("ûв鵽Ŀ"); + } + + } + System.out.println("ָĿơ" + projectname + ""); + + } else { + System.out.println("ҪָĿ"); + } + } + + // putDataset(parser, line, datasets, revision); + if (refresh) { + System.out.println("ɹexcel " + parser.startRow + "и"); + } else { + System.out.println("ɹexcel " + parser.startRow + "д"); + } + } + success++; + } else { + System.out.println("桿excel " + parser.startRow + "IDΪգе봦"); + } + } catch (Exception e) { + e.printStackTrace(); + StringBufferDemo("ID" + id + ",ƣ" + line.get(nameIndex) + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: " + e.toString() + "\r\n", "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: " + e.toString()); + fail++; + continue; + } + } + } catch (Exception e) { + logger.error("ʧ - " + e.toString()); + logger.debug(e.toString()); + } + } + + /** + * cavalier added on 2013-08-15 + */ + public void putDataset(JXLExcelParser parser, List line, MappingAttribute[] datasets, + TCComponentItemRevision revision) { + // TODO ⴦ + String allFilePath = ""; + String allFilePaths[] = null; + if (locationIndex != -2) { + allFilePath = line.get(locationIndex); + if (allFilePath.contains(";")) { + allFilePaths = allFilePath.split(";"); + } else if (allFilePath.contains("")) { + allFilePaths = allFilePath.split(""); + } else { + allFilePaths = new String[] { allFilePath }; + } + System.out.println("⴦ļ" + allFilePaths.length + ""); + } else { + System.out.println("⴦"); + } + int filePathIndex = 0; + + for (int i = 0; i < datasets.length; i++) { + try { + // logger.debug("ʼ" + (i + 1) + ""); + // String filePath = line.get(datasets[i].getColumnIndex()); + String filePath = null; + if (locationIndex != -2) { + if (datasets[i].getColumnIndex() == locationIndex) { + continue; + } + String fileName = line.get(datasets[i].getColumnIndex()); + if (fileName.trim().equals("")) { + System.out.println("⴦ݼΪ"); + continue; + } + + if (filePathIndex < allFilePaths.length) { + filePath = allFilePaths[filePathIndex]; + } else { + System.out.println("⴦ǿļļ飡"); + continue; + } + filePathIndex++; + logger.debug("ʼ" + (filePathIndex) + ""); + } else { + filePath = line.get(datasets[i].getColumnIndex()); + logger.debug("ʼ" + (i + 1) + ""); + } + + if (filePath.trim().length() > 0) { + + // ----------------------------------------- + AIFComponentContext[] cc22 = revision.getChildren(relation); + List listComponent22 = new ArrayList(); + System.out.println(">>>>>>>ɾݼcount=" + cc22.length); + for (int j = 0; j < cc22.length; j++) { + InterfaceAIFComponent tcc = cc22[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + // if (ods.getType().equals(ds)) { + listComponent22.add(cc22[j]); + // } + } + } + for (int k = 0; k < listComponent22.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation(listComponent22.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println(">>>>>>>ɾݼ "); + // ---------------------------------------- + System.out.println("ݼ·Ϊ" + filePath); + String ds = datasets[i].getTcAttribute(); + // String sep = ois.getArraySeparator(); + // filePathԡ||ͱʾҳɶݼԡ;ͱʾһݼӶ + String[] files = filePath.split("\\|\\|"); + List> fis = new ArrayList>(); + for (int j = 0; j < files.length; j++) { + String filepath = files[j].trim(); + if (filepath.contains(";")) { + String[] filepaths = filepath.split(";"); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + // Ҫ + try { + StringBufferDemo("ID " + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: д·" + file.getAbsolutePath() + "\r\n", + "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + fis.add(list); + } else if (filepath.contains("")) { + String[] filepaths = filepath.split(""); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + System.out.println("ļ·Ϊ" + file); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + // Ҫ + try { + StringBufferDemo( + "ID" + " " + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: дݼ·" + file.getAbsolutePath() + "\r\n", + "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + "еʧܣԭ:дݼ·" + + file.getAbsolutePath() + ""); + fail++; + continue; + } + } + fis.add(list); + } else { + System.out.println("files[" + j + "] = " + files[j]); + File file = new File(files[j].trim()); + if (file.exists()) { + List list = new ArrayList(); + list.add(file.getAbsolutePath()); + fis.add(list); + } else { + // Ҫ + try { + StringBufferDemo("ID" + " " + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: д·" + file.getAbsolutePath() + "\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + } + + if (fis.size() > 0) { + String did = line.get(datasets[i].getColumnIndex()); + if (did.contains(".") && did.contains("\\")) { + did = did.substring(did.lastIndexOf("\\") + 1, did.lastIndexOf(".")); + } + // String did = revision.getProperty("item_id"); + // did = did + "/" + + // revision.getProperty("item_revision_id"); + + System.out.println("ɵݼidΪ" + did); + String[] refs = guessDatasetReferenceNames(ds, files); + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + try { + StringBufferDemo( + "ID" + " " + ". ʧܡexcel " + parser.startRow + "еʧ,ԭ: " + "ûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨" + "\r\n", + "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + files[j] + + "ҵ,鿴" + ds + "ݼļģ嶨"); + logger.error("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + files[j] + + "ҵ,鿴" + ds + "ݼļģ嶨"); + fail++; + continue; + } + } + System.out.println("ȡϵͳָļӦݼõֳɹ"); + if (fis.size() == 1) { + AIFComponentContext[] cc2 = revision.getChildren(relation); + List listComponent2 = new ArrayList(); + System.out.println(">>ɾݼcount=" + cc2.length); + for (int j = 0; j < cc2.length; j++) { + InterfaceAIFComponent tcc = cc2[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent2.add(cc2[j]); + } + } + } + for (int k = 0; k < listComponent2.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation(listComponent2.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println(">>ɾݼ "); + + // ---------------------------------- + List listString = fis.get(0); + AIFComponentContext[] cc = revision.getChildren(relation); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getStringProperty("object_name").equals(did)) { + listComponent.add(cc[j]); + } + } + } + if (listComponent.size() > 0) { + if (listComponent.size() > 1) { + for (int k = 0; k < listComponent.size() - 1; k++) { + DeleteOperation deleteOperation = new DeleteOperation(listComponent.get(k)); + session.queueOperation(deleteOperation); + listComponent.remove(k); + k--; + } + if (listComponent.get(0).getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent.get(0) + .getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } + } + } else { + if (listComponent.get(0).getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent.get(0) + .getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } + } + } + } else { + System.out.println("ָID͵ݼѾڣ½"); + System.out.println("ds &&&&&&&&&&&&&&&&&& " + ds); + TCComponentDataset tcd = datasetType.create(did, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(tcd, new File(listString.get(l)), tcd.getType(), refs[0]); + + } + System.out.println(" "); + + revision.add(relation, tcd); + System.out.println("ҵ汾"); + } + } else { + AIFComponentContext[] cc2 = revision.getChildren(relation); + List listComponent2 = new ArrayList(); + System.out.println("ɾݼcount=" + cc2.length); + for (int j = 0; j < cc2.length; j++) { + InterfaceAIFComponent tcc = cc2[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent2.add(cc2[j]); + } + } + } + for (int k = 0; k < listComponent2.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation(listComponent2.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println("ɾݼ "); + + AIFComponentContext[] cc = revision.getChildren(relation); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent.add(cc[j]); + } + } + } + for (int k = 0; k < listComponent.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation(listComponent.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println("fis.size()================= " + fis.size()); + for (int count = 0; count < fis.size(); count++) { + List filePathCount = fis.get(count); + TCComponentDataset tcd = null; + String filepath = filePathCount.get(0); + + String datasetName = did; + // String datasetName = + // did+filepath.substring(filepath.lastIndexOf("-"),filepath.lastIndexOf(".")); + + tcd = datasetType.create(datasetName, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < filePathCount.size(); l++) { + importFilesOperation(tcd, new File(filePathCount.get(l)), tcd.getType(), refs[0]); + + } + System.out.println(" "); + revision.add(relation, tcd); + System.out.println("ҵ汾"); + } + } + } else { + System.out.println("ûݼҪ"); + } + } + } catch (Exception e) { + try { + StringBufferDemo("ID" + " " + ". ʧܡexcel " + parser.startRow + "еʧ,ԭ:йݼ" + + datasets[i].getTcAttribute() + "ʧ\r\n", "ʷݵ"); + } catch (IOException e1) { + e1.printStackTrace(); + } + System.out.println("桿excel " + parser.startRow + "йݼ" + datasets[i].getTcAttribute() + "ʧ"); + continue; + } + } + } + + private void importObjectsByPoi(ObjectsImportSettings ois, File input) { + System.out.println("뿪ʼ"); + + try { + TCComponent[] uoms = uom.extent(); + Map uomMap = new HashMap(); + if (uoms != null) { + for (int i = 0; i < uoms.length; i++) { + uomMap.put(uoms[i].toString(), uoms[i]); + } + } + int uomIndex = -1; + int idIndex = -1; + int nameIndex = -1; + + boolean isthroughParent = ois.isSelectParent(); + MappingAttribute[] items = ois.getItemMapping(); + MappingAttribute[] revisions = ois.getRevMapping(); + MappingAttribute[] forms = ois.getRevFormMapping(); + MappingAttribute[] datasetMap = ois.getDatasetMapping();// 2017/10/24 + + for (int i = 0; i < datasetMap.length; i++) { + if ("·".equals(datasetMap[i].getTcAttribute()) && "·".equals(datasetMap[i].getColumnTitle())) { + this.locationIndex = datasetMap[i].getColumnIndex(); + System.out.println(">>·Ӧ" + locationIndex); + } else { + System.out.println(">>ûҵ·" + locationIndex); + } + + } + + for (int i = 0; i < items.length; i++) { + if ("Ŀ".equals(items[i].getTcAttribute())) { + this.projectIndex = items[i].getColumnIndex(); + System.out.println(">>ĿӦ" + projectIndex); + } else { + System.out.println(">>ûҵĿ" + projectIndex); + } + + } + + for (int i = 0; i < items.length; i++) { + if ("item_id".equals(items[i].getTcAttribute())) { + idIndex = items[i].getColumnIndex(); + System.out.println("IDӦ" + idIndex); + continue; + } + if ("uom_tag".equals(items[i].getTcAttribute())) { + uomIndex = items[i].getColumnIndex(); + System.out.println("λӦΪ" + uomIndex); + } + if ("object_name".equals(items[i].getTcAttribute())) { + nameIndex = items[i].getColumnIndex(); + System.out.println("ӦΪ" + nameIndex); + } + } + + if (idIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡIDӦУɵ", "", 1); + return; + } + + if (nameIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡӦУɵ", "", 1); + return; + } + + int itemRevIndex = -1; + for (int i = 0; i < revisions.length; i++) { + if ("item_revision_id".equals(revisions[i].getTcAttribute())) { + itemRevIndex = revisions[i].getColumnIndex(); + System.out.println("汾ӦΪ" + itemRevIndex); + } + } + + POIExcelParser parser = new POIExcelParser(input, 0, ois.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + try { + String id = line.get(idIndex); + if (id.length() > 0) { + TCComponent uomCom = null; + if (uomIndex >= 0) { + String uom = line.get(uomIndex); + if (uom.length() > 0) { + uomCom = uomMap.get(uom); + + if (uomCom == null) { + StringBufferDemo("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ָĵλûϵͳж\n\r", + "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ָĵλûϵͳж."); + fail++; + continue; + } + } + } + + String rev = ""; + if (itemRevIndex > 0) { + rev = line.get(itemRevIndex); + } + TCComponentItem item = null; + item = itemType.find(id); + TCComponentItemRevision revision = null; + List ps = new ArrayList(); + boolean refresh = false; + if (item == null) { + String name = line.get(nameIndex); + if (name.equals("")) { + StringBufferDemo("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ĵΪΪֵ\n\r", + "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + // TODO Ӷ͵⴦ + if (typeIndex == -2) { + item = itemType.create(id, rev, ois.getItemType(), name, "", uomCom); + } else { + String typeTemp1 = line.get(typeIndex); + String typeTemp = typeMapTemp.get(typeTemp1); + if (typeTemp != null && typeTemp.length() > 0) { + TCTypeService typeService = session.getTypeService(); + TCComponentType type = typeService.getTypeComponent(typeTemp); + if (type == null) { + System.out.println("ʧܡexcel " + parser.startRow + "½ʧ,ԭ: Ҳ"); + continue; + } + item = itemType.create(id, rev, typeTemp, name, "", uomCom); + } else { + System.out.println("ʧܡexcel " + parser.startRow + "½ʧ,ԭ: Ҳ"); + continue; + } + } + revision = item.getLatestItemRevision(); + folder.add("contents", item); + System.out.println("ɹ "); + } else { + refresh = true; + System.out.println("ѾϵͳУҪ"); + } + + if (revision == null) { + System.out.println("ָ汾 - " + rev); + InterfaceAIFComponent[] coms = null; + coms = SearchUtility.searchComponentsCollection(session, "__Item_Revision_name_ID_and_rev", + new String[] { " ID", "汾" }, new String[] { id, rev }); + + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + } + } + + if (revision == null && !rev.equals("")) { + refresh = false; + System.out.println("Ѿ,ָİ汾,ڽ޶ָ汾"); + revision = item.getLatestItemRevision().saveAs(rev, item.getProperty("object_name"), "", + true, null, null); + System.out.println("޶ָ汾ɹ"); + } + if (revision == null) { + revision = item.getLatestItemRevision(); + } + if ((refresh && ois.isExistedRefreshed()) || !refresh) { + String name = line.get(nameIndex); + if (name.equals("")) { + StringBufferDemo("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ĵΪΪֵ\n\r", + "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + "иʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + + if (uomCom != null) { + try { + item.setReferenceProperty("uom_tag", uomCom); + } catch (Exception e) { + StringBufferDemo("ʧܡexcel " + parser.startRow + + "иʧ,ԭ: ĵλ޸,ʱѾBOM\n\r", "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + + "иʧ,ԭ: ĵλ޸,ʱѾBOM"); + fail++; + // continue; + } + } + System.out.println("ϵ"); + ps.clear(); + TCComponentIdentifierType altype = (TCComponentIdentifierType) session.getTypeService() + .getTypeComponent("Identifier"); + TCComponentIdContextRuleType tccomponentidcontextruletype = (TCComponentIdContextRuleType) session + .getTypeComponent("IdContextRule"); + TCComponentIdContext[] context; + context = tccomponentidcontextruletype.getAliasContexts(); + for (int i = 0; i < items.length; i++) { + if (items[i].equals("uom_tag") || items[i].equals("object_name")) { + continue; + } + if (items[i].getTcAttribute().equals("IMAN_aliasid")) { + TCComponentIdentifier alid = altype.createAliasIdentifier("WX3_AAA"); + alid.setReferenceProperty("idcontext", context[0]); + alid.setProperty("idfr_id", line.get(items[i].getColumnIndex())); + alid.setProperty("object_name", "wx"); + alid.setProperty("object_desc", ""); + alid.save(); + item.add("IMAN_aliasid", alid); + continue; + } + TCProperty property = item.getTCProperty(items[i].getTcAttribute()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + if (property.getPropertyName().equals("item_id")) { + continue; + } + setTCProperty(property, line.get(items[i].getColumnIndex())); + ps.add(property); + } + } + item.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("ϵԳɹɸ "); + + System.out.println("´汾ϵ"); + revision.setProperty("object_name", item.getProperty("object_name")); + ps.clear(); + for (int i = 0; i < revisions.length; i++) { + TCProperty property = revision.getTCProperty(revisions[i].getTcAttribute()); + + System.out.println("property:" + revisions[i].getTcAttribute()); + System.out.println("type:" + property.getPropertyType()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + logger.debug(" - " + property.getPropertyName()); + String propertyName = property.getName(); + String relatedItemType = null; + if (propertyName.equals("MnfBrandOAttr")) { + relatedItemType = "MnfBrandObj"; + } else if (propertyName.equals("MnfCategoryOAttr")) { + relatedItemType = "MnfCategoryObj"; + } else if (propertyName.equals("MnfProdLineOAttr")) { + relatedItemType = "MnfProdLineObj"; + } else if (propertyName.equals("MnfSeasonOAttr")) { + relatedItemType = "MnfSeasonObj"; + } else if (propertyName.equals("MnfSeriesOAttr")) { + relatedItemType = "MnfSeriesObj"; + } else if (propertyName.equals("MnfStyleOAttr")) { + relatedItemType = "MnfStyleObj"; + } else if (propertyName.equals("MnfMaterialBOAttr")) { + relatedItemType = "MnfMaterialBType"; + } else if (propertyName.equals("MnfMaterialSOAttr")) { + relatedItemType = "MnfMaterialSType"; + } + if (relatedItemType != null) { + logger.debug("ֺͨͲҶӦItem"); + InterfaceAIFComponent[] cs = SearchUtility.searchComponentsCollection(session, + "ConnorItemSearch", new String[] { "Name1", "Type1" }, + new String[] { line.get(revisions[i].getColumnIndex()), + relatedItemType + "Revision" }); + if (cs != null && cs.length > 0) { + logger.debug("ҵΪ" + line.get(revisions[i].getColumnIndex()) + ",Ϊ" + + relatedItemType + "Ķ"); + if (cs[0] instanceof TCComponentItemRevision) { + TCComponentItemRevision tcc = (TCComponentItemRevision) cs[0]; + property.setPropertyData(tcc); + } + } else { + StringBufferDemo("ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ\n\r", "ʷݵ"); + logger.error("ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ"); + System.out.println("ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ"); + fail++; + continue; + } + } else { + + setTCProperty(property, line.get(revisions[i].getColumnIndex())); + } + ps.add(property); + } + } + revision.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("´ϵԳɹ "); + TCComponentForm form = getItemRevisionMasterForm(revision); + if (form != null) { + System.out.println("ȡ汾Formɹ,ʼ"); + ps.clear(); + + //2021/11/10ϰ˷lovж + String zlb=""; + String flb=""; + for (int i = 0; i < forms.length; i++) { + if (forms[i].getTcAttribute().equals("lb2_cpxzlb")) { + zlb=line.get(forms[i].getColumnIndex()); + continue; + } + if (forms[i].getTcAttribute().equals("lb2_cpxflb")) { + flb=line.get(forms[i].getColumnIndex()); + continue; + } + TCProperty property = form.getTCProperty(forms[i].getTcAttribute()); + if (property != null && property.getDescriptor().isModifiable()) { + + setTCProperty(property, line.get(forms[i].getColumnIndex())); + ps.add(property); + } + } + form.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + form.save(); + if(!zlb.equals("")) { + String zlbzsz=""; + String flbzsz=""; + System.out.println("ʼülov"+zlb+"----"+flb); + TCProperty tcProperty = form.getTCProperty("lb2_cpxzlb"); + TCComponentListOfValues lov = tcProperty.getLOV(); + String[] strs1 = lov.getListOfValues().getStringListOfValues(); + if (strs1!=null) { + TCComponentListOfValues lov2=null; + for (int i = 0; i < strs1.length; i++) { + String a1 = lov.getListOfValues().getDisplayableValue(strs1[i]);//ʾֵ + if (zlb.equals(a1)) { + zlbzsz=strs1[i]; + lov2=lov.getListOfFilterOfValue(strs1[i]); + break; + } + } + if (lov2!=null) { + String[] strs2 = lov2.getListOfValues().getStringListOfValues(); + if (strs2!=null) { + for (int i = 0; i < strs2.length; i++) { + String a2 = lov2.getListOfValues().getDisplayableValue(strs2[i]);//ʾֵ + if (flb.equals(a2)) { + flbzsz=strs2[i]; + break; + } + } + + } + } + } + if (!zlbzsz.equals("")) { + System.out.println(":"+zlbzsz); + form.setStringProperty("lb2_cpxzlb", zlbzsz); + } + if (!flbzsz.equals("")) { + System.out.println("÷:"+flbzsz); + form.setStringProperty("lb2_cpxflb", flbzsz); + } + } + + + } else { + System.out.println("ȡ汾Formʧ"); + } + // TODO ݼ + MappingAttribute[] datasets = ois.getDatasetMapping(); + System.out.println("汾ݼ, " + datasets.length + "Ҫ"); + ps.clear(); + // TODO ⴦ + String allFilePath = ""; + String allFilePaths[] = null; + if (locationIndex != -2) { + allFilePath = line.get(locationIndex); + if (allFilePath.contains(";")) { + allFilePaths = allFilePath.split(";"); + } else if (allFilePath.contains("")) { + allFilePaths = allFilePath.split(""); + } else { + allFilePaths = new String[] { allFilePath }; + } + System.out.println("⴦ļ" + allFilePaths.length + ""); + } else { + System.out.println("⴦"); + } + int filePathIndex = 0; + for (int i = 0; i < datasets.length; i++) { + System.out.println("dataset:" + datasets[i].getColumnIndex()); + System.out.println("dataset2:" + datasets[i].getColumnTitle()); + try { + String filePath = null; + if (locationIndex != -2) { + if (datasets[i].getColumnIndex() == locationIndex) { + continue; + } + String fileName = line.get(datasets[i].getColumnIndex()); + if (fileName.trim().equals("")) { + System.out.println("⴦ݼΪ"); + continue; + } + + if (filePathIndex < allFilePaths.length) { + filePath = allFilePaths[filePathIndex]; + } else { + System.out.println("⴦ǿļļ飡"); + continue; + } + filePathIndex++; + logger.debug("ʼ" + (filePathIndex) + ""); + } else { + filePath = line.get(datasets[i].getColumnIndex()); + logger.debug("ʼ" + (i + 1) + ""); + } + if (filePath.trim().length() > 0) { + System.out.println("ݼ·Ϊ" + filePath); + String ds = datasets[i].getTcAttribute(); + // String sep = ois.getArraySeparator(); + // filePathԡ||ͱʾҳɶݼԡ;ͱʾһݼӶ + String[] files = filePath.split("\\|\\|"); + List> fis = new ArrayList>(); + for (int j = 0; j < files.length; j++) { + String filepath = files[j].trim(); + if (filepath.contains(";")) { + String[] filepaths = filepath.split(";"); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + // Ҫ + StringBufferDemo("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·\r\n", "ʷݵ"); + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + fis.add(list); + } else if (filepath.contains("")) { + String[] filepaths = filepath.split(""); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + System.out.println("ļ·Ϊ" + file); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + // Ҫ + StringBufferDemo("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·\n\r", "ʷݵ"); + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + fis.add(list); + } else { + System.out.println("files[" + j + "] = " + files[j]); + File file = new File(files[j].trim()); + if (file.exists()) { + List list = new ArrayList(); + list.add(file.getAbsolutePath()); + fis.add(list); + } else { + // Ҫ + StringBufferDemo("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·\n\r", "ʷݵ"); + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + logger.error("ʧܡexcel " + parser.startRow + + "еʧܣԭ:дݼ·"); + fail++; + continue; + } + } + } + + if (fis.size() > 0) { + String did = line.get(datasets[i].getColumnIndex()); + if (did.contains(".") && did.contains("\\")) { + did = did.substring(did.lastIndexOf("\\") + 1, did.lastIndexOf(".")); + } + // String did = + // revision.getProperty("item_id"); + // did = did + "/" + + // revision.getProperty("item_revision_id"); + + System.out.println("ɵݼidΪ" + did); + String[] refs = guessDatasetReferenceNames(ds, files); + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + StringBufferDemo("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨\n\r", + "ʷݵ"); + logger.error("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨"); + System.out + .println("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨"); + fail++; + continue; + } + } + System.out.println("ȡϵͳָļӦݼõֳɹ"); + if (fis.size() == 1) { + List listString = fis.get(0); + AIFComponentContext[] cc = revision.getChildren(relation); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getStringProperty("object_name").equals(did)) { + listComponent.add(cc[j]); + } + } + } + if (listComponent.size() > 0) { + if (listComponent.size() > 1) { + for (int k = 0; k < listComponent.size() - 1; k++) { + DeleteOperation deleteOperation = new DeleteOperation( + listComponent.get(k)); + session.queueOperation(deleteOperation); + listComponent.remove(k); + k--; + } + if (listComponent.get(0) + .getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent + .get(0).getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } + } + } else { + if (listComponent.get(0) + .getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent + .get(0).getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + + } + } + } + } + } else { + System.out.println("ָID͵ݼѾڣ½"); + System.out.println("ds &&&&&&&&&&&&&&&&&& " + ds); + TCComponentDataset tcd = datasetType.create(did, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(tcd, new File(listString.get(l)), + tcd.getType(), refs[0]); + + } + System.out.println(" "); + + revision.add(relation, tcd); + System.out.println("ҵ汾"); + } + } else { + AIFComponentContext[] cc = revision.getChildren(relation); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent.add(cc[j]); + } + } + } + for (int k = 0; k < listComponent.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation( + listComponent.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println("fis.size()================= " + fis.size()); + for (int count = 0; count < fis.size(); count++) { + List filePathCount = fis.get(count); + TCComponentDataset tcd = null; + String filepath = filePathCount.get(0); + + String datasetName = did; + // String datasetName = + // did+filepath.substring(filepath.lastIndexOf("-"),filepath.lastIndexOf(".")); + tcd = datasetType.create(datasetName, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < filePathCount.size(); l++) { + importFilesOperation(tcd, new File(filePathCount.get(l)), + tcd.getType(), refs[0]); + + } + System.out.println(" "); + revision.add(relation, tcd); + System.out.println("ҵ汾"); + } + } + } else { + System.out.println("ûݼҪ"); + } + } + } catch (Exception e) { + System.out.println("桿excel " + parser.startRow + "йݼ" + + datasets[i].getTcAttribute() + "ʧ"); + continue; + } + } + // + + // Ŀָ + if (item != null) { + String projectname = ""; + if (projectIndex != -2) { + projectname = line.get(projectIndex); + if (projectname != null && !"".equals(projectname.trim())) { + TCComponentProject pro = qeary(projectname); + if (pro != null) { + pro.assignToProject(new TCComponent[] { item }); + System.out.println("ָɳɹ"); + } else { + StringBufferDemo("ʧܡѯĿ:δ鵽Ŀ[" + projectname + "]\n\r", + "ʷݵ"); + fail++; + System.out.println("ûв鵽Ŀ"); + } + + } + System.out.println("ָĿơ" + projectname + ""); + + } else { + System.out.println("ҪָĿ"); + } + } + + if (refresh) { + System.out.println("ɹexcel " + parser.startRow + "и"); + } else { + System.out.println("ɹexcel " + parser.startRow + "д"); + } + } + success++; + } else { + System.out.println("桿excel " + parser.startRow + "IDΪգе봦"); + } + } catch (Exception e) { + e.printStackTrace(); + StringBufferDemo("ʧܡexcel " + parser.startRow + "еʧ,ԭ: " + e.toString() + "\n\r", + "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: " + e.toString()); + fail++; + continue; + } + } + } catch (Exception e) { + logger.error("ʧ - " + e.toString()); + logger.debug(e.toString()); + } + } + + private TCComponentProject qeary(String str) { + // TODO Auto-generated method stub + TCComponent[] projects = null; + try { + projects = session.search("Ŀ...", new String[] { "Ŀ ID" }, new String[] { str }); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + try { + StringBufferDemo("ʧܡѯĿ:" + e.getMessage() + "\n\r", "ʷݵ"); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + fail++; + } + if (projects != null && projects.length > 0) { + return (TCComponentProject) projects[0]; + } + return null; + } + + private String[] guessDatasetReferenceNames(String ds, String[] files) throws TCException { + System.out.println("ʼȡϵͳָļӦݼõ"); + System.out.println("ds==" + ds); + System.out.println("files.length==" + files.length); + System.out.println("files[0]==" + files[0]); + TCComponentDatasetDefinition definition = dsdefType.find(ds); + System.out.println("definition==" + definition); + NamedReferenceContext[] contexts = definition.getNamedReferenceContexts(); + System.out.println("contexts.length==" + contexts.length); + Hashtable hashtable = new Hashtable(contexts.length); + String all = ""; + for (int i = 0; i < contexts.length; i++) { + String template = contexts[i].getFileTemplate(); + int index = template.lastIndexOf("."); + if (index != -1) { + hashtable.put(template.substring(index + 1).toLowerCase(), contexts[i].getNamedReference()); + } else { + all = template.toLowerCase(); + hashtable.put(all, contexts[i].getNamedReference()); + } + } + + String refers[] = new String[files.length]; + System.out.println("" + files.length + "ļҪȡݼ"); + for (int i = 0; i < files.length; i++) { + String name = (new File(files[i])).getName(); + refers[i] = hashtable.get(name.substring(name.lastIndexOf(".") + 1).toLowerCase()); + if (refers[i] == null) { + refers[i] = hashtable.get(all); + } + + System.out.println(name.substring(name.lastIndexOf(".") + 1).toLowerCase() + "Ӧ" + refers[i]); + } + + return refers; + } + + + private Map fqmmap=new HashMap(); + private Map cbfqmap=new HashMap(); + + private void setTCProperty(TCProperty property, String value) throws TCException { + System.out.println("setTCProperty(TCProperty property =" + property.getPropertyName() + ", String value=" + + value + ") - start"); + // if (value == null || value.length() == 0) { + // System.out.println("setTCProperty(TCProperty property, String value) + // - end"); + // return; + // } + if (value == null || value.trim().length() == 0) + return; + + // //lovתʵֵ2017.11.8 + // TCComponentListOfValues lov=property.getLOV(); + // if(lov!=null){//жǷlov + // String[] strs=lov.getListOfValues().getStringListOfValues();//ʵֵ + // for(String s1:strs){ + // String a1 = lov.getListOfValues().getDisplayableValue(s1);//ʵֵӦʾֵ + // if(a1.equals(value)){ + // System.out.println(); + // value=s1; //ʾֵΪʵֵ + // break; + // } + // } + // } + if (property.getPropertyName().equals("lb2_fqm")) { + System.out.println("ǷȺ,ֵ:"+value); + if (fqmmap!=null&&fqmmap.size()>0) { + for (String key : fqmmap.keySet()) { + if (key.equals(value)) { + value=key + " " + fqmmap.get(key); + break; + } + + } + }else { + TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + String tabalename = session.getPreferenceService().getStringValue("PE_IMZ_V");// Ⱥ + DataBaseControl data = new DataBaseControl(session); + fqmmap = data.getFQM(tabalename); + for (String key : fqmmap.keySet()) { + if (key.equals(value)) { + value=key + " " + fqmmap.get(key); + break; + } + + } + } + + System.out.println("תֵ:"+value); + } + + if (property.getPropertyName().equals("lb2_cbfq")) { + System.out.println("dzɱȺ,ֵ:"+value); + if (cbfqmap!=null&&cbfqmap.size()>0) { + for (String key : cbfqmap.keySet()) { + if (key.equals(value)) { + value=key + " " + cbfqmap.get(key); + break; + } + + } + }else{ + TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + String tabalename = session.getPreferenceService().getStringValue("PE_AZF_V");// ɱȺ + DataBaseControl data = new DataBaseControl(session); + cbfqmap = data.getCBFQM(tabalename); + for (String key : cbfqmap.keySet()) { + if (key.equals(value)) { + value=key + " " + cbfqmap.get(key); + break; + } + + } + + } + + System.out.println("תֵ:"+value); + } + + + TCPropertyDescriptor descriptor = property.getPropertyDescriptor(); + boolean isArray = descriptor.isArray(); + if (!isArray) { + + switch (descriptor.getType()) { + + case TCProperty.PROP_string: + case TCProperty.PROP_long_string: + logger.debug("ӦΪַ"); + TCComponentListOfValues lov = property.getLOV(); + if (lov!=null) { + String[] strs = lov.getListOfValues().getStringListOfValues(); + if (strs!=null) { + for (int i = 0; i < strs.length; i++) { + String a1 = lov.getListOfValues().getDisplayableValue(strs[i]); + if (a1.equals(value)) { + value=strs[i]; + break; + } + } + }else { + System.out.println("̬lov"); + if ("Fnd0ListOfValuesDynamic".equals(lov.getProperty("lov_type"))) { + + } + } + + } + property.setStringValueData(value); + break; + case TCProperty.PROP_char: + logger.debug("ӦΪַ"); + if (value.length() > 0) { + property.setCharValueData(value.charAt(0)); + } + break; + case TCProperty.PROP_double: + logger.debug("ӦΪdouble"); + if (value == null || value.trim().length() == 0) + property.setDoubleValueData((Integer) null); + else + property.setDoubleValueData(Double.parseDouble(value)); + break; + case TCProperty.PROP_float: + logger.debug("ӦΪfloat"); + if (value == null || value.trim().length() == 0) + property.setFloatValueData((Integer) null); + else + property.setFloatValueData(Float.parseFloat(value)); + break; + case TCProperty.PROP_int: + case TCProperty.PROP_short: + logger.debug("ӦΪintshort"); + if (value == null || value.trim().length() == 0) + property.setIntValueData((Integer) null); + else + property.setIntValueData(Integer.parseInt(value)); + break; + case TCProperty.PROP_logical: + logger.debug("ӦΪBoolean"); + property.setLogicalValueData(Boolean.parseBoolean(value)); + break; + case TCProperty.PROP_date: + logger.debug("ӦΪ"); + try { + Date date=null; + try { + date=new SimpleDateFormat("yyyy-MM-dd").parse(value); + } catch (Exception e) { + // TODO: handle exception + try { + date=new SimpleDateFormat("yyyy/MM/dd").parse(value); + } catch (Exception e2) { + // TODO: handle exception + date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value); + } + + } + if (date!=null) { + property.setDateValueData(date); + } + + } catch (ParseException e) { + logger.error("setTCProperty(TCProperty property, String value)", e); + + e.printStackTrace(); + } + break; + } + } else { + System.out.println("ӦΪͣԴ"); + String[] split = value.split(";"); + List list=new ArrayList(); + switch (descriptor.getType()) { + + case TCProperty.PROP_string: + case TCProperty.PROP_long_string: + logger.debug("ӦΪַ"); + + + if (split.length>0) { + for (int t = 0; t < split.length; t++) { + String spval=split[t]; + TCComponentListOfValues lov = property.getLOV(); + if (lov!=null) { + String[] strs = lov.getListOfValues().getStringListOfValues(); + if (strs!=null) { + for (int i = 0; i < strs.length; i++) { + String a1 = lov.getListOfValues().getDisplayableValue(strs[i]); + if (a1.equals(spval)) { + spval=strs[i]; + break; + } + } + }else { + System.out.println("̬lov"); + + } + + } + list.add(spval); + } + } + if (list.size()>0) { + property.setStringValueArray(list.toArray(new String[list.size()] )); + } + break; + case TCProperty.PROP_char: + logger.debug("ӦΪַ,"); + + break; + case TCProperty.PROP_double: + logger.debug("ӦΪdouble"); + if (split.length>0) { + for (int t = 0; t < split.length; t++) { + String spval=split[t]; + if (spval == null || spval.trim().length() == 0) { + + }else{ + list.add(Double.parseDouble(spval)); + } + } + } + if (list.size()>0) { + + //property.setDoubleValueArray(list.toArray(new Double[list.size()])); + } + break; + case TCProperty.PROP_float: + logger.debug("ӦΪfloat"); + if (split.length>0) { + for (int t = 0; t < split.length; t++) { + String spval=split[t]; + if (spval == null || spval.trim().length() == 0) { + + }else{ + list.add(Float.parseFloat(spval)); + } + } + } + if (list.size()>0) { + + //property.setFloatValueArray(list.toArray(new Float[list.size()])); + } + break; + case TCProperty.PROP_int: + case TCProperty.PROP_short: + logger.debug("ӦΪintshort"); + if (split.length>0) { + for (int t = 0; t < split.length; t++) { + String spval=split[t]; + if (spval == null || spval.trim().length() == 0) { + + }else{ + list.add(spval); + } + } + } + if (list.size()>0) { + + //property.setIntegerValueArray(list.toArray(new Integer[list.size()])); + } + break; + case TCProperty.PROP_logical: + logger.debug("ӦΪBoolean"); + if (split.length>0) { + for (int t = 0; t < split.length; t++) { + String spval=split[t]; + if (spval == null || spval.trim().length() == 0) { + + }else{ + list.add(Boolean.parseBoolean(value)); + } + } + } + if (list.size()>0) { + + //property.setLogicalValueArray(list.toArray(new Float[list.size()])); + } + break; + case TCProperty.PROP_date: + logger.debug("ӦΪ"); + if (split.length>0) { + for (int t = 0; t < split.length; t++) { + String spval=split[t]; + if (spval == null || spval.trim().length() == 0) { + + }else{ + try { + Date date=null; + try { + date=new SimpleDateFormat("yyyy-MM-dd").parse(value); + } catch (Exception e) { + // TODO: handle exception + try { + date=new SimpleDateFormat("yyyy/MM/dd").parse(value); + } catch (Exception e2) { + // TODO: handle exception + date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value); + } + } + if (date!=null) { + list.add(date); + } + + + } catch (ParseException e) { + logger.error("setTCProperty(TCProperty property, String value)", e); + + e.printStackTrace(); + } + + } + } + } + if (list.size()>0) { + + property.setDateValueArray(list.toArray(new Date[list.size()])); + } + + + break; + } + } + + System.out.println("setTCProperty(TCProperty property, String value) - end"); + } + + private TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws TCException { + 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) { + TCComponentForm form = (TCComponentForm) component; + + return form; + } + } + } + + return null; + } + + public void removeNRFiles(TCComponentDataset dataset, String namedReference, TCComponentTcFile files[]) + throws Exception { + + System.out.println("--------------------ʼɾļ------------------------"); + + try { + + TCComponent comps[] = dataset.getNamedRefComponents(namedReference); + if (comps != null && comps.length > 0) { + + for (int i = 0; i < comps.length; i++) + dataset.removeNamedReference(namedReference); + + } + for (int i = 0; i < files.length; i++) + if (files[i] != null) { + + try { + System.out.println("delete file " + files[i].getPath()); + files[i].delete(); + } catch (Exception e) { + e.printStackTrace(); + + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public void importFilesOperation(TCComponentDataset dataset, File file, String fileType, String refType) { + System.out.println("-----------------------------ʼļϴ---------------------------"); + + String as[] = { file.getPath() }; + String as1[] = { fileType }; + String as2[] = { "Plain" }; + String as3[] = { refType }; + System.out.println("fileType:" + fileType); + System.out.println("file.getPath()&&&&&&&&&&&&&&&&&&& " + file.getPath()); + try { + dataset.setFiles(as, as1, as2, as3); + } catch (TCException e) { + + e.printStackTrace(); + } + session.setReadyStatus(); + + } + + // д־ + public void StringBufferDemo(String strContext, String strFileName) throws IOException { + // logpath = System.getProperty("java.io.tmpdir")+File.separator+ + // strFileName; + + logpath = System.getenv("TEMP") + "\\" + strFileName + "_" + systitem + ".log"; + File file = new File(logpath); + if (!file.exists()) + file.createNewFile(); + FileOutputStream out = new FileOutputStream(file, true); + StringBuffer sb = new StringBuffer(strContext); + // System.out.println("־"+sb.toString()); + out.write(sb.toString().getBytes("gb2312")); + out.close(); + } + + // //ɾ־ + // public void deleteLog(String strFileName) throws IOException { + // File file = new + // File(System.getProperty("java.io.tmpdir")+File.separator+"OriginTemp" + + // strFileName); + // if (file.exists()) + // file.delete(); + // } + + // javaC bypass + public void setByPass(boolean val) throws TCException { + if (userservice == null) { + userservice = this.session.getUserService(); + } + Object[] obj = new Object[1]; + obj[0] = "origin"; + if (val) { +// userservice.call("ORIGIN_set_bypass", obj); + userservice.call("connor_open_bypass", new Object[] { "true" }); + } else { +// userservice.call("ORIGIN_close_bypass", obj); + userservice.call("connor_close_bypass", new Object[] { "false" }); + } + } + + public void sendItem() { + TCUserService service = this.session.getUserService(); + + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + InterfaceAIFComponent comp = app.getTargetComponent(); + + try { + + if (StaticEnum.isExec) { + + comp = session.getUser().getNewStuffFolder(); + } + Object returnObj = service.call("SendItem", new Object[] { comp }); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public static void main(String[] args) { + String filePath = "C:\\11.txt||C:\\22.txt"; + String[] str = filePath.split("\\|\\|"); + System.out.println(str.length); + System.out.println(str[0]); + System.out.println(str[1]); + } +} diff --git a/src/com/connor/dev/imp/ImportForProEFlex.java b/src/com/connor/dev/imp/ImportForProEFlex.java new file mode 100644 index 0000000..46806ec --- /dev/null +++ b/src/com/connor/dev/imp/ImportForProEFlex.java @@ -0,0 +1,2205 @@ +package com.connor.dev.imp; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.connor.dev.imp.bom.BomsImportSettings; +import com.connor.dev.imp.ob.ObjectsImportSettings; +import com.connor.dev.imp.re.RelationsImportSettings; +import com.connor.dev.imp.toolkit.JXLExcelParser; +import com.connor.dev.imp.toolkit.POIExcelParser; +import com.connor.dev.imp.toolkit.ProgressReporter; +import com.connor.dev.imp.toolkit.SearchUtility; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.commands.delete.DeleteOperation; +import com.teamcenter.rac.kernel.NamedReferenceContext; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMView; +import com.teamcenter.rac.kernel.TCComponentBOMViewRevision; +import com.teamcenter.rac.kernel.TCComponentBOMViewRevisionType; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetDefinition; +import com.teamcenter.rac.kernel.TCComponentDatasetDefinitionType; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentIdContext; +import com.teamcenter.rac.kernel.TCComponentIdContextRuleType; +import com.teamcenter.rac.kernel.TCComponentIdentifier; +import com.teamcenter.rac.kernel.TCComponentIdentifierType; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.util.MessageBox; + +public class ImportForProEFlex { + /** + * Logger for this class + */ + private static final Logger logger = Logger.getLogger(ImportForProEFlex.class); + + private TCComponentFolder folder; + + private TCTypeService service; + + private TCComponentType uom; + private TCComponentItemType itemType; + private TCComponentDatasetType datasetType; + + private TCComponentDatasetDefinitionType dsdefType; + private TCComponentBOMWindowType winType; + public String searchName = "__Item_Revision_name_ID_and_rev"; + String[] keys=new String[] { " ID", "汾" }; + String[] keys1=new String[] { " ID"}; + public int success = 0; + + public int fail = 0; + + public int k = 1;// ݼ汾 + + public String logpath = "";// ־· + + public String systitem = ""; + + private TCSession session; + private ProgressReporter reporter; + private TCUserService userservice; + + // Ӽ¼ҪBOMĶ + private HashMap hasBOMMap; + + /** + * Creates a new instance of ImportFlex. + * + * @param session + * @param reporter + * @throws TCException + */ + public ImportForProEFlex(TCSession session, ProgressReporter reporter) throws TCException { + this.session = session; + this.reporter = reporter; + this.userservice = session.getUserService(); + this.hasBOMMap = new HashMap(); + + logger.debug("ʼʼImportFlex"); + service = session.getTypeService(); + + uom = service.getTypeComponent("UnitOfMeasure"); + itemType = (TCComponentItemType) service.getTypeComponent("Item"); + datasetType = (TCComponentDatasetType) service.getTypeComponent("Dataset"); + dsdefType = (TCComponentDatasetDefinitionType) service.getTypeComponent("DatasetType"); + winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow"); + if (AIFUtility.getCurrentApplication().getTargetComponent() instanceof TCComponentFolder) { + folder = (TCComponentFolder) AIFUtility.getCurrentApplication().getTargetComponent(); + } + + logger.debug("ImportFlexʼ"); + } + + /** + * runImporting:(ʵݵ ) + * + * @param settings + * ݵѡ + * @param input + * 趨ļ + * @since CodingExample Ver 1.1 + */ + public void runImporting(ImportSettings settings, File input) { + + System.out.println("I AM 1"); + systitem = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()); + success = 0; + fail = 0; + System.out.println("Ҫļ·Ϊ" + input.getAbsolutePath()); + if (input.getAbsolutePath().endsWith(".xls")) { + if (settings instanceof ObjectsImportSettings) { + System.out.println("ҪΪ"); + ObjectsImportSettings ois = (ObjectsImportSettings) settings; + importObjectsByJxl(ois, input); + System.out.println(""); + } else if (settings instanceof BomsImportSettings) { + System.out.println("ҪΪBOM"); + BomsImportSettings bis = (BomsImportSettings) settings; + importBomsByJxl(bis, input); + System.out.println("BOM"); + } else { + System.out.println("ҪΪϵ"); + RelationsImportSettings ris = (RelationsImportSettings) settings; + importRelationsByJxl(ris, input); + System.out.println("ϵ"); + } + } else if (input.getAbsolutePath().endsWith(".xlsx")) { + if (settings instanceof ObjectsImportSettings) { + System.out.println("ҪΪ"); + ObjectsImportSettings ois = (ObjectsImportSettings) settings; + importObjectsByPoi(ois, input); + System.out.println(""); + } else if (settings instanceof BomsImportSettings) { + System.out.println("ҪΪBOM"); + BomsImportSettings bis = (BomsImportSettings) settings; + importBomsByPoi(bis, input); + System.out.println("BOM"); + } else { + System.out.println("ҪΪϵ"); + RelationsImportSettings ris = (RelationsImportSettings) settings; + importRelationsByPoi(ris, input); + System.out.println("ϵ"); + } + } + + System.out.println("I AM 2"); + } + + private void importRelationsByJxl(RelationsImportSettings ris, File input) { + System.out.println("ϵ뿪ʼ"); + + if (ris.getCurrentItemID() == null || ris.getRelativeItemID() == null) { + MessageBox.post("ѡǰĿIDӦϵִе", "", 1); + return; + } + + int currentIndex = ris.getCurrentItemID().getColumnIndex(); + System.out.println("ǰӦΪ" + currentIndex); + int relativeIndex = ris.getRelativeItemID().getColumnIndex(); + System.out.println("ĿӦΪ" + relativeIndex); + + String relation = ris.getRelation(); + String propertyName = ""; + if (relation.equals("")) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + } + int propertyIndex = -2; + if (ris.getProperty() != null) { + propertyIndex = ris.getProperty().getColumnIndex(); + } + try { + System.out.println("ʼʼexcelļ"); + JXLExcelParser parser = new JXLExcelParser(input, 0, ris.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String currentID = line.get(currentIndex).trim(); + String relativeID = line.get(relativeIndex).trim(); + if (propertyIndex != -2) { + propertyName = line.get(propertyIndex).trim(); + } + + // if ((propertyName == null) || (propertyName.length() == 0) || + // (relation == null) || (relation.length() == 0)) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + // } + if (currentID.equals("") || relativeID.equals("")) { + System.out.println("桿excel " + parser.startRow + "IDĿIDΪ,е"); + System.out.println("ǰIDĿIDΪգд"); + continue; + } + + System.out.println("ʼҵǰ"); + TCComponentItem currentItem = itemType.find(currentID); + if (currentItem == null) { + System.out.println("桿excel " + parser.startRow + ",е"); + System.out.println("ָĵǰ"); + continue; + } + System.out.println("ǰ"); + + System.out.println("ʼĿ"); + TCComponentItem relativeItem = itemType.find(relativeID); + if (relativeItem == null) { + System.out.println("桿excel " + parser.startRow + "Ŀ,е"); + System.out.println("ָĿ"); + continue; + } + System.out.println("Ŀ"); + + String currentRevision = null; + if (ris.getCurrentItemRevision() != null) { + currentRevision = line.get(ris.getCurrentItemRevision().getColumnIndex()); + } + + String relativeRevision = null; + if (ris.getRelativeItemRevision() != null) { + relativeRevision = line.get(ris.getRelativeItemRevision().getColumnIndex()); + } + if (relation.equals("")) { + if (propertyName != "") { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + propertyName); + } + } else { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + relation); + } + } + } catch (Exception e) { + logger.error("ϵʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + } + + private void importRelationsByPoi(RelationsImportSettings ris, File input) { + System.out.println("ϵ뿪ʼ"); + + if (ris.getCurrentItemID() == null || ris.getRelativeItemID() == null) { + MessageBox.post("ѡǰĿIDӦϵִе", "", 1); + return; + } + + int currentIndex = ris.getCurrentItemID().getColumnIndex(); + System.out.println("ǰӦΪ" + currentIndex); + int relativeIndex = ris.getRelativeItemID().getColumnIndex(); + System.out.println("ĿӦΪ" + relativeIndex); + + String relation = ris.getRelation(); + String propertyName = ""; + if (relation.equals("")) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + } + int propertyIndex = -2; + if (ris.getProperty() != null) { + propertyIndex = ris.getProperty().getColumnIndex(); + } + try { + System.out.println("ʼʼexcelļ"); + POIExcelParser parser = new POIExcelParser(input, 0, ris.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String currentID = line.get(currentIndex).trim(); + String relativeID = line.get(relativeIndex).trim(); + if (propertyIndex != -2) { + propertyName = line.get(propertyIndex).trim(); + } + + // if ((propertyName == null) || (propertyName.length() == 0) || + // (relation == null) || (relation.length() == 0)) { + // MessageBox.post("ָĹϵΪգָϵ", "", 1); + // return; + // } + if (currentID.equals("") || relativeID.equals("")) { + System.out.println("桿excel " + parser.startRow + "IDĿIDΪ,е"); + System.out.println("ǰIDĿIDΪգд"); + continue; + } + + System.out.println("ʼҵǰ"); + TCComponentItem currentItem = itemType.find(currentID); + if (currentItem == null) { + System.out.println("桿excel " + parser.startRow + ",е"); + System.out.println("ָĵǰ"); + continue; + } + System.out.println("ǰ"); + + System.out.println("ʼĿ"); + TCComponentItem relativeItem = itemType.find(relativeID); + if (relativeItem == null) { + System.out.println("桿excel " + parser.startRow + "Ŀ,е"); + System.out.println("ָĿ"); + continue; + } + System.out.println("Ŀ"); + + String currentRevision = null; + if (ris.getCurrentItemRevision() != null) { + currentRevision = line.get(ris.getCurrentItemRevision().getColumnIndex()); + } + + String relativeRevision = null; + if (ris.getRelativeItemRevision() != null) { + relativeRevision = line.get(ris.getRelativeItemRevision().getColumnIndex()); + } + if (relation.equals("")) { + if (propertyName != "") { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + propertyName); + } + } else { + establishRelation(parser.startRow, currentItem, relativeItem, currentRevision, relativeRevision, + relation); + } + } + } catch (Exception e) { + logger.error("ϵʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + } + + private void establishRelation(int row, TCComponentItem currentItem, TCComponentItem relativeItem, + String currentRevision, String relativeRevision, String relation) throws Exception { + TCComponent parent = currentItem; + TCComponent child = relativeItem; + System.out.println("relation====" + relation); + TCComponentItemRevision revision = null; + if ((currentRevision == null) || (currentRevision.length() == 0)) { + System.out.println("ûָǰİ汾"); + // revision = currentItem.getLatestItemRevision(); + } else { + System.out.println("ʼָĵǰ汾"); + // InterfaceAIFComponent[] coms = + // SearchUtility.searchComponentsCollection(session, + // "originSearchItemRevision", new String[] { "ItemID", "Revision" + // }, new String[] { currentItem.getProperty("item_id"), + // currentRevision }); + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName, + keys, + new String[] { currentItem.getProperty("item_id"), currentRevision }); + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + } + + // TCComponentItemRevision[] revisions = + // currentItem.getWorkingItemRevisions(); + // for (int i = 0; i < revisions.length; i++) + // { + // if + // (currentRevision.equals(revisions[i].getProperty("item_revision_id"))) + // { + // revision = revisions[i]; + // break; + // } + // } + + if (revision == null) { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָĵǰİ汾"); + StringBufferDemo("ID" + currentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĵǰİ汾\r\n", "ʷݵϵ"); + fail++; + System.out.println("ָĵǰİ汾"); + return; + } + + System.out.println("ָĵǰ汾ɹ"); + + parent = revision; + } + + TCComponentItemRevision re = null; + if (relativeRevision == null) { + System.out.println("ûָĿ İ汾"); + // re = relativeItem.getLatestItemRevision(); + } else { + System.out.println("ʼĿ汾"); + + // InterfaceAIFComponent[] coms = + // SearchUtility.searchComponentsCollection(session, + // "originSearchItemRevision", new String[] { "ItemID", "Revision" + // }, new String[] { relativeItem.getProperty("item_id"), + // relativeRevision }); + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName,keys, + new String[] { relativeItem.getProperty("item_id"), relativeRevision }); + if (coms != null && coms.length > 0) { + re = (TCComponentItemRevision) coms[0]; + } + + if (re == null) { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָĿİ汾"); + StringBufferDemo("ID" + relativeItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĿİ汾\r\n", "ʷݵϵ"); + fail++; + System.out.println("ָĿİ汾"); + return; + } + + System.out.println("ָĿ汾ɹ"); + + child = re; + } + + boolean find = false; + System.out.println("鵱ǰǷѾָϵĿ"); + AIFComponentContext[] contexts = parent.getRelated(relation); + if (contexts != null) { + System.out.println("contexts != null"); + for (int j = 0; j < contexts.length; j++) { + InterfaceAIFComponent iac = contexts[j].getComponent(); + if (iac.equals(child)) { + find = true; + break; + } + } + } + + if (!find) { + System.out.println("ûҵ"); + parent.add(relation, child); + System.out.println(""); + } else { + System.out.println("ɹexcel " + row + "еɹ"); + System.out.println("Ѿڣд"); + } + + success++; + } + + private void importBomsByJxl(BomsImportSettings bis, File input) { + System.out.println("BOM뿪ʼ"); + if (bis.getParentMapping() == null || bis.getChildMapping() == null) { + MessageBox.post("ѡװװIDִе", "", 1); + + return; + } + + int parentIndex = bis.getParentMapping().getColumnIndex(); + System.out.println("װӦΪ" + parentIndex); + int childIndex = bis.getChildMapping().getColumnIndex(); + System.out.println("ӼװӦΪ" + childIndex); + + try { + System.out.println("ʼʼexcelļ"); + JXLExcelParser parser = new JXLExcelParser(input, 0, bis.getColumns(), 1); + + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + StringBuffer buffer = new StringBuffer(); + // StringBuffer noacl_buffer = new StringBuffer(); + List set = new ArrayList(); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("֤ " + parser.startRow + " "); + String parentID = line.get(parentIndex); + if (parentID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(parentID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + parentID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(parentID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + parentID); + continue; + } + } + } + + String childID = line.get(childIndex); + if (childID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(childID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + childID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(childID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + childID); + continue; + } + } + } + } + + if (buffer.length() > 1) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ǰBOMкϣֱǣ\n" + buffer.toString() + "\n\n봴Ϻٽе", "", 1); + return; + } + // if(noacl_buffer.length()>1) + // { + // MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + // "ǰBOMк޶Ȩϣֱǣ\n" + noacl_buffer.toString() + + // "\n\n봴Ϻٽе", "", 1); + // return; + // } + + parser = new JXLExcelParser(input, 0, bis.getColumns(), 1); + while ((line = parser.parseLine()) != null) { + try { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String parentID = line.get(parentIndex); + TCComponentItem parentItem = null; + System.out.println("ʼҸװӦ "); + if (parentID.trim().length() > 0) { + parentItem = itemType.find(parentID); + } + if (parentItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "иװڣе"); + StringBufferDemo( + "ID" + parentID + ". ʧܡexcel " + parser.startRow + "иװڣе\r\n", + "ʷݵBOM"); + System.out.println("װ"); + fail++; + continue; + } + System.out.println("ҵװӦ "); + + String childID = line.get(childIndex); + System.out.println("ʼӼװӦ "); + TCComponentItem childItem = null; + if (childID.trim().length() > 0) { + childItem = itemType.find(childID); + } + if (childItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "װڣе"); + StringBufferDemo( + "ID" + childID + ". ʧܡexcel " + parser.startRow + "װڣе\r\n", + "ʷݵBOM"); + System.out.println("װ"); + fail++; + continue; + } + System.out.println("ҵӼװӦ "); + + String parantRevision = null; + if (bis.getParentRevMapping() != null) { + parantRevision = line.get(bis.getParentRevMapping().getColumnIndex()); + } + + String childRevision = null; + if (bis.getChildRevMapping() != null) { + childRevision = line.get(bis.getChildRevMapping().getColumnIndex()); + } + + MappingAttribute[] atts = bis.getBomLineMapping(); + Map properties = new HashMap(); + for (int i = 0; i < atts.length; i++) { + properties.put(atts[i].getTcAttribute(), line.get(atts[i].getColumnIndex())); + } + try { + establishBomStructrue(parser.startRow, parentItem, childItem, parantRevision, childRevision, + properties); + } catch (Exception e) { + StringBufferDemo("ʧܡexcel " + parser.startRow + + "BOMʧ,ԭ: һѴBOMǵ룬󵥶BOM\r\n", "ʷݵBOM"); + fail++; + continue; + } + } catch (Exception e) { + System.out.println("ʧܡexcel " + parser.startRow + "BOMʧ"); + StringBufferDemo("ʧܡexcel " + parser.startRow + "BOMʧ\r\n", "ʷݵBOM"); + fail++; + continue; + } + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + } + + private void importBomsByPoi(BomsImportSettings bis, File input) { + System.out.println("BOM뿪ʼ"); + if (bis.getParentMapping() == null || bis.getChildMapping() == null) { + MessageBox.post("ѡװװIDִе", "", 1); + + return; + } + + int parentIndex = bis.getParentMapping().getColumnIndex(); + System.out.println("װӦΪ" + parentIndex); + int childIndex = bis.getChildMapping().getColumnIndex(); + System.out.println("ӼװӦΪ" + childIndex); + + try { + System.out.println("ʼʼexcelļ"); + POIExcelParser parser = new POIExcelParser(input, 0, bis.getColumns(), 1); + + reporter.setTaskRange(0, parser.rows); + List line = null; + System.out.println("ʼexcelļ"); + StringBuffer buffer = new StringBuffer(); + List set = new ArrayList(); + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("֤ " + parser.startRow + " "); + String parentID = line.get(parentIndex); + if (parentID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(parentID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + parentID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(parentID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + parentID); + continue; + } + } + } + + String childID = line.get(childIndex); + if (childID.trim().length() > 0) { + TCComponentItem item = null; + try { + item = itemType.find(childID); + } catch (TCException tce) { + tce.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + tce.getMessage()); + logger.debug(tce.toString()); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), ":" + childID + "޶ȨޣȷϺٽе", + "", 1); + return; + } + if (item == null) { + if (!set.contains(childID)) { + set.add(parentID); + buffer.append("\n" + parser.startRow + ": " + childID); + continue; + } + } + } + } + + if (buffer.length() > 1) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ǰBOMкϣֱǣ\n" + buffer.toString() + "\n\n봴Ϻٽе", "", 1); + return; + } + + parser = new POIExcelParser(input, 0, bis.getColumns(), 1); + while ((line = parser.parseLine()) != null) { + try { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + + String parentID = line.get(parentIndex); + TCComponentItem parentItem = null; + System.out.println("ʼҸװӦ "); + if (parentID.trim().length() > 0) { + parentItem = itemType.find(parentID); + } + if (parentItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "иװڣе"); + System.out.println("װ"); + fail++; + continue; + } + System.out.println("ҵװӦ "); + + String childID = line.get(childIndex); + System.out.println("ʼӼװӦ "); + TCComponentItem childItem = null; + if (childID.trim().length() > 0) { + childItem = itemType.find(childID); + } + if (childItem == null) { + System.out.println("ʧܡexcel " + parser.startRow + "װڣе"); + System.out.println("װ"); + fail++; + continue; + } + System.out.println("ҵӼװӦ "); + + String parantRevision = null; + if (bis.getParentRevMapping() != null) { + parantRevision = line.get(bis.getParentRevMapping().getColumnIndex()); + } + + String childRevision = null; + if (bis.getChildRevMapping() != null) { + childRevision = line.get(bis.getChildRevMapping().getColumnIndex()); + } + + MappingAttribute[] atts = bis.getBomLineMapping(); + Map properties = new HashMap(); + for (int i = 0; i < atts.length; i++) { + properties.put(atts[i].getTcAttribute(), line.get(atts[i].getColumnIndex())); + } + + establishBomStructrue(parser.startRow, parentItem, childItem, parantRevision, childRevision, + properties); + } catch (Exception e) { + System.out.println( + "ʧܡexcel " + parser.startRow + "BOMʧ,ԭ: һѴBOMǵ룬󵥶BOM"); + fail++; + continue; + } + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("ʧܡBOMʧ"); + logger.error("BOMʧ - " + e.getMessage()); + logger.debug(e.toString()); + } + } + + @SuppressWarnings("static-access") + private void establishBomStructrue(int row, TCComponentItem parentItem, TCComponentItem childItem, + String parantRevision, String childRevision, Map properties) throws Exception { + TCComponentItemRevision revision = null; + if (parantRevision == null || parantRevision.trim().equals("")) { + System.out.println("ûָװİ汾ʹ°汾"); + // revision = parentItem.getLatestItemRevision(); + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName,keys1, new String[] { parentItem.getProperty("item_id") }); + + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[coms.length - 1]; + } + } else { + System.out.println("ָװİ汾"); + + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName,keys, + new String[] { parentItem.getProperty("item_id"), parantRevision }); + + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + } + } + + if (revision != null) { + setByPass(true); + TCComponentBOMWindow window = winType.create(null); + window.lock(); + + System.out.println("ָװİ汾ɹ"); + TCComponentBOMLine line = window.setWindowTopLine(parentItem, revision, null, null); + // TCComponentBOMWindow win = winType.create(null); + // win.lock(); + + TCComponentItemRevision re = null; + if (childRevision == null || childRevision.trim().equals("")) { + System.out.println("ûָӼװİ汾ʹ°汾"); + // re = childItem.getLatestItemRevision(); + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName,keys1,new String[] { childItem.getProperty("item_id") }); + + if (coms != null && coms.length > 0) { + re = (TCComponentItemRevision) coms[coms.length - 1]; + } + } else { + System.out.println("ָӼװİ汾"); + + InterfaceAIFComponent[] coms = SearchUtility.searchComponentsCollection(session, searchName,keys, + new String[] { childItem.getProperty("item_id"), childRevision }); + + if (coms != null && coms.length > 0) { + re = (TCComponentItemRevision) coms[0]; + } + } + System.out.println("childRevision = " + childRevision + ":: Ӽre = " + re); + + if (re != null) { + System.out.println("ָӼװİ汾ɹ"); + + System.out.println("жDzѾṹ"); + boolean find = false; + TCComponentBOMLine childLine = null; + TCComponent[] tccomponents = re.whereUsed(re.WHERE_USED_ALL); + if (tccomponents != null && tccomponents.length > 0) { + for (int j = 0; j < tccomponents.length; j++) { + if (tccomponents[j] instanceof TCComponentItemRevision) { + TCComponentItemRevision itemrevision = (TCComponentItemRevision) tccomponents[j]; + if (itemrevision.equals(line.getItemRevision())) { + find = true; + System.out.println("桿excel " + row + "BOMѾе"); + break; + } + } + } + } + + // жǷӽڵ + TCComponent[] b_existBOM = re.getRelatedComponents("structure_revisions"); + if (b_existBOM.length > 0) { + // BOM,¼ + System.out.println("BOM"); + String tempitemid = re.getProperty("item_id"); + System.out.println("BOM:" + tempitemid); + if (!hasBOMMap.containsKey(tempitemid)) + hasBOMMap.put(tempitemid, re); + } + + if (!find) { + System.out.println("ûдṹ"); + if (hasBOMMap.containsKey(line.getProperty("bl_item_item_id"))) { + System.out.println("벻Ҫ"); + } else { + childLine = line.add(childItem, re, null, false, ""); + // String newswquence = + // childLine.getProperty("bl_sequence_no"); + // System.out.println("õIJұΪ:"+newswquence); + int quantity_num = -9999; + for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();) { + String key = iterator.next(); + String value = properties.get(key); + // System.out.println(key + " : " + value); + try { + if (key.equals("bl_quantity")) { + try { + quantity_num = Integer.valueOf(value); + System.out.println("תΪint:" + quantity_num); + } catch (Exception e) { + + } + + } else { + childLine.setProperty(key, value); + } + } catch (TCException e) { + System.out + .println("ʧܡexcel " + row + "еʧܣԭ: װ " + key + " ȷ´"); + StringBufferDemo("ID" + childItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: װ " + key + " ȷ´\r\n", "ʷݵBOM"); + fail++; + // win.close(); + window.save(); + window.unlock(); + window.close(); + return; + } + } + childLine.save(); + // ProEģ + if (quantity_num > 1) { + System.out.println("1"); + for (int tempi = 0; tempi < quantity_num - 1; tempi++) { + TCComponentBOMLine tempchildLine = line.add(childLine, false); + // tempchildLine.setProperty("bl_sequence_no", + // newswquence); + // tempchildLine.save(); + } + } + } + childLine.pack(); + childLine.save(); + System.out.println("ṹ"); + } + + success++; + System.out.println("ɹexcel " + row + "еɹ"); + } else { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָװİ汾"); + StringBufferDemo("ID" + childItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָװİ汾\r\n", "ʷݵBOM"); + System.out.println("ָװİ汾"); + fail++; + } + line.save(); + window.save(); + window.unlock(); + window.close(); + setByPass(false); + } else { + System.out.println("ʧܡexcel " + row + "еʧܣԭ: ָĸװİ汾"); + StringBufferDemo("ID" + parentItem.getProperty("item_id") + ". ʧܡexcel " + row + + "еʧܣԭ: ָĸװİ汾\r\n", "ʷݵBOM"); + System.out.println("ûҵָָ汾"); + fail++; + } + } + + private void importObjectsByJxl(ObjectsImportSettings ois, File input) { + System.out.println("뿪ʼ"); + + try { + TCComponent[] uoms = uom.extent(); + Map uomMap = new HashMap(); + if (uoms != null) { + for (int i = 0; i < uoms.length; i++) { + uomMap.put(uoms[i].toString(), uoms[i]); + } + } + + int uomIndex = -1; + int idIndex = -1; + int nameIndex = -1; + + MappingAttribute[] items = ois.getItemMapping(); + MappingAttribute[] revisions = ois.getRevMapping(); + MappingAttribute[] forms = ois.getRevFormMapping(); + + for (int i = 0; i < items.length; i++) { + if ("item_id".equals(items[i].getTcAttribute())) { + idIndex = items[i].getColumnIndex(); + System.out.println("IDӦ" + idIndex); + continue; + } + if ("uom_tag".equals(items[i].getTcAttribute())) { + uomIndex = items[i].getColumnIndex(); + System.out.println("λӦΪ" + uomIndex); + } + if ("object_name".equals(items[i].getTcAttribute())) { + nameIndex = items[i].getColumnIndex(); + System.out.println("ӦΪ" + nameIndex); + } + } + + if (idIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡIDӦУɵ", "", 1); + return; + } + + if (nameIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡӦУɵ", "", 1); + return; + } + + int itemRevIndex = -1; + for (int i = 0; i < revisions.length; i++) { + if ("item_revision_id".equals(revisions[i].getTcAttribute())) { + itemRevIndex = revisions[i].getColumnIndex(); + System.out.println("汾ӦΪ" + itemRevIndex); + } + } + + JXLExcelParser parser = new JXLExcelParser(input, 0, ois.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + String id = ""; + String rev = ""; + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + try { + String lastid = id; + id = line.get(idIndex); + if (id.length() > 0) { + TCComponent uomCom = null; + if (uomIndex >= 0) { + String uom = line.get(uomIndex); + if (uom.length() > 0) { + uomCom = uomMap.get(uom); + + if (uomCom == null) { + try { + if (line.get(nameIndex).equals("")) { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: ָĵλûϵͳж\r\n", "ʷݵ"); + } else { + StringBufferDemo( + "ID" + id + ",ƣ" + line.get(nameIndex) + ". ʧܡexcel " + + parser.startRow + "еʧ,ԭ: ָĵλûϵͳж\r\n", + "ʷݵ"); + } + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ָĵλûϵͳж."); + fail++; + continue; + } + } + } + + String lastRev = rev; + if (itemRevIndex > 0) { + rev = line.get(itemRevIndex); + } + // ---жǷһεİ汾 zyn + if (!lastid.equals("")) { + if (lastid.equals(id)) { + if (!lastRev.equals("")) { + if (!lastRev.equals(rev)) { + k = 1; + } + } + } else { + k = 1; + } + } + TCComponentItem item = null; + item = itemType.find(id); + TCComponentItemRevision revision = null; + + List ps = new ArrayList(); + boolean refresh = false; + if (item == null) { + String name = line.get(nameIndex); + if (name.equals("")) { + try { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: ĵΪΪֵ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + + item = itemType.create(id, rev, ois.getItemType(), name, "", uomCom); + revision = item.getLatestItemRevision(); + folder.add("contents", item); + System.out.println("ɹ "); + } else { + refresh = true; + System.out.println("ѾϵͳУҪ"); + } + + if (revision == null) { + InterfaceAIFComponent[] coms = null; + System.out.println("ָ汾 - " + rev); + coms = SearchUtility.searchComponentsCollection(session, searchName,keys, new String[] { id, rev }); + System.out.println("coms===" + coms); + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + } + } + System.out.println("revision==" + revision); + if (revision == null && !rev.equals("")) { + refresh = false; + System.out.println("Ѿ,ָİ汾,ڽ޶ָ汾"); + revision = item.getLatestItemRevision().saveAs(rev, item.getProperty("object_name"), "", + true, null, null); + TCComponent[] datasets = revision.getTCProperty("IMAN_specification") + .getReferenceValueArray(); + for (int i = 0; i < datasets.length; i++) { + if (datasets[i] instanceof TCComponentDataset) { + revision.remove("IMAN_specification", datasets[i]);// Ƴǰݼ--dfhm + // by + // zyn + // 2011/08/11 + } + } + System.out.println("޶ָ汾ɹ"); + } + if (revision == null) { + revision = item.getLatestItemRevision(); + } + if ((refresh && ois.isExistedRefreshed()) || !refresh) { + String name = line.get(nameIndex); + if (name.equals("")) { + try { + StringBufferDemo("ID" + id + ". ʧܡexcel " + parser.startRow + + "иʧ,ԭ: ĵΪΪֵ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡexcel " + parser.startRow + "иʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + if (uomCom != null) { + try { + item.setReferenceProperty("uom_tag", uomCom); + } catch (Exception e) { + StringBufferDemo( + "ID" + id + ",ƣ" + line.get(nameIndex) + ". ʧܡexcel " + + parser.startRow + "иʧ,ԭ: ĵλ޸,ǷѾBOM\r\n", + "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + + "иʧ,ԭ: ĵλ޸,ǷѾBOM"); + fail++; + continue; + } + } + System.out.println("ϵ"); + ps.clear(); + TCComponentIdentifierType altype = (TCComponentIdentifierType) session.getTypeService() + .getTypeComponent("Identifier"); + TCComponentIdContextRuleType tccomponentidcontextruletype = (TCComponentIdContextRuleType) session + .getTypeComponent("IdContextRule"); + TCComponentIdContext[] context; + context = tccomponentidcontextruletype.getAliasContexts(); + for (int i = 0; i < items.length; i++) { + if (items[i].equals("uom_tag") || items[i].equals("object_name")) { + continue; + } + if (items[i].equals("IMAN_aliasid")) { + TCComponentIdentifier alid = altype.createAliasIdentifier("WX3_AAA"); + alid.setReferenceProperty("idcontext", context[0]); + alid.setProperty("idfr_id", line.get(items[i].getColumnIndex())); + alid.setProperty("object_name", "wx"); + alid.setProperty("object_desc", ""); + alid.save(); + item.add("IMAN_aliasid", alid); + continue; + } + TCProperty property = item.getTCProperty(items[i].getTcAttribute()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + if (property.getPropertyName().equals("item_id")) { + continue; + } + setTCProperty(property, line.get(items[i].getColumnIndex())); + ps.add(property); + } + } + item.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("ϵԳɹɸ "); + System.out.println("´汾ϵ"); + revision.setProperty("object_name", item.getProperty("object_name")); + ps.clear(); + for (int i = 0; i < revisions.length; i++) { + TCProperty property = revision.getTCProperty(revisions[i].getTcAttribute()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + logger.debug(" - " + property.getPropertyName()); + String propertyName = property.getName(); + String relatedItemType = null; + if (propertyName.equals("MnfBrandOAttr")) { + relatedItemType = "MnfBrandObj"; + } else if (propertyName.equals("MnfCategoryOAttr")) { + relatedItemType = "MnfCategoryObj"; + } else if (propertyName.equals("MnfProdLineOAttr")) { + relatedItemType = "MnfProdLineObj"; + } else if (propertyName.equals("MnfSeasonOAttr")) { + relatedItemType = "MnfSeasonObj"; + } else if (propertyName.equals("MnfSeriesOAttr")) { + relatedItemType = "MnfSeriesObj"; + } else if (propertyName.equals("MnfStyleOAttr")) { + relatedItemType = "MnfStyleObj"; + } else if (propertyName.equals("MnfMaterialBOAttr")) { + relatedItemType = "MnfMaterialBType"; + } else if (propertyName.equals("MnfMaterialSOAttr")) { + relatedItemType = "MnfMaterialSType"; + } + if (relatedItemType != null) { + logger.debug("ֺͨͲҶӦItem"); + InterfaceAIFComponent[] cs = SearchUtility.searchComponentsCollection(session, + "ConnorItemSearch", new String[] { "Name1", "Type1" }, + new String[] { line.get(revisions[i].getColumnIndex()), + relatedItemType + "Revision" }); + if (cs != null && cs.length > 0) { + System.out.println("DDD " + revisions[i].getColumnIndex()); + logger.debug("ҵΪ" + line.get(revisions[i].getColumnIndex()) + ",Ϊ" + + relatedItemType + "Ķ"); + if (cs[0] instanceof TCComponentItemRevision) { + TCComponentItemRevision tcc = (TCComponentItemRevision) cs[0]; + property.setPropertyData(tcc); + } + } else { + try { + StringBufferDemo("ID" + id + ",ƣ" + line.get(nameIndex) + + ". ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ\r\n", "ʷݵ"); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ"); + fail++; + continue; + } + } else { + logger.debug("relatedItemType = " + relatedItemType); + setTCProperty(property, line.get(revisions[i].getColumnIndex())); + } + ps.add(property); + } + } + revision.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("´ϵԳɹ "); + + TCComponentForm form = getItemRevisionMasterForm(revision); + if (form != null) { + System.out.println("ȡ汾Formɹ,ʼ"); + ps.clear(); + for (int i = 0; i < forms.length; i++) { + TCProperty property = form.getTCProperty(forms[i].getTcAttribute()); + if (property != null && property.getDescriptor().isModifiable()) { + setTCProperty(property, line.get(forms[i].getColumnIndex())); + ps.add(property); + } + } + form.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + form.save(); + } else { + System.out.println("ȡ汾Formʧ"); + } + MappingAttribute[] datasets = ois.getDatasetMapping(); + System.out.println("汾ݼ, " + datasets.length + "Ҫ"); + ps.clear(); + putDataset(parser, line, datasets, revision); + if (refresh) { + System.out.println("ɹexcel " + parser.startRow + "и"); + } else { + System.out.println("ɹexcel " + parser.startRow + "д"); + } + } + success++; + } else { + System.out.println("桿excel " + parser.startRow + "IDΪգе봦"); + } + } catch (Exception e) { + e.printStackTrace(); + StringBufferDemo("ID" + id + ",ƣ" + line.get(nameIndex) + ". ʧܡexcel " + parser.startRow + + "еʧ,ԭ: " + e.toString() + "\r\n", "ʷݵ"); + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: " + e.toString()); + fail++; + continue; + } + } + } catch (Exception e) { + logger.error("ʧ - " + e.toString()); + logger.debug(e.toString()); + } + } + + /** + * cavalier added on 2013-08-15 + */ + public void putDataset(JXLExcelParser parser, List line, MappingAttribute[] datasets, + TCComponentItemRevision revision) { + for (int i = 0; i < datasets.length; i++) { + + try { + logger.debug("ʼ" + (i + 1) + ""); + String filePath = line.get(datasets[i].getColumnIndex()); + if (filePath.trim().length() > 0) { + System.out.println("ݼ·Ϊ" + filePath); + String ds = datasets[i].getTcAttribute(); + // String sep = ois.getArraySeparator(); + // filePathԡ||ͱʾҳɶݼԡ;ͱʾһݼӶ + String[] files = filePath.split("\\|\\|"); + List> fis = new ArrayList>(); + for (int j = 0; j < files.length; j++) { + String filepath = files[j].trim(); + if (filepath.contains(";")) { + String[] filepaths = filepath.split(";"); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + } + } + fis.add(list); + } else if (filepath.contains("")) { + String[] filepaths = filepath.split(""); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + System.out.println("ļ·Ϊ" + file); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + } + } + fis.add(list); + } else { + System.out.println("files[" + j + "] = " + files[j]); + File file = new File(files[j].trim()); + if (file.exists()) { + List list = new ArrayList(); + list.add(file.getAbsolutePath()); + fis.add(list); + } else { + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + } + } + } + + if (fis.size() > 0) { + String did = revision.getProperty("item_id"); + did = did + "/" + revision.getProperty("item_revision_id"); + + System.out.println("ɵݼidΪ" + did); + String[] refs = guessDatasetReferenceNames(ds, files); + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + logger.error("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + files[j] + + "ҵ,鿴" + ds + "ݼļģ嶨"); + fail++; + continue; + } + } + System.out.println("ȡϵͳָļӦݼõֳɹ"); + if (fis.size() == 1) { + List listString = fis.get(0); + AIFComponentContext[] cc = revision.getChildren("IMAN_specification"); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent.add(cc[j]); + } + } + } + if (listComponent.size() > 0) { + if (listComponent.size() > 1) { + for (int k = 0; k < listComponent.size() - 1; k++) { + DeleteOperation deleteOperation = new DeleteOperation(listComponent.get(k)); + session.queueOperation(deleteOperation); + listComponent.remove(k); + k--; + } + if (listComponent.get(0).getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent.get(0) + .getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } + } + } else { + if (listComponent.get(0).getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent.get(0) + .getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } + } + } + } else { + System.out.println("ָID͵ݼѾڣ½"); + System.out.println("ds &&&&&&&&&&&&&&&&&& " + ds); + TCComponentDataset tcd = datasetType.create(did, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(tcd, new File(listString.get(l)), tcd.getType(), refs[0]); + } + System.out.println(" "); + + revision.add("IMAN_specification", tcd); + System.out.println("ҵ汾"); + } + } else { + AIFComponentContext[] cc = revision.getChildren("IMAN_specification"); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent.add(cc[j]); + } + } + } + for (int k = 0; k < listComponent.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation(listComponent.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println("fis.size()================= " + fis.size()); + for (int count = 0; count < fis.size(); count++) { + List filePathCount = fis.get(count); + TCComponentDataset tcd = null; + String filepath = filePathCount.get(0); + + String datasetName = did; + // String datasetName = + // did+filepath.substring(filepath.lastIndexOf("-"),filepath.lastIndexOf(".")); + + tcd = datasetType.create(datasetName, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < filePathCount.size(); l++) { + importFilesOperation(tcd, new File(filePathCount.get(l)), tcd.getType(), refs[0]); + } + System.out.println(" "); + revision.add("IMAN_specification", tcd); + System.out.println("ҵ汾"); + } + } + } else { + System.out.println("ûݼҪ"); + } + } + } catch (Exception e) { + System.out.println("桿excel " + parser.startRow + "йݼ" + datasets[i].getTcAttribute() + "ʧ"); + continue; + } + } + + } + + private void importObjectsByPoi(ObjectsImportSettings ois, File input) { + System.out.println("뿪ʼ"); + System.out.println("뿪ʼ"); + try { + TCComponent[] uoms = uom.extent(); + Map uomMap = new HashMap(); + if (uoms != null) { + for (int i = 0; i < uoms.length; i++) { + uomMap.put(uoms[i].toString(), uoms[i]); + } + } + + int uomIndex = -1; + int idIndex = -1; + int nameIndex = -1; + + MappingAttribute[] items = ois.getItemMapping(); + MappingAttribute[] revisions = ois.getRevMapping(); + MappingAttribute[] forms = ois.getRevFormMapping(); + + for (int i = 0; i < items.length; i++) { + if ("item_id".equals(items[i].getTcAttribute())) { + idIndex = items[i].getColumnIndex(); + System.out.println("IDӦ" + idIndex); + continue; + } + if ("uom_tag".equals(items[i].getTcAttribute())) { + uomIndex = items[i].getColumnIndex(); + System.out.println("λӦΪ" + uomIndex); + } + if ("object_name".equals(items[i].getTcAttribute())) { + nameIndex = items[i].getColumnIndex(); + System.out.println("ӦΪ" + nameIndex); + } + } + + if (idIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡIDӦУɵ", "", 1); + return; + } + + if (nameIndex < 0) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ʧܡûѡӦУɵ", "", 1); + return; + } + + int itemRevIndex = -1; + for (int i = 0; i < revisions.length; i++) { + if ("item_revision_id".equals(revisions[i].getTcAttribute())) { + itemRevIndex = revisions[i].getColumnIndex(); + System.out.println("汾ӦΪ" + itemRevIndex); + } + } + + POIExcelParser parser = new POIExcelParser(input, 0, ois.getColumns(), 1); + reporter.setTaskRange(0, parser.rows); + List line = null; + while ((line = parser.parseLine()) != null) { + reporter.setProgressPercent(parser.startRow); + reporter.reportProgressMessage("ڵ " + parser.startRow + " "); + try { + String id = line.get(idIndex); + if (id.length() > 0) { + TCComponent uomCom = null; + if (uomIndex >= 0) { + String uom = line.get(uomIndex); + if (uom.length() > 0) { + uomCom = uomMap.get(uom); + + if (uomCom == null) { + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ָĵλûϵͳж."); + fail++; + continue; + } + } + } + + String rev = ""; + if (itemRevIndex > 0) { + rev = line.get(itemRevIndex); + } + TCComponentItem item = null; + item = itemType.find(id); + TCComponentItemRevision revision = null; + List ps = new ArrayList(); + boolean refresh = false; + if (item == null) { + String name = line.get(nameIndex); + if (name.equals("")) { + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + + item = itemType.create(id, rev, ois.getItemType(), name, "", uomCom); + revision = item.getLatestItemRevision(); + folder.add("contents", item); + System.out.println("ɹ "); + } else { + refresh = true; + System.out.println("ѾϵͳУҪ"); + } + + if (revision == null) { + System.out.println("ָ汾 - " + rev); + InterfaceAIFComponent[] coms = null; + coms = SearchUtility.searchComponentsCollection(session, searchName,keys, new String[] { id, rev }); + + if (coms != null && coms.length > 0) { + revision = (TCComponentItemRevision) coms[0]; + } + } + + if (revision == null && !rev.equals("")) { + refresh = false; + System.out.println("Ѿ,ָİ汾,ڽ޶ָ汾"); + revision = item.getLatestItemRevision().saveAs(rev, item.getProperty("object_name"), "", + true, null, null); + System.out.println("޶ָ汾ɹ"); + } + if (revision == null) { + revision = item.getLatestItemRevision(); + } + if ((refresh && ois.isExistedRefreshed()) || !refresh) { + String name = line.get(nameIndex); + if (name.equals("")) { + System.out.println("ʧܡexcel " + parser.startRow + "иʧ,ԭ: ĵΪΪֵ"); + fail++; + continue; + } + + if (uomCom != null) { + try { + item.setReferenceProperty("uom_tag", uomCom); + } catch (Exception e) { + System.out.println("ʧܡexcel " + parser.startRow + + "иʧ,ԭ: ĵλ޸,ʱѾBOM"); + fail++; + continue; + } + } + System.out.println("ϵ"); + ps.clear(); + TCComponentIdentifierType altype = (TCComponentIdentifierType) session.getTypeService() + .getTypeComponent("Identifier"); + TCComponentIdContextRuleType tccomponentidcontextruletype = (TCComponentIdContextRuleType) session + .getTypeComponent("IdContextRule"); + TCComponentIdContext[] context; + context = tccomponentidcontextruletype.getAliasContexts(); + for (int i = 0; i < items.length; i++) { + if (items[i].equals("uom_tag") || items[i].equals("object_name")) { + continue; + } + if (items[i].equals("IMAN_aliasid")) { + TCComponentIdentifier alid = altype.createAliasIdentifier("WX3_AAA"); + alid.setReferenceProperty("idcontext", context[0]); + alid.setProperty("idfr_id", line.get(items[i].getColumnIndex())); + alid.setProperty("object_name", "wx"); + alid.setProperty("object_desc", ""); + alid.save(); + item.add("IMAN_aliasid", alid); + continue; + } + TCProperty property = item.getTCProperty(items[i].getTcAttribute()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + if (property.getPropertyName().equals("item_id")) { + continue; + } + setTCProperty(property, line.get(items[i].getColumnIndex())); + ps.add(property); + } + } + item.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("ϵԳɹɸ "); + + System.out.println("´汾ϵ"); + revision.setProperty("object_name", item.getProperty("object_name")); + ps.clear(); + for (int i = 0; i < revisions.length; i++) { + TCProperty property = revision.getTCProperty(revisions[i].getTcAttribute()); + if (property != null && property.getPropertyDescriptor().isModifiable()) { + logger.debug(" - " + property.getPropertyName()); + String propertyName = property.getName(); + String relatedItemType = null; + if (propertyName.equals("MnfBrandOAttr")) { + relatedItemType = "MnfBrandObj"; + } else if (propertyName.equals("MnfCategoryOAttr")) { + relatedItemType = "MnfCategoryObj"; + } else if (propertyName.equals("MnfProdLineOAttr")) { + relatedItemType = "MnfProdLineObj"; + } else if (propertyName.equals("MnfSeasonOAttr")) { + relatedItemType = "MnfSeasonObj"; + } else if (propertyName.equals("MnfSeriesOAttr")) { + relatedItemType = "MnfSeriesObj"; + } else if (propertyName.equals("MnfStyleOAttr")) { + relatedItemType = "MnfStyleObj"; + } else if (propertyName.equals("MnfMaterialBOAttr")) { + relatedItemType = "MnfMaterialBType"; + } else if (propertyName.equals("MnfMaterialSOAttr")) { + relatedItemType = "MnfMaterialSType"; + } + if (relatedItemType != null) { + logger.debug("ֺͨͲҶӦItem"); + InterfaceAIFComponent[] cs = SearchUtility.searchComponentsCollection(session, + "ConnorItemSearch", new String[] { "Name1", "Type1" }, + new String[] { line.get(revisions[i].getColumnIndex()), + relatedItemType + "Revision" }); + if (cs != null && cs.length > 0) { + logger.debug("ҵΪ" + line.get(revisions[i].getColumnIndex()) + ",Ϊ" + + relatedItemType + "Ķ"); + if (cs[0] instanceof TCComponentItemRevision) { + TCComponentItemRevision tcc = (TCComponentItemRevision) cs[0]; + property.setPropertyData(tcc); + } + } else { + logger.error("ʧܡûҵΪ" + line.get(revisions[i].getColumnIndex()) + + ",Ϊ" + relatedItemType + "Ķ"); + fail++; + continue; + } + } else { + logger.debug("relatedItemType = " + relatedItemType); + setTCProperty(property, line.get(revisions[i].getColumnIndex())); + } + ps.add(property); + } + } + revision.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + System.out.println("´ϵԳɹ "); + TCComponentForm form = getItemRevisionMasterForm(revision); + if (form != null) { + System.out.println("ȡ汾Formɹ,ʼ"); + ps.clear(); + for (int i = 0; i < forms.length; i++) { + + TCProperty property = form.getTCProperty(forms[i].getTcAttribute()); + if (property != null && property.getDescriptor().isModifiable()) { + + setTCProperty(property, line.get(forms[i].getColumnIndex())); + ps.add(property); + } + } + form.setTCProperties(ps.toArray(new TCProperty[ps.size()])); + form.save(); + } else { + System.out.println("ȡ汾Formʧ"); + } + MappingAttribute[] datasets = ois.getDatasetMapping(); + System.out.println("汾ݼ, " + datasets.length + "Ҫ"); + ps.clear(); + for (int i = 0; i < datasets.length; i++) { + try { + logger.debug("ʼ" + (i + 1) + ""); + String filePath = line.get(datasets[i].getColumnIndex()); + if (filePath.trim().length() > 0) { + System.out.println("ݼ·Ϊ" + filePath); + String ds = datasets[i].getTcAttribute(); + // String sep = ois.getArraySeparator(); + // filePathԡ||ͱʾҳɶݼԡ;ͱʾһݼӶ + String[] files = filePath.split("\\|\\|"); + List> fis = new ArrayList>(); + for (int j = 0; j < files.length; j++) { + String filepath = files[j].trim(); + if (filepath.contains(";")) { + String[] filepaths = filepath.split(";"); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + } + } + fis.add(list); + } else if (filepath.contains("")) { + String[] filepaths = filepath.split(""); + List list = new ArrayList(); + for (int k = 0; k < filepaths.length; k++) { + File file = new File(filepaths[k].trim()); + System.out.println("ļ·Ϊ" + file); + if (file.exists()) { + list.add(file.getAbsolutePath()); + } else { + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + } + } + fis.add(list); + } else { + System.out.println("files[" + j + "] = " + files[j]); + File file = new File(files[j].trim()); + if (file.exists()) { + List list = new ArrayList(); + list.add(file.getAbsolutePath()); + fis.add(list); + } else { + System.out.println("ļ" + file.getAbsolutePath() + "ڣԴ"); + } + } + } + + if (fis.size() > 0) { + String did = revision.getProperty("item_id"); + did = did + "/" + revision.getProperty("item_revision_id"); + + System.out.println("ɵݼidΪ" + did); + String[] refs = guessDatasetReferenceNames(ds, files); + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + logger.error("ʧܡexcel " + parser.startRow + "ݼʧܣûΪļ" + + files[j] + "ҵ,鿴" + ds + "ݼļģ嶨"); + fail++; + continue; + } + } + System.out.println("ȡϵͳָļӦݼõֳɹ"); + if (fis.size() == 1) { + List listString = fis.get(0); + AIFComponentContext[] cc = revision.getChildren("IMAN_specification"); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent.add(cc[j]); + } + } + } + if (listComponent.size() > 0) { + if (listComponent.size() > 1) { + for (int k = 0; k < listComponent.size() - 1; k++) { + DeleteOperation deleteOperation = new DeleteOperation( + listComponent.get(k)); + session.queueOperation(deleteOperation); + listComponent.remove(k); + k--; + } + if (listComponent.get(0) + .getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent + .get(0).getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } + } + } else { + if (listComponent.get(0) + .getComponent() instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) listComponent + .get(0).getComponent(); + if (dataset.getProperty("object_name").equals(did)) { + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } else { + dataset.setProperty("object_name", did); + removeNRFiles(dataset, refs[0], dataset.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(dataset, + new File(listString.get(l)), + dataset.getType(), refs[0]); + } + } + } + } + } else { + System.out.println("ָID͵ݼѾڣ½"); + System.out.println("ds &&&&&&&&&&&&&&&&&& " + ds); + TCComponentDataset tcd = datasetType.create(did, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < listString.size(); l++) { + importFilesOperation(tcd, new File(listString.get(l)), + tcd.getType(), refs[0]); + } + System.out.println(" "); + + revision.add("IMAN_specification", tcd); + System.out.println("ҵ汾"); + } + } else { + AIFComponentContext[] cc = revision.getChildren("IMAN_specification"); + List listComponent = new ArrayList(); + for (int j = 0; j < cc.length; j++) { + InterfaceAIFComponent tcc = cc[j].getComponent(); + if (tcc instanceof TCComponentDataset) { + TCComponentDataset ods = (TCComponentDataset) tcc; + if (ods.getType().equals(ds)) { + listComponent.add(cc[j]); + } + } + } + for (int k = 0; k < listComponent.size(); k++) { + DeleteOperation deleteOperation = new DeleteOperation( + listComponent.get(k)); + session.queueOperation(deleteOperation); + } + System.out.println("fis.size()================= " + fis.size()); + for (int count = 0; count < fis.size(); count++) { + List filePathCount = fis.get(count); + TCComponentDataset tcd = null; + String filepath = filePathCount.get(0); + + String datasetName = did; + // String datasetName = + // did+filepath.substring(filepath.lastIndexOf("-"),filepath.lastIndexOf(".")); + tcd = datasetType.create(datasetName, "", ds); + System.out.println("ݼ½"); + int ifail = -1; + for (int j = 0; j < refs.length; j++) { + if (refs[j] == null) { + ifail = j; + break; + } + } + if (ifail > 0) { + MessageBox.post("ûΪļļҵݼ\n" + files[ifail], "", 1); + continue; + } + removeNRFiles(tcd, refs[0], tcd.getTcFiles()); + for (int l = 0; l < filePathCount.size(); l++) { + importFilesOperation(tcd, new File(filePathCount.get(l)), + tcd.getType(), refs[0]); + } + System.out.println(" "); + revision.add("IMAN_specification", tcd); + System.out.println("ҵ汾"); + } + } + } else { + System.out.println("ûݼҪ"); + } + } + } catch (Exception e) { + System.out.println("桿excel " + parser.startRow + "йݼ" + + datasets[i].getTcAttribute() + "ʧ"); + continue; + } + } + + if (refresh) { + System.out.println("ɹexcel " + parser.startRow + "и"); + } else { + System.out.println("ɹexcel " + parser.startRow + "д"); + } + } + success++; + } else { + System.out.println("桿excel " + parser.startRow + "IDΪգе봦"); + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("ʧܡexcel " + parser.startRow + "еʧ,ԭ: " + e.toString()); + fail++; + continue; + } + } + } catch (Exception e) { + logger.error("ʧ - " + e.toString()); + logger.debug(e.toString()); + } + } + + private String[] guessDatasetReferenceNames(String ds, String[] files) throws TCException { + System.out.println("ʼȡϵͳָļӦݼõ"); + System.out.println("ds==" + ds); + System.out.println("files.length==" + files.length); + System.out.println("files[0]==" + files[0]); + TCComponentDatasetDefinition definition = dsdefType.find(ds); + System.out.println("definition==" + definition); + NamedReferenceContext[] contexts = definition.getNamedReferenceContexts(); + System.out.println("contexts.length==" + contexts.length); + Hashtable hashtable = new Hashtable(contexts.length); + String all = ""; + for (int i = 0; i < contexts.length; i++) { + String template = contexts[i].getFileTemplate(); + int index = template.lastIndexOf("."); + if (index != -1) { + hashtable.put(template.substring(index + 1).toLowerCase(), contexts[i].getNamedReference()); + } else { + all = template.toLowerCase(); + hashtable.put(all, contexts[i].getNamedReference()); + } + } + + String refers[] = new String[files.length]; + System.out.println("" + files.length + "ļҪȡݼ"); + for (int i = 0; i < files.length; i++) { + String name = (new File(files[i])).getName(); + refers[i] = hashtable.get(name.substring(name.lastIndexOf(".") + 1).toLowerCase()); + if (refers[i] == null) { + refers[i] = hashtable.get(all); + } + + System.out.println(name.substring(name.lastIndexOf(".") + 1).toLowerCase() + "Ӧ" + refers[i]); + } + + return refers; + } + + private void setTCProperty(TCProperty property, String value) throws TCException { + System.out.println("setTCProperty(TCProperty property =" + property.getPropertyName() + ", String value=" + + value + ") - start"); + // if (value == null || value.length() == 0) { + // System.out.println("setTCProperty(TCProperty property, String value) + // - end"); + // return; + // } + if (value == null || value.trim().length() == 0) + return; + TCPropertyDescriptor descriptor = property.getPropertyDescriptor(); + boolean isArray = descriptor.isArray(); + if (!isArray) { + switch (descriptor.getType()) { + case TCProperty.PROP_string: + case TCProperty.PROP_long_string: + logger.debug("ӦΪַ"); + property.setStringValueData(value); + break; + case TCProperty.PROP_char: + logger.debug("ӦΪַ"); + if (value.length() > 0) { + property.setCharValueData(value.charAt(0)); + } + break; + case TCProperty.PROP_double: + logger.debug("ӦΪdouble"); + if (value == null || value.trim().length() == 0) + property.setDoubleValueData((Integer) null); + else + property.setDoubleValueData(Double.parseDouble(value)); + break; + case TCProperty.PROP_float: + logger.debug("ӦΪfloat"); + if (value == null || value.trim().length() == 0) + property.setFloatValueData((Integer) null); + else + property.setFloatValueData(Float.parseFloat(value)); + break; + case TCProperty.PROP_int: + case TCProperty.PROP_short: + logger.debug("ӦΪintshort"); + if (value == null || value.trim().length() == 0) + property.setIntValue((Integer) null); + else + property.setIntValueData(Integer.parseInt(value)); + break; + case TCProperty.PROP_logical: + logger.debug("ӦΪBoolean"); + property.setLogicalValueData(Boolean.parseBoolean(value)); + break; + case TCProperty.PROP_date: + logger.debug("ӦΪ"); + try { + property.setDateValueData(new SimpleDateFormat().parse(value)); + } catch (ParseException e) { + logger.error("setTCProperty(TCProperty property, String value)", e); + + e.printStackTrace(); + } + break; + } + } else { + System.out.println("ӦΪͣԴ"); + } + + System.out.println("setTCProperty(TCProperty property, String value) - end"); + } + + private TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws TCException { + 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) { + TCComponentForm form = (TCComponentForm) component; + + return form; + } + } + } + + return null; + } + + public void removeNRFiles(TCComponentDataset dataset, String namedReference, TCComponentTcFile files[]) + throws Exception { + + System.out.println("--------------------ʼɾļ------------------------"); + + try { + + TCComponent comps[] = dataset.getNamedRefComponents(namedReference); + if (comps != null && comps.length > 0) { + + for (int i = 0; i < comps.length; i++) + dataset.removeNamedReference(namedReference); + + } + for (int i = 0; i < files.length; i++) + if (files[i] != null) { + + try { + System.out.println("delete file " + files[i].getPath()); + files[i].delete(); + } catch (Exception e) { + e.printStackTrace(); + + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public void importFilesOperation(TCComponentDataset dataset, File file, String fileType, String refType) { + System.out.println("-----------------------------ʼļϴ---------------------------"); + String as[] = { file.getPath() }; + String as1[] = { fileType }; + String as2[] = { "Plain" }; + String as3[] = { refType }; + System.out.println("file.getPath()&&&&&&&&&&&&&&&&&&& " + file.getPath()); + try { + dataset.setFiles(as, as1, as2, as3); + } catch (TCException e) { + e.printStackTrace(); + } + session.setReadyStatus(); + } + + // д־ + public void StringBufferDemo(String strContext, String strFileName) throws IOException { + // logpath = System.getProperty("java.io.tmpdir")+File.separator+ + // strFileName; + logpath = "C:\\" + strFileName + "_" + systitem + ".log"; + File file = new File(logpath); + if (!file.exists()) + file.createNewFile(); + FileOutputStream out = new FileOutputStream(file, true); + StringBuffer sb = new StringBuffer(strContext); + out.write(sb.toString().getBytes("gb2312")); + out.close(); + } + + // //ɾ־ + // public void deleteLog(String strFileName) throws IOException { + // File file = new + // File(System.getProperty("java.io.tmpdir")+File.separator+"OriginTemp" + + // strFileName); + // if (file.exists()) + // file.delete(); + // } + + // javaC bypass + public void setByPass(boolean val) throws TCException { + if (userservice == null) { + userservice = this.session.getUserService(); + } + Object[] obj = new Object[1]; + obj[0] = "origin"; + if (val) { +// userservice.call("ORIGIN_set_bypass", obj); + userservice.call("connor_open_bypass", new Object[] { "true" }); + } else { +// userservice.call("ORIGIN_close_bypass", obj); + userservice.call("connor_close_bypass", new Object[] { "false" }); + } + } + + public static void main(String[] args) { + String filePath = "C:\\11.txt||C:\\22.txt"; + String[] str = filePath.split("\\|\\|"); + System.out.println(str.length); + System.out.println(str[0]); + System.out.println(str[1]); + } +} diff --git a/src/com/connor/dev/imp/ImportSettings.java b/src/com/connor/dev/imp/ImportSettings.java new file mode 100644 index 0000000..b18c2c7 --- /dev/null +++ b/src/com/connor/dev/imp/ImportSettings.java @@ -0,0 +1,110 @@ +package com.connor.dev.imp; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +public abstract class ImportSettings implements Serializable +{ + private static final long serialVersionUID = 1L; + + private boolean saved; + + private int columns; + + private String dateFormat; + + //private String arraySeparator; + + public boolean save(File file) + { + try + { + FileOutputStream fos = new FileOutputStream(file); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(this); + oos.flush(); + oos.close(); + + saved = true; + + return true; + } + catch (IOException ioe) + { + ioe.printStackTrace(); + } + + return false; + } + + public ImportSettings load(File file) + { + try + { + FileInputStream fis = new FileInputStream(file); + ObjectInputStream ois = new ObjectInputStream(fis); + Object o = ois.readObject(); + + ois.close(); + fis.close(); + + saved = false; + + if (o instanceof ImportSettings) + { + return (ImportSettings) o; + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } + + public void setSaved(boolean saved) + { + this.saved = saved; + } + + public boolean isSaved() + { + return saved; + } + + public void setColumns(int columns) + { + this.columns = columns; + } + + public int getColumns() + { + return columns; + } + + public String getDateFormat() + { + return dateFormat; + } + + public void setDateFormat(String dateFormat) + { + this.dateFormat = dateFormat; + } + + // public String getArraySeparator() + // { + // return arraySeparator; + // } + // + // public void setArraySeparator(String arraySeparator) + // { + // this.arraySeparator = arraySeparator; + // } +} diff --git a/src/com/connor/dev/imp/MappingAttribute.java b/src/com/connor/dev/imp/MappingAttribute.java new file mode 100644 index 0000000..5226e3f --- /dev/null +++ b/src/com/connor/dev/imp/MappingAttribute.java @@ -0,0 +1,69 @@ +package com.connor.dev.imp; + +import java.io.Serializable; + +public class MappingAttribute implements Serializable +{ + private static final long serialVersionUID = 1L; + + private int columnIndex; + + private String columnTitle; + + private String tcAttribute; + + public MappingAttribute(int columnIndex, String columnTitle, String tcAttribute) + { + this.columnIndex = columnIndex; + this.columnTitle = columnTitle; + this.tcAttribute = tcAttribute; + } + + public int getColumnIndex() + { + return columnIndex; + } + + public void setColumnIndex(int columnIndex) + { + this.columnIndex = columnIndex; + } + + public String getColumnTitle() + { + return columnTitle; + } + + public void setColumnTitle(String columnTitle) + { + this.columnTitle = columnTitle; + } + + public String getTcAttribute() + { + return tcAttribute; + } + + public void setTcAttribute(String tcAttribute) + { + this.tcAttribute = tcAttribute; + } + + public boolean equals(Object obj) + { + if (!(obj instanceof MappingAttribute)) + { + return false; + } + else + { + MappingAttribute at = (MappingAttribute) obj; + return tcAttribute.equals(at.tcAttribute); + } + } + + public String toString() + { + return "(" + columnIndex + ")" + columnTitle + " => " + tcAttribute; + } +} diff --git a/src/com/connor/dev/imp/bom/BomsImportSettings.java b/src/com/connor/dev/imp/bom/BomsImportSettings.java new file mode 100644 index 0000000..4c920ab --- /dev/null +++ b/src/com/connor/dev/imp/bom/BomsImportSettings.java @@ -0,0 +1,71 @@ +package com.connor.dev.imp.bom; + +import java.io.Serializable; + +import com.connor.dev.imp.ImportSettings; +import com.connor.dev.imp.MappingAttribute; + +public class BomsImportSettings extends ImportSettings implements Serializable +{ + private static final long serialVersionUID = 1L; + + private MappingAttribute parentMapping; + + private MappingAttribute parentRevMapping; + + private MappingAttribute childMapping; + + private MappingAttribute childRevMapping; + + private MappingAttribute[] bomLineMapping; + + public MappingAttribute getParentMapping() + { + return parentMapping; + } + + public void setParentMapping(MappingAttribute parentMapping) + { + this.parentMapping = parentMapping; + } + + public MappingAttribute getParentRevMapping() + { + return parentRevMapping; + } + + public void setParentRevMapping(MappingAttribute parentRevMapping) + { + this.parentRevMapping = parentRevMapping; + } + + public MappingAttribute getChildMapping() + { + return childMapping; + } + + public void setChildMapping(MappingAttribute childMapping) + { + this.childMapping = childMapping; + } + + public MappingAttribute getChildRevMapping() + { + return childRevMapping; + } + + public void setChildRevMapping(MappingAttribute childRevMapping) + { + this.childRevMapping = childRevMapping; + } + + public void setBomLineMapping(MappingAttribute[] bomLineMapping) + { + this.bomLineMapping = bomLineMapping; + } + + public MappingAttribute[] getBomLineMapping() + { + return bomLineMapping; + } +} diff --git a/src/com/connor/dev/imp/bom/ImportBomsCommand.java b/src/com/connor/dev/imp/bom/ImportBomsCommand.java new file mode 100644 index 0000000..9332bb6 --- /dev/null +++ b/src/com/connor/dev/imp/bom/ImportBomsCommand.java @@ -0,0 +1,20 @@ +package com.connor.dev.imp.bom; + + +import com.connor.dev.imp.AbstractImportCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; + +public class ImportBomsCommand extends AbstractImportCommand +{ + public ImportBomsCommand(AbstractAIFUIApplication application) + { + super(application); + } + + + protected void importHistoryDatas() + { + ImportBomsDialog dialog = new ImportBomsDialog(session, "BOM"); + setRunnable(dialog); + } +} diff --git a/src/com/connor/dev/imp/bom/ImportBomsDialog.java b/src/com/connor/dev/imp/bom/ImportBomsDialog.java new file mode 100644 index 0000000..c270ed5 --- /dev/null +++ b/src/com/connor/dev/imp/bom/ImportBomsDialog.java @@ -0,0 +1,339 @@ +package com.connor.dev.imp.bom; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.DefaultListModel; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeEvent; + +import com.connor.dev.imp.AbstractImportDialog; +import com.connor.dev.imp.ImportSettings; +import com.connor.dev.imp.MappingAttribute; +import com.connor.dev.imp.ob.MappingButton; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.util.MessageBox; + +public class ImportBomsDialog extends AbstractImportDialog +{ + private static final long serialVersionUID = 1L; + + private MappingButton parent; + + private MappingButton child; + + private MappingButton parentRev; + + private MappingButton childRev; + + public ImportBomsDialog(TCSession session, String title) + { + super(session, title, true); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#initializeUI() + */ + protected void initializeUI() + { + super.initializeUI(); + + propertiesList = new JList[1]; + propertiesListModels = new DefaultListModel[1]; + mappingListModels = new DefaultListModel[1]; + mappingList = new JList[1]; + + for (int i = 0; i < propertiesList.length; i++) + { + propertiesListModels[i] = new DefaultListModel(); + propertiesList[i] = new JList(propertiesListModels[i]); + propertiesList[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + propertiesList[i].setVisibleRowCount(20); + mappingListModels[i] = new DefaultListModel(); + mappingList[i] = new JList(mappingListModels[i]); + mappingList[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + } + + parent = new MappingButton("Parent ID"); + child = new MappingButton("Child ID"); + parentRev = new MappingButton("Parent Revision ID"); + childRev = new MappingButton("Child Revision ID"); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#registerActionComponents() + */ + protected void registerActionComponents() + { + super.registerActionComponents(); + + parent.addActionListener(this); + child.addActionListener(this); + parentRev.addActionListener(this); + childRev.addActionListener(this); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#setComponentsTextProperty() + */ + protected void setComponentsTextProperty() + { + super.setComponentsTextProperty(); + + try + { + TCTypeService service = session.getTypeService(); + TCComponentType type = service.getTypeComponent("BOMLine"); + TCPropertyDescriptor descriptor[] = type.getPropertyDescriptors(); + List list = new ArrayList(); + for (int i = 0; i < descriptor.length; i++) + { + if (descriptor[i].isModifiable() && !descriptor[i].toString().equals("bl_pack_count")) + { + list.add(descriptor[i].getName()); + } + } + Collections.sort(list); + for (String str : list) + { + propertiesListModels[0].addElement(str); + } + } + catch (TCException te) + { + te.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#addTabbedPaneComponents() + */ + protected void addTabbedPaneComponents() + { + String[] titles = new String[] { "BOMLine" }; + for (int i = 0; i < propertiesList.length; i++) + { + JPanel panel = new JPanel(new GridLayout()); + panel.add(new JScrollPane(propertiesList[i])); + panel.add(new JScrollPane(mappingList[i])); + rightPane.addTab(titles[i], panel); + } + + rightPane.addTab("", getParameterPanel()); + } + + /* + * (non-Javadoc) + * + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent ae) + { + if (ae.getSource() instanceof MappingButton) + { + assignMappingAttribute((MappingButton) ae.getSource()); + } + else if (ae.getSource() == unlock) + { + parent.setEnabled(true); + child.setEnabled(true); + parentRev.setEnabled(true); + childRev.setEnabled(true); + + super.actionPerformed(ae); + } + else + { + super.actionPerformed(ae); + } + } + + private void assignMappingAttribute(MappingButton button) + { + if (excelList.getSelectedIndex() == -1) + { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ѡӦһָϵ", "", 1); + + return; + } + + String excel = excelList.getSelectedValue().toString(); + int index = excelList.getSelectedIndex(); + + MappingAttribute ma = new MappingAttribute(index, excel, button.getPropertyName()); + button.setMappingAttribute(ma); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) + */ + public void stateChanged(ChangeEvent changeevent) + { + int index = rightPane.getSelectedIndex(); + if (index > 0) + { + add.setEnabled(false); + remove.setEnabled(false); + } + else + { + checkMappingsEditable(); + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#openImportSettings() + */ + protected void openImportSettings() + { + if (chooser.showOpenDialog(null) == 0) + { + BomsImportSettings bis = new BomsImportSettings(); + ImportSettings is = bis.load(chooser.getSelectedFile()); + + if (is == null) + { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ļмʧ.", "", 1); + return; + } + + if (is instanceof BomsImportSettings) + { + bis = (BomsImportSettings) is; + + // arraySepField.setText(bis.getArraySeparator()); + + for (int i = 0; i < mappingListModels.length; i++) + { + mappingListModels[i].removeAllElements(); + } + + for (int i = 0; i < bis.getBomLineMapping().length; i++) + { + mappingListModels[0].addElement(bis.getBomLineMapping()[i]); + } + + parent.setMappingAttribute(bis.getParentMapping()); + child.setMappingAttribute(bis.getChildMapping()); + parentRev.setMappingAttribute(bis.getParentRevMapping()); + childRev.setMappingAttribute(bis.getChildRevMapping()); + + excelList.setEnabled(false); + for (int i = 0; i < propertiesList.length; i++) + { + propertiesList[i].setEnabled(false); + mappingList[i].setEnabled(false); + } + + parent.setEnabled(false); + child.setEnabled(false); + parentRev.setEnabled(false); + childRev.setEnabled(false); + } + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#saveImportSettings() + */ + protected void saveImportSettings() + { + BomsImportSettings bis = generateImportSettings(); + + if (chooser.showSaveDialog(null) == 0) + { + try + { + FileOutputStream fileoutputstream = new FileOutputStream(chooser.getSelectedFile()); + ObjectOutputStream objectoutputstream = new ObjectOutputStream(fileoutputstream); + objectoutputstream.writeObject(bis); + objectoutputstream.flush(); + objectoutputstream.close(); + } + catch (IOException ioe) + { + ioe.printStackTrace(); + } + + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "Ѿɹ\n" + + chooser.getSelectedFile().getAbsolutePath(), "ɹ", 2); + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#generateImportSettings() + */ + public BomsImportSettings generateImportSettings() + { + BomsImportSettings bis = new BomsImportSettings(); + + MappingAttribute[] itemMapping = new MappingAttribute[mappingListModels[0].size()]; + System.arraycopy(mappingListModels[0].toArray(), 0, itemMapping, 0, itemMapping.length); + bis.setBomLineMapping(itemMapping); + + bis.setChildMapping(child.getMappingAttribute()); + bis.setChildRevMapping(childRev.getMappingAttribute()); + bis.setParentMapping(parent.getMappingAttribute()); + bis.setParentRevMapping(parentRev.getMappingAttribute()); + + bis.setColumns(excelList.getModel().getSize()); + + // bis.setArraySeparator(arraySepField.getText().trim()); + bis.setDateFormat(dateFormatField.getText().trim()); + + return bis; + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#getParameterPanel() + */ + protected JPanel getParameterPanel() + { + JPanel p = super.getParameterPanel(); + + p.add("2.1.right.top.preferred.preferred", new JLabel("Parent ID :")); + p.add("2.2.left.top.preferred.preferred", parent); + p.add("3.1.right.top.preferred.preferred", new JLabel("Parent Revision ID :")); + p.add("3.2.left.top.preferred.preferred", parentRev); + + p.add("4.1.right.top.preferred.preferred", new JLabel("Child ID :")); + p.add("4.2.left.top.preferred.preferred", child); + p.add("5.1.right.top.preferred.preferred", new JLabel("Child Revision ID :")); + p.add("5.2.left.top.preferred.preferred", childRev); + + return p; + } +} diff --git a/src/com/connor/dev/imp/bom/ImportBomsForProECommand.java b/src/com/connor/dev/imp/bom/ImportBomsForProECommand.java new file mode 100644 index 0000000..9a7cbca --- /dev/null +++ b/src/com/connor/dev/imp/bom/ImportBomsForProECommand.java @@ -0,0 +1,20 @@ +package com.connor.dev.imp.bom; + + +import com.connor.dev.imp.AbstractImportCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; + +public class ImportBomsForProECommand extends AbstractImportCommand +{ + public ImportBomsForProECommand(AbstractAIFUIApplication application) + { + super(application); + } + + + protected void importHistoryDatas() + { + ImportBomsForProEDialog dialog = new ImportBomsForProEDialog(session, "BOM"); + setRunnable(dialog); + } +} diff --git a/src/com/connor/dev/imp/bom/ImportBomsForProEDialog.java b/src/com/connor/dev/imp/bom/ImportBomsForProEDialog.java new file mode 100644 index 0000000..899da07 --- /dev/null +++ b/src/com/connor/dev/imp/bom/ImportBomsForProEDialog.java @@ -0,0 +1,340 @@ +package com.connor.dev.imp.bom; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.DefaultListModel; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeEvent; + +import com.connor.dev.imp.AbstractImportDialog; +import com.connor.dev.imp.AbstractImportForProEDialog; +import com.connor.dev.imp.ImportSettings; +import com.connor.dev.imp.MappingAttribute; +import com.connor.dev.imp.ob.MappingButton; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.util.MessageBox; + +public class ImportBomsForProEDialog extends AbstractImportForProEDialog +{ + private static final long serialVersionUID = 1L; + + private MappingButton parent; + + private MappingButton child; + + private MappingButton parentRev; + + private MappingButton childRev; + + public ImportBomsForProEDialog(TCSession session, String title) + { + super(session, title, true); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#initializeUI() + */ + protected void initializeUI() + { + super.initializeUI(); + + propertiesList = new JList[1]; + propertiesListModels = new DefaultListModel[1]; + mappingListModels = new DefaultListModel[1]; + mappingList = new JList[1]; + + for (int i = 0; i < propertiesList.length; i++) + { + propertiesListModels[i] = new DefaultListModel(); + propertiesList[i] = new JList(propertiesListModels[i]); + propertiesList[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + propertiesList[i].setVisibleRowCount(20); + mappingListModels[i] = new DefaultListModel(); + mappingList[i] = new JList(mappingListModels[i]); + mappingList[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + } + + parent = new MappingButton("Parent ID"); + child = new MappingButton("Child ID"); + parentRev = new MappingButton("Parent Revision ID"); + childRev = new MappingButton("Child Revision ID"); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#registerActionComponents() + */ + protected void registerActionComponents() + { + super.registerActionComponents(); + + parent.addActionListener(this); + child.addActionListener(this); + parentRev.addActionListener(this); + childRev.addActionListener(this); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#setComponentsTextProperty() + */ + protected void setComponentsTextProperty() + { + super.setComponentsTextProperty(); + + try + { + TCTypeService service = session.getTypeService(); + TCComponentType type = service.getTypeComponent("BOMLine"); + TCPropertyDescriptor descriptor[] = type.getPropertyDescriptors(); + List list = new ArrayList(); + for (int i = 0; i < descriptor.length; i++) + { + if (descriptor[i].isModifiable() && !descriptor[i].toString().equals("bl_pack_count")) + { + list.add(descriptor[i].getName()); + } + } + Collections.sort(list); + for (String str : list) + { + propertiesListModels[0].addElement(str); + } + } + catch (TCException te) + { + te.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#addTabbedPaneComponents() + */ + protected void addTabbedPaneComponents() + { + String[] titles = new String[] { "BOMLine" }; + for (int i = 0; i < propertiesList.length; i++) + { + JPanel panel = new JPanel(new GridLayout()); + panel.add(new JScrollPane(propertiesList[i])); + panel.add(new JScrollPane(mappingList[i])); + rightPane.addTab(titles[i], panel); + } + + rightPane.addTab("", getParameterPanel()); + } + + /* + * (non-Javadoc) + * + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent ae) + { + if (ae.getSource() instanceof MappingButton) + { + assignMappingAttribute((MappingButton) ae.getSource()); + } + else if (ae.getSource() == unlock) + { + parent.setEnabled(true); + child.setEnabled(true); + parentRev.setEnabled(true); + childRev.setEnabled(true); + + super.actionPerformed(ae); + } + else + { + super.actionPerformed(ae); + } + } + + private void assignMappingAttribute(MappingButton button) + { + if (excelList.getSelectedIndex() == -1) + { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ѡӦһָϵ", "", 1); + + return; + } + + String excel = excelList.getSelectedValue().toString(); + int index = excelList.getSelectedIndex(); + + MappingAttribute ma = new MappingAttribute(index, excel, button.getPropertyName()); + button.setMappingAttribute(ma); + } + + /* + * (non-Javadoc) + * + * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) + */ + public void stateChanged(ChangeEvent changeevent) + { + int index = rightPane.getSelectedIndex(); + if (index > 0) + { + add.setEnabled(false); + remove.setEnabled(false); + } + else + { + checkMappingsEditable(); + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#openImportSettings() + */ + protected void openImportSettings() + { + if (chooser.showOpenDialog(null) == 0) + { + BomsImportSettings bis = new BomsImportSettings(); + ImportSettings is = bis.load(chooser.getSelectedFile()); + + if (is == null) + { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ļмʧ.", "", 1); + return; + } + + if (is instanceof BomsImportSettings) + { + bis = (BomsImportSettings) is; + + // arraySepField.setText(bis.getArraySeparator()); + + for (int i = 0; i < mappingListModels.length; i++) + { + mappingListModels[i].removeAllElements(); + } + + for (int i = 0; i < bis.getBomLineMapping().length; i++) + { + mappingListModels[0].addElement(bis.getBomLineMapping()[i]); + } + + parent.setMappingAttribute(bis.getParentMapping()); + child.setMappingAttribute(bis.getChildMapping()); + parentRev.setMappingAttribute(bis.getParentRevMapping()); + childRev.setMappingAttribute(bis.getChildRevMapping()); + + excelList.setEnabled(false); + for (int i = 0; i < propertiesList.length; i++) + { + propertiesList[i].setEnabled(false); + mappingList[i].setEnabled(false); + } + + parent.setEnabled(false); + child.setEnabled(false); + parentRev.setEnabled(false); + childRev.setEnabled(false); + } + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#saveImportSettings() + */ + protected void saveImportSettings() + { + BomsImportSettings bis = generateImportSettings(); + + if (chooser.showSaveDialog(null) == 0) + { + try + { + FileOutputStream fileoutputstream = new FileOutputStream(chooser.getSelectedFile()); + ObjectOutputStream objectoutputstream = new ObjectOutputStream(fileoutputstream); + objectoutputstream.writeObject(bis); + objectoutputstream.flush(); + objectoutputstream.close(); + } + catch (IOException ioe) + { + ioe.printStackTrace(); + } + + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "Ѿɹ\n" + + chooser.getSelectedFile().getAbsolutePath(), "ɹ", MessageBox.INFORMATION); + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#generateImportSettings() + */ + public BomsImportSettings generateImportSettings() + { + BomsImportSettings bis = new BomsImportSettings(); + + MappingAttribute[] itemMapping = new MappingAttribute[mappingListModels[0].size()]; + System.arraycopy(mappingListModels[0].toArray(), 0, itemMapping, 0, itemMapping.length); + bis.setBomLineMapping(itemMapping); + + bis.setChildMapping(child.getMappingAttribute()); + bis.setChildRevMapping(childRev.getMappingAttribute()); + bis.setParentMapping(parent.getMappingAttribute()); + bis.setParentRevMapping(parentRev.getMappingAttribute()); + + bis.setColumns(excelList.getModel().getSize()); + + // bis.setArraySeparator(arraySepField.getText().trim()); + bis.setDateFormat(dateFormatField.getText().trim()); + + return bis; + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#getParameterPanel() + */ + protected JPanel getParameterPanel() + { + JPanel p = super.getParameterPanel(); + + p.add("2.1.right.top.preferred.preferred", new JLabel("Parent ID :")); + p.add("2.2.left.top.preferred.preferred", parent); + p.add("3.1.right.top.preferred.preferred", new JLabel("Parent Revision ID :")); + p.add("3.2.left.top.preferred.preferred", parentRev); + + p.add("4.1.right.top.preferred.preferred", new JLabel("Child ID :")); + p.add("4.2.left.top.preferred.preferred", child); + p.add("5.1.right.top.preferred.preferred", new JLabel("Child Revision ID :")); + p.add("5.2.left.top.preferred.preferred", childRev); + + return p; + } +} diff --git a/src/com/connor/dev/imp/images/add.gif b/src/com/connor/dev/imp/images/add.gif new file mode 100644 index 0000000..d66053c Binary files /dev/null and b/src/com/connor/dev/imp/images/add.gif differ diff --git a/src/com/connor/dev/imp/images/add_16.png b/src/com/connor/dev/imp/images/add_16.png new file mode 100644 index 0000000..bc58bd7 Binary files /dev/null and b/src/com/connor/dev/imp/images/add_16.png differ diff --git a/src/com/connor/dev/imp/images/apply_16.png b/src/com/connor/dev/imp/images/apply_16.png new file mode 100644 index 0000000..19f71f8 Binary files /dev/null and b/src/com/connor/dev/imp/images/apply_16.png differ diff --git a/src/com/connor/dev/imp/images/cancel_16.png b/src/com/connor/dev/imp/images/cancel_16.png new file mode 100644 index 0000000..7186b3d Binary files /dev/null and b/src/com/connor/dev/imp/images/cancel_16.png differ diff --git a/src/com/connor/dev/imp/images/cancel_all_16.png b/src/com/connor/dev/imp/images/cancel_all_16.png new file mode 100644 index 0000000..b43470e Binary files /dev/null and b/src/com/connor/dev/imp/images/cancel_all_16.png differ diff --git a/src/com/connor/dev/imp/images/excel_16.png b/src/com/connor/dev/imp/images/excel_16.png new file mode 100644 index 0000000..f2d45cc Binary files /dev/null and b/src/com/connor/dev/imp/images/excel_16.png differ diff --git a/src/com/connor/dev/imp/images/import_16.png b/src/com/connor/dev/imp/images/import_16.png new file mode 100644 index 0000000..9bc3b90 Binary files /dev/null and b/src/com/connor/dev/imp/images/import_16.png differ diff --git a/src/com/connor/dev/imp/images/open.gif b/src/com/connor/dev/imp/images/open.gif new file mode 100644 index 0000000..7a1658c Binary files /dev/null and b/src/com/connor/dev/imp/images/open.gif differ diff --git a/src/com/connor/dev/imp/images/open_16.png b/src/com/connor/dev/imp/images/open_16.png new file mode 100644 index 0000000..79f8d61 Binary files /dev/null and b/src/com/connor/dev/imp/images/open_16.png differ diff --git a/src/com/connor/dev/imp/images/refresh.GIF b/src/com/connor/dev/imp/images/refresh.GIF new file mode 100644 index 0000000..7df56bb Binary files /dev/null and b/src/com/connor/dev/imp/images/refresh.GIF differ diff --git a/src/com/connor/dev/imp/images/refresh_16.png b/src/com/connor/dev/imp/images/refresh_16.png new file mode 100644 index 0000000..e2798c0 Binary files /dev/null and b/src/com/connor/dev/imp/images/refresh_16.png differ diff --git a/src/com/connor/dev/imp/images/remove.gif b/src/com/connor/dev/imp/images/remove.gif new file mode 100644 index 0000000..e0ced49 Binary files /dev/null and b/src/com/connor/dev/imp/images/remove.gif differ diff --git a/src/com/connor/dev/imp/images/remove_16.png b/src/com/connor/dev/imp/images/remove_16.png new file mode 100644 index 0000000..4ff8845 Binary files /dev/null and b/src/com/connor/dev/imp/images/remove_16.png differ diff --git a/src/com/connor/dev/imp/images/save.gif b/src/com/connor/dev/imp/images/save.gif new file mode 100644 index 0000000..e6ff1c4 Binary files /dev/null and b/src/com/connor/dev/imp/images/save.gif differ diff --git a/src/com/connor/dev/imp/images/save_16.png b/src/com/connor/dev/imp/images/save_16.png new file mode 100644 index 0000000..57e15d9 Binary files /dev/null and b/src/com/connor/dev/imp/images/save_16.png differ diff --git a/src/com/connor/dev/imp/images/yes.gif b/src/com/connor/dev/imp/images/yes.gif new file mode 100644 index 0000000..e6ee93d Binary files /dev/null and b/src/com/connor/dev/imp/images/yes.gif differ diff --git a/src/com/connor/dev/imp/ob/ImportObjectsCommand.java b/src/com/connor/dev/imp/ob/ImportObjectsCommand.java new file mode 100644 index 0000000..0b397e6 --- /dev/null +++ b/src/com/connor/dev/imp/ob/ImportObjectsCommand.java @@ -0,0 +1,47 @@ +package com.connor.dev.imp.ob; + +import com.connor.dev.imp.AbstractImportCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; + +public class ImportObjectsCommand extends AbstractImportCommand { + public ImportObjectsCommand(AbstractAIFUIApplication application) { + super(application); + } + + public void importHistoryDatas() { + try { + ImportObjectsDialog dialog = new ImportObjectsDialog(session, ""); + if (dialog != null) { + setRunnable(dialog); + } + } + catch (Exception e) { + e.printStackTrace(); + } + // try + // { + // TCTypeService service = session.getTypeService(); + // TCComponentType[] items = service.getTypes("UnitOfMeasure"); + // if (items != null) + // { + // for (int i = 0; i < items.length; i++) + // { + // System.out.println(items[i].toString()); + // } + // } + // else + // { + // TCComponentType uom = service.getTypeComponent("UnitOfMeasure"); + // TCComponent[] coms = uom.extent(); + // for (int i = 0; i < coms.length; i++) + // { + // System.out.println(coms[i].toString()); + // System.out.println(coms[i].getClass().getName()); + // } + // } + // } + // catch (TCException e) + // { + // } + } +} diff --git a/src/com/connor/dev/imp/ob/ImportObjectsDialog.java b/src/com/connor/dev/imp/ob/ImportObjectsDialog.java new file mode 100644 index 0000000..383f724 --- /dev/null +++ b/src/com/connor/dev/imp/ob/ImportObjectsDialog.java @@ -0,0 +1,611 @@ +package com.connor.dev.imp.ob; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeEvent; + +import com.connor.dev.imp.AbstractImportDialog; +import com.connor.dev.imp.ImportSettings; +import com.connor.dev.imp.MappingAttribute; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.kernel.TCComponentAliasList; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.util.AIFImageIcon; +import com.teamcenter.rac.util.MessageBox; + +/** + * @author Administrator + * + */ +public class ImportObjectsDialog extends AbstractImportDialog { + private static final long serialVersionUID = 1L; + + private JComboBox itemTypeCombo; + + private JCheckBox replace; + private JCheckBox throughParent; + private JButton addType; + private boolean isCanValues = false; + + public ImportObjectsDialog(TCSession session, String title, String exportFilePath, String settingFilePath, + boolean isCanValues) { + + super(session, title, false, exportFilePath, settingFilePath, isCanValues); + + } + + public ImportObjectsDialog(TCSession session, String title) { + super(session, title, false); + } + + public void init() { + initializeUI(); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#initializeUI() + */ + protected void initializeUI() { + super.initializeUI(); + + propertiesList = new JList[4]; + propertiesListModels = new DefaultListModel[4]; + mappingListModels = new DefaultListModel[4]; + mappingList = new JList[4]; + + for (int i = 0; i < propertiesList.length; i++) { + propertiesListModels[i] = new DefaultListModel(); + propertiesList[i] = new JList(propertiesListModels[i]); + propertiesList[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + propertiesList[i].setVisibleRowCount(20); + mappingListModels[i] = new DefaultListModel(); + mappingList[i] = new JList(mappingListModels[i]); + mappingList[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + } + + itemTypeCombo = new JComboBox(); + + replace = new JCheckBox(); + addType = new JButton(AIFImageIcon.getImageIcon(this, "images/add_16.png")); + addType.setEnabled(false); + throughParent = new JCheckBox(); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#registerActionComponents() + */ + protected void registerActionComponents() { + super.registerActionComponents(); + + itemTypeCombo.addActionListener(this); + throughParent.addActionListener(this); + addType.addActionListener(this); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#setComponentsTextProperty() + */ + protected void setComponentsTextProperty() { + super.setComponentsTextProperty(); + + // populateTypeChoices("Item", itemTypeCombo); + // populateTypeChoices("MEProcess", itemTypeCombo); + // populateTypeChoices("MEOP", itemTypeCombo); + populateItemTypes(itemTypeCombo); + itemTypeCombo.insertItemAt("", 0); + itemTypeCombo.setSelectedIndex(0); + // populateTypeChoices("MENCMachining", itemTypeCombo); + + // arraySepField.setText("||"); + + try { + TCTypeService service = session.getTypeService(); + TCComponentType[] type = service.getTypes("Dataset"); + propertiesListModels[3].removeAllElements(); + List list = new ArrayList(); + if (type != null) + for (int i = 0; i < type.length; i++) { + list.add(type[i] == null ? "" : type[i].toString()); + } + Collections.sort(list); + propertiesListModels[3].addElement("·"); + + for (String str : list) { + propertiesListModels[3].addElement(str); + } + } catch (TCException tce) { + tce.printStackTrace(); + } + + replace.setText("Ѵڵ"); + + throughParent.setText("ֵ"); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#addTabbedPaneComponents() + */ + public void addTabbedPaneComponents() { + String[] titles = new String[] { "", "汾", "汾Form", "ݼ" }; + for (int i = 0; i < 4; i++) { + JPanel panel = new JPanel(new GridLayout()); + panel.add(new JScrollPane(propertiesList[i])); + panel.add(new JScrollPane(mappingList[i])); + rightPane.addTab(titles[i], panel); + } + + rightPane.addTab("", getParameterPanel()); + } + + /** + * ֵֻ + */ + protected void doPurgeComponentProperties(String name) { + super.doPurgeComponentProperties(name); + + if (itemTypeCombo.getSelectedIndex() == 0) { + return; + } + + // õϵ + try { + TCTypeService service = session.getTypeService(); + TCComponentType type = service.getTypeComponent(name); + TCPropertyDescriptor[] descriptor = type.getPropertyDescriptors(); + List list = new ArrayList(); + + for (int i = 0; i < descriptor.length; i++) { + list.add(descriptor[i].getName()); + } + + propertiesListModels[0].removeAllElements(); + Collections.sort(list); + propertiesListModels[0].addElement(""); + propertiesListModels[0].addElement("Ŀ");//2017/10/25 + for (String str : list) { + propertiesListModels[0].addElement(str); + } + + // õ汾ϵ + // if ("Design".equals(name) || "Drawing".equals(name) || + // "EngChange".equals(name) + // || "CommercialPart".equals(name) || "Part".equals(name) || + // "ManufacturerPart".equals(name) + // || "Message".equals(name) || "Paragraph".equals(name) || + // "Requirement".equals(name) + // || "GCS_CP_Plug".equals(name) || "GCS_CP_Socket".equals(name) || + // "GCS_CP".equals(name) + // || "MEWEDM".equals(name) || "Specification".equals(name) || + // "RequirementSpec".equals(name)) + // { + // name = String.valueOf(String.valueOf(name)).concat(" "); + // } + // *** + String temp1 = ""; + String temp2 = ""; + String temp3 = name; + + /* + * try { type = service.getTypeComponent(String.valueOf(name + + * "Revision")); name = name + "Revision"; } catch (Exception e) { + * type = service.getTypeComponent(String.valueOf(name.concat( + * " Revision" ))); name = name + " Revision"; } + */ + type = service.getTypeComponent(String.valueOf(name + " Revision")); + // type.getReferenceListProperty(arg0) + if (type == null) { + type = service.getTypeComponent(String.valueOf(name + "Revision")); + name = name + "Revision"; + temp1 = name; + } else { + name = name + " Revision"; + temp2 = name; + } // ***** + TCComponentFolder folder = null; + descriptor = type.getPropertyDescriptors(); + list.clear(); + for (int i = 0; i < descriptor.length; i++) { + if (descriptor[i].isModifiable()) { + list.add(descriptor[i].getName()); + } + } + propertiesListModels[1].removeAllElements(); + Collections.sort(list); + for (String str : list) { + propertiesListModels[1].addElement(str); + } + // **** + /* + * try { type = service.getTypeComponent(name + "Master"); } catch + * (Exception e) { type = service.getTypeComponent(name + " Master" + * ); } + */ + + type = service.getTypeComponent(name + " Master"); + if (type == null) { + type = service.getTypeComponent(name + "Master"); + + } + if (type == null) { + type = service.getTypeComponent(temp1 + "Master"); + } + if (type == null) { + type = service.getTypeComponent(temp2 + "Master"); + } + if (type == null) { + type = service.getTypeComponent(temp1 + " Master"); + } + if (type == null) { + type = service.getTypeComponent(temp2 + " Master"); + } + if (type == null) { + type = service.getTypeComponent(temp3 + "Rev" + " Master"); + } + if (type == null) { + type = service.getTypeComponent(temp3 + "Rev" + "Master"); + } + // **** + String[] properties = type.getPropertyNames(); + list.clear(); + for (int i = 0; i < properties.length; i++) { + list.add(properties[i]); + } + propertiesListModels[2].removeAllElements(); + Collections.sort(list); + for (String str : list) { + propertiesListModels[2].addElement(str); + } + } catch (TCException tce) { + tce.printStackTrace(); + } + } + + /** + * ֵ + * + * @param name + */ + protected void doPurgeComponentProperties2(String name) { + // super.doPurgeComponentProperties(name); + + if (itemTypeCombo.getSelectedIndex() == 0) { + return; + } + + // õϵ + try { + TCTypeService service = session.getTypeService(); + TCComponentType type = service.getTypeComponent(name); + TCPropertyDescriptor[] descriptor = type.getPropertyDescriptors(); + List list = new ArrayList(); + + for (int i = 0; i < descriptor.length; i++) { + if (descriptor[i].isModifiable()) { + list.add(descriptor[i].getName()); + } + } + for (int i = 0; i < propertiesListModels[0].size(); i++) { + Object obj = propertiesListModels[0].get(i); + list.add((String) obj); + } + + propertiesListModels[0].removeAllElements(); + Collections.sort(list); + if (!propertiesListModels[0].contains("")) { + propertiesListModels[0].addElement(""); + System.out.println("û"); + } else { + System.out.println(""); + } + for (String str : list) { + if (!propertiesListModels[0].contains(str)) + propertiesListModels[0].addElement(str); + } + + // õ汾ϵ + // if ("Design".equals(name) || "Drawing".equals(name) || + // "EngChange".equals(name) + // || "CommercialPart".equals(name) || "Part".equals(name) || + // "ManufacturerPart".equals(name) + // || "Message".equals(name) || "Paragraph".equals(name) || + // "Requirement".equals(name) + // || "GCS_CP_Plug".equals(name) || "GCS_CP_Socket".equals(name) || + // "GCS_CP".equals(name) + // || "MEWEDM".equals(name) || "Specification".equals(name) || + // "RequirementSpec".equals(name)) + // { + // name = String.valueOf(String.valueOf(name)).concat(" "); + // } + // *** + String temp1 = ""; + String temp2 = ""; + String temp3 = name; + + /* + * try { type = service.getTypeComponent(String.valueOf(name + + * "Revision")); name = name + "Revision"; } catch (Exception e) { + * type = service.getTypeComponent(String.valueOf(name.concat( + * " Revision" ))); name = name + " Revision"; } + */ + type = service.getTypeComponent(String.valueOf(name + " Revision")); + if (type == null) { + type = service.getTypeComponent(String.valueOf(name + "Revision")); + name = name + "Revision"; + temp1 = name; + } else { + name = name + " Revision"; + temp2 = name; + } // ***** + + descriptor = type.getPropertyDescriptors(); + list.clear(); + for (int i = 0; i < descriptor.length; i++) { + if (descriptor[i].isModifiable()) { + list.add(descriptor[i].getName()); + } + } + for (int i = 0; i < propertiesListModels[1].size(); i++) { + Object obj = propertiesListModels[1].get(i); + list.add((String) obj); + } + propertiesListModels[1].removeAllElements(); + Collections.sort(list); + for (String str : list) { + if (!propertiesListModels[1].contains(str)) + propertiesListModels[1].addElement(str); + } + // **** + /* + * try { type = service.getTypeComponent(name + "Master"); } catch + * (Exception e) { type = service.getTypeComponent(name + " Master" + * ); } + */ + + type = service.getTypeComponent(name + " Master"); + if (type == null) { + type = service.getTypeComponent(name + "Master"); + + } + if (type == null) { + type = service.getTypeComponent(temp1 + "Master"); + } + if (type == null) { + type = service.getTypeComponent(temp2 + "Master"); + } + if (type == null) { + type = service.getTypeComponent(temp1 + " Master"); + } + if (type == null) { + type = service.getTypeComponent(temp2 + " Master"); + } + if (type == null) { + type = service.getTypeComponent(temp3 + "Rev" + " Master"); + } + if (type == null) { + type = service.getTypeComponent(temp3 + "Rev" + "Master"); + } + // **** + String[] properties = type.getPropertyNames(); + list.clear(); + for (int i = 0; i < properties.length; i++) { + list.add(properties[i]); + } + for (int i = 0; i < propertiesListModels[2].size(); i++) { + Object obj = propertiesListModels[2].get(i); + list.add((String) obj); + } + propertiesListModels[2].removeAllElements(); + Collections.sort(list); + for (String str : list) { + if (!propertiesListModels[2].contains(str)) + propertiesListModels[2].addElement(str); + } + } catch (TCException tce) { + tce.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event. + * ChangeEvent ) + */ + public void stateChanged(ChangeEvent e) { + int index = rightPane.getSelectedIndex(); + if (index > 3) { + add.setEnabled(false); + remove.setEnabled(false); + } else { + checkMappingsEditable(); + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#openImportSettings() + */ + protected void openImportSettings() { + + if (this.isExec) { + openImportSettings2(isExec); + } else if (chooser.showOpenDialog(null) == 0) { + openImportSettings2(false); + } + } + + public void openImportSettings2(boolean c) { + + ObjectsImportSettings ois = new ObjectsImportSettings(); + ImportSettings is = null; + if (!isExec) { + is = ois.load(chooser.getSelectedFile()); + } else { + + is = ois.load(new File(this.settingFilePath)); + } + + if (is == null) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ļмʧ.", "", 1); + return; + } + + if (is instanceof ObjectsImportSettings) { + ois = (ObjectsImportSettings) is; + + replace.setSelected(ois.isExistedRefreshed()); + throughParent.setSelected(ois.isSelectParent()); + itemTypeCombo.setSelectedItem(ois.getItemType()); + // arraySepField.setText(ois.getArraySeparator()); + for (int i = 0; i < 4; i++) { + mappingListModels[i].removeAllElements(); + } + + for (int i = 0; i < ois.getItemMapping().length; i++) { + mappingListModels[0].addElement(ois.getItemMapping()[i]); + } + + for (int i = 0; i < ois.getRevMapping().length; i++) { + mappingListModels[1].addElement(ois.getRevMapping()[i]); + } + + for (int i = 0; i < ois.getRevFormMapping().length; i++) { + mappingListModels[2].addElement(ois.getRevFormMapping()[i]); + } + + for (int i = 0; i < ois.getDatasetMapping().length; i++) { + mappingListModels[3].addElement(ois.getDatasetMapping()[i]); + } + + excelList.setEnabled(false); + for (int i = 0; i < 4; i++) { + propertiesList[i].setEnabled(false); + mappingList[i].setEnabled(false); + } + } + + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#saveImportSettings() + */ + protected void saveImportSettings() { + ObjectsImportSettings ois = generateImportSettings(); + + if (chooser.showSaveDialog(null) == 0) { + if (ois.save(chooser.getSelectedFile())) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "Ѿɹ\n" + chooser.getSelectedFile().getAbsolutePath(), "ɹ", 2); + } else { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ļʧ", "ʧ", 1); + } + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#generateImportSettings() + */ + public ObjectsImportSettings generateImportSettings() { + ObjectsImportSettings ois = new ObjectsImportSettings(); + + MappingAttribute[] itemMapping = new MappingAttribute[mappingListModels[0].size()]; + System.arraycopy(mappingListModels[0].toArray(), 0, itemMapping, 0, itemMapping.length); + ois.setItemMapping(itemMapping); + + MappingAttribute[] revMapping = new MappingAttribute[mappingListModels[1].size()]; + System.arraycopy(mappingListModels[1].toArray(), 0, revMapping, 0, revMapping.length); + ois.setRevMapping(revMapping); + + MappingAttribute[] revFormMapping = new MappingAttribute[mappingListModels[2].size()]; + System.arraycopy(mappingListModels[2].toArray(), 0, revFormMapping, 0, revFormMapping.length); + ois.setRevFormMapping(revFormMapping); + + MappingAttribute[] datasetMapping = new MappingAttribute[mappingListModels[3].size()]; + System.arraycopy(mappingListModels[3].toArray(), 0, datasetMapping, 0, datasetMapping.length); + ois.setDatasetMapping(datasetMapping); + + ois.setItemType(itemTypeCombo.getSelectedItem().toString()); + ois.setColumns(excelList.getModel().getSize()); + ois.setExistedRefreshed(replace.isSelected()); + ois.setSelectParent(throughParent.isSelected()); + + // ois.setArraySeparator(arraySepField.getText().trim()); + ois.setDateFormat(dateFormatField.getText().trim()); + + return ois; + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#getParameterPanel() + */ + protected JPanel getParameterPanel() { + JPanel p = super.getParameterPanel(); + + // p.add("3.1.right.top.preferred.preferred", new JLabel("ļָ:")); + // p.add("3.2.left.top.preferred.preferred", new JTextField(20)); + p.add("2.1.right.top.preferred.preferred", new JLabel(":")); + p.add("2.2.left.top.preferred.preferred", itemTypeCombo); + p.add("2.3.left.top.preferred.preferred", addType); + p.add("2.4.left.top.preferred.preferred", throughParent); + p.add("3.1.right.top.preferred.preferred", new JLabel(" ")); + p.add("3.2.left.top.preferred.preferred", replace); + // p.add("4.1.right.top.preferred.preferred", new JLabel(" ")); + // p.add("4.2.left.top.preferred.preferred", throughParent); + return p; + } + + public void actionPerformed(ActionEvent ae) { + if (ae.getSource() == throughParent) { + if (throughParent.isSelected()) { + isCanValues = true; + addType.setEnabled(true); + } else { + isCanValues = false; + addType.setEnabled(false); + doPurgeComponentProperties(itemTypeCombo.getSelectedItem().toString()); + } + } else if (ae.getSource() == itemTypeCombo) { + if (!isCanValues) + doPurgeComponentProperties(itemTypeCombo.getSelectedItem().toString()); + + } else if (ae.getSource() == addType) { + doPurgeComponentProperties2(itemTypeCombo.getSelectedItem().toString()); + } else { + super.actionPerformed(ae); + } + } +} diff --git a/src/com/connor/dev/imp/ob/MappingButton.java b/src/com/connor/dev/imp/ob/MappingButton.java new file mode 100644 index 0000000..99d5936 --- /dev/null +++ b/src/com/connor/dev/imp/ob/MappingButton.java @@ -0,0 +1,46 @@ +package com.connor.dev.imp.ob; + +import javax.swing.JButton; + +import com.connor.dev.imp.MappingAttribute; + + +public class MappingButton extends JButton +{ + private static final long serialVersionUID = 1L; + + private MappingAttribute mappingAttribute; + + private String propertyName; + + public MappingButton(String propertyName) + { + super(propertyName); + + this.propertyName = propertyName; + } + + public void setMappingAttribute(MappingAttribute mappingAttribute) + { + this.mappingAttribute = mappingAttribute; + + if(mappingAttribute != null) + { + setText(mappingAttribute.toString()); + } + else + { + setText(propertyName); + } + } + + public MappingAttribute getMappingAttribute() + { + return mappingAttribute; + } + + public String getPropertyName() + { + return propertyName; + } +} diff --git a/src/com/connor/dev/imp/ob/ObjectsImportSettings.java b/src/com/connor/dev/imp/ob/ObjectsImportSettings.java new file mode 100644 index 0000000..5f0835b --- /dev/null +++ b/src/com/connor/dev/imp/ob/ObjectsImportSettings.java @@ -0,0 +1,91 @@ +package com.connor.dev.imp.ob; + +import java.io.Serializable; + +import com.connor.dev.imp.ImportSettings; +import com.connor.dev.imp.MappingAttribute; + +public class ObjectsImportSettings extends ImportSettings implements Serializable +{ + private static final long serialVersionUID = 1L; + + private MappingAttribute[] itemMapping; + + private MappingAttribute[] revMapping; + + private MappingAttribute[] revFormMapping; + + private MappingAttribute[] datasetMapping; + + private String itemType; + + private boolean existedRefreshed; + //ѡ࣬ԶĹ + private boolean selectParent; + + + + public boolean isSelectParent() { + return selectParent; + } + public void setSelectParent(boolean selectParent) { + this.selectParent = selectParent; + } + + public MappingAttribute[] getItemMapping() + { + return itemMapping; + } + public void setItemMapping(MappingAttribute[] itemMapping) + { + this.itemMapping = itemMapping; + } + + public MappingAttribute[] getRevMapping() + { + return revMapping; + } + + public void setRevMapping(MappingAttribute[] revMapping) + { + this.revMapping = revMapping; + } + + public MappingAttribute[] getRevFormMapping() + { + return revFormMapping; + } + + public void setRevFormMapping(MappingAttribute[] revFormMapping) + { + this.revFormMapping = revFormMapping; + } + + public MappingAttribute[] getDatasetMapping() + { + return datasetMapping; + } + + public void setDatasetMapping(MappingAttribute[] datasetMapping) + { + this.datasetMapping = datasetMapping; + } + + public void setItemType(String itemType) + { + this.itemType = itemType; + } + + public String getItemType() + { + return itemType; + } + public void setExistedRefreshed(boolean existedRefreshed) + { + this.existedRefreshed = existedRefreshed; + } + public boolean isExistedRefreshed() + { + return existedRefreshed; + } +} diff --git a/src/com/connor/dev/imp/ob/StaticEnum.java b/src/com/connor/dev/imp/ob/StaticEnum.java new file mode 100644 index 0000000..4b223fc --- /dev/null +++ b/src/com/connor/dev/imp/ob/StaticEnum.java @@ -0,0 +1,7 @@ +package com.connor.dev.imp.ob; + +public class StaticEnum { + public static final String Connor_Create_Item_Operation = "Connor_Create_Item_Operation"; + public static boolean isExec = false; + +} diff --git a/src/com/connor/dev/imp/project/ImportProjectAction.java b/src/com/connor/dev/imp/project/ImportProjectAction.java new file mode 100644 index 0000000..3c7aa24 --- /dev/null +++ b/src/com/connor/dev/imp/project/ImportProjectAction.java @@ -0,0 +1,19 @@ +package com.connor.dev.imp.project; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.common.actions.AbstractAIFAction; + +public class ImportProjectAction extends AbstractAIFAction { + AbstractAIFApplication app; + public ImportProjectAction(AbstractAIFApplication arg0, String arg1) { + super(arg0, arg1); + app=arg0; + // TODO Auto-generated constructor stub + } + + public void run() { + // TODO Auto-generated method stub + new Thread(new ImportProjectDialog(app)).run(); + } + +} diff --git a/src/com/connor/dev/imp/project/ImportProjectDialog.java b/src/com/connor/dev/imp/project/ImportProjectDialog.java new file mode 100644 index 0000000..b228122 --- /dev/null +++ b/src/com/connor/dev/imp/project/ImportProjectDialog.java @@ -0,0 +1,415 @@ +package com.connor.dev.imp.project; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.filechooser.FileSystemView; + +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.kernel.TCClassificationService; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentProject; +import com.teamcenter.rac.kernel.TCComponentProjectType; +import com.teamcenter.rac.kernel.TCComponentUser; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.kernel.ics.ICSApplicationObject; +import com.teamcenter.rac.kernel.ics.ICSKeyLov; +import com.teamcenter.rac.kernel.ics.ICSKeyLovValue; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.kernel.ics.ICSPropertyDescription; +import com.teamcenter.rac.kernel.ics.ICSView; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; +import com.teamcenter.soaictstubs.icsadminattrSeqHolder; + +import jxl.CellType; + +public class ImportProjectDialog extends AbstractAIFDialog { + private JFileChooser fileChooser; + private File file; + private TCSession session; + private Integer[] integers; + private JLabel path; + private int succ=0; + private int errlen=0; + private String err=""; + private TCComponentForm form; + private JFileChooser jFileChooser; + private JTextField jt4 = new JTextField(20); + private JLabel jb4; + private JLabel jb; + private JButton pBut; + private JButton button1; + private List attribute; //Եʵֵ + public ImportProjectDialog(AbstractAIFApplication app) { + session = (TCSession) app.getSession(); + } + + public void run() { + //MessageBox.post("","",0); + //return; + initUI(); + } + + private void initUI() { + setLayout(new PropertyLayout()); + + + button1 = new JButton(""); + JButton celBut=new JButton("ȡ"); + FileSystemView fsv = FileSystemView.getFileSystemView(); // õϵͳfileview + String deskPath = fsv.getHomeDirectory().getPath(); // ǰû· + + setLayout(new PropertyLayout()); + jb=new JLabel(" "); + jb4 = new JLabel(" ļ·"); + jt4.setText(deskPath); + pBut = new JButton("ѡļ"); + jFileChooser = new JFileChooser(); + this.jFileChooser.setCurrentDirectory(new File(deskPath));// ļѡijʼĿ¼Ϊǰû + add("1.1.left.top", jb); + add("2.1.left.top", jb4); + add("2.2.left.top", jt4); + add("2.3.left.top", pBut); + add("3.1.left.top", new JLabel("")); + add("3.2.left.top", button1); + add("3.3.left.top", celBut); + + setSize(300, 300); + setVisible(true); + pBut.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + selectFileButtonEvent(); + } + }); + path=new JLabel(""); + + button1.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + jb.setText("ڵ..."); + button1.setEnabled(false); + export(); + disposeDialog(); + } + }); + celBut.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + disposeDialog(); + } + }); + + centerToScreen(); + pack(); + showDialog(); + } + + public void selectFileButtonEvent() { + int state = jFileChooser.showOpenDialog(null);// ˾ǴļѡĴ + if (state == 1) { + return; + } else { + file = jFileChooser.getSelectedFile();// fΪѡ񵽵ļĿ¼ + jt4.setText(file.getAbsolutePath()); + } + } + + private void export() { + List> data = readFile(); + TCUserService service = session.getUserService(); +// try { +// service.call("bypass", new Object[] { true }); + if(data!=null){ + for (int i = 0; i < data.size(); i++) { + + TCComponentUser user =null; + TCComponentUser admin=(TCComponentUser) getUser("admin"); + TCComponentProject pro=null; + try { + if(data.get(i).get(2)!=null&&!data.get(i).get(2).trim().equals("")){ + user=(TCComponentUser) getUser(data.get(i).get(2)); + } + if(user==null){ + pro=createProject(data.get(i).get(0),data.get(i).get(1), "",admin); + }else{ + pro=createProject(data.get(i).get(0),data.get(i).get(1), "",user); + } + if(attribute!=null&&attribute.size()>0){ + for(int j=0;j0&&errlen==0){ + MessageBox.post("Ŀɹ,"+succ+"","ɹ",MessageBox.INFORMATION); + }else{ + MessageBox.post("Ŀ:ɹ"+succ+"\nʧ"+errlen+"\n"+err,"",MessageBox.ERROR); + } + + } +// + private List> readFile() { + List> result = new ArrayList>(); + attribute=new ArrayList(); + FileInputStream is; + try { + is = new FileInputStream(file); + XSSFWorkbook workbook = new XSSFWorkbook(is); + XSSFSheet sheet = workbook.getSheetAt(0); + int row = sheet.getPhysicalNumberOfRows(); + int col = 0; + if (row > 0) + col = sheet.getRow(0).getPhysicalNumberOfCells(); + + System.out.println("row:"+row+";col:" + col); + XSSFRow tempRow = sheet.getRow(0); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMDD"); + XSSFCell cell ; + for (int j = 3; j < col; j++) { + cell = tempRow.getCell(j); + + String string = ""; + if (cell != null) { + int type = cell.getCellType(); + if (type == 0) { + if (DateUtil.isCellDateFormatted(cell)) { + string = sdf.format(cell.getDateCellValue()); + + } else { + cell.setCellType(XSSFCell.CELL_TYPE_STRING); + string = cell.getStringCellValue(); + } + } else { + cell.setCellType(XSSFCell.CELL_TYPE_STRING); + string = cell.getStringCellValue(); + } + + } + try { + System.out.println("string="+string); + attribute.add(string.split("\\/")[1]); + + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + errlen++; + err=err+"ʧܣģô鿴Ƿȷ"; + return null; + } + } + + + for (int i = 1; i < row; i++) { + List temp = new ArrayList(); + tempRow = sheet.getRow(i); + cell=tempRow.getCell(0); + if(cell==null||cell.toString().trim().length()==0) + break; + if (tempRow != null) + for (int j = 0; j < col; j++) { + cell = tempRow.getCell(j); + + String string = ""; + if (cell != null) { + int type = cell.getCellType(); + if (type == 0) { + if (DateUtil.isCellDateFormatted(cell)) { + string = sdf.format(cell.getDateCellValue()); + + } else { + cell.setCellType(XSSFCell.CELL_TYPE_STRING); + string = cell.getStringCellValue(); + } + } else { + cell.setCellType(XSSFCell.CELL_TYPE_STRING); + string = cell.getStringCellValue(); + } + + } + + temp.add(string); + } + result.add(temp); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + MessageBox.post(":"+e.getMessage(),"",2); + } + + return result; + } + + private TCComponent getUser(String User) { + TCComponent[] users = null; + try { + users = session.search(" - ԱϢ", new String[] { "Ա" }, new String[] { User }); + System.out.println("length:" + users.length); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + MessageBox.post(":"+e.getMessage(),"",2); + } + if (users.length > 0) + return users[0]; + return null; + } + + + private TCComponentProject createProject(String id, String name, String desc,TCComponentUser user){ + TCComponentProjectType projecttype; + TCComponentProject proj=null; + try { + projecttype = (TCComponentProjectType) session + .getTypeComponent("TC_Project"); + + + System.out.println("id="+id); + System.out.println("name="+name); + System.out.println("desc="+desc); + System.out.println("user="+user); + + proj = projecttype.create(id, name, desc, + new TCComponent[] {user}, user, new TCComponentUser[] {user}); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + errlen++; + err=err+"id:"+id+" ԭ:"+e.getMessage()+"\n"; + + } + if(proj!=null){ + succ++; + } + return proj; + + } + + + private void setTCProperty(TCProperty property, String value) throws TCException { + System.out.println("setTCProperty(TCProperty property =" + property.getPropertyName() + ", String value=" + + value + ") - start"); + // if (value == null || value.length() == 0) { + // System.out.println("setTCProperty(TCProperty property, String value) + // - end"); + // return; + // } + if (value == null || value.trim().length() == 0) + return; + TCPropertyDescriptor descriptor = property.getPropertyDescriptor(); + boolean isArray = descriptor.isArray(); + TCComponentListOfValues lov=property.getLOV(); + if(lov!=null){//жǷlov + String[] strs=lov.getListOfValues().getStringListOfValues();//ʵֵ + for(String s1:strs){ + String a1 = lov.getListOfValues().getDisplayableValue(s1);//ʵֵӦʾֵ + if(a1.equals(value)){ + System.out.println(); + value=s1; //ʾֵΪʵֵ + break; + } + } + } + if (!isArray) { + + switch (descriptor.getType()) { + + case TCProperty.PROP_string: + case TCProperty.PROP_long_string: + System.out.println("ӦΪַ"); + property.setStringValue(value); + break; + case TCProperty.PROP_char: + System.out.println("ӦΪַ"); + if (value.length() > 0) { + property.setCharValue(value.charAt(0)); + } + break; + case TCProperty.PROP_double: + System.out.println("ӦΪdouble"); + if (value == null || value.trim().length() == 0) + property.setDoubleValue((Integer) null); + else + property.setDoubleValue(Double.parseDouble(value)); + break; + case TCProperty.PROP_float: + System.out.println("ӦΪfloat"); + if (value == null || value.trim().length() == 0) + property.setFloatValue((Integer) null); + else + property.setFloatValue(Float.parseFloat(value)); + break; + case TCProperty.PROP_int: + case TCProperty.PROP_short: + System.out.println("ӦΪintshort"); + if (value == null || value.trim().length() == 0) + property.setIntValue((Integer) null); + else + property.setIntValueData(Integer.parseInt(value)); + break; + case TCProperty.PROP_logical: + System.out.println("ӦΪBoolean"); + property.setLogicalValueData(Boolean.parseBoolean(value)); + break; + case TCProperty.PROP_date: + System.out.println("ӦΪ"); + try { + property.setDateValue(new SimpleDateFormat().parse(value)); + } catch (ParseException e) { + //logger.error("setTCProperty(TCProperty property, String value)", e); + + e.printStackTrace(); + } + break; + } + } else { + System.out.println("ӦΪͣԴ"); + } + + System.out.println("setTCProperty(TCProperty property, String value) - end"); + } +} diff --git a/src/com/connor/dev/imp/re/ImportRelationsCommand.java b/src/com/connor/dev/imp/re/ImportRelationsCommand.java new file mode 100644 index 0000000..8eed88c --- /dev/null +++ b/src/com/connor/dev/imp/re/ImportRelationsCommand.java @@ -0,0 +1,19 @@ +package com.connor.dev.imp.re; + + +import com.connor.dev.imp.AbstractImportCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; + +public class ImportRelationsCommand extends AbstractImportCommand +{ + public ImportRelationsCommand(AbstractAIFUIApplication application) + { + super(application); + } + + protected void importHistoryDatas() + { + ImportRelationsDialog dialog = new ImportRelationsDialog(session, "ϵ"); + setRunnable(dialog); + } +} diff --git a/src/com/connor/dev/imp/re/ImportRelationsDialog.java b/src/com/connor/dev/imp/re/ImportRelationsDialog.java new file mode 100644 index 0000000..c369f64 --- /dev/null +++ b/src/com/connor/dev/imp/re/ImportRelationsDialog.java @@ -0,0 +1,419 @@ +package com.connor.dev.imp.re; + +import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.DefaultListModel; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.event.ChangeEvent; + +import com.connor.dev.imp.AbstractImportDialog; +import com.connor.dev.imp.ImportSettings; +import com.connor.dev.imp.MappingAttribute; +import com.connor.dev.imp.ob.MappingButton; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentItemRevisionType; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class ImportRelationsDialog extends AbstractImportDialog { + private static final long serialVersionUID = 1L; + + private JComboBox relationBox; + + // private JComboBox currentItemBox; + + // private JComboBox relativeItemBox; + + private MappingButton current; + + private MappingButton relative; + + private MappingButton property; + // private String propertyButtonName = ""; + + private MappingButton currentRevision; + + private MappingButton relativeRevision; + + private MappingButton selectedButton; + + public ImportRelationsDialog(TCSession session, String title) { + super(session, title, true); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#addTabbedPaneComponents() + */ + protected void addTabbedPaneComponents() { + rightPane.addTab("", getParameterPanel()); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#openImportSettings() + */ + protected void openImportSettings() { + if (chooser.showOpenDialog(null) == 0) { + RelationsImportSettings ris = new RelationsImportSettings(); + ImportSettings is = ris.load(chooser.getSelectedFile()); + + if (is == null) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ļмʧ.", "", 1); + return; + } + + if (is instanceof RelationsImportSettings) { + ris = (RelationsImportSettings) is; + current.setMappingAttribute(ris.getCurrentItemID()); + currentRevision.setMappingAttribute(ris + .getCurrentItemRevision()); + property.setMappingAttribute(ris.getProperty()); + relative.setMappingAttribute(ris.getRelativeItemID()); + relativeRevision.setMappingAttribute(ris + .getRelativeItemRevision()); + + relationBox.setSelectedItem(ris.getRelation()); + // currentItemBox.setSelectedItem(ris.getCurrentItem()); + // relativeItemBox.setSelectedItem(ris.getRelativeItem()); + // arraySepField.setText(ris.getArraySeparator()); + + excelList.setEnabled(false); + + current.setEnabled(false); + currentRevision.setEnabled(false); + property.setEnabled(false); + relative.setEnabled(false); + relativeRevision.setEnabled(false); + } + } + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#saveImportSettings() + */ + protected void saveImportSettings() { + RelationsImportSettings ris = generateImportSettings(); + if (chooser.showSaveDialog(null) == 0) { + if (ris.save(chooser.getSelectedFile())) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "Ѿɹ\n" + + chooser.getSelectedFile().getAbsolutePath(), + "ɹ", 2); + } else { + + } + } + } + + /* + * (non-Javadoc) + * + * @see + * javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent + * ) + */ + public void stateChanged(ChangeEvent ce) { + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#initializeUI() + */ + protected void initializeUI() { + super.initializeUI(); + propertiesList = new JList[0]; + propertiesListModels = new DefaultListModel[0]; + mappingListModels = new DefaultListModel[0]; + mappingList = new JList[0]; + + relationBox = new JComboBox(); + + // currentItemBox = new JComboBox(); + + // relativeItemBox = new JComboBox(); + + current = new MappingButton("Current Item ID"); + + relative = new MappingButton("Relative Item ID"); + + property = new MappingButton("Property Name"); + + currentRevision = new MappingButton("Current Item Revision ID"); + + relativeRevision = new MappingButton("Relative Item Revision ID"); + + // arraySepField.setText("||"); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#registerActionComponents() + */ + protected void registerActionComponents() { + super.registerActionComponents(); + + current.addActionListener(this); + relative.addActionListener(this); + property.addActionListener(this); + currentRevision.addActionListener(this); + relativeRevision.addActionListener(this); + + // currentItemBox.addItemListener(this); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#setComponentsTextProperty() + */ + protected void setComponentsTextProperty() { + super.setComponentsTextProperty(); + + // populateTypeChoices("Item", currentItemBox); + // populateTypeChoices("MEOP", currentItemBox); + // populateTypeChoices("MENCMachining", currentItemBox); + // currentItemBox.setSelectedItem("Item"); + // populateTypeChoices("Item", relativeItemBox); + + try { + List propList = new ArrayList(); + String[] items = { "Item", "Design", "Document" }; + for (String itemStr : items) { + TCComponentItemType tit = (TCComponentItemType) session + .getTypeComponent(itemStr); + TCPropertyDescriptor[] descriptors = tit.getPasteRelations(); + System.out.println("descriptors.length()===" + + descriptors.length); + for (int i = 0; i < descriptors.length; i++) { + TCPropertyDescriptor descriptor = descriptors[i]; + // propList.add(descriptor.getDisplayName().trim()); + propList.add(descriptor.getName().trim()); + } + + } + items = new String[] { "ItemRevision" }; + for (String itemStr : items) { + TCComponentItemRevisionType revRelation = (TCComponentItemRevisionType) session + .getTypeComponent(itemStr); + TCComponentType[] reltations2 = revRelation.getRelationTypes(); + for (int i = 0; i < reltations2.length; i++) { + TCComponentType reltation = reltations2[i]; + if (!propList.contains(reltation.getTypeName().trim())) { + propList.add(reltation.getTypeName()); + } + } + } + + List list=new ArrayList(); + String[] reltype = session.getPreferenceService().getStringValues("Connor_Import_Rel_Type"); + if (reltype != null) { + for (int i = 0; i < reltype.length; i++) { + list.add(reltype[i]); + } + } + + for (String itemStr : list) { + System.out.println("itemStr="+itemStr); + TCComponentType revRelation = session.getTypeComponent(itemStr); + if (revRelation==null) { + System.out.println("δҵ:"+itemStr); + }else { + TCComponentType[] reltations2 = revRelation.getRelationTypes(); + for (int i = 0; i < reltations2.length; i++) { + TCComponentType reltation = reltations2[i]; + if (!propList.contains(reltation.getTypeName().trim())) { + propList.add(reltation.getTypeName()); + } + } + } + + } + + Collections.sort(propList); + for (int m = 0; m < propList.size(); m++) { + relationBox.addItem(propList.get(m)); + } + relationBox.setEditable(true); + + relationBox.insertItemAt("", 0); + relationBox.setSelectedIndex(0); + } catch (TCException e) { + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see + * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent ae) { + if (ae.getSource() instanceof MappingButton) { + assignMappingAttribute((MappingButton) ae.getSource()); + } else if (ae.getSource() == unlock) { + current.setEnabled(true); + relative.setEnabled(true); + property.setEnabled(true); + currentRevision.setEnabled(true); + relativeRevision.setEnabled(true); + super.actionPerformed(ae); + } else { + super.actionPerformed(ae); + if (ae.getSource() == add) { + + if (selectedButton != null) { + System.out.println("selectedButton.getLabel()===" + + selectedButton.getText()); + selectedButton.setMappingAttribute(null); + } + } else { + if (ae.getSource() == remove) { + + relationBox.setSelectedIndex(0); + current.setMappingAttribute(null); + relative.setMappingAttribute(null); + property.setMappingAttribute(null); + currentRevision.setMappingAttribute(null); + relativeRevision.setMappingAttribute(null); + } + } + } + } + + private void assignMappingAttribute(MappingButton button) { + if (excelList.getSelectedIndex() == -1) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ѡӦһָϵ", "", 1); + return; + } + + String excel = excelList.getSelectedValue().toString(); + int index = excelList.getSelectedIndex(); + + MappingAttribute ma = new MappingAttribute(index, excel, + button.getPropertyName()); + button.setMappingAttribute(ma); + selectedButton = button; + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#generateImportSettings() + */ + public RelationsImportSettings generateImportSettings() { + RelationsImportSettings ris = new RelationsImportSettings(); + + ris.setRelation(relationBox.getSelectedItem().toString().trim()); + // ris.setCurrentItem(currentItemBox.getSelectedItem().toString().trim()); + // ris.setRelativeItem(relativeItemBox.getSelectedItem().toString().trim()); + ris.setCurrentItemID(current.getMappingAttribute()); + ris.setCurrentItemRevision(currentRevision.getMappingAttribute()); + + ris.setRelativeItemID(relative.getMappingAttribute()); + + ris.setProperty(property.getMappingAttribute()); + + ris.setRelativeItemRevision(relativeRevision.getMappingAttribute()); + + ris.setColumns(excelList.getModel().getSize()); + + // ris.setArraySeparator(arraySepField.getText().trim()); + ris.setDateFormat(dateFormatField.getText().trim()); + + return ris; + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#getParameterPanel() + */ + protected JPanel getParameterPanel() { + JPanel p = super.getParameterPanel(); + + // p.add("3.1.right.top.preferred.preferred", new JLabel("ǰ :")); + // p.add("3.2.left.top.preferred.preferred", currentItemBox); + p.add("2.1.right.top.preferred.preferred", new JLabel("ID :")); + p.add("2.2.left.top.preferred.preferred", current); + p.add("3.1.right.top.preferred.preferred", new JLabel("汾 :")); + p.add("3.2.left.top.preferred.preferred", currentRevision); + + p.add("4.1.right.top.preferred.preferred", new JLabel("ϵ:")); + p.add("4.2.left.top.preferred.preferred", relationBox); + + // p.add("5.1.right.top.preferred.preferred", new JLabel(" ")); + // p.add("5.2.left.top.preferred.preferred", new JLabel(" ")); + + p.add("5.1.right.top.preferred.preferred", new JLabel(":")); + p.add("5.2.left.top.preferred.preferred", property); + + // p.add("6.1.right.top.preferred.preferred", new JLabel("Ŀ :")); + // p.add("6.2.left.top.preferred.preferred", relativeItemBox); + p.add("6.1.right.top.preferred.preferred", new JLabel("Ҷ :")); + p.add("6.2.left.top.preferred.preferred", relative); + + p.add("7.1.right.top.preferred.preferred", new JLabel("Ҷ汾 :")); + p.add("7.2.left.top.preferred.preferred", relativeRevision); + + return p; + } + + /* + * (non-Javadoc) + * + * @see + * java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) + */ + public void itemStateChanged(ItemEvent ie) { + doPurgeComponentProperties(relationBox.getSelectedItem().toString()); + } + + /* + * (non-Javadoc) + * + * @see cn.com.origin.imp.AbstractImportDialog#checkNecessaryCondition() + */ + protected boolean checkNecessaryCondition() { + System.out.println("property.getLabel()===" + property.getText()); + System.out.println("relationBox.getSelectedIndex()===" + + relationBox.getSelectedIndex()); + + if ((property.getText().indexOf("=") > 0) + && (relationBox.getSelectedIndex() != 0)) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ͬʱָϵ", "", 1); + return false; + } else { + if ((relationBox.getSelectedIndex() == 0) + && (property.getText().indexOf("=") == -1)) { + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), + "ѡҪĹϵ", "", 1); + return false; + } + } + return super.checkNecessaryCondition(); + } +} diff --git a/src/com/connor/dev/imp/re/RelationsImportSettings.java b/src/com/connor/dev/imp/re/RelationsImportSettings.java new file mode 100644 index 0000000..a25b302 --- /dev/null +++ b/src/com/connor/dev/imp/re/RelationsImportSettings.java @@ -0,0 +1,111 @@ +package com.connor.dev.imp.re; + +import java.io.Serializable; + +import com.connor.dev.imp.ImportSettings; +import com.connor.dev.imp.MappingAttribute; + +public class RelationsImportSettings extends ImportSettings implements Serializable +{ + private static final long serialVersionUID = 1L; + + private String relation; + + //private String currentItem; + + private MappingAttribute currentItemID; + + private MappingAttribute currentItemRevision; + + //private String relativeItem; + + private MappingAttribute relativeItemID; + + private MappingAttribute relativeItemRevision; + + private MappingAttribute property; + + public String getRelation() + { + return relation; + } + + public void setRelation(String relation) + { + this.relation = relation; + } + + // public String getCurrentItem() + // { + // return currentItem; + // } + // + // public void setCurrentItem(String currentItem) + // { + // this.currentItem = currentItem; + // } + + public MappingAttribute getCurrentItemID() + { + return currentItemID; + } + + public void setCurrentItemID(MappingAttribute currentItemID) + { + this.currentItemID = currentItemID; + } + + public MappingAttribute getCurrentItemRevision() + { + return currentItemRevision; + } + + public void setCurrentItemRevision(MappingAttribute currentItemRevision) + { + this.currentItemRevision = currentItemRevision; + } + + // public String getRelativeItem() + // { + // return relativeItem; + // } + // + // public void setRelativeItem(String relativeItem) + // { + // this.relativeItem = relativeItem; + // } + + public MappingAttribute getRelativeItemID() + { + return relativeItemID; + } + + public void setRelativeItemID(MappingAttribute relativeItemID) + { + this.relativeItemID = relativeItemID; + } + + public MappingAttribute getRelativeItemRevision() + { + return relativeItemRevision; + } + + public void setRelativeItemRevision(MappingAttribute relativeItemRevision) + { + this.relativeItemRevision = relativeItemRevision; + } + + /** + * @return the property + */ + public MappingAttribute getProperty() { + return property; + } + + /** + * @param property the property to set + */ + public void setProperty(MappingAttribute property) { + this.property = property; + } +} diff --git a/src/com/connor/dev/imp/solution/handler/ImportBOMsForProEHandler.java b/src/com/connor/dev/imp/solution/handler/ImportBOMsForProEHandler.java new file mode 100644 index 0000000..b5d32b6 --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportBOMsForProEHandler.java @@ -0,0 +1,33 @@ +package com.connor.dev.imp.solution.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.dev.imp.bom.ImportBomsCommand; +import com.connor.dev.imp.bom.ImportBomsForProECommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.util.MessageBox; + +public class ImportBOMsForProEHandler extends AbstractHandler { + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + + AbstractAIFUIApplication application = AIFUtility.getCurrentApplication(); + try + { + + ImportBomsForProECommand command = new ImportBomsForProECommand(application); + command.executeModal(); + } + catch (Exception exception) + { + MessageBox.post(exception, true); + } + + return null; + } + +} diff --git a/src/com/connor/dev/imp/solution/handler/ImportBOMsHandler.java b/src/com/connor/dev/imp/solution/handler/ImportBOMsHandler.java new file mode 100644 index 0000000..1b9411d --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportBOMsHandler.java @@ -0,0 +1,35 @@ +package com.connor.dev.imp.solution.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.dev.imp.bom.ImportBomsCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.util.MessageBox; + +public class ImportBOMsHandler extends AbstractHandler +{ + /* + * (non-Javadoc) + * + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent arg0) throws ExecutionException + { + AbstractAIFUIApplication application = AIFUtility.getCurrentApplication(); + try + { + + ImportBomsCommand command = new ImportBomsCommand(application); + command.executeModal(); + } + catch (Exception exception) + { + MessageBox.post(exception, true); + } + + return null; + } +} diff --git a/src/com/connor/dev/imp/solution/handler/ImportClassificationAction.java b/src/com/connor/dev/imp/solution/handler/ImportClassificationAction.java new file mode 100644 index 0000000..b6ba043 --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportClassificationAction.java @@ -0,0 +1,19 @@ +package com.connor.dev.imp.solution.handler; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.common.actions.AbstractAIFAction; + +public class ImportClassificationAction extends AbstractAIFAction { + AbstractAIFApplication app; + public ImportClassificationAction(AbstractAIFApplication arg0, String arg1) { + super(arg0, arg1); + app=arg0; + // TODO Auto-generated constructor stub + } + + public void run() { + // TODO Auto-generated method stub + new Thread(new ImportClassificationDialog(app)).run(); + } + +} diff --git a/src/com/connor/dev/imp/solution/handler/ImportClassificationDialog.java b/src/com/connor/dev/imp/solution/handler/ImportClassificationDialog.java new file mode 100644 index 0000000..2bbfa00 --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportClassificationDialog.java @@ -0,0 +1,406 @@ +package com.connor.dev.imp.solution.handler; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.filechooser.FileSystemView; + +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.kernel.TCClassificationService; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.kernel.ics.ICSAdminClass; +import com.teamcenter.rac.kernel.ics.ICSAdminClassAttribute; +import com.teamcenter.rac.kernel.ics.ICSApplicationObject; +import com.teamcenter.rac.kernel.ics.ICSKeyLov; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; + +public class ImportClassificationDialog extends AbstractAIFDialog { + private JFileChooser fileChooser; + private File file; + private TCSession session; + private Integer[] integers; + private String logpath; + private int succlen; + private int errlen; + private String err; + private String systitem = ""; + private JLabel jlb; + + + public ImportClassificationDialog(AbstractAIFApplication app) { + session = (TCSession) app.getSession(); + } + + public void run() { + initUI(); + } + + private void initUI() { + setLayout(new PropertyLayout()); + jlb=new JLabel(" "); + fileChooser = new JFileChooser(FileSystemView.getFileSystemView() + .getHomeDirectory()); + JButton button1 = new JButton("ѡļ"); + JButton button2 = new JButton(""); + button1.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int state = fileChooser.showOpenDialog(null); + if (state != 1) { + + file = fileChooser.getSelectedFile(); + } + } + }); + button2.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + jlb.setText("ڵ...."); + export(); + disposeDialog(); + } + }); + add("1.1.left.top", jlb); + add("2.1.left.top", button1); + add("2.2.left.top", button2); + setSize(300, 300); + centerToScreen(); + pack(); + showDialog(); + } + + /* + * + * @ class_id(String) id + * @ target(TCComponent) ҪĶ + * @ partid(String) id + * @ integers(Integer[]) ԣlovid飩 + * @ vals(String[]) ԣlovval飩 + */ + public void createICS(String class_id, TCComponent target, String partid, + Integer[] integers, String[] vals) throws Exception { + + TCClassificationService myService = session.getClassificationService(); + + ICSApplicationObject icsAppObj = myService + .newICSApplicationObject("ICM"); + icsAppObj.setView(class_id); + icsAppObj.create(partid, target.getUid()); + + ICSAdminClass c = myService.newICSAdminClass(); + c.load(class_id); + ICSProperty icspro[] = new ICSProperty[integers.length]; + + for (int i = 0; i < icspro.length; i++) { + System.out.println("getKeyǰvals[i]="+vals[i]); + String va = getKeylov2(c,integers[i], vals[i]);//˴integers[i]һid + //String va = getKeylov(integers[i], vals[i]); + System.out.println(" CLASS ID = " + integers[i] + " =" + va); + //vaһlovбʵֵAҲlovбһʾֵ29 + + icspro[i] = new ICSProperty(integers[i], va); + } + //TODO ǰҪɾеķϢ + + icsAppObj.setProperties(icspro); + icsAppObj.save(); + System.out.println("save:" + target); + } + + private void export() { + systitem = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()); + System.out.println("ʼȡļ"); + List> data = readFile();//һݲ + System.out.println("ļȡɣȡļ"+data.size()); + TCUserService service = session.getUserService(); + + for (int i = 0; i < data.size(); i++) { + int a=i+1; + setLayout(new PropertyLayout()); + jlb.setText("У"+a+"/"+data.size()+"Ϣ"); + +//1.ݱеitem_idͰ汾idȷһTCComponent + System.out.println("id="+data.get(i).get(1)+"-----汾="+data.get(i).get(2)); + TCComponent item = getItem(data.get(i).get(1), data.get(i).get(2)); + System.out.println("item:" + item); + + String[] vals = new String[integers.length]; + int size = data.get(i).size() < (integers.length + 3) ? data.get(i) + .size() : (integers.length + 3); + for (int j = 3; j < size; j++) + vals[j - 3] = data.get(i).get(j);//Ժα浽vals + if (item != null) { + try { + //ǰ汾µķϢ + clearICSofItem(item); + //IDȡTCComponentitem_idԣlovid飩ԣlovval飩 + createICS(data.get(i).get(0), item, data.get(i).get(1), + integers, vals);//integers, valsǵпʼ + succlen++; + } catch (Exception e) { + // TODO Auto-generated catch block + try { + + StringBufferDemo(":"+a+"ʧ"+e.getMessage()+"\r\n","PLM"); + errlen++; + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + errlen++; + + e.printStackTrace(); + } + }else{ + try { + StringBufferDemo(":"+a+"ʧ,Ҫ󲻴\r\n","PLM"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + errlen++; + } + + } + if(errlen==0){ + MessageBox.post("ɹ"+succlen+"", "", 2); + }else{ + MessageBox.post("ɹ"+succlen+" \nʧ"+errlen+" \n ־·:"+logpath, "",MessageBox.ERROR); + } + + } + + /* + * 汾µķϢ + */ + private void clearICSofItem(TCComponent rev) throws TCException { + TCComponentICO[] icos = rev.getClassificationObjects(); + System.out.println("汾з="+icos.length); +// for (TCComponentICO ico : icos) { +// ico.delete(); +// } + if (icos.length>0) { + icos[0].delete(); + } + } + + + private List> readFile() { + List> result = new ArrayList>(); + FileInputStream is; + try { + is = new FileInputStream(file); + XSSFWorkbook workbook = new XSSFWorkbook(is); + XSSFSheet sheet = workbook.getSheetAt(0); + int row = sheet.getLastRowNum()+1; + System.out.println("row="+row); + int col = 0; + if (row > 1){ + col = sheet.getRow(1).getPhysicalNumberOfCells(); + } + if (col > 4) + integers = new Integer[col - 4]; + else + integers = new Integer[0]; + System.out.println("col:" + col); + XSSFRow tempRow = sheet.getRow(1); + for (int i = 4; i < col; i++) { + XSSFCell cell = tempRow.getCell(i); + cell.setCellType(XSSFCell.CELL_TYPE_STRING); + String string = cell.getStringCellValue(); + System.out.println("string:" + + string.substring(string.indexOf('/') + 1)); + integers[i - 4] = Integer.parseInt(string.substring(string + .indexOf('/') + 1)); + + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMDD"); + XSSFCell cell; + for (int i = 2; i < row; i++) { + List temp = new ArrayList(); + tempRow = sheet.getRow(i); + cell = tempRow.getCell(0); + if (cell == null || cell.toString().trim().length() == 0) + break; + if (tempRow != null) + for (int j = 1; j < col; j++) { + cell = tempRow.getCell(j); + + String string = ""; + if (cell != null) { + int type = cell.getCellType(); + if (type == 0) { + if (DateUtil.isCellDateFormatted(cell)) { + string = sdf + .format(cell.getDateCellValue()); + + } else { + cell.setCellType(XSSFCell.CELL_TYPE_STRING); + string = cell.getStringCellValue(); + } + } else { + cell.setCellType(XSSFCell.CELL_TYPE_STRING); + string = cell.getStringCellValue(); + } + + } + + temp.add(string); + } + result.add(temp); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + MessageBox.post("쳣,ģ:"+e.getMessage(),"",0); + } + + return result; + } + + private TCComponent getItem(String id, String reviosion) { + TCComponent[] result = null; + try { + result = session.search("汾...", + new String[] { " ID", "汾" }, new String[] { id, + reviosion }); + System.out.println("length:" + result.length); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (result.length > 0) + return result[0]; + return null; + } + + // lovidvalöӦkay + private String getKeylov(int id, String val) { + // TODO Auto-generated method stub + + ICSKeyLov lov = ICSKeyLov.getICSKeyLov(-id); + String s = val; + System.out.println("val=" + s); + if (lov != null) { + try { + String[] keys = lov.getKeys(); + if(keys!=null&&keys.length>0){ + for(String key:keys){ + System.out.println("key111:"+key); + System.out.println("val111:"+lov.getValueOfKey(key)); + if(key!=null&&!key.equals("")&&!key.equals(" ")&&val.equals(lov.getValueOfKey(key))){ + s = key; + System.out.println("keylov=" + s); + break; + } + } + }else{ + System.out.println("δҵlovʹʵֵ"); + } + + + + } catch (Exception e) { + // TODO Auto-generated catch block + try { + StringBufferDemo(":"+e.getMessage()+"\r\n","PLM"); + errlen++; + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("****" + e.getMessage()); + + } + } + return s; + } + + + // lovidvalöӦkey + private String getKeylov2(ICSAdminClass c, int id, String val) { + // TODO Auto-generated method stub + String keyvalue = val; + try { + ICSAdminClassAttribute attribute = c.getAttribute(id); + if (attribute != null) { + HashMap lovMapping = new HashMap(); + List keyList = new ArrayList(); + boolean isLov = false; + ICSKeyLov lov1 = attribute.getFormat1().getKeyLov();//idȡlov + lov1 = (lov1 == null ? attribute.getFormat2().getKeyLov() : lov1); + if (lov1 != null) {//ǰlov + isLov = true; + String[] keys = lov1.getKeys(); + for (String key : keys) { + String value = lov1.getValueOfKey(key);//ȡԵlovֵ + if (value.equals(val)) { + keyvalue = key; + } + lovMapping.put(value, key); + keyList.add(value); + } + } else { + isLov = false; + } + if (isLov) { + + System.out.println("ǰlov"); + }else { + System.out.println("ǰͨstringͣlov"); + } + + + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return keyvalue; + } + + + // д־ + public void StringBufferDemo(String strContext, String strFileName) throws IOException { + // logpath = System.getProperty("java.io.tmpdir")+File.separator+ + // strFileName; + + logpath = System.getenv("TEMP") + "\\" + strFileName + "_" + systitem + ".log"; + File file = new File(logpath); + if (!file.exists()) + file.createNewFile(); + FileOutputStream out = new FileOutputStream(file, true); + StringBuffer sb = new StringBuffer(strContext); + //System.out.println("־"+sb.toString()); + out.write(sb.toString().getBytes("gb2312")); + out.close(); + } +} diff --git a/src/com/connor/dev/imp/solution/handler/ImportClassificationHandler.java b/src/com/connor/dev/imp/solution/handler/ImportClassificationHandler.java new file mode 100644 index 0000000..2b48c51 --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportClassificationHandler.java @@ -0,0 +1,19 @@ +package com.connor.dev.imp.solution.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aifrcp.AIFUtility; + +public class ImportClassificationHandler extends AbstractHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + + new Thread(new ImportClassificationAction(AIFUtility.getCurrentApplication(), null)).run(); + return null; + } + + +} diff --git a/src/com/connor/dev/imp/solution/handler/ImportObjectsHandler.java b/src/com/connor/dev/imp/solution/handler/ImportObjectsHandler.java new file mode 100644 index 0000000..7d8d583 --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportObjectsHandler.java @@ -0,0 +1,34 @@ +package com.connor.dev.imp.solution.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.dev.imp.ob.ImportObjectsCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.util.MessageBox; + +public class ImportObjectsHandler extends AbstractHandler +{ + /* + * (non-Javadoc) + * + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent arg0) throws ExecutionException + { + AbstractAIFUIApplication application = AIFUtility.getCurrentApplication(); + try + { + ImportObjectsCommand command = new ImportObjectsCommand(application); + command.executeModal(); + } + catch (Exception exception) + { + MessageBox.post(exception, true); + } + + return null; + } +} diff --git a/src/com/connor/dev/imp/solution/handler/ImportProjectHandler.java b/src/com/connor/dev/imp/solution/handler/ImportProjectHandler.java new file mode 100644 index 0000000..fcee8a5 --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportProjectHandler.java @@ -0,0 +1,21 @@ +package com.connor.dev.imp.solution.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.dev.imp.project.ImportProjectAction; +import com.teamcenter.rac.aifrcp.AIFUtility; + +public class ImportProjectHandler extends AbstractHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + + new Thread(new ImportProjectAction(AIFUtility.getCurrentApplication(), null)).run(); + + return null; + } + + +} \ No newline at end of file diff --git a/src/com/connor/dev/imp/solution/handler/ImportRelationHandler.java b/src/com/connor/dev/imp/solution/handler/ImportRelationHandler.java new file mode 100644 index 0000000..3f407eb --- /dev/null +++ b/src/com/connor/dev/imp/solution/handler/ImportRelationHandler.java @@ -0,0 +1,34 @@ +package com.connor.dev.imp.solution.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.dev.imp.re.ImportRelationsCommand; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.util.MessageBox; + +public class ImportRelationHandler extends AbstractHandler +{ + /* + * (non-Javadoc) + * + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent arg0) throws ExecutionException + { + AbstractAIFUIApplication application = AIFUtility.getCurrentApplication(); + try + { + ImportRelationsCommand command = new ImportRelationsCommand(application); + command.executeModal(); + } + catch (Exception exception) + { + MessageBox.post(exception, true); + } + + return null; + } +} diff --git a/src/com/connor/dev/imp/toolkit/JXLExcelParser.java b/src/com/connor/dev/imp/toolkit/JXLExcelParser.java new file mode 100644 index 0000000..bc72596 --- /dev/null +++ b/src/com/connor/dev/imp/toolkit/JXLExcelParser.java @@ -0,0 +1,94 @@ +package com.connor.dev.imp.toolkit; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import jxl.Cell; +import jxl.Sheet; +import jxl.Workbook; +import jxl.WorkbookSettings; +import jxl.read.biff.BiffException; + +public class JXLExcelParser +{ + private Workbook workbook; + + private Sheet sheet; + + public int rows; + + public int startRow; + + private int columns; + + public JXLExcelParser(File input, int sheetIndex, int columns, int startRow) throws BiffException, IOException + { + this.startRow = startRow; + this.columns = columns; + + WorkbookSettings ws = new WorkbookSettings(); + ws.setEncoding("ISO-8859-1"); + workbook = Workbook.getWorkbook(input, ws); + sheet = workbook.getSheet(sheetIndex); + rows = sheet.getRows(); + + System.out.println("excelļһҪȡ" + rows + ""); + } + + public List parseLine() + { + List l = getLine(); + while (isEmpty(l)) + { + l = getLine(); + } + + return l; + } + + private boolean isEmpty(List l) + { + if (l == null) + { + return false; + } + + for (String string : l) + { + if (!string.trim().equals("")) + { + return false; + } + } + + return true; + } + + public List getLine() + { + if (startRow > rows - 1) + { + workbook.close(); + return null; + } + + List line = new ArrayList(); + + Cell[] cells = sheet.getRow(startRow++); + + int cos = Math.min(columns, cells.length); + for (int j = 0; j < cos; j++) + { + line.add(cells[j].getContents().trim()); + } + + for (int j = 0; j < columns - cos + 1; j++) + { + line.add(""); + } + + return line; + } +} diff --git a/src/com/connor/dev/imp/toolkit/Logger.java b/src/com/connor/dev/imp/toolkit/Logger.java new file mode 100644 index 0000000..8534853 --- /dev/null +++ b/src/com/connor/dev/imp/toolkit/Logger.java @@ -0,0 +1,24 @@ +package com.connor.dev.imp.toolkit; + +public class Logger +{ + public void debug(String message) + { + System.out.println("debug" + message); + } + + public void error(String message) + { + System.out.println("error" + message); + } + + public void info(String message) + { + System.out.println("info" + message); + } + + public void warn(String message) + { + System.out.println("warn" + message); + } +} diff --git a/src/com/connor/dev/imp/toolkit/POIExcelParser.java b/src/com/connor/dev/imp/toolkit/POIExcelParser.java new file mode 100644 index 0000000..38d1c88 --- /dev/null +++ b/src/com/connor/dev/imp/toolkit/POIExcelParser.java @@ -0,0 +1,325 @@ +package com.connor.dev.imp.toolkit; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +/** */ +/** + *
    + *
  • Title:[POIϵExcelݶȡ]
  • + *
  • Description: [֧Excell2003,Excell2007,Զʽֵ,Զʽ]
  • + *
  • Copyright 2010 RoadWay Co., Ltd.
  • + *
  • All right reserved.
  • + *
  • Created by [] [Dec 5, 2010]
  • + *
  • Midified by [modifier] [modified time]
  • + * + *
  • Jarб
  • + *
  • poi-3.7-20101029.jar
  • + *
  • poi-examples-3.7-20101029.jar
  • + *
  • poi-ooxml-3.7-2010102.jar
  • + *
  • poi-ooxml-schemas-3.7-2010102.jar
  • + *
  • xmlbeans-2.3.0.jar
  • + *
      + * + * @version 1.0 + */ +public class POIExcelParser { + private Workbook workbook; + + private Sheet sheet; + + public int rows; + + public int startRow; + + private int columns; + + public POIExcelParser(File input, int sheetIndex, int columns, int startRow) + throws FileNotFoundException, IOException { + this.startRow = startRow; + this.columns = columns; + + workbook = new XSSFWorkbook(new FileInputStream(input)); + sheet = workbook.getSheetAt(sheetIndex); + rows = sheet.getPhysicalNumberOfRows(); + + System.out.println("excelļһҪȡ" + rows + ""); + } + + public List parseLine() { + List l = getLine(); + while (isEmpty(l)) { + l = getLine(); + } + + return l; + } + + private boolean isEmpty(List l) { + if (l == null) { + return false; + } + + for (String string : l) { + if (!string.trim().equals("")) { + return false; + } + } + + return true; + } + + public List getLine() { + if (startRow > rows - 1) { + return null; + } + + List line = new ArrayList(); + // FormulaEvaluator + // FormulaEvaluator evaluator = + Row rows = sheet.getRow(startRow++); + if (rows != null) { + // int cos = Math.min(columns, rows.getPhysicalNumberOfCells()); + int cos = sheet.getRow(0).getPhysicalNumberOfCells(); + for (int j = 0; j < cos; j++) { + Cell cell = rows.getCell(j); + String cellValue = ""; + if (cell != null) { + /** */ + /** ͵,Զȥ */ +// if(Cell.CELL_TYPE_NUMERIC == cell.getCellType()){ +// cell.setCellType(Cell.CELL_TYPE_STRING);//ֵתַ +// } + + if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { + /** */ + /** excel,Ҳ,ڴҪж */ + if (DateUtil.isCellDateFormatted(cell)) { + Date dateval = cell.getDateCellValue(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");; + if (dateval!=null) { + cellValue = sdf.format(sdf); + } + + } else { + cell.setCellType(Cell.CELL_TYPE_STRING);//ֵתַ + cellValue = cell.getStringCellValue(); +// BigDecimal bd = new BigDecimal(cell.getNumericCellValue()); +// cellValue = bd.toPlainString();// ֵ BigDecimalװٻȡplainStringԷֹȡѧֵ +// cellValue = cutZero(cell.getNumericCellValue() + ""); + } + +// if (HSSFDateUtil.isCellDateFormatted(cell)) { +// cellValue = String.valueOf(DateUtil +// .getExcelDate(cell.getDateCellValue())); +// } else { +// // cellValue = +// // getRightStr(cell.getNumericCellValue() + ""); +// cellValue = cutZero(cell.getNumericCellValue() + ""); +// } + } + /** */ + /** ַ */ + else if (Cell.CELL_TYPE_STRING == cell.getCellType()) { + cellValue = cell.getStringCellValue(); + } + /** */ + /** */ + else if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) { + cellValue = cell.getBooleanCellValue() + ""; + }// ʽ + else if (Cell.CELL_TYPE_FORMULA == cell.getCellType()) { + // + cell.setCellType(Cell.CELL_TYPE_STRING); + cellValue = cell.getStringCellValue(); + if (cellValue != null) { + cellValue = cellValue.replaceAll("#N/A", "").trim(); + } + } + /** */ + /** ,ϼ */ + else { + cellValue = cell.toString() + ""; + } + line.add(cellValue); + } else { + line.add(cellValue); + } + } + + for (int j = 0; j < columns - cos + 1; j++) { + line.add(""); + } + } + + return line; + } + + /** */ + /** + *
        + *
      • Description:[ȷشԶ]
      • + *
      • Created by [Huyvanpull] [Jan 20, 2010]
      • + *
      • Midified by [modifier] [modified time]
      • + *
          + * + * @param sNum + * @return + */ + private String getRightStr(String sNum) { + DecimalFormat decimalFormat = new DecimalFormat("#.000000"); + String resultStr = decimalFormat.format(new Double(sNum)); + if (resultStr.matches("^[-+]?\\d+\\.[0]+$")) { + resultStr = resultStr.substring(0, resultStr.indexOf(".")); + } + return resultStr; + } + + /** + * ȥС + * + * @param v + * @return + */ + public String cutZero(String v) { + if (v.indexOf(".") > -1) { + while (true) { + if (v.lastIndexOf("0") == (v.length() - 1)) { + v = v.substring(0, v.lastIndexOf("0")); + } else { + break; + } + } + if (v.lastIndexOf(".") == (v.length() - 1)) { + v = v.substring(0, v.lastIndexOf(".")); + } + } + return v; + } + + public POIExcelParser() { + + org.apache.poi.ss.usermodel.Workbook workbook; + try { + workbook = new XSSFWorkbook(new FileInputStream( + "C:\\Users\\hub\\Desktop\\A877ͼֽ.xlsx")); + // workbook = new XSSFWorkbook(new + // FileInputStream("C:\\Users\\Administrator.SD-20101212HAVL\\Desktop\\material.xlsx")); + org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0); + + for (int i = 0; i < 44; i++) { + int cellCount = sheet.getRow(0).getPhysicalNumberOfCells(); + Row row = sheet.getRow(i); + if (row != null) { + System.out.println("" + i + "" + cellCount); + for (int j = 0; j < cellCount; j++) { + System.out.println(i + "" + j + ""); + + Cell cell = row.getCell(j); + String cellValue = ""; + if (cell != null) { + /** */ + /** ͵,Զȥ */ + if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { + /** */ + /** excel,Ҳ,ڴҪж */ + if (HSSFDateUtil.isCellDateFormatted(cell)) { + cellValue = String.valueOf(DateUtil + .getExcelDate(cell + .getDateCellValue())); + } else { + cellValue = getRightStr(cell + .getNumericCellValue() + ""); + System.out.println(cutZero(cell + .getNumericCellValue() + "")); + } + } + /** */ + /** ַ */ + else if (Cell.CELL_TYPE_STRING == cell + .getCellType()) { + cellValue = cell.getStringCellValue(); + System.out.println(cellValue); + } + /** */ + /** */ + else if (Cell.CELL_TYPE_BOOLEAN == cell + .getCellType()) { + cellValue = cell.getBooleanCellValue() + ""; + System.out.println(cellValue); + } else if (Cell.CELL_TYPE_FORMULA == cell + .getCellType()) { + // + cell.setCellType(Cell.CELL_TYPE_STRING); + cellValue = cell.getStringCellValue(); + if (cellValue != null) { + cellValue = cellValue + .replaceAll("#N/A", "").trim(); + } + System.out.println(cellValue); + } + /** */ + /** ,ϼ */ + else { + cellValue = cell.toString() + ""; + System.out.println(cellValue); + } + } + } + } + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static boolean isDateFormat(String dataStr) { + if (dataStr.contains("-")) { + String year = dataStr.split("-")[0]; + String month = dataStr.split("-")[1]; + try { + if (year.length() == 4 && Integer.parseInt(year) > 1900) { + if (month.length() == 2) { + if (Integer.parseInt(month) > 0 + && Integer.parseInt(month) < 13) { + return true; + } else { + System.out.println("·ݲ1º12֮"); + } + } else { + System.out.println("ַ2λ"); + } + } else { + System.out.println("ַ4λ"); + } + } catch (NumberFormatException e) { + System.out.println("кзֵַ"); + e.printStackTrace(); + } + } + return false; + } + + public static void main(String[] args) { + new POIExcelParser(); + } +} diff --git a/src/com/connor/dev/imp/toolkit/POIExcelUtil.java b/src/com/connor/dev/imp/toolkit/POIExcelUtil.java new file mode 100644 index 0000000..a3acdf3 --- /dev/null +++ b/src/com/connor/dev/imp/toolkit/POIExcelUtil.java @@ -0,0 +1,323 @@ +package com.connor.dev.imp.toolkit; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +/** *//** +*
            +*
          • Title:[POIϵExcelݶȡ]
          • +*
          • Description: [֧Excell2003,Excell2007,Զʽֵ,Զʽ]
          • +*
          • Copyright 2010 RoadWay Co., Ltd.
          • +*
          • All right reserved.
          • +*
          • Created by [] [Dec 5, 2010]
          • +*
          • Midified by [modifier] [modified time]
          • +* +*
          • Jarб
          • +*
          • poi-3.7-20101029.jar
          • +*
          • poi-examples-3.7-20101029.jar
          • +*
          • poi-ooxml-3.7-2010102.jar
          • +*
          • poi-ooxml-schemas-3.7-2010102.jar
          • +*
          • xmlbeans-2.3.0.jar
          • +*
              +* +* @version 1.0 +*/ +public class POIExcelUtil +{ + /** *//** */ + private int totalRows = 0; + + /** *//** */ + private int totalCells = 0; + + /** *//** sheetҳ */ + private Sheet sheet; + + /** *//** 췽 */ + public POIExcelUtil() + {} + + /** *//** + *
                + *
              • Description:[ļȡexcelļ]
              • + *
              • Created by [Huyvanpull] [Jan 20, 2010]
              • + *
              • Midified by [modifier] [modified time]
              • + *
                  + * + * @param fileName + * @return + * @throws Exception + */ + public List> read(String fileName) + { + List> dataLst = new ArrayList>(); + + /** *//** ļǷΪջǷExcelʽļ */ + if (fileName == null || !fileName.matches("^.+\\.(?i)((xls)|(xlsx))$")) + { + return dataLst; + } + + boolean isExcel2003 = true; + /** *//** ļĺϷԽ֤ */ + if (fileName.matches("^.+\\.(?i)(xlsx)$")) + { + isExcel2003 = false; + } + + /** *//** ļǷ */ + File file = new File(fileName); + if (file == null || !file.exists()) + { + return dataLst; + } + + try + { + /** *//** ñṩĸȡķ */ + dataLst = read(new FileInputStream(file), isExcel2003); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + /** *//** ȡĽ */ + return dataLst; + } + + /** *//** + *
                    + *
                  • Description:[ȡExcelļ]
                  • + *
                  • Created by [Huyvanpull] [Jan 20, 2010]
                  • + *
                  • Midified by [modifier] [modified time]
                  • + *
                      + * + * @param inputStream + * @param isExcel2003 + * @return + */ + public List> read(InputStream inputStream, + boolean isExcel2003) + { + List> dataLst = null; + try + { + /** *//** ݰ汾ѡ񴴽Workbookķʽ */ + Workbook wb = isExcel2003 ? new HSSFWorkbook(inputStream) + : new XSSFWorkbook(inputStream); + dataLst = read(wb); + } + catch (IOException e) + { + e.printStackTrace(); + } + return dataLst; + } + + /** *//** + *
                        + *
                      • Description:[õ]
                      • + *
                      • Created by [Huyvanpull] [Jan 20, 2010]
                      • + *
                      • Midified by [modifier] [modified time]
                      • + *
                          + * + * @return + */ + public int getTotalRows() + { + return totalRows; + } + + /** *//** + *
                            + *
                          • Description:[õ]
                          • + *
                          • Created by [Huyvanpull] [Jan 20, 2010]
                          • + *
                          • Midified by [modifier] [modified time]
                          • + *
                              + * + * @return + */ + public int getTotalCells() + { + return totalCells; + } + + + public Sheet getSheet(){ + return sheet; + } + + /** *//** + *
                                + *
                              • Description:[ȡ]
                              • + *
                              • Created by [Huyvanpull] [Jan 20, 2010]
                              • + *
                              • Midified by [modifier] [modified time]
                              • + *
                                  + * + * @param wb + * @return + */ + private List> read(Workbook wb) + { + List> dataLst = new ArrayList>(); + + /** *//** õһshell */ + sheet = wb.getSheetAt(0); + this.totalRows = sheet.getPhysicalNumberOfRows(); + if (this.totalRows >= 1 && sheet.getRow(0) != null) + { + this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells(); + } + + /** *//** ѭExcel */ + for (int r = 0; r < this.totalRows; r++) + { + Row row = sheet.getRow(r); + if (row == null) + { + continue; + } + + ArrayList rowLst = new ArrayList(); + /** *//** ѭExcel */ + for (short c = 0; c < this.getTotalCells(); c++) + { + Cell cell = row.getCell(c); + String cellValue = ""; + if (cell == null) + { + rowLst.add(cellValue); + continue; + } + + /** *//** ͵,Զȥ */ + if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) + { + /** *//** excel,Ҳ,ڴҪж */ + if (HSSFDateUtil.isCellDateFormatted(cell)) + { + cellValue = String.valueOf(DateUtil.getExcelDate(cell.getDateCellValue())); + } + else + { + cellValue = getRightStr(cell.getNumericCellValue() + ""); + } + } + /** *//** ַ */ + else if (Cell.CELL_TYPE_STRING == cell.getCellType()) + { + cellValue = cell.getStringCellValue(); + } + /** *//** */ + else if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) + { + cellValue = cell.getBooleanCellValue() + ""; + } + /** *//** ,ϼ */ + else + { + cellValue = cell.toString() + ""; + } + + rowLst.add(cellValue); + } + dataLst.add(rowLst); + } + return dataLst; + } + + /** *//** + *
                                    + *
                                  • Description:[ȷشԶ]
                                  • + *
                                  • Created by [Huyvanpull] [Jan 20, 2010]
                                  • + *
                                  • Midified by [modifier] [modified time]
                                  • + *
                                      + * + * @param sNum + * @return + */ + private String getRightStr(String sNum) + { + DecimalFormat decimalFormat = new DecimalFormat("#.000000"); + String resultStr = decimalFormat.format(new Double(sNum)); + if (resultStr.matches("^[-+]?\\d+\\.[0]+$")) + { + resultStr = resultStr.substring(0, resultStr.indexOf(".")); + } + return resultStr; + } + + + /** *//** + *
                                        + *
                                      • Description:[main]
                                      • + *
                                      • Created by [Huyvanpull] [Dec 5, 2010]
                                      • + *
                                      • Midified by [modifier] [modified time]
                                      • + *
                                          + * + * @param args + * @throws Exception + */ + public static void main(String[] args) + { + System.out.println("123"); + List> dataLst = new POIExcelUtil() + .read("D:\\reprot.xlsx"); +// for (ArrayList innerLst : dataLst) +// { +// StringBuffer rowData = new StringBuffer(); +// for (String dataStr : innerLst) +// { +// rowData.append(",").append(dataStr); +// } +// if (rowData.length() > 0) +// { +// System.out.println(rowData.deleteCharAt(0).toString()); +// } +// } + for(int rowCount=0;rowCount rowDataList = dataLst.get(rowCount); + for(int i = 0;i 0) { + System.out.println("ݼ·Ϊ" + filePath); + // String sep = ois.getArraySeparator(); + String[] files = filePath.split("\\|\\|"); + List fis = new ArrayList(); + for (int j = 0; j < files.length; j++) { + // File f = new + // File(input.getParent(), + // files[j]); + File f = new File(files[j]); + if (f.exists()) { + fis.add(f.getAbsolutePath()); + System.out.println("ļ" + f.getAbsolutePath() + ""); + } else { + System.out.println("ļ" + f.getAbsolutePath() + "ڣԴ"); + } + } + } + } + } + } + + } +} + diff --git a/src/com/connor/dev/imp/toolkit/ProgressReporter.java b/src/com/connor/dev/imp/toolkit/ProgressReporter.java new file mode 100644 index 0000000..d4369b5 --- /dev/null +++ b/src/com/connor/dev/imp/toolkit/ProgressReporter.java @@ -0,0 +1,127 @@ +package com.connor.dev.imp.toolkit; + +import java.awt.BorderLayout; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Toolkit; + +import javax.swing.JLabel; +import javax.swing.JProgressBar; +import javax.swing.JWindow; + +public class ProgressReporter extends JWindow implements Runnable +{ + private static final long serialVersionUID = 1L; + + private JLabel messageLabel; + + private JProgressBar progressBar; + + private boolean requestCanceling; + + private int percent; + + public ProgressReporter() + { + // setAlwaysOnTop(true); + setLayout(new BorderLayout()); + + initializeComponents(); + setTextPropertyForComponents(); + registerComponentsListeners(); + addComponents(); + + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + } + + private void initializeComponents() + { + messageLabel = new JLabel(" ", JLabel.LEFT); + progressBar = new JProgressBar(); + } + + private void setTextPropertyForComponents() + { + // setTitle(""); + } + + private void registerComponentsListeners() + { + } + + private void addComponents() + { + add(messageLabel, BorderLayout.NORTH); + add(progressBar, BorderLayout.SOUTH); + } + + private void centerToClientScreen() + { + Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + + int x = screen.width - getWidth(); + int y = screen.height - getHeight(); + + setLocation(x / 2, y / 2); + } + + public void reportProgressMessage(String message) + { + messageLabel.setText(message); + } + + public void setProgressPercent(int percent) + { + this.percent = percent; + } + + public void requestCanceling() + { + requestCanceling = true; + } + + public void setTaskRange(int min, int max) + { + progressBar.setMinimum(min); + progressBar.setMaximum(max); + } + + public void run() + { + pack(); + setSize(500, getHeight()); + centerToClientScreen(); + setVisible(true); + + while (!requestCanceling) + { + if (percent > progressBar.getMaximum()) + { + percent = 0; + } + + progressBar.setValue(percent); + + try + { + Thread.sleep(500); + } + catch (InterruptedException e) + { + continue; + } + } + + dispose(); + } + + public int getProgess() + { + return progressBar.getValue(); + } + + public boolean isRequestCanceling() + { + return requestCanceling; + } +} diff --git a/src/com/connor/dev/imp/toolkit/SearchUtility.java b/src/com/connor/dev/imp/toolkit/SearchUtility.java new file mode 100644 index 0000000..7bdeb32 --- /dev/null +++ b/src/com/connor/dev/imp/toolkit/SearchUtility.java @@ -0,0 +1,63 @@ +package com.connor.dev.imp.toolkit; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponentContextList; +import com.teamcenter.rac.kernel.TCComponentQuery; +import com.teamcenter.rac.kernel.TCComponentQueryType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTextService; +import com.teamcenter.rac.util.MessageBox; + +public class SearchUtility { + + public static InterfaceAIFComponent[] searchComponentsCollection(TCSession session, String searchName, + String[] keys, String[] values) { + // Ϣ + InterfaceAIFComponent[] result = new InterfaceAIFComponent[0]; + + try { + TCTextService textService = session.getTextService(); + TCComponentQueryType querytype = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery query = (TCComponentQuery) querytype.find(searchName); + querytype.clearCache(); +// String[] as = new String[keys.length]; +// for (int i = 0; i < keys.length; i++) { +// as[i] = textService.getTextValue(keys[i]); +// } +// +// String[] as1 = new String[values.length]; +// for (int i = 0; i < values.length; i++) { +// as1[i] = textService.getTextValue(values[i]); +// } +// if (query == null) { +// MessageBox.post("ûвҵ" + searchName + "ѯ", "", 0); +// return null; +// } + try { + System.out.println("comp length:"+session.search(searchName, keys, values).length); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + query.clearCache(); + TCComponentContextList list = query.getExecuteResultsList(keys, values); + if (list != null) { + int count = list.getListCount(); + result = new InterfaceAIFComponent[count]; + + for (int i = 0; i < count; i++) { + result[i] = list.get(i).getComponent(); + } + } + } catch (TCException e) { + + e.printStackTrace(); + MessageBox.post(AIFDesktop.getActiveDesktop().getShell(), "ͨѯ" + searchName + "ѯ.", "", 1); + + } + + return result; + } +} diff --git a/src/com/connor/dev/test/ImporttestHandler.java b/src/com/connor/dev/test/ImporttestHandler.java new file mode 100644 index 0000000..56781d0 --- /dev/null +++ b/src/com/connor/dev/test/ImporttestHandler.java @@ -0,0 +1,39 @@ +package com.connor.dev.test; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.dev.imp.ob.ImportObjectsCommand; +import com.connor.dev.imp.project.ImportProjectAction; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentProject; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class ImporttestHandler extends AbstractHandler { + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + try { + TCSession session = (TCSession) app.getSession(); + TCComponent tcom = (TCComponent) app.getTargetComponent(); + + TCComponent[] projects = session.search("Ŀ...", + new String[] { "Ŀ" }, new String[] { "test111" }); + if(projects!=null&&projects.length>0){ + System.out.println("aaa"); + ((TCComponentProject)projects[0]).assignToProject(new TCComponent[]{tcom}); + + } + } catch (Exception exception) { + MessageBox.post(exception, true); + } + + return null; + } + +} \ No newline at end of file diff --git a/src/tcimporthistorydatas/Activator.java b/src/tcimporthistorydatas/Activator.java new file mode 100644 index 0000000..39a13f5 --- /dev/null +++ b/src/tcimporthistorydatas/Activator.java @@ -0,0 +1,50 @@ +package tcimporthistorydatas; + +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 = "TCImportHistoryDatas"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + 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/xmlbeans-2.3.0.jar b/xmlbeans-2.3.0.jar new file mode 100644 index 0000000..ccd8163 Binary files /dev/null and b/xmlbeans-2.3.0.jar differ