package com.vci.client.omd.linktype; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.ScrollPaneConstants; import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.table.DefaultTableModel; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import org.dom4j.Document; import org.jdesktop.swingx.JXTable; import com.vci.corba.omd.btm.BtmItem; import com.vci.corba.omd.ltm.LinkType; import com.vci.mw.InvocationUtility; import com.vci.client.common.providers.ServiceProvider; import com.vci.client.omd.attribpool.toOutside.ApTableForOut; import com.vci.client.omd.attribpool.ui.APClient; import com.vci.client.omd.btm.toOutside.BtmTableForOut; //import com.vci.client.omd.ddl.DDLToolClient; import com.vci.client.omd.linktype.LinkTypeWrapper; import com.vci.client.omd.linktype.util.Tool; import com.vci.client.omd.provider.LinkTypeProvider; import com.vci.client.omd.statepool.StatePoolWrapper; import com.vci.client.omd.ui.OmdTreeCellRenderer; import com.vci.client.ui.util.PostorderEnumeration; import com.vci.corba.common.VCIError; import com.vci.omd.utils.LinkTypeComparator; @SuppressWarnings("all") public class LinkTypeUI extends JPanel{ private JButton btnConsistencyCheck, btnCreateView; private JButton addButton,modifyButton,deleteButton,checkButton,saveButton,cancleButton,jb1,jb2,jbutton1,jbutton2,jbutton3,jbutton4; private JPanel northPanel,eastPanel2,eastPanel3,jp1; private JTree ltTree; private JRadioButton jcb1,jcb2,jcb3,jcb4; private JComboBox jchb1,jchb2; private String select = null; private JScrollPane jsl; private JXTable jxt; private JTable jt1,jt2; private JPanel jp3; private JPanel jp2; private JSplitPane splitPane3; private JSplitPane splitPane; private JScrollPane jsp; private DefaultTableModel tableModel1,tableModel; private JTextField jtf1,jtf2,implClassText, shapeText; private JTextField textField ; private JButton sel; private JPanel left=new JPanel(); private JPanel textPanel=new JPanel(); private JLabel jl1,jl2,jl3; private JTextArea jta; private String[] aa = {"111","222"}; /** * true:add * false:Modify */ private boolean addFlag; private JSplitPane splitPane1; private JSplitPane splitPane1_from_toJSplitPane; private String nodeName=""; ArrayList apNameList = new ArrayList(); Map map = new HashMap(); private JScrollPane scrollPane = new JScrollPane(); public static LinkTypeUI linktypeui=null; private List btmItemsFrom = null; private List btmItemsTo = null; private List attributes = null; private String biFrom = null; private String biTo = null; private String ai = null; private String btwNameFrom = null; private String btwNameTo = null; private String lable = null; private String attName = null; private LinkType currentLt = null; Object[][] p= null; Object[][] p1= null; private static BtmItem[] btmArray = null; private static List main_types = null; private JLabel jla2 = new JLabel("业务类型名"); private JLabel jla3 = new JLabel("业务类型名"); private JButton sel2; private JButton sel3; private JTextField fieldFrom = new JTextField(20); private JTextField field_to = new JTextField(20); JXTable JXT; private JButton btnExp; private JButton btnImp; //构造方法用于初始化运行程序所需要的方法 public LinkTypeUI(){ createPoolTree(); initLinkType(p,p1); addListenerDelete(); addListenerAdd(); addListenerSave(); addListenerModify(); addListenerCancle(); addListenerConsistencyCheck(); //queryBtmByNameListener_from(); //queryBtmByNameListener_to(); btnExp.addActionListener(new ExpActionListener()); btnImp.addActionListener(new ImpActionListener(this)); } public void queryBtmByNameListener_from() { fieldFrom.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { ((BtmTableForOut) JXT).initBtmTable(fieldFrom.getText()); } @Override public void insertUpdate(DocumentEvent e) { ((BtmTableForOut) JXT).initBtmTable(fieldFrom.getText()); } @Override public void changedUpdate(DocumentEvent e) { ((BtmTableForOut) JXT).initBtmTable(fieldFrom.getText()); } }); } public void queryBtmByNameListener_to() { field_to.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { ((BtmTableForOut) JXT).initBtmTable(field_to.getText()); } @Override public void insertUpdate(DocumentEvent e) { ((BtmTableForOut) JXT).initBtmTable(field_to.getText()); } @Override public void changedUpdate(DocumentEvent e) { ((BtmTableForOut) JXT).initBtmTable(field_to.getText()); } }); } public static void cleanInstance(){ linktypeui = null; } public static LinkTypeUI getInstance(){ if(linktypeui==null){ linktypeui = new LinkTypeUI(); return linktypeui; } return linktypeui; } //初始化界面,把界面的各个组成部分都显现出来 private void initLinkType(Object[][] p, Object[][] p1){ jta = new JTextArea(); jta.setPreferredSize(new Dimension(180, 50)); jta.setBorder(BorderFactory.createEtchedBorder()); setLayout(new BorderLayout(0, 0)); northPanel = new JPanel(); FlowLayout fl = (FlowLayout) northPanel.getLayout(); fl.setAlignment(FlowLayout.LEFT); this.add(northPanel,BorderLayout.NORTH); addButton = new JButton("创建"); modifyButton = new JButton("修改"); deleteButton = new JButton("删除"); checkButton = new JButton("查看"); saveButton = new JButton("保存"); cancleButton = new JButton("取消"); btnConsistencyCheck = new JButton("一致性检查"); btnConsistencyCheck.setToolTipText("检查类型与数据库中表的一致性"); btnCreateView = new JButton("创建视图"); btnCreateView.setToolTipText("创建链接类型查询全部To/From端业务类型的视图"); btnExp = new JButton("导出"); btnImp = new JButton("导入"); northPanel.add(addButton); northPanel.add(modifyButton); northPanel.add(deleteButton); northPanel.add(checkButton); northPanel.add(saveButton); northPanel.add(cancleButton); northPanel.add(btnConsistencyCheck); northPanel.add(btnCreateView); northPanel.add(btnExp); northPanel.add(btnImp); saveButton.setEnabled(false); cancleButton.setEnabled(false); jl1=new JLabel("名称"); jl2=new JLabel("标签"); jl3=new JLabel("描述"); JLabel implClassLabel = new JLabel("实现类"); JLabel shapeLabel = new JLabel("形状"); jtf1 = new JTextField(); jtf1.setPreferredSize(new Dimension(180, 25)); jtf2 = new JTextField(); jtf2.setPreferredSize(new Dimension(180, 25)); implClassText = new JTextField(); implClassText.setPreferredSize(new Dimension(180, 25)); shapeText = new JTextField(); shapeText.setPreferredSize(new Dimension(180, 25)); jtf1.setEditable(false); jtf2.setEditable(false); jta.setEditable(false); jp1 = new JPanel(); jp1.setLayout(new GridBagLayout()); GridBagConstraints gbc4 = new GridBagConstraints(); gbc4.insets = new Insets(5, 5, 5, 5); gbc4.gridx=0; gbc4.gridy=0; jp1.add(jl1,gbc4); gbc4.gridx=1; jp1.add(jtf1,gbc4); jtf1.setEditable(false); gbc4.gridx=0; gbc4.gridy=1; jp1.add(jl2,gbc4); gbc4.gridx=1; jp1.add(jtf2,gbc4); jtf2.setEditable(false); gbc4.gridx=0; gbc4.gridy=2; jp1.add(implClassLabel,gbc4); gbc4.gridx=1; jp1.add(implClassText,gbc4); implClassText.setEditable(false); gbc4.gridx=0; gbc4.gridy=3; jp1.add(shapeLabel,gbc4); gbc4.gridx=1; jp1.add(shapeText,gbc4); shapeText.setEditable(false); gbc4.gridx=0; gbc4.gridy=4; jp1.add(jl3,gbc4); gbc4.gridx=1; jp1.add(jta,gbc4); jta.setEditable(false); fromAndToPanel(p,p1); jbutton1.setEnabled(false); jbutton2.setEnabled(false); jbutton3.setEnabled(false); jbutton4.setEnabled(false); jsp = new JScrollPane(); jsp.setViewportView(eastPanel3); //jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); JScrollPane jScrollPane = new JScrollPane(); jScrollPane.setViewportView(jp1); splitPane3 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jScrollPane, jsp); splitPane3.setDividerLocation(Toolkit.getDefaultToolkit().getScreenSize().width/6); shuXingPanel(); jb1.setEnabled(false); jb2.setEnabled(false); jchb1.setSelectedItem(null); jchb2.setSelectedItem(null); jcb1.setSelected(false); jcb2.setSelected(false); jcb3.setSelected(false); jcb4.setSelected(false); jchb1.setEnabled(false); jchb2.setEnabled(false); jcb1.setEnabled(false); jcb2.setEnabled(false); jcb3.setEnabled(false); jcb4.setEnabled(false); JScrollPane attributeJScrollPane = new JScrollPane(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); eastPanel2.setPreferredSize(new Dimension(dimension.width/2,dimension.height/3)); attributeJScrollPane.setViewportView(eastPanel2); splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane3, attributeJScrollPane); splitPane.setDividerLocation(Toolkit.getDefaultToolkit().getScreenSize().height / 3); //add by caill start textField=new JTextField(); sel=new JButton("定位"); //搜索框的设置 GridBagConstraints gb = new GridBagConstraints(); gb.gridx = 0; gb.gridy = 0; gb.weightx = 0.7; gb.weighty = 0; gb.fill = GridBagConstraints.HORIZONTAL; textPanel.setLayout(new GridBagLayout()); textPanel.add(textField,gb); textPanel.add(sel); left.setLayout(new BorderLayout()); left.add(textPanel,BorderLayout.NORTH); left.add(scrollPane,BorderLayout.CENTER); //为定位按钮增加点击事件 sel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //e.getSource(); String test = textField.getText().trim(); DefaultTreeModel model = (DefaultTreeModel)ltTree.getModel(); model.reload(); TreeNode root = (TreeNode) model.getRoot(); PostorderEnumeration enumeration = new PostorderEnumeration( root); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration .nextElement(); if (element.getUserObject() instanceof LinkTypeWrapper) { LinkTypeWrapper wrapper = (LinkTypeWrapper) element .getUserObject(); if (wrapper != null && wrapper.linkType != null && wrapper.linkType.name.equals(test)) { TreeNode[] path = element.getPath(); TreePath treePath = new TreePath(path); ltTree.setSelectionPath(treePath); return; } ; } } if (test.equals("")) { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "请输入链接类型", "提示", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "{ " + test + " }链接类型不存在", "提示", JOptionPane.INFORMATION_MESSAGE); } } }); //为定位框添加事件 textField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTextField text = (JTextField) e.getSource(); String test = text.getText().trim(); DefaultTreeModel model = (DefaultTreeModel)ltTree.getModel(); model.reload(); TreeNode root = (TreeNode) model.getRoot(); PostorderEnumeration enumeration = new PostorderEnumeration( root); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration .nextElement(); if (element.getUserObject() instanceof LinkTypeWrapper) { LinkTypeWrapper wrapper = (LinkTypeWrapper) element .getUserObject(); if (wrapper != null && wrapper.linkType != null && wrapper.linkType.name.equals(test)) { TreeNode[] path = element.getPath(); TreePath treePath = new TreePath(path); ltTree.setSelectionPath(treePath); return; } ; } } if (test.equals("")) { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "请输入链接类型", "提示", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "{ " + test + " }链接类型不存在", "提示", JOptionPane.INFORMATION_MESSAGE); } } }); //add by caill end splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, splitPane); //eastPanel = new JPanel(); //splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPane, splitPane); splitPane1.setDividerLocation(Toolkit.getDefaultToolkit().getScreenSize().width/6); this.add(splitPane1,BorderLayout.CENTER); } //新建按钮的监听器,点击新建按钮界面需要的变化在这里实现 public void addListenerAdd(){ addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { addFlag=true; jtf1.setText(""); jtf2.setText(""); implClassText.setText(""); shapeText.setText(""); jta.setText(""); ArrayList list5 = apNameList; apNameList.removeAll(list5); updateShuXing(); int s=jt1.getRowCount(); for(int i=0;i maxLength){ JOptionPane.showMessageDialog(this, "链接类型名长度不能超过" + maxLength, "链接类型名错误", JOptionPane.ERROR_MESSAGE); return false; } String lc_name = jtf1.getText(); if(used(lc_name)){ JOptionPane.showMessageDialog(this, "该链接类型名称已经存在", "请更换", JOptionPane.WARNING_MESSAGE); return false; } if ( (jt1.getRowCount() <1 ) || ( jt2.getRowCount() < 1 ) ) { JOptionPane.showMessageDialog(this, "From端业务类型和To端类型均不能为空!", "提醒", JOptionPane.WARNING_MESSAGE); return false; } return true; } //保存按钮的监听器,保存里面包括新建的保存和修改的保存,具体情况要根据判断来决定 public void addListenerSave(){ saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if(addFlag){ if(!check()){ return; } try { LinkType linkType = new LinkType(); linkType.name = jtf1.getText().toLowerCase(); linkType.tag = jtf2.getText(); linkType.implClass = implClassText.getText(); linkType.shape = shapeText.getText(); linkType.description = jta.getText(); linkType.primitivesFrom = (String) jchb1.getSelectedItem(); linkType.primitivesTo = (String) jchb2.getSelectedItem(); if(jcb4.isSelected() && jcb2.isSelected()){ linkType.relation = "N:N"; linkType.relationFrom = "N"; linkType.relationTo="N"; } if(jcb4.isSelected() && jcb1.isSelected()){ linkType.relation = "N:1"; linkType.relationFrom = "N"; linkType.relationTo="1"; } if(jcb3.isSelected() && jcb2.isSelected()){ linkType.relation = "1:N"; linkType.relationFrom = "1"; linkType.relationTo="N"; } if(jcb3.isSelected() && jcb1.isSelected()){ linkType.relation = "1:1"; linkType.relationFrom = "1"; linkType.relationTo="1"; } int rowFrom = jt1.getRowCount(); btmItemsFrom = new ArrayList(); for(int i=0;i(); for(int i=0;i(); for(int i=0;i list5 = apNameList; apNameList.removeAll(list5); updateShuXing(); int s=jt1.getRowCount(); for(int i=0;i(); for(int i=0;i(); for(int i=0;i(); for(int i=0;i removeAbList = getRemovedApList(currentLt, selectedLT); if(removeAbList.size() > 0 && hasInstance(selectedLT.name)){ JOptionPane.showMessageDialog(getInstance(), "类型已有实例, 不进行移除操作", "不能移除属性", JOptionPane.INFORMATION_MESSAGE); for(int i = 0; i < removeAbList.size(); i++){ String abName = removeAbList.get(i); attributes.add(abName); } } selectedLT.attributes = attributes.toArray(new String[0]); selectedLT.modifier = InvocationUtility.getInvocation().userName; // //修改链接类型TABLE // ArrayList addedAbList = getAddedApList(currentLt, selectedLT); // if(addedAbList != null && addedAbList.size() != 0){ // //更新表btName 增加属性 // String tableName = OmdTools.getLTTableName(selectedLT.name); // String sql = "alter table " + tableName + " add("; // for(int i = 0; i < addedAbList.size(); i++){ // String abName = addedAbList.get(i); // com.vci.corba.omd.attribpool.AttribItem abItem = null; // abItem = APClient.getService().getAttribItemByName(abName); // sql += Tool.getInstance().getAbSql(abItem); // } // sql = sql.substring(0, sql.lastIndexOf(",")); // sql += ")"; // boolean flag = DDLToolClient.getService().executeUpdateOracle(sql); // if(!flag){ // JOptionPane.showMessageDialog(null, "增加链接类型Table列失败", "修改Table失败", JOptionPane.INFORMATION_MESSAGE); // return; // }else{ // JOptionPane.showMessageDialog(null, "增加链接类型Table列成功", "修改Table成功", JOptionPane.INFORMATION_MESSAGE); // } // //将AlterSQL变更到DDL // DDLToolClient.getService().alterTableDDLOracle(sql + ";"); // } // if(removeAbList.size() > 0 && !hasInstance(selectedLT.name)){ // String tableName = OmdTools.getLTTableName(selectedLT.name); // String dropSql = "alter table " + tableName + " drop("; // for(int i = 0; i < removeAbList.size(); i++){ // dropSql += removeAbList.get(i); // if(i < removeAbList.size() -1){ // dropSql += ","; // } // } // dropSql += ")"; // boolean dropFlag = DDLToolClient.getService().executeUpdateOracle(dropSql); // if(!dropFlag){ // JOptionPane.showMessageDialog(getInstance(), "移除链接类型Table列失败", "修改Table失败", JOptionPane.INFORMATION_MESSAGE); // return; // }else{ // JOptionPane.showMessageDialog(getInstance(), "移除链接类型Table列成功", "修改Table成功", JOptionPane.INFORMATION_MESSAGE); // } // //将AlterSQL变更到DDL // DDLToolClient.getService().alterTableDDLOracle(dropSql + ";"); // } //*****先修改数据库中的表结构 , 修改成功后再去修改链接类型 //修改链接类型XML LinkTypeStart.getService().modifyLinkType(selectedLT); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }else{ JOptionPane.showMessageDialog(getThis(), "请选择链接类型", "请选择链接类型", JOptionPane.WARNING_MESSAGE); return; } createPoolTree(); jtf1.setText(""); jtf2.setText(""); implClassText.setText(""); shapeText.setText(""); jta.setText(""); ArrayList list5 = apNameList; apNameList.removeAll(list5); updateShuXing(); int s=jt1.getRowCount(); //每次removeRow(0) for(int i=0;i list5 = apNameList; apNameList.removeAll(list5); updateShuXing(); int s=jt1.getRowCount(); for(int i=0;i list5 = apNameList; apNameList.removeAll(list5); updateShuXing(); int s=jt1.getRowCount(); for(int i=0;i list5 = apNameList; apNameList.removeAll(list5); updateShuXing(); int s=jt1.getRowCount(); for(int i=0;i list = new ArrayList(); int t = jxtab.getRowCount(); for(int i = 0 ;i0){ for(int d1 = 0;d10){ for(int d3=0;d3(); for(int i=0;i ltList = Arrays.asList(lts); Collections.sort(ltList, new LinkTypeComparator()); if(lts != null){ for(LinkType lt : lts){ node1.add(new DefaultMutableTreeNode(new LinkTypeWrapper(lt))); } } } catch (VCIError e) { e.printStackTrace(); } ltTree = new JTree(node1); ltTree.setCellRenderer(new OmdTreeCellRenderer()); scrollPane.setViewportView(ltTree); ltTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent mouseevent) { jbutton1.setEnabled(false); jbutton2.setEnabled(false); jbutton3.setEnabled(false); jbutton4.setEnabled(false); jb1.setEnabled(false); jb2.setEnabled(false); jtf1.setEditable(false); jtf2.setEditable(false); implClassText.setEditable(false); shapeText.setEditable(false); jta.setEditable(false); jchb1.setEnabled(false); jchb2.setEnabled(false); jcb1.setEnabled(false); jcb2.setEnabled(false); jcb3.setEnabled(false); jcb4.setEnabled(false); addButton.setEnabled(true); modifyButton.setEnabled(true); deleteButton.setEnabled(true); checkButton.setEnabled(true); saveButton.setEnabled(false); cancleButton.setEnabled(false); linkTreeSelection(); } }); } /** * 有实例:true * 无实例:false * @return */ private boolean hasInstance(String ltName){ //String tableName = OmdTools.getLTTableName(ltName); boolean flag = false; try { flag = LinkTypeStart.getService().hasData(ltName); } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } //boolean flag = DDLToolClient.getService().hasInstanceOralce(tableName); return flag; } /** * 获取修改链接类型时 增加的属性, 以便将这些属性增加到该业务类型表的属性列中 * @param oldNames * @param names * @return */ private ArrayList getAddedApList(LinkType oldLt, LinkType newLt){ String[] oldAbInfo = oldLt.attributes; ArrayList oldNameList = new ArrayList(); for(int i = 0; i < oldAbInfo.length; i++){ oldNameList.add(oldAbInfo[i]); } String[] newAbInfo = newLt.attributes; ArrayList newNameList = new ArrayList(); for(int i = 0; i < newAbInfo.length; i++){ newNameList.add(newAbInfo[i]); } ArrayList addedApList = new ArrayList(); for(Iterator iterator = newNameList.iterator(); iterator.hasNext();){ String newName = iterator.next(); if(!oldNameList.contains(newName)){ addedApList.add(newName); } } return addedApList; } /** * 获取修改链接类型时 减少的属性 * @param oldNames * @param names * @return */ private ArrayList getRemovedApList(LinkType oldLt, LinkType newLt) { String[] oldAbInfo = oldLt.attributes; ArrayList oldNameList = new ArrayList(); for(int i = 0; i < oldAbInfo.length; i++){ oldNameList.add(oldAbInfo[i]); } String[] newAbInfo = newLt.attributes; ArrayList newNameList = new ArrayList(); for(int i = 0; i < newAbInfo.length; i++){ newNameList.add(newAbInfo[i]); } ArrayList removedApList = new ArrayList(); for(Iterator iterator = oldNameList.iterator(); iterator.hasNext();){ String oldName = iterator.next(); if(!newNameList.contains(oldName)){ removedApList.add(oldName); } } return removedApList; } /** * 获取table(from,to)中的bts * @param jt * @return */ private List getBtsInTable(JTable jt){ List list = new ArrayList(); for(int i = 0; i < jt.getRowCount(); i++){ list.add((String) jt.getValueAt(i, 0)); } return list; } public LinkTypeUI getThis(){ return this; } public LinkType getSelectedLT(){ DefaultMutableTreeNode node = (DefaultMutableTreeNode) ltTree.getLastSelectedPathComponent(); if(node != null){ Object userObj = node.getUserObject(); if(userObj instanceof LinkTypeWrapper){ return ((LinkTypeWrapper)userObj).linkType; } } return null; } public List getSelectedLTs(){ TreePath[] selectionPaths = ltTree.getSelectionPaths(); //未选中, 返回 if(selectionPaths == null || selectionPaths.length == 0){ return null; } //选中根节点, 返回 if(selectionPaths.length == 1 && !(((DefaultMutableTreeNode)selectionPaths[0].getLastPathComponent()).getUserObject() instanceof LinkTypeWrapper)){ return null; } List list = new ArrayList(); for(TreePath path : selectionPaths){ DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object obj = node.getUserObject(); if(obj instanceof LinkTypeWrapper){ list.add(((LinkTypeWrapper)obj).linkType); } } return list; } }