diff --git a/cn.com.origin.autocode/.classpath b/cn.com.origin.autocode/.classpath index 3a847ac..4a1fd3d 100644 --- a/cn.com.origin.autocode/.classpath +++ b/cn.com.origin.autocode/.classpath @@ -1,5 +1,6 @@ + @@ -79,6 +80,7 @@ + diff --git a/cn.com.origin.autocode/META-INF/MANIFEST.MF b/cn.com.origin.autocode/META-INF/MANIFEST.MF index 81f8cdc..82263d6 100644 --- a/cn.com.origin.autocode/META-INF/MANIFEST.MF +++ b/cn.com.origin.autocode/META-INF/MANIFEST.MF @@ -913,4 +913,6 @@ Bundle-ClassPath: json_lib/commons-beanutils-1.7.0.jar, json_lib/fastjson-1.2.9-javadoc.jar, json_lib/fastjson-1.2.9-sources.jar, json_lib/fastjson-1.2.9.jar, - axis2_lib/hutool-all-5.0.7.jar + axis2_lib/hutool-all-5.0.7.jar, + aspose/aspose-cells-18.9.jar, + db_lib/ojdbc6.jar diff --git a/cn.com.origin.autocode/build.properties b/cn.com.origin.autocode/build.properties index ea8997e..07fb997 100644 --- a/cn.com.origin.autocode/build.properties +++ b/cn.com.origin.autocode/build.properties @@ -81,4 +81,6 @@ bin.includes = META-INF/,\ json_lib/fastjson-1.2.9-javadoc.jar,\ json_lib/fastjson-1.2.9-sources.jar,\ json_lib/fastjson-1.2.9.jar,\ - axis2_lib/hutool-all-5.0.7.jar + axis2_lib/hutool-all-5.0.7.jar,\ + aspose/aspose-cells-18.9.jar,\ + db_lib/ojdbc6.jar diff --git a/cn.com.origin.autocode/plugin.xml b/cn.com.origin.autocode/plugin.xml index c89ae98..76ef741 100644 --- a/cn.com.origin.autocode/plugin.xml +++ b/cn.com.origin.autocode/plugin.xml @@ -125,6 +125,7 @@ + + --> + + + true + + + + + --> @@ -234,6 +242,9 @@ + + @@ -263,6 +274,10 @@ class="cn.com.origin.autocode.handlers.AutoCodeNewItemFilterTypeHandler"> + + diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/DBUtil.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/DBUtil.java new file mode 100644 index 0000000..1473625 --- /dev/null +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/DBUtil.java @@ -0,0 +1,42 @@ +package cn.com.origin.autocode.handlers; + +import java.util.HashMap; +import java.util.Map; + +import javax.sql.DataSource; +import javax.swing.JOptionPane; + +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; + +import cn.hutool.db.ds.simple.SimpleDataSource; + +public class DBUtil { + + public static DataSource getDataSource(TCSession session) { + + Map settingMap = getDbSetting(session); + String str = settingMap.get("url") + settingMap.get("user") + settingMap.get("pass"); + DataSource dataSource = new SimpleDataSource(settingMap.get("url"), settingMap.get("user"), + settingMap.get("pass")); + return dataSource; + } + + private static Map getDbSetting(TCSession session) { + Map settingMap = null; + TCPreferenceService service = ((TCSession) AIFUtility.getCurrentApplication().getSession()) + .getPreferenceService(); + String[] dbSettings = service.getStringValues("jd2_db_settings"); + if (dbSettings.length != 3) { + JOptionPane.showMessageDialog(null, "jd2_db_settingsݿô", "", JOptionPane.ERROR); + } else { + settingMap = new HashMap(); + for (String s : dbSettings) { + settingMap.put(s.substring(0, s.indexOf(":")), s.substring(s.indexOf(":") + 1, s.length())); + } + } + return settingMap; + } + +} diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/ORItemSaveAsHandler.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/ORItemSaveAsHandler.java index 96a1d02..38c414b 100644 --- a/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/ORItemSaveAsHandler.java +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/ORItemSaveAsHandler.java @@ -1,193 +1,52 @@ package cn.com.origin.autocode.handlers; -import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; -import com.teamcenter.rac.commands.genericsaveas.ISaveAsService; -import com.teamcenter.rac.common.Activator; -import com.teamcenter.rac.kernel.*; -import com.teamcenter.rac.ui.commands.handlers.SaveASHandler; -import com.teamcenter.rac.util.*; -import com.teamcenter.rac.util.wizard.extension.*; -import java.text.MessageFormat; -import org.apache.log4j.Logger; -import org.eclipse.core.commands.*; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -public class ORItemSaveAsHandler extends AbstractHandler -{ - private class CreateSaveAsDialog - implements Runnable - { - - public void run() - { - BaseExternalWizard baseexternalwizard = getWizard(); - if(baseexternalwizard != null) - { - baseexternalwizard.setForcePreviousAndNextButtons(true); - ISaveAsService isaveasservice =(ISaveAsService)OSGIUtil.getService(Activator.getDefault(), ISaveAsService.class); - if(isaveasservice != null) - { - isaveasservice.setInput((TCComponent)m_selectedCmp); - baseexternalwizard.setWindowTitle(getWizardTitle()); - baseexternalwizard.setContext(new StructuredSelection(m_selectedCmp)); - Shell shell = UIUtilities.getCurrentModalShell(); - BaseExternalWizardDialog baseexternalwizarddialog = new BaseExternalWizardDialog(shell, baseexternalwizard); - baseexternalwizarddialog.create(); - ORItemSaveAsHandler.readDisplayParameters(baseexternalwizard, baseexternalwizarddialog); - Shell shell1 = baseexternalwizarddialog.getShell(); - UIUtilities.setCurrentModalShell(shell1); - baseexternalwizarddialog.open(); - UIUtilities.setCurrentModalShell(shell); - - } else - { - MessageBox.post(m_shell, Messages.getString("saveAsServiceNotAvailble.MEG"), Messages.getString("saveAs.TITLE"), 4); - } - } - } - - private final Shell m_shell; - final ORItemSaveAsHandler this$0; - - private CreateSaveAsDialog(Shell shell) - { - super(); - this$0 = ORItemSaveAsHandler.this; - m_shell = shell; - } - - CreateSaveAsDialog(Shell shell, CreateSaveAsDialog createsaveasdialog) - { - this(shell); - } - } - - - public ORItemSaveAsHandler() - { - } - - public Object execute(ExecutionEvent executionevent) - throws ExecutionException - { - ISelection iselection = HandlerUtil.getCurrentSelection(executionevent); - if(iselection instanceof StructuredSelection) - { - StructuredSelection structuredselection = (StructuredSelection)iselection; - if(structuredselection.size() != 1) - { - MessageBox.post(HandlerUtil.getActiveWorkbenchWindow(executionevent).getShell(), Messages.getString("toomanyObjects.MSG"), Messages.getString("saveAs.TITLE"), 4); - } else - { - m_selectedCmp = (InterfaceAIFComponent)AdapterUtil.getAdapter(iselection, InterfaceAIFComponent.class); - if(m_selectedCmp.getType().endsWith("HX3_WLRevision")){ - try { - m_selectedCmp =((TCComponentItemRevision)m_selectedCmp).getItem(); - } catch (TCException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - if(m_selectedCmp instanceof TCComponent) - { - Object aobj[] = { - ((TCComponent)m_selectedCmp).toDisplayString() - }; - m_selectedCmp = getUnderlyingComponent((TCComponent)m_selectedCmp); - if(m_selectedCmp != null) - { - Shell shell = HandlerUtil.getActiveShell(executionevent); - if(shell != null) - { - CreateSaveAsDialog createsaveasdialog = new CreateSaveAsDialog(shell, null); - createsaveasdialog.run(); - - } - } else - { - MessageBox.post(HandlerUtil.getActiveWorkbenchWindow(executionevent).getShell(), MessageFormat.format(Messages.getString("saveAsNotSupported.MESSAGE"), aobj), Messages.getString("saveAs.TITLE"), 1); - } - } else - { - MessageBox.post(HandlerUtil.getActiveWorkbenchWindow(executionevent).getShell(), Messages.getString("invalidSelection.MESSAGE"), Messages.getString("saveAs.TITLE"), 1); - } - } - } - return null; - } - - protected static void readDisplayParameters(Wizard wizard, WizardDialog wizarddialog) - { - String s = "DialogParameters"; - String s1 = wizard.getClass().getName(); - if(Cookie.exists(s, true)) - try - { - int i = 0; - int j = 0; - int k = 0; - int l = 0; - Cookie cookie = Cookie.getCookie(s, true); - i = cookie.getNumber((new StringBuilder(String.valueOf(s1))).append(".x").toString()); - j = cookie.getNumber((new StringBuilder(String.valueOf(s1))).append(".y").toString()); - k = cookie.getNumber((new StringBuilder(String.valueOf(s1))).append(".w").toString()); - l = cookie.getNumber((new StringBuilder(String.valueOf(s1))).append(".h").toString()); - if(k > 0 && l > 0) - wizarddialog.getShell().setBounds(i, j, k, l); - } - catch(Exception _ex) { } - } - - protected BaseExternalWizard getWizard() - { - String s = "com.teamcenter.rac.ui.commands.saveas.SaveAsWizard"; - return WizardExtensionHelper.getWizard(s); - } - - protected String getWizardTitle() - { - String s = null; - if(m_selectedCmp instanceof TCComponent) - { - Object aobj[] = { - ((TCComponent)m_selectedCmp).getTypeComponent().getDisplayType() - }; - s = MessageFormat.format(Messages.getString("saveAswizard.TITLE"), aobj); - } - return s; - } - - private TCComponent getUnderlyingComponent(TCComponent tccomponent) - { - try - { - if(tccomponent.isRuntimeType()) - return tccomponent.getUnderlyingComponent().isRuntimeType() ? null : tccomponent.getUnderlyingComponent(); - } - catch(TCException tcexception) - { - Logger.getLogger(SaveASHandler.class).error(tcexception.getLocalizedMessage(), tcexception); - } - return tccomponent; - } - - private InterfaceAIFComponent m_selectedCmp; - +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.util.MessageBox; + +import cn.com.origin.autocode.saveas.ORSaveAsCommand; +import cn.com.origin.autocodemanager.common.TCPreferenceUitl; + +public class ORItemSaveAsHandler extends AbstractHandler { + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // AbstractAIFUIApplication abstractAIFUIApplication = + // AIFUtility.getCurrentApplication(); + // new NewCodeItemDialog(AIFDesktop.getActiveDesktop().getShell(), + // "SJ3_ZXCPPRT").open(); + + // new SaveAsCommand(AIFDesktop.getFrames()[0], + // AIFUtility.getCurrentApplication().getTargetComponents(), true).run(); + ORSaveAsCommand orSaveAsCommand = new ORSaveAsCommand(AIFDesktop.getFrames()[0], + AIFUtility.getCurrentApplication().getTargetComponents(), true); + try { + if (orSaveAsCommand != null) + orSaveAsCommand.executeModal(); + } catch (Exception exception) { + MessageBox.post(AIFDesktop.getFrames()[0], exception); + } + return null; + } + + @Override + public boolean isEnabled() { + if (TCPreferenceUitl.isWriteExpire()) { + return false; + } else { + return true; + } + } } - /* - DECOMPILATION REPORT - - Decompiled from: C:\TC\Siemens\Teamcenter11\portal\plugins\com.teamcenter.rac.ui.commands_11000.2.0.jar - Total time: 29 ms - Jad reported messages/errors: - Exit status: 0 - Caught exceptions: -*/ + * DECOMPILATION REPORT + * + * Decompiled from: + * C:\TC\Siemens\Teamcenter11\portal\plugins\com.teamcenter.rac.ui. + * commands_11000.2.0.jar Total time: 29 ms Jad reported messages/errors: Exit + * status: 0 Caught exceptions: + */ diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/SaveAsByCodeHandler.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/SaveAsByCodeHandler.java new file mode 100644 index 0000000..57ca777 --- /dev/null +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/handlers/SaveAsByCodeHandler.java @@ -0,0 +1,322 @@ +package cn.com.origin.autocode.handlers; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AIFPortal; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; + +import cn.com.origin.autocodemanager.common.operations.GetCodeNumber; +import cn.hutool.core.util.StrUtil; +import cn.hutool.db.Db; +import cn.hutool.db.Entity; + +public class SaveAsByCodeHandler extends AbstractHandler { + public TCComponentFolder select = null; + TCComponentFolder selectOld = null; + private JTextField text; + private JScrollPane jsp; + private JPanel root; + private JDialog dialog; + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + Runnable runnable = new Runnable() { + + @Override + public void run() { + try { + // TODO Auto-generated method stub + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCPreferenceService service = session.getPreferenceService(); + File selectFile = new File(System.getenv("temp") + File.separator + "select_folder_" + + session.getUser().getUid() + ".txt"); + selectFile.createNewFile(); +// String uid = service.getStringValue("jd2_folder_select"); + BufferedReader reader = new BufferedReader(new FileReader(selectFile)); + String uid = reader.readLine(); + reader.close(); + if (StrUtil.isNotBlank(uid)) { + selectOld = (TCComponentFolder) session.stringToComponent(uid); + } + TCComponent comp = (TCComponent) app.getTargetComponent(); + if (comp == null) { + JOptionPane.showMessageDialog(null, "ûѡĿ", "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } + System.out.println("type=====>" + comp.getType()); + TCComponentItemRevision latestRev = null; + if (comp instanceof TCComponentItem) { + latestRev = ((TCComponentItem) comp).getLatestItemRevision(); + } else if (comp instanceof TCComponentItemRevision) { + latestRev = (TCComponentItemRevision) comp; + } else { + JOptionPane.showMessageDialog(null, "Ŀ" + comp.getType() + "֧", "ʾ", + JOptionPane.WARNING_MESSAGE); + return; + } + + String newItemId = null; + String itemId = latestRev.getProperty("item_id"); + List res = Db.use(DBUtil.getDataSource(session)).query( + "SELECT * FROM PCD9_CLASSIFICATIONCODENODE pc LEFT JOIN PCD9_TREEANDLISTCODENODE pt ON pc.PCD9_SEGMENT = pt.PUID"); + String type = latestRev.getItem().getProperty("object_type"); + System.out.println("===>" + type); + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent("Item"); + for (Entity entity : res) { + if (itemId.startsWith(entity.getStr("PCD9_NODE_VALUE")) + && type.equals(entity.getStr("PCD9_NODE_NAME"))) { + String patternCode = entity.getStr("PCD9_NODE_VALUE"); + int codeLength = entity.getInt("PCD9_CODE_LENGTH"); + int startIndex = entity.getInt("PCD9_SEQ_BEGIN_VALUE"); + int endIndex = entity.getInt("PCD9_SEQ_MAX_VALUE"); + do { + newItemId = new GetCodeNumber().getCodeNumber(patternCode, codeLength, startIndex, + endIndex, 1, ""); + new GetCodeNumber().delete_recycleID(newItemId); + } while (itemType.find(newItemId) != null); + break; + } + } + if (newItemId == null) { + JOptionPane.showMessageDialog(null, "ûҵӦıϢ", "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } + dialog = new JDialog(); + dialog.setTitle("ѡĿ¼"); + dialog.setAlwaysOnTop(true); + dialog.setAutoRequestFocus(true); + dialog.setResizable(true); + + root = new JPanel(); + root.setLayout(null); + root.setPreferredSize(new Dimension(300, 400)); + + JLabel label1 = new JLabel("Ҫһʱ䣬ȴ"); + jsp = new JScrollPane(label1); + jsp.setBounds(0, 0, 300, 300); + JLabel label = new JLabel("ѡ"); + label.setBounds(20, 310, 60, 25); + text = new JTextField(); + if (selectOld != null) { + text.setText(selectOld.getProperty("object_name")); + } + text.setEditable(false); + text.setBounds(100, 310, 180, 25); + JButton ok = new JButton("ȷ"); + ok.addActionListener(doOK(dialog, session, latestRev, newItemId)); + ok.setBounds(40, 350, 100, 25); + JButton cancel = new JButton("ȡ"); + cancel.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + dialog.dispose(); + } + }); + cancel.setBounds(160, 350, 100, 25); + + root.add(jsp); + root.add(label); + root.add(text); + root.add(ok); + root.add(cancel); + dialog.add(root); + dialog.pack(); + dialog.setLocationRelativeTo(null); + dialog.setVisible(true); + + initMenu(session); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + JOptionPane.showMessageDialog(null, e.getMessage(), " ", JOptionPane.ERROR_MESSAGE); + } + } + }; + + new Thread(runnable).start(); + return null; + } + + private void initMenu(TCSession session) throws Exception, TCException { + TCComponent[] home = session.search("General...", new String[] { "", "Ȩû" }, + new String[] { "Home ļ", session.getUser().getProperty("object_string") }); + JTree tree = getTree((TCComponentFolder) home[0]); + tree.addTreeSelectionListener(new TreeSelectionListener() { + + @Override + public void valueChanged(TreeSelectionEvent e) { + // TODO Auto-generated method stub + DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getNewLeadSelectionPath() + .getLastPathComponent(); + select = (TCComponentFolder) node.getUserObject(); + text.setText(node.toString()); + root.revalidate(); + root.repaint(); + } + }); + + root.remove(jsp); + jsp = new JScrollPane(tree); + jsp.setBounds(0, 0, 300, 300); + root.add(jsp); + root.revalidate(); + root.repaint(); + dialog.pack(); + } + + private ActionListener doOK(JDialog dialog, TCSession session, TCComponentItemRevision latestRev, String newItemId) + throws TCException { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + TCComponentItem newItem = null; + try { + session.getUserService().call("bs_bypass", new Object[] { true }); + newItem = latestRev.saveAsItem(newItemId, null); + + if (selectOld != null && select == null) { + selectOld.add("contents", newItem); + } else if (select != null) { + select.add("contents", newItem); + File selectFile = new File(System.getenv("temp") + File.separator + "select_folder_" + + session.getUser().getUid() + ".txt"); + selectFile.createNewFile(); + BufferedWriter writer = new BufferedWriter(new FileWriter(selectFile)); + writer.write(select.getUid()); + writer.close(); +// TCPreferenceService service = session.getPreferenceService(); +// service.setStringValue("jd2_folder_select", select.getUid()); + } else { + return; + } + } catch (TCException | IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + final TCComponentItem clipContent = newItem; + Transferable transferable = new Transferable() { + @Override + public boolean isDataFlavorSupported(DataFlavor paramDataFlavor) { + // TODO Auto-generated method stub + return true; + } + + @Override + public DataFlavor[] getTransferDataFlavors() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getTransferData(DataFlavor paramDataFlavor) + throws UnsupportedFlavorException, IOException { + // TODO Auto-generated method stub + Vector components = new Vector(); + components.add(clipContent); + return components; + } + }; + AIFPortal.getClipboard().setContents(transferable, null); + + try { + session.getUserService().call("bs_bypass", new Object[] { false }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + dialog.dispose(); + JOptionPane.showMessageDialog(null, "Ϊɹ", "ʾ", JOptionPane.WARNING_MESSAGE); + } + }; + } + + private JTree getTree(TCComponentFolder folder) { + DefaultMutableTreeNode root; + try { + root = new DefaultMutableTreeNode(folder.getProperty("object_name")); + root.setUserObject(folder); + + DefaultMutableTreeNode parent = root; + DefaultTreeModel treeModel = new DefaultTreeModel(root); + + initTree(folder, parent, treeModel); + + JTree tree = new JTree(treeModel); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); + cellRenderer.setTextNonSelectionColor(Color.black); + cellRenderer.setTextSelectionColor(Color.blue); + return tree; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return new JTree(); + } + + private void initTree(TCComponentFolder folder, DefaultMutableTreeNode parent, DefaultTreeModel treeModel) + throws TCException { + TCComponent[] comps = folder.getRelatedComponents("contents"); + if (comps.length == 0) { + return; + } + for (TCComponent comp : comps) { + if (comp instanceof TCComponentFolder) { + DefaultMutableTreeNode temp = new DefaultMutableTreeNode(comp.getProperty("object_name")); + temp.setUserObject(comp); + treeModel.insertNodeInto(temp, parent, parent.getChildCount()); + initTree((TCComponentFolder) comp, temp, treeModel); + } + } + } + +} diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/CNClassPropBean.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/CNClassPropBean.java index ed6baa8..cfda4be 100644 --- a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/CNClassPropBean.java +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/CNClassPropBean.java @@ -23,8 +23,11 @@ public class CNClassPropBean { public int floatsize = 0; public String formate; + public String must = ""; + public CNClassPropBean(ICSAdminClassAttribute icsAttr) { - // System.out.println("attr id :"+icsAttr.getAttributeId()+" attr naem :"+icsAttr.getName()); + // System.out.println("attr id :"+icsAttr.getAttributeId()+" attr naem + // :"+icsAttr.getName()); this.icsAttr = icsAttr; this.propID = icsAttr.getAttributeId(); this.propDisName = icsAttr.getName(); @@ -58,4 +61,21 @@ public class CNClassPropBean { return propDisName + ":"; } + public void setUserLov(String options) { + this.isLov = true; + lovMapping = new HashMap<>(); + keyList = new ArrayList<>(); + String[] arr = options.split(","); + for (String key : arr) { + lovMapping.put(key, key); + keyList.add(key); + } + lovMapping.put("", ""); + keyList.add(""); + } + + public void setMust(boolean isMust) { + this.must = isMust ? "()" : ""; + } + } diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/CustomLovBean.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/CustomLovBean.java new file mode 100644 index 0000000..e792a9b --- /dev/null +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/CustomLovBean.java @@ -0,0 +1,38 @@ +package cn.com.origin.autocode.newitem.generatcode; + +import java.util.ArrayList; +import java.util.List; + +public class CustomLovBean { + private List sub = new ArrayList(); + public String displayName = ""; + + public CustomLovBean(String displayName) { + super(); + this.displayName = displayName; + } + + public CustomLovBean(String displayName, String[] subArray) { + super(); + this.displayName = displayName; + translateArrayToSub(subArray); + } + + public void translateArrayToSub(String[] subArray) { + for (int i = 0; i < subArray.length; i++) { + sub.add(new CustomLovBean(subArray[i])); + } + } + + public List getSub() { + return sub; + } + + public boolean hasChild() { + return sub.size() != 0; + } + + public void addSub(CustomLovBean clb) { + sub.add(clb); + } +} diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/NewCodeItemDialog.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/NewCodeItemDialog.java index 7baf1f3..04925ce 100644 --- a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/NewCodeItemDialog.java +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/NewCodeItemDialog.java @@ -9,6 +9,7 @@ package cn.com.origin.autocode.newitem.generatcode; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; +import java.io.File; import java.io.IOException; import java.math.BigInteger; import java.text.SimpleDateFormat; @@ -22,6 +23,7 @@ import java.util.List; import java.util.Map; import javax.swing.JDialog; +import javax.swing.JOptionPane; import javax.xml.bind.JAXBException; import org.eclipse.jface.dialogs.Dialog; @@ -95,6 +97,8 @@ import com.teamcenter.rac.kernel.ics.ICSFormat; import com.teamcenter.rac.kernel.ics.ICSProperty; import com.teamcenter.rac.kernel.ics.ICSSearchResult; import com.teamcenter.rac.kernel.ics.ICSView; +import com.teamcenter.rac.util.ConfirmDialog; +import com.teamcenter.rac.util.ConfirmationDialog; import com.teamcenter.rac.util.MessageBox; import com.teamcenter.rac.util.PlatformHelper; import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException; @@ -122,6 +126,8 @@ import cn.com.origin.autocode.xmlutil.CNPart; import cn.com.origin.autocode.xmlutil.CNPartList; import cn.com.origin.autocode.xmlutil.CNProperty; import cn.com.origin.autocode.xmlutil.CNXmlUtil; +import cn.com.origin.autocode.xmlutil.ExcelInfoScanner; +import cn.com.origin.autocode.xmlutil.TranslateEnglish; import cn.com.origin.autocodemanager.common.AutoCodeManagerPropertyName; import cn.com.origin.autocodemanager.common.CreateCompositeUtil; import cn.com.origin.autocodemanager.common.PackCodeDescInfos; @@ -135,7 +141,8 @@ import cn.com.origin.autocodemanager.common.tree.AbstractTreeData; import cn.com.origin.autocodemanager.common.tree.TreeViewOperation; import cn.com.origin.autocodemanager.views.listcodeview.NewItemListCodeView; import cn.com.origin.autocodemanager.views.treecodeview.NewItemTreeCodeView; -import net.sf.json.JSONObject; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; public class NewCodeItemDialog extends Dialog { private Table propTable; @@ -257,6 +264,11 @@ public class NewCodeItemDialog extends Dialog { private String ys = null; private String cz = null; private String xh = null; + private String nodeName; + private String rootNodeName; + private Map classMustMap = new HashMap(); + private TCComponentItemRevision gltz; + private TCComponentItemRevision glwl; public Text getIdLengthText() { return idLengthText; @@ -455,7 +467,7 @@ public class NewCodeItemDialog extends Dialog { @Override public void controlResized(ControlEvent e) { Point r = classPropComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT); - classSrolledComposite.setMinSize(classSrolledComposite.computeSize(r.x, r.y)); + classSrolledComposite.setMinSize(classSrolledComposite.computeSize(r.x, r.y + 200)); } }); classPropTab.setControl(classCompsite); @@ -487,6 +499,19 @@ public class NewCodeItemDialog extends Dialog { if (classID == null || classID.replace(" ", "").equals("")) { return; } + + // ȡԶѡ + String uid = getPrefStr("jd_class_prop_option"); + TCComponent comp = null; + try { + comp = session.stringToComponent(uid); + } catch (TCException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + TCComponentDataset op = null; + Map propOption = null; + try { if (session == null) { session = (TCSession) AIFUtility.getCurrentApplication().getSession(); @@ -502,6 +527,16 @@ public class NewCodeItemDialog extends Dialog { ICSAdminClassAttribute[] icsAttrS = adminClass.getAttributes(); if (icsAttrS != null) { + // Զѡ + if (comp != null) { + op = (TCComponentDataset) comp; + String temp = System.getenv("temp"); + String[] types = op.getProperty("ref_names").split(","); + File optionFile = op.getFiles(types[0], temp)[0]; + optionFile.deleteOnExit(); + propOption = ExcelInfoScanner.getClassPropOptions(optionFile.getPath(), rootNodeName); + } + for (ICSAdminClassAttribute attr : icsAttrS) { if (attr.isReferenceAttribute()) { continue; @@ -510,8 +545,23 @@ public class NewCodeItemDialog extends Dialog { continue; } CNClassPropBean bean = new CNClassPropBean(attr); + // Զ + if (op != null) { + String options = propOption.get(bean.propID); + System.out.println(bean.propDisName + "ѡ" + options); + if (options != null && !"".equals(options)) { + bean.setUserLov(options); + } + } + + // ÷Ա + if (classMustMap.get(rootNodeName) != null + && classMustMap.get(rootNodeName).contains(bean.propID + "")) { + bean.setMust(true); + } + classPropList.add(bean); - Label label = CreateCompositeUtil.createNewLabel(classPropComposite, bean.propDisName); + Label label = CreateCompositeUtil.createNewLabel(classPropComposite, bean.propDisName + bean.must); label.getParent().layout(); classLabelList.add(label); Widget widget = null; @@ -641,13 +691,68 @@ public class NewCodeItemDialog extends Dialog { generalPropLabelList.clear(); generalPropTextList.clear(); + // Զ༶ȡ + String uid = getPrefStr("jd2_general_muti_lov"); + File mutiSetting = null; + try { + TCComponent comp = session.stringToComponent(uid); + if (comp != null) { + TCComponentDataset muti = (TCComponentDataset) comp; + String temp = System.getenv("temp"); + String[] types = muti.getProperty("ref_names").split(","); + mutiSetting = muti.getFiles(types[0], temp)[0]; + mutiSetting.deleteOnExit(); + } + } catch (TCException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + if (this.cnpropList != null) { + Map settingMap = new HashMap(); + if (mutiSetting != null) { + settingMap = ExcelInfoScanner.getGeneralPropMutiLovInfo(mutiSetting.getPath(), rootNodeName); + } for (CNProperty cnProp : this.cnpropList) { Label label = CreateCompositeUtil.createNewLabel(objPropComposite, cnProp.getIsMust() ? (cnProp.getDisplayName() + "()") : cnProp.getDisplayName()); generalPropLabelList.add(label); Widget widget = null; + if (settingMap.containsKey(cnProp.getDisplayName())) { + final CustomLovBean lovBean = settingMap.get(cnProp.getDisplayName()); + final Button comb = CreateCompositeUtil.createButton(objPropComposite, cnProp.getDefaultValue(), 20, + 240); + comb.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Point p = objPropComposite.toDisplay(((Button) e.getSource()).getLocation()); + + ShowLovDialog dialog = new ShowLovDialog(objPropComposite.getShell(), SWT.NONE, + comb.getText(), comb.getData(), p, lovBean); + ((Button) e.getSource()).setEnabled(false); + Object resault = dialog.open(); + ((Button) e.getSource()).setEnabled(true); + if (resault != null && resault instanceof LovKeyValue + && ((LovKeyValue) resault).value != null) { + LovKeyValue kv = (LovKeyValue) resault; + + ((Button) e.getSource()).setData(kv.key); + ((Button) e.getSource()).setText(kv.value); + System.out.println("LOV=>KEY>" + kv.key + "|VALUE=>V>" + kv.value); + } else { + ((Button) e.getSource()).setData(""); + ((Button) e.getSource()).setText(""); + System.out.println("LovKeyValue NULL"); + } + + } + }); + widget = comb; // Combo(propTable, // SWT.NONE); + comb.setText(cnProp.getDefaultValue()); + generalPropTextList.add(widget); + continue; + } if (!cnProp.getIsLov()) { if (cnProp.getPropertyType().toUpperCase().equals("STRING")) { final Text text = CreateCompositeUtil.createNewText(objPropComposite, cnProp.getDefaultValue()); @@ -683,7 +788,7 @@ public class NewCodeItemDialog extends Dialog { widget = text; } else if (cnProp.getPropertyType().toUpperCase().equals("BOOLEAN")) { final Combo comb = CreateCompositeUtil.createNotFillNewCombo(objPropComposite, - new String[] { "true", "false" }); // new + new String[] { "true", "false", "" }); // new comb.setText(cnProp.getDefaultValue()); // Combo(propTable, widget = comb; // SWT.NONE); } @@ -728,6 +833,8 @@ public class NewCodeItemDialog extends Dialog { ((Button) e.getSource()).setText(kv.value); System.out.println("LOV=>KEY>" + kv.key + "|VALUE=>V>" + kv.value); } else { + ((Button) e.getSource()).setData(""); + ((Button) e.getSource()).setText(""); System.out.println("LovKeyValue NULL"); } @@ -736,8 +843,11 @@ public class NewCodeItemDialog extends Dialog { widget = comb; // Combo(propTable, // SWT.NONE); comb.setText(cnProp.getDefaultValue()); } else { - final Combo comb = CreateCompositeUtil.createNotFillNewCombo(objPropComposite, - cnProp.lovDisplayValueList.toArray(new String[cnProp.lovDisplayValueList.size()])); + String[] items = cnProp.lovDisplayValueList + .toArray(new String[cnProp.lovDisplayValueList.size()]); + String[] newItems = Arrays.copyOf(items, items.length + 1); + newItems[newItems.length - 1] = ""; + final Combo comb = CreateCompositeUtil.createNotFillNewCombo(objPropComposite, newItems); // new widget = comb; // Combo(propTable, // SWT.NONE); comb.setText(cnProp.getDefaultValue()); @@ -1023,6 +1133,7 @@ public class NewCodeItemDialog extends Dialog { */ @Override protected Control createDialogArea(Composite parent) { + // ȡѡе propBeanList = JFomMethodUtil.getTcPropInfo(JFomUtil.ITEM_TYPE_PROP_MAPPING_REF, session); propMapping = JFomMethodUtil.getMapping(JFomUtil.FORM_TYPE_PROP_MAPPING, session); @@ -1291,6 +1402,12 @@ public class NewCodeItemDialog extends Dialog { CreateCompositeUtil.createNewLabel(composite, "볤"); idLengthText = CreateCompositeUtil.createNewText(composite, ""); + // ȡ + String[] prefStrArray = getPrefStrArray("jd_class_prop_must"); + for (String str : prefStrArray) { + classMustMap.put(str.split("/")[0], str.split("/")[1]); + } + // ===JY 2017.01.09==== GridLayout gridLayout2 = new GridLayout(); gridLayout2.numColumns = 4; @@ -1308,6 +1425,11 @@ public class NewCodeItemDialog extends Dialog { nameText = CreateCompositeUtil.createNewText(composite, ""); // ѡеĶͼֽͣƾ͸ TCComponent targetObject = (TCComponent) AIFUtility.getCurrentApplication().getTargetComponent(); + if (targetObject == null) { + MessageBox.post("δѡĿ꣬ѡٽд", "", MessageBox.ERROR); + this.close(); + return; + } if (targetObject instanceof TCComponentItemRevision) { TCComponentItemRevision design = (TCComponentItemRevision) targetObject; try { @@ -1321,7 +1443,7 @@ public class NewCodeItemDialog extends Dialog { if (TCPreferenceUitl.isTrueTCPreferenceValue(session, origin_newItem_isShowUnit)) { try { - CreateCompositeUtil.createNewLabel(composite, "λ"); + CreateCompositeUtil.createNewLabel(composite, "λ"); TCComponentListOfValues listOfValues = TCLOVUtil.findLOVByName(session, unitLOVName); ListOfValuesInfo listOfValuesInfo = listOfValues.getListOfValues(); String[] values = listOfValuesInfo.getLOVDisplayValues(); @@ -1865,6 +1987,12 @@ public class NewCodeItemDialog extends Dialog { if ((selectedData.getPackCodeNodeInfo().is_lock)) { return; } + objPropComposite.setVisible(true); + if (selectedData.getPackCodeNodeInfo().isContainsChildren()) { + objPropComposite.setVisible(false); + return; + } + String currentNodeDesc = ""; String currentNodeValue = ""; String name = ""; @@ -1915,6 +2043,7 @@ public class NewCodeItemDialog extends Dialog { } else { nameText.setText(""); } + getFinalPattern(); // idText.setText(pattern); idText.setText(finalPattern); @@ -1931,6 +2060,32 @@ public class NewCodeItemDialog extends Dialog { // = // >"+msg,"INFO",MessageBox.ERROR); + // дӢ + try { + for (int i = 0; i < classLabelList.size(); i++) { + String text = classLabelList.get(i).getText(); + System.out.println(text); + if ("Ӣƣ".equals(text)) { + String uid = getPrefStr("jd_chinese_to_english"); + TCComponentDataset en = (TCComponentDataset) session.stringToComponent(uid); + String temp = System.getenv("temp"); + String[] types = en.getProperty("ref_names").split(","); + File englishFile = en.getFiles(types[0], temp)[0]; + String res = TranslateEnglish.getEnglish(englishFile.getPath(), nodeName); + System.out.println("ǰѡڵƣ" + nodeName); + System.out.println("ǰѡڵӢƣ" + res); + if (res != null) { +// Text englishText = CreateCompositeUtil.createNewText(classPropComposite, +// res); + ((Text) classTextList.get(i)).setText(res); + } + } + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } }); } else if (selectedSegmentNode.getPackCodeNodeInfo().getNode_type() @@ -2222,7 +2377,16 @@ public class NewCodeItemDialog extends Dialog { codeDesc = codeDesc + "\n"; } this.codeRemark = treeData.getPackCodeNodeInfo().getNode_desc(); + this.nodeName = treeData.getPackCodeNodeInfo().getNode_name(); + + System.out.println("node_name ===>" + treeData.getPackCodeNodeInfo().getNode_name()); System.out.println("node_desc ===>" + treeData.getPackCodeNodeInfo().getNode_desc()); + AbstractTreeData temp = treeData; + while (temp != null) { + rootNodeName = temp.getPackCodeNodeInfo().getNode_name(); + temp = temp.getParentTreeData(); + } + System.out.println("rootNodeName ===>" + rootNodeName); } } } @@ -3125,7 +3289,6 @@ public class NewCodeItemDialog extends Dialog { public boolean finitPropList() { for (int i = 0; i < this.cnpropList.size(); i++) { Widget wd = generalPropTextList.get(i); - if (wd instanceof Text) { if (cnpropList.get(i).getPropertyType().toUpperCase().endsWith("STRING")) { @@ -3152,15 +3315,20 @@ public class NewCodeItemDialog extends Dialog { } else if (wd instanceof Combo) { if (cnpropList.get(i).getIsLov()) { int index = ((Combo) wd).getSelectionIndex(); - if (index != -1) { + if (index != -1 && cnpropList.get(i).lovValueList.size() > index) { cnpropList.get(i).value = cnpropList.get(i).lovValueList.get(index); + } else { + cnpropList.get(i).value = ""; } } else if (cnpropList.get(i).getPropertyType().toUpperCase().endsWith("BOOLEAN")) { if (!((Combo) wd).getText().replace(" ", "").equals("")) { - cnpropList.get(i).value = Boolean.parseBoolean(((Combo) wd).getText()); - + if (!"".equals(((Combo) wd).getText())) { + cnpropList.get(i).value = Boolean.parseBoolean(((Combo) wd).getText()); + } else { + cnpropList.get(i).value = ""; + } } } @@ -3259,6 +3427,7 @@ public class NewCodeItemDialog extends Dialog { type = targetObject.getType(); System.out.println("ѡж:" + targetObject + " :" + type); } + TCComponentItem newItem = (TCComponentItem) newComp; for (int i = 0; i < generalPropLabelList.size(); i++) { String text = generalPropLabelList.get(i).getText(); @@ -3279,9 +3448,8 @@ public class NewCodeItemDialog extends Dialog { flag = true; TCComponent cadTemplate = session.stringToComponent(uid); TCComponentDataset cadDataset = (TCComponentDataset) cadTemplate; - TCComponentItem item = (TCComponentItem) newComp; - TCComponentDataset newCad = cadDataset.saveAs(item.getProperty("item_id")); - item.getLatestItemRevision().add("TC_Attaches", newCad); + TCComponentDataset newCad = cadDataset.saveAs(newItem.getProperty("item_id")); + newItem.getLatestItemRevision().add("IMAN_specification", newCad); System.out.println("cadݼɹ"); // MessageBox.post("άͼСΪ\"" + rwtk + "\"cadݼ\"" + newCad.getProperty("object_string") // + "\"ɹ", "", MessageBox.WARNING); @@ -3297,7 +3465,6 @@ public class NewCodeItemDialog extends Dialog { } if (ksfl != null) { - TCComponentItem newItem = (TCComponentItem) newComp; TCComponentItemRevision rev = newItem.getLatestItemRevision(); TCComponentForm form = (TCComponentForm) rev.getRelatedComponents("IMAN_master_form_rev")[0]; if (ksfl.equals(form.getProperty("jd2_ksfl"))) { @@ -3315,35 +3482,38 @@ public class NewCodeItemDialog extends Dialog { } if (ysjtzRev != null) { - TCComponentItem item = (TCComponentItem) newComp; if (ysdzbForm != null) { if (ysjTable != null) { -// String[][] ysjTable1 = new String[ysjTable.length + 1][colNames.length]; - List ysjTable1 = new ArrayList(); - for (String[] arr : ysjTable) { - ysjTable1.add(arr); - } - - String[] newRow = new String[] { item.getProperty("item_id"), cz, ys, xh }; - ysjTable1.add(newRow); + List ysjTableList = new ArrayList<>(Arrays.asList(ysjTable)); + String[] newRow = new String[] { newItem.getProperty("item_id"), cz, ys, xh }; + System.out.println("new row===>" + Arrays.toString(newRow)); + ysjTableList.add(newRow); TCTableUtil.setTableRows(ysdzbForm, "jd2_ysdzb", "JD2_YSDZBTABLE", colNames, - ysjTable1.toArray(new String[ysjTable1.size()][colNames.length])); + ysjTableList.toArray(new String[ysjTableList.size()][colNames.length])); } } else { TCComponentFormType formType = (TCComponentFormType) session.getTypeComponent("Form"); ysdzbForm = formType.create("ɫձ", "ɫձ", "JD2_YSDZB"); - ysjTable = new String[][] { { item.getProperty("item_id"), cz, ys, xh } }; + ysjTable = new String[][] { { newItem.getProperty("item_id"), cz, ys, xh } }; + System.out.println("init row===>" + Arrays.deepToString(ysjTable)); TCTableUtil.setTableRows(ysdzbForm, "jd2_ysdzb", "JD2_YSDZBTABLE", colNames, ysjTable); session.getUserService().call("bs_bypass", new Object[] { true }); ysjtzRev.add("IMAN_specification", ysdzbForm); session.getUserService().call("bs_bypass", new Object[] { false }); } - item.getLatestItemRevision().add("TC_Is_Represented_By", ysjtzRev); + newItem.getLatestItemRevision().add("TC_Is_Represented_By", ysjtzRev); ysjtzRev.refresh(); - item.refresh(); + newItem.refresh(); System.out.println("ɫɹ"); } + if (gltz != null) { + newItem.getLatestItemRevision().add("TC_Is_Represented_By", gltz); + } + if (glwl != null) { + newItem.getLatestItemRevision().add("representation_for", glwl); + } + if (targetObject instanceof TCComponentFolder) { if (newComp != null) { @@ -4123,6 +4293,23 @@ public class NewCodeItemDialog extends Dialog { MessageBox.post("д", "", MessageBox.ERROR); return; } + for (int i = 0; i < classPropList.size(); i++) { + CNClassPropBean bean = classPropList.get(i); + if (classMustMap.get(rootNodeName) != null + && classMustMap.get(rootNodeName).contains(bean.propID + "")) { + String value = ""; + if (bean.isLov) { + value = ((Combo) classTextList.get(i)).getText(); + value = bean.lovMapping.get(value); + } else { + value = ((Text) classTextList.get(i)).getText(); + } + if (value == null || "".equals(value.trim())) { + MessageBox.post("д", "", MessageBox.ERROR); + return; + } + } + } // ͼֽ ksfl = null; @@ -4140,7 +4327,7 @@ public class NewCodeItemDialog extends Dialog { String text = generalPropLabelList.get(i).getText(); System.out.println(text); if (text.equals("ʽࣺ")) { - ksfl = ((Text) generalPropTextList.get(i)).getText(); + ksfl = ((Button) generalPropTextList.get(i)).getText(); break; } } @@ -4159,6 +4346,9 @@ public class NewCodeItemDialog extends Dialog { // ɫ String ysjth = null; + ysjtzRev = null; + ysdzbForm = null; + ysjTable = null; ys = null; cz = null; xh = null; @@ -4173,8 +4363,6 @@ public class NewCodeItemDialog extends Dialog { } } for (int i = 0; i < classPropList.size(); i++) { - // System.out.println(" CLASS ID = " + integers[i] + " =" + - // vals[i]); CNClassPropBean bean = classPropList.get(i); System.out.println(bean.propDisName); if ("ɫ".equals(bean.propDisName)) { @@ -4184,7 +4372,6 @@ public class NewCodeItemDialog extends Dialog { } else { ys = ((Text) classTextList.get(i)).getText(); } - // icspro[i] = new ICSProperty(bean.propID, value); System.out.println("ɫ" + ys); } if ("".equals(bean.propDisName)) { @@ -4194,7 +4381,6 @@ public class NewCodeItemDialog extends Dialog { } else { cz = ((Text) classTextList.get(i)).getText(); } - // icspro[i] = new ICSProperty(bean.propID, value); System.out.println("ʣ" + cz); } if ("ͺ".equals(bean.propDisName)) { @@ -4204,15 +4390,23 @@ public class NewCodeItemDialog extends Dialog { } else { xh = ((Text) classTextList.get(i)).getText(); } - // icspro[i] = new ICSProperty(bean.propID, value); System.out.println("ͺţ" + xh); } } - if (ysjth != null && !"".equals(ysjth.trim()) && ys == null) { - MessageBox.post("ϲɫ", "", MessageBox.ERROR); - return; + if ((ysjth == null || "".equals(ysjth)) && ys != null && !"".equals(ys.trim())) { +// int res = JOptionPane.showConfirmDialog(null, "üɫȡдɫͼ", "ʾ", +// JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); + int res = ConfirmDialog.prompt(this.getShell(), "ʾ", "üɫ밴дɫͼ"); + System.out.println("res======>" + res); + if (res == ConfirmationDialog.YES) { + System.out.println("YES"); + // do nothing + } else { + System.out.println("NO OR CANCEL"); + return; + } } - if (ysjth != null && !"".equals(ysjth.trim())) { + if (ysjth != null && !"".equals(ysjth.trim()) && ys != null && !"".equals(ys.trim())) { TCComponent comp = null; try { comp = session.search("Item ID", new String[] { " ID" }, new String[] { ysjth })[0]; @@ -4230,8 +4424,8 @@ public class NewCodeItemDialog extends Dialog { ysjTable = TCTableUtil.getTableRows(ysdzbForm, "jd2_ysdzb", colNames); for (String[] row : ysjTable) { if (ys.equals(row[2])) { - MessageBox.post("ͼΪ\"" + ysjth + "\"ɫѴɫ\"" + ys + "\"", "", - MessageBox.ERROR); + MessageBox.post("ͼΪ\"" + ysjth + "\"ɫѴɫ\"" + ys + "\"", "ʾ", + MessageBox.WARNING); return; } } @@ -4239,11 +4433,57 @@ public class NewCodeItemDialog extends Dialog { } } } else { - MessageBox.post("ûҵ\"" + ysjth + "\"ӦͼֽϢ", "", MessageBox.ERROR); + MessageBox.post("ûҵ\"" + ysjth + "\"ӦͼֽϢ", "ʾ", MessageBox.WARNING); return; } } + // ͼֽ໥ + gltz = null; + glwl = null; + System.out.println("ͼֽ໥"); + for (int i = 0; i < generalPropLabelList.size(); i++) { + String text = generalPropLabelList.get(i).getText(); + if (text.equals("ͼŹ")) { + String th = ((Text) generalPropTextList.get(i)).getText(); + if (StrUtil.isNotBlank(th)) { + System.out.println("ͼţ" + th); + try { + TCComponent[] comps = session.search("Item ID", new String[] { " ID" }, + new String[] { th }); + if (comps.length > 0) { + System.out.println(comps[0].getUid()); + gltz = ((TCComponentItem) comps[0]).getLatestItemRevision(); + } else { + MessageBox.post("ͼŲڣдֵ", "ʾ", MessageBox.WARNING); + return; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + if (text.equals("ϺŹ")) { + String wlh = ((Text) generalPropTextList.get(i)).getText(); + if (StrUtil.isNotBlank(wlh)) { + System.out.println("Ϻţ" + wlh); + try { + TCComponent[] comps = session.search("Item ID", new String[] { " ID" }, + new String[] { wlh }); + if (comps.length > 0) { + System.out.println(comps[0].getUid()); + glwl = ((TCComponentItem) comps[0]).getLatestItemRevision(); + } else { + MessageBox.post("ϺŲڣдֵ", "ʾ", MessageBox.WARNING); + return; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + TCComponentItem oldItem = tccomponentitemtype.find(getJYNewID(newID)); if (oldItem != null) { MessageBox.post("IDΪ" + getJYNewID(newID) + "Ѿ!", "INFO", MessageBox.WARNING); @@ -4509,15 +4749,15 @@ public class NewCodeItemDialog extends Dialog { TCComponentForm form = (TCComponentForm) rev.getRelatedComponents("IMAN_master_form_rev")[0]; String type = form.getProperty("jd2_wllx"); TCProperty tcProperty = form.getTCProperty("jd2_wllx"); - System.out.println(tcProperty==null?"":tcProperty.getLOV()); + System.out.println(tcProperty == null ? "" : tcProperty.getLOV()); if (tcProperty != null) { System.out.println("isLov"); type = (String) form.getTCProperty("jd2_wllx").getLOV().getListOfValues().getRealValue(type); - }else { - type=""; + } else { + type = ""; } System.out.println("ͣ" + type); - property.append(item.getProperty("object_type")); + property.append(item.getProperty("object_name")); System.out.println(type); if (type != null && !"".equals(type)) { @@ -4529,7 +4769,7 @@ public class NewCodeItemDialog extends Dialog { flag = true; for (int j = 0; j < row[3].split(",").length; j++) { int id = Integer.parseInt(row[3].split(",")[j]); - if (map.get(id) != null) { + if (map.get(id) != null && !"".equals(map.get(id))) { property.append("" + map.get(id)); System.out.println(map.get(id)); } @@ -4542,7 +4782,7 @@ public class NewCodeItemDialog extends Dialog { row = arr[2].split("/"); for (int j = 0; j < row[2].split(",").length; j++) { int id = Integer.parseInt(row[2].split(",")[j]); - if (map.get(id) != null) { + if (map.get(id) != null && !"".equals(map.get(id))) { property.append("" + map.get(id)); System.out.println(map.get(id)); } @@ -4554,7 +4794,7 @@ public class NewCodeItemDialog extends Dialog { row = arr[0].split("/"); for (int j = 0; j < row[2].split(",").length; j++) { int id = Integer.parseInt(row[2].split(",")[j]); - if (map.get(id) != null) { + if (map.get(id) != null && !"".equals(map.get(id))) { property.append("" + map.get(id)); System.out.println(map.get(id)); } @@ -4564,7 +4804,7 @@ public class NewCodeItemDialog extends Dialog { row = arr[1].split("/"); for (int j = 0; j < row[2].split(",").length; j++) { int id = Integer.parseInt(row[2].split(",")[j]); - if (map.get(id) != null) { + if (map.get(id) != null && !"".equals(map.get(id))) { property.append("" + map.get(id)); System.out.println(map.get(id)); } @@ -4582,12 +4822,17 @@ public class NewCodeItemDialog extends Dialog { } public boolean sendToClassification() { + if (classPropList.size() == 0) { + System.out.println("бsize=0"); + return false; + } TCComponentItem item = (TCComponentItem) newComp; try { String uid = item.getLatestItemRevision().getUid(); String cid = codeRemark.trim(); List idsList = new ArrayList(); List valuesList = new ArrayList(); + List namesList = new ArrayList(); for (int i = 0; i < classPropList.size(); i++) { // System.out.println(" CLASS ID = " + integers[i] + " =" + // vals[i]); @@ -4602,6 +4847,7 @@ public class NewCodeItemDialog extends Dialog { // icspro[i] = new ICSProperty(bean.propID, value); if (!"".equals(value)) { idsList.add(bean.propID); + namesList.add(bean.propDisName); valuesList.add(value); } @@ -4614,18 +4860,18 @@ public class NewCodeItemDialog extends Dialog { System.out.println(Arrays.toString(ids)); System.out.println(Arrays.toString(values)); - JSONObject obj = new JSONObject(); + cn.hutool.json.JSONObject obj = JSONUtil.createObj(); obj.put("ids", ids); obj.put("values", values); String prop = obj.toString(); - prop = prop.replace("\"", "\\\""); +// prop = prop.replace("\"", "\\\""); System.out.println(prop); String server = getPrefStr("jd2_server_ip"); if (server == null || "".equals(server)) { MessageBox.post("δjd2_server_ipѡ", "", MessageBox.ERROR); return false; } - String url = "http://" + server + ":8080/classification"; + String url = "http://" + server + ":8880/api/sendClassification"; Map paramMap = new HashMap(); paramMap.put("uid", uid); paramMap.put("cid", cid); @@ -4639,6 +4885,7 @@ public class NewCodeItemDialog extends Dialog { public void run() { // TODO Auto-generated method stub cn.hutool.http.HttpUtil.post(URL, PARAMMAP); + setFLFH(namesList, values); System.out.println("success"); } }).start(); @@ -4648,4 +4895,53 @@ public class NewCodeItemDialog extends Dialog { } return true; } + + private void setFLFH(List namesList, String[] values) { + try { + TCComponentItemRevision rev = ((TCComponentItem) newComp).getLatestItemRevision(); + rev.refresh(); + String[] prefArr = getPrefStrArray("jd2_custom_display_name"); + String classAddress = getClassificationAddress(rev.getClassificationClass()); + System.out.println("classAddress=====>" + classAddress); + for (String pref : prefArr) { + String[] className = pref.split(":")[0].split("/"); + if (classAddress.contains(className[0]) && classAddress.contains(className[1])) { + String[] prefClassNamesArr = pref.split(":")[1].split(","); + System.out.println("pref class porp names=====>" + Arrays.toString(prefClassNamesArr)); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < prefClassNamesArr.length; i++) { + for (int ii = 0; ii < namesList.size(); ii++) { + if (prefClassNamesArr[i].equals(namesList.get(ii)) && !"".equals(values[ii].trim())) { + builder.append(values[ii] + ","); + } + } + } + String temp = builder.toString().substring(0, builder.toString().length() - 1); + System.out.println("class porp values=====>" + temp); + session.getUserService().call("bs_bypass", new Object[] { true }); + rev.lock(); + rev.setProperty("jd2_flfh", temp); + rev.save(); + rev.unlock(); + session.getUserService().call("bs_bypass", new Object[] { false }); + break; + } + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "ѡjd2_custom_display_name\r\n" + e.getMessage(), "ʾ", + JOptionPane.WARNING_MESSAGE); + return; + } + } + + private String getClassificationAddress(String classId) throws TCException { + ICSAdminClass clazz = session.getClassificationService().newICSAdminClass(); + clazz.load(classId); + if ("ICM".equals(clazz.askClassId())) { + return ""; + } + return clazz.getName() + "=>" + getClassificationAddress(clazz.getParent()); + } } diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/ShowLovDialog.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/ShowLovDialog.java index 8aafcd1..0b85305 100644 --- a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/ShowLovDialog.java +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/ShowLovDialog.java @@ -1,6 +1,10 @@ package cn.com.origin.autocode.newitem.generatcode; +import java.util.List; + import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; @@ -38,8 +42,9 @@ public class ShowLovDialog extends Dialog { private String msg; private Point p; private Text text; - private TCComponentListOfValues lov; + private Object lov; private String data; + private TreeItem selectedItem; /** * Create the dialog. @@ -47,8 +52,7 @@ public class ShowLovDialog extends Dialog { * @param parent * @param style */ - public ShowLovDialog(Shell parent, int style, String msg, Object data, - Point p, TCComponentListOfValues lov) { + public ShowLovDialog(Shell parent, int style, String msg, Object data, Point p, TCComponentListOfValues lov) { super(parent, style); this.msg = msg; @@ -59,6 +63,17 @@ public class ShowLovDialog extends Dialog { } } + public ShowLovDialog(Shell parent, int style, String msg, Object data, Point p, CustomLovBean customLov) { + super(parent, style); + + this.msg = msg; + this.p = p; + this.lov = customLov; + if (data != null) { + this.data = data.toString(); + } + } + /** * Open the dialog. * @@ -103,8 +118,7 @@ public class ShowLovDialog extends Dialog { } treeItem0.setText(disPlayv); treeItem0.setData(v); - TCComponentListOfValues cLov = lov - .getListOfFilterOfValue(v); + TCComponentListOfValues cLov = lov.getListOfFilterOfValue(v); if (cLov != null) { initLovTree(treeItem0, cLov); } @@ -117,6 +131,32 @@ public class ShowLovDialog extends Dialog { } + private void initLovTree(Widget lovTree, CustomLovBean lov) { + + if (lov != null) { + List subs = lov.getSub(); + + for (CustomLovBean clb : subs) { + String disPlayv = clb.displayName; + if (msg != null && disPlayv.equals(msg)) { + data = disPlayv; + } + TreeItem treeItem0 = null; + if (lovTree instanceof Tree) { + treeItem0 = new TreeItem((Tree) lovTree, 0); + } else { + treeItem0 = new TreeItem((TreeItem) lovTree, 0); + + } + treeItem0.setText(disPlayv); + treeItem0.setData(disPlayv); + if (clb.hasChild()) { + initLovTree(treeItem0, clb); + } + } + } + } + /** * Create contents of the dialog. */ @@ -124,23 +164,42 @@ public class ShowLovDialog extends Dialog { shell = new Shell(getParent(), getStyle()); shell.setSize(335, 281); shell.setBounds(p.x, p.y, 330, 270); - OS.SetWindowPos(shell.handle, OS.HWND_TOPMOST, p.x, p.y, 330, 270, - SWT.NULL); + OS.SetWindowPos(shell.handle, OS.HWND_TOPMOST, p.x, p.y, 330, 270, SWT.NULL); shell.setText(getText()); lovTree = new Tree(shell, SWT.BORDER); lovTree.setBounds(10, 10, 304, 168); // initTree(); - initLovTree(lovTree, this.lov); + if (lov instanceof CustomLovBean) { + initLovTree(lovTree, (CustomLovBean) this.lov); + } else { + initLovTree(lovTree, (TCComponentListOfValues) this.lov); + } + lovTree.addListener(SWT.Selection, new Listener() { + @Override public void handleEvent(Event event) { - + selectedItem = (TreeItem) event.item; + System.out.println(selectedItem.getParent() == null ? "not Parent" : "yes Parent"); + System.out.println(selectedItem.getParentItem() == null ? "not ParentItem" : "yes ParentItem"); + System.out.println("selectedItem.getItemCount()====>" + selectedItem.getItemCount()); if (event.detail == SWT.CHECK) { - text.setText(((TreeItem) event.item).getText()); - data = ((TreeItem) event.item).getData().toString(); + text.setText(selectedItem.getText()); + data = selectedItem.getData().toString(); } else { - text.setText(((TreeItem) event.item).getText()); - data = ((TreeItem) event.item).getData().toString(); + text.setText(selectedItem.getText()); + data = selectedItem.getData().toString(); + } + } + }); + + lovTree.addMouseListener(new MouseAdapter() { + @Override + public void mouseDoubleClick(MouseEvent e) { + if (selectedItem.getItemCount() == 0) { + result.value = text.getText(); + result.key = data; + shell.dispose(); } } }); @@ -150,9 +209,11 @@ public class ShowLovDialog extends Dialog { @Override public void widgetSelected(SelectionEvent e) { - result.value = text.getText(); - result.key = data; - shell.dispose(); + if (selectedItem.getItemCount() == 0) { + result.value = text.getText(); + result.key = data; + shell.dispose(); + } } }); btnNewButton.setBounds(38, 228, 80, 27); diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/Test.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/Test.java index 08262d9..124d9bd 100644 --- a/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/Test.java +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/newitem/generatcode/Test.java @@ -1,10 +1,9 @@ package cn.com.origin.autocode.newitem.generatcode; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.nio.charset.Charset; +import java.util.List; +import java.util.Map; -import net.sf.json.JSONObject; +import cn.com.origin.autocode.xmlutil.ExcelInfoScanner; public class Test { @@ -13,46 +12,20 @@ public class Test { */ public static void main(String[] args) { // TODO Auto-generated method stub - int[] ids = new int[] { 1003, 1042, 1005, 1004 }; - String[] values = new String[] { "", "", "", "" }; - JSONObject obj = new JSONObject(); - obj.put("ids", ids); - obj.put("values", values); - String url = obj.toString(); - url = url.replace("\"", "\\\""); - Charset charset_gbk = Charset.forName("gbk"); - url = new String(url.getBytes(), charset_gbk); - url = URLEncoder.encode(url); - System.out.println(url); - url = URLDecoder.decode(url); - System.out.println(url); + Map map = ExcelInfoScanner + .getGeneralPropMutiLovInfo("C:\\Users\\5rKB5bPlusD\\Desktop\\testLov.xlsx", "ϴ»ͼֽ"); +// new Test().getinfo(bean); } - static class ClassficationBean { - int[] ids; - String[] values; - - ClassficationBean(int[] ids, String[] values) { - this.ids = ids; - this.values = values; + public void getinfo(CustomLovBean bean) { + if (!bean.hasChild()) { + return; } - - public int[] getIds() { - return ids; + List list = bean.getSub(); + for (CustomLovBean clb : list) { + System.out.println(clb.displayName); + getinfo(clb); } - - public void setIds(int[] ids) { - this.ids = ids; - } - - public String[] getValues() { - return values; - } - - public void setValues(String[] values) { - this.values = values; - } - } } diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/xmlutil/ExcelInfoScanner.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/xmlutil/ExcelInfoScanner.java new file mode 100644 index 0000000..2d6dd23 --- /dev/null +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/xmlutil/ExcelInfoScanner.java @@ -0,0 +1,99 @@ +package cn.com.origin.autocode.xmlutil; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.aspose.cells.Cells; +import com.aspose.cells.License; +import com.aspose.cells.Workbook; +import com.aspose.cells.WorksheetCollection; + +import cn.com.origin.autocode.newitem.generatcode.CustomLovBean; + +public class ExcelInfoScanner { + + public static Map getClassPropOptions(String path, String nodeName) { + Map res = new HashMap(); + try { + getLicense(); + Workbook excel = new Workbook(path); + WorksheetCollection wc = excel.getWorksheets(); + Cells cells = wc.get(0).getCells(); + for (int i = 0; i <= cells.getMaxDataRow(); i++) { + if (cells.get(i, 0).getStringValue().equals(nodeName)) { + res.put(cells.get(i, 1).getIntValue(), cells.get(i, 2).getStringValue()); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return res; + } + + public static Map getGeneralPropMutiLovInfo(String path, String nodeName) { + Map map = new HashMap(); + try { + getLicense(); + Workbook excel = new Workbook(path); + WorksheetCollection wc = excel.getWorksheets(); + Cells cells = wc.get(0).getCells(); + for (int i = 0; i <= cells.getMaxDataRow(); i++) { + CustomLovBean customLov = new CustomLovBean("ѡ"); + if (cells.get(i, 0).getStringValue().equals(nodeName)) { + getLovSubInfo(customLov, cells, i, 2); + map.put(cells.get(i, 1).getStringValue(), customLov); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return map; + } + + private static int getLovSubInfo(CustomLovBean customLov, Cells cells, int rowIndex, int columnIndex) { + int oldIndex = rowIndex; + int offset = 0; + do { + CustomLovBean clb = new CustomLovBean(cells.get(rowIndex, columnIndex).getStringValue()); + System.out.println(clb.displayName); + customLov.addSub(clb); + if (!"".equals(cells.get(rowIndex, columnIndex + 1).getStringValue())) { + offset = getLovSubInfo(clb, cells, rowIndex, columnIndex + 1); + } +// System.out.println(offset); +// System.out.println(rowIndex); + rowIndex = rowIndex + offset + 1; + offset = 0; +// System.out.println(rowIndex); + } while (!"".equals(cells.get(rowIndex, columnIndex).getStringValue()) + && "".equals(cells.get(rowIndex, columnIndex - 1).getStringValue())); + return rowIndex - oldIndex - 1; + } + + public static boolean getLicense() throws Exception { + boolean result = false; + try { + InputStream is = com.aspose.cells.Cell.class.getResourceAsStream("/com/aspose/cells/resources/license.xml"); + License aposeLic = new License(); + aposeLic.setLicense(is); + result = true; + is.close(); + } catch (Exception e) { + e.printStackTrace(System.out); + throw e; + } + return result; + } + + public static void main(String[] args) { + Map res = ExcelInfoScanner.getClassPropOptions("C:\\Users\\5rKB5bPlusD\\Desktop\\zh_cn.xlsx", + ""); + for (Entry entry : res.entrySet()) { + System.out.println(entry.getKey() + "," + entry.getValue()); + } + } +} diff --git a/cn.com.origin.autocode/src/cn/com/origin/autocode/xmlutil/TranslateEnglish.java b/cn.com.origin.autocode/src/cn/com/origin/autocode/xmlutil/TranslateEnglish.java new file mode 100644 index 0000000..0f30ff9 --- /dev/null +++ b/cn.com.origin.autocode/src/cn/com/origin/autocode/xmlutil/TranslateEnglish.java @@ -0,0 +1,49 @@ +package cn.com.origin.autocode.xmlutil; + +import java.io.InputStream; + +import com.aspose.cells.Cells; +import com.aspose.cells.License; +import com.aspose.cells.Workbook; +import com.aspose.cells.WorksheetCollection; + +public class TranslateEnglish { + + public static String getEnglish(String path, String value) { + try { + getLicense(); + Workbook excel = new Workbook(path); + WorksheetCollection wc = excel.getWorksheets(); + Cells cells = wc.get(0).getCells(); + for (int i = 0; i <= cells.getMaxDataRow(); i++) { + if (cells.get(i, 0).getStringValue().equals(value)) { + return cells.get(i, 1).getStringValue(); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + public static boolean getLicense() throws Exception { + boolean result = false; + try { + InputStream is = com.aspose.cells.Cell.class.getResourceAsStream("/com/aspose/cells/resources/license.xml"); + License aposeLic = new License(); + aposeLic.setLicense(is); + result = true; + is.close(); + } catch (Exception e) { + e.printStackTrace(System.out); + throw e; + } + return result; + } + + public static void main(String[] args) { + String res = TranslateEnglish.getEnglish("C:\\Users\\5rKB5bPlusD\\Desktop\\zh_cn.xlsx", ""); + System.out.println("" + res); + } +}