commit
79ab5ea130
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry exported="true" kind="lib" path="lib/ojdbc8.jar"/>
|
||||
<classpathentry kind="lib" path="lib/mssql-jdbc-7.0.0.jre8.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="lib/swingx-1.6.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-4.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/dom4j-2.1.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-examples-3.7-20101029.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-ooxml-3.7-20101029.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-ooxml-schemas-3.7-20101029.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.connor.jd</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -0,0 +1,8 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@ -0,0 +1,20 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Jd
|
||||
Bundle-SymbolicName: com.connor.jd;singleton:=true
|
||||
Bundle-Version: 1.0.0
|
||||
Bundle-Vendor: CONNOR
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
com.teamcenter.rac.kernel;bundle-version="13000.1.0",
|
||||
com.teamcenter.rac.util;bundle-version="13000.1.0",
|
||||
com.teamcenter.rac.common;bundle-version="13000.1.0",
|
||||
com.teamcenter.rac.aifrcp;bundle-version="13000.1.0",
|
||||
org.eclipse.core.runtime;bundle-version="3.15.100",
|
||||
TcSoaStructureManagementLoose;bundle-version="13000.1.0",
|
||||
org.apache.poi.39;bundle-version="3.9.0"
|
||||
Automatic-Module-Name: com.connor.jd
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ClassPath: lib/ojdbc8.jar,
|
||||
.,
|
||||
lib/swingx-1.6.1.jar,
|
||||
lib/mssql-jdbc-7.0.0.jre8.jar
|
||||
@ -0,0 +1 @@
|
||||
/com/
|
||||
@ -0,0 +1,9 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = plugin.xml,\
|
||||
META-INF/,\
|
||||
.,\
|
||||
icons/,\
|
||||
lib/ojdbc8.jar,\
|
||||
lib/swingx-1.6.1.jar,\
|
||||
lib/mssql-jdbc-7.0.0.jre8.jar
|
||||
|
After Width: | Height: | Size: 332 B |
|
After Width: | Height: | Size: 526 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<category
|
||||
id="test.commands.category"
|
||||
name="Sample Category">
|
||||
</category>
|
||||
<command
|
||||
categoryId="test.commands.category"
|
||||
name="图号申请"
|
||||
id="DrawingNoApplyHandler">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="com.connor.jingdiao.handlers.DrawingNoApplyHandler"
|
||||
commandId="DrawingNoApplyHandler">
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.bindings">
|
||||
<key
|
||||
commandId="test.commands.sampleCommand"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
contextId="org.eclipse.ui.contexts.window"
|
||||
sequence="M1+6">
|
||||
</key>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
|
||||
<menu
|
||||
id="com.connor.jingdiao.menus"
|
||||
label="精雕菜单"
|
||||
mnemonic="M">
|
||||
<command
|
||||
commandId="DrawingNoApplyHandler"
|
||||
mnemonic="S">
|
||||
</command>
|
||||
</menu>
|
||||
</menuContribution>
|
||||
<menuContribution
|
||||
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
|
||||
<toolbar
|
||||
id="test.toolbars.sampleToolbar">
|
||||
<command
|
||||
id="test.toolbars.sampleCommand"
|
||||
commandId="test.commands.sampleCommand"
|
||||
icon="icons/sample.png"
|
||||
tooltip="Say hello world">
|
||||
</command>
|
||||
</toolbar>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
</plugin>
|
||||
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
|
||||
<extension point="org.eclipse.ui.commands">
|
||||
<command name="查询物料库存信息" id="erpIntegrationHandler"/>
|
||||
<command name="派生中间件" id="deriveCenterHandler"/>
|
||||
<command name="派生MBOM产品" id="deriveMBOMHandler"/>
|
||||
<command name="图号申请" id="DrawingNoApplyHandler"/>
|
||||
<!-- <command name="申请物料编码" id="WlbmApplyHandler"/> -->
|
||||
<command id="CodeApplyHandler" name="物料编码申请"/>
|
||||
<!--command name="DBOM转EBOM" categoryId="com.connor.ml.tcm.outfile.commands.category" id="DBOMtoEBOM"> </command!-->
|
||||
<command name="依据设计创建物料" id="DesignToPartHandler"/>
|
||||
<command name="标准化审核" id="StandardHandler"/>
|
||||
<command name="用户登录设置" id="LoginIPSetHandler"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.ui.handlers">
|
||||
<handler class="com.connor.jingdiao.handlers.DrawingNoApplyHandler" commandId="DrawingNoApplyHandler"/>
|
||||
<!-- <handler class="com.connor.jingdiao.handlers.WlbmApplyHandler" commandId="WlbmApplyHandler"/> -->
|
||||
<!--handler class="com.connor.ml.tcm.outfile.ML_01.DbomTransitionToEbomHandler" commandId="DBOMtoEBOM"> </handler!-->
|
||||
<handler commandId="CodeApplyHandler" class="com.connor.jingdiao.handlers.CodeApplyHandler"/>
|
||||
<handler commandId="DesignToPartHandler" class="com.connor.jingdiao.handlers.DesignToPartHandler"/>
|
||||
<handler commandId="StandardHandler" class="com.connor.jingdiao.handlers.StandardHandler"/>
|
||||
<handler commandId="LoginIPSetHandler" class="com.connor.jingdiao.handlers.LoginIPSetHandler"/>
|
||||
<handler class="com.connor.jd.erp.erpIntegrationHandler" commandId="erpIntegrationHandler"/>
|
||||
<handler class="com.connor.jd.derive.deriveCenterHandler" commandId="deriveCenterHandler"/>
|
||||
<handler class="com.connor.jd.derive.deriveMBOMHandler" commandId="deriveMBOMHandler"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.ui.menus">
|
||||
<menuContribution locationURI="menu:com.connor.plm.test.menus.sampleMenu?after=additions">
|
||||
<command commandId="DrawingNoApplyHandler" style="push"> </command>
|
||||
<command commandId="DesignToPartHandler" style="push"> </command>
|
||||
<!-- <command commandId="WlbmApplyHandler" style="push">
|
||||
</command>
|
||||
|
||||
BOM转换 -->
|
||||
<!--command commandId="DBOMtoEBOM" style="push"/!-->
|
||||
<command commandId="CodeApplyHandler" style="push"> </command>
|
||||
<command commandId="StandardHandler" style="push"> </command>
|
||||
<command commandId="erpIntegrationHandler" style="push"> </command>
|
||||
<command commandId="deriveCenterHandler" style="push"> </command>
|
||||
<command commandId="deriveMBOMHandler" style="push"> </command>
|
||||
<command commandId="LoginIPSetHandler" style="push"> </command>
|
||||
</menuContribution>
|
||||
<!--menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
|
||||
<menu id="com.connor.jingdiao.menus" label="精雕菜单">
|
||||
<command commandId="DrawingNoApplyHandler" mnemonic="S">
|
||||
</command>
|
||||
</menu>
|
||||
</menuContribution-->
|
||||
</extension>
|
||||
</plugin>
|
||||
@ -0,0 +1,49 @@
|
||||
package com.connor.jd.erp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class erpIntegrationHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
// TODO Auto-generated method stub
|
||||
// 获取当前系统活动
|
||||
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
// 获取tc当前选择的操作
|
||||
InterfaceAIFComponent target = app.getTargetComponent();
|
||||
if (target instanceof TCComponentItemRevision) {
|
||||
try {
|
||||
String[] value = session.getPreferenceService().getStringValues("JD_WLKCCXLX");
|
||||
List<String> list = new ArrayList<>(Arrays.asList(value));
|
||||
if (list.contains(((TCComponentItemRevision) target).getStringProperty("object_type"))) {
|
||||
TCComponentItemRevision f = (TCComponentItemRevision) target;
|
||||
erpIntegrationOpertaion operation = new erpIntegrationOpertaion(session, f);
|
||||
session.queueOperation(operation);
|
||||
} else {
|
||||
MessageBox.post("请选择物料执行操作", "提示", MessageBox.INFORMATION);
|
||||
return null;
|
||||
}
|
||||
} catch (TCException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.connor.jd.handlers;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
|
||||
public class SampleHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
|
||||
MessageDialog.openInformation(
|
||||
window.getShell(),
|
||||
"Jd",
|
||||
"Hello, Eclipse world");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,242 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.connor.jingdiao.util.TCUtil;
|
||||
import com.connor.ml.tcm.outfile.util.MethodUtil;
|
||||
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCAccessControlService;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemType;
|
||||
import com.teamcenter.rac.kernel.TCProperty;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class DesignToPartDialog extends AbstractAIFDialog {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private TCSession session;
|
||||
private JButton exportBtn;
|
||||
private JButton closeBtn;
|
||||
private JTable impTable;
|
||||
private DefaultTableModel impModel;
|
||||
private ArrayList<TCComponentItemRevision> list;
|
||||
private HashMap<String, Integer> map;
|
||||
|
||||
// public DrawingNoApplyDialog(TCSession session, String tables[], String[] options, String[] sqlOptions, InterfaceAIFComponent[] targets) throws Exception {
|
||||
public DesignToPartDialog(TCSession session, ArrayList<String[]> options, InterfaceAIFComponent[] targets) throws Exception {
|
||||
super(AIFUtility.getActiveDesktop());
|
||||
this.session = session;
|
||||
list = new ArrayList<>();
|
||||
map = new HashMap<>();
|
||||
setTitle("创建物料");
|
||||
|
||||
exportBtn = new JButton("创建");
|
||||
closeBtn = new JButton("关闭");
|
||||
JPanel btnPanel = new JPanel(new FlowLayout());
|
||||
btnPanel.add(exportBtn);
|
||||
btnPanel.add(closeBtn);
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.add(BorderLayout.SOUTH, btnPanel);
|
||||
|
||||
ArrayList<String[]> props = new ArrayList<>();
|
||||
// String[] tableHeader = new String[] { "序号", "itemID", "名称", "版本", "加工类型", "产品分类码", "课题号", "配置码", "部件码", "图纸类型", "新图号" };
|
||||
String[] tables = options.get(0);
|
||||
String[] tableHeader = new String[tables.length + 1];
|
||||
tableHeader[0] = "序号";
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
String[] split = tables[i].split("=");
|
||||
props.add(split[1].split("\\."));
|
||||
tableHeader[i + 1] = split[0];
|
||||
map.put(split[1], i + 1);
|
||||
}
|
||||
impModel = new DefaultTableModel(tableHeader, 0);
|
||||
impTable = new JTable() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
impTable.getTableHeader().setReorderingAllowed(false);
|
||||
impTable.setFillsViewportHeight(true);
|
||||
// impTable.setEnabled(false);
|
||||
impTable.setEnabled(true);
|
||||
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
impTable.setModel(impModel);
|
||||
for (int i = 1; i < impModel.getColumnCount(); i++)
|
||||
impTable.getColumnModel().getColumn(i).setPreferredWidth(150);
|
||||
int r = 1;
|
||||
TCAccessControlService acs = session.getTCAccessControlService();
|
||||
TCComponent[] user = new TCComponent[]{ session.getUser(), session.getGroup(), session.getRole() };
|
||||
StringBuilder msg = new StringBuilder("");
|
||||
StringBuilder msg2 = new StringBuilder("");
|
||||
for (InterfaceAIFComponent t : targets) {
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision) t;
|
||||
if (rev.getProperty("j6_drawingno").isEmpty()) {
|
||||
msg.append(rev).append("、");
|
||||
continue;
|
||||
}
|
||||
if(!acs.checkAccessorsPrivilege(user, rev, "WRITE")) {
|
||||
msg2.append(rev).append("、");
|
||||
continue;
|
||||
}
|
||||
TCComponentItem item = rev.getItem();
|
||||
int size = props.size() + 1;
|
||||
Object[] data = new Object[size];
|
||||
data[0] = r++;
|
||||
for (int i = 1; i < size; i++) {
|
||||
String[] ss = props.get(i-1);
|
||||
if (ss[0].equals("item")) {
|
||||
data[i] = item.getStringProperty(ss[1]);
|
||||
} else {
|
||||
data[i] = rev.getStringProperty(ss[1]);
|
||||
}
|
||||
}
|
||||
|
||||
impModel.addRow(data);
|
||||
list.add(rev);
|
||||
}
|
||||
if (targets.length > list.size()) {
|
||||
StringBuilder m = new StringBuilder("所选对象:\n");
|
||||
if(msg.length()>0) {
|
||||
m.append(msg.deleteCharAt(msg.length() - 1)).append(" 图号为空,无法创建物料!\n");
|
||||
}
|
||||
if(msg2.length()>0) {
|
||||
m.append(msg2.deleteCharAt(msg2.length() - 1)).append(" 无编辑权限,无法创建物料!");
|
||||
}
|
||||
MessageBox.post(AIFUtility.getActiveDesktop(), m.toString(), "警告", MessageBox.WARNING);
|
||||
}
|
||||
if (list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
JScrollPane tablePanel = new JScrollPane(impTable);
|
||||
|
||||
addActionListener(options);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(BorderLayout.NORTH, topPanel);
|
||||
add(BorderLayout.CENTER, tablePanel);
|
||||
pack();
|
||||
setSize(new Dimension(1400, 700));
|
||||
setDefaultLookAndFeelDecorated(true);
|
||||
Dimension screen = getToolkit().getScreenSize();
|
||||
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
|
||||
// setAlwaysOnTop(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void addActionListener(ArrayList<String[]> options) {
|
||||
exportBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
exportBtn.setEnabled(false);
|
||||
closeBtn.setEnabled(false);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
TCComponentItemRevision rev = list.get(i);
|
||||
TCComponentItem item = rev.getItem();
|
||||
TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
|
||||
String type = "", dtype = item.getType(), ptype = rev.getProperty("j6_processtype");
|
||||
String t = dtype+";"+ptype+"=";
|
||||
for(String ss : options.get(1)) {
|
||||
if(ss.startsWith(t)) {
|
||||
type = ss.substring(ss.indexOf("=")+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(type.isEmpty())
|
||||
continue;
|
||||
AIFComponentContext[] rfs = rev.getChildren("representation_for")[0].getComponent().getChildren();
|
||||
if(rfs!=null && rfs.length>0) {
|
||||
int choose = JOptionPane.showOptionDialog(DesignToPartDialog.this, rev+" 下已存在物料,是否继续创建?", "提示",
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] {"是","否"}, "结束操作");
|
||||
if(choose==1)
|
||||
continue;
|
||||
}
|
||||
TCComponentItemType typec = (TCComponentItemType)session.getTypeComponent(type);
|
||||
TCComponentItem pitem = typec.create(typec.getNewID(), null, type, item.getProperty("object_name"), "", null);
|
||||
TCComponentItemRevision prev = pitem.getLatestItemRevision();
|
||||
TCComponentForm pform = TCUtil.getItemRevisionMasterForm(prev);
|
||||
t = dtype+";"+type+"@@";
|
||||
for(String s : options.get(2)) {
|
||||
if(!s.startsWith(t))
|
||||
continue;
|
||||
String[] ss = s.substring(s.indexOf("@@")+2).split(";");
|
||||
for(String s1 : ss) {
|
||||
String[] ps = s1.split("=");
|
||||
setProp(ps, pitem, prev, pform, item, rev, form);
|
||||
}
|
||||
break;
|
||||
}
|
||||
rev.add("representation_for", prev);
|
||||
}
|
||||
MessageBox.post(DesignToPartDialog.this, "物料创建完成!", "提示", MessageBox.INFORMATION);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
MessageBox.post(DesignToPartDialog.this, "错误:" + e1.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
}
|
||||
exportBtn.setEnabled(true);
|
||||
closeBtn.setEnabled(true);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
});
|
||||
closeBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setProp(String[] ps, TCComponentItem pitem, TCComponentItemRevision prev, TCComponentForm pform,
|
||||
TCComponentItem item, TCComponentItemRevision rev, TCComponentForm form) throws Exception {
|
||||
String[] p1 = ps[0].split("\\."), p2 = ps[1].split("\\.");
|
||||
Object val = "";
|
||||
if(p2.length<2) {
|
||||
val = p2[0];
|
||||
}else if(p2[0].equals("item")) {
|
||||
val = MethodUtil.getTCPropertyValue(item, p2[1]);
|
||||
//val = item.getProperty(p2[1]);
|
||||
}else if(p2[0].equals("rev")) {
|
||||
val = MethodUtil.getTCPropertyValue(rev, p2[1]);
|
||||
//val = rev.getProperty(p2[1]);
|
||||
}else if(p2[0].equals("revmaster")) {
|
||||
val = MethodUtil.getTCPropertyValue(form, p2[1]);
|
||||
//val = form.getProperty(p2[1]);
|
||||
}
|
||||
System.out.println("val:"+val);
|
||||
if(p1[0].equals("item")) {
|
||||
MethodUtil.setTCPropertyValue(pitem, p1[1], val);
|
||||
}else if(p1[0].equals("rev")) {
|
||||
MethodUtil.setTCPropertyValue(prev, p1[1], val);
|
||||
}else if(p1[0].equals("revmaster")) {
|
||||
MethodUtil.setTCPropertyValue(pform, p1[1], val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
|
||||
import com.teamcenter.rac.aif.AIFDesktop;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
//创建常规文件夹结构
|
||||
public class DesignToPartHandler extends AbstractHandler implements IHandler{
|
||||
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
System.out.println("DesignToPartHandler");
|
||||
TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession();
|
||||
AIFDesktop desktop = AIFUtility.getActiveDesktop();
|
||||
try {
|
||||
String[] types = session.getPreferenceService().getStringValues("JD6_Part_Design_Type");
|
||||
if(types == null || types.length == 0) {
|
||||
MessageBox.post(desktop, "首选项JD6_Part_Design_Type配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
InterfaceAIFComponent[] targets = AIFUtility.getCurrentApplication().getTargetComponents();
|
||||
for(InterfaceAIFComponent t : targets) {
|
||||
if(t instanceof TCComponentItemRevision) {
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision) t;
|
||||
if(rev.getProperty("j6_drawingno").isEmpty()) {
|
||||
MessageBox.post(desktop, "选中对象"+t+"未申请图号,无法创建物料!", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
String type = rev.getItem().getType()+";";
|
||||
boolean no = true;
|
||||
for(String s : types) {
|
||||
if(s.startsWith(type)) {
|
||||
no = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(no) {
|
||||
MessageBox.post(desktop, "选中对象"+t+"不是设计版本类型,无法创建物料!", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
MessageBox.post(desktop, "选中对象"+t+"不是设计版本类型,无法创建物料!", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
ArrayList<String[]> list = new ArrayList<>();
|
||||
String[] ops = new String[] { "Jd_Code_Table_Design", "JD6_Part_Design_Type", "JD6_Part_Design_Copy_Properties" };
|
||||
for(String name : ops) {
|
||||
String[] options = session.getPreferenceService().getStringValues(name);
|
||||
if(options == null || options.length == 0) {
|
||||
MessageBox.post(desktop, "首选项"+name+"配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
list.add(options);
|
||||
}
|
||||
new DesignToPartDialog(session, list, targets);
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,376 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.Connection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.connor.jingdiao.util.SqlUtil;
|
||||
import com.connor.jingdiao.util.TCUtil;
|
||||
import com.connor.ml.tcm.outfile.util.MethodUtil;
|
||||
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCAccessControlService;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemType;
|
||||
import com.teamcenter.rac.kernel.TCProperty;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class DrawingNoApplyDialog extends AbstractAIFDialog {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private TCSession session;
|
||||
private JCheckBox createChx;
|
||||
private JButton exportBtn;
|
||||
private JButton closeBtn;
|
||||
private JTable impTable;
|
||||
private DefaultTableModel impModel;
|
||||
private ArrayList<TCComponentItemRevision> list;
|
||||
private HashMap<String, Integer> map;
|
||||
private Map<String, String[]> ruleOpsMap;
|
||||
// public DrawingNoApplyDialog(TCSession session, String tables[], String[] options, String[] sqlOptions, InterfaceAIFComponent[] targets) throws Exception {
|
||||
public DrawingNoApplyDialog(TCSession session, ArrayList<String[]> options,
|
||||
InterfaceAIFComponent[] targets,Map<String, String[]> ruleOpsMap) throws Exception {
|
||||
super(AIFUtility.getActiveDesktop());
|
||||
this.session = session;
|
||||
list = new ArrayList<>();
|
||||
map = new HashMap<>();
|
||||
setTitle("图号申请");
|
||||
this.ruleOpsMap = ruleOpsMap;
|
||||
System.out.println(ruleOpsMap.toString());
|
||||
createChx = new JCheckBox("生成物料");
|
||||
createChx.setSelected(true);
|
||||
exportBtn = new JButton("申请");
|
||||
closeBtn = new JButton("关闭");
|
||||
JPanel btnPanel = new JPanel(new FlowLayout());
|
||||
btnPanel.add(createChx);
|
||||
btnPanel.add(exportBtn);
|
||||
btnPanel.add(closeBtn);
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.add(BorderLayout.SOUTH, btnPanel);
|
||||
|
||||
ArrayList<String[]> props = new ArrayList<>();
|
||||
// String[] tableHeader = new String[] { "序号", "itemID", "名称", "版本", "加工类型", "产品分类码", "课题号", "配置码", "部件码", "图纸类型", "新图号" };
|
||||
String[] tables = options.get(0);
|
||||
String[] tableHeader = new String[tables.length + 1];
|
||||
tableHeader[0] = "序号";
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
String[] split = tables[i].split("=");
|
||||
props.add(split[1].split("\\."));
|
||||
tableHeader[i + 1] = split[0];
|
||||
map.put(split[1], i + 1);
|
||||
}
|
||||
impModel = new DefaultTableModel(tableHeader, 0);
|
||||
impTable = new JTable() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
impTable.getTableHeader().setReorderingAllowed(false);
|
||||
impTable.setFillsViewportHeight(true);
|
||||
// impTable.setEnabled(false);
|
||||
impTable.setEnabled(true);
|
||||
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
impTable.setModel(impModel);
|
||||
for (int i = 1; i < impModel.getColumnCount(); i++)
|
||||
impTable.getColumnModel().getColumn(i).setPreferredWidth(150);
|
||||
int r = 1;
|
||||
TCAccessControlService acs = session.getTCAccessControlService();
|
||||
TCComponent[] user = new TCComponent[]{ session.getUser(), session.getGroup(), session.getRole() };
|
||||
StringBuilder msg = new StringBuilder("");
|
||||
StringBuilder msg2 = new StringBuilder("");
|
||||
for (InterfaceAIFComponent t : targets) {
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision) t;
|
||||
if (!rev.getProperty("j6_drawingno").isEmpty()) {
|
||||
msg.append(rev).append("、");
|
||||
continue;
|
||||
}
|
||||
if(!acs.checkAccessorsPrivilege(user, rev, "WRITE")) {
|
||||
msg2.append(rev).append("、");
|
||||
continue;
|
||||
}
|
||||
TCComponentItem item = rev.getItem();
|
||||
int size = props.size() + 1;
|
||||
Object[] data = new Object[size];
|
||||
data[0] = r++;
|
||||
for (int i = 1; i < size; i++) {
|
||||
String[] ss = props.get(i-1);
|
||||
if (ss[0].equals("item")) {
|
||||
data[i] = item.getStringProperty(ss[1]);
|
||||
} else {
|
||||
data[i] = rev.getStringProperty(ss[1]);
|
||||
}
|
||||
}
|
||||
|
||||
impModel.addRow(data);
|
||||
list.add(rev);
|
||||
}
|
||||
if (targets.length > list.size()) {
|
||||
StringBuilder m = new StringBuilder("所选对象:\n");
|
||||
if(msg.length()>0) {
|
||||
m.append(msg.deleteCharAt(msg.length() - 1)).append(" 已有图号,无法再次申请!\n");
|
||||
}
|
||||
if(msg2.length()>0) {
|
||||
m.append(msg2.deleteCharAt(msg2.length() - 1)).append(" 无编辑权限,无法申请图号!");
|
||||
}
|
||||
MessageBox.post(AIFUtility.getActiveDesktop(), m.toString(), "警告", MessageBox.WARNING);
|
||||
}
|
||||
if (list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
JScrollPane tablePanel = new JScrollPane(impTable);
|
||||
|
||||
addActionListener(options);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(BorderLayout.NORTH, topPanel);
|
||||
add(BorderLayout.CENTER, tablePanel);
|
||||
pack();
|
||||
setSize(new Dimension(1400, 700));
|
||||
setDefaultLookAndFeelDecorated(true);
|
||||
Dimension screen = getToolkit().getScreenSize();
|
||||
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
|
||||
// setAlwaysOnTop(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void addActionListener(ArrayList<String[]> options) {
|
||||
exportBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
createChx.setEnabled(false);
|
||||
exportBtn.setEnabled(false);
|
||||
closeBtn.setEnabled(false);
|
||||
String[] sqlOptions = options.get(2);
|
||||
Connection conn = SqlUtil.getSqlserverConnection("oracle.jdbc.driver.OracleDriver",
|
||||
"jdbc:oracle:thin:@" + sqlOptions[0] + ":1521:" + sqlOptions[3], sqlOptions[1], sqlOptions[2]);
|
||||
if (conn == null) {
|
||||
throw new Exception("无法获取数据库连接信息");
|
||||
}
|
||||
StringBuilder msg = new StringBuilder("");
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
TCComponentItemRevision rev = list.get(i);
|
||||
String itemtype = rev.getItem().getType();
|
||||
HashMap<String[], String> opm = new HashMap<>();
|
||||
if(ruleOpsMap.containsKey(itemtype)) {
|
||||
String[] ops = ruleOpsMap.get(itemtype);
|
||||
for (int tt = 0; tt < ops.length; tt++) {
|
||||
String[] ss = ops[tt].split("@@");
|
||||
opm.put(ss[0].split("@"), ss[1]);
|
||||
}
|
||||
}
|
||||
String dno = "";
|
||||
boolean norule = true;
|
||||
OPM: for (String[] ss : opm.keySet()) {
|
||||
boolean check = false;
|
||||
for (int j = 0; j < ss.length; j++) {
|
||||
String[] s2 = ss[j].split("=");
|
||||
String[] ss2 = s2[1].split(";");
|
||||
boolean c = true;
|
||||
for(String s : ss2) {
|
||||
System.out.println(i+"::"+s+"=="+impTable.getValueAt(i, map.get(s2[0]))+"<<"+s2[0]);
|
||||
if(s.equals(impTable.getValueAt(i, map.get(s2[0])))){
|
||||
c = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println(c);
|
||||
if(c)
|
||||
check = true;
|
||||
}
|
||||
System.out.println("check:"+check);
|
||||
if(check)
|
||||
continue;
|
||||
norule = false;
|
||||
StringBuilder id = new StringBuilder("");
|
||||
String rul = opm.get(ss);
|
||||
String[] rule = rul.split("\\+");
|
||||
for(String s : rule) {
|
||||
if(s.startsWith(".")) {
|
||||
id.append(s);
|
||||
}else if(s.startsWith("LSH")) {
|
||||
String lsh = "%" + String.format("%02d", Integer.parseInt(s.substring(3))) + "d";
|
||||
List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
if (results.size() == 0) {
|
||||
SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',1)");
|
||||
id.append(String.format(lsh, 1));
|
||||
} else {
|
||||
int no = (Integer) results.get(0).get("SERIALNUMBER") + 1;
|
||||
SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" +id+ "'");
|
||||
id.append(String.format(lsh, no));
|
||||
}
|
||||
}else if(s.startsWith("#rev.")) {
|
||||
String value = rev.getStringProperty(s.substring(5));
|
||||
if(value.isEmpty()) {
|
||||
msg.append(rev).append(" 的部分图号相关属性为空,请检查\n");
|
||||
break OPM;
|
||||
}
|
||||
id.append(value);
|
||||
}else if(map.containsKey(s)) {
|
||||
String value = impTable.getValueAt(i, map.get(s)).toString();
|
||||
if(value.isEmpty()) {
|
||||
msg.append(rev).append(" 的部分图号相关属性为空,请检查\n");
|
||||
break OPM;
|
||||
}
|
||||
id.append(value);
|
||||
}else if(s.contains(".")) {//.startsWith("J6_ASSOCIATED_REL.j6_drawingno")
|
||||
String[] sp = s.split("\\.");
|
||||
AIFComponentContext[] parent = rev.whereReferencedByTypeRelation(null, new String[] { sp[0] });
|
||||
if(parent==null || parent.length==0) {
|
||||
msg.append(rev).append(" 与零件未关联,请关联后再申请图号\n");
|
||||
break OPM;
|
||||
}
|
||||
String p = parent[0].getComponent().getProperty(sp[1]);
|
||||
if(p.isEmpty()) {
|
||||
if(sp[1].equals("j6_drawingno")) {
|
||||
msg.append(rev).append(" 上级图纸无图号,请先申请上级图号后再申请本图图号\n");
|
||||
break OPM;
|
||||
}else {
|
||||
msg.append(rev).append(" 上级对象属性为空,请检查\n");
|
||||
break OPM;
|
||||
}
|
||||
}
|
||||
id.append(p);
|
||||
}else {
|
||||
id.append(s);
|
||||
}
|
||||
}
|
||||
if(!rul.contains("LSH")) {
|
||||
List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn,
|
||||
"select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
if (results.size() == 0) {
|
||||
SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',0)");
|
||||
}else {
|
||||
msg.append(rev).append(" 的图号 ").append(id).append(" 已存在,请检查相关属性值\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dno = id.toString();
|
||||
rev.setProperty("j6_drawingno", dno);
|
||||
impTable.setValueAt(dno, i, map.get("rev.j6_drawingno"));
|
||||
break;
|
||||
}
|
||||
if(norule) {
|
||||
msg.append(rev).append(" 无满足条件的规则,无法申请图号 ");
|
||||
}
|
||||
norule = true;
|
||||
|
||||
if(dno.isEmpty())
|
||||
continue;
|
||||
if(!createChx.isSelected())
|
||||
continue;
|
||||
TCComponentItem item = rev.getItem();
|
||||
TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
|
||||
String type = "", dtype = item.getType(), ptype = rev.getProperty("j6_processtype");
|
||||
String t = dtype+";"+ptype+"=";
|
||||
for(String ss : options.get(3)) {
|
||||
if(ss.startsWith(t)) {
|
||||
type = ss.substring(ss.indexOf("=")+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(type.isEmpty())
|
||||
continue;
|
||||
AIFComponentContext[] rfs = rev.getChildren("representation_for")[0].getComponent().getChildren();
|
||||
if(rfs!=null && rfs.length>0) {
|
||||
int choose = JOptionPane.showOptionDialog(DrawingNoApplyDialog.this, rev+" 下已存在物料,是否继续创建?", "提示",
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] {"是","否"}, "结束操作");
|
||||
if(choose==1)
|
||||
continue;
|
||||
}
|
||||
TCComponentItemType typec = (TCComponentItemType)session.getTypeComponent(type);
|
||||
TCComponentItem pitem = typec.create(typec.getNewID(), null, type, item.getProperty("object_name"), "", null);
|
||||
TCComponentItemRevision prev = pitem.getLatestItemRevision();
|
||||
TCComponentForm pform = TCUtil.getItemRevisionMasterForm(prev);
|
||||
t = dtype+";"+type+"@@";
|
||||
for(String s : options.get(4)) {
|
||||
if(!s.startsWith(t))
|
||||
continue;
|
||||
String[] ss = s.substring(s.indexOf("@@")+2).split(";");
|
||||
for(String s1 : ss) {
|
||||
String[] ps = s1.split("=");
|
||||
setProp(ps, pitem, prev, pform, item, rev, form);
|
||||
}
|
||||
break;
|
||||
}
|
||||
rev.add("representation_for", prev);
|
||||
}
|
||||
if(msg.length()>0)
|
||||
MessageBox.post(DrawingNoApplyDialog.this, "以下对象图号申请遇到问题,请检查:\n" + msg, "提示", MessageBox.WARNING);
|
||||
else
|
||||
MessageBox.post(DrawingNoApplyDialog.this, "图号申请完成!", "提示", MessageBox.INFORMATION);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
MessageBox.post(DrawingNoApplyDialog.this, "错误:" + e1.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
}
|
||||
createChx.setEnabled(true);
|
||||
exportBtn.setEnabled(true);
|
||||
closeBtn.setEnabled(true);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
});
|
||||
closeBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setProp(String[] ps, TCComponentItem pitem, TCComponentItemRevision prev, TCComponentForm pform,
|
||||
TCComponentItem item, TCComponentItemRevision rev, TCComponentForm form) throws Exception {
|
||||
String[] p1 = ps[0].split("\\."), p2 = ps[1].split("\\.");
|
||||
Object val = "";
|
||||
if(p2.length<2) {
|
||||
val = p2[0];
|
||||
}else if(p2[0].equals("item")) {
|
||||
val = MethodUtil.getTCPropertyValue(item, p2[1]);
|
||||
//val = item.getProperty(p2[1]);
|
||||
}else if(p2[0].equals("rev")) {
|
||||
val = MethodUtil.getTCPropertyValue(rev, p2[1]);
|
||||
//val = rev.getProperty(p2[1]);
|
||||
}else if(p2[0].equals("revmaster")) {
|
||||
val = MethodUtil.getTCPropertyValue(form, p2[1]);
|
||||
//val = form.getProperty(p2[1]);
|
||||
}
|
||||
System.out.println("val:"+val);
|
||||
if(p1[0].equals("item")) {
|
||||
MethodUtil.setTCPropertyValue(pitem, p1[1], val);
|
||||
}else if(p1[0].equals("rev")) {
|
||||
MethodUtil.setTCPropertyValue(prev, p1[1], val);
|
||||
}else if(p1[0].equals("revmaster")) {
|
||||
MethodUtil.setTCPropertyValue(pform, p1[1], val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
|
||||
import com.teamcenter.rac.aif.AIFDesktop;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentBOMLine;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
//创建常规文件夹结构
|
||||
public class DrawingNoApplyHandler extends AbstractHandler implements IHandler{
|
||||
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
System.out.println("DrawingNoApplyHandler");
|
||||
TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession();
|
||||
AIFDesktop desktop = AIFUtility.getActiveDesktop();
|
||||
try {
|
||||
Map<String, String[]> ruleOpsMap = new HashMap<String, String[]>();
|
||||
String ruleString = "Jd_Code_Rule_";
|
||||
InterfaceAIFComponent[] targets = AIFUtility.getCurrentApplication().getTargetComponents();
|
||||
for(InterfaceAIFComponent t : targets) {
|
||||
TCComponentItemRevision revision;
|
||||
if(t instanceof TCComponentItemRevision) {
|
||||
revision = (TCComponentItemRevision) t;
|
||||
}else if(t instanceof TCComponentBOMLine) {
|
||||
revision = ((TCComponentBOMLine) t).getItemRevision();
|
||||
}else {
|
||||
MessageBox.post(desktop, "选中对象"+t+"不是设计版本类型,无法申请图号!", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
String type = revision.getItem().getType();
|
||||
if(!ruleOpsMap.containsKey(type)) {
|
||||
String[] options = session.getPreferenceService().getStringValues(ruleString+type);
|
||||
if(options==null || options.length==0) {
|
||||
MessageBox.post(desktop, "选中对象"+t+"不是设计版本类型,无法申请图号!", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}else {
|
||||
ruleOpsMap.put(type, options);
|
||||
}
|
||||
}
|
||||
// if(!(t instanceof TCComponentItemRevision) || !t.getType().contains("Design")) {// Revision
|
||||
// MessageBox.post(desktop, "选中对象"+t+"不是设计版本类型,无法申请图号!", "ERROR", MessageBox.ERROR);
|
||||
// return null;
|
||||
// }else {
|
||||
// TCComponentItemRevision revision = (TCComponentItemRevision)t;
|
||||
// String type = revision.getItem().getType();
|
||||
// if(!ruleOpsMap.containsKey(type)) {
|
||||
// String typeString = ruleString + type;
|
||||
// String[] options = session.getPreferenceService().getStringValues(typeString);
|
||||
// ruleOpsMap.put(type, options);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
String ruleType = "Jd_Code_Rule_Design";
|
||||
|
||||
|
||||
|
||||
ArrayList<String[]> list = new ArrayList<>();
|
||||
String[] ops = new String[] { "Jd_Code_Table_Design", ruleType, "Jd_TC_Info_Connect",
|
||||
"JD6_Part_Design_Type", "JD6_Part_Design_Copy_Properties" };
|
||||
for(String name : ops) {
|
||||
String[] options = session.getPreferenceService().getStringValues(name);
|
||||
if(options == null || options.length == 0) {
|
||||
MessageBox.post(desktop, "首选项"+name+"配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
list.add(options);
|
||||
}
|
||||
new DrawingNoApplyDialog(session, list, targets,ruleOpsMap);
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
|
||||
import com.teamcenter.rac.aif.AIFDesktop;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentUser;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
//标准化审核
|
||||
public class LoginIPSetHandler extends AbstractHandler implements IHandler{
|
||||
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
System.out.println("LoginIPSetHandler");
|
||||
new Thread() {
|
||||
public void run() {
|
||||
AIFDesktop desktop = AIFUtility.getActiveDesktop();
|
||||
try {
|
||||
TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession();
|
||||
TCComponentUser user = session.getUser();
|
||||
if(!user.getUserId().equals("infodba")) {
|
||||
MessageBox.post(desktop, "禁止操作", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
String[] options = session.getPreferenceService().getStringValues("Jd_TC_Info_Connect");
|
||||
if(options == null || options.length < 4) {
|
||||
MessageBox.post(desktop, "首选项Jd_TC_Info_Connect配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
String option = session.getPreferenceService().getStringValue("Jd6_IP_model");
|
||||
if(option == null || option.isEmpty()) {
|
||||
MessageBox.post(desktop, "首选项Jd6_IP_model配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
TCComponent dataset = session.stringToComponent(option);
|
||||
if(dataset==null || !dataset.getType().equals("MSExcelX")) {
|
||||
MessageBox.post(desktop, "首选项Jd6_IP_model配置不正确", "ERROR", MessageBox.ERROR);//QiAAAI4S5kSPsC
|
||||
return;
|
||||
}
|
||||
new LoginIPSetDialog(session, dataset, options);
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,421 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
//import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import com.connor.jingdiao.util.TCUtil;
|
||||
import com.connor.ml.tcm.outfile.util.MethodUtil;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentDataset;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentTask;
|
||||
import com.teamcenter.rac.kernel.TCComponentTcFile;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class StandardDialog extends JDialog {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private TCSession session;
|
||||
private JTextArea remark;
|
||||
private JButton remarkBtn;
|
||||
private JButton exportBtn;
|
||||
private JButton closeBtn;
|
||||
private JTable impTable;
|
||||
private DefaultTableModel impModel;
|
||||
private ArrayList<TCComponentItemRevision> revlist;
|
||||
private String[] mark;
|
||||
private int mrow = -1;
|
||||
// private HashMap<String, Integer> map;
|
||||
// private LinkedHashMap<String, String[]> ruleOpsMap;
|
||||
|
||||
// public DrawingNoApplyDialog(TCSession session, String tables[], String[] options, String[] sqlOptions, InterfaceAIFComponent[] targets) throws Exception {
|
||||
public StandardDialog(TCSession session, TCComponent[] models, TCComponentTask task, LinkedHashMap<String, String[]> ruleOpsMap, int[] cols)
|
||||
throws Exception {
|
||||
super(AIFUtility.getActiveDesktop());
|
||||
this.session = session;
|
||||
// list = new ArrayList<>();
|
||||
// map = new HashMap<>();
|
||||
// this.ruleOpsMap = ruleOpsMap;
|
||||
// System.out.println(ruleOpsMap.toString());
|
||||
setTitle("标准化审核");
|
||||
remark = new JTextArea();
|
||||
// remark.setPreferredSize(new Dimension(10, 10));
|
||||
remark.setLineWrap(true);
|
||||
remarkBtn = new JButton("修改备注");
|
||||
exportBtn = new JButton("导出Excel");
|
||||
closeBtn = new JButton("关闭");
|
||||
JPanel btnPanel = new JPanel(new FlowLayout());
|
||||
btnPanel.add(remarkBtn);
|
||||
btnPanel.add(exportBtn);
|
||||
btnPanel.add(closeBtn);
|
||||
JScrollPane remarkPanel = new JScrollPane(remark);
|
||||
remarkPanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.add(BorderLayout.NORTH, new JLabel("标准化备注"));
|
||||
topPanel.add(BorderLayout.CENTER, remarkPanel);
|
||||
topPanel.add(BorderLayout.SOUTH, btnPanel);
|
||||
|
||||
// ArrayList<String[]> props = new ArrayList<>();
|
||||
// String[] tableHeader = new String[] { "序号", "itemID", "名称", "版本", "加工类型", "产品分类码", "课题号", "配置码", "部件码", "图纸类型", "新图号" };
|
||||
// String[] tables = options.get(0);
|
||||
String[] tableHeader = new String[ruleOpsMap.size() + 1];
|
||||
tableHeader[0] = "序号";
|
||||
int h = 1;
|
||||
for (String s : ruleOpsMap.keySet()) {
|
||||
// String[] split = tables[h].split("=");
|
||||
// props.add(split[1].split("\\."));
|
||||
tableHeader[h] = s;
|
||||
if(s.equals("标准化备注")) {
|
||||
mark = ruleOpsMap.get(s);
|
||||
mrow = h;
|
||||
}
|
||||
// map.put(split[1], h);
|
||||
h++;
|
||||
}
|
||||
if(mrow < 0)
|
||||
throw new Exception("首选项Jd_Standard_UI配置不正确");
|
||||
impModel = new DefaultTableModel(tableHeader, 0);
|
||||
impTable = new JTable() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
impTable.getTableHeader().setReorderingAllowed(false);
|
||||
impTable.setFillsViewportHeight(true);
|
||||
// impTable.setEnabled(false);
|
||||
impTable.setEnabled(true);
|
||||
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
impTable.setModel(impModel);
|
||||
for (int i = 1; i < impModel.getColumnCount(); i++) {
|
||||
TableColumn col = impTable.getColumnModel().getColumn(i);
|
||||
col.setCellRenderer(new TextAreaRenderer());
|
||||
col.setPreferredWidth(150);
|
||||
}
|
||||
|
||||
setDatas(task, (TCComponentDataset) models[0], ruleOpsMap);
|
||||
addActionListener(models, cols);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(BorderLayout.EAST, topPanel);
|
||||
add(BorderLayout.CENTER, new JScrollPane(impTable));
|
||||
pack();
|
||||
setSize(new Dimension(1400, 500));
|
||||
setDefaultLookAndFeelDecorated(true);
|
||||
Dimension screen = getToolkit().getScreenSize();
|
||||
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
|
||||
setAlwaysOnTop(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setDatas(TCComponentTask task, TCComponentDataset model, LinkedHashMap<String, String[]> ruleOpsMap) throws Exception {
|
||||
TCComponentTcFile[] files = model.getTcFiles();
|
||||
File file = files[0].getFile(System.getProperty("java.io.tmpdir"));
|
||||
SAXReader saxReader = new SAXReader();
|
||||
Document doc = saxReader.read(file);
|
||||
Element root = doc.getRootElement();
|
||||
Element condizione = root.element("condizione");
|
||||
List typeEs = condizione.element("object_type").elements();
|
||||
ArrayList<String> types = new ArrayList<>();
|
||||
for(Object e : typeEs) {
|
||||
types.add(((Element)e).getText());
|
||||
}
|
||||
List regolaEs = condizione.element("regola").elements();
|
||||
HashMap<String, Boolean> regolas = new HashMap<>();
|
||||
for(Object e : regolaEs) {
|
||||
String t = ((Element)e).getText();
|
||||
String name = ((Element)e).getName();
|
||||
if(name.equals("item"))
|
||||
name = "object_type";
|
||||
if(t.equals("*")) {
|
||||
regolas.put(name, false);
|
||||
}else {
|
||||
regolas.put(name, true);
|
||||
}
|
||||
}
|
||||
List rows = root.element("data").elements();
|
||||
AIFComponentContext[] contexts = TCUtil.getPseudoFolder(task, "root_target_attachments").getChildren();
|
||||
revlist = new ArrayList<>();
|
||||
for(AIFComponentContext c : contexts) {
|
||||
if(!types.contains(c.getComponent().getType()))
|
||||
continue;
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision) c.getComponent();
|
||||
HashMap<String, String> props = new HashMap<>();
|
||||
for(String s : regolas.keySet()) {
|
||||
if(rev.getTCProperty(s) == null) {
|
||||
System.out.println(rev+" >> "+s+"\n属性未找到");
|
||||
throw new Exception("判断条件配置错误,请检查配置信息");
|
||||
}
|
||||
props.put(s, rev.getProperty(s));
|
||||
}
|
||||
ROW:for(Object e : rows) {
|
||||
for(Object t : ((Element)e).elements()) {
|
||||
String name = ((Element)t).getName();
|
||||
if(!props.containsKey(name))
|
||||
continue;
|
||||
String text = ((Element)t).getText();
|
||||
String val = props.get(name);
|
||||
if(regolas.get(name)) {
|
||||
if(text.equals("null")) {
|
||||
if(!val.isEmpty())
|
||||
continue ROW;
|
||||
}else if(!val.equals(text))
|
||||
continue ROW;
|
||||
}else if(!regolas.get(name) && !val.contains(text)) {
|
||||
continue ROW;
|
||||
}
|
||||
}
|
||||
TCComponentItem item = rev.getItem();
|
||||
String[] row = new String[ruleOpsMap.size()+1];
|
||||
row[0] = impTable.getRowCount()+1+"";
|
||||
int i = 1;
|
||||
for(String n : ruleOpsMap.keySet()) {
|
||||
row[i] = getProp(ruleOpsMap.get(n), item, rev);
|
||||
i++;
|
||||
}
|
||||
System.out.println("row:"+Arrays.toString(row));
|
||||
impModel.addRow(row);
|
||||
revlist.add(rev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addActionListener(TCComponent[] models, int[] cols) {
|
||||
impTable.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
try {
|
||||
int row = impTable.getSelectedRow();
|
||||
if(row < 0) {
|
||||
return;
|
||||
}
|
||||
remark.setText(""+impTable.getValueAt(row, mrow));
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
MessageBox.post(StandardDialog.this, "错误:" + e1.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
}
|
||||
}
|
||||
});
|
||||
remarkBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
try {
|
||||
int row = impTable.getSelectedRow();
|
||||
if(row < 0) {
|
||||
MessageBox.post(StandardDialog.this, "请选择要编辑的行!", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
String text = remark.getText();
|
||||
if(text.getBytes().length > 1024) {
|
||||
MessageBox.post(StandardDialog.this, "标准化备注填写长度过长,无法修改!", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
TCComponentItemRevision rev = revlist.get(row);
|
||||
TCComponentItem item = rev.getItem();
|
||||
if(mark[0].equals("item") && item.isCheckedOut()) {
|
||||
MessageBox.post(StandardDialog.this, item+" 已签出,无法修改!", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}else if(mark[0].equals("rev") && rev.isCheckedOut()) {
|
||||
MessageBox.post(StandardDialog.this, rev+" 已签出,无法修改!", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
MethodUtil.openByPass(session);
|
||||
if(mark[0].equals("item")) {
|
||||
item.setProperty(mark[1], text);
|
||||
}else if(mark[0].equals("rev")) {
|
||||
rev.setProperty(mark[1], text);
|
||||
}
|
||||
impTable.setValueAt(text, row, mrow);
|
||||
MethodUtil.closeByPass(session);
|
||||
}catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
MessageBox.post(StandardDialog.this, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
}finally {
|
||||
try {
|
||||
MethodUtil.closeByPass(session);
|
||||
}catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
//TODO
|
||||
exportBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
FileInputStream input = null;
|
||||
FileOutputStream output = null;
|
||||
XSSFWorkbook wb = null;
|
||||
try {
|
||||
File directory = TCUtil.saveExcelChooser(StandardDialog.this, "");
|
||||
if(directory==null)
|
||||
return;
|
||||
if(directory.exists())
|
||||
directory.delete();
|
||||
TCComponentDataset model = (TCComponentDataset) models[1];
|
||||
TCComponentTcFile[] files = model.getTcFiles();
|
||||
File file = files[0].getFile(System.getProperty("java.io.tmpdir"));
|
||||
input = new FileInputStream(file);
|
||||
wb = new XSSFWorkbook(input);
|
||||
XSSFSheet sheet = wb.getSheetAt(0);
|
||||
XSSFRow row;
|
||||
XSSFCell cell;
|
||||
row = getRow(sheet, cols[0]);
|
||||
TableColumnModel cm = impTable.getColumnModel();
|
||||
for(int i=0; i<cm.getColumnCount(); i++) {
|
||||
cell = getCell(row, i);
|
||||
cell.setCellValue(cm.getColumn(i).getHeaderValue().toString());
|
||||
}
|
||||
for(int i=0; i<impTable.getRowCount(); i++) {
|
||||
row = getRow(sheet, i + cols[1]);
|
||||
for(int j=0; j<impTable.getColumnCount(); j++) {
|
||||
cell = getCell(row, j);
|
||||
cell.setCellValue(impTable.getValueAt(i, j).toString());
|
||||
}
|
||||
}
|
||||
output = new FileOutputStream(file.getPath());
|
||||
wb.write(output);
|
||||
input.close();
|
||||
output.close();
|
||||
file.renameTo(directory);
|
||||
MessageBox.post(StandardDialog.this, "导出完成!", "提示", MessageBox.INFORMATION);
|
||||
}catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
MessageBox.post(StandardDialog.this, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
}finally {
|
||||
if(input!=null)
|
||||
try {
|
||||
input.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(output!=null)
|
||||
try {
|
||||
output.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
closeBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getProp(String[] ps, TCComponentItem item, TCComponentItemRevision rev) throws Exception {
|
||||
if(ps[0].equals("item")) {
|
||||
return item.getProperty(ps[1]);
|
||||
}else if(ps[0].equals("rev")) {
|
||||
return rev.getProperty(ps[1]);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private XSSFRow getRow(XSSFSheet sheet, int num) throws Exception {
|
||||
XSSFRow row = sheet.getRow(num);
|
||||
if(row==null)
|
||||
row = sheet.createRow(num);
|
||||
return row;
|
||||
}
|
||||
private XSSFCell getCell(XSSFRow row, int col) throws Exception {
|
||||
XSSFCell cell = row.getCell(col);
|
||||
if(cell==null)
|
||||
cell = row.createCell(col);
|
||||
// if(row.getRowNum()>1)
|
||||
// cell.setCellStyle(getCell(sourceRow, col).getCellStyle());
|
||||
return cell;
|
||||
}
|
||||
|
||||
public class TextAreaRenderer extends JTextArea implements TableCellRenderer {
|
||||
private static final long serialVersionUID = 1L;
|
||||
// ArrayList<Integer> area;
|
||||
|
||||
public TextAreaRenderer() {
|
||||
// this.area = area;
|
||||
setLineWrap(true); //利用JTextArea的自动换行方法
|
||||
setWrapStyleWord(true);
|
||||
}
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
// 计算当下行的最佳高度
|
||||
int maxPreferredHeight = 22;
|
||||
JTextArea cell = new JTextArea();
|
||||
// cell.setLineWrap(true);
|
||||
for (int i=0; i<table.getColumnCount(); i++) {
|
||||
cell.setText("" + table.getValueAt(row, i));
|
||||
// maxPreferredHeight = Math.max(maxPreferredHeight,cell.getPreferredSize().height);
|
||||
// if(row == 19)
|
||||
// System.out.println(i+">>>"+table.getValueAt(row, i)+">>>"+cell.getPreferredSize().width+","+cell.getPreferredSize().height);
|
||||
maxPreferredHeight = Math.max(maxPreferredHeight,
|
||||
(cell.getPreferredSize().width/table.getColumnModel().getColumn(i).getWidth()+1)*cell.getPreferredSize().height+7);
|
||||
}
|
||||
if (table.getRowHeight(row) != maxPreferredHeight)
|
||||
// 少了这行则处理器瞎忙
|
||||
table.setRowHeight(row, maxPreferredHeight);
|
||||
//System.out.println(row+":"+maxPreferredHeight);
|
||||
|
||||
setText(value == null ? "" : value.toString());
|
||||
fillColor(table,this,isSelected);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void fillColor(JTable t,JTextArea l,boolean isSelected ){
|
||||
if(isSelected){
|
||||
l.setBackground(t.getSelectionBackground());
|
||||
l.setForeground(t.getSelectionForeground());
|
||||
} else {
|
||||
l.setBackground(t.getBackground());
|
||||
l.setForeground(t.getForeground());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
HashMap<String[], String> opm = new HashMap<>();
|
||||
// for (int i = 0; i < options.length; i++) {
|
||||
String optionString = "rev.j6_drawingtype=零件@rev.j6_processtype=外购件@@#rev.j6_productseries+rev.j6_topicno";
|
||||
String[] sss = optionString.split("@@");
|
||||
opm.put(sss[0].split("@"), sss[1]);
|
||||
|
||||
boolean present = Optional.ofNullable("ss").isPresent();
|
||||
System.out.println("::"+present);
|
||||
|
||||
OPM: for (String[] ss : opm.keySet()) {
|
||||
boolean check = false;
|
||||
for (int j = 0; j < ss.length; j++) {
|
||||
String[] s2 = ss[j].split("=");
|
||||
String[] ss2 = s2[1].split(";");
|
||||
boolean c = true;
|
||||
for(String s : ss2) {
|
||||
System.out.println("::"+s+"=="+"<<"+s2[0]);
|
||||
// if(s.equals(impTable.getValueAt(i, map.get(s2[0])))){
|
||||
// c = false;
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
System.out.println(c);
|
||||
if(c)
|
||||
check = true;
|
||||
}
|
||||
System.out.println("check:"+check);
|
||||
// if(check)
|
||||
// continue;
|
||||
// norule = false;
|
||||
StringBuilder id = new StringBuilder("");
|
||||
String rul = opm.get(ss);
|
||||
String[] rule = rul.split("\\+");
|
||||
for(String s : rule) {
|
||||
if(s.startsWith(".")) {
|
||||
id.append(s);
|
||||
}else if(s.startsWith("LSH")) {
|
||||
String lsh = "%" + String.format("%02d", Integer.parseInt(s.substring(3))) + "d";
|
||||
id.append(String.format(lsh, 2));
|
||||
// List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
// if (results.size() == 0) {
|
||||
// SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',1)");
|
||||
// id.append(String.format(lsh, 1));
|
||||
// } else {
|
||||
// int no = (Integer) results.get(0).get("SERIALNUMBER") + 1;
|
||||
// SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" +id+ "'");
|
||||
// id.append(String.format(lsh, no));
|
||||
// }
|
||||
}else if(s.startsWith("#rev.")) {
|
||||
System.out.println("s.substring(5)==>"+s.substring(5));
|
||||
// String value = rev.getStringProperty(s.substring(5));
|
||||
// if(value.isEmpty()) {
|
||||
// msg.append(rev).append(" 的部分图号相关属性为空,请检查\n");
|
||||
// break OPM;
|
||||
// }
|
||||
id.append("revVal");
|
||||
}
|
||||
// else if(map.containsKey(s)) {
|
||||
// String value = impTable.getValueAt(i, map.get(s)).toString();
|
||||
// if(value.isEmpty()) {
|
||||
// msg.append(rev).append(" 的部分图号相关属性为空,请检查\n");
|
||||
// break OPM;
|
||||
// }
|
||||
// id.append(value);
|
||||
// }
|
||||
else if(s.contains(".")) {//.startsWith("J6_ASSOCIATED_REL.j6_drawingno")
|
||||
String[] sp = s.split("\\.");
|
||||
System.out.println("sp[0]"+sp[0]+"sp[1]"+sp[1]);
|
||||
// id.append(s);
|
||||
}else {
|
||||
id.append(s);
|
||||
}
|
||||
}
|
||||
if(!rul.contains("LSH")) {
|
||||
System.out.println("sql==>"+"select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
// List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
// if (results.size() == 0) {
|
||||
//
|
||||
// SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',0)");
|
||||
// }else {
|
||||
// msg.append(rev).append(" 的物料编码 ").append(id).append(" 已存在,请检查相关属性值\n");
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
String dno = id.toString();
|
||||
System.out.println("dno==>"+dno);
|
||||
break;
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,377 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.connor.jingdiao.util.SqlTIUtil;
|
||||
import com.connor.jingdiao.util.SqlUtil;
|
||||
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCAccessControlService;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class WlbmApplyDialog extends AbstractAIFDialog {
|
||||
|
||||
private JButton exportBtn;
|
||||
private JButton closeBtn;
|
||||
private JTable impTable;
|
||||
private DefaultTableModel impModel;
|
||||
private ArrayList<TCComponentItemRevision> list;
|
||||
private HashMap<String, Integer> map;
|
||||
private HashMap<String, String> productClassMap;
|
||||
public WlbmApplyDialog(TCSession session, String tables[], String[] options,
|
||||
String[] sqlOptions, InterfaceAIFComponent[] targets,String[] sqlOptionsTI,String[] productClass) throws Exception {
|
||||
super(AIFUtility.getActiveDesktop());
|
||||
// this.session = session;
|
||||
list = new ArrayList<>();
|
||||
map = new HashMap<>();
|
||||
productClassMap = new HashMap<String, String>();
|
||||
setTitle("物料编码申请");
|
||||
|
||||
exportBtn = new JButton("申请");
|
||||
closeBtn = new JButton("关闭");
|
||||
JPanel btnPanel = new JPanel(new FlowLayout());
|
||||
btnPanel.add(exportBtn);
|
||||
btnPanel.add(closeBtn);
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.add(BorderLayout.SOUTH, btnPanel);
|
||||
|
||||
ArrayList<String[]> props = new ArrayList<>();
|
||||
// String[] tableHeader = new String[] { "序号", "itemID", "名称", "版本", "加工类型", "产品分类码", "课题号", "配置码", "部件码", "图纸类型", "新图号" };
|
||||
String[] tableHeader = new String[tables.length + 1];
|
||||
tableHeader[0] = "序号";
|
||||
|
||||
for(int i=0;i<productClass.length;i++) {
|
||||
String[] split = productClass[i].split("=");
|
||||
productClassMap.put(split[0], split[1]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < tables.length; i++) { //存放表头信息
|
||||
String[] split = tables[i].split("=");
|
||||
props.add(split[1].split("\\."));
|
||||
tableHeader[i + 1] = split[0];
|
||||
map.put(split[1], i + 1);
|
||||
}
|
||||
System.out.println("MAP==>"+map.toString());
|
||||
impModel = new DefaultTableModel(tableHeader, 0);
|
||||
impTable = new JTable() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
impTable.getTableHeader().setReorderingAllowed(false);
|
||||
impTable.setFillsViewportHeight(true);
|
||||
// impTable.setEnabled(false);
|
||||
impTable.setEnabled(true);
|
||||
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
impTable.setModel(impModel);
|
||||
for (int i = 1; i < impModel.getColumnCount(); i++)
|
||||
impTable.getColumnModel().getColumn(i).setPreferredWidth(150);
|
||||
int r = 1;
|
||||
TCAccessControlService acs = session.getTCAccessControlService();
|
||||
TCComponent[] user = new TCComponent[]{ session.getUser(), session.getGroup(), session.getRole() };
|
||||
StringBuilder msg = new StringBuilder("");
|
||||
StringBuilder msg2 = new StringBuilder("");
|
||||
for (InterfaceAIFComponent t : targets) {
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision) t;
|
||||
if (!rev.getProperty("j6_wlbm").isEmpty()) {
|
||||
msg.append(rev).append("、");
|
||||
continue;
|
||||
}
|
||||
if(!acs.checkAccessorsPrivilege(user, rev, "WRITE")) {
|
||||
msg2.append(rev).append("、");
|
||||
continue;
|
||||
}
|
||||
TCComponentItem item = rev.getItem();
|
||||
int size = props.size() + 1;
|
||||
Object[] data = new Object[size];
|
||||
data[0] = r++;
|
||||
for (int i = 1; i < size; i++) {
|
||||
String[] ss = props.get(i-1);
|
||||
System.out.println("prop==>"+ss[1]);
|
||||
if (ss[0].equals("item")) {
|
||||
data[i] = item.getProperty(ss[1]);
|
||||
} else {
|
||||
data[i] = rev.getProperty(ss[1]);
|
||||
}
|
||||
}
|
||||
|
||||
impModel.addRow(data);
|
||||
list.add(rev);
|
||||
}
|
||||
if (targets.length > list.size()) {
|
||||
StringBuilder m = new StringBuilder("所选对象:\n");
|
||||
if(msg.length()>0) {
|
||||
m.append(msg.deleteCharAt(msg.length() - 1)).append(" 已有物料编码,无法再次申请!\n");
|
||||
}
|
||||
if(msg2.length()>0) {
|
||||
m.append(msg2.deleteCharAt(msg2.length() - 1)).append(" 无编辑权限,无法申请物料编码!");
|
||||
}
|
||||
MessageBox.post(AIFUtility.getActiveDesktop(), m.toString(), "警告", MessageBox.WARNING);
|
||||
}
|
||||
if (list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
JScrollPane tablePanel = new JScrollPane(impTable);
|
||||
addActionListener(options, sqlOptions,sqlOptionsTI);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(BorderLayout.NORTH, topPanel);
|
||||
add(BorderLayout.CENTER, tablePanel);
|
||||
pack();
|
||||
setSize(new Dimension(1400, 700));
|
||||
setDefaultLookAndFeelDecorated(true);
|
||||
Dimension screen = getToolkit().getScreenSize();
|
||||
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
|
||||
// setAlwaysOnTop(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void addActionListener(String[] options, String[] sqlOptions, String[] sqlOptionsTI) {
|
||||
exportBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
try {
|
||||
Connection conn = SqlUtil.getSqlserverConnection("oracle.jdbc.driver.OracleDriver",
|
||||
"jdbc:oracle:thin:@" + sqlOptions[0] + ":1521:" + sqlOptions[3], sqlOptions[1], sqlOptions[2]);
|
||||
if (conn == null) {
|
||||
throw new Exception("无法获取数据库连接信息");
|
||||
}
|
||||
Connection connTI = SqlTIUtil.getSqlserverConnection("oracle.jdbc.driver.OracleDriver",
|
||||
"jdbc:oracle:thin:@" + sqlOptionsTI[0] + ":1521:" + sqlOptionsTI[3], sqlOptionsTI[1], sqlOptionsTI[2]);
|
||||
if (connTI == null) {
|
||||
throw new Exception("无法获取TI数据库连接信息");
|
||||
}
|
||||
StringBuilder msg = new StringBuilder("");
|
||||
HashMap<String[], String> opm = new HashMap<>();
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
String[] ss = options[i].split("@@");
|
||||
opm.put(ss[0].split("@"), ss[1]);
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
TCComponentItemRevision rev = list.get(i);
|
||||
//加工方式为零件的Part 找bom上级
|
||||
String processType = rev.getProperty("j6_processtype");
|
||||
String itemType = rev.getItem().getType();
|
||||
if(itemType.equals("Part")&&processType.equals("零件")) {
|
||||
|
||||
TCComponent[] procs = rev.whereUsed(TCComponentItemRevision.WHERE_USED_ALL);
|
||||
for(TCComponent component : procs) {
|
||||
if(component instanceof TCComponentItemRevision) {
|
||||
TCComponentItemRevision zjRevision = (TCComponentItemRevision) component;
|
||||
String zjType = zjRevision.getProperty("j6_processtype");
|
||||
if(zjRevision.getType().contains("Part") && zjType.equals("组件")) {
|
||||
|
||||
String pDon = zjRevision.getProperty("j6_wlbm");
|
||||
if(pDon.isEmpty()) {
|
||||
msg.append(rev).append(" 上级图纸无物料编码,请先申请上级物料编码后再申请本物料编码\n");
|
||||
break;
|
||||
}
|
||||
if(pDon.endsWith("00")) {
|
||||
String id = pDon.substring(0, pDon.length()-2);
|
||||
StringBuffer code = new StringBuffer("");
|
||||
List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
if (results.size() == 0) {
|
||||
|
||||
List<HashMap<String, Object>> resultsTi = SqlTIUtil.getDBInfo(connTI, "select ECMS_NEXTCODE from ECMS_SERIAL where ECMS_PRE='"+id+"'");
|
||||
|
||||
if(resultsTi.size()==0) {
|
||||
SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',1)");
|
||||
code.append(String.format("%02d", 1));
|
||||
}else {
|
||||
int no = (Integer) results.get(0).get("ECMS_NEXTCODE") + 1;
|
||||
SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" +id+ "'");
|
||||
code.append(String.format("%02d", no));
|
||||
}
|
||||
} else {
|
||||
int no = (Integer) results.get(0).get("SERIALNUMBER") + 1;
|
||||
SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" +id+ "'");
|
||||
code.append(String.format("%02d", no));
|
||||
}
|
||||
|
||||
rev.setProperty("j6_wlbm", code.toString());
|
||||
impTable.setValueAt(code, i, map.get("rev.j6_wlbm"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean norule = true;
|
||||
OPM: for (String[] ss : opm.keySet()) {
|
||||
boolean check = false;
|
||||
for (int j = 0; j < ss.length; j++) {
|
||||
String[] s2 = ss[j].split("=");
|
||||
String[] ss2 = s2[1].split(";");
|
||||
boolean c = true;
|
||||
for(String s : ss2) {
|
||||
System.out.println(i+"::"+s+"=="+impTable.getValueAt(i, map.get(s2[0]))+"<<"+s2[0]);
|
||||
if(s.equals(impTable.getValueAt(i, map.get(s2[0])))){
|
||||
c = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println(c);
|
||||
if(c) {
|
||||
check = true;
|
||||
}else {
|
||||
check = false;
|
||||
}
|
||||
}
|
||||
System.out.println("check:"+check);
|
||||
if(check) {
|
||||
continue;
|
||||
}
|
||||
norule = false;
|
||||
StringBuilder id = new StringBuilder("");
|
||||
String rul = opm.get(ss);
|
||||
System.out.println("rule==>"+rul);
|
||||
String[] rule = rul.split("\\+");
|
||||
for(String s : rule) {
|
||||
System.out.println(s);
|
||||
if(s.startsWith(".")) {
|
||||
System.out.println("startWish . "+s);
|
||||
id.append(s);
|
||||
}else if(s.startsWith("LSH")) {
|
||||
String lsh = "%" + String.format("%02d", Integer.parseInt(s.substring(3))) + "d";
|
||||
List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
if (results.size() == 0) {
|
||||
|
||||
List<HashMap<String, Object>> resultsTi = SqlTIUtil.getDBInfo(connTI, "select ECMS_NEXTCODE from ECMS_SERIAL where ECMS_PRE='"+id+"'");
|
||||
|
||||
if(resultsTi.size()==0) {
|
||||
SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',1)");
|
||||
id.append(String.format(lsh, 1));
|
||||
}else {
|
||||
int no = (Integer) results.get(0).get("ECMS_NEXTCODE") + 1;
|
||||
SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" +id+ "'");
|
||||
id.append(String.format(lsh, no));
|
||||
}
|
||||
} else {
|
||||
int no = (Integer) results.get(0).get("SERIALNUMBER") + 1;
|
||||
SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" +id+ "'");
|
||||
id.append(String.format(lsh, no));
|
||||
}
|
||||
}else if(s.startsWith("#rev.")) {
|
||||
String prop = s.substring(5);
|
||||
String value = rev.getStringProperty(prop);
|
||||
if(value.isEmpty()) {
|
||||
msg.append(rev).append(" 的部分物料编码相关属性为空,请检查\n");
|
||||
break OPM;
|
||||
}else if(prop.equals("j6_productseries")){
|
||||
if(productClassMap.containsKey(value)) {
|
||||
value = productClassMap.get(value);
|
||||
}else {
|
||||
msg.append("产品分类码 ").append(value).append(" 在首选项 Jd_Code_Product_Class 中未找到配置,请检查\n");
|
||||
}
|
||||
}
|
||||
id.append(value);
|
||||
}else if(s.startsWith("rev.")) {
|
||||
System.out.println("rev==>"+s);
|
||||
String prop = s.substring(4);
|
||||
String value = "";
|
||||
value = rev.getStringProperty(prop);
|
||||
System.out.println(value);
|
||||
if(s.contains("j6_topicno")) {
|
||||
value = value.substring(0,3);
|
||||
}
|
||||
id.append(value);
|
||||
}
|
||||
else if(map.containsKey(s)) {
|
||||
String value = impTable.getValueAt(i, map.get(s)).toString();
|
||||
if(value.isEmpty()) {
|
||||
msg.append(rev).append(" 的部分物料编码相关属性为空,请检查\n");
|
||||
break OPM;
|
||||
}
|
||||
id.append(value);
|
||||
}else if(s.contains(".")) {//.startsWith("J6_ASSOCIATED_REL.j6_drawingno")
|
||||
String[] sp = s.split("\\.");
|
||||
AIFComponentContext[] parent = rev.whereReferencedByTypeRelation(null, new String[] { sp[0] });
|
||||
if(parent==null || parent.length==0) {
|
||||
msg.append(rev).append(" 与零件未关联,请关联后再申请图号\n");
|
||||
break OPM;
|
||||
}
|
||||
String p = parent[0].getComponent().getProperty(sp[1]);
|
||||
if(p.isEmpty()) {
|
||||
if(sp[1].equals("j6_drawingno")) {
|
||||
msg.append(rev).append(" 上级图纸无物料编码,请先申请上级物料编码后再申请本物料编码\n");
|
||||
break OPM;
|
||||
}else {
|
||||
msg.append(rev).append(" 上级对象属性为空,请检查\n");
|
||||
break OPM;
|
||||
}
|
||||
}
|
||||
id.append(p);
|
||||
}else {
|
||||
id.append(s);
|
||||
}
|
||||
}
|
||||
if(!rul.contains("LSH")) {
|
||||
List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
|
||||
if (results.size() == 0) {
|
||||
|
||||
SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',0)");
|
||||
}else {
|
||||
msg.append(rev).append(" 的物料编码 ").append(id).append(" 已存在,请检查相关属性值\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
String dno = id.toString();
|
||||
rev.setProperty("j6_wlbm", dno);
|
||||
if(map.containsKey("rev.j6_wlbm")) {
|
||||
impTable.setValueAt(dno, i, map.get("rev.j6_wlbm"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(norule) {
|
||||
msg.append(rev).append(" 无满足条件的规则,无法申请物料编码 ");
|
||||
}
|
||||
norule = true;
|
||||
}
|
||||
if(msg.length()>0)
|
||||
MessageBox.post(WlbmApplyDialog.this, "以下对象物料编码申请遇到问题,请检查:\n" + msg, "提示", MessageBox.WARNING);
|
||||
else
|
||||
MessageBox.post(WlbmApplyDialog.this, "物料编码申请完成!", "提示", MessageBox.INFORMATION);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
MessageBox.post(WlbmApplyDialog.this, "错误:" + e1.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
}finally {
|
||||
SqlUtil.freeAll();
|
||||
SqlTIUtil.freeAll();
|
||||
}
|
||||
}
|
||||
});
|
||||
closeBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
package com.connor.jingdiao.handlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
|
||||
import com.teamcenter.rac.aif.AIFDesktop;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class WlbmApplyHandler extends AbstractHandler implements IHandler{
|
||||
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
System.out.println("DrawingNoApplyHandler");
|
||||
TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession();
|
||||
AIFDesktop desktop = AIFUtility.getActiveDesktop();
|
||||
try {
|
||||
// TCComponent
|
||||
String typeName = "";
|
||||
List<String> typeList = new ArrayList<String>();
|
||||
typeList.add("Part");
|
||||
typeList.add("J6_PRODUCT");
|
||||
typeList.add("J6_FUNCTIONASS");
|
||||
typeList.add("J6_DQPart");
|
||||
typeList.add("J6_WGPart");
|
||||
typeList.add("J6_VMPART");
|
||||
typeList.add("J6_GZPart");
|
||||
InterfaceAIFComponent[] targets = AIFUtility.getCurrentApplication().getTargetComponents();
|
||||
for(InterfaceAIFComponent t : targets) {
|
||||
|
||||
if(t instanceof TCComponentItemRevision) {
|
||||
TCComponentItemRevision revision = (TCComponentItemRevision) t;
|
||||
String type = revision.getItem().getType();
|
||||
System.out.println("type==>"+type);
|
||||
if(!typeList.contains(type)) {
|
||||
MessageBox.post(desktop, "选中对象"+t+"不是物料版本类型,无法申请物料编码!", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
typeName = type;
|
||||
}else if(t.getType().contains("J6_FUNCTIONASS")) {
|
||||
typeName = "J6_FUNCTIONASS";
|
||||
}
|
||||
else {
|
||||
MessageBox.post(desktop, "选中对象"+t+"不是物料版本类型,无法申请物料编码!", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
// if(!t.getType().equals("Design Revision")) {
|
||||
// //判断是否为
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
String ruleNameString = "Jd_Code_Rule_"+typeName;
|
||||
|
||||
String tables[] = session.getPreferenceService().getStringValues("Jd_Code_Table_Design"); //表头配置
|
||||
if(tables==null || tables.length==0) {
|
||||
MessageBox.post(desktop, "首选项配置Jd_Code_Table_Design不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
String options[] = session.getPreferenceService().getStringValues(ruleNameString); //编码规则配置
|
||||
if(options == null || options.length == 0) {
|
||||
MessageBox.post(desktop, "首选项"+ruleNameString+"配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
String sqlOptions[] = session.getPreferenceService().getStringValues("Jd_TC_Info_Connect"); //tc数据库链接
|
||||
if(sqlOptions==null || sqlOptions.length<4) {
|
||||
MessageBox.post(desktop, "首选项Jd_TC_Info_Connect配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
String sqlOptionsTI[] = session.getPreferenceService().getStringValues("Jd_TICODE_Info_Connect"); //TI数据库链接
|
||||
if(sqlOptionsTI==null || sqlOptionsTI.length<4) {
|
||||
MessageBox.post(desktop, "首选项Jd_TICODE_Info_Connect配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
String productClass[] = session.getPreferenceService().getStringValues("Jd_Code_Product_Class"); //TI数据库链接
|
||||
if(productClass==null || productClass.length==0) {
|
||||
MessageBox.post(desktop, "首选项Jd_Code_Product_Class配置不正确", "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
new WlbmApplyDialog(session, tables, options, sqlOptions, targets,sqlOptionsTI,productClass);
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,349 @@
|
||||
package com.connor.jingdiao.util;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.commands.open.OpenFormDialog;
|
||||
import com.teamcenter.rac.kernel.ListOfValuesInfo;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentBOMLine;
|
||||
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
|
||||
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
|
||||
import com.teamcenter.rac.kernel.TCComponentContextList;
|
||||
import com.teamcenter.rac.kernel.TCComponentDataset;
|
||||
import com.teamcenter.rac.kernel.TCComponentDatasetType;
|
||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentListOfValues;
|
||||
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
|
||||
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
|
||||
import com.teamcenter.rac.kernel.TCComponentQuery;
|
||||
import com.teamcenter.rac.kernel.TCComponentQueryType;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCQueryClause;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class TCUtil {
|
||||
public static final int MINWIDTH = 1280;
|
||||
public static final int MINHEIGHT = 768;
|
||||
|
||||
public static void fitToScreen(AbstractAIFDialog abstractAIFDialog) {
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
double screenWidth = screenSize.getWidth();
|
||||
double screenHeight = screenSize.getHeight();
|
||||
Dimension dialogSize = abstractAIFDialog.getSize();
|
||||
if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
|
||||
abstractAIFDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
|
||||
abstractAIFDialog.setLocation(10, (int) Math.floor(abstractAIFDialog.getLocation().getY()));
|
||||
}
|
||||
if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
|
||||
abstractAIFDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
|
||||
abstractAIFDialog.setLocation((int) Math.floor(abstractAIFDialog.getLocation().getX()), 10);
|
||||
}
|
||||
/*
|
||||
* if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
|
||||
* MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new
|
||||
* Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
|
||||
* abstractAIFDialog.setLocation(10, 10); }
|
||||
*/
|
||||
}
|
||||
|
||||
public static void fitToScreen(OpenFormDialog openFormDialog) {
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
double screenWidth = screenSize.getWidth();
|
||||
double screenHeight = screenSize.getHeight();
|
||||
Dimension dialogSize = openFormDialog.getSize();
|
||||
if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
|
||||
openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
|
||||
openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY()));
|
||||
}
|
||||
if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
|
||||
openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
|
||||
openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10);
|
||||
}
|
||||
/*
|
||||
* if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
|
||||
* MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new
|
||||
* Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
|
||||
* openFormDialog.setLocation(10, 10); }
|
||||
*/
|
||||
}
|
||||
|
||||
public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{
|
||||
TCComponentBOMWindow window = null;
|
||||
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
|
||||
window = bomWinType.create(null);
|
||||
return window;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision)
|
||||
throws Exception {
|
||||
window.lock();
|
||||
TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null);
|
||||
window.save();
|
||||
window.unlock();
|
||||
return bomLine;
|
||||
}
|
||||
public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation)
|
||||
throws Exception {
|
||||
TCComponentPseudoFolder pseudoFolder = null;
|
||||
AIFComponentContext[] comps = parent.getChildren();
|
||||
if (comps != null && comps.length > 0 && comps[0] != null) {
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
TCComponent comp = (TCComponent) comps[i].getComponent();
|
||||
if (comp instanceof TCComponentPseudoFolder) {
|
||||
if (comp.isTypeOf("PseudoFolder")) {
|
||||
// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation());
|
||||
if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) {
|
||||
pseudoFolder = (TCComponentPseudoFolder) comp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return pseudoFolder;
|
||||
}
|
||||
public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception {
|
||||
if (revision != null) {
|
||||
AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev");
|
||||
if (contexts != null && contexts.length > 0) {
|
||||
InterfaceAIFComponent component = contexts[0].getComponent();
|
||||
if (component instanceof TCComponentForm) {
|
||||
return (TCComponentForm) component;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, String> getlovValues(TCSession session, String lovName) throws TCException {
|
||||
LinkedHashMap<String, String> lovVal = new LinkedHashMap<String, String>();
|
||||
TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues");
|
||||
TCComponentListOfValues[] lovs = lovType.find(lovName);
|
||||
if (lovs != null && lovs.length > 0) {
|
||||
TCComponentListOfValues lov = lovs[0];
|
||||
ListOfValuesInfo lovInfo = lov.getListOfValues();
|
||||
String[] code = lovInfo.getStringListOfValues();
|
||||
String[] name = lovInfo.getLOVDisplayValues();
|
||||
if (code != null && name != null) {
|
||||
for (int i = 0; i < code.length; i++) {
|
||||
// System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]);
|
||||
lovVal.put(code[i], name[i]);
|
||||
}
|
||||
}
|
||||
return lovVal;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getTableValue(JTable table, int row, int col){
|
||||
Object val = table.getValueAt(row, col);
|
||||
if(val==null)
|
||||
return "";
|
||||
else
|
||||
return val.toString();
|
||||
}
|
||||
public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception {
|
||||
TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
|
||||
TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName);
|
||||
if (imancomponentquery == null) {
|
||||
throw new Exception("未找到查询构建器 " + queryName + "!");
|
||||
}
|
||||
aKey = session.getTextService().getTextValues(aKey);
|
||||
// for (int i = 0; i < aKey.length; i++) {
|
||||
// System.out.println(aKey[i] + "===============" + aVal[i]);
|
||||
// }
|
||||
TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal);
|
||||
return componentContextList.toTCComponentArray();
|
||||
}
|
||||
public static TCComponent[] query(TCSession session, String queryName, Vector<String> Keys, Vector<String> Vals) throws Exception {
|
||||
TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
|
||||
TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName);
|
||||
if (imancomponentquery == null) {
|
||||
System.out.println("未找到查询构建器" + queryName);
|
||||
throw new Exception("Query:"+queryName+" cannot find");
|
||||
}
|
||||
TCQueryClause[] qc = imancomponentquery.describe();
|
||||
// Map<String, String> clauseMap = new HashMap<>();
|
||||
for(TCQueryClause c : qc) {
|
||||
String key = c.getUserEntryNameDisplay();
|
||||
String value = c.getDefaultValue();
|
||||
// System.out.println(key + "==>" + c.getAttributeName());
|
||||
if(!value.trim().isEmpty() && !Keys.contains(key)) {
|
||||
if(key.isEmpty())
|
||||
Keys.add(c.getAttributeName());
|
||||
else
|
||||
Keys.add(key);
|
||||
Vals.add(value);
|
||||
}
|
||||
}
|
||||
int size = Keys.size();
|
||||
String[] keyA = new String[size];
|
||||
String[] valueA = new String[size];
|
||||
for(int i=0; i<size; i++) {
|
||||
keyA[i] = Keys.get(i);
|
||||
valueA[i] = Vals.get(i);
|
||||
System.out.println(keyA[i] + ":" + valueA[i]);
|
||||
}
|
||||
TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(keyA, valueA);
|
||||
return componentContextList.toTCComponentArray();
|
||||
}
|
||||
public static String getSerialNo(TCSession session, String itemId, String objectType) throws Exception {
|
||||
TCComponent[] comps = null;
|
||||
if (objectType.equals("")) {
|
||||
comps = query(session, "零组件 ID", new String[] { "ItemID" }, new String[] { itemId + "*" });
|
||||
} else {
|
||||
comps = query(session, "零组件...", new String[] { "ItemID", "Type" }, new String[] { itemId + "*", objectType });
|
||||
}
|
||||
// System.out.println("getSerialNo comps.len:" + (comps == null ? 0 : comps.length));
|
||||
if (comps.length > 0) {
|
||||
Integer maxId = 0;
|
||||
for (TCComponent comp : comps) {
|
||||
String pid = comp.getProperty("item_id");
|
||||
System.out.println("pid:" + pid);
|
||||
String pidSuffix = pid.substring(pid.length() - 3);
|
||||
if (Integer.parseInt(pidSuffix) > maxId) {
|
||||
maxId = Integer.parseInt(pidSuffix);
|
||||
}
|
||||
}
|
||||
return String.format("%03d", maxId + 1);
|
||||
}
|
||||
return "001";
|
||||
}
|
||||
|
||||
public static File saveExcelChooser() {
|
||||
File dir = null;
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setAcceptAllFileFilterUsed(false);
|
||||
// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory();
|
||||
File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
|
||||
chooser.setCurrentDirectory(desktopDir);
|
||||
String saveType[] = { "xlsx" };
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType));
|
||||
int returnVal = chooser.showSaveDialog(new Frame());
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
dir = chooser.getSelectedFile();
|
||||
String path = dir.getPath();
|
||||
if(!path.toLowerCase().endsWith(".xlsx")) {
|
||||
path += ".xlsx";
|
||||
dir = new File(path);
|
||||
}
|
||||
System.out.println("saveExcelChooser1:" + path);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static File saveExcelChooser(Window parent, String defaultFile) {
|
||||
File dir = null;
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setAcceptAllFileFilterUsed(false);
|
||||
// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory();
|
||||
File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
|
||||
chooser.setCurrentDirectory(desktopDir);
|
||||
chooser.setSelectedFile(new File(defaultFile));
|
||||
String saveType[] = { "xlsx" };
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType));
|
||||
int returnVal = chooser.showSaveDialog(new JDialog(parent));
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
dir = chooser.getSelectedFile();
|
||||
String path = dir.getPath();
|
||||
if(!path.toLowerCase().endsWith(".xlsx")) {
|
||||
path += ".xlsx";
|
||||
dir = new File(path);
|
||||
}
|
||||
if(dir.exists())
|
||||
dir.delete();
|
||||
// System.out.println("saveExcelChooser1:" + dir.getPath());
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static boolean contains(String[] array, String str) {
|
||||
for(String s : array) {
|
||||
// System.out.println("contains:"+s+"="+str);
|
||||
if(s.equals(str))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Map<String, String> executeToMap(InputStream in){
|
||||
System.out.println("Read properties file");
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
||||
String line = null;
|
||||
Map<String, String> resultMap = new LinkedHashMap<>(16);
|
||||
if (reader.ready()) {
|
||||
while (null != (line = reader.readLine())) {
|
||||
if (line.length() <= 0 || line.startsWith("#") || !line.contains("=")) {
|
||||
continue;
|
||||
}
|
||||
resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1));
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
reader.close();
|
||||
return resultMap;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception {
|
||||
String refType = null, objType = null, fileName = null;
|
||||
fileName = file.getName().toLowerCase();
|
||||
if (fileName.endsWith("xls")) {
|
||||
refType = "excel";
|
||||
objType = "MSExcel";
|
||||
} else if (fileName.endsWith("xlsx")) {
|
||||
refType = "excel";
|
||||
objType = "MSExcelX";
|
||||
}
|
||||
TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset");
|
||||
TCComponentDataset dataset = compType.create(datasetName, "description", objType);
|
||||
dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType });
|
||||
return dataset;
|
||||
}
|
||||
|
||||
public static Vector<TCComponent> getChildren(TCComponent parent, String relation, String name) throws Exception {
|
||||
Vector<TCComponent> result = new Vector<>();
|
||||
AIFComponentContext[] children;
|
||||
if(relation==null || relation.isEmpty())
|
||||
children = parent.getChildren();
|
||||
else
|
||||
children = parent.getChildren(relation);
|
||||
for(AIFComponentContext c : children) {
|
||||
TCComponent comp = (TCComponent) c.getComponent();
|
||||
if(comp.getProperty("object_name").equals(name))
|
||||
result.add(comp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setByPass(boolean b) {
|
||||
// KUtil.setByPass(b);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
public class BomValBean {
|
||||
|
||||
private String bl_czbh;
|
||||
private String bl_jdjz;
|
||||
|
||||
private String bl_quantity;
|
||||
public String getBl_quantity() {
|
||||
return bl_quantity;
|
||||
}
|
||||
public void setBl_quantity(String bl_quantity) {
|
||||
this.bl_quantity = bl_quantity;
|
||||
}
|
||||
public String getBl_czbh() {
|
||||
return bl_czbh;
|
||||
}
|
||||
public void setBl_czbh(String bl_czbh) {
|
||||
this.bl_czbh = bl_czbh;
|
||||
}
|
||||
public String getBl_jdjz() {
|
||||
return bl_jdjz;
|
||||
}
|
||||
public void setBl_jdjz(String bl_jdjz) {
|
||||
this.bl_jdjz = bl_jdjz;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BomValBean [bl_czbh=" + bl_czbh + ", bl_jdjz=" + bl_jdjz + ", bl_quantity=" + bl_quantity + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,30 @@
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
|
||||
|
||||
public class DbomTransitionToEbomHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
// TODO Auto-generated method stub
|
||||
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
try {
|
||||
DbomTransitionToEbomCommand command = new DbomTransitionToEbomCommand(app.getTargetComponent(),session);
|
||||
command.executeModal();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,267 @@
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
//import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JButton;
|
||||
//import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
|
||||
public class DbomTransitionToEbomSearchDialog extends AbstractAIFDialog {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
// private TCSession session;
|
||||
private DbomTransitionToEbomDialog parent;
|
||||
private JTable impTable;
|
||||
private DefaultTableModel impModel;
|
||||
private Map<String, JTextField> searchMap;
|
||||
private JButton addBtn;
|
||||
private JButton delBtn;
|
||||
private JButton searchBtn;
|
||||
private JButton okBtn;
|
||||
private JButton cancelBtn;
|
||||
public String codeID;
|
||||
|
||||
public DbomTransitionToEbomSearchDialog(TCSession session, DbomTransitionToEbomDialog parent, String[] head, String[][] tags) {
|
||||
super(parent, true);
|
||||
// this.session = session;
|
||||
this.parent = parent;
|
||||
searchMap = new LinkedHashMap<>();
|
||||
|
||||
String[] tableHeader = new String[] { "AND/OR", "属性名称", "运算符", "搜索值" };
|
||||
int size = tableHeader.length;
|
||||
|
||||
impModel = new DefaultTableModel(tableHeader, 0);
|
||||
impTable = new JTable() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
if(row == 0 && col == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public TableCellRenderer getCellRenderer(int row, int column) {
|
||||
return super.getCellRenderer(row, column);
|
||||
}
|
||||
};
|
||||
impModel.setDataVector(tags, tableHeader);
|
||||
impTable.getTableHeader().setReorderingAllowed(false);
|
||||
impTable.setFillsViewportHeight(true);
|
||||
impTable.setEnabled(true);
|
||||
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
impTable.setModel(impModel);
|
||||
int[] widths = { 100, 100, 80, 150 };
|
||||
TableColumnModel colModel = impTable.getColumnModel();
|
||||
for (int i = 0; i < size; i++) {
|
||||
colModel.getColumn(i).setPreferredWidth(widths[i]);
|
||||
}
|
||||
String[][] comboBoxItems = {{ "AND", "OR" }, head, { "=", "==", "!=" }, { "已勾选", "未勾选" }}; // 下拉框选项列表
|
||||
for(int i = 0; i < comboBoxItems.length; i++) {
|
||||
TableColumn column = colModel.getColumn(i); // 获取第三列模型对象
|
||||
// JComboBox<Object> comboBox = new JComboBox<>(comboBoxItems[i]);
|
||||
// comboBox.setEditable(i == comboBoxItems.length - 1);
|
||||
// column.setCellEditor(new DefaultCellEditor(comboBox));
|
||||
column.setCellEditor(new TableCellComboBoxEditor(comboBoxItems[i], i == comboBoxItems.length - 1));
|
||||
column.setCellRenderer(new DefaultTableCellRenderer());
|
||||
// 设置编辑器到第三列模型对象上,这将允许在该列编辑时显示下拉框。如果你也想设置渲染器:
|
||||
// column.setCellRenderer(new TableCellComboBoxRenderer(comboBoxItems[i]));
|
||||
// 设置渲染器到第三列模型对象上,这将允许在该列显示时显示下拉框。
|
||||
}
|
||||
impTable.setRowHeight(25);
|
||||
impTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
|
||||
// Container container = myframe.getContentPane();
|
||||
JPanel CPanel = new JPanel(new BorderLayout(10, 10));
|
||||
CPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
// JPanel leftPanel = new JPanel(new BorderLayout(10, 10));
|
||||
JPanel msgPanel = new JPanel(new GridLayout(10,2,10,10));
|
||||
for(Entry<String, JTextField> e : searchMap.entrySet()) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(BorderLayout.WEST, new JLabel(e.getKey()+" "));
|
||||
panel.add(BorderLayout.EAST, e.getValue());
|
||||
msgPanel.add(panel);
|
||||
}
|
||||
// leftPanel.add(BorderLayout.NORTH, msgPanel);
|
||||
JPanel btnPanel = new JPanel(new FlowLayout());
|
||||
addBtn = new JButton("+");
|
||||
delBtn = new JButton("-");
|
||||
searchBtn = new JButton("搜索");
|
||||
okBtn = new JButton("确定");
|
||||
cancelBtn = new JButton("取消");
|
||||
btnPanel.add(addBtn);
|
||||
btnPanel.add(delBtn);
|
||||
btnPanel.add(searchBtn);
|
||||
btnPanel.add(okBtn);
|
||||
btnPanel.add(cancelBtn);
|
||||
// leftPanel.add(BorderLayout.SOUTH, btnPanel);
|
||||
JScrollPane tablePanel = new JScrollPane();
|
||||
tablePanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
||||
tablePanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
tablePanel.setViewportView(impTable);
|
||||
CPanel.add(BorderLayout.SOUTH, btnPanel);
|
||||
CPanel.add(BorderLayout.CENTER, tablePanel);
|
||||
this.add(CPanel);
|
||||
|
||||
addActionListener();
|
||||
|
||||
setSize(750, 600);
|
||||
//awtContainer.setSize(730, 570);
|
||||
Dimension screen = getToolkit().getScreenSize();
|
||||
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
|
||||
setAlwaysOnTop(true);
|
||||
setVisible(true);
|
||||
// open();
|
||||
}
|
||||
|
||||
public void run(){
|
||||
showDialog();
|
||||
}
|
||||
|
||||
private void addActionListener() {
|
||||
addBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if(impTable.getRowCount() > 0)
|
||||
impModel.addRow(new String[] { "AND" });
|
||||
else
|
||||
impModel.addRow(new String[] { "" });
|
||||
}
|
||||
});
|
||||
//final Shell dialog = shell;
|
||||
delBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if(impTable.getRowCount() == 0)
|
||||
return;
|
||||
int[] rows = impTable.getSelectedRows();
|
||||
if(rows.length == 0)
|
||||
return;
|
||||
if(impTable.getCellEditor() != null)
|
||||
impTable.getCellEditor().stopCellEditing();
|
||||
for(int i = rows.length - 1; i >= 0; i--) {
|
||||
impModel.removeRow(rows[i]);
|
||||
if(rows[i] == 0 && impTable.getRowCount() > 0)
|
||||
impTable.setValueAt("", 0, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
searchBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if(impTable.getCellEditor() != null)
|
||||
impTable.getCellEditor().stopCellEditing();
|
||||
ArrayList<String[]> list = new ArrayList<>();
|
||||
for(int i = 0, len = impTable.getRowCount(); i < len; i++) {
|
||||
String[] val = new String[4];
|
||||
for(int j = 0; j < 4; j++)
|
||||
val[j] = "" + impTable.getValueAt(i, j);
|
||||
list.add(val);
|
||||
}
|
||||
String[][] tags = list.toArray(new String[0][0]);
|
||||
parent.search(tags);
|
||||
}
|
||||
});
|
||||
|
||||
okBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
/*
|
||||
int[] selected = impTable.getSelectedRows();
|
||||
if(selected==null || selected.length==0) {
|
||||
MessageBox.post(CodeIDDialog.this, "请搜索并选择零部件", "ERROR", MessageBox.ERROR);
|
||||
return;
|
||||
}
|
||||
parent.codeID = impTable.getValueAt(selected[0], codeCol).toString();
|
||||
// new Thread() {
|
||||
// public void run() {
|
||||
// combo.setText(text.replace("[CodeID]", codeID));
|
||||
// }
|
||||
// }.start();
|
||||
final String text = "[CodeID]<---->"+parent.codeID;
|
||||
final int w = new JLabel(text).getPreferredSize().width+10;
|
||||
|
||||
Display display = Display.getDefault();
|
||||
display.asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
// String text = combo.getText().replaceAll("", "");
|
||||
combo.add(text);
|
||||
combo.setText(text);
|
||||
Rectangle r = combo.getBounds();
|
||||
combo.setBounds(r.x, r.y, w, r.height);
|
||||
combo.getParent().redraw();
|
||||
System.out.println("Text:"+combo.getText());
|
||||
parent.updateMap(false);
|
||||
// shell.getDisplay().sleep();
|
||||
// shell.close();
|
||||
// display.sleep();
|
||||
}
|
||||
});*/
|
||||
dispose();
|
||||
// while (!display.isDisposed()) {
|
||||
// // Always gives a thread access error, but still calls async event:
|
||||
// if (!display.readAndDispatch())
|
||||
// display.sleep();
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
cancelBtn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
// Display.getDefault().asyncExec(new Runnable() {
|
||||
// public void run() {
|
||||
// parent.updateMap(false);
|
||||
//// shell.getDisplay().sleep();
|
||||
//// shell.close();
|
||||
//// display.sleep();
|
||||
// }
|
||||
// });
|
||||
// parent.updateMap(false);
|
||||
dispose();
|
||||
// shell.getDisplay().sleep();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception {
|
||||
if (revision != null) {
|
||||
AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev");
|
||||
if (contexts != null && contexts.length > 0) {
|
||||
InterfaceAIFComponent component = contexts[0].getComponent();
|
||||
if (component instanceof TCComponentForm) {
|
||||
return (TCComponentForm) component;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
import org.jdesktop.swingx.JXTreeTable;
|
||||
|
||||
import com.connor.ml.tcm.outfile.bean.NodeBean;
|
||||
|
||||
public class JTreeTable extends JXTreeTable {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private List<Integer> isNotEditableRow;
|
||||
//CheckBoxCellEditor checkBoxCellEditor = new CheckBoxCellEditor(this);
|
||||
private TableCellCheckboxRenderer checkboxRenderer = new TableCellCheckboxRenderer(this);
|
||||
|
||||
public List<Integer> getIsNotEditableRow() {
|
||||
return isNotEditableRow;
|
||||
}
|
||||
|
||||
public void setIsNotEditableRow(List<Integer> isNotEditableRow) {
|
||||
this.isNotEditableRow = isNotEditableRow;
|
||||
}
|
||||
|
||||
public JTreeTable(JTreeTableModel testTreeTableModel) {
|
||||
// Auto-generated constructor stub
|
||||
super(testTreeTableModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int arg0, int arg1) {
|
||||
// Auto-generated method stub
|
||||
return true;//super.isCellEditable(arg0, arg1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableCellEditor getCellEditor(int row, int column) {
|
||||
// Auto-generated method stub
|
||||
//if(isNotEditableRow.contains(row) && column == 2)
|
||||
|
||||
|
||||
return cellEditor;
|
||||
//return super.getCellEditor(row, column);
|
||||
}
|
||||
|
||||
public String getToolTipText(MouseEvent e) {
|
||||
int row = this.rowAtPoint(e.getPoint());
|
||||
int col = this.columnAtPoint(e.getPoint());
|
||||
String tiptextString = null;
|
||||
if (row > -1 && col > -1) {
|
||||
Object value = this.getValueAt(row, col);
|
||||
if (null != value && !"".equals(value))
|
||||
tiptextString = value.toString();// 技륫鞫刻데禱목코휭
|
||||
}
|
||||
return tiptextString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableCellRenderer getCellRenderer(int row, int column) {
|
||||
// Auto-generated method stub
|
||||
Object val = getValueAt(row, NodeBean.LABEL);
|
||||
if(column == NodeBean.LABEL && val != null && (val.equals("0") || val.equals("1")))
|
||||
{
|
||||
return checkboxRenderer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.getCellRenderer(row, column);
|
||||
}
|
||||
}
|
||||
|
||||
// 茶꾜죗
|
||||
public void HiddenCell(int column) {
|
||||
TableColumn tc = this.getTableHeader().getColumnModel()
|
||||
.getColumn(column);
|
||||
tc.setMaxWidth(0);
|
||||
tc.setPreferredWidth(0);
|
||||
tc.setWidth(0);
|
||||
tc.setMinWidth(0);
|
||||
this.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0);
|
||||
this.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
|
||||
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
|
||||
import org.jdesktop.swingx.treetable.TreeTableNode;
|
||||
|
||||
import com.connor.ml.tcm.outfile.bean.NodeBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author vearn
|
||||
*/
|
||||
public class JTreeTableModel extends DefaultTreeTableModel {
|
||||
|
||||
private String[] _names = { "DBOM对象", "EBOM对象","选中", "EBOMID", "物料描述","数量","发布状态","对应父节点"};
|
||||
|
||||
|
||||
private List<Integer> isNotEditableRow;
|
||||
|
||||
|
||||
|
||||
public JTreeTableModel(TreeTableNode node, String[] names) {
|
||||
super(node);
|
||||
|
||||
_names = names;
|
||||
}
|
||||
|
||||
|
||||
public List<Integer> getIsNotEditableRow() {
|
||||
return isNotEditableRow;
|
||||
}
|
||||
|
||||
public void setIsNotEditableRow(List<Integer> isNotEditableRow) {
|
||||
this.isNotEditableRow = isNotEditableRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列的数量
|
||||
*/
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return _names.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表头显示的内容
|
||||
*/
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
return _names[column];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回在单元格中显示的Object
|
||||
*/
|
||||
@Override
|
||||
public Object getValueAt(Object node, int column) {
|
||||
Object value = null;
|
||||
if (node instanceof DefaultMutableTreeTableNode) {
|
||||
DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node;
|
||||
Object o = mutableNode.getUserObject();
|
||||
if (o != null && o instanceof NodeBean) {
|
||||
NodeBean bean = (NodeBean) o;
|
||||
value = bean.getValueAt(column);
|
||||
if(column == NodeBean.LABEL && value.equals("3")) {
|
||||
value = "";
|
||||
}
|
||||
// if(column > 4)
|
||||
// System.out.println("getValueAt" + column + "==" + value);
|
||||
/*switch (column) {
|
||||
case 0:
|
||||
value = bean.getDbom();
|
||||
break;
|
||||
case 1:
|
||||
value = bean.getEbom();
|
||||
break;
|
||||
case 2:
|
||||
value = bean.getLabel();
|
||||
if(value.equals("3")) {
|
||||
value = "";
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
value = bean.getEbomId();
|
||||
break;
|
||||
case 4:
|
||||
value = bean.getEbomDesc();
|
||||
break;
|
||||
case 5:
|
||||
value = bean.getNum();
|
||||
break;
|
||||
case 6:
|
||||
value = bean.getRefreshStatus();
|
||||
break;
|
||||
case 7:
|
||||
value = bean.getParentString();
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置所有单元格都不能编辑
|
||||
*
|
||||
* @param the node (i.e. row) for which editing is to be determined
|
||||
* @param the column for which editing is to be determined
|
||||
* @return false
|
||||
*/
|
||||
@Override
|
||||
public boolean isCellEditable(Object node, int column) {
|
||||
//if(column == 5)
|
||||
//{
|
||||
return true;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.EventListenerList;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
|
||||
public class TableCellCheckboxRenderer extends JCheckBox implements
|
||||
TableCellRenderer {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private List<Integer> processRows;
|
||||
protected EventListenerList listenerList = new EventListenerList();
|
||||
protected ChangeEvent changeEvent = new ChangeEvent(this);
|
||||
//private TestTreeTableModel tableModel;
|
||||
|
||||
public List<Integer> getProcessRows() {
|
||||
return processRows;
|
||||
}
|
||||
|
||||
public void setProcessRows(List<Integer> processRows) {
|
||||
this.processRows = processRows;
|
||||
|
||||
}
|
||||
|
||||
public TableCellCheckboxRenderer(final JTreeTable table) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
// TODO Auto-generated method stub
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);// ±íÍ·±êÇ©¾çÖÐ
|
||||
this.setBorderPainted(true);
|
||||
|
||||
if(value != null)
|
||||
{
|
||||
// if(value.toString().equals("1"))
|
||||
// {
|
||||
// if(table.getColumnName(column).equals("¸ÄÖÆ") && hasFocus)
|
||||
// {
|
||||
// if(table.getValueAt(row, column + 1).toString().equals("1"))
|
||||
// {
|
||||
// table.setValueAt(0, row, column + 1);
|
||||
// }
|
||||
// }
|
||||
// else if(table.getColumnName(column).equals("ɾ³ý") && hasFocus)
|
||||
// {
|
||||
// if(table.getValueAt(row, column - 1).toString().equals("1"))
|
||||
// {
|
||||
// table.setValueAt(0, row, column - 1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(value.toString().equals("1"))
|
||||
// {
|
||||
// System.out.println(value.toString().equals("1") + "====");
|
||||
// }
|
||||
this.setSelected(value.toString().equals("1"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setSelected(false);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.DefaultCellEditor;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
|
||||
public class TableCellComboBoxEditor extends DefaultCellEditor implements TableCellEditor {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JComboBox<Object> comboBox;
|
||||
// private Object value;
|
||||
private JTable table;
|
||||
private int row;
|
||||
private int column;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public TableCellComboBoxEditor(Object[] items, boolean editable) {
|
||||
super(new JComboBox<>(items));
|
||||
comboBox = (JComboBox<Object>) getComponent();
|
||||
comboBox.setEditable(editable);
|
||||
comboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// System.out.println("action1£º" + comboBox.getSelectedItem());
|
||||
fireEditingStopped();
|
||||
// System.out.println("action2£º" + comboBox.getSelectedItem());
|
||||
if(table != null)
|
||||
table.setValueAt(comboBox.getSelectedItem(), row, column);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
|
||||
// System.out.println("getTableCellEditorComponent1£º" + comboBox.getSelectedItem() + "==" + value);
|
||||
this.table = table;
|
||||
this.row = row;
|
||||
this.column = column;
|
||||
if(value == null)
|
||||
comboBox.setSelectedItem("");
|
||||
else
|
||||
comboBox.setSelectedItem(value);
|
||||
// this.value = value;
|
||||
// System.out.println("getTableCellEditorComponent2£º" + comboBox.getSelectedItem() + "==" + table.getValueAt(row, column));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCellEditorValue() {
|
||||
return comboBox.getSelectedItem();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package com.connor.ml.tcm.outfile.ML_010;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
String s = "11111112-32222222-4444";
|
||||
System.out.println(s.substring(0, s.indexOf("-")));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.connor.ml.tcm.outfile.bean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
|
||||
|
||||
import com.connor.ml.tcm.outfile.ML_010.BomValBean;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentBOMLine;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author vearn
|
||||
*/
|
||||
public class NodeBean {
|
||||
|
||||
private String dbom;//对象ID
|
||||
private String ebom;//对象名称
|
||||
// private String ebomId;//对象名称
|
||||
// private String ebomDesc;//物料描述
|
||||
private String num;//数量
|
||||
private String label;//对象名称
|
||||
private String refreshStatus;//发布状态
|
||||
private String parentString;//对应父节点
|
||||
// private String bl_plmxml_abs_xform ;//绝对变换矩阵
|
||||
private TCComponentItemRevision pRev;//对应父节点
|
||||
private TCComponentItemRevision rev;//对应父节点
|
||||
private TCComponent tcComponent;
|
||||
private Boolean isTw = false;
|
||||
private DefaultMutableTreeTableNode rootNode;
|
||||
private Map<TCComponentItemRevision, List<BomValBean>> bomValMap = new HashMap<TCComponentItemRevision, List<BomValBean>>();
|
||||
|
||||
public static int DBOM = 0;
|
||||
public static int PARENT = 1;
|
||||
public static int EBOM = 2;
|
||||
public static int STATUS = 3;
|
||||
public static int LABEL = 4;
|
||||
|
||||
private HashMap<Integer, String> values = new HashMap<>();
|
||||
private TCComponentBOMLine bomLine;
|
||||
|
||||
public Boolean getIsTw() {
|
||||
return isTw;
|
||||
}
|
||||
public DefaultMutableTreeTableNode getRootNode() {
|
||||
return rootNode;
|
||||
}
|
||||
public void setRootNode(DefaultMutableTreeTableNode rootNode) {
|
||||
this.rootNode = rootNode;
|
||||
}
|
||||
public void setIsTw(Boolean isTw) {
|
||||
this.isTw = isTw;
|
||||
}
|
||||
public TCComponent getTcComponent() {
|
||||
return tcComponent;
|
||||
}
|
||||
public void setTcComponent(TCComponent tcComponent) {
|
||||
this.tcComponent = tcComponent;
|
||||
}
|
||||
public TCComponentItemRevision getRev() {
|
||||
return rev;
|
||||
}
|
||||
public void setRev(TCComponentItemRevision rev) {
|
||||
this.rev = rev;
|
||||
}
|
||||
public TCComponentItemRevision getpRev() {
|
||||
return pRev;
|
||||
}
|
||||
public Map<TCComponentItemRevision, List<BomValBean>> getBomValMap() {
|
||||
return bomValMap;
|
||||
}
|
||||
public void setBomValMap(Map<TCComponentItemRevision, List<BomValBean>> bomValMap) {
|
||||
this.bomValMap = bomValMap;
|
||||
}
|
||||
public void setpRev(TCComponentItemRevision pRev) {
|
||||
this.pRev = pRev;
|
||||
}
|
||||
// public String getBl_plmxml_abs_xform() {
|
||||
// return bl_plmxml_abs_xform;
|
||||
// }
|
||||
// public void setBl_plmxml_abs_xform(String bl_plmxml_abs_xform) {
|
||||
// this.bl_plmxml_abs_xform = bl_plmxml_abs_xform;
|
||||
// }
|
||||
|
||||
public String getDbom() {//0
|
||||
return dbom;
|
||||
}
|
||||
public void setDbom(String dbom) {//0
|
||||
this.dbom = dbom;
|
||||
setValueAt(DBOM, dbom);
|
||||
}
|
||||
public String getEbom() {//1
|
||||
return ebom;
|
||||
}
|
||||
public void setEbom(String ebom) {//1
|
||||
this.ebom = ebom;
|
||||
setValueAt(EBOM, ebom);
|
||||
}
|
||||
public String getLabel() {//2
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {//2
|
||||
this.label = label;
|
||||
setValueAt(LABEL, label);
|
||||
}
|
||||
// public String getEbomId() {//3
|
||||
// return ebomId;
|
||||
// }
|
||||
// public void setEbomId(String ebomId) {//3
|
||||
// this.ebomId = ebomId;
|
||||
// }
|
||||
// public String getEbomDesc() {//4
|
||||
// return ebomDesc;
|
||||
// }
|
||||
// public void setEbomDesc(String ebomDesc) {//4
|
||||
// this.ebomDesc = ebomDesc;
|
||||
// }
|
||||
public String getNum() {//5
|
||||
return num;
|
||||
}
|
||||
public void setNum(String num) {//5
|
||||
this.num = num;
|
||||
}
|
||||
public String getRefreshStatus() {//6
|
||||
return refreshStatus;
|
||||
}
|
||||
public void setRefreshStatus(String refreshStatus) {//6
|
||||
this.refreshStatus = refreshStatus;
|
||||
setValueAt(STATUS, refreshStatus);
|
||||
}
|
||||
public String getParentString() {//7
|
||||
return parentString;
|
||||
}
|
||||
public void setParentString(String parentString) {//7
|
||||
this.parentString = parentString;
|
||||
setValueAt(PARENT, parentString);
|
||||
}
|
||||
|
||||
public String getValueAt(int i) {
|
||||
if(values.containsKey(i))
|
||||
return values.get(i);
|
||||
return "";
|
||||
}
|
||||
public void setValueAt(int i, String val) {
|
||||
values.put(i, val);
|
||||
}
|
||||
|
||||
public TCComponentBOMLine getBom() {
|
||||
return bomLine;
|
||||
}
|
||||
public void setBom(TCComponentBOMLine bomLine) {
|
||||
this.bomLine = bomLine;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return dbom + " >>> " + ebom + " == " + label;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,171 @@
|
||||
package com.connor.ml.tcm.outfile.util;
|
||||
|
||||
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;
|
||||
private String propName;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getPropName() {
|
||||
return propName;
|
||||
}
|
||||
|
||||
public void setPropName(String propName) {
|
||||
this.propName = propName;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue