diff --git a/.classpath b/.classpath index e801ebf..47d8633 100644 --- a/.classpath +++ b/.classpath @@ -1,5 +1,6 @@ + diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index ddd09d3..186cb31 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -3,7 +3,11 @@ Bundle-ManifestVersion: 2 Bundle-Name: Cust Bundle-SymbolicName: com.connor.cust;singleton:=true Bundle-Version: 1.0.0 +Import-Package: org.apache.commons.httpclient, + org.apache.commons.httpclient.methods Bundle-Activator: com.connor.cust.Activator +Bundle-ClassPath: lib/fastjson-1.2.78.jar, + . Bundle-Vendor: CONNOR Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, @@ -11,7 +15,8 @@ Require-Bundle: org.eclipse.ui, com.teamcenter.rac.aifrcp;bundle-version="14000.3.0", com.teamcenter.rac.util;bundle-version="14000.3.0", org.apache.poi;bundle-version="5.2.1", - TcSoaCoreRac;bundle-version="14000.3.0" + TcSoaCoreRac;bundle-version="14000.3.0", + com.teamcenter.rac.common;bundle-version="14000.3.0" Bundle-RequiredExecutionEnvironment: JavaSE-11 Automatic-Module-Name: com.connor.cust Bundle-ActivationPolicy: lazy diff --git a/bin/com/connor/cust/box/BoxReportHandler$1.class b/bin/com/connor/cust/box/BoxReportHandler$1.class new file mode 100644 index 0000000..68540b1 Binary files /dev/null and b/bin/com/connor/cust/box/BoxReportHandler$1.class differ diff --git a/bin/com/connor/cust/box/BoxReportHandler.class b/bin/com/connor/cust/box/BoxReportHandler.class index 90205c5..a4c6280 100644 Binary files a/bin/com/connor/cust/box/BoxReportHandler.class and b/bin/com/connor/cust/box/BoxReportHandler.class differ diff --git a/bin/com/connor/cust/box/BoxReportOperation$1$1.class b/bin/com/connor/cust/box/BoxReportOperation$1$1.class new file mode 100644 index 0000000..e387c41 Binary files /dev/null and b/bin/com/connor/cust/box/BoxReportOperation$1$1.class differ diff --git a/bin/com/connor/cust/box/BoxReportOperation$1.class b/bin/com/connor/cust/box/BoxReportOperation$1.class new file mode 100644 index 0000000..0742cbb Binary files /dev/null and b/bin/com/connor/cust/box/BoxReportOperation$1.class differ diff --git a/bin/com/connor/cust/box/BoxReportOperation.class b/bin/com/connor/cust/box/BoxReportOperation.class new file mode 100644 index 0000000..2a6e934 Binary files /dev/null and b/bin/com/connor/cust/box/BoxReportOperation.class differ diff --git a/bin/com/connor/cust/box/history_locale.properties b/bin/com/connor/cust/box/box_locale.properties similarity index 100% rename from bin/com/connor/cust/box/history_locale.properties rename to bin/com/connor/cust/box/box_locale.properties diff --git a/bin/com/connor/cust/box/box_locale_zh_CN.properties b/bin/com/connor/cust/box/box_locale_zh_CN.properties new file mode 100644 index 0000000..c663dc4 --- /dev/null +++ b/bin/com/connor/cust/box/box_locale_zh_CN.properties @@ -0,0 +1,32 @@ +preferr=\u9996\u9009\u9879\u914D\u7F6E\u4E0D\u6B63\u786E +#XYBOM +ok=\u786E\u5B9A +err=\u9519\u8BEF\uFF1A +cel=\u53D6\u6D88 +notbom= \u4E0D\u662FBOM\u884C\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 +setbox=\u8BBE\u7F6E\u88C5\u7BB1\u5355 +boxfinish=\u88C5\u7BB1\u5355\u8BBE\u7F6E\u5B8C\u6210\uFF01 +#BoxReport +choose=\u8BF7\u9009\u62E9\u5BFC\u51FA\u683C\u5F0F\uFF1A +multiple=\u591A\u9875 +single=\u5355\u9875 +nottop=\u9009\u4E2D\u5BF9\u8C61\u4E0D\u662FBOM\u9876\u5C42\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 +sheetname=\u88C5\u7BB1\u660E\u7EC6 +sheeterr=sheet\u9875\u672A\u627E\u5230\uFF01 +exportsuccess=\u5BFC\u51FA\u5B8C\u6210\uFF01 +boxno=\u7B2C;\u7BB1 +numstr=\u96F6;\u4E00;\u4E8C;\u4E09;\u56DB;\u4E94;\u516D;\u4E03;\u516B;\u4E5D;\u5341 +importing=\u6B63\u5728\u5BFC\u51FA\uFF0C\u8BF7\u7A0D\u5019... +#EditClassification +chooserev=\u8BF7\u9009\u62E9Item\u8FDB\u884C\u4FEE\u6539\uFF01 +notinoptions=\u6B64\u529F\u80FD\u914D\u7F6E\u6CA1\u6709\u5F53\u524D\u5BF9\u8C61\u7C7B\u578B +noaccess=\u6CA1\u6709\u7248\u672C\u4FEE\u6539\u6743\u9650\uFF0C\u8BF7\u8054\u7CFB\u7CFB\u7EDF\u7BA1\u7406\u5458 +revcounterr=\u5B58\u5728\u591A\u7248\u672C\uFF0C\u65E0\u6CD5\u4FEE\u6539ID +statuserr=\u5B58\u5728\u72B6\u6001\u6807\u8BC6\uFF0C\u65E0\u6CD5\u4FEE\u6539ID +noclasserr=\u5F53\u524D\u5BF9\u8C61\u672A\u88AB\u5206\u7C7B +classtitle=\u4FEE\u6539\u5206\u7C7B\u5C5E\u6027 +delete=\u5220\u9664 +send=\u53D1\u9001 +message1=\u5206\u7C7B\u5C5E\u6027\u5931\u8D25 +message2=\uFF0C\u9519\u8BEF\u53F7\uFF1A +message3=\uFF0C\u8FD4\u56DE\u7ED3\u679C\uFF1A \ No newline at end of file diff --git a/bin/com/connor/cust/box/history_locale_zh_CN.properties b/bin/com/connor/cust/box/history_locale_zh_CN.properties deleted file mode 100644 index 4b66227..0000000 --- a/bin/com/connor/cust/box/history_locale_zh_CN.properties +++ /dev/null @@ -1,10 +0,0 @@ -preferr=\u9996\u9009\u9879\u914D\u7F6E\u4E0D\u6B63\u786E -#XYBOM -ok=\u786E\u5B9A -err=\u9519\u8BEF\uFF1A -cel=\u53D6\u6D88 -notbom= \u4E0D\u662FBOM\u884C\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 -setbox=\u8BBE\u7F6E\u88C5\u7BB1\u5355 -boxfinish=\u88C5\u7BB1\u5355\u8BBE\u7F6E\u5B8C\u6210\uFF01 -#BoxReport -nottop=\u9009\u4E2D\u5BF9\u8C61\u4E0D\u662FBOM\u9876\u5C42\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\uFF01 \ No newline at end of file diff --git a/bin/com/connor/cust/classification/AutoCompleter.class b/bin/com/connor/cust/classification/AutoCompleter.class new file mode 100644 index 0000000..790c347 Binary files /dev/null and b/bin/com/connor/cust/classification/AutoCompleter.class differ diff --git a/bin/com/connor/cust/classification/ClassPropBean.class b/bin/com/connor/cust/classification/ClassPropBean.class new file mode 100644 index 0000000..178b962 Binary files /dev/null and b/bin/com/connor/cust/classification/ClassPropBean.class differ diff --git a/bin/com/connor/cust/classification/ClassProperty.class b/bin/com/connor/cust/classification/ClassProperty.class new file mode 100644 index 0000000..db957cc Binary files /dev/null and b/bin/com/connor/cust/classification/ClassProperty.class differ diff --git a/bin/com/connor/cust/classification/EditClassificationDialog$1$1.class b/bin/com/connor/cust/classification/EditClassificationDialog$1$1.class new file mode 100644 index 0000000..a48abab Binary files /dev/null and b/bin/com/connor/cust/classification/EditClassificationDialog$1$1.class differ diff --git a/bin/com/connor/cust/classification/EditClassificationDialog$1.class b/bin/com/connor/cust/classification/EditClassificationDialog$1.class new file mode 100644 index 0000000..ba297a2 Binary files /dev/null and b/bin/com/connor/cust/classification/EditClassificationDialog$1.class differ diff --git a/bin/com/connor/cust/classification/EditClassificationDialog$2.class b/bin/com/connor/cust/classification/EditClassificationDialog$2.class new file mode 100644 index 0000000..89c74d6 Binary files /dev/null and b/bin/com/connor/cust/classification/EditClassificationDialog$2.class differ diff --git a/bin/com/connor/cust/classification/EditClassificationDialog.class b/bin/com/connor/cust/classification/EditClassificationDialog.class new file mode 100644 index 0000000..78a6eb4 Binary files /dev/null and b/bin/com/connor/cust/classification/EditClassificationDialog.class differ diff --git a/bin/com/connor/cust/classification/EditClassificationHandler.class b/bin/com/connor/cust/classification/EditClassificationHandler.class new file mode 100644 index 0000000..ba8c2fe Binary files /dev/null and b/bin/com/connor/cust/classification/EditClassificationHandler.class differ diff --git a/bin/com/connor/cust/classification/JAutoCompleteComboBox.class b/bin/com/connor/cust/classification/JAutoCompleteComboBox.class new file mode 100644 index 0000000..bdaee22 Binary files /dev/null and b/bin/com/connor/cust/classification/JAutoCompleteComboBox.class differ diff --git a/bin/com/connor/cust/util/POIUtil.class b/bin/com/connor/cust/util/POIUtil.class new file mode 100644 index 0000000..c0325a0 Binary files /dev/null and b/bin/com/connor/cust/util/POIUtil.class differ diff --git a/bin/com/connor/cust/util/ProgressReporterDialog.class b/bin/com/connor/cust/util/ProgressReporterDialog.class new file mode 100644 index 0000000..df25b05 Binary files /dev/null and b/bin/com/connor/cust/util/ProgressReporterDialog.class differ diff --git a/bin/com/connor/cust/util/TCUtil$1.class b/bin/com/connor/cust/util/TCUtil$1.class index 6afc74a..624d317 100644 Binary files a/bin/com/connor/cust/util/TCUtil$1.class and b/bin/com/connor/cust/util/TCUtil$1.class differ diff --git a/bin/com/connor/cust/util/TCUtil.class b/bin/com/connor/cust/util/TCUtil.class index ce5060b..4c2d571 100644 Binary files a/bin/com/connor/cust/util/TCUtil.class and b/bin/com/connor/cust/util/TCUtil.class differ diff --git a/bin/com/teamcenter/rac/commands/cut/CutCommand.class b/bin/com/teamcenter/rac/commands/cut/CutCommand.class new file mode 100644 index 0000000..c896d2f Binary files /dev/null and b/bin/com/teamcenter/rac/commands/cut/CutCommand.class differ diff --git a/bin/com/teamcenter/rac/commands/cut/cut_locale_zh_CN.properties b/bin/com/teamcenter/rac/commands/cut/cut_locale_zh_CN.properties new file mode 100644 index 0000000..d0260d9 --- /dev/null +++ b/bin/com/teamcenter/rac/commands/cut/cut_locale_zh_CN.properties @@ -0,0 +1 @@ +foldercut=\u4E0D\u80FD\u5BF9\u8BE5\u7C7B\u578B\u7684\u6587\u4EF6\u5939\u8FDB\u884C\u526A\u5207\u64CD\u4F5C \ No newline at end of file diff --git a/build.properties b/build.properties index 0d3d3a7..7b93364 100644 --- a/build.properties +++ b/build.properties @@ -3,4 +3,5 @@ output.. = bin/ bin.includes = plugin.xml,\ META-INF/,\ .,\ - icons/ + icons/,\ + lib/fastjson-1.2.78.jar diff --git a/lib/fastjson-1.2.78.jar b/lib/fastjson-1.2.78.jar new file mode 100644 index 0000000..bb42302 Binary files /dev/null and b/lib/fastjson-1.2.78.jar differ diff --git a/plugin.xml b/plugin.xml index d47df30..b65eb8e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,36 +2,63 @@ - + + + + + - + + + + + - - - - - + + <--> + + + + + + + + + + + + + + - - <--> + + + + + + + + + + + + diff --git a/src/com/connor/cust/box/BoxReportHandler.java b/src/com/connor/cust/box/BoxReportHandler.java index cbd974f..8804a36 100644 --- a/src/com/connor/cust/box/BoxReportHandler.java +++ b/src/com/connor/cust/box/BoxReportHandler.java @@ -1,5 +1,7 @@ package com.connor.cust.box; +import javax.swing.JOptionPane; + import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -43,7 +45,20 @@ public class BoxReportHandler extends AbstractHandler{ MessageBox.post(desktop, "KWC_ReportTemplate_XYBOX" + PlmLocale.getString("preferr"), "ERROR", MessageBox.ERROR); return null; } -// new XYBOMDialog(session, targets); + new Thread() { + public void run() { + try { + int choose = JOptionPane.showOptionDialog(desktop, PlmLocale.getString("choose"), "INFO", + JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, + new String[] { PlmLocale.getString("multiple"), PlmLocale.getString("single") }, "End"); + if(choose < 0) + return; + new BoxReportOperation(session, bom, options, choose == 1).executeOperation(); + }catch(Exception e) { + e.printStackTrace(); + } + } + }.start(); } catch(Exception e) { e.printStackTrace(); MessageBox.post(desktop, PlmLocale.getString("err") + e.getMessage(), "ERROR", MessageBox.ERROR); diff --git a/src/com/connor/cust/box/BoxReportOperation.java b/src/com/connor/cust/box/BoxReportOperation.java new file mode 100644 index 0000000..1b9f2f3 --- /dev/null +++ b/src/com/connor/cust/box/BoxReportOperation.java @@ -0,0 +1,285 @@ +package com.connor.cust.box; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedList; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFPrintSetup; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.connor.cust.util.POIUtil; +import com.connor.cust.util.ProgressReporterDialog; +import com.connor.cust.util.TCUtil; +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.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +/** + * : װ䵥 + * :2024-01-05 + * @author  + * + * ޸ ޸ ޸ + * 2019-01-24 XXXX + */ +public class BoxReportOperation extends AbstractAIFOperation { + + private TCSession session; + private boolean single; + private TCComponentBOMLine target; + private String[] options; + private LinkedList datas; + private HashMap boxMap; + + private final int PAGE_CNT = 23;// + private final int TITLE_CNT = 4; + private final int PAGE = PAGE_CNT + TITLE_CNT; + private final int COL_CNT = 9; + /** + * װ䵥 + * @param session TCSession + * @param target ѡBOM + * @param options Excelģѡֵ + * @param single Ƿҳ + */ + public BoxReportOperation(TCSession session, TCComponentBOMLine target, String[] options, boolean single) { + this.session = session; + this.target = target; + this.options = options; + this.single = single; + } + + @Override + public void executeOperation() throws Exception { + TCComponent model = session.stringToComponent(options[single ? 0 : 1]); + if(model==null || !model.getType().equals("MSExcelX")) { + MessageBox.post(AIFUtility.getActiveDesktop(), "KWC_ReportTemplate_XYBOX" + PlmLocale.getString("preferr"), "ERROR", MessageBox.ERROR); + return; + } + File directory = TCUtil.saveExcelChooser(); + if(directory == null) + return; + final ProgressReporterDialog reporter = new ProgressReporterDialog("INFO"); + reporter.reportProgressMessage(PlmLocale.getString("importing")); + new Thread(reporter).start(); + new Thread() { + public void run(){ + FileInputStream input = null; + FileOutputStream output = null; + XSSFWorkbook workbook = null; + try { + datas = new LinkedList<>(); + boxMap = new HashMap<>(); + String topid = target.getProperty("bl_item_item_id"); + recycleBom(target.getChildren(), topid); + if(datas.size() == 0) { + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("sheetname") + PlmLocale.getString("sheeterr"), "ERROR", MessageBox.ERROR); + return; + } + //XYBOX + Collections.sort(datas, new Comparator() { + public int compare(String[] data1, String[] data2) { + return Integer.parseInt(data1[COL_CNT]) - Integer.parseInt(data2[COL_CNT]); + } + }); + + File file = ((TCComponentDataset)model).getTcFiles()[0].getFile(System.getProperty("java.io.tmpdir")); + input = new FileInputStream(file); + workbook = new XSSFWorkbook(input); + XSSFSheet sheet = workbook.getSheet(PlmLocale.getString("sheetname")); + if(sheet == null) { + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("sheetname") + PlmLocale.getString("sheeterr"), "ERROR", MessageBox.ERROR); + return; + } + int sheet0 = workbook.getSheetIndex(sheet); + if(single) { + //ҳ + XSSFRow xssfrow = TCUtil.getRow(sheet, 0); + XSSFCell cell = TCUtil.getCell(xssfrow, 9); + cell.setCellValue(topid); + int pageCnt = 0; + for(int b : boxMap.values()) { + pageCnt += b/PAGE_CNT; + if(b % PAGE_CNT > 0) + pageCnt ++; + } + for(int i=1; i<=pageCnt; i++) { +// sheet.copyRows(0, PAGE, i*PAGE, null); + POIUtil.copyRows(workbook, sheet, 0, PAGE-1, i*PAGE, COL_CNT, 1); + } + int row = 0, rbox = 0, pbox = 0; + for(String[] data : datas) { + int box = Integer.parseInt(data[COL_CNT]); + if(box != pbox) { + // + row --; + int page = row / PAGE; + if(row % PAGE > 0) + page ++; + row = page * PAGE + TITLE_CNT; + rbox = 1; + pbox = box; + + xssfrow = TCUtil.getRow(sheet, page * PAGE + 1); + cell = TCUtil.getCell(xssfrow, 5); + String[] boxno = PlmLocale.getString("boxno").split(";"); + cell.setCellValue(boxno[0] + getNumStr(box) + boxno[1]); + }else if(row % PAGE == 1) { + //ҳ + xssfrow = TCUtil.getRow(sheet, row); + cell = TCUtil.getCell(xssfrow, 5); + String[] boxno = PlmLocale.getString("boxno").split(";"); + cell.setCellValue(boxno[0] + getNumStr(box) + boxno[1]); + + int page = row / PAGE + 1; + row = page * PAGE + TITLE_CNT; + } + xssfrow = TCUtil.getRow(sheet, row); + cell = TCUtil.getCell(xssfrow, 0); + cell.setCellValue(rbox); + for(int i=1; i propMap; + private TCComponentItem item; + private int[] ids; + private String[] values; + private String[] names; + private boolean finished; + private ICSPropertyDescription[] desc; + + public EditClassificationDialog(AbstractAIFApplication app) throws Exception { +// this.app = app; + this.session = (TCSession) app.getSession(); +// this.myService = session.getClassificationService(); + InterfaceAIFComponent target = AIFUtility.getCurrentApplication().getTargetComponent(); + + if (!(target instanceof TCComponentItem)) { + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("chooserev"), "ERROR", MessageBox.ERROR); + return; + } + address = session.getPreferenceService().getStringValue("Autocode_SendClassServer_URL"); + if(address == null || address.isEmpty()) { + MessageBox.post(AIFUtility.getActiveDesktop(), "Autocode_SendClassServer_URL" + PlmLocale.getString("preferr"), "ERROR", MessageBox.ERROR); + return; + } + String[] options = session.getPreferenceService().getStringValues("KWC_IDAddrule"); + if(options == null || options.length == 0) { + MessageBox.post(AIFUtility.getActiveDesktop(), "KWC_IDAddrule" + PlmLocale.getString("preferr"), "ERROR", MessageBox.ERROR); + return; + } + item = (TCComponentItem) target; + if(!TCUtil.contains(options, item.getType())) { + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("notinoptions"), "ERROR", MessageBox.ERROR); + return; + } + boolean isAccess = session.getTCAccessControlService().checkPrivilege(item, "WRITE"); + if (!isAccess) { + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("noaccess"), "ERROR", MessageBox.ERROR); + return; + } + if(item.getReferenceListProperty("revision_list").length > 1) { + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("revcounterr"), "ERROR", MessageBox.ERROR); + return; + } + if(item.getLatestItemRevision().getDateProperty("date_released") != null) { + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("statuserr"), "ERROR", MessageBox.ERROR); + return; + } +// System.out.println("deleteClass:" + deleteClass("UID")); + initUI(); + } + + @SuppressWarnings("unchecked") + private void initUI() throws Exception { + this.setTitle(PlmLocale.getString("classtitle")); + + JPanel rootPanel = new JPanel(); + rootPanel.setLayout(null); + rootPanel.setPreferredSize(new Dimension(600, 350)); + + Map displayMap = new LinkedHashMap(); + propMap = new HashMap(); + + if (item.getClassificationClass() != null && !"".equals(item.getClassificationClass())) { + try { + item.refresh(); + System.out.println("rev.getClassificationClass()=" + item.getClassificationClass()); + TCComponentICO ico = item.getClassificationObjects()[0]; + ICSProperty[] props = ico.getICSProperties(true); + desc = ico.getICSPropertyDescriptors(); + for (int i = 0; i < props.length; i++) { +// System.out.println(props[i].getId() + "===>" + props[i].getValue());// 30101===> + // desc.getName=Type and size series ǷԵ||| desc.getId=30101ǷID +// System.out.println("desc.getName=" + desc[i].getName() + " desc.getId=" + desc[i].getId()); + displayMap.put(props[i], desc[i]); + } + } catch (Exception e1) { + e1.printStackTrace(); + } + } else { + this.disposeDialog(); + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("noclasserr"), "ERROR", MessageBox.ERROR); + return; + } + + if (displayMap.size() == 0) { + return; + } + + JPanel content = new JPanel(); + content.setLayout(null); + content.setPreferredSize(new Dimension(600, displayMap.size() * (25 + 10))); + + int num = 0; + // ͨȡеķԣȻ + for (Entry entry : displayMap.entrySet()) { + JLabel label = new JLabel(entry.getValue().getName() + ""); + label.setBounds(10, num * 35 + 10, 100, 25); + + ICSKeyLov lov = entry.getValue().getFormat().getKeyLov(); +// ArrayList list = new ArrayList<>(); + if (lov != null) { + String[] keys = lov.getKeys(); + JAutoCompleteComboBox combo = new JAutoCompleteComboBox(); +// JComboBox combo = new JComboBox(); + combo.addItem(new ClassPropBean("", "", "")); + for (String key : keys) { + combo.addItem(new ClassPropBean(key, lov.getValueOfKey(key), "")); + } + + String v = entry.getKey().getValue(); + for (int i = 0; i < combo.getItemCount(); i++) { + if (v.equals(((ClassPropBean) combo.getItemAt(i)).getId())) { + combo.setSelectedIndex(i); + break; + } + } +// combo.setSelectedItem(v); +// if (!Arrays.asList(lov.getDisplayValues()).contains(v)) { +// combo.addItem(v); +// combo.setSelectedItem(v); +// } + + combo.setBounds(130, num * 35 + 10, 350, 25); + + propMap.put(entry.getValue().getName(), combo); + content.add(combo); + } else { + JTextField text = new JTextField(entry.getKey().getValue()); + text.setBounds(130, num * 35 + 10, 350, 25); + propMap.put(entry.getValue().getName(), text); + content.add(text); + } + + content.add(label); + + num++; + } + + JButton okBtn = new JButton(PlmLocale.getString("ok")); + okBtn.setBounds(40, 310, 100, 25); + okBtn.setSelected(true); + okBtn.addActionListener(ok()); + JButton cancelBtn = new JButton(PlmLocale.getString("cel")); + cancelBtn.setBounds(160, 310, 100, 25); + cancelBtn.addActionListener(cancel()); + + JScrollPane jsp = new JScrollPane(content); + jsp.getVerticalScrollBar().setUnitIncrement(16); + jsp.setBounds(0, 0, 600, 300); + jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + rootPanel.add(jsp); + rootPanel.add(okBtn); + rootPanel.add(cancelBtn); + this.add(rootPanel); + this.pack(); + this.centerToScreen(); + this.setAutoRequestFocus(true); +// this.setResizable(false); + this.setAlwaysOnTop(true); + this.showDialog(); + } + + private ActionListener ok() { + return new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + ((JButton) e.getSource()).setEnabled(false); +// TCComponentItemRevision rev = item.getLatestItemRevision(); + + new Thread(new Runnable() { + @Override + public void run() { + int i = 1; + while (!finished) { + try { + setTitle("޸ķ " + createPoint(i++ % 3)); + Thread.sleep(200); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }).start(); + + setAlwaysOnTop(false); + if (saveClassification()) { + MessageBox.post(EditClassificationDialog.this, "޸ķԳɹ", "INFO", MessageBox.INFORMATION); + disposeDialog(); + } else { + MessageBox.post(EditClassificationDialog.this, "޸ķʧܣ", "ERROR", MessageBox.ERROR); + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(EditClassificationDialog.this, PlmLocale.getString("err") + e1.toString(), "ERROR", MessageBox.ERROR); + } + } + }; + } + + private ActionListener cancel() { + return new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + disposeDialog(); + } + }; + } + + @SuppressWarnings("unchecked") + private boolean saveClassification() { + try { +// TCComponentForm form = (TCComponentForm) rev.getRelatedComponents("IMAN_master_form_rev")[0]; +// TCComponent[] status = form.getRelatedComponents("release_status_list"); +// for (TCComponent comp : status) { +// if (comp.getProperty("object_name").contains("ʽ")) { +// JOptionPane.showMessageDialog(this, "汾ʽ޸ķ", "ʾ", JOptionPane.WARNING_MESSAGE); +// return false; +// } +// } + TCComponentICO[] icoS = item.getClassificationObjects(); +// System.out.println("======>ȡķ:" + icoS.length); + if (icoS == null || icoS.length == 0) { + return false; + } + String classID = item.getClassificationClass(); + ArrayList propList = new ArrayList<>(); + TCComponentICO ico = icoS[0]; + ICSPropertyDescription[] desc = ico.getICSPropertyDescriptors(); + ICSProperty[] oldICSProps = ico.getICSProperties(true); + ids = new int[oldICSProps.length]; + values = new String[oldICSProps.length]; + names = new String[oldICSProps.length]; + StringBuilder id = new StringBuilder(""); + StringBuilder json = new StringBuilder(""); + // "[{\"value\":\"1\",\"propertyID\":-500003},{\"value\":\"1\",\"propertyID\":-500011}]" + for (int j = 0; j < oldICSProps.length; j++) { + ids[j] = oldICSProps[j].getId(); + if (propMap.get(desc[j].getName()) instanceof JComboBox) { + ClassPropBean bean = (ClassPropBean) ((JComboBox) propMap.get(desc[j].getName())).getSelectedItem(); + String str = bean.getId(); + values[j] = " ".equals(str) ? "" : str; + } else { + values[j] = ((JTextField) propMap.get(desc[j].getName())).getText(); + } + names[j] = desc[j].getName(); + ClassProperty prop = new ClassProperty(ids[j], values[j]); + propList.add(prop); + id.append("/").append(values[j]); + json.append(",{\"value\":\"").append(values[j]).append("\",\"propertyID\":\"").append(ids[j]).append("\"}"); + } +// String json = "";//objectToJson(propList); + System.out.println("classID=" + classID); +// System.out.println("json=" + json); +// System.out.println("ɾ..."); + String[] result = deleteClass(getICO(item, classID).getUid()).split("&&"); + if(!result[0].equals("200")) { + MessageBox.post(EditClassificationDialog.this, + String.format("%s%s%s%s%s%s", PlmLocale.getString("delete"), PlmLocale.getString("message1"), PlmLocale.getString("message2"), + result[0], PlmLocale.getString("message3"), result[1]), "ERROR", MessageBox.ERROR); + return false; + } + JSONObject resultJson = JSON.parseObject(result[1]); + Boolean success = resultJson.getBoolean("Status"); + if(!success) { + MessageBox.post(EditClassificationDialog.this, + String.format("%s%s%s%s", PlmLocale.getString("delete"), PlmLocale.getString("message1"), PlmLocale.getString("message3"), + result[1]), "ERROR", MessageBox.ERROR); + return false; + } + +// System.out.println("ͷ..."); + result = sendToClass(item.getUid(), classID, "["+json.substring(1)+"]").split("&&"); + if(!result[0].equals("200")) { + MessageBox.post(EditClassificationDialog.this, + String.format("%s%s%s%s%s%s", PlmLocale.getString("send"), PlmLocale.getString("message1"), PlmLocale.getString("message2"), + result[0], PlmLocale.getString("message3"), result[1]), "ERROR", MessageBox.ERROR); + return false; + } + resultJson = JSON.parseObject(result[1]); + success = resultJson.getBoolean("Status"); + if(!success) { + MessageBox.post(EditClassificationDialog.this, + String.format("%s%s%s%s", PlmLocale.getString("send"), PlmLocale.getString("message1"), PlmLocale.getString("message3"), + result[1]), "ERROR", MessageBox.ERROR); + return false; + } + String newid = id.substring(1); + System.out.println("newid:"+newid); + /**/ + String oldid = item.getProperty("item_id"); + item.setProperty("item_id", newid); + TCComponent itemForm = item.getRelatedComponents("IMAN_master_form")[0]; + itemForm.setProperty("object_name", itemForm.getProperty("object_name").replaceAll(oldid, newid)); + TCComponent revForm = item.getLatestItemRevision().getRelatedComponents("IMAN_master_form_rev")[0]; + revForm.setProperty("object_name", revForm.getProperty("object_name").replaceAll(oldid, newid)); + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(EditClassificationDialog.this, PlmLocale.getString("err") + e1.toString(), "ʾ", MessageBox.ERROR); + return false; + } + return true; + } + + private TCComponentICO getICO(TCComponent target, String classId) throws Exception { + if (target == null || classId.equals("")) { + return null; + } + TCComponentICO[] icos = target.getClassificationObjects(); + System.out.println(target + " -> Ѵڷࣺ" + Arrays.toString(icos)); + int len = icos.length; + if (len == 0) { + return null; + } + TCClassificationService classService = session.getClassificationService(); + for (int i = 0; i < len; i++) { + TCComponentICO ico = icos[i]; + classService.loadICOs(new String[] { ico.getUid() }, ""); + if (ico.getClassId() == null || ico.getClassId().equals("")) { + throw new Exception("쳣ϵԱ"); + } + if (classId.equals(ico.getClassId())) { + return ico; + } + } + return null; + } + + /** + * ȡLOVʾֵ + * @param icsD + * @return + */ + public static String getClassDisplayableValue(ICSPropertyDescription icsD) { + String result = ""; + ICSKeyLov lov = icsD.getFormat().getKeyLov(); + if (lov != null) { + String[] keys = lov.getKeys(); + for (String key : keys) { + result = lov.getValueOfKey(key); + return result; + } + } + return result; + } + + private String createPoint(int num) { + StringBuilder sb = new StringBuilder(); + while (num > 0) { + sb.append("."); + num--; + } + return sb.toString(); + } + + private String deleteClass(String icoPuid) throws Exception { + String soapRequestData = "" + + "" + + "" + + icoPuid + + ""; + + System.out.println("xml:"+soapRequestData); + System.out.println("address:"+address); + PostMethod postMethod = new PostMethod(address); + byte[] b = soapRequestData.getBytes("utf-8"); + ByteArrayInputStream is = new ByteArrayInputStream(b, 0, b.length); + InputStreamRequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=utf-8"); + postMethod.setRequestEntity(re); + + HttpClient httpClient = new HttpClient(); + int statusCode = httpClient.executeMethod(postMethod); + soapRequestData = postMethod.getResponseBodyAsString(); + System.out.println("soapRequestData="+soapRequestData); + + //TODO + // 200˵ + + if(soapRequestData.indexOf("")>0) { + soapRequestData = soapRequestData.substring(soapRequestData.indexOf("") + 19, soapRequestData.indexOf("")); + } + return statusCode+"&&"+soapRequestData; + } + + private String sendToClass(String wsoPUID, String classID, String json) throws Exception { + String soapRequestData = "" + + "" + + "" + + ""+wsoPUID+"" + + ""+classID+"" + + ""+json+""; + + System.out.println("xml:"+soapRequestData); + System.out.println("address:"+address); + PostMethod postMethod = new PostMethod(address); + byte[] b = soapRequestData.getBytes("utf-8"); + ByteArrayInputStream is = new ByteArrayInputStream(b, 0, b.length); + InputStreamRequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=utf-8"); + postMethod.setRequestEntity(re); + + HttpClient httpClient = new HttpClient(); + int statusCode = httpClient.executeMethod(postMethod); + soapRequestData = postMethod.getResponseBodyAsString(); + System.out.println("soapRequestData="+soapRequestData); + + //TODO + // 200˵ + + if(soapRequestData.indexOf("")>0) { + soapRequestData = soapRequestData.substring(soapRequestData.indexOf("") + 19, soapRequestData.indexOf("")); + } + return statusCode+"&&"+soapRequestData; + } +/* + public void deleteClass(String icoPuid) { + try { + ServiceClient sc = new ServiceClient(); + Options opts = new Options(); + String url = JDMethodUtil.getPrefStr("Autocode_SendClassServer_URL", session);// "http://10.201.5.203:19090/ErpWebService.asmx?WSDL"; + EndpointReference end = new EndpointReference(url); + opts.setTo(end); + opts.setAction("DeleteClass"); + sc.setOptions(opts); + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", ""); + OMElement method = fac.createOMElement("DeleteClass", omNs); + OMElement value = fac.createOMElement("icoPuid", omNs); + value.setText(icoPuid); + + method.addChild(value); + + OMElement res = sc.sendReceive(method); + res.getFirstElement().getText(); + System.out.println(res.getFirstElement().getText()); + } catch (AxisFault e) { + e.printStackTrace(); + } + + } + + public boolean sendToClass(String wsoPUID, String classID, String json) { + try { + ServiceClient sc = new ServiceClient(); + Options opts = new Options(); + String url = JDMethodUtil.getPrefStr("Autocode_SendClassServer_URL", session); + // "http://10.201.5.203:19090/ErpWebService.asmx?WSDL"; + EndpointReference end = new EndpointReference(url); + opts.setTo(end); + opts.setAction("SendToClass"); + sc.setOptions(opts); + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", ""); + OMElement method = fac.createOMElement("SendToClass", omNs); + OMElement value = fac.createOMElement("wsoPuiid", omNs); + value.setText(wsoPUID); + OMElement value1 = fac.createOMElement("classID", omNs); + value1.setText(classID); + OMElement value2 = fac.createOMElement("JsonContainer", omNs); + // "[{\"value\":\"1\",\"propertyID\":-500003},{\"value\":\"1\",\"propertyID\":-500011}]" + value2.setText(json); + + method.addChild(value); + method.addChild(value1); + method.addChild(value2); + + OMElement res = sc.sendReceive(method); + res.getFirstElement().getText(); + System.out.println(res.getFirstElement().getText()); + } catch (AxisFault e) { +// MessageBox.post("ͷʧܣ", "", MessageBox.ERROR); + e.printStackTrace(); + return false; + } + return true; + + } + + public static String objectToJson(List props) { + String str = null; + try { + JSONArray json = JSONArray.fromObject(props);// javaתΪjson + str = json.toString();// jsonתΪַ + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("JSON =>" + str); + return str; + }*/ +} diff --git a/src/com/connor/cust/classification/EditClassificationHandler.java b/src/com/connor/cust/classification/EditClassificationHandler.java new file mode 100644 index 0000000..f807db5 --- /dev/null +++ b/src/com/connor/cust/classification/EditClassificationHandler.java @@ -0,0 +1,31 @@ +package com.connor.cust.classification; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.cust.box.PlmLocale; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.util.MessageBox; +/** + * : ޸ķԺItemID + * :2024-01-10 + * @author  + * + * ޸ ޸ ޸ + * 2019-01-24 XXXX + */ +public class EditClassificationHandler extends AbstractHandler{ + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("EditClassificationHandler"); + try { + new EditClassificationDialog(AIFUtility.getCurrentApplication()); + } catch(Exception e) { + e.printStackTrace(); + MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("err") + e.getMessage(), "ERROR", MessageBox.ERROR); + } + return null; + } +} diff --git a/src/com/connor/cust/classification/JAutoCompleteComboBox.java b/src/com/connor/cust/classification/JAutoCompleteComboBox.java new file mode 100644 index 0000000..5caca57 --- /dev/null +++ b/src/com/connor/cust/classification/JAutoCompleteComboBox.java @@ -0,0 +1,160 @@ +package com.connor.cust.classification; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.List; +import java.util.Vector; + +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JTextField; + +@SuppressWarnings({ "serial", "rawtypes", "unchecked" }) +public class JAutoCompleteComboBox extends JComboBox { + private AutoCompleter completer; + + public JAutoCompleteComboBox() { + super(); + addCompleter(); + } + + public JAutoCompleteComboBox(ComboBoxModel cm) { + super(cm); + addCompleter(); + } + + public JAutoCompleteComboBox(Object[] items) { + super(items); + addCompleter(); + } + + public JAutoCompleteComboBox(List v) { + super((Vector) v); + addCompleter(); + } + + private void addCompleter() { + setEditable(true); + completer = new AutoCompleter(this); + } + + public void autoComplete(String str) { + this.completer.autoComplete(str, str.length()); + } + + public String getText() { + return ((JTextField) getEditor().getEditorComponent()).getText(); + } + + public void setText(String text) { + ((JTextField) getEditor().getEditorComponent()).setText(text); + } + + public boolean containsItem(String itemString) { + for (int i = 0; i < this.getModel().getSize(); i++) { + String _item = " " + this.getModel().getElementAt(i); + if (_item.equals(itemString)) + return true; + } + return false; + } + +} + +@SuppressWarnings({"rawtypes"}) +class AutoCompleter implements KeyListener, ItemListener { + + private JComboBox owner = null; + private JTextField editor = null; + + private ComboBoxModel model = null; + + public AutoCompleter(JComboBox comboBox) { + owner = comboBox; + editor = (JTextField) comboBox.getEditor().getEditorComponent(); + editor.addKeyListener(this); + model = comboBox.getModel(); + owner.addItemListener(this); + } + + public void keyTyped(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + } + + @SuppressWarnings("unused") + public void keyReleased(KeyEvent e) { + char ch = e.getKeyChar(); + // if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch) + // || ch == KeyEvent.VK_DELETE) + // return; + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + int caretPosition = editor.getCaretPosition(); + String str = editor.getText(); + if (str.length() == 0) + return; + autoComplete(str, caretPosition); + } + } + + @SuppressWarnings({ "unchecked", "unused" }) + protected void autoComplete(String strf, int caretPosition) { + Object[] opts; + opts = getMatchingOptions(strf.substring(0, caretPosition)); + if (owner != null) { + model = new DefaultComboBoxModel(opts); + owner.setModel(model); + } + if (opts.length > 0) { + String str = opts[0].toString(); + editor.setCaretPosition(caretPosition); + if (owner != null) { + try { + owner.showPopup(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } + + @SuppressWarnings("unchecked") + protected Object[] getMatchingOptions(String str) { + List v = new Vector(); + List v1 = new Vector(); + // v.add(str); + for (int k = 0; k < model.getSize(); k++) { + Object itemObj = model.getElementAt(k); + if (itemObj != null) { + String item = itemObj.toString().toLowerCase(); + if (item.indexOf((str.toLowerCase())) > -1) + v.add(model.getElementAt(k)); + else + v1.add(model.getElementAt(k)); + } else + v1.add(model.getElementAt(k)); + } + for (int i = 0; i < v1.size(); i++) { + v.add(v1.get(i)); + } + // if (v.isEmpty()) + return v.toArray(); + } + + public void itemStateChanged(ItemEvent event) { + if (event.getStateChange() == ItemEvent.SELECTED) { + int caretPosition = editor.getCaretPosition(); + if (caretPosition != -1) { + try { + editor.moveCaretPosition(caretPosition); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/src/com/connor/cust/util/POIUtil.java b/src/com/connor/cust/util/POIUtil.java new file mode 100644 index 0000000..8518e61 --- /dev/null +++ b/src/com/connor/cust/util/POIUtil.java @@ -0,0 +1,1000 @@ +package com.connor.cust.util; + +import java.awt.Point; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.poi.ooxml.POIXMLDocumentPart; +import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.ClientAnchor; +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.ss.util.AreaReference; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFColor; +import org.apache.poi.xssf.usermodel.XSSFDrawing; +import org.apache.poi.xssf.usermodel.XSSFFont; +import org.apache.poi.xssf.usermodel.XSSFName; +import org.apache.poi.xssf.usermodel.XSSFPicture; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFShape; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide; + +public class POIUtil { + +// public static XSSFColor GRAY = new XSSFColor(new Color(217, 217, 217)); +// public static XSSFColor YELLOW = new XSSFColor(new Color(255, 255, 204)); +// public static XSSFColor BLUE = new XSSFColor(new Color(0, 0, 255)); +// public static XSSFColor GREEN = new XSSFColor(new Color(158, 234, 106)); + + public static void setValue(XSSFSheet sheet, int rowId, int col, String val) { + setValue(sheet, rowId, col, val, null); + } + + public static int getTitleRow(XSSFSheet sheet, int startRow, String[] titleData) { + if (sheet == null || titleData.length == 0) { + return -1; + } + int lastRow = sheet.getLastRowNum(); + for (int i = startRow; i <= lastRow; i++) { + LinkedHashMap data = POIUtil.readRow(null, sheet, i, false); + if (data == null) { + continue; + } + boolean match = true; + for (String title : titleData) { + if (!data.containsValue(title)) { + match = false; + break; + } + } + if (match) { + return i; + } + } + return -1; + } + + public static XSSFCellStyle getMergeCellStyle(XSSFWorkbook wb, XSSFColor bgColor, XSSFColor fontColor, String fontFamily, short fontSize, boolean bold, boolean top, boolean right, boolean bottom, + boolean left, HorizontalAlignment ha) { + XSSFCellStyle style = wb.createCellStyle(); + style.setBorderBottom(bottom ? BorderStyle.MEDIUM : BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderLeft(left ? BorderStyle.MEDIUM : BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderRight(right ? BorderStyle.MEDIUM : BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderTop(top ? BorderStyle.MEDIUM : BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + style.setAlignment(ha); + style.setVerticalAlignment(VerticalAlignment.CENTER); + if (bgColor != null) { + style.setFillForegroundColor(bgColor); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + XSSFFont font = wb.createFont(); + if (fontColor != null) { + font.setColor(fontColor); + } + if (!fontFamily.isEmpty()) { + font.setFontName(fontFamily);// (FontFamily.valueOf(fontFamily)); + } + if (fontSize > 0) { + font.setFontHeightInPoints(fontSize); + } + font.setBold(bold); + style.setFont(font); + + return style; + } + + public static CellRangeAddress CellRangeAddress(XSSFWorkbook wb, XSSFSheet sheet, int a, int b, int c, int d, XSSFColor bgColor, XSSFColor fontColor, String fontFamily, short fontSize, + boolean bold, boolean top, boolean right, boolean bottom, boolean left, HorizontalAlignment ha) { + CellRangeAddress res = new CellRangeAddress(a, b, c, d); + XSSFCellStyle style = getMergeCellStyle(wb, bgColor, fontColor, fontFamily, fontSize, bold, top, right, bottom, left, ha); + for (int rowId = a; rowId <= b; rowId++) { + XSSFRow row = sheet.getRow(rowId); + if (row == null) { + continue; + } + for (int colId = c; colId <= d; colId++) { + XSSFCell cell = row.getCell(colId); + if (cell == null) { + cell = row.createCell(colId); + } + cell.setCellStyle(style); + } + } + return res; + } + + public static CellRangeAddress CellRangeAddress(XSSFWorkbook wb, XSSFSheet sheet, int a, int b, int c, int d, XSSFCellStyle style) { + CellRangeAddress res = new CellRangeAddress(a, b, c, d); + for (int rowId = a; rowId <= b; rowId++) { + XSSFRow row = sheet.getRow(rowId); + if (row == null) { + continue; + } + for (int colId = c; colId <= d; colId++) { + XSSFCell cell = row.getCell(colId); + if (cell == null) { + cell = row.createCell(colId); + } + cell.setCellStyle(style); + } + } + return res; + } + + public static CellRangeAddress CellRangeAddress(XSSFWorkbook wb, XSSFSheet sheet, int a, int b, int c, int d, XSSFColor bgColor, XSSFColor fontColor, String fontFamily, short fontSize, + boolean bold, boolean top, boolean right, boolean bottom, boolean left) { + return CellRangeAddress(wb, sheet, a, b, c, d, bgColor, fontColor, fontFamily, fontSize, bold, top, right, bottom, left, HorizontalAlignment.CENTER); + } + + public static CellRangeAddress CellRangeAddress(XSSFWorkbook wb, XSSFSheet sheet, int a, int b, int c, int d) { + return CellRangeAddress(wb, sheet, a, b, c, d, null, null, "SimSun", (short) 11, false, false, false, false, false, HorizontalAlignment.CENTER); + } + + public static CellRangeAddress CellRangeAddress(XSSFWorkbook wb, XSSFSheet sheet, int a, int b, int c, int d, HorizontalAlignment ha) { + return CellRangeAddress(wb, sheet, a, b, c, d, null, null, "SimSun", (short) 11, false, false, false, false, false, ha); + } + + public static void setValue(XSSFSheet sheet, int rowId, int col, String val, XSSFCellStyle style) { + XSSFRow row = sheet.getRow(rowId); + if (row == null) { + row = sheet.createRow(rowId); + } + XSSFCell cell = row.getCell(col); + if (cell == null) { + cell = row.createCell(col); + } + cell.setCellValue(val); + if (style != null) { + cell.setCellStyle(style); + } + } + + public static void setValue(XSSFRow row, int col, String val, XSSFCellStyle style) { + XSSFCell cell = row.getCell(col); + if (cell == null) { + cell = row.createCell(col); + } + cell.setCellValue(val); + if (style != null) { + cell.setCellStyle(style); + } + } + + public static XSSFCellStyle getCellStyle(XSSFWorkbook wb, XSSFColor color, boolean isRight) { + XSSFCellStyle style = wb.createCellStyle(); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderRight(isRight ? BorderStyle.MEDIUM : BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + if (color != null) { + style.setFillForegroundColor(color); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + return style; + } + + public static XSSFCellStyle getCellStyle(XSSFWorkbook wb, XSSFColor color, boolean isRight, String fontFamily, short fontSize) { + XSSFCellStyle style = wb.createCellStyle(); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderRight(isRight ? BorderStyle.MEDIUM : BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + if (color != null) { + style.setFillForegroundColor(color); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + XSSFFont font = wb.createFont(); + if (!fontFamily.isEmpty()) { + font.setFontName(fontFamily);// (FontFamily.valueOf(fontFamily)); + } + if (fontSize > 0) { + font.setFontHeightInPoints(fontSize); + } + style.setFont(font); + return style; + } + + public static XSSFCellStyle getCellStyleNoBorder(XSSFWorkbook wb, XSSFColor color, String fontFamily, short fontSize) { + XSSFCellStyle style = wb.createCellStyle(); + if (color != null) { + style.setFillForegroundColor(color); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + XSSFFont font = wb.createFont(); + if (!fontFamily.isEmpty()) { + font.setFontName(fontFamily);// (FontFamily.valueOf(fontFamily)); + } + if (fontSize > 0) { + font.setFontHeightInPoints(fontSize); + } + style.setFont(font); + return style; + } + + public static XSSFCellStyle getCellStyleCenter(XSSFWorkbook wb, XSSFColor color, boolean isRight, String fontFamily, short fontSize) { + XSSFCellStyle style = wb.createCellStyle(); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderRight(isRight ? BorderStyle.MEDIUM : BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + if (color != null) { + style.setFillForegroundColor(color); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + XSSFFont font = wb.createFont(); + if (!fontFamily.isEmpty()) { + font.setFontName(fontFamily);// (FontFamily.valueOf(fontFamily)); + } + if (fontSize > 0) { + font.setFontHeightInPoints(fontSize); + } + style.setFont(font); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setAlignment(HorizontalAlignment.CENTER); + return style; + } + + public static void setValue(XSSFRow row, int col, String val) { + XSSFCell cell = row.getCell(col); + if (cell == null) { + cell = row.createCell(col); + // cell.setCellType(STRING); + } + cell.setCellValue(val); + } + + public static void setValue(XSSFRow row, int col, int val) { + XSSFCell cell = row.getCell(col); + if (cell == null) { + cell = row.createCell(col); + } + cell.setCellValue(val); + } + + public static void setValue(XSSFRow row, int col, double val) { + XSSFCell cell = row.getCell(col); + if (cell == null) { + cell = row.createCell(col); + } + cell.setCellValue(val); + } + + public static int[] parseLocation(String location) { + if (location.isEmpty()) { + return null; + } + int ind = -1; + char[] arr = location.toCharArray(); + int len = arr == null ? 0 : arr.length; + for (int i = 0; i < len; i++) { + char c = arr[i]; + if (c >= '0' && c <= '9') { + ind = i; + break; + } + } + if (ind < 0) { + return null; + } + String col = location.substring(0, ind); + String row = location.substring(ind); + int colNum = parseExcelCol(col) - 1; + int rowNum = 0; + if (!row.isEmpty()) { + try { + rowNum = Integer.parseInt(row) - 1; + } catch (Exception e) { + e.printStackTrace(); + } + } + return new int[] { colNum, rowNum }; + } + + public static int parseExcelCol(String s) { + int length = s.length(); + int col = 0; + for (int i = 0; i < length; i++) { + col = col * 26 + s.charAt(i) - 64; + } + return col; + } + + public static String formatExcelCol(int s) { + int n; + String res = ""; + while (s / 26 != 0) { + n = s % 26; + s = s / 26; + if (n == 0) { + n = 26; + s = s - 1; + } + res = (char) (n + 64) + res; + } + if (s != 0) { + res = (char) (s + 64) + res; + } + return res; + } + + public static void deleteCol(XSSFSheet sheet, int startRow, int EndRow, int columnToDelete) { + int maxColumn = 0; + for (int r = startRow; r <= EndRow; r++) { + Row row = sheet.getRow(r); + if (row == null) + continue; + int lastColumn = row.getLastCellNum(); + if (lastColumn > maxColumn) + maxColumn = lastColumn; + + if (lastColumn < columnToDelete) + continue; + for (int x = columnToDelete + 1; x < lastColumn + 1; x++) { + Cell oldCell = row.getCell(x - 1); + if (oldCell != null) + row.removeCell(oldCell); + + Cell nextCell = row.getCell(x); + if (nextCell != null) { + Cell newCell = row.createCell(x - 1, nextCell.getCellType()); + cloneCell(newCell, nextCell, true); + } + } + } + for (int c = 0; c < maxColumn; c++) { + sheet.setColumnWidth(c, sheet.getColumnWidth(c + 1)); + } + } + + public static void deleteColumn(Sheet sheet, int columnToDelete) { + int maxColumn = 0; + for (int r = 0; r < sheet.getLastRowNum() + 1; r++) { + Row row = sheet.getRow(r); + + // if no row exists here; then nothing to do; next! + if (row == null) + continue; + + // if the row doesn't have this many columns then we are good; next! + int lastColumn = row.getLastCellNum(); + if (lastColumn > maxColumn) + maxColumn = lastColumn; + + if (lastColumn < columnToDelete) + continue; + + for (int x = columnToDelete + 1; x < lastColumn + 1; x++) { + Cell oldCell = row.getCell(x - 1); + if (oldCell != null) + row.removeCell(oldCell); + + Cell nextCell = row.getCell(x); + if (nextCell != null) { + Cell newCell = row.createCell(x - 1, nextCell.getCellType()); + cloneCell(newCell, nextCell, true); + } + } + } + + // Adjust the column widths + for (int c = 0; c < maxColumn; c++) { + sheet.setColumnWidth(c, sheet.getColumnWidth(c + 1)); + } + } + + /* + * Takes an existing Cell and merges all the styles and forumla into the new one + */ + public static void cloneCell(Cell cNew, Cell cOld, boolean includeValue) { + cNew.setCellComment(cOld.getCellComment()); + cNew.setCellStyle(cOld.getCellStyle()); + if (!includeValue) { + return; + } + switch (cOld.getCellType()) { + case BOOLEAN: + cNew.setCellValue(cOld.getBooleanCellValue()); + break; + case NUMERIC: + cNew.setCellValue(cOld.getNumericCellValue()); + break; + case STRING: + cNew.setCellValue(cOld.getStringCellValue()); + break; + case ERROR: + cNew.setCellValue(cOld.getErrorCellValue()); + break; + case FORMULA: + cNew.setCellFormula(cOld.getCellFormula()); + break; + default: + break; + } + + } + + public static XSSFRow insertRow(XSSFSheet sheet, int row) { + int regionCnt = sheet.getNumMergedRegions(); + int sourceRowNum = row-1; + List copyRanges = new ArrayList(); + for (int n = 0; n < regionCnt; n++) { + CellRangeAddress region = sheet.getMergedRegion(n); + if ((region.getFirstRow() == sourceRowNum) && (region.getLastRow() == sourceRowNum)) { + copyRanges.add(region); + + } + } + XSSFRow sourceRow = sheet.getRow(sourceRowNum); + sheet.shiftRows(row, sheet.getLastRowNum(), 1, true, false); + XSSFRow targetRow = null; + XSSFCell sourceCell = null; + XSSFCell targetCell = null; + short m; + targetRow = sheet.createRow(row); + if (sourceRow != null) { + targetRow.setHeight(sourceRow.getHeight()); + for (m = sourceRow.getFirstCellNum(); m < sourceRow.getLastCellNum(); m++) { + sourceCell = sourceRow.getCell(m); + targetCell = targetRow.createCell(m); + targetCell.setCellStyle(sourceCell.getCellStyle()); + targetCell.setCellType(sourceCell.getCellType()); + } + } + for (CellRangeAddress region : copyRanges) { + CellRangeAddress newRegion = new CellRangeAddress(row, row, region.getFirstColumn(), region.getLastColumn()); + sheet.addMergedRegion(newRegion); + } + return targetRow; + } + + /** + * Excel + * @param workbook + * @param sheet sheetҳ + * @param startRow Դʼ + * @param endRow ԴֹУ + * @param margin Ŀ + * @param endCol к + * @param copyCount + */ + public static void copyRows(XSSFWorkbook workbook, XSSFSheet sheet, int startRow, int endRow, int margin, int endCol, int copyCount) { + int regionCnt = sheet.getNumMergedRegions(); + CellRangeAddress region; + for (int i = startRow; i <= endRow; i++) { + XSSFRow sourceRow = null; + XSSFRow targetRow = null; + XSSFCell sourceCell = null; + XSSFCell targetCell = null; + short m; + sourceRow = getRow(sheet, i); + for (int j = 1; j <= copyCount; j++) { + int space = (endRow - startRow + 1 + margin) * j; + targetRow = sheet.createRow(i + space); + targetRow.setHeight(sourceRow.getHeight()); + for (m = sourceRow.getFirstCellNum(); m <= endCol; m++) { + if(m < 0) + continue; + sourceCell = getCell(sourceRow, m); + targetCell = targetRow.createCell(m); + if (sourceCell != null) { + targetCell.setCellStyle(sourceCell.getCellStyle()); + CellType cType = sourceCell.getCellType(); + switch (cType) { + case STRING: + targetCell.setCellType(cType); + targetCell.setCellValue(sourceCell.getRichStringCellValue()); + break; + case NUMERIC: + targetCell.setCellType(cType); + targetCell.setCellValue(sourceCell.getNumericCellValue()); + break; + case FORMULA: + targetCell.setCellFormula(sourceCell.getCellFormula()); + break; + case BOOLEAN: + targetCell.setCellType(cType); + targetCell.setCellValue(sourceCell.getBooleanCellValue()); + break; + case ERROR: + targetCell.setCellType(cType); + targetCell.setCellValue(sourceCell.getErrorCellValue()); + break; + default: + targetCell.setCellType(cType); + targetCell.setCellValue(sourceCell.getRichStringCellValue()); + break; + } + } + } + + } + } + for (int j = 1; j <= copyCount; j++) { + int space = (endRow - startRow + 1 + margin) * j; + for (int n = 0; n < regionCnt; n++) { + region = sheet.getMergedRegion(n); + if ((region.getFirstColumn() >= startRow) && (region.getLastRow() <= endRow) && (region.getLastColumn() <= endCol)) { + CellRangeAddress newRegion = new CellRangeAddress(region.getFirstRow() + space, region.getLastRow() + space, region.getFirstColumn(), region.getLastColumn()); + sheet.addMergedRegion(newRegion); + } + } + } + } + + public static boolean writeToExcel(File tempFile, int[] cols, String[][] vals, int startRow, int endRow, Map otherData) { + FileInputStream input = null; + FileOutputStream output = null; + int rowCount = vals.length; + int colCount = cols.length; + XSSFRow row = null; + XSSFCell cell = null; + int index = 0; + try { + input = new FileInputStream(tempFile); + XSSFWorkbook wb = new XSSFWorkbook(input); + XSSFSheet sheet = wb.getSheetAt(index); + for (Point point : otherData.keySet()) { + row = sheet.getRow(point.x); + cell = row.getCell(point.y); + cell.setCellType(CellType.STRING); + cell.setCellValue(otherData.get(point)); + } + int sheetCount = vals.length % (endRow - startRow + 1) == 0 ? vals.length / (endRow - startRow + 1) : vals.length / (endRow - startRow + 1) + 1; + Map sheetMap = new HashMap<>(); + for (int i = 1; i < sheetCount; i++) { + XSSFSheet newSheet = wb.createSheet(); + copySheet(wb, sheet, newSheet); + sheetMap.put(i, newSheet); + } + for (int i = 0; i < rowCount; i++) { + if ((i + startRow - (endRow - startRow + 1) * index) > endRow) { + index++; + sheet = sheetMap.get(index); + row = sheet.getRow(i + startRow - (endRow - startRow + 1) * index); + } else { + row = sheet.getRow(i + startRow - (endRow - startRow + 1) * index); + } + for (int j = 0; j < colCount; j++) { + cell = row.getCell(cols[j]); + cell.setCellType(CellType.STRING); + cell.setCellValue(vals[i][j]); + } + } + output = new FileOutputStream(tempFile); + wb.write(output); + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + if (output != null) { + try { + output.close(); + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + System.out.println("-------WRITE EXCEL OVER-------"); + return true; + } + + public static XSSFSheet copySheet(XSSFWorkbook workbook, XSSFSheet sheetFrom, XSSFSheet sheetTo) { + CellRangeAddress region = null; + XSSFRow rowFrom = null; + XSSFRow rowTo = null; + XSSFCell cellFrom = null; + XSSFCell cellTo = null; + for (int i = 0; i < sheetFrom.getNumMergedRegions(); i++) { + region = sheetFrom.getMergedRegion(i); + if ((region.getFirstColumn() >= sheetFrom.getFirstRowNum()) && (region.getLastRow() <= sheetFrom.getLastRowNum())) { + sheetTo.addMergedRegion(region); + } + } + for (int intRow = sheetFrom.getFirstRowNum(); intRow < sheetFrom.getLastRowNum(); intRow++) { + rowFrom = sheetFrom.getRow(intRow); + rowTo = sheetTo.createRow(intRow); + if (null == rowFrom) + continue; + rowTo.setHeight(rowFrom.getHeight()); + for (int intCol = 0; intCol < rowFrom.getLastCellNum(); intCol++) { + sheetTo.setDefaultColumnStyle(intCol, sheetFrom.getColumnStyle(intCol)); + sheetTo.setColumnWidth(intCol, sheetFrom.getColumnWidth(intCol)); + cellFrom = rowFrom.getCell(intCol); + cellTo = rowTo.createCell(intCol); + if (null == cellFrom) + continue; + cellTo.setCellStyle(cellFrom.getCellStyle()); + CellType cType = cellFrom.getCellType(); + cellTo.setCellType(cType); + switch (cType) { + case STRING: + cellTo.setCellValue(cellFrom.getRichStringCellValue()); + break; + case NUMERIC: + cellTo.setCellValue(cellFrom.getNumericCellValue()); + break; + case FORMULA: + cellTo.setCellFormula(cellFrom.getCellFormula()); + break; + case BOOLEAN: + cellTo.setCellValue(cellFrom.getBooleanCellValue()); + break; + case ERROR: + cellTo.setCellValue(cellFrom.getErrorCellValue()); + break; + default: + cellTo.setCellValue(cellFrom.getRichStringCellValue()); + break; + } + /* + * if (null != cellFrom.getStringCellValue() && + * !"".equals(cellFrom.getStringCellValue().trim())) + * cellTo.setCellValue(cellFrom.getStringCellValue()); + */ + } + } + XSSFDrawing patriarchTo = sheetTo.createDrawingPatriarch(); + for (POIXMLDocumentPart dr : sheetFrom.getRelations()) { + if (dr instanceof XSSFDrawing) { + XSSFDrawing drawing = (XSSFDrawing) dr; + List shapes = drawing.getShapes(); + for (XSSFShape shape : shapes) { + XSSFPicture pic = (XSSFPicture) shape; + patriarchTo.createPicture((ClientAnchor) pic.getAnchor(), workbook.addPicture(pic.getPictureData().getData(), XSSFWorkbook.PICTURE_TYPE_PNG)); + } + } + } + sheetTo.setDisplayGridlines(false); + sheetTo.setZoom(100); + return sheetTo; + + } + + // public static String getValue(XSSFRow titleRow, int i) { + // XSSFCell cell = titleRow.getCell(i); + // if(cell==null) { + // return ""; + // } + // if(cell.getCellType()==NUMERIC) { + // return cell.getNumericCellValue()+""; + // }else { + // return cell.getStringCellValue(); + // } + // } + + private static DecimalFormat DF = new DecimalFormat("#.##########################################"); + + public static String getValue(XSSFRow titleRow, int i) { + XSSFCell cell = titleRow.getCell(i); + if (cell == null) { + return ""; + } + if (cell.getCellType() == CellType.NUMERIC) { + return DF.format(cell.getNumericCellValue()); + } else if (cell.getCellType() == CellType.STRING) { + return cell.getStringCellValue(); + } + return ""; + } + + public static String getValue(XSSFSheet sheet, int i, int j) { + XSSFRow row = sheet.getRow(i); + if (row == null) { + return null; + } + return getValue(row, j); + } + + public static XSSFRow getRow(XSSFSheet sheet, int i) { + XSSFRow row = sheet.getRow(i); + if (row == null) { + row = sheet.createRow(i); + } + return row; + } + + public static LinkedHashMap readRow(SimpleDateFormat dateFormat, XSSFSheet sheet, int rowNum, boolean readEmpty) { + if (sheet == null) { + return null; + } + XSSFRow row = sheet.getRow(rowNum); + if (row == null) { + return null; + } + LinkedHashMap data = new LinkedHashMap(); + int firstCol = row.getFirstCellNum(); + if (firstCol < 0) { + firstCol = 0; + } + int lastCol = row.getLastCellNum(); + for (int i = firstCol; i <= lastCol; i++) { + XSSFCell cell = row.getCell(i); + if (cell == null) { + continue; + } + String value; + switch (cell.getCellType()) { + case STRING: + value = cell.getStringCellValue(); + break; + case NUMERIC: + if (dateFormat != null && DateUtil.isCellDateFormatted(cell)) { + value = cell.getDateCellValue() == null ? "" : dateFormat.format(cell.getDateCellValue()); + } else { + value = DF.format(cell.getNumericCellValue()); + } + break; + case FORMULA: + value = cell.getCellFormula(); + break; + case ERROR: + value = cell.getErrorCellString(); + break; + case BOOLEAN: + value = cell.getBooleanCellValue() ? "true" : "false"; + break; + case BLANK: + value = ""; + break; + default: + value = ""; + break; + } + if (!readEmpty && (value == null || "".equals(value))) { + continue; + } + data.put(i, value); + } + return data; + } + + public static LinkedHashMap readRow(SimpleDateFormat dateFormat, XSSFSheet sheet, int rowNum, Integer[] cols) { + if (sheet == null || cols.length == 0) { + return null; + } + XSSFRow row = sheet.getRow(rowNum); + if (row == null) { + return null; + } + LinkedHashMap data = new LinkedHashMap(); + for (Integer i : cols) { + XSSFCell cell = row.getCell(i); + if (cell == null) { + data.put(i, ""); + continue; + } + String value; + switch (cell.getCellType()) { + case STRING: + value = cell.getStringCellValue(); + break; + case NUMERIC: + if (dateFormat != null && DateUtil.isCellDateFormatted(cell)) { + value = cell.getDateCellValue() == null ? "" : dateFormat.format(cell.getDateCellValue()); + } else { + value = DF.format(cell.getNumericCellValue()); + } + break; + case FORMULA: + value = cell.getCellFormula(); + break; + case ERROR: + value = cell.getErrorCellString(); + break; + case BOOLEAN: + value = cell.getBooleanCellValue() ? "true" : "false"; + break; + case BLANK: + value = ""; + break; + default: + value = ""; + break; + } + data.put(i, value); + } + return data; + } + + public static void writeToNamedCells(XSSFWorkbook wb, Map excelDataMap) throws Exception { + if (wb == null || excelDataMap == null || excelDataMap.size() == 0) { + return; + } + for (String cellName : excelDataMap.keySet()) { + String value = excelDataMap.get(cellName); + System.out.println("[" + cellName + "]=[" + value + "]"); + XSSFName name = wb.getName(cellName); + if (name == null) { + System.out.println(">> Named Cell Not Found"); + } else { + AreaReference aref = new AreaReference(name.getRefersToFormula(), null); + CellReference[] crefs = aref.getAllReferencedCells(); + for (int i = 0; i < crefs.length; i++) { + XSSFSheet s = wb.getSheet(crefs[i].getSheetName()); + int row = crefs[i].getRow(); + int col = crefs[i].getCol(); + System.out.println(">> " + crefs[i].formatAsString()); + POIUtil.setValue(s, row, col, value); + } + } + } + } + + public static XSSFCellStyle cloneCellStype(XSSFCellStyle fromStyle, XSSFWorkbook wb, Map fontMap) throws Exception{ + if(fromStyle==null||wb==null) { + return null; + } + XSSFCellStyle toStyle = wb.createCellStyle(); + toStyle.setAlignment(fromStyle.getAlignment()); + toStyle.setBorderColor(BorderSide.TOP, fromStyle.getBorderColor(BorderSide.TOP)); + toStyle.setBorderColor(BorderSide.LEFT, fromStyle.getBorderColor(BorderSide.LEFT)); + toStyle.setBorderColor(BorderSide.BOTTOM, fromStyle.getBorderColor(BorderSide.BOTTOM)); + toStyle.setBorderColor(BorderSide.RIGHT, fromStyle.getBorderColor(BorderSide.RIGHT)); + toStyle.setBorderTop(fromStyle.getBorderTop()); + toStyle.setBorderLeft(fromStyle.getBorderLeft()); + toStyle.setBorderBottom(fromStyle.getBorderBottom()); + toStyle.setBorderRight(fromStyle.getBorderRight()); + XSSFFont fromFont = fromStyle.getFont(); + if(fromFont!=null) { + XSSFFont toFont = wb.createFont(); + if(fontMap.containsKey(fromFont)) { + toFont = fontMap.get(fromFont); + }else { + toFont = wb.createFont(); + toFont.setBold(fromFont.getBold()); +// toFont.setBoldweight(fromFont.getBoldweight()); + toFont.setCharSet(fromFont.getCharSet()); + toFont.setColor(fromFont.getColor()); + toFont.setColor(fromFont.getXSSFColor()); + toFont.setFamily(fromFont.getFamily()); + toFont.setFontHeight(fromFont.getFontHeight()); + toFont.setFontHeightInPoints(fromFont.getFontHeightInPoints()); + toFont.setFontName(fromFont.getFontName()); + toFont.setItalic(fromFont.getItalic()); + toFont.setScheme(fromFont.getScheme()); + toFont.setStrikeout(fromFont.getStrikeout()); + // toFont.setThemeColor(fromFont.getThemeColor()); + toFont.setTypeOffset(fromFont.getTypeOffset()); + toFont.setUnderline(fromFont.getUnderline()); + } + toStyle.setFont(toFont); + } + toStyle.setFillBackgroundColor(fromStyle.getFillBackgroundXSSFColor()); + toStyle.setFillForegroundColor(fromStyle.getFillForegroundXSSFColor()); + toStyle.setFillPattern(fromStyle.getFillPattern()); + toStyle.setHidden(fromStyle.getHidden()); + toStyle.setIndention(fromStyle.getIndention()); + toStyle.setLocked(fromStyle.getLocked()); + toStyle.setRotation(fromStyle.getRotation()); + toStyle.setVerticalAlignment(fromStyle.getVerticalAlignment()); + toStyle.setWrapText(fromStyle.getWrapText()); + return toStyle; + } + + /** + * ȡExcelԪ + * @param row Ԫ + * @param col Ԫк + * @return ExcelԪ + */ + private static XSSFCell getCell(XSSFRow row, int col) { + XSSFCell cell = row.getCell(col); + if(cell==null) + cell = row.createCell(col); + return cell; + } + + + /** + * Excel + */ + public static void main(String[] args) { + System.out.println("BoxReport main"); + FileInputStream input = null; + FileOutputStream output = null; + XSSFWorkbook workbook = null; + try { + String s = "[b][c["; + String[] ss = s.split("[\\[\\]]"); + System.out.println(Arrays.toString(ss)); + /*File file = new File("Z:\\TC_install\\SGXY\\ҳģ0 - .xlsx"); + input = new FileInputStream(file); + workbook = new XSSFWorkbook(input); + XSSFSheet sheet = workbook.getSheet("װϸ"); +// for(int i=0; i progressBar.getMaximum()) + { + percent = 0; + } + + progressBar.setValue(percent); + + percent += 5; + + try + { + Thread.sleep(100); + } + catch (InterruptedException e) + { + continue; + } + } + + dispose(); + } + + public int getProgess() + { + return progressBar.getValue(); + } + + public boolean isRequestCanceling() + { + return requestCanceling; + } + + public void setMaximum(int n) { + progressBar.setMaximum(n); + } + public void setProgess(int n) { + progressBar.setValue(n); + } +} diff --git a/src/com/connor/cust/util/TCUtil.java b/src/com/connor/cust/util/TCUtil.java index 08fbff1..ed98840 100644 --- a/src/com/connor/cust/util/TCUtil.java +++ b/src/com/connor/cust/util/TCUtil.java @@ -294,10 +294,16 @@ public class TCUtil { return dir; } - public static boolean contains(Object[] array, Object str) { + /** + * жǷָ + * @param array Ҫжϵ + * @param target ָ + * @return true򷵻false + */ + public static boolean contains(Object[] array, Object target) { for(Object s : array) { // System.out.println("contains:"+s+"="+str); - if(s.equals(str)) + if(s.equals(target)) return true; } return false; @@ -432,7 +438,7 @@ public class TCUtil { /** * ȡExcelԪ * @param row Ԫ - * @param i Ԫк + * @param col Ԫк * @return ExcelԪ */ public static XSSFCell getCell(XSSFRow row, int col) throws Exception { diff --git a/src/com/teamcenter/rac/commands/cut/CutCommand.java b/src/com/teamcenter/rac/commands/cut/CutCommand.java new file mode 100644 index 0000000..438a7e7 --- /dev/null +++ b/src/com/teamcenter/rac/commands/cut/CutCommand.java @@ -0,0 +1,280 @@ +package com.teamcenter.rac.commands.cut; + +import com.teamcenter.rac.aif.AbstractAIFCommand; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.common.TCUtilities; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMViewRevision; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentTask; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTaskState; +import com.teamcenter.rac.kernel.bom.BOMMarkupHelper; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.Registry; +import com.teamcenter.rac.util.Utilities; +import java.awt.Frame; +import java.text.MessageFormat; +import java.util.ArrayList; + +public class CutCommand extends AbstractAIFCommand { + private Frame parent; + + private ArrayList parentsWithNoAccess = new ArrayList<>(); + + public CutCommand() { + } + + public CutCommand(AIFComponentContext[] paramArrayOfAIFComponentContext, Frame paramFrame, Boolean paramBoolean1, + Boolean paramBoolean2) { + this.parent = paramFrame; + AIFComponentContext[] arrayOfAIFComponentContext = checkInput(this.parent, paramArrayOfAIFComponentContext); + if (arrayOfAIFComponentContext != null) { + boolean bool = showConfirmation(arrayOfAIFComponentContext); + setRunnable((Runnable) new CutDialog(arrayOfAIFComponentContext, this.parent, bool, + paramBoolean2.booleanValue())); + } + } + + public CutCommand(AIFComponentContext[] paramArrayOfAIFComponentContext, Boolean paramBoolean1, + Boolean paramBoolean2) { + AIFComponentContext[] arrayOfAIFComponentContext = checkInput((Frame) null, paramArrayOfAIFComponentContext); + if (arrayOfAIFComponentContext != null) { + boolean bool = showConfirmation(arrayOfAIFComponentContext); + setRunnable((Runnable) new CutDialog(arrayOfAIFComponentContext, bool, paramBoolean2.booleanValue())); + } + } + + public CutCommand(AIFComponentContext paramAIFComponentContext, Frame paramFrame, Boolean paramBoolean1, + Boolean paramBoolean2) { + this(new AIFComponentContext[]{paramAIFComponentContext}, paramFrame, paramBoolean1, paramBoolean2); + } + + public CutCommand(AIFComponentContext paramAIFComponentContext, Boolean paramBoolean1, Boolean paramBoolean2) { + this(new AIFComponentContext[]{paramAIFComponentContext}, paramBoolean1, paramBoolean2); + } + + public CutCommand(AIFComponentContext[] paramArrayOfAIFComponentContext, Boolean paramBoolean1, + Boolean paramBoolean2, Boolean paramBoolean3) { + AIFComponentContext[] arrayOfAIFComponentContext = checkInput((Frame) null, paramArrayOfAIFComponentContext); + if (arrayOfAIFComponentContext != null && paramBoolean1.booleanValue()) { + boolean bool = showConfirmation(arrayOfAIFComponentContext); + setRunnable((Runnable) new CutDialog(arrayOfAIFComponentContext, bool, paramBoolean3.booleanValue())); + } + } + + public CutCommand(AIFComponentContext paramAIFComponentContext, Boolean paramBoolean1, Boolean paramBoolean2, + Boolean paramBoolean3) { + this(new AIFComponentContext[]{paramAIFComponentContext}, paramBoolean1, paramBoolean2, paramBoolean3); + } + + protected AIFComponentContext[] checkInput(Frame paramFrame, + AIFComponentContext[] paramArrayOfAIFComponentContext) { + Registry registry = Registry.getRegistry(this); + ArrayList arrayList1 = new ArrayList<>(); + ArrayList arrayList2 = new ArrayList<>(); + ArrayList arrayList = new ArrayList<>(); + if (paramArrayOfAIFComponentContext == null || paramArrayOfAIFComponentContext.length == 0) { + MessageBox.post(paramFrame, registry.getString("noSelection"), registry.getString("error.TITLE"), 4); + return null; + } + boolean bool = false; + InterfaceAIFComponent interfaceAIFComponent = paramArrayOfAIFComponentContext[0].getComponent(); + if (interfaceAIFComponent instanceof TCComponentBOMViewRevision + || interfaceAIFComponent instanceof com.teamcenter.rac.kernel.TCComponentBOMView) { + TCPreferenceService tCPreferenceService = ((TCSession) interfaceAIFComponent.getSession()) + .getPreferenceService(); + if (tCPreferenceService != null + && tCPreferenceService.isDefinitionExistForPreference("PS_allow_cut_in_pseudofolder") + && tCPreferenceService.getLogicalValue("PS_allow_cut_in_pseudofolder").booleanValue()) + bool = true; + } + String str = "User_Inbox"; + for (int b = 0; b < paramArrayOfAIFComponentContext.length; b++) { + InterfaceAIFComponent interfaceAIFComponent1 = paramArrayOfAIFComponentContext[b].getParentComponent(); + InterfaceAIFComponent interfaceAIFComponent2 = paramArrayOfAIFComponentContext[b].getComponent(); + if (interfaceAIFComponent2 == null) { + MessageBox.post(paramFrame, registry.getString("invalidSelection"), registry.getString("error.TITLE"), 4); + return null; + } + //TODO Զļ͡KWC6_FOLDER;ֹУֻɾ + System.out.println("getType:"+interfaceAIFComponent2.getType()); + if(interfaceAIFComponent2.getType().equals("KWC6_FOLDER")) { + MessageBox.post(paramFrame, "ܶԸ͵ļнмв", registry.getString("error.TITLE"), MessageBox.ERROR); + //Registry.getRegistry(CutCommand.class).getString("foldercut") + return null; + } + + if (interfaceAIFComponent2 instanceof TCComponentBOMViewRevision + && (interfaceAIFComponent1 instanceof TCComponentItemRevision + || (interfaceAIFComponent1 instanceof com.teamcenter.rac.kernel.TCComponentPseudoFolder + && !bool)) + && paramArrayOfAIFComponentContext[b].getContext() != null + && paramArrayOfAIFComponentContext[b].getContext().toString().equals("structure_revisions")) { + MessageBox.post(paramFrame, registry.getString("invalidSelectionBOMViewRev"), + registry.getString("error.TITLE"), 4); + return null; + } + if (interfaceAIFComponent2 instanceof com.teamcenter.rac.kernel.TCComponentBOMView + && (interfaceAIFComponent1 instanceof com.teamcenter.rac.kernel.TCComponentItem + || (interfaceAIFComponent1 instanceof com.teamcenter.rac.kernel.TCComponentPseudoFolder + && !bool)) + && paramArrayOfAIFComponentContext[b].getContext() != null + && paramArrayOfAIFComponentContext[b].getContext().toString().equals("bom_view_tags")) { + MessageBox.post(paramFrame, registry.getString("invalidSelectionBOMView"), + registry.getString("error.TITLE"), 4); + return null; + } + if (interfaceAIFComponent2 instanceof com.teamcenter.rac.kernel.TCComponentPseudoFolder) { + MessageBox + .post(paramFrame, + String.valueOf(Utilities.trimString(registry.getString("invalidSelection"), ".")) + + " -- " + interfaceAIFComponent2 + ".", + registry.getString("command.TITLE"), 4); + return null; + } + if (interfaceAIFComponent2 instanceof com.teamcenter.rac.kernel.TCComponentAssemblyArrangement + && interfaceAIFComponent1 != null && interfaceAIFComponent1 instanceof TCComponentBOMViewRevision + && paramArrayOfAIFComponentContext[b].getContext() != null + && (paramArrayOfAIFComponentContext[b].getContext().toString().equals("TC_Arrangement") + || paramArrayOfAIFComponentContext[b].getContext().toString() + .equals("TC_DefaultArrangement") + || paramArrayOfAIFComponentContext[b].getContext().toString() + .equals("Fnd0AsSavedArrangement"))) { + MessageBox.post(paramFrame, registry.getString("invalidSelectionAssemblyArrangement"), + registry.getString("error.TITLE"), 4); + return null; + } + if (interfaceAIFComponent2 instanceof com.teamcenter.rac.kernel.TCComponentIDCLine + && interfaceAIFComponent1 instanceof com.teamcenter.rac.kernel.TCComponentIDCLine) { + MessageBox.post(paramFrame, registry.getString("invalidSelection"), registry.getString("command.TITLE"), + 1); + return null; + } + if (interfaceAIFComponent2 instanceof TCComponentBOMLine) { + if (!BOMMarkupHelper.allowStructureEdit(AIFUtility.getActiveDesktop().getShell(), + (TCComponentBOMLine) interfaceAIFComponent2)) + return null; + try { + TCComponentBOMViewRevision tCComponentBOMViewRevision = ((TCComponentBOMLine) interfaceAIFComponent1) + .getBOMViewRevision(); + if (tCComponentBOMViewRevision != null) { + if (!arrayList.contains(tCComponentBOMViewRevision)) { + tCComponentBOMViewRevision.clearCache("is_modifiable"); + arrayList.add(tCComponentBOMViewRevision); + } + arrayList2.add(paramArrayOfAIFComponentContext[b]); + continue; + } + } catch (TCException tCException) { + tCException.printStackTrace(); + } + } else if (interfaceAIFComponent2 instanceof com.teamcenter.rac.kernel.TCComponentTaskInBox) { + TCComponent tCComponent = (TCComponent) paramArrayOfAIFComponentContext[b].getParentComponent(); + if (tCComponent instanceof com.teamcenter.rac.kernel.TCComponentTaskInBox + || tCComponent.getType().equals(str)) { + MessageBox + .post(paramFrame, + String.valueOf(Utilities.trimString(registry.getString("invalidSelection"), ".")) + + " -- " + interfaceAIFComponent2 + ".", + registry.getString("command.TITLE"), 4); + return null; + } + } else if (interfaceAIFComponent1 instanceof com.teamcenter.rac.kernel.TCComponentTaskInBox) { + boolean bool1 = true; + if (interfaceAIFComponent2 instanceof TCComponentTask) + try { + if (((TCComponentTask) interfaceAIFComponent2).getState() == TCTaskState.COMPLETED) + bool1 = false; + } catch (TCException tCException) { + } + if (bool1) { + MessageBox + .post(paramFrame, + String.valueOf(Utilities.trimString(registry.getString("invalidSelection"), ".")) + + " -- " + interfaceAIFComponent2 + ".", + registry.getString("command.TITLE"), 4); + return null; + } + } else if (interfaceAIFComponent2.getType().equals(str)) { + TCComponent tCComponent = (TCComponent) paramArrayOfAIFComponentContext[b].getParentComponent(); + if (tCComponent == null) { + MessageBox + .post(paramFrame, + String.valueOf(Utilities.trimString(registry.getString("invalidSelection"), ".")) + + " -- " + interfaceAIFComponent2 + ".", + registry.getString("command.TITLE"), 4); + return null; + } + } + if (interfaceAIFComponent2 instanceof com.teamcenter.rac.kernel.TCComponentArchitecture + && interfaceAIFComponent1 instanceof TCComponentItemRevision + && paramArrayOfAIFComponentContext[b].getContext().equals(TCUtilities.ARCHITECTURE_RELATION)) { + try { + TCComponentItemRevision tCComponentItemRevision = (TCComponentItemRevision) paramArrayOfAIFComponentContext[b] + .getParentComponent(); + TCComponentItemRevision[] arrayOfTCComponentItemRevision = TCUtilities + .getAllContextRevisions(tCComponentItemRevision, null); + Utilities.addElements(arrayList1, + (Object[]) AIFComponentContext.getContexts( + (InterfaceAIFComponent[]) arrayOfTCComponentItemRevision, + paramArrayOfAIFComponentContext[b].getComponent(), + paramArrayOfAIFComponentContext[b].getContext()), + true); + } catch (TCException tCException) { + } + } else { + arrayList1.add(paramArrayOfAIFComponentContext[b]); + } + continue; + } + if (!arrayList.isEmpty()) + try { + TCComponentType.getTCPropertiesSet(arrayList, new String[]{"is_modifiable"}); + for (AIFComponentContext aIFComponentContext : arrayList2) { + InterfaceAIFComponent interfaceAIFComponent1 = aIFComponentContext.getParentComponent(); + TCComponentBOMViewRevision tCComponentBOMViewRevision = ((TCComponentBOMLine) interfaceAIFComponent1) + .getBOMViewRevision(); + if (tCComponentBOMViewRevision != null && !tCComponentBOMViewRevision.okToModify()) { + if (!this.parentsWithNoAccess.contains(tCComponentBOMViewRevision)) + this.parentsWithNoAccess.add(tCComponentBOMViewRevision); + continue; + } + arrayList1.add(aIFComponentContext); + } + } catch (TCException tCException) { + tCException.printStackTrace(); + } + if (this.parentsWithNoAccess.size() > 0) { + StringBuffer stringBuffer = new StringBuffer(); + String str1 = ", "; + for (byte b1 = 0; b1 < this.parentsWithNoAccess.size(); b1++) { + if (b1 == this.parentsWithNoAccess.size() - 1) + str1 = ""; + stringBuffer.append(this.parentsWithNoAccess.get(b1)); + stringBuffer.append(str1); + } + MessageBox.post(paramFrame, + String.valueOf(MessageFormat.format(registry.getString("inaccessibleBOMViewRev"), + new Object[]{stringBuffer.toString()})) + " " + registry.getString("acessDenied"), + registry.getString("error.TITLE"), 4); + } + return arrayList1.isEmpty() + ? null + : arrayList1.toArray(new AIFComponentContext[arrayList1.size()]); + } + + private boolean showConfirmation(AIFComponentContext[] paramArrayOfAIFComponentContext) { + if (paramArrayOfAIFComponentContext == null) + return true; + Registry registry = Registry.getRegistry(this); + int i = registry.getInt("confirmationLimit", 10); + return (paramArrayOfAIFComponentContext.length > i); + } +} \ No newline at end of file diff --git a/src/com/teamcenter/rac/commands/cut/cut_locale_zh_CN.properties b/src/com/teamcenter/rac/commands/cut/cut_locale_zh_CN.properties new file mode 100644 index 0000000..d0260d9 --- /dev/null +++ b/src/com/teamcenter/rac/commands/cut/cut_locale_zh_CN.properties @@ -0,0 +1 @@ +foldercut=\u4E0D\u80FD\u5BF9\u8BE5\u7C7B\u578B\u7684\u6587\u4EF6\u5939\u8FDB\u884C\u526A\u5207\u64CD\u4F5C \ No newline at end of file