KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > tuple > lib > TupleCollectionView


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 package org.objectweb.medor.tuple.lib;
25
26 import org.objectweb.medor.api.MedorException;
27 import org.objectweb.medor.api.TupleStructure;
28 import org.objectweb.medor.tuple.api.TupleCollection;
29
30 import javax.swing.*;
31 import java.awt.*;
32 import java.awt.event.WindowAdapter JavaDoc;
33 import java.awt.event.WindowEvent JavaDoc;
34 import java.util.LinkedList JavaDoc;
35
36 public class TupleCollectionView extends JFrame {
37     public TupleCollectionView(TupleCollection tc) throws MedorException {
38         org.objectweb.medor.tuple.api.Tuple t;
39         Object JavaDoc o;
40         int nbTuple;
41         Object JavaDoc[][] data;
42         int nbAtt = tc.getMetaData().getSize();
43         LinkedList JavaDoc tuples = new LinkedList JavaDoc();
44         int c;
45         int l;
46         tc.first();
47         if (tc.isEmpty())
48             throw new MedorException("The TupleCollection is empty");
49         else {
50             do {
51                 //Tuple t1 = tc.getTuple();
52
//MemoryTuple t2 = (MemoryTuple)t1;
53
o = tc.getTuple();//.clone();
54
tuples.add(o);
55             } while (tc.next());
56             nbTuple = tuples.size();
57             data = new Object JavaDoc[nbTuple][nbAtt];
58             for (l = 0; (l < nbTuple); l++) {
59                 t = (org.objectweb.medor.tuple.api.Tuple) tuples.get(l);
60                 for (c = 1; (c <= nbAtt); c++) data[l][c - 1] = t.getObject(c);
61             }
62
63             TupleStructure md1 = tc.getMetaData();
64             String JavaDoc[] columnNames = new String JavaDoc[nbAtt];
65             c = 0;
66             while (c <= (nbAtt - 1)) {
67                 columnNames[c] = md1.getField(c + 1).getName();
68                 c++;
69             }
70
71             final JTable table = new JTable(data, columnNames);
72             table.setPreferredScrollableViewportSize(new Dimension(1000, 150));
73
74             //Create the scroll pane and add the table to it.
75
JScrollPane scrollPane = new JScrollPane(table);
76
77             //Add the scroll pane to this window.
78
getContentPane().add(scrollPane, BorderLayout.CENTER);
79
80             addWindowListener(new WindowAdapter JavaDoc() {
81                 public void windowClosing(WindowEvent JavaDoc e) {
82                     System.exit(0);
83                 }
84             });
85         }
86     }
87 }
88
Popular Tags