1.装箱单报表功能提测

2.新增修改分类及item_id功能
master
李冬阳 1 year ago
parent e85afb0702
commit 49672d3fa1

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/fastjson-1.2.78.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>

@ -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

@ -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

@ -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

@ -0,0 +1 @@
foldercut=\u4E0D\u80FD\u5BF9\u8BE5\u7C7B\u578B\u7684\u6587\u4EF6\u5939\u8FDB\u884C\u526A\u5207\u64CD\u4F5C

@ -3,4 +3,5 @@ output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/
icons/,\
lib/fastjson-1.2.78.jar

Binary file not shown.

@ -2,36 +2,63 @@
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<extension point="org.eclipse.ui.commands">
<command
name="设置装箱单"
id="XYBOMHandler">
</command>
<command
name="装箱单报表"
id="BoxReportHandler">
</command>
<command
name="修改分类及ItemID"
id="EditClassificationHandler">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<extension point="org.eclipse.ui.handlers">
<handler
class="com.connor.cust.box.XYBOMHandler"
commandId="XYBOMHandler">
</handler>
<handler
class="com.connor.cust.box.BoxReportHandler"
commandId="BoxReportHandler">
</handler>
<handler
class="com.connor.cust.classification.EditClassificationHandler"
commandId="EditClassificationHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
<!-->
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
id="com.connor.cust.menus.sampleMenu"
label="Sample Menu"
mnemonic="M">
<command
commandId="com.connor.cust.commands.sampleCommand"
id="com.connor.cust.menus.sampleCommand"
mnemonic="S">
<extension point="org.eclipse.ui.menus">
<!--><-->
<menuContribution locationURI="menu:cn.net.connor.kwc.plm.seconddevelop.menus?after=additions">
<command commandId="BoxReportHandler" id="BoxReportHandler" label="装箱单报表">
<visibleWhen checkEnabled="true">
<and>
<reference definitionId="com.teamcenter.rac.pse.inMainView"/>
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals value="BoxReportHandler"/>
</iterate>
</not>
</with>
</and>
</visibleWhen>
</command>
</menu>
</menuContribution><-->
<command commandId="EditClassificationHandler" id="EditClassificationHandler" label="修改分类及ItemID">
<visibleWhen checkEnabled="true">
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals value="EditClassificationHandler"/>
</iterate>
</not>
</with>
</visibleWhen>
</command>
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command commandId="XYBOMHandler" id="XYBOMHandler" label="设置装箱单">
<visibleWhen checkEnabled="true">

@ -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);

