001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.tool.archive.wizard;
024:
025: // ToolBox
026: import org.enhydra.tool.archive.WebApplication;
027: import org.enhydra.tool.common.PathHandle;
028:
029: // JDK
030: import java.awt.Component;
031: import java.util.ArrayList;
032: import javax.swing.JTable;
033: import javax.swing.table.AbstractTableModel;
034:
035: //
036: public class WarSelector extends OneColumnFileSelector {
037: private JTable table = null;
038:
039: public WarSelector() {
040: super ();
041: warInit();
042: }
043:
044: // override OneColumnFileSelector
045: protected void removeSelection() {
046: int index = table.getSelectedRow();
047:
048: if ((index > -1) && (index < getTableModel().getRowCount())) {
049: getTableModel().removeRow(index);
050: }
051: }
052:
053: // override OneColumnFileSelector
054: protected void addToModel(PathHandle path) {
055: int count = getTableModel().getRowCount();
056: ArrayList list = new ArrayList();
057:
058: for (int i = 0; i < count; i++) {
059: list.add(getTableModel().getValueAt(i, 1).toString());
060: }
061: if (!list.contains(path.getPath())) {
062: WebApplication webApp = null;
063:
064: webApp = new WebApplication(path.getPath());
065: getTableModel().addWebApplication(webApp);
066: }
067: }
068:
069: protected void setWebApplications(WebApplication[] webApps) {
070: int count = getTableModel().getRowCount();
071:
072: for (int i = 0; i < count; i++) {
073: getTableModel().removeRow(i);
074: }
075: for (int i = 0; i < webApps.length; i++) {
076: getTableModel().addWebApplication(webApps[i]);
077: }
078: }
079:
080: protected WebApplication[] getWebApplications() {
081: int count = getTableModel().getRowCount();
082: WebApplication[] webApps = new WebApplication[count];
083:
084: for (int i = 0; i < count; i++) {
085: webApps[i] = new WebApplication(getTableModel().getValueAt(
086: i, 1).toString());
087: webApps[i].setContextRoot(getTableModel().getValueAt(i, 0)
088: .toString());
089: }
090: return webApps;
091: }
092:
093: private void warInit() {
094: Component[] comps = getScrollPane().getViewport()
095: .getComponents();
096:
097: for (int i = 0; i < comps.length; i++) {
098: getScrollPane().getViewport().remove(comps[i]);
099: }
100: table = new JTable();
101: table.setModel(new WarTableModel());
102: getScrollPane().getViewport().add(table, null);
103: table.getColumnModel().getColumn(0).setPreferredWidth(40);
104: table.getColumnModel().getColumn(1).setPreferredWidth(250);
105: getTableModel().addTableModelListener(table);
106: }
107:
108: private WarTableModel getTableModel() {
109: return (WarTableModel) table.getModel();
110: }
111:
112: private class WarTableModel extends AbstractTableModel {
113: ArrayList tableList = new ArrayList();
114:
115: public WarTableModel() {
116: super ();
117: }
118:
119: public String getColumnName(int column) {
120: String cn = "Unknown";
121:
122: switch (column) {
123: case 0:
124: cn = "Context Root";
125: break;
126: case 1:
127: cn = "Web Application";
128: break;
129: }
130: return cn;
131: }
132:
133: public void removeRow(int index) {
134: tableList.remove(index);
135: fireTableRowsDeleted(index, index);
136: }
137:
138: public Object getValueAt(int row, int column) {
139: WebApplication webApp = (WebApplication) tableList.get(row);
140: Object value = "Unknown";
141:
142: switch (column) {
143: case 0:
144: value = webApp.getContextRoot();
145: break;
146: case 1:
147: value = webApp.getArchive();
148: break;
149: }
150: return value;
151: }
152:
153: public void setValueAt(Object value, int row, int column) {
154: WebApplication webApp = (WebApplication) tableList.get(row);
155:
156: switch (column) {
157: case 0:
158: webApp.setContextRoot(value.toString());
159: break;
160: case 1:
161: webApp.setArchive(value.toString());
162: break;
163: }
164: }
165:
166: public int getColumnCount() {
167: return 2;
168: }
169:
170: public boolean isCellEditable(int row, int col) {
171: return (col == 0);
172: }
173:
174: public int getRowCount() {
175: return tableList.size();
176: }
177:
178: protected void addWebApplication(WebApplication webApp) {
179: int index = tableList.size();
180:
181: tableList.add(webApp);
182: fireTableRowsInserted(index, index);
183: }
184:
185: }
186: }
|