KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > console > nodes > ExtentNode


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.console.nodes;
31
32 import javax.swing.ImageIcon JavaDoc;
33 import javax.swing.JTree JavaDoc;
34 import javax.swing.tree.DefaultTreeModel JavaDoc;
35 import javax.swing.tree.TreePath JavaDoc;
36
37 import com.genimen.djeneric.language.Messages;
38 import com.genimen.djeneric.repository.DjExtent;
39 import com.genimen.djeneric.repository.DjPersistenceManager;
40 import com.genimen.djeneric.repository.DjProperty;
41 import com.genimen.djeneric.repository.DjRelation;
42 import com.genimen.djeneric.util.DjLogger;
43 import com.genimen.djeneric.util.DjString;
44
45 public class ExtentNode extends CustomTreeNode
46 {
47   private static final long serialVersionUID = 1L;
48   DjExtent _extent;
49
50   public ExtentNode(JTree JavaDoc theTree, DefaultTreeModel JavaDoc theModel, DjExtent extent)
51   {
52     super(theTree, theModel);
53     _extent = extent;
54   }
55
56   public ImageIcon JavaDoc getImageIcon()
57   {
58     return (getImageIcon("images/extent.gif"));
59   }
60
61   public String JavaDoc toString()
62   {
63     return _extent.getName() + " (" + _extent.getAlias() + ")";
64   }
65
66   String JavaDoc _detailDescr = null;
67
68   public String JavaDoc getDetailDescription()
69   {
70     if (_detailDescr != null) return _detailDescr;
71
72     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(200);
73
74     sb.append(Messages.getString("ExtentNode.ObjectType", _extent.getObjectType()) + "\n"
75               + Messages.getString("ExtentNode.ExtentAlias", _extent.getInternalCode()) + "\n\n");
76
77     DjProperty cols[] = _extent.getProperties();
78     int maxLen = 0;
79     for (int i = 0; i < cols.length; i++)
80     {
81       if (cols[i].getName().length() > maxLen) maxLen = cols[i].getName().length();
82     }
83     maxLen++;
84
85     sb.append(DjString.appendToLength(Messages.getString("global.Name"), " ", maxLen)
86               + DjString.appendToLength(Messages.getString("global.Mapping"), " ", 10)
87               + DjString.appendToLength(Messages.getString("global.Type"), " ", 10)
88               + DjString.appendToLength(Messages.getString("ExtentNode.Size"), " ", 10)
89               + DjString.appendToLength(Messages.getString("global.Required"), " ", 8));
90     sb.append("\n" + DjString.appendToLength("", "-", sb.length()) + "\n");
91
92     for (int i = 0; i < cols.length; i++)
93     {
94       sb.append(DjString.appendToLength(cols[i].getName(), " ", maxLen)
95                 + DjString.appendToLength(cols[i].getMapping(), " ", 10)
96                 + DjString.appendToLength(cols[i].getTypeName(), " ", 10)
97                 + DjString.appendToLength("(" + cols[i].getLength() + ", " + cols[i].getDecimals() + ")", " ", 10));
98       if (cols[i].isRequired()) sb.append(DjString.appendToLength("" + cols[i].isRequired(), " ", 8));
99       sb.append("\n");
100     }
101
102     try
103     {
104       DjRelation[] detail = _extent.getDetailRelations();
105       for (int i = 0; i < detail.length; i++)
106       {
107         if (i == 0) sb.append("\n" + Messages.getString("ExtentNode.DetailExtents") + "\n");
108         sb.append(detail[i].getName() + " (" + detail[i].getDescription() + "):\n " + _extent.getName());
109         if (detail[i].isDetailsContained()) sb.append(" " + Messages.getString("ExtentNode.Contain") + " ");
110         else sb.append(" " + Messages.getString("ExtentNode.Reference") + " ");
111
112         sb.append(detail[i].getDetailExtent().getName() + "\n where " + _extent.getName() + "."
113                   + _extent.getPropertyByMapping(DjPersistenceManager.MAPPING_OBJECT_ID).getName() + " = "
114                   + detail[i].getDetailExtent().getName() + "." + detail[i].getDetailProperty().getName() + "\n\n");
115       }
116     }
117     catch (Exception JavaDoc x)
118     {
119       sb.append(x.getClass().getName() + ": " + x.getMessage());
120       DjLogger.log(x);
121     }
122
123     _detailDescr = sb.toString();
124     return _detailDescr;
125   }
126
127   public void expandNode() throws Exception JavaDoc
128   {
129     if (_alreadyLoaded) return;
130
131     boolean isCollapsed = _tree.isCollapsed(new TreePath JavaDoc(this.getPath()));
132     removeAllChildren();
133     _treeModel.nodeStructureChanged(this);
134
135     try
136     {
137       DjRelation[] details = _extent.getDetailRelations();
138       for (int i = 0; i < details.length; i++)
139       {
140         DjExtent tab = details[i].getDetailExtent();
141         insertAsFolder(new ExtentNode(getTree(), getModel(), tab));
142       }
143       _alreadyLoaded = true;
144     }
145     catch (Exception JavaDoc x)
146     {
147       DjLogger.log(x);
148     }
149     if (!isCollapsed) _tree.expandPath(new TreePath JavaDoc(this.getPath()));
150   }
151 }
Popular Tags