KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > relatedevents > RelatedEventValueDisplay


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.relatedevents;
20
21 import java.awt.*;
22 import java.beans.*;
23 import java.util.*;
24 import java.util.List JavaDoc;
25
26 import javax.swing.*;
27 import javax.swing.tree.*;
28
29 import org.openharmonise.him.*;
30 import org.openharmonise.him.metadata.range.swing.*;
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.ServerList;
36
37
38 /**
39  *
40  * @author Michael Bell
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class RelatedEventValueDisplay
45     extends AbstractRangeDisplay
46     implements RangeDisplay, LayoutManager, PropertyChangeListener {
47
48     private RelatedEventText m_eventText = null;
49     private RelatedEventRelationship m_eventType = null;
50     private RelatedEventRelationship m_place = null;
51     private RelatedEventRelationship m_people = null;
52     ArrayList m_propDisplays = new ArrayList(3);
53     protected int m_nHeight = 300;
54
55     private HashMap m_pathOrderMapping = new HashMap();
56
57     private SortedSet m_propPanels = new TreeSet();
58
59     private int m_nNextOrderVal = 1;
60
61     private PropertyValue m_propValue = null;
62
63     private RelatedEventRangeDisplay m_display = null;
64
65     private RelatedEventApproxDate m_startDate = null;
66     private RelatedEventApproxDate m_endDate = null;
67     private int m_nWidth = 300;
68     protected static int m_nSpace = 10;
69
70     public static final String JavaDoc PROPERTY_METADATA_CHANGE = "MetadataChanged";
71     /**
72      * @param display
73      * @param instance
74      * @param value
75      */

76     public RelatedEventValueDisplay(
77         RelatedEventRangeDisplay display,
78         PropertyInstance propInstance,
79         PropertyValue propValue) {
80         super(propInstance);
81         this.m_display = display;
82         this.m_propValue = propValue;
83         this.setup();
84     }
85
86     /**
87      *
88      */

89     private void setup() {
90         this.setLayout(this);
91
92         PropertyRange propRange =
93             (PropertyRange) this
94                 .getPropertyInstance()
95                 .getDefinition()
96                 .getRange();
97         List JavaDoc aHREFs = propRange.getHREFs();
98         AbstractVirtualFileSystem vfs =
99             ServerList.getInstance().getHarmoniseServer().getVFS();
100
101         Iterator itor = aHREFs.iterator();
102         while (itor.hasNext()) {
103             String JavaDoc sGroupPath = (String JavaDoc) itor.next();
104             VirtualFile vfPropGroup = vfs.getVirtualFile(sGroupPath).getResource();
105             if (vfPropGroup != null) {
106                 int nCount = 1;
107                 Iterator itor2 = vfPropGroup.getChildren().iterator();
108                 while (itor2.hasNext()) {
109                     String JavaDoc sPath = (String JavaDoc) itor2.next();
110                     this.m_pathOrderMapping.put(sPath, new Integer JavaDoc(nCount));
111                     nCount++;
112                 }
113                 this.m_nNextOrderVal = nCount;
114             }
115         }
116
117     }
118
119     /**
120      * @param propInstance
121      */

122     public RelatedEventValueDisplay(PropertyInstance propInstance) {
123         super(propInstance);
124     }
125
126
127     /* (non-Javadoc)
128      * @see java.awt.Component#isValid()
129      */

130     public boolean isMetadataValid() {
131         boolean bIsValid = false;
132         
133         
134         //need to call for each component so any changes to
135
//display are made
136
boolean bStartValid = m_startDate.isMetadataValid();
137         boolean bEndValid = m_endDate.isMetadataValid();
138         boolean bPeople = m_people.isMetadataValid();
139         boolean bPlace = m_place.isMetadataValid();
140         boolean bType = m_eventType.isMetadataValid();
141         boolean bText = m_eventText.isMetadataValid();
142         
143         bIsValid = (bStartValid
144                         && bEndValid
145                         && bPeople
146                         && bPlace
147                         && bType
148                         && bText);
149         
150         return bIsValid;
151     }
152
153     /* (non-Javadoc)
154      * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
155      */

