KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > wfxml > WfXMLPanel


1 /* XMLTablePanel.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11
12 package org.enhydra.jawe.wfxml;
13
14 import javax.swing.*;
15 import java.awt.Dimension JavaDoc;
16 import org.enhydra.jawe.xml.*;
17 import org.enhydra.jawe.xml.elements.*;
18 import org.enhydra.jawe.xml.panels.*;
19 import org.enhydra.jawe.xml.panels.*;
20 import org.enhydra.jawe.xml.panels.XMLTableControlPanel;
21 import org.enhydra.jawe.xml.panels.XMLTablePanel;
22 import org.enhydra.jawe.xml.*;
23
24 import java.awt.Dimension JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Vector JavaDoc;
30 import javax.swing.Box JavaDoc;
31 import javax.swing.JComboBox JavaDoc;
32 import javax.swing.JOptionPane JavaDoc;
33 import javax.swing.JTable JavaDoc;
34 import javax.swing.table.DefaultTableModel JavaDoc;
35 import org.enhydra.jawe.*;
36 import org.enhydra.jawe.xml.*;
37 import org.enhydra.jawe.xml.panels.*;
38 import org.w3c.dom.Node JavaDoc;
39
40
41 /**
42  * Creates a table panel.
43  */

44 public class WfXMLPanel extends XMLPanel {
45
46    XMLTablePanel lstPanel;
47    WfXMLComboPanel cboPanel;
48
49    public WfXMLPanel (XMLCollection myOwner) {
50
51       super(myOwner,1,"",XMLPanel.BOX_LAYOUT,true,false);
52
53       cboPanel=new WfXMLComboPanel(myOwner);
54
55       lstPanel=new XMLTablePanel (myOwner,myOwner.toLabel(),false,true,false,false,false);
56
57       add(cboPanel);
58       add(Box.createRigidArea(new Dimension JavaDoc(0,10)));
59       add(lstPanel);
60
61       setPreferredSize(new Dimension JavaDoc(850,500));
62
63       XMLButton buttonConnect=cboPanel.getConnectButton();
64       final JComboBox JavaDoc jcb=cboPanel.getComboBox();
65       // action listener for connecting to registry service
66
buttonConnect.addActionListener(new ActionListener JavaDoc(){
67                public void actionPerformed(ActionEvent JavaDoc ae){
68                   String JavaDoc selected=(String JavaDoc)jcb.getSelectedItem();
69                   DefInfos dis=(DefInfos)getOwner();
70                   if (selected!=null) {
71                      try {
72                         List JavaDoc l=WfXMLConnector.wfxmlListDefinitions(new URL JavaDoc(selected),dis);
73                         cleanTable();
74                         for (int i=0; i<l.size(); i++) {
75                            addElement((XMLElement)l.get(i));
76                         }
77                         JaWE.getInstance().message(ResourceManager.getLanguageDependentString("InformationWfXMLSuccessfullyConnectedToRegistryService")+" "+selected,JOptionPane.INFORMATION_MESSAGE);
78                      } catch (Exception JavaDoc ex) {
79                         ex.printStackTrace();
80                         JaWE.getInstance().message(ResourceManager.getLanguageDependentString("ErrorWfXMLProblemsWhileGettingDefinitionListForRegistry")+" "+selected+" !",JOptionPane.ERROR_MESSAGE);
81                      }
82                   } else {
83                      complainLoudly("WarningEmptySelectionToEditOrDelete");
84                   }
85                }
86             });
87
88
89
90    }
91
92    public XMLPanel getControlledPanel () {
93       return lstPanel;
94    }
95
96    public WfXMLComboPanel getComboPanel () {
97       return cboPanel;
98    }
99
100    /**
101     * Pops message into message dialog.
102     */

103    public void complainLoudly(String JavaDoc message) {
104       JOptionPane.showMessageDialog(getDialog(),
105                                     XMLUtil.getLanguageDependentString(message),
106                                     XMLUtil.getLanguageDependentString("Title"),
107                                     JOptionPane.WARNING_MESSAGE);
108    }
109
110    public void cleanTable () {
111       ((XMLCollection)getOwner()).clear();
112       JTable JavaDoc t=lstPanel.getTable();
113       DefaultTableModel JavaDoc dtm=(DefaultTableModel JavaDoc)t.getModel();
114       int rc=dtm.getRowCount();
115       for (int i=rc-1; i>=0; i--) {
116          dtm.removeRow(i);
117       }
118    }
119
120    public void addElement(XMLElement e) {
121       XMLCollection owncol=(XMLCollection)getOwner();
122       int rowpos=owncol.size();
123       owncol.add(e);
124       JTable JavaDoc t=lstPanel.getTable();
125       DefaultTableModel JavaDoc dtm=(DefaultTableModel JavaDoc)t.getModel();
126       Vector JavaDoc v=null;
127       if (e instanceof XMLComplexElement) {
128          v=new Vector JavaDoc(((XMLComplexElement)e).toComplexTypeValues());
129       } else {
130          v=new Vector JavaDoc();
131          v.add(e.toString());
132       }
133
134       // add object itself to the first column (it is invisible column)
135
v.add(0,e);
136       dtm.insertRow(rowpos,v);
137       //dtm.addRow(v);
138
try {
139          //t.setRowSelectionInterval(t.getRowCount()-1,t.getRowCount()-1);
140
t.setRowSelectionInterval(rowpos,rowpos);
141       } catch (Exception JavaDoc ex) {}
142       t.requestFocus();
143    }
144
145    public XMLElement getSelectedElement() {
146       return lstPanel.getSelectedElement();
147    }
148
149
150    public Object JavaDoc getSelectedItem () {
151       Object JavaDoc si=cboPanel.getComboBox().getSelectedItem();
152       System.out.println("Si="+si);
153       return si;
154    }
155
156 }
157
158
Popular Tags