⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalreferencepane.java

📁 自动生成JAVA-Struts网站的程序
💻 JAVA
字号:
package com.sutternow.swingkar.gui;import com.sutternow.swingkar.ConfigManager;import com.sutternow.misc.Utils;import net.sf.easylayouts.RowLayout;import org.dom4j.Element;import org.dom4j.Node;import javax.swing.*;import javax.swing.table.AbstractTableModel;import java.awt.*;import java.awt.event.*;import java.util.*;import java.util.List;/*   @done test save process*//** * Created by IntelliJ IDEA. * User: Matthew Payne * Date: Jan 18, 2003 * Time: 1:01:50 AM * To change this template use Options | File Templates. */public class GlobalReferencePane implements SimpleForm, ActionListener, ItemListener, MouseListener {    public String Title = "Global Reference";    public GlobalReferencePane(ConfigManager _cm) {        cm = _cm;        refPanel = this.createPanel();    }     public String getTitle() {        return Title;    }     public JPanel getEditForm() {        return refPanel;    }     private JPanel createPanel() {         final JPanel panel = new JPanel();         final JPanel bottomPanel = new JPanel();         RowLayout rowLayout = new RowLayout(panel, 1, 10);         rowLayout.add(new JLabel("Reference Name:"), 0);         refName = new JTextField(25);         rowLayout.add(refName, 0);         rowLayout.add(new JLabel("Bean Name:"), 1);         beanName = new JComboBox();         beanName.addItemListener(this);         rowLayout.add(beanName, 1);         rowLayout.add(new JLabel("Query Name:"), 2);         queryName = new JComboBox();         rowLayout.add(queryName, 2);         rowLayout.add(new JLabel("Scope:"), 3);         scope = new JComboBox(new String[] {"session", "application"});         rowLayout.add(scope, 3);        // panel.addMouseListener(this);         paramTable = new JTable();         paramTable.addMouseListener(this);         JScrollPane jsp = new JScrollPane(paramTable);         jsp.setMinimumSize(new Dimension(90, 80));         jsp.setMaximumSize(new Dimension(150, 110));         jsp.setPreferredSize(new Dimension(150, 110));         rowLayout.add(jsp, 4);         // popup menu         popmenu = new JPopupMenu();         addEntry = new JMenuItem("Add");         addEntry.addActionListener(this);         popmenu.add(addEntry);         delEntry = new JMenuItem("Delete");         delEntry.addActionListener(this);         popmenu.add(delEntry);////         cmdSave = new JButton("Save");//         cmdCancel = new JButton("Cancel");////         cmdSave.addActionListener(this);//         cmdCancel.addActionListener(this);  //       bottomPanel.add(cmdSave);  //       bottomPanel.add(cmdCancel);         rowLayout.add(bottomPanel, 5);         return panel;     }    public void setValues(Element gvNode) {        this.clearForm();  /* <global-reference>   <name>Users</name>   <bean-name>Users</bean-name>   <query-name>SearchByPK</query-name>   <scope>session</scope>   <param>request.getRemoteUser()</param>   </global-reference>   */        globalRefElement =  gvNode;        String relPath = gvNode.getUniquePath();        refName.setText(Utils.parseNull(gvNode.valueOf(relPath + "/name")));        scope.setSelectedItem(gvNode.valueOf(relPath + "/scope"));        beanName.removeAllItems();        Iterator itr = gvNode.selectNodes("//bean/name").iterator();        while (itr.hasNext()) {            Element el = (Element)itr.next();            beanName.addItem(el.getText());        }        beanName.setSelectedItem(gvNode.valueOf(relPath + "/bean-name"));        this.fillQuery((String)beanName.getSelectedItem());        paramModel = new ParamTableModel(globalRefElement);        paramTable.setModel(paramModel);    }    private void makeResponse() {        Element e = globalRefElement;        //e.clearContent();        e.element("name").setText(refName.getText());        e.element("bean-name").setText((String)beanName.getSelectedItem());        e.element("query-name").setText((String)queryName.getSelectedItem());        e.element("scope").setText((String)scope.getSelectedItem());         // clear empty parameters         Collection emptys =  e.selectNodes(e.getUniquePath() + "/param[.='']");         Iterator itr = emptys.iterator();            while (itr.hasNext()) {                ((Element)itr.next()).detach();            }    }    public void itemStateChanged( ItemEvent event ) {		if (event.getSource() == beanName && event.getStateChange() == ItemEvent.SELECTED ) {			    System.out.println( "Change:" + beanName.getSelectedItem());            String name = (String)beanName.getSelectedItem();            fillQuery(name);		}	}    public void actionPerformed(ActionEvent ae) {        Object src = ae.getSource();        if (src == delEntry) {            deleteRow();        } else if (src == addEntry)  {            paramModel.addParameter("");        }    }    private void fillQuery(String name) {         queryName.removeAllItems();         queryName.addItem("SearchByPK");        Iterator itr = globalRefElement.selectNodes("//bean[name='" + name + "']/query/name").iterator();        while (itr.hasNext()) {            Element el = (Element)itr.next();            queryName.addItem(el.getText());        }    }    //{{{ deleteRow() method    private void deleteRow() {        // Deletes a row from the Table:        int targetRow;        String keyCol;        if (paramTable.getSelectedRowCount() > 0) {            targetRow = paramTable.getSelectedRow();            keyCol = (String) paramTable.getValueAt(targetRow, 0);            paramModel.requestRefresh();        }    } //}}}    private void clearForm() {        refName.setText("");        beanName.setSelectedIndex(-1);        queryName.setSelectedIndex(-1);        scope.setSelectedIndex(-1);    }    public void doSave() {        this.makeResponse();       // cm.saveChanges();        System.out.println(this.Title + " Saved");        // cm.addAntScript(this.makeResponse());    }    //{{{ Mouse Listener Interface Implementation    private void handleMouseEvent(MouseEvent evt) {        if (evt.isPopupTrigger()) {            if (popmenu.isVisible()) {                popmenu.setVisible(false);            } else {                popmenu.show((Component) evt.getSource(), evt.getX(), evt.getY());            }        }    }    public void mousePressed(MouseEvent evt) {        handleMouseEvent(evt);    }    public void mouseReleased(MouseEvent evt) {        handleMouseEvent(evt);    }    public void mouseClicked(MouseEvent e) {    }    public void mouseEntered(MouseEvent e) {    }    public void mouseExited(MouseEvent e) {    }    private JPanel refPanel;    private JTextField refName;    private JComboBox beanName;    private JComboBox queryName;    private JComboBox scope;    private JTable paramTable;    private ParamTableModel paramModel;    JPopupMenu popmenu;    JMenuItem addEntry;    JMenuItem delEntry;  //  private JButton cmdSave;  //  private JButton cmdCancel;    private ConfigManager cm;    private Element globalRefElement;class ParamTableModel extends AbstractTableModel {    /**     * Constructs an AppList table model.     * @param _globRef the Element the Represents a Global Reference Object     */    public ParamTableModel(Element _globRef) {        globRef = _globRef;        relPath = globRef.getUniquePath();        if (globRef.selectNodes(relPath + "/param").size() == 0 )  {            this.addParameter("");        }    }    public int getRowCount() {        return globRef.selectNodes(relPath + "/param").size();    }    public boolean isCellEditable(int rowIndex, int columnIndex) {        return true;    }    public void requestRefresh() {        /* Used to refresh the table */        super.fireTableDataChanged();    }    public int getColumnCount() {        return 1;    }    public void addParameter(String paramName) {        globRef.addElement("param").setText(paramName);        requestRefresh();    }    public Object getValueAt(int r, int c) {        Element el =  (Element)globRef.selectNodes(relPath + "/param").get(r);        return el.getText();    }    public void setValueAt(Object aValue, int r, int c) {        List list =  globRef.selectNodes(relPath + "/param");        if (((String)aValue).length() == 0 && r != list.size() - 1) {                Element e = (Element)list.get(r);                e.detach();				fireTableRowsDeleted(r,r);		}        Element el =  (Element)list.get(r);        el.setText((String)aValue);         if (r == list.size() - 1) {					 this.addParameter("");                  	 fireTableRowsInserted(r + 1, r + 1);		}    }    public String getColumnName(int c) {        switch (c) {            case 0:                return "Parameters";        }        return "no value dude";    }    private Element globRef;    String relPath = "";}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -