KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > configuration > searchin > SearchInOptions


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.configuration.searchin;
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.configuration.*;
28 import org.openharmonise.him.harmonise.HarmonisePaths;
29 import org.openharmonise.him.swing.resourcetree.formresourcetree.*;
30 import org.openharmonise.vfs.VirtualFile;
31 import org.openharmonise.vfs.servers.*;
32
33
34 /**
35  * Configuration for the extra paths that appear in the Search panel.
36  *
37  * @author Matthew Large
38  * @version $Revision: 1.2 $
39  *
40  */

41 public class SearchInOptions
42     extends JPanel
43     implements LayoutManager, FormResourceTreeListener, ApplyChangesListener {
44
45     /**
46      * Configuration dialog in which these options will appear.
47      */

48     private ConfigDialog m_dialog = null;
49     
50     /**
51      * Tree to choose paths from.
52      */

53     private FormResourceTree m_tree = null;
54     
55     /**
56      * true if the values for this option have changed.
57      */

58     private boolean m_bChanged = false;
59     
60     private static List JavaDoc m_hiddenRootPaths = new ArrayList();
61     
62     static {
63         m_hiddenRootPaths.add(HarmonisePaths.PATH_ARCHIVE);
64         m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_DEFINITIONS);
65         m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_PROPS);
66         m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_STAGES);
67     }
68
69     /**
70      * Constructs a new search in options.
71      *
72      * @param dialog Configuration dialog
73      */

74     public SearchInOptions(ConfigDialog dialog) {
75         super();
76         this.m_dialog = dialog;
77         this.setup();
78     }
79     
80     private boolean isPathHiddenRoot(String JavaDoc sPath) {
81         boolean bHidden = false;
82         
83         Iterator itor = SearchInOptions.m_hiddenRootPaths.iterator();
84         while (itor.hasNext()) {
85             String JavaDoc sRootPath = (String JavaDoc) itor.next();
86             if(sPath.equals(sRootPath) || sPath.startsWith(sRootPath)) {
87                 bHidden=true;
88             }
89         }
90         
91         return bHidden;
92     }
93     
94     /**
95      * Configures this options class.
96      *
97      */

98     private void setup() {
99         this.m_dialog.addApplyChangesListener(this);
100         
101         this.setLayout(this);
102
103         List JavaDoc aValues = ConfigStore.getInstance().getPropertyVals("SEARCHPATHS");
104         Server server = ServerList.getInstance().getHarmoniseServer();
105
106         if(aValues!=null) {
107     
108             ArrayList aRemovePaths = new ArrayList();
109     
110             Iterator itor = aValues.iterator();
111             while (itor.hasNext()) {
112                 String JavaDoc sTempPath = (String JavaDoc) itor.next();
113                 if(server.getVFS().getVirtualFile(sTempPath)==null) {
114                     aRemovePaths.add(sTempPath);
115                 }
116             }
117             if(aRemovePaths.size()>0) {
118                 aValues.removeAll(aRemovePaths);
119                 ConfigStore.getInstance().setProperty("SEARCHPATHS", (ArrayList) aValues);
120             }
121         } else {
122             aValues = new ArrayList();
123         }
124         
125         m_tree = new FormResourceTree(aValues);
126         m_tree.setShowLeafNodes(false);
127         m_tree.setBorder(BorderFactory.createLineBorder(Color.BLACK));
128         m_tree.addFormResourceTreeListener(this);
129
130         this.add(m_tree);
131
132         String JavaDoc fontName = "Dialog";
133         int fontSize = 11;
134         Font font = new Font(fontName, Font.PLAIN, fontSize);
135
136         VirtualFile vfFile =
137             server.getVFS().getVirtualFile(
138                 "/" + server.getVFS().getRootPathSegment() + "/").getResource();
139         List JavaDoc children = vfFile.getChildren();
140         Iterator itor2 = children.iterator();
141         while (itor2.hasNext()) {
142             VirtualFile vfDir =
143                 server.getVFS().getVirtualFile((String JavaDoc) itor2.next()).getResource();
144             if (vfDir.isDirectory() && !this.isPathHiddenRoot(vfDir.getFullPath())) {
145                 this.m_tree.addCollection(vfDir);
146             }
147         }
148     }
149
150     /* (non-Javadoc)
151      * @see java.awt.Component#getPreferredSize()
152      */

153     public Dimension getPreferredSize() {
154         return new Dimension(this.getParent().getSize().width, 200);
155     }
156
157     /* (non-Javadoc)
158      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
159      */

160     public boolean applyChanges() {
161         if(this.m_bChanged) {
162             
163             ConfigStore.getInstance().setProperty("SEARCHPATHS", (ArrayList) this.m_tree.getPathValues());
164
165             this.m_bChanged = false;
166         }
167         return true;
168     }
169
170     /* (non-Javadoc)
171      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
172      */

173     public void layoutContainer(Container arg0) {
174         int nHeight = 0;
175         
176         this.m_tree.setSize(this.getParent().getSize().width-20, 280);
177         this.m_tree.setLocation(10, nHeight + 20);
178
179     }
180
181     /* (non-Javadoc)
182      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
183      */

184     public Dimension minimumLayoutSize(Container arg0) {
185         return this.getPreferredSize();
186     }
187
188     /* (non-Javadoc)
189      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
190      */

191     public Dimension preferredLayoutSize(Container arg0) {
192         return this.getPreferredSize();
193     }
194
195     /* (non-Javadoc)
196      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
197      */

198     public void removeLayoutComponent(Component arg0) {
199     }
200
201     /* (non-Javadoc)
202      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
203      */

204     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
205     }
206
207     /**
208      * @param arg0
209      */

210     private SearchInOptions(boolean arg0) {
211         super(arg0);
212     }
213
214     /**
215      * @param arg0
216      */

217     private SearchInOptions(LayoutManager arg0) {
218         super(arg0);
219     }
220
221     /**
222      * @param arg0
223      * @param arg1
224      */

225     private SearchInOptions(LayoutManager arg0, boolean arg1) {
226         super(arg0, arg1);
227     }
228
229     /* (non-Javadoc)
230      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
231      */

232     public void discardChanges() {
233         
234     }
235
236     /* (non-Javadoc)
237      * @see com.simulacramedia.contentmanager.swing.resourcetree.formresourcetree.FormResourceTreeListener#pathValuesChanged(java.util.List)
238      */

239     public void pathValuesChanged(List JavaDoc pathValues) {
240         this.m_bChanged = true;
241     }
242
243 }
244
Popular Tags