KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.event.*;
23 import java.util.*;
24 import java.util.List JavaDoc;
25
26 import javax.swing.*;
27
28 import org.openharmonise.him.*;
29 import org.openharmonise.him.harmonise.*;
30 import org.openharmonise.him.metadata.range.swing.range.*;
31 import org.openharmonise.him.swing.resourcetree.formresourcetree.*;
32 import org.openharmonise.vfs.*;
33 import org.openharmonise.vfs.metadata.*;
34 import org.openharmonise.vfs.metadata.range.*;
35 import org.openharmonise.vfs.metadata.value.*;
36 import org.openharmonise.vfs.servers.*;
37
38
39 /**
40  * @author Matthew Large
41  * @version $Revision: 1.1 $
42  *
43  */

44 public class RelationshipDetails extends AbstractRangeDetails
45 implements LayoutManager, FormResourceTreeListener, ActionListener {
46
47     private FormResourceTree m_tree = null;
48
49     private int m_nHeight = 400;
50     
51     private HashMap m_domainPathMapping = new HashMap();
52     
53     private RangeValue m_value = null;
54     private Range m_range = null;
55     
56     private JLabel m_collectionsOnlyLabel = null;
57     private JCheckBox m_collectionsOnlyCheck = null;
58     
59     private static List JavaDoc m_hiddenRootPaths = new ArrayList();
60     
61     static {
62         m_hiddenRootPaths.add(HarmonisePaths.PATH_ARCHIVE);
63         m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_DEFINITIONS);
64         m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_PROPS);
65         m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_STAGES);
66     }
67
68     /**
69      * @param propInst
70      * @param sTitle
71      */

72     public RelationshipDetails(PropertyInstance propInst) {
73         super(propInst, "Relationship details");
74         this.setup();
75     }
76     
77     private void setup() {
78
79         this.setLayout(this);
80         
81
82         
83         this.m_collectionsOnlyLabel = new JLabel("Collections only");
84         this.add(this.m_collectionsOnlyLabel);
85         this.m_collectionsOnlyCheck = new JCheckBox();
86         this.m_collectionsOnlyCheck.addActionListener(this);
87         this.add(this.m_collectionsOnlyCheck);
88
89         List JavaDoc selectedPaths = new ArrayList();
90         
91         if(this.getPropertyInstance().getValues().size()>0) {
92             this.m_value = (RangeValue) this.getPropertyInstance().getValues().get(0);
93
94             this.m_range = this.m_value.getRange();
95             if(this.m_range!=null) {
96                 List JavaDoc aHREFs = null;
97                 if(this.m_range instanceof CollectionRange) {
98                     aHREFs = ((CollectionRange)this.m_range).getHREFs();
99                     this.m_collectionsOnlyCheck.setSelected(true);
100                 } else {
101                     aHREFs = ((ResourceRange)this.m_range).getHREFs();
102                     this.m_collectionsOnlyCheck.setSelected(false);
103                 }
104                 Iterator itor = aHREFs.iterator();
105                 Vector vRemovals = new Vector();
106                 while (itor.hasNext()) {
107                     String JavaDoc sHREF = (String JavaDoc) itor.next();
108                     AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS();
109                     VirtualFile vFile = vfs.getVirtualFile(sHREF).getResource();
110                     if(vFile == null) {
111                         //assume that it has been removed
112
vRemovals.add(sHREF);
113                     } else {
114                         selectedPaths.add(sHREF);
115                     }
116                 }
117                 //reset range values for Property Instance
118
for(int i=0;i<vRemovals.size();i++){
119                     String JavaDoc href = (String JavaDoc)vRemovals.get(i);
120                     aHREFs.remove(href);
121                     RangeValue val = new RangeValue();
122                     if(this.m_range instanceof CollectionRange) {
123                         CollectionRange range = new CollectionRange();
124                         range.setHREFs(aHREFs);
125                         m_range = range;
126                         val.setRange(range);
127                     } else {
128                         ResourceRange range = new ResourceRange();
129                         range.setHREFs(aHREFs);
130                         m_range = range;
131                         val.setRange(range);
132                     }
133                     this.getPropertyInstance().removeValueWithoutFiringVirtualFileEvent(m_value);
134                     m_value = val;
135                     this.getPropertyInstance().addValueWithoutFiringVirtualFileEvent(val);
136                 }
137             } else {
138                 this.m_range = new ResourceRange();
139                 this.m_collectionsOnlyCheck.setSelected(false);
140             }
141         }
142         
143         m_tree = new FormResourceTree(false, selectedPaths);
144         m_tree.setShowLeafNodes(false);
145         m_tree.setBorder(BorderFactory.createEtchedBorder());
146         m_tree.addFormResourceTreeListener(this);
147         this.add(m_tree);
148
149         String JavaDoc fontName = "Dialog";
150         int fontSize = 11;
151         Font font = new Font(fontName, Font.PLAIN, fontSize);
152
153         Server server = ServerList.getInstance().getHarmoniseServer();
154         AbstractVirtualFileSystem vfs = server.getVFS();
155         VirtualFile vfFile =
156             vfs.getVirtualFile(
157                 "/" + server.getVFS().getRootPathSegment() + "/").getResource();
158         Iterator itor = vfFile.getChildren().iterator();
159         while (itor.hasNext()) {
160             String JavaDoc sChildPath = (String JavaDoc) itor.next();
161             VirtualFile vfChild = vfs.getVirtualFile(sChildPath).getResource();
162             if(vfChild.isDirectory() && !this.isPathHiddenRoot(vfChild.getFullPath())) {
163                 this.m_tree.addCollection(vfChild);
164             }
165         }
166     }
167     
168     private boolean isPathHiddenRoot(String JavaDoc sPath) {
169         boolean bHidden = false;
170         
171         Iterator itor = RelationshipDetails.m_hiddenRootPaths.iterator();
172         while (itor.hasNext()) {
173             String JavaDoc sRootPath = (String JavaDoc) itor.next();
174             if(sPath.equals(sRootPath) || sPath.startsWith(sRootPath)) {
175                 bHidden=true;
176             }
177         }
178         
179         return bHidden;
180     }
181
182     /* (non-Javadoc)
183      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
184      */

