commit 6ae1f4d92951c7a73e8e0947fddff764f99f0069 Author: hongcj Date: Fri Apr 11 14:03:16 2025 +0800 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..59e94a1 --- /dev/null +++ b/.classpath @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..a524107 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.connor.ly.process + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..af5d92d --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/com/connor/ly/project/test.java=GBK diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9f6ece8 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d1fafa1 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,57 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Process +Bundle-SymbolicName: com.connor.ly.process;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: CONNOR +Require-Bundle: org.eclipse.ui.forms;bundle-version="3.7.400", + org.eclipse.ui, + org.eclipse.core.runtime;bundle-version="3.15.100", + com.teamcenter.rac.common;bundle-version="13000.1.0", + com.teamcenter.rac.external;bundle-version="13000.1.0", + com.teamcenter.rac.workflow.processdesigner;bundle-version="13000.1.0", + com.teamcenter.rac.util;bundle-version="13000.1.0", + com.teamcenter.rac.aifrcp;bundle-version="13000.1.0", + com.teamcenter.rac.neva;bundle-version="2.0.0", + com.teamcenter.rac.kernel;bundle-version="13000.1.0" +Automatic-Module-Name: com.connor.ld.process +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: ., + lib/swingx-1.6.1.jar, + lib/aspose-cells-18.9.jar, + lib/axiom-api-1.2.13.jar, + lib/axis2-kernel-1.6.2.jar, + lib/commons-codec-1.13.jar, + lib/commons-collections4-4.4.jar, + lib/commons-compress-1.19.jar, + lib/commons-lang3-3.9.jar, + lib/commons-logging-1.2.jar, + lib/commons-math3-3.6.1.jar, + lib/datepicker.jar, + lib/fastjson-1.2.9.jar, + lib/hutool-all-5.0.7.jar, + lib/jaxb-api-2.3.1.jar, + lib/jaxb-core-2.3.0.1.jar, + lib/jaxb-impl-2.3.2.jar, + lib/jfxrt.jar, + lib/json-lib-2.2.2-jdk15.jar, + lib/poi-4.1.1.jar, + lib/poi-examples-4.1.1.jar, + lib/poi-excelant-4.1.1.jar, + lib/poi-ooxml-4.1.1.jar, + lib/poi-ooxml-schemas-4.1.1.jar, + lib/poi-scratchpad-4.1.1.jar, + lib/xmlbeans-3.1.0.jar, + lib/docx4j-export-fo-11.5.1.jar, + lib/org.apache.poi.xwpf.converter.xhtml-1.0.6.jar, + lib/slf4j-api-2.0.16.jar, + lib/slf4j-simple-2.0.16.jar, + lib/commons-io-2.16.1.jar, + lib/docx4j-3.2.1.jar, + lib/pdfbox-2.0.27.jar, + lib/fontbox-2.0.27.jar, + lib/ojdbc8.jar, + lib/cn.net.connor.std.gdtex_13000.1.0.jar, + lib/ojdbc6.jar, + lib/spire.doc-3.2.3.jar +Export-Package: org.jdesktop.swingx.table diff --git a/bin/com/connor/ly/process/ProcessWordExportHandler.class b/bin/com/connor/ly/process/ProcessWordExportHandler.class new file mode 100644 index 0000000..428d86d Binary files /dev/null and b/bin/com/connor/ly/process/ProcessWordExportHandler.class differ diff --git a/bin/com/connor/ly/process/ProcessWordExportOperation$1.class b/bin/com/connor/ly/process/ProcessWordExportOperation$1.class new file mode 100644 index 0000000..969a761 Binary files /dev/null and b/bin/com/connor/ly/process/ProcessWordExportOperation$1.class differ diff --git a/bin/com/connor/ly/process/ProcessWordExportOperation.class b/bin/com/connor/ly/process/ProcessWordExportOperation.class new file mode 100644 index 0000000..b52a7e8 Binary files /dev/null and b/bin/com/connor/ly/process/ProcessWordExportOperation.class differ diff --git a/bin/com/connor/ly/process2/ProcessWordExportHandler.class b/bin/com/connor/ly/process2/ProcessWordExportHandler.class new file mode 100644 index 0000000..b9c3c69 Binary files /dev/null and b/bin/com/connor/ly/process2/ProcessWordExportHandler.class differ diff --git a/bin/com/connor/ly/process2/ProcessWordExportOperation$1.class b/bin/com/connor/ly/process2/ProcessWordExportOperation$1.class new file mode 100644 index 0000000..508ad1f Binary files /dev/null and b/bin/com/connor/ly/process2/ProcessWordExportOperation$1.class differ diff --git a/bin/com/connor/ly/process2/ProcessWordExportOperation.class b/bin/com/connor/ly/process2/ProcessWordExportOperation.class new file mode 100644 index 0000000..cf1745b Binary files /dev/null and b/bin/com/connor/ly/process2/ProcessWordExportOperation.class differ diff --git a/bin/com/connor/ly/project/DateChooser$1.class b/bin/com/connor/ly/project/DateChooser$1.class new file mode 100644 index 0000000..0e4b891 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$1.class differ diff --git a/bin/com/connor/ly/project/DateChooser$2.class b/bin/com/connor/ly/project/DateChooser$2.class new file mode 100644 index 0000000..80f6e33 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$2.class differ diff --git a/bin/com/connor/ly/project/DateChooser$3.class b/bin/com/connor/ly/project/DateChooser$3.class new file mode 100644 index 0000000..7e6f05e Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$3.class differ diff --git a/bin/com/connor/ly/project/DateChooser$4.class b/bin/com/connor/ly/project/DateChooser$4.class new file mode 100644 index 0000000..558ba74 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$4.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP1$1.class b/bin/com/connor/ly/project/DateChooser$JP1$1.class new file mode 100644 index 0000000..c1d547d Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP1$1.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP1$2.class b/bin/com/connor/ly/project/DateChooser$JP1$2.class new file mode 100644 index 0000000..9c8867f Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP1$2.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP1$3.class b/bin/com/connor/ly/project/DateChooser$JP1$3.class new file mode 100644 index 0000000..970ba41 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP1$3.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP1$4.class b/bin/com/connor/ly/project/DateChooser$JP1$4.class new file mode 100644 index 0000000..809bd06 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP1$4.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP1.class b/bin/com/connor/ly/project/DateChooser$JP1.class new file mode 100644 index 0000000..b2586b9 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP1.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP2.class b/bin/com/connor/ly/project/DateChooser$JP2.class new file mode 100644 index 0000000..cd6a7af Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP2.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP3.class b/bin/com/connor/ly/project/DateChooser$JP3.class new file mode 100644 index 0000000..92332c6 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP3.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP4$1.class b/bin/com/connor/ly/project/DateChooser$JP4$1.class new file mode 100644 index 0000000..f4b6810 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP4$1.class differ diff --git a/bin/com/connor/ly/project/DateChooser$JP4.class b/bin/com/connor/ly/project/DateChooser$JP4.class new file mode 100644 index 0000000..2bfad62 Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$JP4.class differ diff --git a/bin/com/connor/ly/project/DateChooser$LabelManager.class b/bin/com/connor/ly/project/DateChooser$LabelManager.class new file mode 100644 index 0000000..8def67b Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$LabelManager.class differ diff --git a/bin/com/connor/ly/project/DateChooser$MyLabel.class b/bin/com/connor/ly/project/DateChooser$MyLabel.class new file mode 100644 index 0000000..5d475bb Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser$MyLabel.class differ diff --git a/bin/com/connor/ly/project/DateChooser.class b/bin/com/connor/ly/project/DateChooser.class new file mode 100644 index 0000000..3b2ec4e Binary files /dev/null and b/bin/com/connor/ly/project/DateChooser.class differ diff --git a/bin/com/connor/ly/project/ExportProjectDashboardHandler.class b/bin/com/connor/ly/project/ExportProjectDashboardHandler.class new file mode 100644 index 0000000..f1ab0aa Binary files /dev/null and b/bin/com/connor/ly/project/ExportProjectDashboardHandler.class differ diff --git a/bin/com/connor/ly/project/ExportProjectDashboardOperations.class b/bin/com/connor/ly/project/ExportProjectDashboardOperations.class new file mode 100644 index 0000000..4a5ce5c Binary files /dev/null and b/bin/com/connor/ly/project/ExportProjectDashboardOperations.class differ diff --git a/bin/com/connor/ly/project/ProjectDashboardExporter.class b/bin/com/connor/ly/project/ProjectDashboardExporter.class new file mode 100644 index 0000000..5ac6385 Binary files /dev/null and b/bin/com/connor/ly/project/ProjectDashboardExporter.class differ diff --git a/bin/com/connor/ly/project/TimeSheet.class b/bin/com/connor/ly/project/TimeSheet.class new file mode 100644 index 0000000..742f4a1 Binary files /dev/null and b/bin/com/connor/ly/project/TimeSheet.class differ diff --git a/bin/com/connor/ly/project/WaitingDialog.class b/bin/com/connor/ly/project/WaitingDialog.class new file mode 100644 index 0000000..1e94508 Binary files /dev/null and b/bin/com/connor/ly/project/WaitingDialog.class differ diff --git a/bin/com/connor/ly/project/test$1.class b/bin/com/connor/ly/project/test$1.class new file mode 100644 index 0000000..1ef1ecd Binary files /dev/null and b/bin/com/connor/ly/project/test$1.class differ diff --git a/bin/com/connor/ly/project/test.class b/bin/com/connor/ly/project/test.class new file mode 100644 index 0000000..8c0190c Binary files /dev/null and b/bin/com/connor/ly/project/test.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox$RwBasicComboPopup.class b/bin/com/connor/lyProess/CheckboxComboBox$RwBasicComboPopup.class new file mode 100644 index 0000000..cc3507b Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox$RwBasicComboPopup.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox$RwDefaultComboBoxModel.class b/bin/com/connor/lyProess/CheckboxComboBox$RwDefaultComboBoxModel.class new file mode 100644 index 0000000..2811725 Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox$RwDefaultComboBoxModel.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox$RwDefaultListSelectionModel.class b/bin/com/connor/lyProess/CheckboxComboBox$RwDefaultListSelectionModel.class new file mode 100644 index 0000000..b4083be Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox$RwDefaultListSelectionModel.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox$RwJCheckBox.class b/bin/com/connor/lyProess/CheckboxComboBox$RwJCheckBox.class new file mode 100644 index 0000000..d445d39 Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox$RwJCheckBox.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox$RwJComboBox.class b/bin/com/connor/lyProess/CheckboxComboBox$RwJComboBox.class new file mode 100644 index 0000000..bc3dd45 Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox$RwJComboBox.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox$RwMetalComboBoxUI.class b/bin/com/connor/lyProess/CheckboxComboBox$RwMetalComboBoxUI.class new file mode 100644 index 0000000..ab10dbf Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox$RwMetalComboBoxUI.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox$RwMouseAdapter.class b/bin/com/connor/lyProess/CheckboxComboBox$RwMouseAdapter.class new file mode 100644 index 0000000..93ce83b Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox$RwMouseAdapter.class differ diff --git a/bin/com/connor/lyProess/CheckboxComboBox.class b/bin/com/connor/lyProess/CheckboxComboBox.class new file mode 100644 index 0000000..59b28a0 Binary files /dev/null and b/bin/com/connor/lyProess/CheckboxComboBox.class differ diff --git a/bin/com/connor/lyProess/ProcessWorker.class b/bin/com/connor/lyProess/ProcessWorker.class new file mode 100644 index 0000000..884aa91 Binary files /dev/null and b/bin/com/connor/lyProess/ProcessWorker.class differ diff --git a/bin/com/connor/lyProess/Template.class b/bin/com/connor/lyProess/Template.class new file mode 100644 index 0000000..c91c57a Binary files /dev/null and b/bin/com/connor/lyProess/Template.class differ diff --git a/bin/com/connor/lyProess/Util.class b/bin/com/connor/lyProess/Util.class new file mode 100644 index 0000000..714dd02 Binary files /dev/null and b/bin/com/connor/lyProess/Util.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$1.class b/bin/com/connor/lyProess/exportToWordOperation$1.class new file mode 100644 index 0000000..5a40288 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$1.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$2.class b/bin/com/connor/lyProess/exportToWordOperation$2.class new file mode 100644 index 0000000..8fff069 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$2.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$3.class b/bin/com/connor/lyProess/exportToWordOperation$3.class new file mode 100644 index 0000000..7246431 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$3.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$RwBasicComboPopup.class b/bin/com/connor/lyProess/exportToWordOperation$RwBasicComboPopup.class new file mode 100644 index 0000000..297f27a Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$RwBasicComboPopup.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$RwDefaultComboBoxModel.class b/bin/com/connor/lyProess/exportToWordOperation$RwDefaultComboBoxModel.class new file mode 100644 index 0000000..592c7d7 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$RwDefaultComboBoxModel.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$RwDefaultListSelectionModel.class b/bin/com/connor/lyProess/exportToWordOperation$RwDefaultListSelectionModel.class new file mode 100644 index 0000000..23575d1 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$RwDefaultListSelectionModel.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$RwJCheckBox.class b/bin/com/connor/lyProess/exportToWordOperation$RwJCheckBox.class new file mode 100644 index 0000000..e02063d Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$RwJCheckBox.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$RwJComboBox.class b/bin/com/connor/lyProess/exportToWordOperation$RwJComboBox.class new file mode 100644 index 0000000..2add376 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$RwJComboBox.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$RwMetalComboBoxUI.class b/bin/com/connor/lyProess/exportToWordOperation$RwMetalComboBoxUI.class new file mode 100644 index 0000000..255c364 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$RwMetalComboBoxUI.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$RwMouseAdapter.class b/bin/com/connor/lyProess/exportToWordOperation$RwMouseAdapter.class new file mode 100644 index 0000000..65f861d Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$RwMouseAdapter.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation$TextFieldComboBoxEditor.class b/bin/com/connor/lyProess/exportToWordOperation$TextFieldComboBoxEditor.class new file mode 100644 index 0000000..e28754e Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation$TextFieldComboBoxEditor.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation.class b/bin/com/connor/lyProess/exportToWordOperation.class new file mode 100644 index 0000000..349c052 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$1.class b/bin/com/connor/lyProess/exportToWordOperation2$1.class new file mode 100644 index 0000000..4f3404d Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$1.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$2.class b/bin/com/connor/lyProess/exportToWordOperation2$2.class new file mode 100644 index 0000000..c148b85 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$2.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$3.class b/bin/com/connor/lyProess/exportToWordOperation2$3.class new file mode 100644 index 0000000..011d04e Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$3.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$RwBasicComboPopup.class b/bin/com/connor/lyProess/exportToWordOperation2$RwBasicComboPopup.class new file mode 100644 index 0000000..bd02ff1 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$RwBasicComboPopup.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$RwDefaultComboBoxModel.class b/bin/com/connor/lyProess/exportToWordOperation2$RwDefaultComboBoxModel.class new file mode 100644 index 0000000..28d76ee Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$RwDefaultComboBoxModel.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$RwDefaultListSelectionModel.class b/bin/com/connor/lyProess/exportToWordOperation2$RwDefaultListSelectionModel.class new file mode 100644 index 0000000..6968fc2 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$RwDefaultListSelectionModel.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$RwJCheckBox.class b/bin/com/connor/lyProess/exportToWordOperation2$RwJCheckBox.class new file mode 100644 index 0000000..1d5f491 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$RwJCheckBox.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$RwJComboBox.class b/bin/com/connor/lyProess/exportToWordOperation2$RwJComboBox.class new file mode 100644 index 0000000..efebdd6 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$RwJComboBox.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$RwMetalComboBoxUI.class b/bin/com/connor/lyProess/exportToWordOperation2$RwMetalComboBoxUI.class new file mode 100644 index 0000000..9c26b55 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$RwMetalComboBoxUI.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$RwMouseAdapter.class b/bin/com/connor/lyProess/exportToWordOperation2$RwMouseAdapter.class new file mode 100644 index 0000000..36bb290 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$RwMouseAdapter.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2$TextFieldComboBoxEditor.class b/bin/com/connor/lyProess/exportToWordOperation2$TextFieldComboBoxEditor.class new file mode 100644 index 0000000..ec588d9 Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2$TextFieldComboBoxEditor.class differ diff --git a/bin/com/connor/lyProess/exportToWordOperation2.class b/bin/com/connor/lyProess/exportToWordOperation2.class new file mode 100644 index 0000000..71b995a Binary files /dev/null and b/bin/com/connor/lyProess/exportToWordOperation2.class differ diff --git a/bin/com/connor/lyProess/exportWordHandler.class b/bin/com/connor/lyProess/exportWordHandler.class new file mode 100644 index 0000000..94b3588 Binary files /dev/null and b/bin/com/connor/lyProess/exportWordHandler.class differ diff --git a/bin/com/connor/lyProess/test$1.class b/bin/com/connor/lyProess/test$1.class new file mode 100644 index 0000000..19e95cc Binary files /dev/null and b/bin/com/connor/lyProess/test$1.class differ diff --git a/bin/com/connor/lyProess/test$RwBasicComboPopup.class b/bin/com/connor/lyProess/test$RwBasicComboPopup.class new file mode 100644 index 0000000..d0fecf1 Binary files /dev/null and b/bin/com/connor/lyProess/test$RwBasicComboPopup.class differ diff --git a/bin/com/connor/lyProess/test$RwDefaultComboBoxModel.class b/bin/com/connor/lyProess/test$RwDefaultComboBoxModel.class new file mode 100644 index 0000000..67dd149 Binary files /dev/null and b/bin/com/connor/lyProess/test$RwDefaultComboBoxModel.class differ diff --git a/bin/com/connor/lyProess/test$RwDefaultListSelectionModel.class b/bin/com/connor/lyProess/test$RwDefaultListSelectionModel.class new file mode 100644 index 0000000..6268926 Binary files /dev/null and b/bin/com/connor/lyProess/test$RwDefaultListSelectionModel.class differ diff --git a/bin/com/connor/lyProess/test$RwJCheckBox.class b/bin/com/connor/lyProess/test$RwJCheckBox.class new file mode 100644 index 0000000..cfdba7d Binary files /dev/null and b/bin/com/connor/lyProess/test$RwJCheckBox.class differ diff --git a/bin/com/connor/lyProess/test$RwJComboBox.class b/bin/com/connor/lyProess/test$RwJComboBox.class new file mode 100644 index 0000000..10016a7 Binary files /dev/null and b/bin/com/connor/lyProess/test$RwJComboBox.class differ diff --git a/bin/com/connor/lyProess/test$RwMetalComboBoxUI.class b/bin/com/connor/lyProess/test$RwMetalComboBoxUI.class new file mode 100644 index 0000000..4e059de Binary files /dev/null and b/bin/com/connor/lyProess/test$RwMetalComboBoxUI.class differ diff --git a/bin/com/connor/lyProess/test$RwMouseAdapter.class b/bin/com/connor/lyProess/test$RwMouseAdapter.class new file mode 100644 index 0000000..988a48a Binary files /dev/null and b/bin/com/connor/lyProess/test$RwMouseAdapter.class differ diff --git a/bin/com/connor/lyProess/test$TextFieldComboBoxEditor.class b/bin/com/connor/lyProess/test$TextFieldComboBoxEditor.class new file mode 100644 index 0000000..e3c8274 Binary files /dev/null and b/bin/com/connor/lyProess/test$TextFieldComboBoxEditor.class differ diff --git a/bin/com/connor/lyProess/test.class b/bin/com/connor/lyProess/test.class new file mode 100644 index 0000000..42c737a Binary files /dev/null and b/bin/com/connor/lyProess/test.class differ diff --git a/bin/com/connor/lyProess/test1.class b/bin/com/connor/lyProess/test1.class new file mode 100644 index 0000000..7ad8958 Binary files /dev/null and b/bin/com/connor/lyProess/test1.class differ diff --git a/bin/com/connor/lyProess/test2.class b/bin/com/connor/lyProess/test2.class new file mode 100644 index 0000000..4c379e3 Binary files /dev/null and b/bin/com/connor/lyProess/test2.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand$1.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand$1.class new file mode 100644 index 0000000..35faef7 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand$1.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.class new file mode 100644 index 0000000..6db3a7d Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.class new file mode 100644 index 0000000..e191cfe Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.class new file mode 100644 index 0000000..aefcfae Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTable.class b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTable.class new file mode 100644 index 0000000..dd20f67 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTable.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.class b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.class new file mode 100644 index 0000000..2626613 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.class b/bin/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.class new file mode 100644 index 0000000..9a7f33a Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/Test.class b/bin/com/connor/ml/tcm/outfile/ML_01/Test.class new file mode 100644 index 0000000..2d84ef1 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/Test.class differ diff --git a/bin/com/connor/ml/tcm/outfile/bean/NodeBean.class b/bin/com/connor/ml/tcm/outfile/bean/NodeBean.class new file mode 100644 index 0000000..921bd3c Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/bean/NodeBean.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/Adapter.class b/bin/com/connor/ml/tcm/outfile/util/Adapter.class new file mode 100644 index 0000000..1d08b2c Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/Adapter.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/AutoCompleter.class b/bin/com/connor/ml/tcm/outfile/util/AutoCompleter.class new file mode 100644 index 0000000..9fdfb6e Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/AutoCompleter.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.class b/bin/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.class new file mode 100644 index 0000000..bbb1c6b Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/MethodUtil.class b/bin/com/connor/ml/tcm/outfile/util/MethodUtil.class new file mode 100644 index 0000000..2e33925 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/MethodUtil.class differ diff --git a/bin/processRevision/KUtil.class b/bin/processRevision/KUtil.class new file mode 100644 index 0000000..f7a17c4 Binary files /dev/null and b/bin/processRevision/KUtil.class differ diff --git a/bin/processRevision/ProcessRevisionCommand$1.class b/bin/processRevision/ProcessRevisionCommand$1.class new file mode 100644 index 0000000..80e6c80 Binary files /dev/null and b/bin/processRevision/ProcessRevisionCommand$1.class differ diff --git a/bin/processRevision/ProcessRevisionCommand.class b/bin/processRevision/ProcessRevisionCommand.class new file mode 100644 index 0000000..93b83a6 Binary files /dev/null and b/bin/processRevision/ProcessRevisionCommand.class differ diff --git a/bin/processRevision/TCUtil$1.class b/bin/processRevision/TCUtil$1.class new file mode 100644 index 0000000..2b225b0 Binary files /dev/null and b/bin/processRevision/TCUtil$1.class differ diff --git a/bin/processRevision/TCUtil$2.class b/bin/processRevision/TCUtil$2.class new file mode 100644 index 0000000..5c986ef Binary files /dev/null and b/bin/processRevision/TCUtil$2.class differ diff --git a/bin/processRevision/TCUtil.class b/bin/processRevision/TCUtil.class new file mode 100644 index 0000000..545952d Binary files /dev/null and b/bin/processRevision/TCUtil.class differ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..dbf4c9e --- /dev/null +++ b/build.properties @@ -0,0 +1,42 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + lib/swingx-1.6.1.jar,\ + lib/aspose-cells-18.9.jar,\ + lib/axiom-api-1.2.13.jar,\ + lib/axis2-kernel-1.6.2.jar,\ + lib/commons-codec-1.13.jar,\ + lib/commons-collections4-4.4.jar,\ + lib/commons-compress-1.19.jar,\ + lib/commons-lang3-3.9.jar,\ + lib/commons-logging-1.2.jar,\ + lib/commons-math3-3.6.1.jar,\ + lib/datepicker.jar,\ + lib/fastjson-1.2.9.jar,\ + lib/hutool-all-5.0.7.jar,\ + lib/jaxb-api-2.3.1.jar,\ + lib/jaxb-core-2.3.0.1.jar,\ + lib/jaxb-impl-2.3.2.jar,\ + lib/jfxrt.jar,\ + lib/json-lib-2.2.2-jdk15.jar,\ + lib/poi-4.1.1.jar,\ + lib/poi-examples-4.1.1.jar,\ + lib/poi-excelant-4.1.1.jar,\ + lib/poi-ooxml-4.1.1.jar,\ + lib/poi-ooxml-schemas-4.1.1.jar,\ + lib/poi-scratchpad-4.1.1.jar,\ + lib/xmlbeans-3.1.0.jar,\ + lib/docx4j-export-fo-11.5.1.jar,\ + lib/org.apache.poi.xwpf.converter.xhtml-1.0.6.jar,\ + lib/slf4j-api-2.0.16.jar,\ + lib/slf4j-simple-2.0.16.jar,\ + lib/commons-io-2.16.1.jar,\ + lib/docx4j-3.2.1.jar,\ + lib/pdfbox-2.0.27.jar,\ + lib/fontbox-2.0.27.jar,\ + lib/ojdbc8.jar,\ + lib/cn.net.connor.std.gdtex_13000.1.0.jar,\ + lib/ojdbc6.jar,\ + lib/spire.doc-3.2.3.jar +source.. = src/ diff --git a/icons/sample.png b/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/icons/sample.png differ diff --git a/icons/sample@2x.png b/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/icons/sample@2x.png differ diff --git a/lib/aspose-cells-18.9.jar b/lib/aspose-cells-18.9.jar new file mode 100644 index 0000000..2cefe55 Binary files /dev/null and b/lib/aspose-cells-18.9.jar differ diff --git a/lib/axiom-api-1.2.13.jar b/lib/axiom-api-1.2.13.jar new file mode 100644 index 0000000..84cb42c Binary files /dev/null and b/lib/axiom-api-1.2.13.jar differ diff --git a/lib/axis2-kernel-1.6.2.jar b/lib/axis2-kernel-1.6.2.jar new file mode 100644 index 0000000..3ae5f7a Binary files /dev/null and b/lib/axis2-kernel-1.6.2.jar differ diff --git a/lib/cn.net.connor.std.gdtex_13000.1.0.jar b/lib/cn.net.connor.std.gdtex_13000.1.0.jar new file mode 100644 index 0000000..26b8448 Binary files /dev/null and b/lib/cn.net.connor.std.gdtex_13000.1.0.jar differ diff --git a/lib/commons-codec-1.13.jar b/lib/commons-codec-1.13.jar new file mode 100644 index 0000000..bf6ccb3 Binary files /dev/null and b/lib/commons-codec-1.13.jar differ diff --git a/lib/commons-collections4-4.4.jar b/lib/commons-collections4-4.4.jar new file mode 100644 index 0000000..da06c3e Binary files /dev/null and b/lib/commons-collections4-4.4.jar differ diff --git a/lib/commons-compress-1.19.jar b/lib/commons-compress-1.19.jar new file mode 100644 index 0000000..5c9f52a Binary files /dev/null and b/lib/commons-compress-1.19.jar differ diff --git a/lib/commons-io-2.16.1.jar b/lib/commons-io-2.16.1.jar new file mode 100644 index 0000000..eb3c2b0 Binary files /dev/null and b/lib/commons-io-2.16.1.jar differ diff --git a/lib/commons-lang3-3.9.jar b/lib/commons-lang3-3.9.jar new file mode 100644 index 0000000..0d89693 Binary files /dev/null and b/lib/commons-lang3-3.9.jar differ diff --git a/lib/commons-logging-1.2.jar b/lib/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/lib/commons-logging-1.2.jar differ diff --git a/lib/commons-math3-3.6.1.jar b/lib/commons-math3-3.6.1.jar new file mode 100644 index 0000000..0ff582c Binary files /dev/null and b/lib/commons-math3-3.6.1.jar differ diff --git a/lib/datepicker.jar b/lib/datepicker.jar new file mode 100644 index 0000000..8304d36 Binary files /dev/null and b/lib/datepicker.jar differ diff --git a/lib/docx4j-3.2.1.jar b/lib/docx4j-3.2.1.jar new file mode 100644 index 0000000..5d07f6b Binary files /dev/null and b/lib/docx4j-3.2.1.jar differ diff --git a/lib/docx4j-export-fo-11.5.1.jar b/lib/docx4j-export-fo-11.5.1.jar new file mode 100644 index 0000000..3c7a318 Binary files /dev/null and b/lib/docx4j-export-fo-11.5.1.jar differ diff --git a/lib/fastjson-1.2.9.jar b/lib/fastjson-1.2.9.jar new file mode 100644 index 0000000..839cea3 Binary files /dev/null and b/lib/fastjson-1.2.9.jar differ diff --git a/lib/fontbox-2.0.27.jar b/lib/fontbox-2.0.27.jar new file mode 100644 index 0000000..d2737d9 Binary files /dev/null and b/lib/fontbox-2.0.27.jar differ diff --git a/lib/hutool-all-5.0.7.jar b/lib/hutool-all-5.0.7.jar new file mode 100644 index 0000000..0ed0b10 Binary files /dev/null and b/lib/hutool-all-5.0.7.jar differ diff --git a/lib/jaxb-api-2.3.1.jar b/lib/jaxb-api-2.3.1.jar new file mode 100644 index 0000000..4565865 Binary files /dev/null and b/lib/jaxb-api-2.3.1.jar differ diff --git a/lib/jaxb-core-2.3.0.1.jar b/lib/jaxb-core-2.3.0.1.jar new file mode 100644 index 0000000..431e143 Binary files /dev/null and b/lib/jaxb-core-2.3.0.1.jar differ diff --git a/lib/jaxb-impl-2.3.2.jar b/lib/jaxb-impl-2.3.2.jar new file mode 100644 index 0000000..58035e8 Binary files /dev/null and b/lib/jaxb-impl-2.3.2.jar differ diff --git a/lib/jfxrt.jar b/lib/jfxrt.jar new file mode 100644 index 0000000..49b7d90 Binary files /dev/null and b/lib/jfxrt.jar differ diff --git a/lib/json-lib-2.2.2-jdk15.jar b/lib/json-lib-2.2.2-jdk15.jar new file mode 100644 index 0000000..27e7c7c Binary files /dev/null and b/lib/json-lib-2.2.2-jdk15.jar differ diff --git a/lib/ojdbc6.jar b/lib/ojdbc6.jar new file mode 100644 index 0000000..ec3d6f1 Binary files /dev/null and b/lib/ojdbc6.jar differ diff --git a/lib/ojdbc8.jar b/lib/ojdbc8.jar new file mode 100644 index 0000000..2ebb05e Binary files /dev/null and b/lib/ojdbc8.jar differ diff --git a/lib/org.apache.poi.xwpf.converter.xhtml-1.0.6.jar b/lib/org.apache.poi.xwpf.converter.xhtml-1.0.6.jar new file mode 100644 index 0000000..95df5d0 Binary files /dev/null and b/lib/org.apache.poi.xwpf.converter.xhtml-1.0.6.jar differ diff --git a/lib/pdfbox-2.0.27.jar b/lib/pdfbox-2.0.27.jar new file mode 100644 index 0000000..5510e40 Binary files /dev/null and b/lib/pdfbox-2.0.27.jar differ diff --git a/lib/poi-4.1.1.jar b/lib/poi-4.1.1.jar new file mode 100644 index 0000000..5b12817 Binary files /dev/null and b/lib/poi-4.1.1.jar differ diff --git a/lib/poi-examples-4.1.1.jar b/lib/poi-examples-4.1.1.jar new file mode 100644 index 0000000..334db49 Binary files /dev/null and b/lib/poi-examples-4.1.1.jar differ diff --git a/lib/poi-excelant-4.1.1.jar b/lib/poi-excelant-4.1.1.jar new file mode 100644 index 0000000..f0eb13a Binary files /dev/null and b/lib/poi-excelant-4.1.1.jar differ diff --git a/lib/poi-ooxml-4.1.1.jar b/lib/poi-ooxml-4.1.1.jar new file mode 100644 index 0000000..bf3569d Binary files /dev/null and b/lib/poi-ooxml-4.1.1.jar differ diff --git a/lib/poi-ooxml-schemas-4.1.1.jar b/lib/poi-ooxml-schemas-4.1.1.jar new file mode 100644 index 0000000..d4d0292 Binary files /dev/null and b/lib/poi-ooxml-schemas-4.1.1.jar differ diff --git a/lib/poi-scratchpad-4.1.1.jar b/lib/poi-scratchpad-4.1.1.jar new file mode 100644 index 0000000..1b6a94f Binary files /dev/null and b/lib/poi-scratchpad-4.1.1.jar differ diff --git a/lib/slf4j-api-2.0.16.jar b/lib/slf4j-api-2.0.16.jar new file mode 100644 index 0000000..cbb5448 Binary files /dev/null and b/lib/slf4j-api-2.0.16.jar differ diff --git a/lib/slf4j-simple-2.0.16.jar b/lib/slf4j-simple-2.0.16.jar new file mode 100644 index 0000000..d3d8bd9 Binary files /dev/null and b/lib/slf4j-simple-2.0.16.jar differ diff --git a/lib/spire.doc-3.2.3.jar b/lib/spire.doc-3.2.3.jar new file mode 100644 index 0000000..749d809 Binary files /dev/null and b/lib/spire.doc-3.2.3.jar differ diff --git a/lib/swingx-1.6.1.jar b/lib/swingx-1.6.1.jar new file mode 100644 index 0000000..b0bcc87 Binary files /dev/null and b/lib/swingx-1.6.1.jar differ diff --git a/lib/xmlbeans-3.1.0.jar b/lib/xmlbeans-3.1.0.jar new file mode 100644 index 0000000..18e568f Binary files /dev/null and b/lib/xmlbeans-3.1.0.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..480a9f8 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/connor/ly/process/ProcessWordExportHandler.java b/src/com/connor/ly/process/ProcessWordExportHandler.java new file mode 100644 index 0000000..d06f3af --- /dev/null +++ b/src/com/connor/ly/process/ProcessWordExportHandler.java @@ -0,0 +1,176 @@ +package com.connor.ly.process; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.List; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.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.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class ProcessWordExportHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("ProcessWordExportHandler"); +// new Thread() { +// public void run() { +// } +// }.start(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent target = app.getTargetComponent(); + TCComponentBOMLine bomLine = null; + TCComponentItemRevision revision = null; + if(target instanceof TCComponentItemRevision) { + //bom + revision = (TCComponentItemRevision)target; + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + bomLine = view.setWindowTopLine(revision.getItem(), revision, null, null); + } else if (target instanceof TCComponentBOMLine){ + bomLine = (TCComponentBOMLine)target; + revision = bomLine.getItemRevision(); + } else { + MessageBox.post(desktop, "ѡ汾е", "ERROR", MessageBox.ERROR); + return null; + } + + //ȡѡ жѡ + String[] values = session.getPreferenceService().getStringValues("LY_ExportMenu_Template_Mapping"); + if(values == null || values.length == 0) { + MessageBox.post(desktop, "ѡLY_ExportMenu_Template_Mapping", "ERROR", MessageBox.ERROR); + return null; + } + Map typeMap = new HashMap(); + Map dataSetMap = new HashMap(); + for(String value : values) { + String[] split = value.split("="); + typeMap.put(split[0], split[2]); + dataSetMap.put(split[0], split[1]); + } + String name = ""; + String id = arg0.getCommand().getId(); + int type = Integer.parseInt(id.substring(id.length()-8, id.length()-7)); + + if(id.equals("ProcessWordExport1Handler")){//000590 + name = "ӹտƬ"; + }else if(id.equals("ProcessWordExport2Handler")) { + name = "װտƬ"; + }else if(id.equals("ProcessWordExport3Handler")) { + name = "ʱտƬ"; + } + if(!typeMap.get(name).equals(revision.getType())) { + MessageBox.post(desktop, "ѡȷİ汾ͺִйտƬ", "ERROR", MessageBox.ERROR); + return null; + } + + if(id.equals("JJProcessWordExport1Handler") || id.equals("GZProcessWordExport1Handler")) { + TCComponent[] referenceListProperty = revision.getReferenceListProperty("IMAN_METarget"); + if(referenceListProperty == null || referenceListProperty.length == 0) { + MessageBox.post(desktop, "ѡжĿϵΪ", "ERROR", MessageBox.ERROR); + return null; + } + String property = referenceListProperty[0].getProperty("ly6_partNum"); + String property2 = revision.getProperty("ly6_partNum"); + String property3 = referenceListProperty[0].getProperty("ly6_drawRev"); + String property4 = revision.getProperty("ly6_drawRev"); + if(property != property2 || property3 != property4) { + if(referenceListProperty == null || referenceListProperty.length == 0) { + MessageBox.post(desktop, "·߰汾ϼź汾Ŀϵļšͼֽ汾һ£!", "ERROR", MessageBox.ERROR); + return null; + } + } + + } + + + + //2024 6 3 hcj ǵڶεտƬʱ򣬲ٴģлȡݼֱʹõǰϵµݼļ + ArrayList modelList = new ArrayList(); + + Boolean create = true; + for(AIFComponentContext c : bomLine.getItemRevision().getChildren("IMAN_specification")) { + TCComponent comp = (TCComponent)c.getComponent(); + System.out.println("ݼƣ"+comp.getProperty("object_name")); + System.out.println("ɸѡƣ"+name); + System.out.println("Ƿ"+comp.getProperty("object_name").contains(name)); + if(comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains(name)) { + create = false; + modelList.add((TCComponentDataset)comp); + break; + } + } + if(create) { + //һεտƬ ʹģļ + String ids = dataSetMap.get(name); + String[] split = ids.split(";"); + for(String idString : split) { + TCComponentDataset model = null; + TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent("Item"); + TCComponentItem[] item = itemType.findItems(idString); + if(item==null || item.length==0) { + MessageBox.post(desktop, "ѡConnor_ExportMenu_Template_Mappingòȷ", "ERROR", MessageBox.ERROR); + return null; + } + AIFComponentContext[] comps = item[0].getLatestItemRevision().getChildren("IMAN_specification"); + if(comps.length==0) { + MessageBox.post(desktop, ""+id+"°汾δҵWordģ", "ERROR", MessageBox.ERROR); + return null; + } + + for(AIFComponentContext c : comps) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.isTypeOf("MSWordX")) { + model = (TCComponentDataset) comp; + break; + } + } + if(model==null) { + MessageBox.post(desktop, ""+id+"°汾δҵWordģ", "ERROR", MessageBox.ERROR); + return null; + } + modelList.add(model); + } + + } + + String[] options = session.getPreferenceService().getStringValues("LY_GYKP_types"); + System.out.println(options.length); + if(options==null || options.length<4) { + MessageBox.post(desktop, "ѡLY_GYKP_typesòȷ", "ERROR", MessageBox.ERROR); + return null; + } + + ProcessWordExportOperation operation = new ProcessWordExportOperation(session, bomLine, modelList, type, options,name,create); + session.queueOperation(operation); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ly/process/ProcessWordExportOperation.java b/src/com/connor/ly/process/ProcessWordExportOperation.java new file mode 100644 index 0000000..2674c6a --- /dev/null +++ b/src/com/connor/ly/process/ProcessWordExportOperation.java @@ -0,0 +1,1363 @@ +package com.connor.ly.process; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +import org.apache.poi.xwpf.usermodel.IBodyElement; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; + +import com.spire.doc.Body; +import com.spire.doc.Document; +import com.spire.doc.DocumentObject; +import com.spire.doc.FileFormat; +import com.spire.doc.Section; +import com.spire.doc.Table; +import com.spire.doc.TableCell; +import com.spire.doc.TableRow; +import com.spire.doc.collections.CellCollection; +import com.spire.doc.collections.ParagraphCollection; +import com.spire.doc.collections.RowCollection; +import com.spire.doc.collections.SectionCollection; +import com.spire.doc.collections.TableCollection; +import com.spire.doc.documents.Paragraph; +import com.spire.doc.documents.SubSuperScript; +import com.spire.doc.fields.omath.OfficeMath; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +import cn.net.connor.std.gdtex.KGenerateGDTHTML; + +import processRevision.KUtil; +import processRevision.TCUtil; + +public class ProcessWordExportOperation extends AbstractAIFOperation { + + private TCSession session; + private ArrayList model; + private TCComponentBOMLine target; + private ArrayList nums; + private int choice; + private String[] options; + private TableCollection tables; + private int totalRow; + private int first; + private ArrayList symbols; + private Document doc; + private String oldName; + private Map queryName = new HashMap(); + private Boolean create; +// private static final int ROW = 12; + + public ProcessWordExportOperation(TCSession session, TCComponentBOMLine target, ArrayList model, + int type, String[] options, String name, Boolean create) { + this.session = session; + this.model = model; + this.target = target; + this.choice = type; + this.options = options; + this.oldName = name; + this.create = create; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + FileInputStream input = null; + FileOutputStream output = null; + BufferedWriter buffered = null; + try { + String[] equips = options[0].split(";"); + String[] docs = options[1].split(";"); + String[] split = options[2].split(";"); + HashMap types = new HashMap<>(); + for (String s : split) { + String[] ss = s.split("="); + types.put(ss[1], ss[0]); + } + symbols = new ArrayList<>(); + symbols.add('.'); + symbols.add('+'); + symbols.add('-'); + symbols.add('*'); + symbols.add('/'); + symbols.add('='); + symbols.add('('); + symbols.add(')'); + symbols.add(''); + + nums = new ArrayList<>(); + nums.add(""); + nums.add("һ"); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + + // ȡѡ + String[] dl = session.getPreferenceService().getStringValues("ly6_deviceGroup"); + if (dl != null && dl.length > 0) { + for (String str : dl) { + try { + String[] split1 = str.split("="); + queryName.put(split1[0], split1[1].split(";")); + } catch (Exception e) { + // TODO Auto-generated catch block + MessageBox.post("ѡly6_deviceGroup" + str + "", "ʾ", MessageBox.ERROR); + return; + } + } + String idString = ""; + + for (AIFComponentContext c : target.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision rev = bom.getItemRevision(); + String dg = property(rev, "ly6_deviceGroup"); + // 豸ϢҵѡĴ + int count1 = 0; + for (Entry entry : queryName.entrySet()) { + if (!Arrays.asList(entry.getValue()).contains(dg)) { + count1++; + } + } + if (count1 == queryName.size()) { + // ʾû + idString += dg + "(" + property(rev, "item_id") + ")"; + idString += ","; + continue; + } + } + if (idString.length() > 0) { + String newString = idString.substring(0, idString.length() - 1); + MessageBox.post("" + newString + "δҵ࣬ϵԱάϢִеտƬ", "ʾ", MessageBox.ERROR); + return; + } + } + boolean find = false; + int last = 0; + + TCComponentItemRevision proRev = target.getItemRevision(); + TCComponent aifComponentContext = proRev.getReferenceListProperty("IMAN_METarget")[0]; + String property = aifComponentContext.getProperty("object_string"); + System.out.println("name:" + property); + TCComponentItemRevision tarRev = (TCComponentItemRevision) aifComponentContext; + int countNum = 0; + List newFiles = new ArrayList(); + LinkedHashSet dataSetFiles = new LinkedHashSet(); + for (int p = 0; p < model.size(); p++) { + TCComponentDataset dataset = model.get(p); + ArrayList blist = new ArrayList<>(); + File newFile = null; + countNum += 1; + + for (AIFComponentContext c : target.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision rev = bom.getItemRevision(); + System.out.println("revType:" + rev.getType()); +// if(!rev.isTypeOf("LD6_MEProcessRevision")) + System.out.println("choice:" + choice); + if ((choice == 1 || choice == 3) && countNum == 1) { + if (!rev.getType().equals("LY6_MachineMEOPRevision")) + continue; + } + if ((choice == 1 || choice == 3) && countNum == 2) { + if (!rev.getType().equals("LY6_PostPMEOPRevision")) + continue; + } + blist.add(bom); + } + System.out.println("blist:" + blist); + System.out.println("blist:" + blist.size()); + if (blist.size() > 0) { + ArrayList slist = new ArrayList<>(); + HashMap> meopMap = new HashMap<>(); + HashMap sequences = new HashMap<>(); + for (int i = 0; i < blist.size(); i++) { + TCComponentBOMLine bom = blist.get(i); + TCComponentItemRevision rev = bom.getItemRevision(); + String name = rev.getProperty("object_name"), sequence = bom.getProperty("bl_sequence_no"); + if (sequences.containsKey(sequence)) { + if (!name.equals(sequences.get(sequence))) { + MessageBox.post(desktop, "ͬŲͬƵĹ", "ERROR", MessageBox.ERROR); + return; + } + } else { + meopMap.put(sequence, new ArrayList()); + slist.add(sequence); + sequences.put(sequence, name); + } + meopMap.get(sequence).add(bom); + } + if (slist.size() > 20) { + MessageBox.post(desktop, "ʮ޷е", "ERROR", MessageBox.ERROR); + return; + } + + TCComponentTcFile[] files = dataset.getTcFiles(); + File file = files[0].getFile(System.getProperty("java.io.tmpdir")); + // ȡjava.io.tmpdirĿ¼ΪļĿ¼ + String tempDir = System.getProperty("java.io.tmpdir"); + + // ļǰʱȷΨһ + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String timestamp = dateFormat.format(new Date()); // ǰʱȷ + int randomNum = ThreadLocalRandom.current().nextInt(1000, 9999); // һλ + String newFileName = "file_" + timestamp + "_" + randomNum + ".docx"; // ļʽ + + // µļ· + newFile = new File(tempDir, newFileName); + + try { + // ļλò + Files.copy(file.toPath(), newFile.toPath()); + System.out.println("File renamed and moved to: " + newFile.getAbsolutePath()); + + // Ҫɾԭļ + // originalFile.delete(); + } catch (IOException e) { + System.err.println("Error occurred while renaming the file: " + e.getMessage()); + } + input = new FileInputStream(newFile); + doc = new Document(input); + + ArrayList datas = new ArrayList<>(); + ArrayList words = new ArrayList<>(); + for (int i = 0; i < slist.size(); i++) { + String[] data = new String[5]; + String sequence = slist.get(i); + String name = sequences.get(sequence); + data[0] = getChineseNum(i + 1); + data[1] = name; + + ArrayList boms = meopMap.get(sequence); + StringBuilder contents = new StringBuilder(""), machine = new StringBuilder(""), + equip = new StringBuilder(""), remark = new StringBuilder(""); + TCComponent[] mecs = boms.get(0).getItemRevision().getReferenceProperty("root_activity") + .getReferenceListProperty("contents"); + mecs = TCsort(mecs, "ly6_activityNum"); + for (TCComponent mec : mecs) { + contents.append(mec.getProperty("ly6_activityNum")).append("") + .append(mec.getProperty("ly6_activityDesc")).append("\n"); + remark.append(mec.getProperty("ly6_controlPoint")).append("\n"); + } + ArrayList idSet = new ArrayList<>(); + Boolean isExit = false; + for (TCComponentBOMLine bom : boms) { + TCComponentItemRevision rev = bom.getItemRevision(); + + String dg = property(rev, "ly6_deviceGroup"); + if (!dg.isEmpty()) { + // 豸ϢҵѡĴ + for (Entry entry : queryName.entrySet()) { + if (Arrays.asList(entry.getValue()).contains(dg)) { + if (isExit) { + break; + } + machine.append(entry.getKey()); + isExit = true; + machine.append(";"); + break; + } + } + + } + + for (AIFComponentContext c : bom.getChildren()) { + TCComponentBOMLine line = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision r = line.getItemRevision(); + String id = r.getProperty("item_id"); + if (idSet.contains(id)) + continue; + idSet.add(id); + String occ = line.getProperty("bl_occ_type"); + if (occ.equals("ָ") && r.isTypeOf("LY6_TechDocRevision")) { + String t = property(r, "ly6_type"); + if (TCUtil.contains(docs, t)) + equip.append(options[3]).append(t).append("").append(id).append("\\") + .append(property(r, "ly6_docNum")).append("\n"); + } else if (occ.equals("Դ")) { + String type = r.getType(); + if (r.isTypeOf("LY6_EquipmentRevision")) { + String t = property(r, "ly6_equType"); + if (TCUtil.contains(equips, t)) + equip.append(options[3]).append(t).append("").append(id).append("\\") + .append(property(r, "ly6_drawNum")).append("\n"); + } else if (types.containsKey(type)) { + String q = property(line, "bl_quantity"); + equip.append(options[3]).append(types.get(type)).append("").append(id) + .append("\\").append(q.isEmpty() ? "1" : q).append("\\") + .append(property(r, "ly6_materialDesc")).append("\n"); + } + } + } + + TCComponentDataset word = null; + AIFComponentContext[] cs = rev.getChildren("IMAN_specification"); + for (AIFComponentContext c : cs) { + TCComponent comp = (TCComponent) c.getComponent(); + if (comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains("ռͼ")) { + word = (TCComponentDataset) comp; + break; + } + } + if (word == null) { + continue; + } + dataSetFiles.add(word); + + } + + if (contents.length() > 0) + contents.deleteCharAt(contents.length() - 1); + if (machine.length() > 0) + machine.deleteCharAt(machine.length() - 1).append("\n").insert(0, options[3] + ""); + if (equip.length() > 0) + equip.deleteCharAt(equip.length() - 1); + if (remark.length() > 0) + remark.deleteCharAt(remark.length() - 1); + data[2] = shiftRow(contents.toString(), 74).toString(); + // ⴦װ + StringBuilder builder = new StringBuilder(""); + for (TCComponentBOMLine bomLine : boms) { + if (bomLine.hasChildren()) { + for (AIFComponentContext gxBomLine : bomLine.getChildren()) { + TCComponentBOMLine line = (TCComponentBOMLine) gxBomLine.getComponent(); + String stringProperty = line.getStringProperty("bl_occ_type"); + String stringProperty2 = line.getItemRevision().getStringProperty("object_type"); + if (("MEResource".equals(stringProperty) || "Դ".equals(stringProperty)) + && (stringProperty2.equals("LY6_WorkCenterRevision"))) { + builder.append("ģ") + .append(line.getItemRevision().getProperty("object_name")).append(".") + .append(line.getItemRevision().getProperty("ly6_deviceNum")).append(";") + .append("\n"); + } + if (("MEOther".equals(stringProperty) || "ָ".equals(stringProperty))) { + builder.append("ָ飺").append(line.getItemRevision().getProperty("object_name")) + .append(";").append("\n"); + } + if (("MEResource".equals(stringProperty) || "Դ".equals(stringProperty)) + && (stringProperty2.equals("LY6_EquipmentRevision"))) { + builder.append("оߣ").append(line.getItemRevision().getProperty("ly6_partNum")) + .append("_").append(line.getItemRevision().getProperty("object_name")) + .append(";").append("\n"); + } + if (("MEResource".equals(stringProperty) || "Դ".equals(stringProperty)) + && (stringProperty2.equals("LY6_MeasureToolRevision"))) { + builder.append("ߣ").append(line.getItemRevision().getProperty("ly6_partNum")) + .append("_").append(line.getItemRevision().getProperty("object_name")) + .append(";").append("\n"); + } + } + } + } + data[3] = shiftRow(builder.toString(), 32).toString();// TODO shiftRow + data[4] = shiftRow(remark.toString(), 24).toString(); + datas.add(data); + } + Section section = doc.getSections().get(0); + tables = section.getTables(); + System.out.println("tables:" + tables.getCount()); + totalRow = 0; + first = choice > 3 ? 11 : 12; + ArrayList hights = new ArrayList<>(); + for (String[] data : datas) { + int a = rowCount(data[2], 75, first, totalRow); + int b = rowCount(data[3], 31, first, totalRow); + int c = rowCount(data[4], 24, first, totalRow); + System.out.println("rowCount" + a + "==" + b + "==" + c); + if (a >= b && a >= c) { + totalRow += a; + hights.add(a); + } else if (b >= a && b >= c) { + totalRow += b; + hights.add(b); + } else { + totalRow += c; + hights.add(c); + } + System.out.println("data" + hights.size() + "" + hights.get(hights.size() - 1)); + } + // ¼һͼֽ + int tznum = 0; + if (!create) { + int sum = tables.getCount(); + int txtsum = totalRow / 2 + totalRow % 2; + tznum = sum - txtsum; + System.out.println("tznum:" + tznum); + } + + // һεʱ򴴽ҳ ظʱ ֱ滻 ҳ + if (create) { + + System.out.println("ʼҳ"); + int count = totalRow / 2 + totalRow % 2; + if (count > 2) { + for (int i = 0; i < count - 2; i++) { + tables.add(tables.get(1).deepClone()); + // doc.getLastParagraph().setText("last\n\n"); + section.addParagraph(); + section.addParagraph(); +// System.out.println("Last:"+doc.pa); + } + } + } + + totalRow = 0; + for (int i = 0; i < datas.size(); i++) { + String[] strings = datas.get(i); + + System.out.println("totalRow" + totalRow); + + write(datas.get(i), hights.get(i));// TODO wright + } + // ݺ жĵ ǷڲҪĿҳ ɾ + cleanEmptyTables(doc); + + // ظʱ Ѿڵͼֽɾ µ + if (!create) { + System.out.println("ʼɾͼֽ"); + System.out.println("count:" + tables.getCount()); + int tznum2 = tznum; + for (int a = tables.getCount() - 1; tznum2 > 0; a--, tznum2--) { + tables.removeAt(a); + } + // Ϊɾ񣬻пвԸɾն + ParagraphCollection paragraphs = section.getParagraphs(); + // һ俪ʼ + for (int n = paragraphs.getCount() - 1; n >= 0; n--) { + if (tznum < 0) { + break; + } + Paragraph paragraph = paragraphs.get(n); + tznum--; + // ǷΪ + if (paragraph.getText().trim().isEmpty()) { + // ɾն + paragraphs.remove(paragraph); + + } else { + // ǿնʱ˳ѭ + break; + } + } + } + + output = new FileOutputStream(newFile.getPath()); + doc.saveToFile(output, FileFormat.Docx_2010); + doc.dispose(); + TCUtil.deleteWarning(newFile); + input.close(); + output.close(); + String t = ""; + + if (choice == 3 && countNum == 2) { + t = "-T04-"; + } else { + t = "-T02-"; + } + + if (choice == 3) + t += "L"; + + StringBuilder builder = new StringBuilder(""); + String no = new StringBuilder("LJ.Y-").append(property(tarRev, "ly6_partNum")).append(t) + .append(property(proRev, "ly6_sequence_Comp")).toString(); + + builder.append("ͻ=").append(value(property(tarRev, "ly6_clientName"), 10)).append("|ͺ=") + .append(value(property(tarRev, "ly6_specsModel"), 10)).append("|ͼ=") + .append(value(property(tarRev, "ly6_partNum"), 24)).append("|=") + .append(value(property(tarRev, "object_name"), 24)).append("|ļ=").append(value(no, 28)) + .append("|汾=").append(value(property(tarRev, "ly6_drawRev"), 28)).append("|ļ=") + .append(property(tarRev, "item_revision_id")) + + .append("|ƺ=").append(property(tarRev, "ly6_partMaterialQ")).append("|ëߴ=") + .append(property(proRev, "ly6_blankSize")).append("|=") + .append(property(tarRev, "ly6_netWeight")).append("|ע=") + .append(property(proRev, "ly6_notes")).append("|ë=") + .append(property(proRev, "ly6_blanktype")).append("|Ƴ=") + .append(property(proRev, "ly6_madePartNum")).append("|ë=") + .append(property(tarRev, "ly6_grossWeight")).append("|ÿ̨=") + .append(property(proRev, "ly6_eachNum")) + + .append("|װ=").append(value(property(tarRev, "ly6_equType"), 28)).append("|װͼ=") + .append(value(property(tarRev, "ly6_partNum"), 46)).append("|װͼŰ汾=") + .append(value(property(tarRev, "ly6_drawRev"), 24)).append("|װ=") + .append(property(tarRev, "object_name")).append("|ԭ=") + .append(property(proRev, "ly6_reason")).append("|ǷҪò=") + .append(property(proRev, "ly6_ifConcession")).append("|λ=") + .append(property(proRev, "ly6_workpieceStation")).append("|÷Χ=") + .append(property(proRev, "ly6_scope")).append("|ģ״̬=") + .append(property(proRev, "ly6_progsimstat")).append("|=") + .append(property(proRev, "ly6_type")); + + for (int j = 0; j < meopMap.size(); j++) { + builder.append("|").append(j + 1).append("=").append(sequences.get(slist.get(j)));// .getItemRevision().getProperty("object_name") + } + File saveFile = new File(System.getProperty("java.io.tmpdir") + "\\word.txt"); + if (saveFile.exists()) { + saveFile.delete(); + } + saveFile.createNewFile(); + buffered = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile, true))); + buffered.write(builder.toString()); + buffered.close(); + String pluginsDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); + pluginsDir = pluginsDir.substring(1, pluginsDir.lastIndexOf("/")); + runWsf(pluginsDir + "\\SubstMacros-MSWord_KP.wsf", + new String[] { newFile.getPath(), saveFile.getPath() }); + newFiles.add(newFile); + } + if (p == model.size() - 1) { + for (TCComponentDataset word : dataSetFiles) { + FileInputStream input2 = null; + try { + File file2 = word.getTcFiles()[0].getFile(System.getProperty("java.io.tmpdir")); + String pluginsDir = this.getClass().getProtectionDomain().getCodeSource().getLocation() + .getPath(); + pluginsDir = pluginsDir.substring(1, pluginsDir.lastIndexOf("/")); + File saveFile = new File(System.getProperty("java.io.tmpdir") + "\\word.txt"); + runWsf(pluginsDir + "\\SubstMacros-MSWord_KP.wsf", + new String[] { file2.getPath(), saveFile.getPath() }); + newFiles.add(file2); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, "" + e.getMessage(), "ERROR", MessageBox.ERROR); + } finally { + if (input2 != null) + input2.close(); + } + } + } + + } + if (newFiles.size() == 0) { + return; + } + + // 鿴·Ƿijδı֪ͨECNĸĺϵ + String changeID = ""; + AIFComponentContext[] whereReferenced = proRev.whereReferenced(); + for (AIFComponentContext componentContext : whereReferenced) { + TCComponent component = (TCComponent) componentContext.getComponent(); + System.out.println("component.getType():" + component.getType()); + if ("LY6_CNRevision".equals(component.getType())) { + // δ + if (!KUtil.isTCM(component)) { + // ȡϵµĶ + TCComponent[] referenceListProperty = component.getReferenceListProperty("CMHasSolutionItem"); + for (TCComponent component2 : referenceListProperty) { + if (proRev.getStringProperty("item_id").equals(component2.getStringProperty("item_id"))) { + changeID = component.getStringProperty("item_id"); + break; + } + } + if (!changeID.isEmpty()) { + break; + } + } + } + } + File mergedFile = null; + if (newFiles.size() > 1) { + // ϲwordĵ + mergedFile = mergeWordTables(newFiles); + + } else { + mergedFile = newFiles.get(0); + } + + int countY = 0; // ¼ " X ҳ" ļ + + + int totalPages = 0; // ͳҳ + + // һͳҳ + try (FileInputStream fis = new FileInputStream(mergedFile)) { + Document document = new Document(fis); + + // н + for (int sectionIndex = 0; sectionIndex < document.getSections().getCount(); sectionIndex++) { + Section section = document.getSections().get(sectionIndex); + TableCollection tables = section.getTables(); + + // б + for (int i = 0; i < tables.getCount(); i++) { + Table table = tables.get(i); + RowCollection rows = table.getRows(); + int rowc = rows.getCount(); + + if (rowc >= 3) { // ȷ3ԱԽ쳣 + totalPages++; // ͳҪ " X ҳ" ı + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + // ڶ " X ҳ" " Y ҳ" + try (FileInputStream fis = new FileInputStream(mergedFile)) { + Document document = new Document(fis); + + // н + for (int sectionIndex = 0; sectionIndex < document.getSections().getCount(); sectionIndex++) { + Section section = document.getSections().get(sectionIndex); + TableCollection tables = section.getTables(); + + // б + for (int i = 0; i < tables.getCount(); i++) { + Table table = tables.get(i); + RowCollection rows = table.getRows(); + int rowc = rows.getCount(); + + if (rowc >= 3) { // ȷ3ԱԽ쳣 + try { + // " X ҳ" ڵڶеһ + table.getRows().get(rowc - 2).getCells() + .get(table.getRows().get(rowc - 2).getCells().getCount() - 1) + .getParagraphs().get(0).setText(" " + ++countY + " ҳ"); + } catch (Exception e) { + System.err.println("Error setting ' " + countY + " ҳ' in table: " + e.getMessage()); + } + + try { + // " Y ҳ" ڵеһ + table.getRows().get(rowc - 3).getCells() + .get(table.getRows().get(rowc - 3).getCells().getCount() - 1) + .getParagraphs().get(0).setText(" " + totalPages + " ҳ"); + } catch (Exception e) { + System.err.println("Error setting ' " + totalPages + " ҳ' in table: " + e.getMessage()); + } + } else { + System.out.println("Table " + (i + 1) + " in section " + (sectionIndex + 1) + + " does not have enough rows to set page numbers."); + } + } + } + + // ޸ĺĵԭļΪļ + document.saveToFile(mergedFile.getAbsolutePath(), FileFormat.Docx_2013); + System.out.println( + "Page numbers have been added successfully to the tables in: " + mergedFile.getAbsolutePath()); + + } catch (IOException e) { + e.printStackTrace(); + } + + // Ƴһвʹ + mergedFile = removeFirstLineAndShiftUp(mergedFile); + + String name = ""; + if (choice == 1) { + name = getDatasetName(proRev, "LY_Exportname1_Mapping", changeID); + } else if (choice == 2) { + name = getDatasetName(proRev, "LY_Exportname3_Mapping", changeID); + } else if (choice == 3) { + name = getDatasetName(proRev, "LY_Exportname4_Mapping", changeID); + } + System.out.println("name:" + name); + + boolean create = true; + for (AIFComponentContext c : proRev.getChildren("IMAN_specification")) { + TCComponent comp = (TCComponent) c.getComponent(); + if (comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains(oldName)) { + KUtil.setByPass(session, true); + proRev.remove("IMAN_specification", comp); + KUtil.setByPass(session, false); + break; + } + } + if (create) { + File namedref = new File(mergedFile.getParent() + "\\" + name + ".docx"); + if (namedref.exists()) + namedref.delete(); + mergedFile.renameTo(namedref); + System.out.println("newFile:" + namedref.getPath()); + TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService() + .getTypeComponent("Dataset"); + TCComponentDataset dataset = compType.create(name, "", "MSWordX"); + dataset.setFiles(new String[] { namedref.getAbsolutePath() }, new String[] { "word" }); + proRev.add("IMAN_specification", dataset); + } + + MessageBox.post(desktop, "", "INFO", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, "" + e.getMessage(), "ERROR", MessageBox.ERROR); + } finally { + if (input != null) + input.close(); + if (output != null) + output.close(); + if (buffered != null) + buffered.close(); + } + } + + private void cleanEmptyTables(Document doc) { + // ȡĵенڣSection + SectionCollection sections = doc.getSections(); + for (int i = sections.getCount() - 1; i >= 0; i--) { + Section section = sections.get(i); + TableCollection tables = section.getTables(); + for (int j = tables.getCount() - 1; j >= 0; j--) { + Table table = tables.get(j); + if (isFourthRowEmpty(table)) { + // ܲĿն + ParagraphCollection paragraphs = section.getParagraphs(); + for (int n = paragraphs.getCount() - 1; n >= 0; n--) { + Paragraph paragraph = paragraphs.get(n); + if (paragraph.getText().trim().isEmpty()) { + paragraphs.remove(paragraph); + } + } + tables.removeAt(j); + } + } + } + } + + private boolean isFourthRowEmpty(Table table) { + // ǷУҵǷΪ + if (table.getRows().getCount() < 4) { + return true; + } + + TableRow fourthRow = table.getRows().get(3); // ȡ + CellCollection cells = fourthRow.getCells(); // ȡееԪ + + // ееԪ񣬼ǷΪ + for (int k = 0; k < cells.getCount(); k++) { + TableCell cell = cells.get(k); + String cellText = getCellText(cell).trim(); + if (!cellText.isEmpty()) { + return false; + } + } + + return true; + } + + private String getCellText(TableCell cell) { + // ȡԪеж䣬ǵıƴ + StringBuilder textBuilder = new StringBuilder(); + ParagraphCollection paragraphs = cell.getParagraphs(); + for (Object obj : paragraphs) { + if (obj instanceof Paragraph) { + Paragraph paragraph = (Paragraph) obj; + textBuilder.append(paragraph.getText()); + } + } + return textBuilder.toString(); + } + + /** + * ƳWordĵĵһ֣зȻ󱣴Ϊµļ + * + * @param file Wordĵļ + * @return ļ + * @throws IOException 쳣 + */ + public static File removeFirstLineAndShiftUp(File file) throws IOException { + if (file == null || !file.exists() || !file.isFile()) { + throw new IllegalArgumentException("Invalid file parameter."); + } + + // ʹ try-with-resources ȷԴȷر + try (FileInputStream fis = new FileInputStream(file); XWPFDocument document = new XWPFDocument(fis)) { + + // ȡĵԪ + List paragraphs = document.getParagraphs(); + + if (!paragraphs.isEmpty()) { + // Ƴһ + XWPFParagraph firstParagraph = paragraphs.get(0); + document.removeBodyElement(document.getBodyElements().indexOf(firstParagraph)); + } + + // ļ޸ĺĵ + Path outputPath = Paths.get(file.getParent(), "modified_" + file.getName()); + File newFile = outputPath.toFile(); + + try (FileOutputStream fos = new FileOutputStream(newFile)) { + document.write(fos); + } + + System.out.println("The first line has been removed successfully in: " + newFile.getAbsolutePath()); + return newFile; + } catch (IOException e) { + // ṩϸĴϢ + System.err.println("An error occurred while processing the file at path: " + file.getAbsolutePath()); + e.printStackTrace(); + throw e; // ׳쳣Աߴ + } + } + + /** + * ϲWordļеݵһµWordļС + * + * @param newFiles ҪϲWordļб + * @return غϲļ + * @throws IOException IO쳣 + */ + private static File mergeWordTables(List newFiles) throws IOException { + // һµʱļΪļ + File outputFile = File.createTempFile("merged_output", ".docx"); + + // ӿհģ崴һµDocument + Document document = new Document(newFiles.get(0).getAbsolutePath()); + newFiles.remove(0); + + for (File file : newFiles) { + try (FileInputStream fis = new FileInputStream(file)) { + // ҪдWordĵ + com.spire.doc.Document docToMerge = new com.spire.doc.Document(fis); + // ںϲһĵ֮ǰһ½ڣҳ + Section newSection = document.addSection(); + // ÿ + for (int i = 0; i < docToMerge.getSections().getCount(); i++) { + Section s = docToMerge.getSections().get(i); + Body body = s.getBody(); + // еӶ󣨶䡢ȣ + for (int j = 0; j < body.getChildObjects().getCount(); j++) { + DocumentObject obj = body.getChildObjects().get(j); + // ÿӵĵһ + newSection.getBody().getChildObjects().add(obj.deepClone()); + } + } + } catch (Exception e) { + // 񲢴Aspose.Words׳쳣 + throw new IOException("Error processing file: " + file.getAbsolutePath(), e); + } + } + + // ϲĵ浽ļ + document.saveToFile(outputFile.getAbsolutePath(), FileFormat.Docx_2013); + + return outputFile; + } + + private String getDatasetName(TCComponentItemRevision revision, String name, String id) throws TCException { + String[] stringValues = session.getPreferenceService().getStringValues(name); + if (stringValues == null || stringValues.length == 0) { + MessageBox.post("ѡ" + name + "òȷ", "ERROR", MessageBox.ERROR); + return null; + } + if (!stringValues[0].contains("ӹտƬ") && !stringValues[0].contains("װտƬ") + && !stringValues[0].contains("ʱտƬ")) { + MessageBox.post("ѡ" + name + "òȷ,ȱٹؼʡ*տƬ", "ERROR", MessageBox.ERROR); + return null; + } + System.out.println(stringValues[0]); + String[] split = stringValues[0].split("\\|"); + StringBuilder names = new StringBuilder(""); + for (String str : split) { + String[] split2 = str.split("\\."); + String value = ""; + if (split2.length == 1) { + if (split2[0].contains("ECNID")) { + if (!id.isEmpty()) { + value = split2[0].replaceAll("ECNID", id); + } else { + value = ""; + } + + } else { + value = split2[0]; + } + } else if (split2.length == 2) { + if ("item".equals(split2[0])) { + value = property(revision.getItem(), split2[1]); + } else if ("rev".equals(split2[0])) { + value = property(revision, split2[1]); + } + + } else if (split2.length == 4) { + // ȡϵ + TCComponent[] referenceListProperty = revision.getReferenceListProperty(split2[0]); + for (TCComponent component : referenceListProperty) { + if (split2[1].equals(component.getType())) { + if ("item".equals(split2[2])) { + value = property(((TCComponentItemRevision) component).getItem(), split2[3]); + } else if ("rev".equals(split2[2])) { + value = property((TCComponentItemRevision) component, split2[3]); + } + } + } + } else { + MessageBox.post("ѡ" + name + "", "ERROR", MessageBox.ERROR); + return null; + } + names.append(value); + } + return names.toString(); + } + + private String getChineseNum(int num) throws Exception { + String value = ""; + int ten = num / 10, n = num % 10; + if (ten > 1) + value += nums.get(ten) + "ʮ"; + else if (ten == 1) + value += "ʮ"; + value += nums.get(n); + return value; + } + + private String property(TCComponent comp, String prop) { + try { + TCProperty tcprop = comp.getTCProperty(prop); + if (tcprop == null) + return ""; + return comp.getProperty(prop); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + private String value(String str, int max) { + int len = str.length(); + if (len < 1 || len >= max) + return str; + int count = 0; + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) + count += 1; + else + count += 2; + } + if (count >= max) + return str; + StringBuilder sb = new StringBuilder(str); + for (int i = 0; i < (max - count) / 2; i++) { + sb.insert(0, " ").append(" "); + } + return sb.toString(); + } + + private int rowCount(String str) { + if (str == null) + return 0; + return str.replaceAll("\n", "\n0").length() - str.length(); + } + + private int rowCount(String str, int max, int first, int row) { + System.out.println("str:" + str); + System.out.println("max:" + max); + System.out.println("first:" + first); + System.out.println("row:" + row); + int r = rowCount(str); + System.out.println("r:" + r); + int f2 = first * 2 + 1; + System.out.println("f2:" + f2); + if (row == 0) { + if (r > f2) + return 2 + rowCount(r - f2, true); + else if (r > first) + return 2; + else + return 1; + } else if (row == 1) { + if (r > first) + return 1 + rowCount(r - first, true); + else + return 1; + } else { + return rowCount(r, row % 2 == 0); + } + } + + private int rowCount(int row, boolean up) { + if (row <= 13) + return 1; + else { + if (up) { + if (row <= 27) + return 2; + else + return 2 + rowCount(row - 27, true); + } else { + return 1 + rowCount(row - 13, true); + } + } + } + + private StringBuilder shiftRow(String str, int max) { + str = str.replaceAll("\n\n", "\n"); + int len = str.replaceAll("\n", "").length(); + if (len < max / 2) + return new StringBuilder(str); + + if (str.indexOf("\n") < 0) { + StringBuilder sb = new StringBuilder(str); + int count = 1; + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || symbols.contains(c)) + count += 1; + else + count += 2; + if (count >= max) {// && count= '0' && c <= '9') || (c >= 'a' && c <= 'z') || symbols.contains(c)) + count += 1; + else + count += 2; + if (count >= max) {// && count 0 && sb.substring(sb.length() - 1).equals("\n")) + sb.deleteCharAt(sb.length() - 1); + return sb; + } + } + + private void write(String[] data, int h) throws Exception { + Table table = tables.get(totalRow / 2); + int uod = totalRow % 2; + int row = totalRow > 1 ? (3 + uod) : (5 + uod);// TODO + if (totalRow < 2 && choice > 3) + row += 2; + + if (h < 2) { + for (int i = 0; i < 5; i++) { + System.out.println("1:" + data[i]); + TableCell tableCell = table.get(row, i); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for (int n = 0; n < paragraphs.getCount(); n++) { + Paragraph paragraph = paragraphs.get(n); + paragraph.setText(""); + // ȷûлз + String paragraphText = paragraph.getText(); + if (paragraphText != null && paragraphText.contains("\n")) { + paragraphText = paragraphText.replace("\n", ""); + paragraph.setText(paragraphText); // ı + } + } + + setText(table.get(row, i).getParagraphs().get(0), data[i]); + } + totalRow++; + } else { + if (uod == 0) { + if (h < 3) { + for (int j = 0; j < 5; j++) { + + TableCell tableCell = table.get(row, j); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for (int n = 0; n < paragraphs.getCount(); n++) { + Paragraph paragraph = paragraphs.get(n); + paragraph.setText(""); + // ȷûлз + String paragraphText = paragraph.getText(); + if (paragraphText != null && paragraphText.contains("\n")) { + paragraphText = paragraphText.replace("\n", ""); + paragraph.setText(paragraphText); // ı + } + } +// System.out.println("getParagraphs"+table.get(row, j).getParagraphs().getCount()); +// ParagraphCollection para = table.get(row, j).getParagraphs(); +// if(para.getCount()==0) { +// para. +// } + System.out.println("2:" + data[j]); + setText(table.get(row, j).getParagraphs().get(0), data[j]); + table.applyVerticalMerge(j, row, row + 1); + } + totalRow += 2; + } else { + String[] data2 = new String[5]; + data2[0] = ""; + data2[1] = ""; + int each = (totalRow > 1 ? 13 : first); + each = each * 2; + System.out.println("3.1:" + data[0]); + setText(table.get(row, 0).getParagraphs().get(0), data[0]); + table.applyVerticalMerge(0, row, row + 1); + System.out.println("3.2:" + data[1]); + setText(table.get(row, 1).getParagraphs().get(0), data[1]); + table.applyVerticalMerge(1, row, row + 1); + for (int j = 2; j < 5; j++) { + TableCell tableCell = table.get(row, j); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for (int n = 0; n < paragraphs.getCount(); n++) { + Paragraph paragraph = paragraphs.get(n); + paragraph.setText(""); + // ȷûлз + String paragraphText = paragraph.getText(); + if (paragraphText != null && paragraphText.contains("\n")) { + paragraphText = paragraphText.replace("\n", ""); + paragraph.setText(paragraphText); // ı + } + } + if (rowCount(data[j]) <= each) { + System.out.println("4.1:" + data[j]); + setText(table.get(row, j).getParagraphs().get(0), data[j]); + } + + else { + int cut = TCUtil.findChar(data[j], '\n', each); + System.out.println("4.2:" + data[j].substring(0, cut)); + setText(table.get(row, j).getParagraphs().get(0), data[j].substring(0, cut)); + data2[j] = data[j].substring(cut + 1); + } + table.applyVerticalMerge(j, row, row + 1); + } + totalRow += 2; + if (data2[2] != null || data2[3] != null || data2[4] != null) { + write(data2, h - 2);// wright + } + + } + } else { + + String[] data2 = new String[5]; + data2[0] = ""; + data2[1] = ""; + int each = (totalRow > 1 ? 13 : first); + System.out.println("5.1:" + data[0]); + table.get(row, 0).getParagraphs().get(0).setText(""); + setText(table.get(row, 0).getParagraphs().get(0), data[0]); + + System.out.println("5.2:" + data[1]); + table.get(row, 1).getParagraphs().get(0).setText(""); + setText(table.get(row, 1).getParagraphs().get(0), data[1]); + for (int j = 2; j < 5; j++) { + TableCell tableCell = table.get(row, j); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for (int n = 0; n < paragraphs.getCount(); n++) { + Paragraph paragraph = paragraphs.get(n); + paragraph.setText(""); + // ȷûлз + String paragraphText = paragraph.getText(); + if (paragraphText != null && paragraphText.contains("\n")) { + paragraphText = paragraphText.replace("\n", ""); + paragraph.setText(paragraphText); // ı + } + } + if (rowCount(data[j]) <= each) { + System.out.println("6.1:" + data[j]); + setText(table.get(row, j).getParagraphs().get(0), data[j]); + } + + else { + int cut = TCUtil.findChar(data[j], '\n', each); + System.out.println("6.2:" + data[j].substring(0, cut)); + setText(table.get(row, j).getParagraphs().get(0), data[j].substring(0, cut)); + data2[j] = data[j].substring(cut + 1); + } + } + totalRow += 1; + if (data2[2] != null || data2[3] != null || data2[4] != null) { + write(data2, h - 1);// wright + } + + } + } + } + + private void setText(Paragraph parag, String data) { + if (data == null) { + return; + } else if (data.contains("", t)); + String s5 = data.substring(data.indexOf(">", t) + 1); + setText(parag, s1); + StringBuilder sb = new StringBuilder("$"); + sb.append(s2).append("_{").append(s3).append("}^{").append(s4).append("}$"); + + OfficeMath officeMath2 = new OfficeMath(doc); + parag.getItems().add(officeMath2); + officeMath2.fromLatexMathCode(sb.toString()); + + setText(parag, s5); + } else if (data.contains("")) { + String[] split = data.split(""); + for (int j = 0; j < split.length; j += 2) { +// parag.appendText(split[j]); + setText(parag, split[j]); + if (j + 1 < split.length) + parag.appendText(split[j + 1]).getCharacterFormat().setSubSuperScript(SubSuperScript.Super_Script);// TODO + } + } else if (data.contains("<#G>")) { + String[] split = data.split("<#G>"); + for (int i = 0; i < split.length; i++) { +// parag.appendText(split[j]); + setText(parag, split[i]); + if (i + 1 < split.length) { +// ShapeObject triangle = parag.appendShape(10, 5, ShapeType.Triangle); +// +// triangle.setStrokeColor(Color.BLACK); +// triangle.setFillColor(Color.WHITE); +//// triangle.setVerticalPosition(50); +//// triangle.setHorizontalPosition(170);S +// triangle.setRotation(225); +// +// triangle.setTextWrappingStyle(TextWrappingStyle.Through); + getHTML(parag, "<#G>"); + } + } + } else { + String[] options = session.getPreferenceService().getStringValues("connor_gdt_custom_symbols"); + boolean hast = false; + for (String s : options) { + String[] ss = s.split("="); + String sy = ""; + if (ss.length == 2 && data.contains(ss[0])) { + sy = ss[0]; + hast = true; + } else if (ss.length == 3 && data.contains(ss[1])) { + sy = ss[1]; + hast = true; + } + if (sy.isEmpty()) + continue; + String[] split = data.split(sy); + for (int i = 0; i < split.length; i++) { + setText(parag, split[i]); + if (i + 1 < split.length) { + getHTML(parag, sy); + } + } + + } + if (!hast) + parag.appendText(data); + } + } + + private void getHTML(Paragraph parag, String txt) { + String htmlstring = KGenerateGDTHTML.generatePage(txt); + System.out.println(txt + " == " + htmlstring); + parag.appendHTML(htmlstring); +// String out = System.getProperty("java.io.tmpdir") + "\\out.html"; +// File htmlfile = new File(out); +// if(htmlfile.exists()) +// htmlfile.delete(); +// htmlfile.createNewFile(); +// FileWriter fos = new FileWriter(htmlfile); +// fos.write(htmlstring); +// fos.close(); + +// Document doc = new Document(); +// doc.loadFromFile(out, FileFormat.Html, XHTMLValidationType.None); +// Paragraph d = doc.getSections().get(0).getParagraphs().get(0); + +// parag. + } + + private TCComponent[] TCsort(TCComponent[] TCComponent, String property) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for (TCComponent comp : TCComponent) { + try { + map.put(comp, comp.getProperty(property)); + } catch (Exception e) { + e.printStackTrace(); + } + } + // ͨArrayList캯map.entrySet()תlist + List> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { +// return mapping1.getValue().compareTo(mapping2.getValue()); + int v1 = Integer.parseInt(mapping1.getValue()); + int v2 = Integer.parseInt(mapping2.getValue()); + return v1 - v2; + } + }); + TCComponent = new TCComponent[count]; + int i = 0; + for (Map.Entry mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + + public static void runWsf(String wsfPath, String[] paras) throws Exception { + ArrayList cmdVector = new ArrayList<>(); + cmdVector.add("wscript"); + cmdVector.add(wsfPath); + for (String para : paras) { + cmdVector.add(para); + } + StringBuilder builder = new StringBuilder("wscript ").append(wsfPath).append(" ").append(paras[0]).append(" ") + .append(paras[1]); + System.out.println(builder.toString()); + String[] cmd = (String[]) cmdVector.toArray(new String[cmdVector.size()]); +// for (int i = 0; i < cmd.length; i++) { +// System.out.println(cmd[i]); +// } + Process process = Runtime.getRuntime().exec(cmd); + process.waitFor(); +// MessageBox.post("Success!","INFORMATION",MessageBox.INFORMATION); +// Runtime.getRuntime().exec(paras[0]); + } +} diff --git a/src/com/connor/ly/process2/ProcessWordExportHandler.java b/src/com/connor/ly/process2/ProcessWordExportHandler.java new file mode 100644 index 0000000..e06d825 --- /dev/null +++ b/src/com/connor/ly/process2/ProcessWordExportHandler.java @@ -0,0 +1,228 @@ +package com.connor.ly.process2; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.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.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class ProcessWordExportHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("ProcessWordExportHandler"); +// new Thread() { +// public void run() { +// } +// }.start(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent target = app.getTargetComponent(); + TCComponentBOMLine bomLine = null; + TCComponentItemRevision revision = null; + if(target instanceof TCComponentItemRevision) { + //bom + revision = (TCComponentItemRevision)target; + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + bomLine = view.setWindowTopLine(revision.getItem(), revision, null, null); + } else if (target instanceof TCComponentBOMLine){ + bomLine = (TCComponentBOMLine)target; + revision = bomLine.getItemRevision(); + } else { + MessageBox.post(desktop, "ѡ汾е", "ERROR", MessageBox.ERROR); + return null; + } + + //ȡѡ жѡ + String[] values = session.getPreferenceService().getStringValues("LY_ExportMenu_Template_Mapping"); + if(values == null || values.length == 0) { + MessageBox.post(desktop, "ѡLY_ExportMenu_Template_Mapping", "ERROR", MessageBox.ERROR); + return null; + } + Map typeMap = new HashMap(); + Map dataSetMap = new HashMap(); + for(String value : values) { + String[] split = value.split("="); + typeMap.put(split[0], split[2]); + dataSetMap.put(split[0], split[1]); + } + String name = ""; + String id = arg0.getCommand().getId(); + int type = Integer.parseInt(id.substring(id.length()-8, id.length()-7)); + + if(id.equals("ProcessWordExport1Handler")){//000590 + name = "ӹտƬ"; + }else if(id.equals("ProcessWordExport2Handler")) { + name = "װտƬ"; + }else if(id.equals("ProcessWordExport3Handler")) { + name = "ʱտƬ"; + } + if(!typeMap.get(name).equals(revision.getType())) { + MessageBox.post(desktop, "ѡȷİ汾ͺִйտƬ", "ERROR", MessageBox.ERROR); + return null; + } + + if(id.equals("JJProcessWordExport1Handler") || id.equals("GZProcessWordExport1Handler")) { + TCComponent[] referenceListProperty = revision.getReferenceListProperty("IMAN_METarget"); + if(referenceListProperty == null || referenceListProperty.length == 0) { + MessageBox.post(desktop, "ѡжĿϵΪ", "ERROR", MessageBox.ERROR); + return null; + } + String property = referenceListProperty[0].getProperty("ly6_partNum"); + String property2 = revision.getProperty("ly6_partNum"); + String property3 = referenceListProperty[0].getProperty("ly6_drawRev"); + String property4 = revision.getProperty("ly6_drawRev"); + if(property != property2 || property3 != property4) { + if(referenceListProperty == null || referenceListProperty.length == 0) { + MessageBox.post(desktop, "·߰汾ϼź汾Ŀϵļšͼֽ汾һ£!", "ERROR", MessageBox.ERROR); + return null; + } + } + + } + + + + //2024 6 3 hcj ǵڶεտƬʱ򣬲ٴģлȡݼֱʹõǰϵµݼļ + ArrayList modelList = new ArrayList(); + + Boolean create = true; + for(AIFComponentContext c : bomLine.getItemRevision().getChildren("IMAN_specification")) { + TCComponent comp = (TCComponent)c.getComponent(); + System.out.println("ݼƣ"+comp.getProperty("object_name")); + System.out.println("ɸѡƣ"+name); + System.out.println("Ƿ"+comp.getProperty("object_name").contains(name)); + if(comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains(name)) { + create = false; + modelList.add((TCComponentDataset)comp); + break; + } + } + if(create) { + //һεտƬ ʹģļ + String ids = dataSetMap.get(name); + String[] split = ids.split(";"); + for(String idString : split) { + TCComponentDataset model = null; + TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent("Item"); + TCComponentItem[] item = itemType.findItems(idString); + if(item==null || item.length==0) { + MessageBox.post(desktop, "ѡConnor_ExportMenu_Template_Mappingòȷ", "ERROR", MessageBox.ERROR); + return null; + } + AIFComponentContext[] comps = item[0].getLatestItemRevision().getChildren("IMAN_specification"); + if(comps.length==0) { + MessageBox.post(desktop, ""+id+"°汾δҵWordģ", "ERROR", MessageBox.ERROR); + return null; + } + + for(AIFComponentContext c : comps) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.isTypeOf("MSWordX")) { + model = (TCComponentDataset) comp; + break; + } + } + if(model==null) { + MessageBox.post(desktop, ""+id+"°汾δҵWordģ", "ERROR", MessageBox.ERROR); + return null; + } + modelList.add(model); + } + + } + + String[] options = session.getPreferenceService().getStringValues("LY_GYKP_types"); + System.out.println(options.length); + if(options==null || options.length<4) { + MessageBox.post(desktop, "ѡLY_GYKP_typesòȷ", "ERROR", MessageBox.ERROR); + return null; + } + + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } + + public Object getWord(String id,TCComponentBOMLine bomLine,TCSession session,AIFDesktop desktop,TCComponentDataset model,Boolean create,String[] options) throws ExecutionException { + + + try { + + String option = ""; + String name = ""; + int type = Integer.parseInt(id.substring(id.length()-8, id.length()-7)); + if(id.equals("ProcessWordExport1Handler")){//000590 + option = "ӹտƬ"; + name = "ӹտƬ"; + }else if(id.equals("ProcessWordExport2Handler")) { + option = "տƬ"; + name = "տƬ"; + }else if(id.equals("ProcessWordExport3Handler")) { + option = "װտƬ"; + name = "װտƬ"; + }else if(id.equals("ProcessWordExport4Handler")) { + option = "ʱӹտƬ"; + name = "ӹʱտƬ"; + }else { + option = "ʱտƬ"; + name = "ʱտƬ"; + } + TCComponentItemRevision rev = bomLine.getItemRevision(); + if(type > 3 && !rev.isTypeOf("LD6_LSMEProcessRevision")) { + MessageBox.post(desktop, "ѡʱ·BOMе", "ERROR", MessageBox.ERROR); + return null; + } + TCComponent[] mets = rev.getReferenceListProperty("IMAN_METarget"); + if(mets==null || mets.length==0) { + MessageBox.post(desktop, "ѡδĿ꣬!", "ERROR", MessageBox.ERROR); + return null; + } + if(type==3) { + if(!mets[0].getProperty("ld6_drawNum").equals(rev.getProperty("ld6_clientPartNum"))) { + MessageBox.post(desktop, "·߰汾ĿϵĹװͼŲһ£!", "ERROR", MessageBox.ERROR); + return null; + } + }else { + if(!mets[0].getProperty("ld6_clientPartNum").equals(rev.getProperty("ld6_clientPartNum")) + || !mets[0].getProperty("ld6_clientPartRev").equals(rev.getProperty("ld6_clientPartRev"))) { + MessageBox.post(desktop, "·߰汾ź汾Ŀϵš汾һ£!", "ERROR", MessageBox.ERROR); + return null; + } + } + + ProcessWordExportOperation operation = new ProcessWordExportOperation(session, bomLine, model, type, options,name,create); + session.queueOperation(operation); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ly/process2/ProcessWordExportOperation.java b/src/com/connor/ly/process2/ProcessWordExportOperation.java new file mode 100644 index 0000000..5d0bfe9 --- /dev/null +++ b/src/com/connor/ly/process2/ProcessWordExportOperation.java @@ -0,0 +1,1188 @@ +package com.connor.ly.process2; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ThreadLocalRandom; + +import com.spire.doc.Document; +import com.spire.doc.FileFormat; +import com.spire.doc.Section; +import com.spire.doc.Table; +import com.spire.doc.TableCell; +import com.spire.doc.collections.ParagraphCollection; +import com.spire.doc.collections.RowCollection; +import com.spire.doc.collections.TableCollection; +import com.spire.doc.documents.Paragraph; +import com.spire.doc.documents.SubSuperScript; +import com.spire.doc.fields.omath.OfficeMath; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +import cn.net.connor.std.gdtex.KGenerateGDTHTML; +import processRevision.KUtil; +import processRevision.TCUtil; + + +public class ProcessWordExportOperation extends AbstractAIFOperation { + + private TCSession session; + private TCComponentDataset model; + private TCComponentBOMLine target; + private ArrayList nums; + private int choice; + private String[] options; + private TableCollection tables; + private int totalRow; + private int first; + private ArrayList symbols; + private Document doc; + private String oldName; + private Map queryName = new HashMap(); + private Boolean create; +// private static final int ROW = 12; + + public ProcessWordExportOperation(TCSession session, TCComponentBOMLine target, TCComponentDataset model, int type, + String[] options, String name, Boolean create) { + this.session = session; + this.model = model; + this.target = target; + this.choice = type; + this.options = options; + this.oldName = name; + this.create = create; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + FileInputStream input = null; + FileOutputStream output = null; + BufferedWriter buffered = null; + try { + String[] equips = options[0].split(";"); + String[] docs = options[1].split(";"); + String[] split = options[2].split(";"); + HashMap types = new HashMap<>(); + for (String s : split) { + String[] ss = s.split("="); + types.put(ss[1], ss[0]); + } + symbols = new ArrayList<>(); + symbols.add('.'); + symbols.add('+'); + symbols.add('-'); + symbols.add('*'); + symbols.add('/'); + symbols.add('='); + symbols.add('('); + symbols.add(')'); + symbols.add(''); + + nums = new ArrayList<>(); + nums.add(""); + nums.add("һ"); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + ArrayList blist = new ArrayList<>(); + + //ȡѡ + String[] dl = session.getPreferenceService().getStringValues("ld6_deviceGroup"); + if(dl == null || dl.length == 0) { + MessageBox.post("ѡld6_deviceGroup", "ʾ", MessageBox.ERROR); + return; + } + for (String str : dl) { + try { + String[] split1 = str.split("="); + queryName.put(split1[0], split1[1].split(";")); + } catch (Exception e) { + // TODO Auto-generated catch block + MessageBox.post("ѡld6_deviceGroup" + str + "", "ʾ", MessageBox.ERROR); + return; + } + } + +// TCComponentForm form = TCUtil.getItemRevisionMasterForm(target.getItemRevision()); + boolean find = false; + int last = 0; + String idString = ""; + + for (AIFComponentContext c : target.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision rev = bom.getItemRevision(); + String dg = property(rev, "ld6_deviceGroup"); + // 豸ϢҵѡĴ + int count1 = 0; + for (Entry entry : queryName.entrySet()) { + if(!Arrays.asList(entry.getValue()).contains(dg)) { + count1++; + } + } + if(count1 == queryName.size()) { + //ʾû + idString += dg+"("+property(rev, "item_id")+")"; + idString += ","; + continue; + } + } + if(idString.length()>0) { + String newString = idString.substring(0, idString.length() - 1); + MessageBox.post("" + newString + "δҵ࣬ϵԱάϢִеտƬ", "ʾ", MessageBox.ERROR); + return; + } + + for (AIFComponentContext c : target.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision rev = bom.getItemRevision(); +// if(!rev.isTypeOf("LD6_MEProcessRevision")) + if (!rev.isTypeOf("LD6_MEOPRevision")) + continue; + String ld6_MEprocessType = rev.getProperty("ld6_MEprocessType"); + if (choice == 1 || choice == 4) { + if (ld6_MEprocessType.equals("ϵ¹")) { + blist.add(bom); + continue; + } + boolean type = ld6_MEprocessType.equals("ӹ"); + if (!find && !type) + continue; + find = true; + blist.add(bom); + if (type) + last = blist.size(); + } else if (choice == 2 || choice == 5) { + if (ld6_MEprocessType.equals("")) { + blist.add(bom); + find = true; + last = blist.size(); + } else if (find && ld6_MEprocessType.equals("ӹ")) { +// list.add(bom); +// list.get(sequence).removeAll(list.get(sequence)); + blist.removeAll(blist); + find = false; + } + } else { + blist.add(bom); + } + } + if (choice != 3 && last < blist.size()) { + for (int i = blist.size(); i > last; i--) { + blist.remove(i - 1); + } + } + ArrayList slist = new ArrayList<>(); + HashMap> meopMap = new HashMap<>(); + HashMap sequences = new HashMap<>(); + for (int i = 0; i < blist.size(); i++) { + TCComponentBOMLine bom = blist.get(i); + TCComponentItemRevision rev = bom.getItemRevision(); + String name = rev.getProperty("object_name"), sequence = bom.getProperty("bl_sequence_no"); + if (sequences.containsKey(sequence)) { + if (!name.equals(sequences.get(sequence))) { + MessageBox.post(desktop, "ͬŲͬƵĹ", "ERROR", MessageBox.ERROR); + return; + } + } else { + meopMap.put(sequence, new ArrayList()); + slist.add(sequence); + sequences.put(sequence, name); + } + meopMap.get(sequence).add(bom); + } + if (slist.size() > 20) { + MessageBox.post(desktop, "ʮ޷е", "ERROR", MessageBox.ERROR); + return; + } + TCComponentItemRevision proRev = target.getItemRevision(); + TCComponentItemRevision tarRev = (TCComponentItemRevision) proRev.getChildren("IMAN_METarget")[0] + .getComponent(); +// TCComponent[] components = form.getReferenceListProperty(tableProp); + + TCComponentTcFile[] files = model.getTcFiles(); + File file = files[0].getFile(System.getProperty("java.io.tmpdir")); + // ȡjava.io.tmpdirĿ¼ΪļĿ¼ + String tempDir = System.getProperty("java.io.tmpdir"); + + // ļǰʱȷΨһ + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String timestamp = dateFormat.format(new Date()); // ǰʱȷ + int randomNum = ThreadLocalRandom.current().nextInt(1000, 9999); // һλ + String newFileName = "file_" + timestamp + "_" + randomNum + ".txt"; // ļʽ + + // µļ· + File newFile = new File(tempDir, newFileName); + + try { + // ļλò + Files.copy(file.toPath(), newFile.toPath()); + System.out.println("File renamed and moved to: " + newFile.getAbsolutePath()); + + // Ҫɾԭļ + // originalFile.delete(); + } catch (IOException e) { + System.err.println("Error occurred while renaming the file: " + e.getMessage()); + } + input = new FileInputStream(newFile); + doc = new Document(input); + + ArrayList datas = new ArrayList<>(); + ArrayList words = new ArrayList<>(); + for (int i = 0; i < slist.size(); i++) { + String[] data = new String[5]; +// Table table = tables.get(i/2); +// int row = i>1 ? (3 + i%2) : (5 + i%2);//TODO +// if(i<2 && choice>3) +// row += 2; + String sequence = slist.get(i); + String name = sequences.get(sequence); +// table.get(row, 0).getParagraphs().get(0).setText(getChineseNum(i+1)); +// table.get(row, 1).getParagraphs().get(0).setText(name); + data[0] = getChineseNum(i + 1); + data[1] = name; + + ArrayList boms = meopMap.get(sequence); + StringBuilder contents = new StringBuilder(""), machine = new StringBuilder(""), + equip = new StringBuilder(""), remark = new StringBuilder(""); + TCComponent[] mecs = boms.get(0).getItemRevision().getReferenceProperty("root_activity") + .getReferenceListProperty("contents"); + mecs = TCsort(mecs, "ld6_activityno"); + for (TCComponent mec : mecs) { + contents.append(mec.getProperty("ld6_activityno")).append("") + .append(mec.getProperty("ld6_activitydesc")).append("\n"); + remark.append(mec.getProperty("ld6_controlpoint")).append("\n"); + } + ArrayList idSet = new ArrayList<>(); + Boolean isExit = false; + for (TCComponentBOMLine bom : boms) { +// TCComponentBOMLine bom = boms.get(0); + TCComponentItemRevision rev = bom.getItemRevision(); + + String dg = property(rev, "ld6_deviceGroup"); + if (!dg.isEmpty()) { + // 豸ϢҵѡĴ + for (Entry entry : queryName.entrySet()) { + if(Arrays.asList(entry.getValue()).contains(dg)) { + if(isExit) { + break; + } + machine.append(entry.getKey()); + isExit = true; +// machine.append("(ͼϵͳ)"); + machine.append(";"); + break; + } + } + + } + + for (AIFComponentContext c : bom.getChildren()) { + TCComponentBOMLine line = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision r = line.getItemRevision(); + String id = r.getProperty("item_id"); + if (idSet.contains(id)) + continue; + idSet.add(id); + String occ = line.getProperty("bl_occ_type"); + if (occ.equals("ָ") && r.isTypeOf("LD6_TecDOCRevision")) { + String t = property(r, "ld6_type"); + if (TCUtil.contains(docs, t)) + equip.append(options[3]).append(t).append("").append(id).append("\\") + .append(property(r, "ld6_docNum")).append("\n"); + } else if (occ.equals("Դ")) { + String type = r.getType(); + if (r.isTypeOf("LD6_EquipmentRevision")) { + String t = property(r, "ld6_equType"); + if (TCUtil.contains(equips, t)) + equip.append(options[3]).append(t).append("").append(id).append("\\") + .append(property(r, "ld6_drawNum")).append("\n"); + } else if (types.containsKey(type)) { + String q = property(line, "bl_quantity"); + equip.append(options[3]).append(types.get(type)).append("").append(id).append("\\") + .append(q.isEmpty() ? "1" : q).append("\\") + .append(property(r, "ld6_materialDesc")).append("\n"); + } + } + } + + TCComponentDataset word = null; + AIFComponentContext[] cs = rev.getChildren("IMAN_specification"); + for (AIFComponentContext c : cs) { + TCComponent comp = (TCComponent) c.getComponent(); + if (comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains("ռͼ")) { + word = (TCComponentDataset) comp; + break; + } + } + if (word == null) { + continue; + } + words.add(word); + } + + if (contents.length() > 0) + contents.deleteCharAt(contents.length() - 1); + if (machine.length() > 0) + machine.deleteCharAt(machine.length() - 1).append("\n").insert(0, options[3] + ""); + if (equip.length() > 0) + equip.deleteCharAt(equip.length() - 1); + if (remark.length() > 0) + remark.deleteCharAt(remark.length() - 1); +// table.get(row, 2).getParagraphs().get(0).setText(contents.toString()); +// table.get(row, 3).getParagraphs().get(0).setText(machine.append(equip).toString()); +// table.get(row, 4).getParagraphs().get(0).setText(remark.toString()); + data[2] = shiftRow(contents.toString(), 74).toString(); + data[3] = shiftRow(machine.append(equip).toString(), 32).toString();// TODO shiftRow + data[4] = shiftRow(remark.toString(), 24).toString(); + datas.add(data); +// System.out.println("data"+data[2]+""+contents.toString()); + } + Section section = doc.getSections().get(0); + tables = section.getTables(); + System.out.println("tables:" + tables.getCount()); + totalRow = 0; + first = choice > 3 ? 11 : 12; + ArrayList hights = new ArrayList<>(); + for (String[] data : datas) { + int a = rowCount(data[2], 75, first, totalRow); + int b = rowCount(data[3], 31, first, totalRow); + int c = rowCount(data[4], 24, first, totalRow); + System.out.println("rowCount" + a + "==" + b + "==" + c); + if (a >= b && a >= c) { + totalRow += a; + hights.add(a); + } else if (b >= a && b >= c) { + totalRow += b; + hights.add(b); + } else { + totalRow += c; + hights.add(c); + } + System.out.println("data" + hights.size() + "" + hights.get(hights.size() - 1)); + } + //¼һͼֽ + int tznum = 0; + if(!create) { + int sum = tables.getCount(); + int txtsum = totalRow / 2 + totalRow % 2; + tznum = sum - txtsum; + System.out.println("tznum:"+tznum); + } + + //һεʱ򴴽ҳ ظʱ ֱ滻 ҳ + if(create) { + + System.out.println("ʼҳ"); + int count = totalRow / 2 + totalRow % 2; + if (count > 2) { + for (int i = 0; i < count - 2; i++) { + tables.add(tables.get(1).deepClone()); + // doc.getLastParagraph().setText("last\n\n"); + section.addParagraph(); + section.addParagraph(); +// System.out.println("Last:"+doc.pa); + } + } + } + + + + totalRow = 0; + for (int i = 0; i < datas.size(); i++) { + String[] strings = datas.get(i); + + System.out.println("totalRow" + totalRow); + + write(datas.get(i), hights.get(i));// TODO wright + } + //ظʱ Ѿڵͼֽɾ µ + if(!create) { + System.out.println("ʼɾͼֽ"); + System.out.println("count:"+tables.getCount()); + int tznum2 = tznum; + for(int a = tables.getCount()-1;tznum2>0;a--,tznum2--) { + tables.removeAt(a); + } + // Ϊɾ񣬻пвԸɾն + ParagraphCollection paragraphs = section.getParagraphs(); + // һ俪ʼ + for (int n = paragraphs.getCount() - 1; n >= 0; n--) { + if(tznum < 0) { + break; + } + Paragraph paragraph = paragraphs.get(n); + tznum--; + // ǷΪ + if (paragraph.getText().trim().isEmpty()) { + // ɾն + paragraphs.remove(paragraph); + + } else { + // ǿնʱ˳ѭ + break; + } + } + } + + + + for (TCComponentDataset word : words) { + FileInputStream input2 = null; + try { + File file2 = word.getTcFiles()[0].getFile(System.getProperty("java.io.tmpdir")); + input2 = new FileInputStream(file2); + Document doc2 = new Document(input2); + TableCollection tables2 = doc2.getSections().get(0).getTables(); + for (int j = 0; j < tables2.getCount(); j++) { + + tables.add(tables2.get(j).deepClone()); + section.addParagraph(); + section.addParagraph(); + } + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, "" + e.getMessage(), "ERROR", MessageBox.ERROR); + } finally { + if (input2 != null) + input2.close(); + } + } + tables = doc.getSections().get(0).getTables(); + for (int i = 0; i < tables.getCount(); i++) { + Table table = tables.get(i); + RowCollection rows = table.getRows(); + int rowc = rows.getCount(); +// System.out.println("tables:"+table.get(rowc-1, rows.get(rowc-1).getCells().getCount()-1).getParagraphs().get(0).getText()); +// System.out.println("tables:"+table.get(rowc-2, rows.get(rowc-2).getCells().getCount()-1).getParagraphs().get(0).getText()); + table.get(rowc - 2, rows.get(rowc - 2).getCells().getCount() - 1).getParagraphs().get(0) + .setText(" " + (i + 1) + " ҳ"); + table.get(rowc - 3, rows.get(rowc - 3).getCells().getCount() - 1).getParagraphs().get(0) + .setText(" " + tables.getCount() + " ҳ"); + } + + output = new FileOutputStream(newFile.getPath()); + doc.saveToFile(output, FileFormat.Docx_2010); + doc.dispose(); + TCUtil.deleteWarning(newFile); + input.close(); + output.close(); + + String t = (choice == 2 || choice == 5) ? "-T04-" : "-T02-"; + if (choice > 3) + t += "L"; + StringBuilder builder = new StringBuilder(""); + String no = new StringBuilder("LD.Y-") + .append(tarRev.getType().equals("LD6_EquipmentRevision") ? property(tarRev, "ld6_drawNum") + : property(tarRev, "ld6_clientPartNum")) + .append(t).append(property(proRev.getItem(), "ld6_SeqNum")).toString(); + builder.append("ͻ=").append(value(property(tarRev, "ld6_clientName"), 10)).append("|ͺ=") + .append(value(property(tarRev, "ld6_specsModel"), 10)).append("|ͼ=") + .append(value(property(tarRev, "ld6_clientPartNum"), 24)).append("|=") + .append(value(property(tarRev, "object_name"), 24)).append("|ļ=").append(value(no, 28)) + .append("|汾=").append(value(property(tarRev, "ld6_clientPartRev"), 28)).append("|ļ=") + .append(property(tarRev, "item_revision_id")) + + .append("|ƺ=").append(property(tarRev, "ld6_partMaterialQ")).append("|ëߴ=") + .append(property(proRev, "ld6_blankSize")).append("|=") + .append(property(tarRev, "ld6_netWeight")).append("|ע=").append(property(proRev, "ld6_notes")) + .append("|ë=").append(property(proRev, "ld6_blanktype")).append("|Ƴ=") + .append(property(proRev, "ld6_madePartNum")).append("|ë=") + .append(property(tarRev, "ld6_grossWeight")).append("|ÿ̨=") + .append(property(proRev, "ld6_eachNum")) + + .append("|װ=").append(value(property(tarRev, "ld6_equType"), 28)).append("|װͼ=") + .append(value(property(tarRev, "ld6_drawNum"), 46)).append("|װͼŰ汾=") + .append(value(property(proRev, "ld6_clientPartRev"), 24)).append("|װ=") + .append(property(tarRev, "object_name")).append("|ԭ=").append(property(proRev, "ld6_reason")) + .append("|ǷҪò=").append(property(proRev, "ld6_ifConcession")).append("|λ=") + .append(property(proRev, "ld6_workpieceStation")).append("|÷Χ=") + .append(property(proRev, "ld6_scope")).append("|ģ״̬=") + .append(property(proRev, "ld6_progsimstat")).append("|=").append(property(proRev, "ld6_type")); + // жǷҪӹߡߡԼӦʱӵ + if (choice == 1 || choice == 4) { + String property = property(proRev, "ld6_creatordate1"); + if(property.contains("00:00")) { + property = property.replace("00:00", ""); + } + builder.append("|=").append(property(proRev, "ld6_creator")).append("|=") + .append(property); + } else if (choice == 2 || choice == 5) { + String property = property(proRev, "ld6_creatordate1"); + if(property.contains("00:00")) { + property = property.replace("00:00", ""); + } + builder.append("|=").append(property(proRev, "ld6_creator2")).append("|=") + .append(property); + } + for (int j = 0; j < meopMap.size(); j++) { + builder.append("|").append(j + 1).append("=").append(sequences.get(slist.get(j)));// .getItemRevision().getProperty("object_name") + } + File saveFile = new File(System.getProperty("java.io.tmpdir") + "\\word.txt"); + if (saveFile.exists()) { + saveFile.delete(); + } + saveFile.createNewFile(); + buffered = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile, true))); + buffered.write(builder.toString()); + buffered.close(); + String pluginsDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); + pluginsDir = pluginsDir.substring(1, pluginsDir.lastIndexOf("/")); + runWsf(pluginsDir + "\\SubstMacros-MSWord.wsf", new String[] { newFile.getPath(), saveFile.getPath() }); + +// String name = file.getName().replace(".docx", "");//TODO name +// String name = model.getProperty("object_name"); + + // 鿴·Ƿijδı֪ͨECNĸĺϵ + String changeID = ""; + AIFComponentContext[] whereReferenced = proRev.whereReferenced(); + for (AIFComponentContext componentContext : whereReferenced) { + TCComponent component = (TCComponent) componentContext.getComponent(); + System.out.println("component.getType():" + component.getType()); + if ("LD6_CNRevision".equals(component.getType())) { + // δ + if (!KUtil.isTCM(component)) { + // ȡϵµĶ + TCComponent[] referenceListProperty = component.getReferenceListProperty("CMHasSolutionItem"); + for (TCComponent component2 : referenceListProperty) { + if (proRev.getStringProperty("item_id").equals(component2.getStringProperty("item_id"))) { + changeID = component.getStringProperty("item_id"); + break; + } + } + if (!changeID.isEmpty()) { + break; + } + } + } + } + +// StringBuilder names = new StringBuilder(""); +// if (choice == 1) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("ӹտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 2) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("տƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 3) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("װտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 4) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("ӹʱտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 5) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("ʱտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } +// String name = names.toString(); + String name = ""; + if (choice == 1) { + name = getDatasetName(proRev, "Connor_Exportname1_Mapping", changeID); + } else if (choice == 2) { + name = getDatasetName(proRev, "Connor_Exportname2_Mapping", changeID); + } else if (choice == 3) { + name = getDatasetName(proRev, "Connor_Exportname3_Mapping", changeID); + } else if (choice == 4) { + name = getDatasetName(proRev, "Connor_Exportname4_Mapping", changeID); + } else if (choice == 5) { + name = getDatasetName(proRev, "Connor_Exportname5_Mapping", changeID); + } + System.out.println("name:"+name); + + boolean create = true; + for (AIFComponentContext c : proRev.getChildren("IMAN_specification")) { + TCComponent comp = (TCComponent) c.getComponent(); + if (comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains(oldName)) { + KUtil.setByPass(session, true); + proRev.remove("IMAN_specification", comp); +// comp.delete(); + KUtil.setByPass(session, false); + break; + } + } + if (create) { + File namedref = new File(newFile.getParent() + "\\" + name + ".docx"); + if (namedref.exists()) + namedref.delete(); +// if(!file.getName().equals(name+".docx")) + newFile.renameTo(namedref); + System.out.println("newFile:" + namedref.getPath()); + TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService() + .getTypeComponent("Dataset"); + TCComponentDataset dataset = compType.create(name, "", "MSWordX"); + dataset.setFiles(new String[] { namedref.getAbsolutePath() }, new String[] { "word" }); + proRev.add("IMAN_specification", dataset); + } + + MessageBox.post(desktop, "", "INFO", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, "" + e.getMessage(), "ERROR", MessageBox.ERROR); + } finally { + if (input != null) + input.close(); + if (output != null) + output.close(); + if (buffered != null) + buffered.close(); + } + } + + private String getDatasetName(TCComponentItemRevision revision, String name, String id) throws TCException { + String[] stringValues = session.getPreferenceService().getStringValues(name); + if (stringValues == null || stringValues.length == 0) { + MessageBox.post("ѡ" + name + "òȷ", "ERROR", MessageBox.ERROR); + return null; + } + if (!stringValues[0].contains("ӹտƬ") && !stringValues[0].contains("տƬ") + && !stringValues[0].contains("װտƬ") && !stringValues[0].contains("ӹʱտƬ") + && !stringValues[0].contains("ʱտƬ")) { + MessageBox.post("ѡ" + name + "òȷ,ȱٹؼʡ*տƬ", "ERROR", MessageBox.ERROR); + return null; + } + System.out.println(stringValues[0]); + String[] split = stringValues[0].split("\\|"); + StringBuilder names = new StringBuilder(""); + for (String str : split) { + String[] split2 = str.split("\\."); + String value = ""; + if (split2.length == 1) { + if (split2[0].contains("ECNID")) { + if(!id.isEmpty()) { + value = split2[0].replaceAll("ECNID", id); + }else { + value = ""; + } + + } else { + value = split2[0]; + } + } else if (split2.length == 2) { + if ("item".equals(split2[0])) { + value = property(revision.getItem(), split2[1]); + } else if ("rev".equals(split2[0])) { + value = property(revision, split2[1]); + } + + } else if (split2.length == 4) { + // ȡϵ + TCComponent[] referenceListProperty = revision.getReferenceListProperty(split2[0]); + for (TCComponent component : referenceListProperty) { + if (split2[1].equals(component.getType())) { + if ("item".equals(split2[2])) { + value = property(((TCComponentItemRevision) component).getItem(), split2[3]); + } else if ("rev".equals(split2[2])) { + value = property((TCComponentItemRevision) component, split2[3]); + } + } + } + } else { + MessageBox.post("ѡ" + name + "", "ERROR", MessageBox.ERROR); + return null; + } + names.append(value); + } + return names.toString(); + } + + private String getChineseNum(int num) throws Exception { + String value = ""; + int ten = num / 10, n = num % 10; + if (ten > 1) + value += nums.get(ten) + "ʮ"; + else if (ten == 1) + value += "ʮ"; + value += nums.get(n); + return value; + } + + private String property(TCComponent comp, String prop) { + try { + TCProperty tcprop = comp.getTCProperty(prop); + if (tcprop == null) + return ""; + return comp.getProperty(prop); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + private String value(String str, int max) { + int len = str.length(); + if (len < 1 || len >= max) + return str; + int count = 0; + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) + count += 1; + else + count += 2; + } + if (count >= max) + return str; + StringBuilder sb = new StringBuilder(str); + for (int i = 0; i < (max - count) / 2; i++) { + sb.insert(0, " ").append(" "); + } + return sb.toString(); + } + + private int rowCount(String str) { + if (str == null) + return 0; + return str.replaceAll("\n", "\n0").length() - str.length(); + } + + /* + * private int rowCount(String str, int max) { String[] ss = str.split("\n"); + * int r = ss.length; for(String s : ss) { int w = s.length(); for(int i=0; + * i='0' && c<=9) && !(c>='a' + * && c<='z')) w += 1; } r += w/max; } return r; } + */ + + private int rowCount(String str, int max, int first, int row) { + System.out.println("str:"+str); + System.out.println("max:"+max); + System.out.println("first:"+first); + System.out.println("row:"+row); +// int r = str.replaceAll("\n", "\n0").length() - str.length(); + int r = rowCount(str); + System.out.println("r:"+r); + int f2 = first * 2 + 1; + System.out.println("f2:"+f2); + if (row == 0) { + if (r > f2) + return 2 + rowCount(r - f2, true); + else if (r > first) + return 2; + else + return 1; + } else if (row == 1) { + if (r > first) + return 1 + rowCount(r - first, true); + else + return 1; + } else { + return rowCount(r, row % 2 == 0); + } + } + + private int rowCount(int row, boolean up) { + if (row <= 13) + return 1; + else { + if (up) { + if (row <= 27) + return 2; + else + return 2 + rowCount(row - 27, true); + } else { + return 1 + rowCount(row - 13, true); + } + } + } + + private StringBuilder shiftRow(String str, int max) { + str = str.replaceAll("\n\n", "\n"); + int len = str.replaceAll("\n", "").length(); +// System.out.println("shiftRow"+len+""+max/2+""+str.indexOf("\n")); + if (len < max / 2) + return new StringBuilder(str); + + if (str.indexOf("\n") < 0) { + StringBuilder sb = new StringBuilder(str); + int count = 1; + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || symbols.contains(c)) + count += 1; + else + count += 2; + if (count >= max) {// && count= '0' && c <= '9') || (c >= 'a' && c <= 'z') || symbols.contains(c)) + count += 1; + else + count += 2; +// if(s.startsWith("־")) +// System.out.println("count"+sbd+""+count+""+l); + if (count >= max) {// && count 0 && sb.substring(sb.length() - 1).equals("\n")) + sb.deleteCharAt(sb.length() - 1); + return sb; + } + } + + private void write(String[] data, int h) throws Exception { + Table table = tables.get(totalRow / 2); + int uod = totalRow % 2; + int row = totalRow > 1 ? (3 + uod) : (5 + uod);// TODO + if (totalRow < 2 && choice > 3) + row += 2; +// String[] data = datas.get(i); +// if(i<2 && h<=first || h<=13) { +// System.out.println("data3"+data[2]+""+data[0]); +// if(h>0) { +// for(int a= 0;a 1 ? 13 : first); + each = each * 2; + System.out.println("3.1:"+data[0]); + setText(table.get(row, 0).getParagraphs().get(0), data[0]); + table.applyVerticalMerge(0, row, row + 1); + System.out.println("3.2:"+data[1]); + setText(table.get(row, 1).getParagraphs().get(0), data[1]); + table.applyVerticalMerge(1, row, row + 1); + for (int j = 2; j < 5; j++) { + TableCell tableCell = table.get(row, j); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for(int n=0;n 1 ? 13 : first); + System.out.println("5.1:"+data[0]); + table.get(row, 0).getParagraphs().get(0).setText(""); + setText(table.get(row, 0).getParagraphs().get(0), data[0]); + + System.out.println("5.2:"+data[1]); + table.get(row, 1).getParagraphs().get(0).setText(""); + setText(table.get(row, 1).getParagraphs().get(0), data[1]); + for (int j = 2; j < 5; j++) { + TableCell tableCell = table.get(row, j); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for(int n=0;n", t)); + String s5 = data.substring(data.indexOf(">", t) + 1); + setText(parag, s1); + StringBuilder sb = new StringBuilder("$"); + sb.append(s2).append("_{").append(s3).append("}^{").append(s4).append("}$"); + + OfficeMath officeMath2 = new OfficeMath(doc); + parag.getItems().add(officeMath2); + officeMath2.fromLatexMathCode(sb.toString()); + + setText(parag, s5); + } else if (data.contains("")) { + String[] split = data.split(""); + for (int j = 0; j < split.length; j += 2) { +// parag.appendText(split[j]); + setText(parag, split[j]); + if (j + 1 < split.length) + parag.appendText(split[j + 1]).getCharacterFormat().setSubSuperScript(SubSuperScript.Super_Script);// TODO + } + } else if (data.contains("<#G>")) { + String[] split = data.split("<#G>"); + for (int i = 0; i < split.length; i++) { +// parag.appendText(split[j]); + setText(parag, split[i]); + if (i + 1 < split.length) { +// ShapeObject triangle = parag.appendShape(10, 5, ShapeType.Triangle); +// +// triangle.setStrokeColor(Color.BLACK); +// triangle.setFillColor(Color.WHITE); +//// triangle.setVerticalPosition(50); +//// triangle.setHorizontalPosition(170);S +// triangle.setRotation(225); +// +// triangle.setTextWrappingStyle(TextWrappingStyle.Through); + getHTML(parag, "<#G>"); + } + } + } else { + String[] options = session.getPreferenceService().getStringValues("connor_gdt_custom_symbols"); + boolean hast = false; + for (String s : options) { + String[] ss = s.split("="); + String sy = ""; + if (ss.length == 2 && data.contains(ss[0])) { + sy = ss[0]; + hast = true; + } else if (ss.length == 3 && data.contains(ss[1])) { + sy = ss[1]; + hast = true; + } + if (sy.isEmpty()) + continue; + String[] split = data.split(sy); + for (int i = 0; i < split.length; i++) { + setText(parag, split[i]); + if (i + 1 < split.length) { + getHTML(parag, sy); + } + } + + } + if (!hast) + parag.appendText(data); + } + } + + private void getHTML(Paragraph parag, String txt) { + String htmlstring = KGenerateGDTHTML.generatePage(txt); + System.out.println(txt + " == " + htmlstring); + parag.appendHTML(htmlstring); +// String out = System.getProperty("java.io.tmpdir") + "\\out.html"; +// File htmlfile = new File(out); +// if(htmlfile.exists()) +// htmlfile.delete(); +// htmlfile.createNewFile(); +// FileWriter fos = new FileWriter(htmlfile); +// fos.write(htmlstring); +// fos.close(); + +// Document doc = new Document(); +// doc.loadFromFile(out, FileFormat.Html, XHTMLValidationType.None); +// Paragraph d = doc.getSections().get(0).getParagraphs().get(0); + +// parag. + } + + private TCComponent[] TCsort(TCComponent[] TCComponent, String property) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for (TCComponent comp : TCComponent) { + try { + map.put(comp, comp.getProperty(property)); + } catch (Exception e) { + e.printStackTrace(); + } + } + // ͨArrayList캯map.entrySet()תlist + List> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { +// return mapping1.getValue().compareTo(mapping2.getValue()); + int v1 = Integer.parseInt(mapping1.getValue()); + int v2 = Integer.parseInt(mapping2.getValue()); + return v1 - v2; + } + }); + TCComponent = new TCComponent[count]; + int i = 0; + for (Map.Entry mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + + public static void runWsf(String wsfPath, String[] paras) throws Exception { + ArrayList cmdVector = new ArrayList<>(); + cmdVector.add("wscript"); + cmdVector.add(wsfPath); + for (String para : paras) { + cmdVector.add(para); + } + StringBuilder builder = new StringBuilder("wscript ").append(wsfPath).append(" ").append(paras[0]).append(" ") + .append(paras[1]); + System.out.println(builder.toString()); + String[] cmd = (String[]) cmdVector.toArray(new String[cmdVector.size()]); +// for (int i = 0; i < cmd.length; i++) { +// System.out.println(cmd[i]); +// } + Process process = Runtime.getRuntime().exec(cmd); + process.waitFor(); +// MessageBox.post("Success!","INFORMATION",MessageBox.INFORMATION); +// Runtime.getRuntime().exec(paras[0]); + } +} diff --git a/src/com/connor/ly/project/DateChooser.java b/src/com/connor/ly/project/DateChooser.java new file mode 100644 index 0000000..5fc1175 --- /dev/null +++ b/src/com/connor/ly/project/DateChooser.java @@ -0,0 +1,698 @@ +package com.connor.ly.project; + +import java.awt.BasicStroke; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Polygon; +import java.awt.Stroke; +import java.awt.Toolkit; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Comparator; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.Popup; +import javax.swing.PopupFactory; +import javax.swing.SwingUtilities; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; + +public class DateChooser extends JPanel { + private static final long serialVersionUID = 4529266044762990227L; + private Date initDate; + private Calendar now; + private Calendar select; + private JPanel monthPanel; + private DateChooser.JP1 jp1; + private DateChooser.JP2 jp2; + private DateChooser.JP3 jp3; + private DateChooser.JP4 jp4; + private Font font; + private final DateChooser.LabelManager lm; + private SimpleDateFormat sdf; + private boolean isShow; + private Popup pop; + private JComponent showDate; + + public static DateChooser getInstance() { + return new DateChooser(); + } + + public static DateChooser getInstance(Date date) { + return new DateChooser(date); + } + + public static DateChooser getInstance(String format) { + return new DateChooser(format); + } + + public static DateChooser getInstance(Date date, String format) { + return new DateChooser(date, format); + } + + private DateChooser() { + this(new Date()); + } + + private DateChooser(Date date) { + this(date, "yyyyMMdd"); + } + + private DateChooser(String format) { + this(new Date(), format); + } + + private DateChooser(Date date, String format) { + this.now = Calendar.getInstance(); + this.font = new Font("", 0, 12); + this.lm = new DateChooser.LabelManager(); + this.isShow = false; + this.initDate = date; + this.sdf = new SimpleDateFormat(format); + this.select = Calendar.getInstance(); + this.select.setTime(this.initDate); + this.initPanel(); + } + + public void setEnabled(boolean b) { + super.setEnabled(b); + this.showDate.setEnabled(b); + } + + public Date getDate() { + return this.select.getTime(); + } + + public String getStrDate() { + return this.sdf.format(this.select.getTime()); + } + + public String getStrDate(String format) { + this.sdf = new SimpleDateFormat(format); + return this.sdf.format(this.select.getTime()); + } + + private void initPanel() { + this.monthPanel = new JPanel(new BorderLayout()); + this.monthPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE)); + JPanel up = new JPanel(new BorderLayout()); + up.add(this.jp1 = new DateChooser.JP1(), "North"); + up.add(this.jp2 = new DateChooser.JP2(), "Center"); + this.monthPanel.add(this.jp3 = new DateChooser.JP3(), "Center"); + this.monthPanel.add(up, "North"); + this.monthPanel.add(this.jp4 = new DateChooser.JP4(), "South"); + this.addAncestorListener(new AncestorListener() { + public void ancestorAdded(AncestorEvent event) { + } + + public void ancestorRemoved(AncestorEvent event) { + } + + public void ancestorMoved(AncestorEvent event) { + DateChooser.this.hidePanel(); + } + }); + } + + public void register(final JComponent showDate) { + this.showDate = showDate; + showDate.setRequestFocusEnabled(true); + showDate.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent me) { + showDate.requestFocusInWindow(); + } + }); + this.setBackground(Color.WHITE); + this.add(showDate, "Center"); + this.setPreferredSize(new Dimension(90, 25)); + this.setBorder(BorderFactory.createLineBorder(Color.GRAY)); + showDate.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent me) { + if (showDate.isEnabled()) { + showDate.setCursor(new Cursor(12)); + showDate.setForeground(Color.RED); + } + + } + + public void mouseExited(MouseEvent me) { + if (showDate.isEnabled()) { + showDate.setCursor(new Cursor(0)); + showDate.setForeground(Color.BLACK); + } + + } + + public void mousePressed(MouseEvent me) { + if (showDate.isEnabled()) { + showDate.setForeground(Color.CYAN); + if (DateChooser.this.isShow) { + DateChooser.this.hidePanel(); + } else { + DateChooser.this.showPanel(showDate); + } + } + + } + + public void mouseReleased(MouseEvent me) { + if (showDate.isEnabled()) { + showDate.setForeground(Color.BLACK); + } + + } + }); + showDate.addFocusListener(new FocusListener() { + public void focusLost(FocusEvent e) { + DateChooser.this.hidePanel(); + } + + public void focusGained(FocusEvent e) { + } + }); + } + + private void refresh() { + this.jp1.updateDate(); + this.jp2.updateDate(); + this.jp3.updateDate(); + this.jp4.updateDate(); + SwingUtilities.updateComponentTreeUI(this); + } + + private void commit() { + if (this.showDate instanceof JTextField) { + ((JTextField) this.showDate).setText(this.sdf.format(this.select.getTime())); + } else if (this.showDate instanceof JLabel) { + ((JLabel) this.showDate).setText(this.sdf.format(this.select.getTime())); + } + + this.hidePanel(); + } + + private void hidePanel() { + if (this.pop != null) { + this.isShow = false; + this.pop.hide(); + this.pop = null; + } + + } + + private void showPanel(Component owner) { + if (this.pop != null) { + this.pop.hide(); + } + + Point show = new Point(0, this.showDate.getHeight()); + SwingUtilities.convertPointToScreen(show, this.showDate); + Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); + int x = show.x; + int y = show.y; + if (x < 0) { + x = 0; + } + + if (x > size.width - 295) { + x = size.width - 295; + } + + if (y >= size.height - 170) { + y -= 188; + } + + this.pop = PopupFactory.getSharedInstance().getPopup(owner, this.monthPanel, x, y); + this.pop.show(); + this.isShow = true; + } + + public static void main(String[] args) { + DateChooser dateChooser1 = getInstance("yyyy-MM-dd HH:mm"); + DateChooser dateChooser2 = getInstance("yyyy-MM-dd"); + JTextField showDate1 = new JTextField("ѡ"); + JLabel showDate2 = new JLabel("ѡ"); + dateChooser1.register(showDate1); + dateChooser2.register(showDate2); + JFrame jf = new JFrame("ѡ"); + jf.add(showDate1, "North"); + jf.add(showDate2, "South"); + jf.pack(); + jf.setLocationRelativeTo((Component) null); + jf.setVisible(true); + jf.setDefaultCloseOperation(3); + } + + private class JP1 extends JPanel { + private static final long serialVersionUID = -5638853772805561174L; + JLabel yearleft; + JLabel yearright; + JLabel monthleft; + JLabel monthright; + JLabel center; + JLabel centercontainer; + + public JP1() { + super(new BorderLayout()); + this.setBackground(new Color(160, 185, 215)); + this.initJP1(); + } + + private void initJP1() { + this.yearleft = new JLabel(" <<", 0); + this.yearleft.setToolTipText("һ"); + this.yearright = new JLabel(">> ", 0); + this.yearright.setToolTipText("һ"); + this.yearleft.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); + this.yearright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); + this.monthleft = new JLabel(" <", 4); + this.monthleft.setToolTipText("һ"); + this.monthright = new JLabel("> ", 2); + this.monthright.setToolTipText("һ"); + this.monthleft.setBorder(BorderFactory.createEmptyBorder(2, 30, 0, 0)); + this.monthright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 30)); + this.centercontainer = new JLabel("", 0); + this.centercontainer.setLayout(new BorderLayout()); + this.center = new JLabel("", 0); + this.centercontainer.add(this.monthleft, "West"); + this.centercontainer.add(this.center, "Center"); + this.centercontainer.add(this.monthright, "East"); + this.add(this.yearleft, "West"); + this.add(this.centercontainer, "Center"); + this.add(this.yearright, "East"); + this.setPreferredSize(new Dimension(295, 25)); + this.updateDate(); + this.yearleft.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent me) { + JP1.this.yearleft.setCursor(new Cursor(12)); + JP1.this.yearleft.setForeground(Color.RED); + } + + public void mouseExited(MouseEvent me) { + JP1.this.yearleft.setCursor(new Cursor(0)); + JP1.this.yearleft.setForeground(Color.BLACK); + } + + public void mousePressed(MouseEvent me) { + DateChooser.this.select.add(1, -1); + JP1.this.yearleft.setForeground(Color.WHITE); + DateChooser.this.refresh(); + } + + public void mouseReleased(MouseEvent me) { + JP1.this.yearleft.setForeground(Color.BLACK); + } + }); + this.yearright.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent me) { + JP1.this.yearright.setCursor(new Cursor(12)); + JP1.this.yearright.setForeground(Color.RED); + } + + public void mouseExited(MouseEvent me) { + JP1.this.yearright.setCursor(new Cursor(0)); + JP1.this.yearright.setForeground(Color.BLACK); + } + + public void mousePressed(MouseEvent me) { + DateChooser.this.select.add(1, 1); + JP1.this.yearright.setForeground(Color.WHITE); + DateChooser.this.refresh(); + } + + public void mouseReleased(MouseEvent me) { + JP1.this.yearright.setForeground(Color.BLACK); + } + }); + this.monthleft.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent me) { + JP1.this.monthleft.setCursor(new Cursor(12)); + JP1.this.monthleft.setForeground(Color.RED); + } + + public void mouseExited(MouseEvent me) { + JP1.this.monthleft.setCursor(new Cursor(0)); + JP1.this.monthleft.setForeground(Color.BLACK); + } + + public void mousePressed(MouseEvent me) { + DateChooser.this.select.add(2, -1); + JP1.this.monthleft.setForeground(Color.WHITE); + DateChooser.this.refresh(); + } + + public void mouseReleased(MouseEvent me) { + JP1.this.monthleft.setForeground(Color.BLACK); + } + }); + this.monthright.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent me) { + JP1.this.monthright.setCursor(new Cursor(12)); + JP1.this.monthright.setForeground(Color.RED); + } + + public void mouseExited(MouseEvent me) { + JP1.this.monthright.setCursor(new Cursor(0)); + JP1.this.monthright.setForeground(Color.BLACK); + } + + public void mousePressed(MouseEvent me) { + DateChooser.this.select.add(2, 1); + JP1.this.monthright.setForeground(Color.WHITE); + DateChooser.this.refresh(); + } + + public void mouseReleased(MouseEvent me) { + JP1.this.monthright.setForeground(Color.BLACK); + } + }); + } + + private void updateDate() { + this.center.setText(DateChooser.this.select.get(1) + "" + (DateChooser.this.select.get(2) + 1) + ""); + } + } + + private class JP2 extends JPanel { + private static final long serialVersionUID = -8176264838786175724L; + + public JP2() { + this.setPreferredSize(new Dimension(295, 20)); + } + + protected void paintComponent(Graphics g) { + g.setFont(DateChooser.this.font); + g.drawString(" һ ڶ ", 5, 10); + g.drawLine(0, 15, this.getWidth(), 15); + } + + private void updateDate() { + } + } + + private class JP3 extends JPanel { + private static final long serialVersionUID = 43157272447522985L; + + public JP3() { + super(new GridLayout(6, 7)); + this.setPreferredSize(new Dimension(295, 100)); + this.initJP3(); + } + + private void initJP3() { + this.updateDate(); + } + + public void updateDate() { + this.removeAll(); + DateChooser.this.lm.clear(); + Date temp = DateChooser.this.select.getTime(); + Calendar select = Calendar.getInstance(); + select.setTime(temp); + select.set(5, 1); + int index = select.get(7); + int sum = index == 1 ? 8 : index; + select.add(5, 0 - sum); + + for (int i = 0; i < 42; ++i) { + select.add(5, 1); + DateChooser.this.lm.addLabel(DateChooser.this.new MyLabel(select.get(1), select.get(2), select.get(5))); + } + + Iterator var6 = DateChooser.this.lm.getLabels().iterator(); + + while (var6.hasNext()) { + DateChooser.MyLabel my = (DateChooser.MyLabel) var6.next(); + this.add(my); + } + + select.setTime(temp); + } + } + + private class JP4 extends JPanel { + private static final long serialVersionUID = -6391305687575714469L; + + public JP4() { + super(new BorderLayout()); + this.setPreferredSize(new Dimension(295, 20)); + this.setBackground(new Color(160, 185, 215)); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + final JLabel jl = new JLabel(": " + sdf.format(new Date())); + jl.setToolTipText("ѡ"); + this.add(jl, "Center"); + jl.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent me) { + jl.setCursor(new Cursor(12)); + jl.setForeground(Color.RED); + } + + public void mouseExited(MouseEvent me) { + jl.setCursor(new Cursor(0)); + jl.setForeground(Color.BLACK); + } + + public void mousePressed(MouseEvent me) { + jl.setForeground(Color.WHITE); + DateChooser.this.select.setTime(new Date()); + DateChooser.this.refresh(); + DateChooser.this.commit(); + } + + public void mouseReleased(MouseEvent me) { + jl.setForeground(Color.BLACK); + } + }); + } + + private void updateDate() { + } + } + + private class LabelManager { + private List list = new ArrayList(); + + public LabelManager() { + } + + public List getLabels() { + return this.list; + } + + public void addLabel(DateChooser.MyLabel my) { + this.list.add(my); + } + + public void clear() { + this.list.clear(); + } + + public void setSelect(DateChooser.MyLabel my, boolean b) { + Iterator var4 = this.list.iterator(); + + while (var4.hasNext()) { + DateChooser.MyLabel m = (DateChooser.MyLabel) var4.next(); + if (m.equals(my)) { + m.setSelected(true, b); + } else { + m.setSelected(false, b); + } + } + + } + + public void setSelect(Point p, boolean b) { + if (b) { + boolean findPrevious = false; + boolean findNext = false; + Iterator var6 = this.list.iterator(); + + while (var6.hasNext()) { + DateChooser.MyLabel mx = (DateChooser.MyLabel) var6.next(); + if (mx.contains(p)) { + findNext = true; + if (mx.getIsSelected()) { + findPrevious = true; + } else { + mx.setSelected(true, b); + } + } else if (mx.getIsSelected()) { + findPrevious = true; + mx.setSelected(false, b); + } + + if (findPrevious && findNext) { + return; + } + } + } else { + DateChooser.MyLabel temp = null; + Iterator var9 = this.list.iterator(); + + while (var9.hasNext()) { + DateChooser.MyLabel m = (DateChooser.MyLabel) var9.next(); + if (m.contains(p)) { + temp = m; + } else if (m.getIsSelected()) { + m.setSelected(false, b); + } + } + + if (temp != null) { + temp.setSelected(true, b); + } + } + + } + } + + private class MyLabel extends JLabel + implements Comparator, MouseListener, MouseMotionListener { + private static final long serialVersionUID = 3668734399227577214L; + private int year; + private int month; + private int day; + private boolean isSelected; + + public MyLabel(int year, int month, int day) { + super("" + day, 0); + this.year = year; + this.day = day; + this.month = month; + this.addMouseListener(this); + this.addMouseMotionListener(this); + this.setFont(DateChooser.this.font); + if (month == DateChooser.this.select.get(2)) { + this.setForeground(Color.BLACK); + } else { + this.setForeground(Color.LIGHT_GRAY); + } + + if (day == DateChooser.this.select.get(5)) { + this.setBackground(new Color(160, 185, 215)); + } else { + this.setBackground(Color.WHITE); + } + + } + + public boolean getIsSelected() { + return this.isSelected; + } + + public void setSelected(boolean b, boolean isDrag) { + this.isSelected = b; + if (b && !isDrag) { + int temp = DateChooser.this.select.get(2); + DateChooser.this.select.set(this.year, this.month, this.day); + if (temp == this.month) { + SwingUtilities.updateComponentTreeUI(DateChooser.this.jp3); + } else { + DateChooser.this.refresh(); + } + } + + this.repaint(); + } + + protected void paintComponent(Graphics g) { + if (this.day == DateChooser.this.select.get(5) && this.month == DateChooser.this.select.get(2)) { + g.setColor(new Color(160, 185, 215)); + g.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + if (this.year == DateChooser.this.now.get(1) && this.month == DateChooser.this.now.get(2) + && this.day == DateChooser.this.now.get(5)) { + Graphics2D gdx = (Graphics2D) g; + gdx.setColor(Color.RED); + Polygon p = new Polygon(); + p.addPoint(0, 0); + p.addPoint(this.getWidth() - 1, 0); + p.addPoint(this.getWidth() - 1, this.getHeight() - 1); + p.addPoint(0, this.getHeight() - 1); + gdx.drawPolygon(p); + } + + if (this.isSelected) { + Stroke s = new BasicStroke(1.0F, 2, 2, 1.0F, new float[] { 2.0F, 2.0F }, 1.0F); + Graphics2D gd = (Graphics2D) g; + gd.setStroke(s); + gd.setColor(Color.BLACK); + Polygon px = new Polygon(); + px.addPoint(0, 0); + px.addPoint(this.getWidth() - 1, 0); + px.addPoint(this.getWidth() - 1, this.getHeight() - 1); + px.addPoint(0, this.getHeight() - 1); + gd.drawPolygon(px); + } + + super.paintComponent(g); + } + + public boolean contains(Point p) { + return this.getBounds().contains(p); + } + + private void update() { + this.repaint(); + } + + public void mouseClicked(MouseEvent e) { + } + + public void mousePressed(MouseEvent e) { + this.isSelected = true; + this.update(); + } + + public void mouseReleased(MouseEvent e) { + Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3); + DateChooser.this.lm.setSelect(p, false); + DateChooser.this.commit(); + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + + public void mouseDragged(MouseEvent e) { + Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3); + DateChooser.this.lm.setSelect(p, true); + } + + public void mouseMoved(MouseEvent e) { + } + + public int compare(DateChooser.MyLabel o1, DateChooser.MyLabel o2) { + Calendar c1 = Calendar.getInstance(); + c1.set(o1.year, o2.month, o1.day); + Calendar c2 = Calendar.getInstance(); + c2.set(o2.year, o2.month, o2.day); + return c1.compareTo(c2); + } + } +} diff --git a/src/com/connor/ly/project/ExportProjectDashboardHandler.java b/src/com/connor/ly/project/ExportProjectDashboardHandler.java new file mode 100644 index 0000000..7ce25d1 --- /dev/null +++ b/src/com/connor/ly/project/ExportProjectDashboardHandler.java @@ -0,0 +1,22 @@ +package com.connor.ly.project; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; + +public class ExportProjectDashboardHandler extends AbstractHandler{ + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + session.queueOperation(new ExportProjectDashboardOperations(app,session)); + return null; + } + +} diff --git a/src/com/connor/ly/project/ExportProjectDashboardOperations.java b/src/com/connor/ly/project/ExportProjectDashboardOperations.java new file mode 100644 index 0000000..ffa7fcf --- /dev/null +++ b/src/com/connor/ly/project/ExportProjectDashboardOperations.java @@ -0,0 +1,791 @@ +package com.connor.ly.project; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Label; +import java.awt.event.ActionEvent; + +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.function.BiConsumer; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import com.connor.lyProess.exportToWordOperation2.RwJComboBox; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class ExportProjectDashboardOperations extends AbstractAIFOperation{ + private TCSession session; + private AbstractAIFUIApplication app; + private TCComponentDataset dataset; + private File file; + private String[] tempNames; + private JComboBox templatebBox = new JComboBox<>(); + private JTextField customerNameField; + private JTextField startAfterField; + private JTextField startBeforeField; + private JTextField finishAfterField; + private JTextField finishBeforeField; + private JTextField creationAfterField; + private JTextField creationBeforeField; + + private DateChooser dateChooser1 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser2 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser3 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser4 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser5 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser6 = DateChooser.getInstance("yyyy-M-d"); + + private JTextField outputPathField; + private JButton browseButton; + private JButton exportButton; + private JButton cancelButton; + + private int rowCounter = 0; // м + + public ExportProjectDashboardOperations(AbstractAIFUIApplication app, TCSession session) { + // TODO Auto-generated constructor stub + this.app = app; + this.session = session; + try { + if(!getSXX()) { + return; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * + * @Title: getSXX + * @Description: ȡѡ + * @param @return + * @param @throws TCException + * @return Boolean + * @throws + */ + private Boolean getSXX() throws TCException { + // TODO Auto-generated method stub + String uid = session.getPreferenceService().getStringValue("LY_ProjectDashBoard_UID"); + TCComponent component = session.stringToComponent(uid); + if(component instanceof TCComponentDataset) { + dataset = (TCComponentDataset)component; + }else { + MessageBox.post(app.getDesktop(), "ѡLY_ProjectDashBoard_UIDδҵݼģ", "ERROR", MessageBox.ERROR); + return false; + } + TCComponentTcFile[] files = dataset.getTcFiles(); + file = files[0].getFile(System.getProperty("java.io.tmpdir")); + + tempNames = session.getPreferenceService().getStringValues("LY_ProjectDashBoard_ScheduleTemplate"); + if(tempNames == null || tempNames.length == 0) { + MessageBox.post(app.getDesktop(), "ѡLY_ProjectDashBoard_ScheduleTemplateδҵʱģѡ", "ERROR", MessageBox.ERROR); + return false; + } + return true; + } + + @Override + public void executeOperation() throws Exception { + // TODO Auto-generated method stub + //ʼҳ + JFrame jFrame = new JFrame(); + jFrame.setTitle("Ŀ"); + jFrame.setSize(750, 300); + jFrame.setDefaultCloseOperation(2); + jFrame.setLocationRelativeTo(null); + jFrame.setResizable(true); // ڴС + + // 岢 GridBagLayout + JPanel mainPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(5, 5, 5, 5); // ֮ļࣨϡ¡ң + + // ڴһԱǩı򣬲һǵ + BiConsumer addPairRow = (panel, labels) -> { + System.out.println("Processing labels: " + Arrays.toString(labels)); // ӡǩȷֵ + + JLabel label1 = new JLabel(labels[0] + ":", SwingConstants.RIGHT); + JTextField textField1 = null; // ֻеҪʱŴ + JComboBox textbBox = null; // ֻеҪʱŴ + + JLabel label2 = new JLabel(labels[1] + ":", SwingConstants.RIGHT); + JTextField textField2 = null; // ֻеҪʱŴ + + // ݱǩıʵԣҪ + if ("ʱģ".equals(labels[0])) { + templatebBox = new RwJComboBox(tempNames); + templatebBox.setSelectedIndex(-1); + templatebBox.setModel(new DefaultComboBoxModel<>(tempNames)); + textbBox = templatebBox; + } else if ("ƻʼ".equals(labels[0])) { + if (startAfterField == null) startAfterField = new JTextField(20); + textField1 = startAfterField; + dateChooser1.register(textField1); + System.out.println("Registered dateChooser1 with startAfterField"); + } else if ("ƻ".equals(labels[0])) { + if (finishAfterField == null) finishAfterField = new JTextField(20); + textField1 = finishAfterField; + dateChooser3.register(finishAfterField); + System.out.println("Registered dateChooser3 with finishAfterField"); + } else if ("ʱ".equals(labels[0])) { + if (creationAfterField == null) creationAfterField = new JTextField(20); + textField1 = creationAfterField; + dateChooser5.register(creationAfterField); + System.out.println("Registered dateChooser5 with creationAfterField"); + } + + // ڶУ"" + if ("ͻ".equals(labels[1])) { + if (customerNameField == null) customerNameField = new JTextField(20); + textField2 = customerNameField; + }else if ("ƻʼ".equals(labels[1])) { + if (startBeforeField == null) startBeforeField = new JTextField(20); + textField2 = startBeforeField; + dateChooser2.register(startBeforeField); + System.out.println("Registered dateChooser2 with startBeforeField"); + } else if ("ƻ".equals(labels[1])) { + if (finishBeforeField == null) finishBeforeField = new JTextField(20); + textField2 = finishBeforeField; + dateChooser4.register(finishBeforeField); + System.out.println("Registered dateChooser4 with finishBeforeField"); + } else if ("ʱ".equals(labels[1])) { + if (creationBeforeField == null) creationBeforeField = new JTextField(20); + textField2 = creationBeforeField; + dateChooser6.register(creationBeforeField); + System.out.println("Registered dateChooser6 with creationBeforeField"); + } + + // ĬϵıֶΣûдĻ + if (textField1 == null) textField1 = new JTextField(20); + if (textField2 == null) textField2 = new JTextField(20); + + // ӵһǩı + if ("ʱģ".equals(labels[0])) { + gbc.gridx = 0; gbc.gridy = rowCounter; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + panel.add(label1, gbc); + + gbc.gridx = 1; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + panel.add(textbBox, gbc); + }else { + gbc.gridx = 0; gbc.gridy = rowCounter; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + panel.add(label1, gbc); + + gbc.gridx = 1; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + panel.add(textField1, gbc); + } + + + // ӵڶǩı + gbc.gridx = 2; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + panel.add(label2, gbc); + + gbc.gridx = 3; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + panel.add(textField2, gbc); + + rowCounter++; + }; + + // ʱģ ͻ + addPairRow.accept(mainPanel, new String[]{"ʱģ", "ͻ"}); + + // ƻʼ ƻʼ + addPairRow.accept(mainPanel, new String[]{"ƻʼ", "ƻʼ"}); + + // ƻ ƻ + addPairRow.accept(mainPanel, new String[]{"ƻ", "ƻ"}); + + // ʱ ʱ + addPairRow.accept(mainPanel, new String[]{"ʱ", "ʱ"}); + + // · + JLabel outputPathLabel = new JLabel("·:"); + outputPathField = new JTextField(40); + browseButton = new JButton(""); + // ΪťӼ + browseButton.addActionListener((ActionEvent e) -> { + // ļѡΪֻѡĿ¼ + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("ѡ񵼳·"); // ñ + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // ֻѡĿ¼ + fileChooser.setAcceptAllFileFilterUsed(false); // ʾ "ļ" ѡ + + // Ĭϴ򿪵ļΪ + File desktopDir = new File(System.getProperty("user.home"), "Desktop"); + fileChooser.setCurrentDirectory(desktopDir); + + // ļѡԻ + int returnValue = fileChooser.showOpenDialog(browseButton.getParent()); + + // û "ȷ" ť + if (returnValue == JFileChooser.APPROVE_OPTION) { + File selectedFolder = fileChooser.getSelectedFile(); + // ѡļ·õıֶ + outputPathField.setText(selectedFolder.getAbsolutePath()); + } + }); + + gbc.gridx = 0; gbc.gridy = rowCounter; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + mainPanel.add(outputPathLabel, gbc); + + gbc.gridx = 1; + gbc.gridwidth = 3; + gbc.fill = GridBagConstraints.HORIZONTAL; + mainPanel.add(outputPathField, gbc); + + gbc.gridx = 4; + gbc.fill = GridBagConstraints.NONE; + mainPanel.add(browseButton, gbc); + + rowCounter++; + + // ť + JPanel buttonPanel = new JPanel(); + exportButton = new JButton(""); + exportButton.addActionListener((ActionEvent e) -> { + try { + if("".equals(outputPathField.getText().trim())) { + MessageBox.post(app.getDesktop(), "ѡ·󵼳", "ERROR", MessageBox.INFORMATION); + return; + } + WaitingDialog dia = new WaitingDialog(AIFUtility.getCurrentApplication().getDesktop(), "INFOMATION", "ڵ......"); + dia.setVisible(true); + TCComponent[] query = query(); + if(query == null || query.length == 0) { + dia.setVisible(false); + MessageBox.post(app.getDesktop(), "Ϊ", "ʾ", MessageBox.INFORMATION); + return; + } + System.out.println("ʼѯ"); + List property = getProperty(query); + if(property == null || property.size() == 0) { + return; + } + System.out.println("ʼ"); + String export = export(property,file,outputPathField.getText().trim()); + if(export == null) { + dia.setVisible(false); + MessageBox.post(app.getDesktop(), "Ŀ嵼ʧ", "ʧ", MessageBox.ERROR); + return; + } + dia.setVisible(false); + MessageBox.post(app.getDesktop(), "Ŀ嵼ɹ"+export, "ɹ", MessageBox.INFORMATION); + jFrame.dispose(); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + }); + cancelButton = new JButton("ȡ"); + cancelButton.addActionListener((ActionEvent e) -> { + jFrame.dispose(); + }); + buttonPanel.add(exportButton); + buttonPanel.add(cancelButton); + + // + jFrame.add(mainPanel, BorderLayout.CENTER); + jFrame.add(buttonPanel, BorderLayout.SOUTH); + + // ʾ + jFrame.setVisible(true); + } + + /** + * + * @Title: export + * @Description: ݵexcel + * @param @param timeSheets + * @param @param inputFile + * @param @param outputPath + * @param @return + * @return String + * @throws + */ + public String export(List timeSheets, File inputFile, String outputPath) { + Path outputFilePath = null; + try (FileInputStream fis = new FileInputStream(inputFile); + Workbook workbook = new XSSFWorkbook(fis)) { + + Sheet sheet = workbook.getSheetAt(0); // Assuming data is on the first sheet + + int rowIndex = 1; // Start from the second row + for (TimeSheet ts : timeSheets) { + Row row = sheet.getRow(rowIndex) != null ? sheet.getRow(rowIndex) : sheet.createRow(rowIndex); + fillRow(workbook,row, ts); + rowIndex++; + } + + // ȡǰʱʽ + String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")); + + // ļ·ʱȷĿ¼ڡ + String originalFileName = inputFile.getName(); + String fileNameWithoutExtension = originalFileName.substring(0, originalFileName.lastIndexOf('.')); + String fileExtension = originalFileName.substring(originalFileName.lastIndexOf('.')); + String outputFileName = fileNameWithoutExtension + "_" + timestamp + fileExtension; + outputFilePath = Paths.get(outputPath, outputFileName); + Files.createDirectories(outputFilePath.getParent()); + + // Write the output to the specified output path and close the workbook. + try (FileOutputStream fos = new FileOutputStream(outputFilePath.toString())) { + workbook.write(fos); + System.out.println("Export completed successfully. File saved at: " + outputFilePath); + } + } catch (IOException e) { + e.printStackTrace(); + System.err.println("An error occurred while exporting the file."); + } + + // ļַ + return outputFilePath != null ? outputFilePath.toAbsolutePath().toString() : null; + } + + private void fillRow(Workbook workbook, Row row, TimeSheet ts) { + // Ensure the cells exist before setting their values. + for (int i = 0; i <= 21; i++) { // Adjust the loop bound if you have more columns + if (row.getCell(i) == null) { + row.createCell(i); + } + } + row.getCell(0).setCellValue(ts.getId()); // + row.getCell(1).setCellValue(ts.getResponsibleCompany()); // еҵ + row.getCell(2).setCellValue(ts.getResearchGroup()); // Ƶλ + row.getCell(3).setCellValue(ts.getProjectType()); // Ŀ + row.getCell(4).setCellValue(ts.getProjectGrade()); // Ŀȼ + row.getCell(5).setCellValue(ts.getPriority()); // ȼ + row.getCell(6).setCellValue(ts.getProductCode()); // Ʒ + row.getCell(7).setCellValue(ts.getProjectName()); // Ŀ + row.getCell(8).setCellValue(ts.getProductSeries()); // Ʒϵ + row.getCell(9).setCellValue(ts.getProductModel()); // Ʒͺ + row.getCell(10).setCellValue(ts.getClientName()); // ͻ + row.getCell(11).setCellValue(ts.getClientModel()); // ͻͺ/ϱ + row.getCell(12).setCellValue(ts.getProjectStatus()); // ǰչ + row.getCell(13).setCellValue(ts.getMarketPromote()); // Ӫ + row.getCell(14).setCellValue(ts.getPrincipal()); // Ŀ + row.getCell(15).setCellValue(ts.getGate1()); // Gate1 + row.getCell(16).setCellValue(ts.getGate2()); // Gate2 + row.getCell(17).setCellValue(ts.getGate3()); // Gate3 + row.getCell(18).setCellValue(ts.getGate4()); // Gate4 + row.getCell(19).setCellValue(ts.getGate5()); // Gate5 + row.getCell(20).setCellValue(ts.getGate6()); // Gate6 + row.getCell(21).setCellValue(ts.getGate7()); // Gate7 + + // ߿ʽ + XSSFCellStyle borderStyle = (XSSFCellStyle) workbook.createCellStyle(); + borderStyle.setBorderTop(BorderStyle.THIN); + borderStyle.setBorderBottom(BorderStyle.THIN); + borderStyle.setBorderLeft(BorderStyle.THIN); + borderStyle.setBorderRight(BorderStyle.THIN); + + // ÿԪӦñ߿ʽ + for (Cell cell : row) { + cell.setCellStyle(borderStyle); + } + } + + /** + * + * @Title: query + * @Description: Ҷ + * @param + * @return void + * @throws Exception + * @throws + */ + private TCComponent[] query() throws Exception { + // ûIJѯ òѯ ȡ + String template = (String) templatebBox.getSelectedItem(); + String customerName = customerNameField.getText().trim(); + String startAfter = startAfterField.getText().trim(); + String startBefore = startBeforeField.getText().trim(); + String finishAfter = finishAfterField.getText().trim(); + String finishBefore = finishBeforeField.getText().trim(); + String creationAfter = creationAfterField.getText().trim(); + String creationBefore = creationBeforeField.getText().trim(); + + ListqueryNameList = new ArrayList(); + ListqueryAttrList = new ArrayList(); + + if(template != null && !template.isEmpty()) { + String replaceAll = template.replaceAll(", ", ";"); + queryNameList.add("templatename"); + queryAttrList.add(replaceAll); + } + if(customerName != null && !customerName.isEmpty()) { + queryNameList.add("clientName"); + queryAttrList.add(customerName); + } + if(startAfter != null && !startAfter.isEmpty()) { + queryNameList.add("AfterStarted"); + queryAttrList.add(startAfter + " 00:00"); + } + if(startBefore != null && !startBefore.isEmpty()) { + queryNameList.add("BeforeStarted"); + queryAttrList.add(startBefore + " 00:00"); + } + if(finishAfter != null && !finishAfter.isEmpty()) { + queryNameList.add("AfterFinished"); + queryAttrList.add(finishAfter + " 00:00"); + } + if(finishBefore != null && !finishBefore.isEmpty()) { + queryNameList.add("BeforeFinished"); + queryAttrList.add(finishBefore + " 00:00"); + } + if(creationAfter != null && !creationAfter.isEmpty()) { + queryNameList.add("Aftercreationdate"); + queryAttrList.add(creationAfter + " 00:00"); + } + if(creationBefore != null && !creationBefore.isEmpty()) { + queryNameList.add("Beforecreationdate"); + queryAttrList.add(creationBefore + " 00:00"); + } + System.out.println("ѯĿ"+queryNameList); + System.out.println("ѯԣ"+queryAttrList); + //òѯ + TCComponent[] search = session.search("LY_Om_SearchSchedules", queryNameList.toArray(new String [0]), queryAttrList.toArray(new String [0])); + if(search != null && search.length > 0) { + System.out.println("ѯҵ"+search.length+""); + //ʼɸѡ + List tcComponents = new ArrayList(); + for(TCComponent tcComponent : search) { + System.out.println("is_template:"+tcComponent.getProperty("is_template")); + System.out.println("is_baseline:"+tcComponent.getProperty("is_baseline")); + System.out.println("published:"+tcComponent.getProperty("published")); + if("".equalsIgnoreCase(tcComponent.getProperty("is_template")) + && "".equalsIgnoreCase(tcComponent.getProperty("is_baseline")) + && "".equalsIgnoreCase(tcComponent.getProperty("published"))) { + tcComponents.add(tcComponent); + }else { + continue; + } + } + System.out.println("ɸѡ"+tcComponents.size()); + return tcComponents.toArray(new TCComponent[0]); + } + MessageBox.post(app.getDesktop(), "δѯЧ", "ERROR", MessageBox.ERROR); + return null; + } + + private List getProperty(TCComponent[] query) throws TCException { + // TODO Auto-generated method stub + List timeSheets = new ArrayList(); + for(int i = 0;i 0) { + for(TCComponent tcComponent : referenceListProperty) { + if("LY6_NPIForm".equals(tcComponent.getType())) { + form = tcComponent; + break; + } + } + } + if(form == null) { + System.out.println("ȡΪգûIMAN_referenceҵLY6_NPIFormͱ"); + } + + + // + timeSheet.setId(i+1); + // еҵ + timeSheet.setResponsibleCompany(form == null ? "" : form.getProperty("ly6_responsibleCompany")); + // Ƶλ + timeSheet.setResearchGroup(form == null ? "" : form.getProperty("ly6_researchGroup")); + // Ŀ + timeSheet.setProjectType(form == null ? "" : form.getProperty("ly6_projectClass")); + // Ŀȼ + timeSheet.setProjectGrade(form == null ? "" : form.getProperty("ly6_projectGrade")); + //ȼ + timeSheet.setPriority(form == null ? "" : form.getProperty("ly6_priority")); + // Ʒ + timeSheet.setProductCode(form == null ? "" : form.getProperty("ly6_projectID")); + // Ŀ + timeSheet.setProjectName(form == null ? "" : form.getProperty("ly6_projectName")); + // Ʒϵ + timeSheet.setProductSeries(form == null ? "" : form.getProperty("ly6_productSeries")); + // Ʒͺ + timeSheet.setProductModel(form == null ? "" : form.getProperty("ly6_productModel")); + // ͻ + timeSheet.setClientName(form == null ? "" : form.getProperty("ly6_clientName")); + // ͻͺ/ϱ + timeSheet.setClientModel(form == null ? "" : form.getProperty("ly6_clientModel")); + // ǰչ + timeSheet.setProjectStatus(form == null ? "" : form.getProperty("ly6_projectStatus")); + // Ӫ + timeSheet.setMarketPromote(form == null ? "" : form.getProperty("ly6_marketPromote")); + // Ŀ + timeSheet.setPrincipal(form == null ? "" : form.getProperty("ly6_principal")); + + //ȡ󼯺 + TCComponent[] gates = getGates2(component); + // Gate1 + timeSheet.setGate1(gates[0] == null ? "N/A" : gates[0].getProperty("fnd0status")); + // Gate2 + timeSheet.setGate2(gates[1] == null ? "N/A" : gates[1].getProperty("fnd0status")); + // Gate3 + timeSheet.setGate3(gates[2] == null ? "N/A" : gates[2].getProperty("fnd0status")); + // Gate4 + timeSheet.setGate4(gates[3] == null ? "N/A" : gates[3].getProperty("fnd0status")); + // Gate5 + timeSheet.setGate5(gates[4] == null ? "N/A" : gates[4].getProperty("fnd0status")); + // Gate6 + timeSheet.setGate6(gates[5] == null ? "N/A" : gates[5].getProperty("fnd0status")); + // Gate7 + timeSheet.setGate7(gates[6] == null ? "N/A" : gates[6].getProperty("fnd0status")); + + System.out.println(timeSheet.toString()); + timeSheets.add(timeSheet); + } + return timeSheets; + } + private TCComponent[] getGates(TCComponent component) throws TCException { + TCComponent[] gates = new TCComponent[7]; + // Ԥŵƥ + String[] gatePatterns = { + "׶(Gate1)", "׶(Gate2)", "׶(Gate3)", + "׶(Gate4)", "׶(Gate5)", "׶(Gate6)", "Ŀƽ" + }; + + // ݹ + traverseComponentTree(component, gates, gatePatterns, 0); + return gates; + } + + private boolean traverseComponentTree(TCComponent current, TCComponent[] gates, String[] patterns, int depth) throws TCException { + // ݹֹȳ3 ҵ + if (depth > 3 || allGatesFilled(gates)) { + return allGatesFilled(gates); + } + + if (current instanceof TCComponentFolder) { + return false; // ļ + } + + // ǵIJ㣬ƥ + if (depth == 3) { + String objectName = current.getProperty("object_name"); + String taskType = current.getProperty("task_type"); + + for (int i = 0; i < patterns.length; i++) { + if (gates[i] == null && objectName.contains(patterns[i]) && "1".equals(taskType)) { + gates[i] = current; + System.out.printf("ҵ%s%n", patterns[i]); + break; // ظƥ + } + } + } + + // ݹ + AIFComponentContext[] children = current.getChildren(); + for (AIFComponentContext childCtx : children) { + TCComponent child = (TCComponent) childCtx.getComponent(); + if (traverseComponentTree(child, gates, patterns, depth + 1)) { + return true; // ӱзǰֹ + } + } + + return allGatesFilled(gates); + } + + // Ƿҵ + private boolean allGatesFilled(TCComponent[] gates) { + for (TCComponent gate : gates) { + if (gate == null) { + return false; + } + } + return true; + } + + private TCComponent[] getGates2(TCComponent component) throws TCException { + // TODO Auto-generated method stub + //һ + TCComponent[] gates = new TCComponent[7]; + System.out.println("1ƣ"+component.getProperty("object_name")); + System.out.println(component.getChildrenCount()); + if(component.getChildrenCount() > 0) { + AIFComponentContext[] children = component.getChildren(); + for(AIFComponentContext aifComponentContext : children) { + TCComponent component2 = (TCComponent)aifComponentContext.getComponent(); + System.out.println("2ƣ"+component2.getProperty("object_name")); + if(component2 instanceof TCComponentFolder) { + continue; + } + //ڶ + System.out.println(component2.getChildrenCount()); + if(component2.getChildrenCount() > 0) { + AIFComponentContext[] children2 = component2.getChildren(); + for(AIFComponentContext aifComponentContext2 : children2) { + TCComponent component3 = (TCComponent)aifComponentContext2.getComponent(); + System.out.println("3ƣ"+component3.getProperty("object_name")); + if(component3.getChildrenCount() > 0) { + AIFComponentContext[] children3 = component3.getChildren(); + for(AIFComponentContext aifComponentContext1 : children3) { + if(gates[0] != null && gates[1] != null && gates[2] != null + && gates[3] != null && gates[4] != null && gates[5] != null + && gates[6] != null) { + return gates; + } + TCComponent component4 = (TCComponent)aifComponentContext1.getComponent(); + System.out.println("4ƣ"+component4.getProperty("object_name")); + System.out.println("task_type:"+component4.getProperty("task_type")); + // 鵱ǰǷƥ + + if (gates[0] == null && component4.getProperty("object_name").contains("׶(Gate1)") && + component4.getProperty("task_type").equals("1")) { + System.out.printf("ҵ׶(Gate1)"); + gates[0] = component4; + continue; + } + if (gates[1] == null && component4.getProperty("object_name").contains("׶(Gate2)") && + component4.getProperty("task_type").equals("1")) { + System.out.printf("ҵ׶(Gate2)"); + gates[1] = component4; + continue; + } + if (gates[2] == null && component4.getProperty("object_name").contains("׶(Gate3)") && + component4.getProperty("task_type").equals("1")) { + System.out.printf("ҵ׶(Gate3)"); + gates[2] = component4; + continue; + } + if (gates[3] == null && component4.getProperty("object_name").contains("׶(Gate4)") && + component4.getProperty("task_type").equals("1")) { + System.out.printf("ҵ׶(Gate4)"); + gates[3] = component4; + continue; + } + if (gates[4] == null && component4.getProperty("object_name").contains("׶(Gate5)") && + component4.getProperty("task_type").equals("1")) { + System.out.printf("ҵ׶(Gate5)"); + gates[4] = component4; + continue; + } + if (gates[5] == null && component4.getProperty("object_name").contains("׶(Gate6)") && + component4.getProperty("task_type").equals("1")) { + System.out.printf("ҵ׶(Gate6)"); + gates[5] = component4; + continue; + } + if (gates[6] == null && component4.getProperty("object_name").contains("Ŀƽ") && + component4.getProperty("task_type").equals("1")) { + System.out.printf("Ŀƽ"); + gates[6] = component4; + continue; + } + } + } + + } + } + } + }else { + return null; + } + return gates; + } +} + +/** + * + * @ClassName: WaitingDialog + * @Description: + * @author hcj + * @date 202526 + * + */ +class WaitingDialog extends com.teamcenter.rac.aif.AbstractAIFDialog { + private static final long serialVersionUID = 1L; + public JPanel panel; + JProgressBar progressBar = null; + + public WaitingDialog(Frame arg0, String title, String message) { + super(arg0, title); + this.setModal(false); + + panel = new JPanel(new BorderLayout()); + + /* + * JLabel label = new JLabel(message); System.out.println("message:"+message); + * System.out.println("label:"+label); panel.add(label); + */ + + progressBar = new JProgressBar(SwingConstants.HORIZONTAL); + progressBar.setVisible(true); + progressBar.setIndeterminate(true); + + panel.add(BorderLayout.CENTER, new Label(message)); + panel.add(BorderLayout.SOUTH, progressBar); + + panel.setPreferredSize(new Dimension(350, 60)); + + this.getContentPane().add(panel); + + centerToScreen(); + + pack(); + + } +} \ No newline at end of file diff --git a/src/com/connor/ly/project/ProjectDashboardExporter.java b/src/com/connor/ly/project/ProjectDashboardExporter.java new file mode 100644 index 0000000..5edbdaf --- /dev/null +++ b/src/com/connor/ly/project/ProjectDashboardExporter.java @@ -0,0 +1,243 @@ +package com.connor.ly.project; + +import javax.swing.*; + +import com.connor.lyProess.exportToWordOperation2.RwJComboBox; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.io.File; +import java.util.Arrays; +import java.util.function.BiConsumer; + +public class ProjectDashboardExporter { + + private JComboBox templatebBox = new JComboBox<>(); + private JTextField customerNameField; + private JTextField startAfterField; + private JTextField startBeforeField; + private JTextField finishAfterField; + private JTextField finishBeforeField; + private JTextField creationAfterField; + private JTextField creationBeforeField; + + private DateChooser dateChooser1 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser2 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser3 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser4 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser5 = DateChooser.getInstance("yyyy-M-d"); + private DateChooser dateChooser6 = DateChooser.getInstance("yyyy-M-d"); + + private JTextField outputPathField; + private JButton browseButton; + private JButton exportButton; + private JButton cancelButton; + + private int rowCounter = 0; // м + + public ProjectDashboardExporter() { + JFrame jFrame = new JFrame(); + jFrame.setTitle("Ŀ"); + jFrame.setSize(750, 300); + jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jFrame.setLocationRelativeTo(null); + jFrame.setResizable(true); // ڴС + + // 岢 GridBagLayout + JPanel mainPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(5, 5, 5, 5); // ֮ļࣨϡ¡ң + + // ڴһԱǩı򣬲һǵ + BiConsumer addPairRow = (panel, labels) -> { + System.out.println("Processing labels: " + Arrays.toString(labels)); // ӡǩȷֵ + + JLabel label1 = new JLabel(labels[0] + ":", SwingConstants.RIGHT); + JTextField textField1 = null; // ֻеҪʱŴ + JComboBox textbBox = null; // ֻеҪʱŴ + + JLabel label2 = new JLabel(labels[1] + ":", SwingConstants.RIGHT); + JTextField textField2 = null; // ֻеҪʱŴ + + // ݱǩıʵԣҪ + if ("ʱģ".equals(labels[0])) { + String[] array = new String[]{"Ӣ","ȷ","Խ",""}; + templatebBox = new RwJComboBox(array); + templatebBox.setSelectedIndex(-1); + templatebBox.setModel(new DefaultComboBoxModel<>(array)); + textbBox = templatebBox; + } else if ("ƻʼ".equals(labels[0])) { + if (startAfterField == null) startAfterField = new JTextField(20); + textField1 = startAfterField; + dateChooser1.register(textField1); + System.out.println("Registered dateChooser1 with startAfterField"); + } else if ("ƻ".equals(labels[0])) { + if (finishAfterField == null) finishAfterField = new JTextField(20); + textField1 = finishAfterField; + dateChooser3.register(finishAfterField); + System.out.println("Registered dateChooser3 with finishAfterField"); + } else if ("ʱ".equals(labels[0])) { + if (creationAfterField == null) creationAfterField = new JTextField(20); + textField1 = creationAfterField; + dateChooser5.register(creationAfterField); + System.out.println("Registered dateChooser5 with creationAfterField"); + } + + // ڶУ"" + if ("ͻ".equals(labels[1])) { + if (customerNameField == null) customerNameField = new JTextField(20); + textField2 = customerNameField; + }else if ("ƻʼ".equals(labels[1])) { + if (startBeforeField == null) startBeforeField = new JTextField(20); + textField2 = startBeforeField; + dateChooser2.register(startBeforeField); + System.out.println("Registered dateChooser2 with startBeforeField"); + } else if ("ƻ".equals(labels[1])) { + if (finishBeforeField == null) finishBeforeField = new JTextField(20); + textField2 = finishBeforeField; + dateChooser4.register(finishBeforeField); + System.out.println("Registered dateChooser4 with finishBeforeField"); + } else if ("ʱ".equals(labels[1])) { + if (creationBeforeField == null) creationBeforeField = new JTextField(20); + textField2 = creationBeforeField; + dateChooser6.register(creationBeforeField); + System.out.println("Registered dateChooser6 with creationBeforeField"); + } + + // ĬϵıֶΣûдĻ + if (textField1 == null) textField1 = new JTextField(20); + if (textField2 == null) textField2 = new JTextField(20); + + // ӵһǩı + if ("ʱģ".equals(labels[0])) { + gbc.gridx = 0; gbc.gridy = rowCounter; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + panel.add(label1, gbc); + + gbc.gridx = 1; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + panel.add(textbBox, gbc); + }else { + gbc.gridx = 0; gbc.gridy = rowCounter; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + panel.add(label1, gbc); + + gbc.gridx = 1; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + panel.add(textField1, gbc); + } + + + // ӵڶǩı + gbc.gridx = 2; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + panel.add(label2, gbc); + + gbc.gridx = 3; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + panel.add(textField2, gbc); + + rowCounter++; + }; + + // ʱģ ͻ + addPairRow.accept(mainPanel, new String[]{"ʱģ", "ͻ"}); + + // ƻʼ ƻʼ + addPairRow.accept(mainPanel, new String[]{"ƻʼ", "ƻʼ"}); + + // ƻ ƻ + addPairRow.accept(mainPanel, new String[]{"ƻ", "ƻ"}); + + // ʱ ʱ + addPairRow.accept(mainPanel, new String[]{"ʱ", "ʱ"}); + + // · + JLabel outputPathLabel = new JLabel("·:"); + outputPathField = new JTextField(40); + outputPathField.setText("C:\\Users\\Administrator\\Desktop"); + browseButton = new JButton(""); + // ΪťӼ + browseButton.addActionListener((ActionEvent e) -> { + // ļѡΪֻѡĿ¼ + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("ѡ񵼳·"); // ñ + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // ֻѡĿ¼ + fileChooser.setAcceptAllFileFilterUsed(false); // ʾ "ļ" ѡ + + // Ĭϴ򿪵ļΪ + File desktopDir = new File(System.getProperty("user.home"), "Desktop"); + fileChooser.setCurrentDirectory(desktopDir); + + // ļѡԻ + int returnValue = fileChooser.showOpenDialog(browseButton.getParent()); + + // û "ȷ" ť + if (returnValue == JFileChooser.APPROVE_OPTION) { + File selectedFolder = fileChooser.getSelectedFile(); + // ѡļ·õıֶ + outputPathField.setText(selectedFolder.getAbsolutePath()); + } + }); + + gbc.gridx = 0; gbc.gridy = rowCounter; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.NONE; + mainPanel.add(outputPathLabel, gbc); + + gbc.gridx = 1; + gbc.gridwidth = 3; + gbc.fill = GridBagConstraints.HORIZONTAL; + mainPanel.add(outputPathField, gbc); + + gbc.gridx = 4; + gbc.fill = GridBagConstraints.NONE; + mainPanel.add(browseButton, gbc); + + rowCounter++; + + // ť + JPanel buttonPanel = new JPanel(); + exportButton = new JButton(""); + cancelButton = new JButton("ȡ"); + exportButton.addActionListener((ActionEvent e) -> { + String template = (String) templatebBox.getSelectedItem(); + String customerName = customerNameField.getText().trim(); + String startAfter = startAfterField.getText().trim(); + String startBefore = startBeforeField.getText().trim(); + String finishAfter = finishAfterField.getText().trim(); + String finishBefore = finishBeforeField.getText().trim(); + String creationAfter = creationAfterField.getText().trim(); + String creationBefore = creationBeforeField.getText().trim(); + String outputPath = outputPathField.getText().trim(); + System.out.println(template); + System.out.println(customerName); + System.out.println(startAfter); + System.out.println(startBefore); + System.out.println(finishAfter); + System.out.println(finishBefore); + System.out.println(creationAfter); + System.out.println(creationBefore); + System.out.println(outputPath); + }); + buttonPanel.add(exportButton); + buttonPanel.add(cancelButton); + + // + jFrame.add(mainPanel, BorderLayout.CENTER); + jFrame.add(buttonPanel, BorderLayout.SOUTH); + + // ʾ + jFrame.setVisible(true); + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> new ProjectDashboardExporter()); + } +} \ No newline at end of file diff --git a/src/com/connor/ly/project/TimeSheet.java b/src/com/connor/ly/project/TimeSheet.java new file mode 100644 index 0000000..3447962 --- /dev/null +++ b/src/com/connor/ly/project/TimeSheet.java @@ -0,0 +1,171 @@ +package com.connor.ly.project; + +public class TimeSheet { + private int id; // + private String responsibleCompany; // еҵ + private String researchGroup; // Ƶλ + private String projectType; // Ŀ + private String projectGrade; // Ŀȼ + private String priority; // ȼ + private String productCode; // Ʒ + private String projectName; // Ŀ + private String productSeries; // Ʒϵ + private String productModel; // Ʒͺ + private String clientName; // ͻ + private String clientModel; // ͻͺ/ϱ + private String projectStatus; // ǰչ + private String marketPromote; // Ӫ + private String principal; // Ŀ + private String gate1; // Gate1 + private String gate2; // Gate2 + private String gate3; // Gate3 + private String gate4; // Gate4 + private String gate5; // Gate5 + private String gate6; // Gate6 + private String gate7; // Gate7 + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getResponsibleCompany() { + return responsibleCompany; + } + public void setResponsibleCompany(String responsibleCompany) { + this.responsibleCompany = responsibleCompany; + } + public String getResearchGroup() { + return researchGroup; + } + public void setResearchGroup(String researchGroup) { + this.researchGroup = researchGroup; + } + public String getProjectType() { + return projectType; + } + public void setProjectType(String projectType) { + this.projectType = projectType; + } + public String getProjectGrade() { + return projectGrade; + } + public void setProjectGrade(String projectGrade) { + this.projectGrade = projectGrade; + } + public String getPriority() { + return priority; + } + public void setPriority(String priority) { + this.priority = priority; + } + public String getProductCode() { + return productCode; + } + public void setProductCode(String productCode) { + this.productCode = productCode; + } + public String getProjectName() { + return projectName; + } + public void setProjectName(String projectName) { + this.projectName = projectName; + } + public String getProductSeries() { + return productSeries; + } + public void setProductSeries(String productSeries) { + this.productSeries = productSeries; + } + public String getProductModel() { + return productModel; + } + public void setProductModel(String productModel) { + this.productModel = productModel; + } + public String getClientName() { + return clientName; + } + public void setClientName(String clientName) { + this.clientName = clientName; + } + public String getClientModel() { + return clientModel; + } + public void setClientModel(String clientModel) { + this.clientModel = clientModel; + } + public String getProjectStatus() { + return projectStatus; + } + public void setProjectStatus(String projectStatus) { + this.projectStatus = projectStatus; + } + public String getMarketPromote() { + return marketPromote; + } + public void setMarketPromote(String marketPromote) { + this.marketPromote = marketPromote; + } + public String getPrincipal() { + return principal; + } + public void setPrincipal(String principal) { + this.principal = principal; + } + public String getGate1() { + return gate1; + } + public void setGate1(String gate1) { + this.gate1 = gate1; + } + public String getGate2() { + return gate2; + } + public void setGate2(String gate2) { + this.gate2 = gate2; + } + public String getGate3() { + return gate3; + } + public void setGate3(String gate3) { + this.gate3 = gate3; + } + public String getGate4() { + return gate4; + } + public void setGate4(String gate4) { + this.gate4 = gate4; + } + public String getGate5() { + return gate5; + } + public void setGate5(String gate5) { + this.gate5 = gate5; + } + public String getGate6() { + return gate6; + } + public void setGate6(String gate6) { + this.gate6 = gate6; + } + public String getGate7() { + return gate7; + } + public void setGate7(String gate7) { + this.gate7 = gate7; + } + @Override + public String toString() { + return "TimeSheet [id=" + id + ", responsibleCompany=" + responsibleCompany + ", researchGroup=" + researchGroup + + ", projectType=" + projectType + ", projectGrade=" + projectGrade + ", priority=" + priority + + ", productCode=" + productCode + ", projectName=" + projectName + ", productSeries=" + productSeries + + ", productModel=" + productModel + ", clientName=" + clientName + ", clientModel=" + clientModel + + ", projectStatus=" + projectStatus + ", marketPromote=" + marketPromote + ", principal=" + principal + + ", gate1=" + gate1 + ", gate2=" + gate2 + ", gate3=" + gate3 + ", gate4=" + gate4 + ", gate5=" + gate5 + + ", gate6=" + gate6 + ", gate7=" + gate7 + "]"; + } + + + +} diff --git a/src/com/connor/ly/project/test.java b/src/com/connor/ly/project/test.java new file mode 100644 index 0000000..9c762a4 --- /dev/null +++ b/src/com/connor/ly/project/test.java @@ -0,0 +1,268 @@ +package com.connor.ly.project; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.geom.RoundRectangle2D; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +public class test extends JPanel { + private JTextField dateField; + private JDialog dateDialog; + private JComboBox yearCombo; + private JComboBox monthCombo; + private JComboBox dayCombo; + private JButton[][] dayButtons; + private Calendar currentCalendar; + private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + public test() { + initUI(); + } + + private void initUI() { + // Ͱť + setLayout(new BorderLayout(5, 5)); + setBorder(new EmptyBorder(10, 10, 10, 10)); + setBackground(new Color(245, 245, 245)); + + dateField = new JTextField(10); + dateField.setFont(new Font("Segoe UI", Font.PLAIN, 14)); + dateField.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(new Color(200, 200, 200)), + BorderFactory.createEmptyBorder(5, 10, 5, 10))); + dateField.setEditable(true); + + JButton openBtn = new JButton("selct"); + openBtn.setFont(new Font("Segoe UI", Font.PLAIN, 14)); + openBtn.setBackground(new Color(0, 123, 255)); + openBtn.setForeground(Color.WHITE); + openBtn.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15)); + openBtn.setFocusPainted(false); + + // ı + dateField.getDocument().addDocumentListener(new DocumentListener() { + public void changedUpdate(DocumentEvent e) { updateDatePanel(); } + public void removeUpdate(DocumentEvent e) { updateDatePanel(); } + public void insertUpdate(DocumentEvent e) { updateDatePanel(); } + }); + + // 尴ť + openBtn.addActionListener(e -> showDateDialog()); + + add(dateField, BorderLayout.CENTER); + add(openBtn, BorderLayout.EAST); + createDatePanel(); + } + + // ѡ + private void createDatePanel() { + dateDialog = new JDialog(); + dateDialog.setModal(true); + dateDialog.setSize(300, 300); + dateDialog.setLayout(new BorderLayout()); + dateDialog.getContentPane().setBackground(new Color(245, 245, 245)); + dateDialog.setUndecorated(true); + dateDialog.setShape(new RoundRectangle2D.Double(0, 0, 300, 300, 20, 20)); + + // ѡ + JPanel yearMonthDayPanel = new JPanel(); + yearMonthDayPanel.setBackground(new Color(245, 245, 245)); + yearMonthDayPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); + + yearCombo = new JComboBox<>(); + yearCombo.setFont(new Font("Segoe UI", Font.PLAIN, 14)); + yearCombo.setBackground(Color.WHITE); + yearCombo.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); + + monthCombo = new JComboBox<>(new String[]{"1", "2", "3", "4", "5", "6", + "7", "8", "9", "10", "11", "12"}); + monthCombo.setFont(new Font("Segoe UI", Font.PLAIN, 14)); + monthCombo.setBackground(Color.WHITE); + monthCombo.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); + + dayCombo = new JComboBox<>(); + dayCombo.setFont(new Font("Segoe UI", Font.PLAIN, 14)); + dayCombo.setBackground(Color.WHITE); + dayCombo.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); + + // ʼݣǰ20꣩ + int currentYear = Calendar.getInstance().get(Calendar.YEAR); + for (int i = currentYear - 20; i <= currentYear + 20; i++) { + yearCombo.addItem(i); + } + + // ʼ·ݺ + monthCombo.setSelectedIndex(Calendar.getInstance().get(Calendar.MONTH)); + updateDayCombo(); // ʼ + + yearMonthDayPanel.add(yearCombo); + yearMonthDayPanel.add(monthCombo); + yearMonthDayPanel.add(dayCombo); + + // ڰť + JPanel dayPanel = new JPanel(new GridLayout(6, 7, 5, 5)); + dayPanel.setBackground(new Color(245, 245, 245)); + dayPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); + + dayButtons = new JButton[6][7]; + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 7; j++) { + dayButtons[i][j] = new JButton(); + dayButtons[i][j].setFont(new Font("Segoe UI", Font.PLAIN, 12)); + dayButtons[i][j].setBackground(Color.WHITE); + dayButtons[i][j].setForeground(new Color(50, 50, 50)); + dayButtons[i][j].setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + dayButtons[i][j].setFocusPainted(false); + dayPanel.add(dayButtons[i][j]); + } + } + + // ѡ + yearCombo.addActionListener(e -> { + updateDayCombo(); + updateCalendar(); + }); + monthCombo.addActionListener(e -> { + updateDayCombo(); + updateCalendar(); + }); + dayCombo.addActionListener(e -> updateCalendar()); + + dateDialog.add(yearMonthDayPanel, BorderLayout.NORTH); + dateDialog.add(dayPanel, BorderLayout.CENTER); + } + + // + private void updateDayCombo() { + int year = (Integer) yearCombo.getSelectedItem(); + int month = monthCombo.getSelectedIndex(); + + // 㵱ǰ·ݵ + Calendar temp = Calendar.getInstance(); + temp.set(year, month, 1); + int maxDay = temp.getActualMaximum(Calendar.DAY_OF_MONTH); + + // + dayCombo.removeAllItems(); + for (int i = 1; i <= maxDay; i++) { + dayCombo.addItem(i); + } + + // Ĭѡ + if (currentCalendar != null) { + int currentDay = currentCalendar.get(Calendar.DAY_OF_MONTH); + if (currentDay <= maxDay) { + dayCombo.setSelectedItem(currentDay); + } else { + dayCombo.setSelectedItem(maxDay); + } + } else { + dayCombo.setSelectedItem(1); + } + } + + // ʾڶԻ + private void showDateDialog() { + initCurrentCalendar(); + updateDayCombo(); // ȷȷʼ + updateCalendar(); + dateDialog.setLocationRelativeTo(this); + dateDialog.setVisible(true); + } + + // ʼǰ + private void initCurrentCalendar() { + currentCalendar = Calendar.getInstance(); + try { + Date date = dateFormat.parse(dateField.getText()); + currentCalendar.setTime(date); + } catch (ParseException e) { + currentCalendar.setTime(new Date()); + } + } + + // ʾ + private void updateCalendar() { + int year = (Integer) yearCombo.getSelectedItem(); + int month = monthCombo.getSelectedIndex(); + int day = (Integer) dayCombo.getSelectedItem(); + + currentCalendar.set(Calendar.YEAR, year); + currentCalendar.set(Calendar.MONTH, month); + currentCalendar.set(Calendar.DAY_OF_MONTH, day); + + // + for (JButton[] row : dayButtons) { + for (JButton btn : row) { + btn.setText(""); + btn.setEnabled(false); + btn.setBackground(Color.WHITE); + btn.setForeground(new Color(50, 50, 50)); + btn.removeActionListener(null); + } + } + + // 㵱 + Calendar temp = (Calendar) currentCalendar.clone(); + int startDay = temp.get(Calendar.DAY_OF_WEEK); + int maxDay = temp.getActualMaximum(Calendar.DAY_OF_MONTH); + + // ڰť + int row = 0; + for (int d = 1; d <= maxDay; d++) { + int column = (startDay + d - 2) % 7; + if (d > 1 && column == 0) row++; + + JButton btn = dayButtons[row][column]; + btn.setText(String.valueOf(d)); + btn.setEnabled(true); + + if (d == currentCalendar.get(Calendar.DAY_OF_MONTH)) { + btn.setBackground(new Color(0, 123, 255)); + btn.setForeground(Color.WHITE); + } + + final int selectedDay = d; + btn.addActionListener(e -> { + currentCalendar.set(Calendar.DAY_OF_MONTH, selectedDay); + dateField.setText(dateFormat.format(currentCalendar.getTime())); + dateDialog.setVisible(false); + }); + } + } + + // ı + private void updateDatePanel() { + try { + Date date = dateFormat.parse(dateField.getText()); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + + yearCombo.setSelectedItem(cal.get(Calendar.YEAR)); + monthCombo.setSelectedIndex(cal.get(Calendar.MONTH)); + dayCombo.setSelectedItem(cal.get(Calendar.DAY_OF_MONTH)); + updateCalendar(); + } catch (ParseException ex) { + // Чڸʽ + } + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + JFrame frame = new JFrame("ѡʾ"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(new test()); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + }); + } +} \ No newline at end of file diff --git a/src/com/connor/lyProess/CheckboxComboBox.java b/src/com/connor/lyProess/CheckboxComboBox.java new file mode 100644 index 0000000..6694cc2 --- /dev/null +++ b/src/com/connor/lyProess/CheckboxComboBox.java @@ -0,0 +1,151 @@ +package com.connor.lyProess; + +import javax.swing.*; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.ComboPopup; +import javax.swing.plaf.metal.MetalComboBoxUI; +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +public class CheckboxComboBox { + public static void main(String[] args) { + String[] items = new String[10]; + for (int i = 0; i < items.length; i++) { + items[i] = "Item " + (i + 1); + } + + JComboBox comboBox = new RwJComboBox(items); + comboBox.setEditable(true); + comboBox.setPreferredSize(new Dimension(400, 60)); + + JFrame frame = new JFrame("Checkbox ComboBox Demo"); + frame.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20)); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(500, 500); + frame.setLocationRelativeTo(null); + frame.add(comboBox); + frame.add(new JTextField(40)); // Խ¼ + frame.setVisible(true); + } + + public static class RwJComboBox extends JComboBox implements FocusListener { + protected Set selectedIndices = new HashSet<>(); + + public RwJComboBox(String[] items) { + setModel(new RwDefaultComboBoxModel(items)); + setUI(new RwMetalComboBoxUI(this)); + setRenderer(new RwJCheckBox()); + setSelectedIndex(-1); + addFocusListener(this); + } + + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + } + } + + public static class RwMetalComboBoxUI extends MetalComboBoxUI { + private RwMetalComboBoxUI(RwJComboBox rwJComboBox) { + this.comboBox = rwJComboBox; + } + + protected ComboPopup createPopup() { + return new RwBasicComboPopup(comboBox); + } + } + + public static class RwBasicComboPopup extends BasicComboPopup { + public RwBasicComboPopup(JComboBox combo) { + super(combo); + } + + protected void configureList() { + super.configureList(); + list.setSelectionModel(new RwDefaultListSelectionModel(comboBox)); + } + + protected MouseListener createListMouseListener() { + return new RwMouseAdapter(list, comboBox); + } + } + + private static class RwDefaultListSelectionModel extends DefaultListSelectionModel { + protected RwJComboBox rwJComboBox; + + public RwDefaultListSelectionModel(JComboBox comboBox) { + this.rwJComboBox = (RwJComboBox) comboBox; + } + + @Override + public boolean isSelectedIndex(int index) { + return rwJComboBox.selectedIndices.contains(index); + } + } + + private static class RwMouseAdapter extends MouseAdapter { + protected JList list; + protected RwJComboBox rwJComboBox; + + private RwMouseAdapter(JList list, JComboBox comboBox) { + this.list = list; + this.rwJComboBox = (RwJComboBox) comboBox; + } + + @Override + public void mousePressed(MouseEvent e) { + int index = list.getSelectedIndex(); + if (index != -1) { + if (rwJComboBox.selectedIndices.contains(index)) { + rwJComboBox.selectedIndices.remove(index); + } else { + rwJComboBox.selectedIndices.add(index); + } + updateTextField(rwJComboBox); + list.repaint(); + } + } + + private void updateTextField(RwJComboBox comboBox) { + StringBuilder sb = new StringBuilder(); + for (Integer index : comboBox.selectedIndices) { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(comboBox.getModel().getElementAt(index)); + } + ((JTextField) comboBox.getEditor().getEditorComponent()).setText(sb.toString()); + } + } + + public static class RwDefaultComboBoxModel extends DefaultComboBoxModel { + public RwDefaultComboBoxModel(String[] items) { + for (String item : items) { + addElement(item); + } + } + } + + public static class RwJCheckBox extends JCheckBox implements ListCellRenderer { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + setComponentOrientation(list.getComponentOrientation()); + if (isSelected) { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } else { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + setEnabled(list.isEnabled()); + setSelected(isSelected); + setText(value == null ? "" : value.toString()); + setFont(list.getFont()); + return this; + } + } +} \ No newline at end of file diff --git a/src/com/connor/lyProess/ProcessWorker.java b/src/com/connor/lyProess/ProcessWorker.java new file mode 100644 index 0000000..87db8ff --- /dev/null +++ b/src/com/connor/lyProess/ProcessWorker.java @@ -0,0 +1,31 @@ +package com.connor.lyProess; + +import java.io.InputStreamReader; + +public class ProcessWorker extends Thread{ + + private Process process; + private volatile int exitCode = -99; + private volatile boolean completed = false; + + public ProcessWorker(Process process) { + this.process = process; + } + @Override + public void run() { + try (InputStreamReader reader = new InputStreamReader( + process.getInputStream(), "gbk")){ + exitCode = process.waitFor(); + completed = true; + } catch (Exception e) { + Thread.currentThread().interrupt(); + } + } + + public int getExitCode() { + return exitCode; + } + public boolean isCompleted() { + return completed; + } +} diff --git a/src/com/connor/lyProess/Template.java b/src/com/connor/lyProess/Template.java new file mode 100644 index 0000000..650af15 --- /dev/null +++ b/src/com/connor/lyProess/Template.java @@ -0,0 +1,56 @@ +package com.connor.lyProess; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class Template { + private LinkedHashMap nameToIdMap = new LinkedHashMap<>(); + private String xmlId; + + public LinkedHashMap getNameToIdMap() { + return nameToIdMap; + } + + public void setNameToIdMap(Map nameToIdMap) { + this.nameToIdMap.putAll(nameToIdMap); + } + + public String getXmlId() { + return xmlId; + } + + public void setXmlId(String xmlId) { + this.xmlId = xmlId; + } + + /** + * ƻȡӦ ID + * + * @param name Ƽ + * @return Ӧ ID ֵ򷵻 null + */ + public String getIdByName(String name) { + return nameToIdMap.get(name); + } + + /** + * ƺ ID ӵӳС + * + * @param name Ƽ + * @param id Ӧ ID ֵ + */ + public void addNameIdPair(String name, String id) { + if (name != null && id != null) { + nameToIdMap.put(name.trim(), id.trim()); + } + } + + /** + * ӡӳݣҪڵԣ + */ + public void printNameToIdMap() { + System.out.println("Name to ID Map: " + nameToIdMap); + } +} diff --git a/src/com/connor/lyProess/Util.java b/src/com/connor/lyProess/Util.java new file mode 100644 index 0000000..1dfbc96 --- /dev/null +++ b/src/com/connor/lyProess/Util.java @@ -0,0 +1,527 @@ +/** * @Title: util.java + * @Package com.connor.kwc.createBom + * @Description: TODO(һ仰ļʲô) + * @author admin * @date 20231218 + * @version V1.0 + */ +package com.connor.lyProess; + +import java.nio.charset.StandardCharsets; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.JTree; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCAccessControlService; +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.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentPseudoFolder; +import com.teamcenter.rac.kernel.TCComponentQuery; +import com.teamcenter.rac.kernel.TCComponentQueryType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTextService; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.kernel.ics.ICSKeyLov; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.kernel.ics.ICSPropertyDescription; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException; + +import com.teamcenter.soa.client.model.ServiceData; + +/** + * @ClassName: util + * @Description: + * @author hcj + * @date 20231218 + * + */ +public class Util { + public static final TCSession session; + public static final TCTextService textService; + + static { + session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + textService = session.getTextService(); + } + + /** + * + * @Title: getText + * @Description: ȡûĿֵ + * @param @param session + * @param @param str + * @param @return + * @param @throws Exception + * @return String + * @throws + */ + public static String getText(TCSession session, String str) throws Exception { + if (isEmpty(str)) { + return str; + } else { + String res = session.getTextService().getTextValue(str); + return !isEmpty(res) ? res : str; + } + } + + /** + * + * @Title: isEmpty + * @Description: жǷΪ + * @param @param str + * @param @return + * @return boolean + * @throws + */ + public static boolean isEmpty(String str) { + return str == null || "".equals(str.trim()); + } + + /** + * + * @Title: getItemById + * @Description: idòѯض + * @param @param id + * @param @return + * @return TCComponent + * @throws + */ + public static TCComponent getItemById(String id) { + + try { + System.out.println("ûĿ" + getText(session, "ItemID")); + // òѯ + String[] keys = new String[] { getText(session, "ItemID") }; + // òѯidֵ + String[] values = new String[] { id }; + List comps = queryObject("...", keys, values); + if (comps != null || comps.size() > 0) { + return comps.get(0); + } else { + MessageBox.post("ѡûвѯ", "", MessageBox.ERROR); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + /** + * + * @Title: expandAll + * @Description: չ۵ָ·µнڵķ + * @param @param tree + * @param @param parent + * @param @param expand + * @return void + * @throws + */ + public static void expandAll(JTree tree, TreePath parent, boolean expand) { + TreeNode node = (TreeNode) parent.getLastPathComponent(); + if (node.getChildCount() >= 0) { + for (Enumeration e = node.children(); e.hasMoreElements();) { + TreeNode n = (TreeNode) e.nextElement(); + TreePath path = parent.pathByAddingChild(n); + tree.expandPath(path); // չ· + expandAll(tree, path, expand); // ݹչӽڵ + } + } + } + + /** + * + * @Title: getRevisionPseudoFolder + * @Description: ȡαļ + * @param @param itemRev + * @param @param relation + * @param @return + * @return TCComponentPseudoFolder + * @throws + */ + public static TCComponentPseudoFolder getRevisionPseudoFolder(TCComponent tcComponent, String relation) { + TCComponentPseudoFolder realtionFolder = null; + try { + AIFComponentContext[] comps = tcComponent.getChildren(); + if (comps != null && comps.length > 0 && comps[0] != null) { + for (int i = 0; i < comps.length; i++) { + TCComponent comp = (TCComponent) comps[i].getComponent(); +// System.out.println("property_name:" + comp.getProperty("property_name")); + if ((comp instanceof TCComponentPseudoFolder)) { + if (comp.isTypeOf("PseudoFolder")) { + if (comp.getProperty("property_name").equalsIgnoreCase(relation)) { + realtionFolder = (TCComponentPseudoFolder) comp; + break; + } + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return realtionFolder; + } + + /** + * + * @Title: queryObject + * @Description: òѯ + * @param @param queryName + * @param @param keys + * @param @param values + * @param @return + * @return List + * @throws + */ + public static List queryObject(String queryName, String[] keys, String[] values) { + TCComponent[] components = null; + try { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery query = (TCComponentQuery) queryType.find(queryName); + if (query == null) { + MessageBox.post("ûҵѯ:" + queryName, "", MessageBox.ERROR); + return null; + } + + components = query.execute(keys, values); + } catch (TCException e) { + e.printStackTrace(); + } + if (components != null && components.length > 0) { + List compList = Arrays.asList(components); + return compList; + } else { + MessageBox.post("ûвѯ", "", MessageBox.ERROR); + return null; + } + } + + + /** + * + * @Title: queryObject + * @Description: òѯ + * @param @param queryName + * @param @param keys + * @param @param values + * @param @return + * @return List + * @throws + */ + public static List queryObject2(String queryName, String[] keys, String[] values) { + TCComponent[] components = null; + try { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery query = (TCComponentQuery) queryType.find(queryName); + if (query == null) { + MessageBox.post("ûҵѯ:" + queryName, "", MessageBox.ERROR); + return null; + } + + components = query.execute(keys, values); + } catch (TCException e) { + e.printStackTrace(); + } + if (components != null && components.length > 0) { + List compList = Arrays.asList(components); + return compList; + } else { + return null; + } + } + + /** + * + * @Title: getTCPropertyValue + * @Description: ȡԵʵֵ + * @param @param item + * @param @param propertyName + * @param @return + * @return Object + * @throws + */ + public static Object getTCPropertyValue(TCComponent item, String propertyName) { + Object result = ""; + + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + if (tcProperty == null) { + System.out.println("δȡԣ" + propertyName); + return result; + } + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + result = tcProperty.getDoubleValue(); + break; + case TCProperty.PROP_int: + result = tcProperty.getIntValue(); + break; + case TCProperty.PROP_string: + result = tcProperty.getStringValue(); + break; + case TCProperty.PROP_date: + result = tcProperty.getDateValue(); + break; + default: + break; + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return result; + } + + + + + + + + + /** + * MapеString͵ֵתΪUTF-8 + * + * @param map ҪתMap + * @return תMapеStringֵתΪUTF-8 + */ + public static Map convertValuesToUtf8(Map map) { + Map resultMap = new HashMap<>(); + for (Map.Entry entry : map.entrySet()) { + // ֵStringͣԽתΪֽڣٴֽתΪUTF-8String + String key = entry.getKey(); + String value = entry.getValue(); + byte[] bytes = value.getBytes(StandardCharsets.UTF_8); // ԭʼַѾȷıʽʧ + String utf8Value = new String(bytes, StandardCharsets.UTF_8); + resultMap.put(key, utf8Value); + } + return resultMap; + } + + /** + * + * @Title: setTCPropertyValue + * @Description: ݶֵ + * @param @param item + * @param @param propertyName + * @param @param value + * @return void + * @throws + */ + public static void setTCPropertyValue(TCComponent item, String propertyName, Object value) { + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + if (value instanceof Double) { + tcProperty.setDoubleValue((double) value); + } else { + tcProperty.setDoubleValue(Double.parseDouble(value.toString())); + } + break; + case TCProperty.PROP_int: + if (value instanceof Integer) { + tcProperty.setDoubleValue((int) value); + } else { + tcProperty.setDoubleValue(Integer.parseInt(value.toString())); + } + break; + case TCProperty.PROP_string: + tcProperty.setStringValue(value.toString()); + break; + case TCProperty.PROP_long_string: + tcProperty.setStringValueArray((String[]) value); + break; + case TCProperty.PROP_date: + if (value instanceof Date) { + tcProperty.setDateValue((Date) value); + } else { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm"); + tcProperty.setDateValue(sdf.parse(value.toString())); + } + break; + default: + break; + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * + * @Title: getSXX + * @Description: ȡѡֵ + * @param @param session + * @param @param name + * @param @return + * @return String[] + * @throws + */ + public static String[] getSXX(TCSession session, String name) { + String[] value = session.getPreferenceService().getStringValues(name); + if (value != null && value.length > 0) { + return value; + } else { + MessageBox.post("ѡ" + name + "", "ʾ", MessageBox.ERROR); + } + return null; + } + + /** + * + * @Title: userHasPowerForCompont + * @Description: жûǷijдȨ + * @param @param session + * @param @param component + * @param @return + * @return Boolean + * @throws + */ + public static Boolean userHasPowerForCompont(TCSession session, TCComponent component) { + TCAccessControlService tcAccessControlService = session.getTCAccessControlService(); + TCComponent[] user = new TCComponent[] { session.getUser(), session.getGroup(), session.getRole() }; + try { + return tcAccessControlService.checkAccessorsPrivilege(user, component, "WRITE"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + + } + + /** + * + * @Title: setByPass + * @Description: /ر· + * @param @param val + * @return void + * @throws + */ + public static void setByPass(boolean val) { + try { + Object[] obj = new Object[1]; + obj[0] = ""; + TCUserService userservice = session.getUserService(); + if(val) { + userservice.call("Connor_set_bypass", new Object[] { obj }); + }else { + userservice.call("Connor_close_bypass", new Object[] { obj }); + } + } catch (Exception e) { + System.out.println("Connor_set_bypassConnor_close_bypassķδעû"); + } + } + + + + public static void throwServiceDataError(ServiceData serviceData) throws Exception { + if (serviceData.sizeOfPartialErrors() > 0) { + StringBuilder errInfo = new StringBuilder(); + for (int i = 0; i < serviceData.sizeOfPartialErrors(); i++) { + for (String msg : serviceData.getPartialError(i).getMessages()) { + errInfo.append(msg + "\n"); + } + } + // System.out.println(errInfo.toString()); + throw new Exception(errInfo.toString()); + } + } + + /** + * ȡ + * + * @param comp ǰѡеĶ + * @return ȡĶ + * @throws TCException + */ + public String getIcoProperty(TCComponent comp, String propertyName) throws Exception { + // ͵ + TCComponentICO[] icos = comp.getClassificationObjects(); + if (icos.length <= 0) { + return ""; + } + // icos[0].delete(); + // ȡ + ICSProperty[] icsProps = icos[0].getICSProperties(true); + // ȡ + + ICSPropertyDescription[] icsDs = icos[0].getICSPropertyDescriptors(); + + for (ICSPropertyDescription icsD : icsDs) { + // System.out.println(icsD.getName()); + if (icsD.getName().compareTo(propertyName) == 0) { + String value = ""; + for (ICSProperty icsProperty : icsProps) { + if (icsProperty.getId() == icsD.getId()) { + value = icsProperty.getValue(); + if (icsD.isKeyLOV()) { + value = getClassDisplayableValue(value, icsD); + } + return value; + } + } + } + } + return ""; + } + + /** + * ȡLOVʾֵ + * + * @param icsD + * @return + */ + public static String getClassDisplayableValue(String value, ICSPropertyDescription icsD) { + String result = ""; + ICSKeyLov lov1 = icsD.getFormat().getKeyLov(); + if (lov1 != null) { + String[] keys = lov1.getKeys(); + for (String key : keys) { + if (value.equals(key)) { + result = lov1.getValueOfKey(key); + return result; + } + } + } + return result; + } + + + + +} diff --git a/src/com/connor/lyProess/exportToWordOperation.java b/src/com/connor/lyProess/exportToWordOperation.java new file mode 100644 index 0000000..a0766f4 --- /dev/null +++ b/src/com/connor/lyProess/exportToWordOperation.java @@ -0,0 +1,1863 @@ +package com.connor.lyProess; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Toolkit; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.FileInputStream; + +import java.text.SimpleDateFormat; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.pdfbox.multipdf.PDFMergerUtility; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.text.PDFTextStripper; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.apache.poi.xwpf.usermodel.XWPFTableCell; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.xml.sax.SAXException; + +import javax.swing.ComboBoxEditor; +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListSelectionModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.ListCellRenderer; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.ComboPopup; +import javax.swing.plaf.metal.MetalComboBoxUI; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class exportToWordOperation extends AbstractAIFOperation { + + private static AbstractAIFApplication app; + private static TCSession session; + private static LinkedHashMap companyAndWord; + private static LinkedHashMap attrsMap; + + // ҳ + private static JComboBox company = new JComboBox<>(); + private static JComboBox template = new JComboBox<>(); + + private static JPanel templatePanel = new JPanel(); + + public exportToWordOperation(AbstractAIFApplication app, TCSession session) { + // TODO Auto-generated constructor stub + this.app = app; + this.session = session; + } + + @Override + public void executeOperation() throws Exception { + // TODO Auto-generated method stub + // ȡѡֵ + String[] docTypes = session.getPreferenceService().getStringValues("LY6_MEP_CoverType"); + + // docTypes ǷΪ null ߳Ϊ 0 + if (docTypes == null || docTypes.length == 0) { + MessageBox.post("ѡLY6_MEP_CoverType", "", MessageBox.ERROR); + return; + } else { + companyAndWord = new LinkedHashMap<>(); + + for (String docType : docTypes) { + try { + // ַָ + String[] split = docType.trim().split("=", -1); // ʹ-1в֣յIJ + + if (split.length < 4) { // ȷ㹻IJֱָ + throw new IllegalArgumentException("ʽȷ: " + docType); + } + + Template template = new Template(); + + // nameToIdMap + LinkedHashMap nameToIdMap = new LinkedHashMap<>(); + String[] names = split[1].split(","); + String[] nameIds = split[2].split(","); + + if (names.length != nameIds.length) { + throw new IllegalArgumentException("nameList nameIdList Ȳһ"); + } + + for (int i = 0; i < names.length; i++) { + String name = names[i].trim(); + String id = nameIds[i].trim(); + if (!name.isEmpty() && !id.isEmpty()) { + nameToIdMap.put(name, id); + } + } + + template.setNameToIdMap(nameToIdMap); + template.setXmlId(split[3]); + companyAndWord.put(split[0], template); + + // ѡӡӳȷȷԣڵԣ + template.printNameToIdMap(); + + } catch (Exception e) { + // ¼쳣ϢԿǽ docType ʹϢ¼ + MessageBox.post("ѡLY6_MEP_CoverTypeʱ" + e.getMessage(), "", MessageBox.ERROR); + // ҪǷѭֱӷ + continue; // ʹ return ֹͣ + } + } + + System.out.println("companyAndWord:" + companyAndWord); + } + + attrsMap = new LinkedHashMap(); + String coverProps = session.getPreferenceService().getStringValue("LY6_MEP_CoverProps"); + if (coverProps == null) { + MessageBox.post("ѡLY6_MEP_CoverProps", "", MessageBox.ERROR); + return; + } else { + String[] split = coverProps.split(","); + for (String coverProp : split) { + String[] split2 = coverProp.split(":"); + attrsMap.put(split2[0], split2[1]); + } + } + + // ҳ + ArrayList keys = new ArrayList<>(companyAndWord.keySet()); + DefaultComboBoxModel companyModel = new DefaultComboBoxModel<>(); + for (String key : keys) { + companyModel.addElement(key); + } + company.setModel(companyModel); + + company.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + String selectedCompany = (String) e.getItem(); + Template templates = companyAndWord.get(selectedCompany); + if (templates != null) { + LinkedHashMap nameToIdMap = templates.getNameToIdMap(); + + // ȷ nameToIdMap LinkedHashMap Ա˳ + if (!(nameToIdMap instanceof LinkedHashMap)) { + nameToIdMap = new LinkedHashMap<>(nameToIdMap); + } + + // keySet תΪ + String[] array = nameToIdMap.keySet().toArray(new String[0]); + + // µģϿ + template = new RwJComboBox(array); + template.setPreferredSize(new Dimension(300, 50)); + template.setSelectedIndex(-1); + + // + templatePanel.removeAll(); // ɵϿ + templatePanel.add(template); // µϿ + templatePanel.revalidate(); // ֤ + templatePanel.repaint(); // » + + // Ͽģͣȷ˳򲻱 + template.setModel(new DefaultComboBoxModel<>(array)); + } else { + MessageBox.post("ѡûҵ" + selectedCompany + "Ӧģ", "", MessageBox.ERROR); + return; + } + } + } + }); + JButton okButton = new JButton("ȷ"); + JButton cancelButton = new JButton("ȡ"); + JFrame jFrame = new JFrame("ģ"); + + company.setSelectedIndex(-1); + company.setPreferredSize(new Dimension(300, 50)); + + template.setSelectedIndex(-1); + template.setPreferredSize(new Dimension(300, 50)); + jFrame.setLayout(new BorderLayout()); + + JPanel panel = new JPanel(); + panel.setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(50, 10, 10, 10); // ϱ߾Ϊ20߾Ϊ10 + + // ˾ǩ + JLabel companyLabel = new JLabel("˾: "); + companyLabel.setFont(new Font("", Font.BOLD, 16)); // Ϊ壬Ӵ֣СΪ16 + + gbc.gridx = 0; + gbc.gridy = 0; + gbc.anchor = GridBagConstraints.EAST; + panel.add(companyLabel, gbc); + + gbc.gridx = 1; + gbc.gridy = 0; + gbc.anchor = GridBagConstraints.WEST; + panel.add(company, gbc); + + // һյ JLabel Ӵֱ + gbc.gridx = 0; + gbc.gridy = 1; + gbc.gridwidth = 1; // ռ + gbc.weighty = 1.0; // ӴֱȨأʹ + panel.add(new JLabel(), gbc); + + // ģǩ + JLabel templateLabel = new JLabel("ģ: "); + templateLabel.setFont(new Font("", Font.BOLD, 16)); // Ϊ壬Ӵ֣СΪ16 + + gbc.gridx = 0; + gbc.gridy = 2; + gbc.gridwidth = 1; // gridwidth + gbc.weighty = 0.0; // weighty + gbc.anchor = GridBagConstraints.EAST; + panel.add(templateLabel, gbc); + + gbc.gridx = 1; + gbc.gridy = 2; + gbc.anchor = GridBagConstraints.WEST; + templatePanel = new JPanel(); + templatePanel.setLayout(new BorderLayout()); + templatePanel.add(template, BorderLayout.CENTER); + panel.add(templatePanel, gbc); + JPanel panel1 = new JPanel(); + panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 10)); // òΪж룬ˮƽʹֱ + + // ðť + okButton.setFont(new Font("", Font.BOLD, 16)); // Ϊ壬Ӵ֣СΪ16 + cancelButton.setFont(new Font("", Font.BOLD, 16)); // Ϊ壬Ӵ֣СΪ16 + + // ΪȷťӼ + okButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String selectedCompany = (String) company.getSelectedItem(); + String selectedTemplate = (String) template.getSelectedItem(); + System.out.println("˾: " + selectedCompany); + System.out.println("ģ: " + selectedTemplate); + if (selectedCompany == null || selectedTemplate == null || selectedCompany.isEmpty() + || selectedTemplate.isEmpty()) { + MessageBox.post("ѡ˾ģв", "", MessageBox.ERROR); + return; + } + // ʼҵ߼ + // ȡݼļ + LinkedHashMap nameAndFile = new LinkedHashMap(); + for (String temp : selectedTemplate.split(",")) { + System.out.println("ģƣ" + temp); + System.out.println("ģIDӦϵ" + companyAndWord.get(selectedCompany).getNameToIdMap()); + String tempId = companyAndWord.get(selectedCompany).getNameToIdMap().get(temp.trim()); + System.out.println("ǰģIDΪ" + tempId); + File file = null; + try { + TCComponent item = Util.getItemById(tempId); + TCComponent[] referenceListProperty = ((TCComponentItem) item) + .getReferenceListProperty("revision_list"); + TCComponentItemRevision revision = null; + for (int i = referenceListProperty.length - 1; i >= 0; i--) { + Date tempDate = ((TCComponentItemRevision) referenceListProperty[i]) + .getDateProperty("date_released"); + if (tempDate == null) { + continue; + } else { + revision = ((TCComponentItemRevision) referenceListProperty[i]); + break; + } + } + if (revision != null) { + TCComponent[] referenceListProperty2 = revision + .getReferenceListProperty("IMAN_specification"); + for (TCComponent component : referenceListProperty2) { + if (component instanceof TCComponentDataset) { + file = ((TCComponentDataset) component).getTcFiles()[0] + .getFile(System.getProperty("java.io.tmpdir")); + nameAndFile.put(temp, file); + break; + } + } + if (file == null) { + MessageBox.post("ģID" + selectedTemplate + "ûҵļ", "", MessageBox.ERROR); + return; + } + + } else { + MessageBox.post("ģID" + selectedTemplate + "ûз汾", "", MessageBox.ERROR); + return; + } + + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + // ȡxmlģ + File XMLfile = null; + TCComponent item = Util.getItemById(companyAndWord.get(selectedCompany).getXmlId()); + TCComponent[] referenceListProperty = null; + try { + referenceListProperty = ((TCComponentItem) item).getReferenceListProperty("revision_list"); + } catch (TCException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + TCComponentItemRevision revision = null; + for (int i = referenceListProperty.length - 1; i >= 0; i--) { + Date tempDate = null; + try { + tempDate = ((TCComponentItemRevision) referenceListProperty[i]) + .getDateProperty("date_released"); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + if (tempDate == null) { + continue; + } else { + revision = ((TCComponentItemRevision) referenceListProperty[i]); + break; + } + } + if (revision != null) { + TCComponent[] referenceListProperty2 = null; + try { + referenceListProperty2 = revision.getReferenceListProperty("IMAN_specification"); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + for (TCComponent component : referenceListProperty2) { + if (component instanceof TCComponentDataset) { + try { + XMLfile = ((TCComponentDataset) component).getTcFiles()[0] + .getFile(System.getProperty("java.io.tmpdir")); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + break; + } + } + if (XMLfile == null) { + MessageBox.post("ģID" + companyAndWord.get(selectedCompany).getXmlId() + "ûҵļ", "", + MessageBox.ERROR); + return; + } + + } else { + MessageBox.post("ģID" + companyAndWord.get(selectedCompany).getXmlId() + "ûз汾", "", + MessageBox.ERROR); + return; + } + TCComponentItem gyitem = null; + TCComponentItemRevision gyRevision = null; + InterfaceAIFComponent targetComponent = app.getTargetComponent(); + gyRevision = (TCComponentItemRevision) targetComponent; + try { + gyitem = gyRevision.getItem(); + } catch (TCException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + // ȡjava.io.tmpdirĿ¼ΪļĿ¼ + String tempDir = System.getProperty("java.io.tmpdir"); + // ļǰʱȷΨһ + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String timestamp = dateFormat.format(new Date()); // ǰʱȷ + int randomNum = ThreadLocalRandom.current().nextInt(1000, 9999); // һλ + String newFileName = "file_" + timestamp + "_" + randomNum; // ļʽ + // ȡݣݿƲֵ + File newFile = new File(tempDir, newFileName + ".docx"); + LinkedHashMap popsMap = new LinkedHashMap(); + try { + for (Entry entry : attrsMap.entrySet()) { + String key = entry.getKey(); + String val = entry.getValue(); + String[] split = key.split("\\."); + if (split[0].equals("item")) { + popsMap.put(val, item.getProperty(split[1])); + } else if (split[0].equals("rev")) { + popsMap.put(val, gyRevision.getProperty(split[1])); + } + } + StringBuilder builder = new StringBuilder(""); + for (Entry entry : popsMap.entrySet()) { + builder.append(entry.getKey()).append("=").append(entry.getValue()).append("|"); + } + // ɾһ"|" + if (builder.length() > 0) { + builder.setLength(builder.length() - 1); + } + + File saveFile = new File(System.getProperty("java.io.tmpdir") + "\\word.txt"); + if (saveFile.exists()) { + saveFile.delete(); + } + saveFile.createNewFile(); + BufferedWriter buffered = new BufferedWriter( + new OutputStreamWriter(new FileOutputStream(saveFile, true))); + buffered.write(builder.toString()); + buffered.close(); + + String outputFilePath2 = mergeDocuments(nameAndFile, XMLfile, gyitem, gyRevision, saveFile, this); + // ض + // ϴ· + String url = outputFilePath2; + // ݼ + String pref = "PDF_Reference"; + // 飬öݼ + String as1[] = { url }; + String as2[] = { pref }; + // ȡݼ + TCComponentDatasetType tccomponentDatasetType = (TCComponentDatasetType) session + .getTypeComponent("Dataset"); + // ݼʹݼƣãݼ + TCComponentDataset tccomponentDataset = tccomponentDatasetType.create("շ", "", "PDF"); + // ϴļϴ + tccomponentDataset.setFiles(as1, as2); + // ѡеļ + gyRevision.add("IMAN_specification", tccomponentDataset); + } catch (Exception e1) { + e1.printStackTrace(); + // TODO Auto-generated catch block + MessageBox.post("ݼʧ", "", MessageBox.ERROR); + + // رմ + jFrame.dispose(); + e1.printStackTrace(); + return; + } + + MessageBox.post("ݼɹ", "ʾ", MessageBox.INFORMATION); + + // رմ + jFrame.dispose(); + return; + } + + }); + + // ΪȡťӼ + cancelButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.out.println("ȡ"); + jFrame.dispose(); + return; + } + }); + panel1.add(okButton); + panel1.add(cancelButton); + + jFrame.add(panel, BorderLayout.NORTH); + jFrame.add(panel1, BorderLayout.SOUTH); + jFrame.setPreferredSize(new Dimension(450, 200)); + + // ôڴС + jFrame.setSize(800, 500); + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // ȡĻߴ + int screenWidth = screenSize.width; // ȡĻ + int screenHeight = screenSize.height; // ȡĻ߶ + int x = (screenWidth - 450) / 2; // FrameϽx + int y = (screenHeight - 200) / 2; // FrameϽy + jFrame.setLocation(x, y); // Frameλ + + jFrame.setDefaultCloseOperation(2); + jFrame.setVisible(true); + + } + + public static void removeBlankPages(String inputFilePath, String outputFilePath) throws IOException { + try (PDDocument document = PDDocument.load(new File(inputFilePath))) { + PDFTextStripper pdfStripper = new PDFTextStripper(); + int totalPages = document.getNumberOfPages(); + List pagesToRemove = new ArrayList<>(); + + for (int i = 1; i <= totalPages; i++) { + // Extract text from each page + pdfStripper.setStartPage(i); + pdfStripper.setEndPage(i); + String pageText = pdfStripper.getText(document).trim(); + + // If the page has no text, mark it for removal + if (pageText.isEmpty()) { + pagesToRemove.add(i); + } + } + + // Remove marked pages in reverse order to avoid index shifting + for (int i = pagesToRemove.size() - 1; i >= 0; i--) { + document.removePage(pagesToRemove.get(i) - 1); // Pages are 0-indexed + } + + // Save the modified document + document.save(outputFilePath); + } + } + + public static String mergeDocuments(LinkedHashMap nameAndFile, File xmlFile, TCComponentItem gyItem, + TCComponentItemRevision gyRevision, File saveFile, ActionListener actionListener) throws Exception { + List documents = new ArrayList<>(); + + for (Map.Entry entry : nameAndFile.entrySet()) { + String key = entry.getKey(); + File value = entry.getValue(); + + // Ensure the file is a .docx file + if (!value.getName().toLowerCase().endsWith(".docx")) { + System.err.println("Error: File " + value.getName() + " is not a .docx file."); + continue; + } + byte[] insertDataIntoWord = insertDataIntoWord(xmlFile, entry, gyItem, gyRevision); + System.out.println(insertDataIntoWord); + if (insertDataIntoWord == null) { + // Directly add the document to the list + XWPFDocument document = new XWPFDocument(new FileInputStream(value)); + // ޸ĺĵתΪֽ + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + document.write(baos); + insertDataIntoWord = baos.toByteArray(); + } + // ͷǩ תΪpdf + // ȡjava.io.tmpdirĿ¼ΪļĿ¼ + String tempDir = System.getProperty("java.io.tmpdir"); + // ļǰʱȷΨһ + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String timestamp = dateFormat.format(new Date()); // ǰʱȷ + int randomNum = ThreadLocalRandom.current().nextInt(1000, 9999); // һλ + String newFileName = "file_" + timestamp + "_" + randomNum; // ļʽ + String pluginsDir = actionListener.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); + pluginsDir = pluginsDir.substring(1, pluginsDir.lastIndexOf("/")); + String outputFilePath = System.getProperty("java.io.tmpdir") + "\\" + newFileName + ".pdf"; + File newFile = new File(tempDir, newFileName + ".docx"); + // ʹ FileOutputStream ֽд뵽ļ + try (FileOutputStream fos = new FileOutputStream(newFile)) { + fos.write(insertDataIntoWord); + } + runWsf(pluginsDir + "\\SubstMacros-MSWord.wsf", + new String[] { newFile.getPath(), saveFile.getPath(), outputFilePath }); + String outputFilePath2 = System.getProperty("java.io.tmpdir") + "\\" + newFileName + "1" + ".pdf"; + // ɾĿհҳ + removeBlankPages(outputFilePath, outputFilePath2); + documents.add(outputFilePath2); + + } + // ϲpdf + // ָļ· + String outputFilePath = System.getProperty("java.io.tmpdir") + "/merged_document.pdf"; + + // úϲ + mergePdfFiles(documents, outputFilePath); + + System.out.println("PDF ļѳɹϲ"); + + return outputFilePath; + } + + /** + * + * @Title: insertDataIntoWord + * @Description: ѭ ƥxmlӦwordģ + * @param @param xmlFile + * @param @param nameAndFile + * @param @param gyitem + * @param @param gyRevision + * @return + * @return void + * @throws TCException + * @throws + */ + private static byte[] insertDataIntoWord(File xmlFile, Entry entry, TCComponentItem gyItem, + TCComponentItemRevision gyRevision) throws TCException { + try { + // ʼDOMԽXMLļӡʼ״̬ + System.out.println("ʼʼDOM..."); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(xmlFile); + doc.getDocumentElement().normalize(); // 淶ĵԪ + System.out.println("DOMʼ"); + + // ȡ