@ -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<String[]> datas;
private HashMap<String, Integer> 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<String[]>() {
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<COL_CNT; i++) {
if(i == 2)
continue;
cell = TCUtil.getCell(xssfrow, i);
cell.setCellValue(data[i]);
}
row ++;
rbox ++;
}
}else {
//多页
XSSFRow xssfrow = TCUtil.getRow(sheet, 0);
XSSFCell cell = TCUtil.getCell(xssfrow, 9);
cell.setCellValue(topid);
XSSFPrintSetup ps = sheet.getPrintSetup();
for(int i=0; i<boxMap.size(); i++) {
XSSFSheet sheet2 = workbook.cloneSheet(sheet0);
workbook.setSheetOrder(sheet2.getSheetName(), sheet0+i+1);
XSSFPrintSetup ps2 = sheet2.getPrintSetup();
ps2.setLandscape(ps.getLandscape());
ps2.setPaperSize(ps.getPaperSizeEnum());
}
int row = 0, rbox = 0, pbox = 0;
for(String[] data : datas) {
int box = Integer.parseInt(data[COL_CNT]);
if(box != pbox) {
//换箱号
sheet = workbook.getSheetAt(sheet0 + box - 1);
row = TITLE_CNT;
rbox = 1;
pbox = box;
xssfrow = TCUtil.getRow(sheet, 0);
cell = TCUtil.getCell(xssfrow, 5);
String[] boxno = PlmLocale.getString("boxno").split(";");
cell.setCellValue(boxno[0] + getNumStr(box) + boxno[1]);
}
xssfrow = TCUtil.getRow(sheet, row);
cell = TCUtil.getCell(xssfrow, 0);
cell.setCellValue(rbox);
for(int i=1; i<COL_CNT; i++) {
if(i == 2)
continue;
cell = TCUtil.getCell(xssfrow, i);
cell.setCellValue(data[i]);
}
row ++;
rbox ++;
}
}
output = new FileOutputStream(file.getPath());
workbook.write(output);
workbook.close();
output.close();
input.close();
if(directory.exists())
directory.delete();
file.renameTo(directory);
reporter.requestCanceling();
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("exportsuccess"), "INFO", MessageBox.INFORMATION);
} catch (Exception e1) {
e1.printStackTrace();
reporter.requestCanceling();
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("err") + e1.getMessage(), "ERROR", MessageBox.ERROR);
}finally {
try {
if(workbook != null)
workbook.close();
if(output != null)
output.close();
if(input != null)
input.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}.start();
}
/**
* BOM
* @param contexts BOM.getChildren()
* @param pid item_id
*/
private void recycleBom(AIFComponentContext[] contexts, String pid) throws Exception {
for(AIFComponentContext c : contexts) {
TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent();
String id = bom.getProperty("bl_item_item_id");
String box = bom.getProperty("XYBOX");
if(!box.isEmpty()) {
TCComponentItemRevision rev = bom.getItemRevision();
String[] data = new String[COL_CNT + 1];
data[0] = "";
data[1] = id;
data[2] = "";
data[3] = rev.getProperty("object_name");
data[4] = TCUtil.getItemRevisionMasterForm(rev).getProperty("item_id");
data[5] = pid;
data[6] = bom.getProperty("Detail_ID");
data[7] = bom.getProperty("bl_quantity");
data[8] = "";
data[9] = box;
if(boxMap.containsKey(box))
boxMap.put(box, boxMap.get(box) + 1);
else
boxMap.put(box, 1);
datas.add(data);
}
recycleBom(bom.getChildren(), id);
}
}
/**
*
* @param num
*/
private String getNumStr(int num) throws Exception {
String[] nums = PlmLocale.getString("numstr").split(";");
StringBuilder numstr = new StringBuilder("");
if(num < 11) {
numstr.append(nums[num]);
}else if(num < 20) {
numstr.append(nums[10]).append(nums[num%10]);
}else if(num%10 == 0) {
numstr.append(nums[num/10]).append(nums[10]);
}else {
numstr.append(nums[num/10]).append(nums[10]).append(nums[num%10]);
}
return numstr.toString();
}
}

@ -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

@ -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

@ -0,0 +1,44 @@
package com.connor.cust.classification;
public class ClassPropBean {
private String id;
private String name;
private String value;
public ClassPropBean(String id, String name, String value) {
super();
this.id = id;
this.name = name;
this.value = value;
}
public String getId() {
return id;
}
@Override
public String toString() {
return name;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

@ -0,0 +1,42 @@
package com.connor.cust.classification;
/**
* @copyRight
* @author E-mail:hub@connor.net.cn
* @date 2017-7-3 11:47:03
* @version v1.0
* @parameter
* @since
* @return
*/
public class ClassProperty {
private int propertyID;
private String value;
public ClassProperty() {
}
public ClassProperty(int propertyID, String value) {
this.propertyID = propertyID;
this.value = value;
}
public int getPropertyID() {
return propertyID;
}
public void setPropertyID(int propertyID) {
this.propertyID = propertyID;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

@ -0,0 +1,552 @@
package com.connor.cust.classification;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.connor.cust.box.PlmLocale;
import com.connor.cust.util.TCUtil;
//import org.apache.axiom.om.OMAbstractFactory;
//import org.apache.axiom.om.OMElement;
//import org.apache.axiom.om.OMFactory;
//import org.apache.axiom.om.OMNamespace;
//import org.apache.axis2.AxisFault;
//import org.apache.axis2.addressing.EndpointReference;
//import org.apache.axis2.client.Options;
//import org.apache.axis2.client.ServiceClient;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCClassificationService;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCSession;
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 net.sf.json.JSONArray;
/**
*
*/
public class EditClassificationDialog extends AbstractAIFDialog {
private static final long serialVersionUID = 1L;
// private AbstractAIFApplication app;
private TCSession session;
private String address;
// private TCComponent target;
private Map<String, JComponent> 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<ICSProperty, ICSPropertyDescription> displayMap = new LinkedHashMap<ICSProperty, ICSPropertyDescription>();
propMap = new HashMap<String, JComponent>();
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<ICSProperty, ICSPropertyDescription> 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<Object> list = new ArrayList<>();
if (lov != null) {
String[] keys = lov.getKeys();
JAutoCompleteComboBox combo = new JAutoCompleteComboBox();
// JComboBox<ClassPropBean> combo = new JComboBox<ClassPropBean>();
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<ClassProperty> 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<ClassPropBean>) 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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body><DeleteClass xmlns=\"http://tempuri.org/\"><icoPuid>"
+ icoPuid
+ "</icoPuid></DeleteClass></soap:Body></soap:Envelope>";
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("<DeleteClassResult>")>0) {
soapRequestData = soapRequestData.substring(soapRequestData.indexOf("<DeleteClassResult>") + 19, soapRequestData.indexOf("</DeleteClassResult>"));
}
return statusCode+"&&"+soapRequestData;
}
private String sendToClass(String wsoPUID, String classID, String json) throws Exception {
String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body><SendToClass xmlns=\"http://tempuri.org/\">"
+ "<wsoPuiid>"+wsoPUID+"</wsoPuiid>"
+ "<classID>"+classID+"</classID>"
+ "<JsonContainer>"+json+"</JsonContainer></SendToClass></soap:Body></soap:Envelope>";
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("<SendToClassResult>")>0) {
soapRequestData = soapRequestData.substring(soapRequestData.indexOf("<SendToClassResult>") + 19, soapRequestData.indexOf("</SendToClassResult>"));
}
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<ClassProperty> 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;
}*/
}

@ -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;
}
}

