KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > range > details > CompoundDetails


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.metadata.range.swing.range.details;
20
21 import java.awt.*;
22 import java.util.*;
23 import java.util.List JavaDoc;
24
25 import javax.swing.*;
26
27 import org.openharmonise.him.*;
28 import org.openharmonise.him.metadata.range.swing.range.*;
29 import org.openharmonise.him.swing.resourcetree.formresourcetree.*;
30 import org.openharmonise.him.window.messages.*;
31 import org.openharmonise.vfs.*;
32 import org.openharmonise.vfs.metadata.*;
33 import org.openharmonise.vfs.metadata.range.*;
34 import org.openharmonise.vfs.metadata.value.*;
35 import org.openharmonise.vfs.servers.*;
36
37
38 /**
39  * @author Matthew Large
40  * @version $Revision: 1.1 $
41  *
42  */

43 public class CompoundDetails extends AbstractRangeDetails
44 implements LayoutManager, FormResourceTreeListener {
45
46     private FormResourceTree m_tree = null;
47
48     private int m_nHeight = 400;
49     
50     private HashMap m_domainPathMapping = new HashMap();
51     
52     private RangeValue m_value = null;
53     private PropertyRange m_range = null;
54
55     /**
56      * @param propInst
57      * @param sTitle
58      */

59     public CompoundDetails(PropertyInstance propInst) {
60         super(propInst, "Compound Property details");
61         this.setup();
62     }
63     
64     private void setup() {
65
66         this.setLayout(this);
67         
68         List JavaDoc aSelectedPaths = new ArrayList();
69         
70         if(this.getPropertyInstance().getValues().size()>0) {
71             this.m_value = (RangeValue) this.getPropertyInstance().getValues().get(0);
72             this.m_range = (PropertyRange) this.m_value.getRange();
73             if(this.m_range!=null) {
74                 List JavaDoc aHREFs = this.m_range.getHREFs();
75                 Iterator itor = aHREFs.iterator();
76                 while (itor.hasNext()) {
77                     String JavaDoc sHREF = (String JavaDoc) itor.next();
78                     aSelectedPaths.add(sHREF);
79                 }
80             } else {
81                 this.m_range = new PropertyRange();
82             }
83         }
84
85         m_tree = new FormResourceTree(false, aSelectedPaths);
86         m_tree.setShowLeafNodes(false);
87         m_tree.setBorder(BorderFactory.createEtchedBorder());
88         m_tree.addFormResourceTreeListener(this);
89         
90         this.add(m_tree);
91
92         String JavaDoc fontName = "Dialog";
93         int fontSize = 11;
94         Font font = new Font(fontName, Font.PLAIN, fontSize);
95
96         Server server = ServerList.getInstance().getHarmoniseServer();
97         VirtualFile vfFile =
98             server.getVFS().getVirtualFile(
99                 "/" + server.getVFS().getRootPathSegment() + "/Metadata/Properties").getResource();
100         this.m_tree.addCollection(vfFile);
101     }
102
103     /* (non-Javadoc)
104      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
105      */

106     public void removeLayoutComponent(Component arg0) {
107     }
108
109     /* (non-Javadoc)
110      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
111      */

112     public void layoutContainer(Container arg0) {
113         int nHeight = 0;
114
115         this.m_tree.setSize(this.m_tree.getPreferredSize());
116         this.m_tree.setLocation(0, nHeight + 20);
117     }
118
119     /* (non-Javadoc)
120      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
121      */

122     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
123     }
124
125     /* (non-Javadoc)
126      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
127      */

128     public Dimension minimumLayoutSize(Container arg0) {
129         return this.getPreferredSize();
130     }
131
132     /* (non-Javadoc)
133      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
134      */

135     public Dimension preferredLayoutSize(Container arg0) {
136         return this.getPreferredSize();
137     }
138     
139     private boolean checkForInfiniteLoop(String JavaDoc sPath) {
140         boolean bLoopFound = false;
141         if(this.getPropertyInstance().getVirtualFile().getFullPath().startsWith(sPath)) {
142             bLoopFound = true;
143         } else {
144             PropertyGroup propGroup = PropertyCache.getInstance().getPropertyGroup(sPath);
145         
146             Iterator itor = propGroup.getChildren().iterator();
147         
148             while (itor.hasNext()) {
149                 Property prop = (Property) itor.next();
150                 Range range = prop.getRange();
151                 if(range instanceof PropertyRange) {
152                     if(prop.getHREF().equals(this.getPropertyInstance().getVirtualFile().getFullPath())) {
153                         bLoopFound = true;
154                         break;
155                     }
156                     Iterator itor2 = ((PropertyRange)range).getHREFs().iterator();
157                     while (itor2.hasNext()) {
158                         String JavaDoc sHREF = (String JavaDoc) itor2.next();
159                         if(this.checkForInfiniteLoop(sHREF)) {
160                             bLoopFound = true;
161                             break;
162                         }
163                     }
164                 }
165             }
166         
167             if(!bLoopFound) {
168                 itor = propGroup.getSubGroups().iterator();
169                 while (itor.hasNext()) {
170                     PropertyGroup subGroup = (PropertyGroup) itor.next();
171                     if(this.checkForInfiniteLoop(subGroup.getHREF())) {
172                         bLoopFound = true;
173                         break;
174                     }
175                 }
176             }
177         }
178         
179         return bLoopFound;
180     }
181
182     /* (non-Javadoc)
183      * @see java.awt.Component#getPreferredSize()
184      */

185      public Dimension getPreferredSize() {
186         return new Dimension(this.m_tree.getPreferredSize().width, this.m_tree.getPreferredSize().height+20);
187      }
188
189     /* (non-Javadoc)
190      * @see com.simulacramedia.contentmanager.swing.resourcetree.formresourcetree.FormResourceTreeListener#pathValuesChanged(java.util.List)
191      */

192     public void pathValuesChanged(List JavaDoc pathValues) {
193         List JavaDoc aPathsToAdd = new ArrayList();
194         
195         Iterator itor = pathValues.iterator();
196         while (itor.hasNext()) {
197             String JavaDoc sPath = (String JavaDoc) itor.next();
198             if(!this.checkForInfiniteLoop(sPath)) {
199                 aPathsToAdd.add(sPath);
200             } else {
201                 VirtualFile vfFile = ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(sPath).getResource();
202                 String JavaDoc sDisplayName = ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFileSystemView().getDisplayName(vfFile);
203                 MessageHandler.getInstance().fireMessageEvent("Warning! You cannot add the property group " + sDisplayName + " because it would create an infinite loop of Compound Properties.", MessageHandler.TYPE_ERROR);
204                 this.m_tree.removePathValue(sPath);
205             }
206         }
207         
208         this.m_range.setHREFs( aPathsToAdd);
209         RangeValue newValue = (RangeValue) this.getPropertyInstance().getNewValueInstance();
210         newValue.setRange(this.m_range);
211         this.fireRangeDetailsChanged(newValue);
212     }
213
214 }
215
Popular Tags