185     public void removeLayoutComponent(Component arg0) {
186     }
187
188     /* (non-Javadoc)
189      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
190      */

191     public void layoutContainer(Container arg0) {
192         int nHeight = 0;
193         
194         this.m_collectionsOnlyCheck.setSize(this.m_collectionsOnlyCheck.getPreferredSize());
195         this.m_collectionsOnlyCheck.setLocation(0, 20);
196         
197         nHeight = nHeight + 20;
198         
199         this.m_collectionsOnlyLabel.setSize(120, this.m_collectionsOnlyLabel.getPreferredSize().height);
200         this.m_collectionsOnlyLabel.setLocation(30, 20);
201
202         this.m_tree.setSize(this.m_tree.getPreferredSize());
203         this.m_tree.setLocation(0, nHeight + 20);
204     }
205
206     /* (non-Javadoc)
207      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
208      */

209     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
210     }
211
212     /* (non-Javadoc)
213      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
214      */

215     public Dimension minimumLayoutSize(Container arg0) {
216         return this.getPreferredSize();
217     }
218
219     /* (non-Javadoc)
220      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
221      */

222     public Dimension preferredLayoutSize(Container arg0) {
223         return this.getPreferredSize();
224     }
225
226     /* (non-Javadoc)
227      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
228      */

229     public void actionPerformed(ActionEvent ae) {
230         if(ae.getSource()==this.m_collectionsOnlyCheck) {
231             Range currentRange = (Range) this.m_range;
232             Range newRange = null;
233             if(this.m_collectionsOnlyCheck.isSelected()) {
234                 ResourceRange tempCurrRange = (ResourceRange)currentRange;
235                 CollectionRange tempRange = new CollectionRange();
236                 if(tempCurrRange.getHREFs()!=null) {
237                     tempRange.setHREFs(tempCurrRange.getHREFs());
238                 }
239                 this.m_range = (Range) tempRange;
240                 this.m_value.setRange((org.openharmonise.vfs.metadata.Range) this.m_range);
241                 this.fireRangeDetailsChanged(m_value);
242             } else {
243                 CollectionRange tempCurrRange = (CollectionRange)currentRange;
244                 ResourceRange tempRange = new ResourceRange();
245                 if(tempCurrRange.getHREFs()!=null) {
246                     tempRange.setHREFs(tempCurrRange.getHREFs());
247                 }
248                 this.m_range = (Range) tempRange;
249                 this.m_value.setRange((org.openharmonise.vfs.metadata.Range) this.m_range);
250                 this.fireRangeDetailsChanged(m_value);
251             }
252         }
253     }
254
255     /* (non-Javadoc)
256      * @see java.awt.Component#getPreferredSize()
257      */

258      public Dimension getPreferredSize() {
259         return new Dimension(this.m_tree.getPreferredSize().width, this.m_collectionsOnlyCheck.getPreferredSize().height + 20 + this.m_tree.getPreferredSize().height+20);
260      }
261
262     /* (non-Javadoc)
263      * @see com.simulacramedia.contentmanager.swing.resourcetree.formresourcetree.FormResourceTreeListener#pathValuesChanged(java.util.List)
264      */

265     public void pathValuesChanged(List JavaDoc pathValues) {
266         if(this.m_range instanceof CollectionRange) {
267             ((CollectionRange)this.m_range).setHREFs( pathValues);
268         } else {
269             ((ResourceRange)this.m_range).setHREFs( pathValues);
270         }
271         RangeValue newValue = (RangeValue) this.getPropertyInstance().getNewValueInstance();
272         newValue.setRange(this.m_range);
273         this.fireRangeDetailsChanged(newValue);
274     }
275
276 }
277
Popular Tags