@ -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();
}
}
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,159 @@
package com.connor.cust.util;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import com.teamcenter.rac.aif.AbstractAIFDialog;
@SuppressWarnings("serial")
public class ProgressReporterDialog extends AbstractAIFDialog
{
private JLabel messageLabel;
private JProgressBar progressBar;
private boolean requestCanceling;
private int percent;
public ProgressReporterDialog(String title)
{
//super(false);
setLayout(new BorderLayout());
setAlwaysOnTop(true);
initializeComponents();
//setTitle(title);
registerComponentsListeners();
addComponents();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
public ProgressReporterDialog(Dialog parent, String title)
{
super(parent, false);
setLayout(new BorderLayout());
// setAlwaysOnTop(true);
setDefaultCloseOperation(AbstractAIFDialog.DO_NOTHING_ON_CLOSE);
initializeComponents();
// setTitle(title);
registerComponentsListeners();
addComponents();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
public ProgressReporterDialog(Frame parent, String title)
{
super(parent, false);
setLayout(new BorderLayout());
// setAlwaysOnTop(true);
setDefaultCloseOperation(AbstractAIFDialog.DO_NOTHING_ON_CLOSE);
initializeComponents();
// setTitle(title);
registerComponentsListeners();
addComponents();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
private void initializeComponents()
{
messageLabel = new JLabel(" ", JLabel.LEFT);
progressBar = new JProgressBar();
}
private void registerComponentsListeners()
{
}
private void addComponents()
{
add(messageLabel, BorderLayout.NORTH);
add(progressBar, BorderLayout.SOUTH);
}
public void centerToClientScreen()
{
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = screen.width - getWidth();
int y = screen.height - getHeight();
setLocation(x / 2, y / 2);
}
public void reportProgressMessage(String message)
{
messageLabel.setText(message);
}
public void setProgressPercent(int percent)
{
this.percent = percent;
}
public void requestCanceling()
{
requestCanceling = true;
}
public void run()
{
pack();
setSize(400, getHeight());
centerToClientScreen();
setVisible(true);
while (!requestCanceling)
{
if(percent > 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);
}
}

@ -294,10 +294,16 @@ public class TCUtil {
return dir;
}
public static boolean contains(Object[] array, Object str) {
/**
*
* @param array
* @param target
* @return truefalse
*/
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 {

@ -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<TCComponentBOMViewRevision> 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<AIFComponentContext> arrayList1 = new ArrayList<>();
ArrayList<AIFComponentContext> arrayList2 = new ArrayList<>();
ArrayList<TCComponentBOMViewRevision> 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.<AIFComponentContext>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);
}
}

@ -0,0 +1 @@
foldercut=\u4E0D\u80FD\u5BF9\u8BE5\u7C7B\u578B\u7684\u6587\u4EF6\u5939\u8FDB\u884C\u526A\u5207\u64CD\u4F5C
Loading…
Cancel
Save