156     public JPanel getPanel() {
157         PropertyRange range =
158             (PropertyRange) this
159                 .getPropertyInstance()
160                 .getDefinition()
161                 .getRange();
162
163         List JavaDoc props = range.getProperties();
164         
165         Iterator itor = props.iterator();
166         
167         List JavaDoc propInstances = this.m_propValue.getValue();
168
169         ArrayList aFillingPropInstances = new ArrayList();
170         aFillingPropInstances.addAll(propInstances);
171
172         while (itor.hasNext()) {
173             Property prop = (Property) itor.next();
174
175             String JavaDoc sPropName = prop.getName();
176             
177             PropertyInstance propInst = getPropertyInstance(prop);
178
179             if(propInst==null) {
180                 propInst = new PropertyInstance(prop.getNamespace(), prop.getName());
181                 aFillingPropInstances.add(propInst);
182
183                 if(getPropertyInstance().getVirtualFile() == null) {
184                     throw new NullPointerException JavaDoc();
185                 }
186                 
187                 propInst.setVirtualFile(this.getPropertyInstance().getVirtualFile());
188             }
189
190             if (sPropName.equals("event_start_date")) {
191                 m_startDate = new RelatedEventApproxDate(propInst);
192                 m_startDate.addPropertyChangeListener(this);
193                 this.add(m_startDate);
194             } else if (sPropName.equals("event_end_date")) {
195                 m_endDate = new RelatedEventApproxDate(propInst);
196                 m_endDate.addPropertyChangeListener(this);
197                 this.add(m_endDate);
198             } else if (sPropName.equals("event_people")) {
199                 m_people = new RelatedEventRelationship(propInst);
200                 m_people.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
201                 m_people.setSelectedLeafOnly(true);
202                 this.add(m_people);
203             } else if (sPropName.equals("event_place")) {
204                 m_place = new RelatedEventRelationship(propInst);
205                 m_place.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
206                 m_place.setSelectedLeafOnly(true);
207                 this.add(m_place);
208             } else if(sPropName.equals("event_type")) {
209                 m_eventType = new RelatedEventRelationship(propInst);
210                 m_eventType.setSelectedLeafOnly(true);
211                 m_eventType.setMaxOccurs(1);
212                 m_eventType.setMinOccurs(1);
213                 m_eventType.addPropertyChangeListener(this);
214                 this.add(m_eventType);
215                 
216             } else if(sPropName.equals("event_text")) {
217                 m_eventText = new RelatedEventText(propInst);
218                 m_eventText.addPropertyChangeListener(this);
219                 this.add(m_eventText);
220             }
221
222         }
223         
224         if(aFillingPropInstances.size()>propInstances.size()) {
225             this.m_propValue.setValue(aFillingPropInstances);
226         }
227
228         this.setBorder(BorderFactory.createRaisedBevelBorder());
229
230         return this;
231     }
232
233     /**
234      * @param prop
235      * @return
236      */

237     private PropertyInstance getPropertyInstance(Property prop) {
238         PropertyInstance propInst = null;
239         
240         List JavaDoc propInstances = this.m_propValue.getValue();
241         
242         Iterator iter = propInstances.iterator();
243         
244         while(iter.hasNext()) {
245             PropertyInstance propInstTemp = (PropertyInstance)iter.next();
246             if(prop.getName().equals(propInstTemp.getName()) && prop.getNamespace().equals(propInstTemp.getNamespaceURI())) {
247                 propInst = propInstTemp;
248             }
249         }
250         
251         return propInst;
252     }
253
254     /* (non-Javadoc)
255      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
256      */

257     public void removeLayoutComponent(Component comp) {
258     }
259
260     /* (non-Javadoc)
261      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
262      */

263     public void layoutContainer(Container parent) {
264         this.setSize(this.getPreferredSize());
265
266         m_nWidth = 10;
267
268         m_startDate.setSize(m_startDate.getPreferredSize().width, m_startDate.getPreferredSize().height);
269         m_startDate.setLocation(m_nWidth, 10);
270         m_nWidth = m_nWidth + m_startDate.getPreferredSize().width + m_nSpace;
271
272         m_endDate.setSize(m_endDate.getPreferredSize().width, m_endDate.getPreferredSize().height);
273         m_endDate.setLocation(m_nWidth, 10);
274         
275         m_nWidth = m_nWidth + m_endDate.getPreferredSize().width + m_nSpace;
276
277         
278
279         m_eventType.setSize(m_eventType.getPreferredSize());
280         m_eventType.setLocation(m_nWidth, 10);
281
282         m_nWidth = m_nWidth + m_eventType.getPreferredSize().width + m_nSpace;
283
284         m_eventText.setSize(m_eventText.getPreferredSize());
285         m_eventText.setLocation(m_nWidth, 10);
286
287         m_nWidth = m_nWidth + m_eventText.getPreferredSize().width + m_nSpace;
288
289         
290         m_people.setSize(m_people.getPreferredSize());
291         m_people.setLocation(m_nWidth, 10);
292
293         m_nWidth = m_nWidth + m_people.getPreferredSize().width + m_nSpace;
294
295         m_place.setSize(m_place.getPreferredSize());
296         m_place.setLocation(m_nWidth, 10);
297
298         m_nWidth = m_nWidth + m_place.getPreferredSize().width + m_nSpace;
299
300         m_nHeight = m_startDate.getSize().height + 20;
301         
302         m_nWidth = m_nWidth + 20;
303
304         this.repaint();
305
306     }
307
308     /* (non-Javadoc)
309      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
310      */

311     public void addLayoutComponent(String JavaDoc name, Component comp) {
312     }
313
314     /* (non-Javadoc)
315      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
316      */

317     public Dimension minimumLayoutSize(Container arg0) {
318         return this.getPreferredSize();
319     }
320
321     /* (non-Javadoc)
322      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
323      */

324     public Dimension preferredLayoutSize(Container arg0) {
325         return this.getPreferredSize();
326     }
327
328     /* (non-Javadoc)
329      * @see java.awt.Component#getPreferredSize()
330      */

331     public Dimension getPreferredSize() {
332         return new Dimension(m_nWidth, this.m_nHeight);
333     }
334     
335     Dimension getDateSize() {
336         return m_startDate.getPreferredSize();
337     }
338     
339     Dimension getRelationshipSize() {
340         return m_place.getPreferredSize();
341     }
342     
343     Dimension getTextSize() {
344         return m_eventText.getPreferredSize();
345     }
346     
347     public PropertyValue getValue() {
348         return this.m_propValue;
349     }
350
351     /* (non-Javadoc)
352      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
353      */

354     public void propertyChange(PropertyChangeEvent evt) {
355         if(evt.getPropertyName() == RelatedEventValueDisplay.PROPERTY_METADATA_CHANGE) {
356             this.validateTab();
357         }
358         
359     }
360
361 }
362
Popular Tags