001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.beanmgr;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Dimension;
023: import java.net.URL;
024: import java.util.Iterator;
025:
026: import javax.swing.DefaultListModel;
027: import javax.swing.JList;
028: import javax.swing.JTable;
029: import javax.swing.table.TableColumnModel;
030:
031: import com.jeta.forms.components.panel.FormPanel;
032: import com.jeta.open.gui.framework.JETAPanel;
033: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
034: import com.jeta.swingbuilder.store.ImportedBeanInfo;
035: import com.jeta.swingbuilder.store.ImportedBeansModel;
036:
037: /**
038: * The view for managing imported beans in the builder
039: *
040: * @author Jeff Tassin
041: */
042: public class BeanManagerView extends JETAPanel {
043: /**
044: * The beanManager.jfrm form
045: */
046: private FormPanel m_view;
047:
048: /**
049: * The beans model.
050: */
051: private BeansModel m_beansmodel;
052:
053: /**
054: * The list model for the classpaths
055: */
056: private DefaultListModel m_paths_model;
057:
058: /**
059: * Resonsible for loading beans from a classpath of URLs
060: */
061: private BeanLoader m_bean_loader;
062:
063: /**
064: * ctor
065: */
066: public BeanManagerView(ImportedBeansModel ibmodel) {
067: initialize(ibmodel);
068: setController(new BeanManagerController(this ));
069: }
070:
071: /**
072: * Adds a user to the list model
073: */
074: public void addUrl(URL url) {
075: m_paths_model.addElement(url);
076: m_bean_loader = null;
077: }
078:
079: /**
080: * Deletes the bean from the view/model
081: */
082: public void deleteSelectedBean() {
083: JTable table = m_view.getTable(BeanManagerNames.ID_BEAN_TABLE);
084: int row = table.getSelectedRow();
085: m_beansmodel.removeRow(row);
086: table.repaint();
087: m_view.repaint();
088: }
089:
090: /**
091: * Deletes the selected URL from the view/model
092: */
093: public void deleteSelectedUrl() {
094: JList list = m_view.getList(BeanManagerNames.ID_CLASSPATH_LIST);
095: int index = list.getSelectedIndex();
096: if (index >= 0) {
097: m_paths_model.removeElementAt(index);
098: }
099: m_bean_loader = null;
100: }
101:
102: /**
103: * @return the bean loader which is responsible for creating beans using the
104: * given classpaths
105: */
106: BeanLoader getBeanLoader() {
107: if (m_bean_loader == null) {
108: m_bean_loader = new BeanLoader();
109: for (int index = 0; index < m_paths_model.size(); index++) {
110: m_bean_loader.addUrl((URL) m_paths_model
111: .elementAt(index));
112: }
113: }
114: return m_bean_loader;
115: }
116:
117: /**
118: * @return the underlying beans model
119: */
120: BeansModel getBeansModel() {
121: return m_beansmodel;
122: }
123:
124: /**
125: * @return the model that describes the imported beans and their classpaths
126: */
127: public ImportedBeansModel getImportedBeansModel() {
128: ImportedBeansModel ibm = new ImportedBeansModel();
129: for (int row = 0; row < m_beansmodel.getRowCount(); row++) {
130: ibm.addImportedBean(m_beansmodel.getRow(row));
131: }
132:
133: for (int index = 0; index < m_paths_model.size(); index++) {
134: ibm.addUrl((URL) m_paths_model.elementAt(index));
135: }
136: return ibm;
137: }
138:
139: /**
140: * @return the preferred size for this view
141: */
142: public Dimension getPreferredSize() {
143: return FormDesignerUtils.getWindowDimension(this , 280, 240);
144: }
145:
146: /**
147: * @return the selected bean
148: */
149: public ImportedBeanInfo getSelectedBean() {
150: JTable table = m_view.getTable(BeanManagerNames.ID_BEAN_TABLE);
151: int row = table.getSelectedRow();
152: return m_beansmodel.getRow(row);
153: }
154:
155: /**
156: * Initializes the view
157: */
158: public void initialize(ImportedBeansModel ibmodel) {
159: setLayout(new BorderLayout());
160: m_view = new FormPanel(
161: "com/jeta/swingbuilder/gui/beanmgr/beanManager.jfrm");
162: add(m_view, BorderLayout.CENTER);
163: setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10,
164: 10, 10));
165:
166: JTable table = m_view.getTable(BeanManagerNames.ID_BEAN_TABLE);
167: m_beansmodel = new BeansModel();
168: table.setModel(m_beansmodel);
169: Iterator iter = ibmodel.getImportedBeans().iterator();
170: while (iter.hasNext()) {
171: m_beansmodel.addRow((ImportedBeanInfo) iter.next());
172: }
173:
174: int col_width = 60;
175: TableColumnModel cmodel = table.getColumnModel();
176: cmodel.getColumn(BeansModel.ICON_COLUMN).setPreferredWidth(
177: col_width);
178: cmodel.getColumn(BeansModel.NAME_COLUMN).setPreferredWidth(
179: col_width * 5);
180: cmodel.getColumn(BeansModel.SCROLLABLE_COLUMN)
181: .setPreferredWidth(col_width);
182:
183: m_paths_model = new DefaultListModel();
184: JList list = m_view.getList(BeanManagerNames.ID_CLASSPATH_LIST);
185: list.setModel(m_paths_model);
186:
187: iter = ibmodel.getUrls().iterator();
188: while (iter.hasNext()) {
189: m_paths_model.addElement((URL) iter.next());
190: }
191:
192: }
193:
194: }
|