KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > deployer > ArchiveTableModel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.deployer;
24
25 // ToolBox imports
26
import org.enhydra.tool.archive.JarPlan;
27 import org.enhydra.tool.common.PathHandle;
28
29 // Standard imports
30
import javax.swing.table.DefaultTableModel JavaDoc;
31
32 //
33
public class ArchiveTableModel extends DefaultTableModel JavaDoc {
34     //
35
public ArchiveTableModel() {
36         super();
37         addColumn("Built");
38         addColumn("Path");
39     }
40
41     public void setPlans(JarPlan[] plans) {
42         PathHandle ph = null;
43
44         clear();
45         for (int i = 0; i < plans.length; i++) {
46             addPlan(plans[i]);
47         }
48     }
49
50     public JarPlan getPlan(int index) {
51        JarPlan plan = null;
52        if ((index > -1) && (index < getRowCount())) {
53          plan = (JarPlan) getValueAt(index, 1);
54        }
55        return plan;
56     }
57
58     public void setPlan(JarPlan plan, int index) {
59        if ((index > -1) && (index < getRowCount())) {
60          setValueAt(plan, index, 1);
61        }
62
63     }
64
65     public JarPlan[] getPlans() {
66         JarPlan[] plans = new JarPlan[0];
67         int count = getRowCount();
68
69         plans = new JarPlan[count];
70         for (int i = 0; i < count; i++) {
71             plans[i] = (JarPlan) getValueAt(i, 1);
72         }
73         return plans;
74     }
75
76     public int addPlan(JarPlan newPlan) {
77         int count = getRowCount();
78         int index = -1;
79         JarPlan plan = null;
80         Object JavaDoc[] row = new Object JavaDoc[0];
81         PathHandle ph = null;
82
83         for (int i = 0; i < count; i++) {
84             plan = (JarPlan) getValueAt(i, 1);
85             if (plan.getArchivePath().equals(newPlan.getArchivePath())) {
86                 setValueAt(newPlan, i, 1);
87                 index = i;
88                 break;
89             }
90         }
91         if (index == -1) {
92             ph = PathHandle.createPathHandle(newPlan.getArchivePath());
93             row = new Object JavaDoc[2];
94             row[0] = new Boolean JavaDoc(ph.isFile());
95             row[1] = newPlan;
96             addRow(row);
97             index = getRowCount() - 1;
98         }
99         return index;
100     }
101
102     public boolean isCellEditable(int row, int col) {
103         return false;
104     }
105
106     protected void clear() {
107         while (getRowCount() > 0) {
108             removeRow(0);
109         }
110     }
111
112 }
113
Popular Tags