KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > modeler > userperspective > ExtentUsageNode


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.modeler.userperspective;
31
32 import javax.swing.JTree JavaDoc;
33 import javax.swing.tree.DefaultTreeModel JavaDoc;
34
35 import com.genimen.djeneric.repository.DjDomain;
36 import com.genimen.djeneric.repository.DjExtent;
37 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException;
38 import com.genimen.djeneric.structure.ExtentUsage;
39 import com.genimen.djeneric.structure.PropertyUsage;
40 import com.genimen.djeneric.structure.RelationDescriptor;
41 import com.genimen.djeneric.tools.modeler.ModelEditor;
42
43 public class ExtentUsageNode extends ExtentNode
44 {
45   private static final long serialVersionUID = 1L;
46   PropertyUsageTableModel _columnUsageModel = new PropertyUsageTableModel(_extentUsage);
47
48   public ExtentUsageNode(ExtentUsage usage)
49   {
50     super(usage);
51     updateIcon();
52   }
53
54   public ExtentUsageNode(JTree JavaDoc theTree, DefaultTreeModel JavaDoc theModel, DjExtent extent)
55   {
56     super(theTree, theModel, extent);
57     _extentUsage.setExtent(extent);
58     updateIcon();
59   }
60
61   public void updateIcon()
62   {
63     if (_extentUsage == null)
64     {
65       _icon = ModelEditor.getImageIcon("editor.gif");
66     }
67     else if (isMultiRow()) _icon = ModelEditor.getImageIcon("table.gif");
68     else _icon = ModelEditor.getImageIcon("editor.gif");
69   }
70
71   public ExtentUsageNode(JTree JavaDoc theTree, DefaultTreeModel JavaDoc theModel, RelationDescriptor relDesc, ExtentUsage usage)
72   {
73     super(theTree, theModel, relDesc, usage);
74     updateIcon();
75   }
76
77   public String JavaDoc getRoleName()
78   {
79     return "Editor Node";
80   }
81
82   public void setExtentUsage(ExtentUsage taus)
83   {
84     _extentUsage = taus;
85     _columnUsageModel = new PropertyUsageTableModel(_extentUsage);
86     updateIcon();
87   }
88
89   public PropertyUsageTableModel getPropertyUsageModel()
90   {
91     return _columnUsageModel;
92   }
93
94   public void initPropertyUsages() throws ObjectNotDefinedException
95   {
96     RelationDescriptor via = getVia();
97     String JavaDoc detailProp = "";
98     if (via != null) detailProp = via.getDetailPropertyName();
99
100     for (int i = 0; i < getExtent().getPropertyCount(); i++)
101     {
102       // skip the object_id
103
if (getExtent().getProperty(i).getName().equals(getExtent().getIdProperty().getName())) continue;
104       // skip the property that is in fact the relation to the parent
105
if (getExtent().getProperty(i).getName().equals(detailProp)) continue;
106
107       PropertyUsage pu = new PropertyUsage(getExtent().getProperty(i));
108       if (getExtent().getProperty(i).getType() instanceof DjDomain)
109       {
110         DjDomain dom = (DjDomain) getExtent().getProperty(i).getType();
111         pu.setComponentType(dom.getComponentType());
112       }
113       addPropertyUsage(pu);
114     }
115   }
116
117   public int getRowsDisplayed()
118   {
119     return _extentUsage.getRowsDisplayed();
120   }
121
122   public void setRowsDisplayed(int rows)
123   {
124     _extentUsage.setRowsDisplayed(rows);
125   }
126
127   public boolean isMultiRow()
128   {
129     return _extentUsage.isMultiRow();
130   }
131
132   public void setMultiRow(boolean multirow)
133   {
134     _extentUsage.setMultiRow(multirow);
135     updateIcon();
136     _treeModel.nodeChanged(this);
137   }
138
139   public int getPropertyUsageCount()
140   {
141     return _extentUsage.getPropertyUsageCount();
142   }
143
144   public PropertyUsage getPropertyUsage(int idx)
145   {
146     return _extentUsage.getPropertyUsage(idx);
147   }
148
149   public void addPropertyUsage(PropertyUsage usg)
150   {
151     _extentUsage.addPropertyUsage(usg);
152   }
153
154   public void removePropertyUsage(int idx)
155   {
156     _extentUsage.removePropertyUsage(idx);
157   }
158
159   public void removePropertyUsage(PropertyUsage cu)
160   {
161     _extentUsage.removePropertyUsage(cu);
162   }
163
164   // factory methods
165
protected ExtentNode createNewNode(RelationDescriptor relDesc, ExtentUsage usage)
166   {
167     return new ExtentUsageNode(getTree(), getModel(), relDesc, usage);
168   }
169
170   protected ExtentNode createNewNode(DjExtent extent)
171   {
172     return new ExtentUsageNode(getTree(), getModel(), extent);
173   }
174
175   public void sortPropertyUsages()
176   {
177     _extentUsage.sortPropertyUsages();
178   }
179
180   public boolean shouldDeleteFromStructure(ModelEditor editor)
181   {
182     if (super.shouldDeleteFromStructure(editor))
183     {
184       return true;
185     }
186
187     // Now check the column usages
188
int i = 0;
189     while (i < getPropertyUsageCount())
190     {
191       if (getPropertyUsage(i).getBaseProperty() == null)
192       {
193         removePropertyUsage(i);
194       }
195       else i++;
196     }
197     return false;
198   }
199
200   public void removeFromparent()
201   {
202     _treeModel.removeNodeFromParent(this);
203     getExtentUsage().removeFromParent();
204   }
205
206 }
Popular Tags