001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.configuration.searchin;
020:
021: import java.awt.*;
022: import java.util.*;
023: import java.util.List;
024:
025: import javax.swing.*;
026:
027: import org.openharmonise.him.configuration.*;
028: import org.openharmonise.him.harmonise.HarmonisePaths;
029: import org.openharmonise.him.swing.resourcetree.formresourcetree.*;
030: import org.openharmonise.vfs.VirtualFile;
031: import org.openharmonise.vfs.servers.*;
032:
033: /**
034: * Configuration for the extra paths that appear in the Search panel.
035: *
036: * @author Matthew Large
037: * @version $Revision: 1.2 $
038: *
039: */
040: public class SearchInOptions extends JPanel implements LayoutManager,
041: FormResourceTreeListener, ApplyChangesListener {
042:
043: /**
044: * Configuration dialog in which these options will appear.
045: */
046: private ConfigDialog m_dialog = null;
047:
048: /**
049: * Tree to choose paths from.
050: */
051: private FormResourceTree m_tree = null;
052:
053: /**
054: * true if the values for this option have changed.
055: */
056: private boolean m_bChanged = false;
057:
058: private static List m_hiddenRootPaths = new ArrayList();
059:
060: static {
061: m_hiddenRootPaths.add(HarmonisePaths.PATH_ARCHIVE);
062: m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_DEFINITIONS);
063: m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_PROPS);
064: m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_STAGES);
065: }
066:
067: /**
068: * Constructs a new search in options.
069: *
070: * @param dialog Configuration dialog
071: */
072: public SearchInOptions(ConfigDialog dialog) {
073: super ();
074: this .m_dialog = dialog;
075: this .setup();
076: }
077:
078: private boolean isPathHiddenRoot(String sPath) {
079: boolean bHidden = false;
080:
081: Iterator itor = SearchInOptions.m_hiddenRootPaths.iterator();
082: while (itor.hasNext()) {
083: String sRootPath = (String) itor.next();
084: if (sPath.equals(sRootPath) || sPath.startsWith(sRootPath)) {
085: bHidden = true;
086: }
087: }
088:
089: return bHidden;
090: }
091:
092: /**
093: * Configures this options class.
094: *
095: */
096: private void setup() {
097: this .m_dialog.addApplyChangesListener(this );
098:
099: this .setLayout(this );
100:
101: List aValues = ConfigStore.getInstance().getPropertyVals(
102: "SEARCHPATHS");
103: Server server = ServerList.getInstance().getHarmoniseServer();
104:
105: if (aValues != null) {
106:
107: ArrayList aRemovePaths = new ArrayList();
108:
109: Iterator itor = aValues.iterator();
110: while (itor.hasNext()) {
111: String sTempPath = (String) itor.next();
112: if (server.getVFS().getVirtualFile(sTempPath) == null) {
113: aRemovePaths.add(sTempPath);
114: }
115: }
116: if (aRemovePaths.size() > 0) {
117: aValues.removeAll(aRemovePaths);
118: ConfigStore.getInstance().setProperty("SEARCHPATHS",
119: (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 fontName = "Dialog";
133: int fontSize = 11;
134: Font font = new Font(fontName, Font.PLAIN, fontSize);
135:
136: VirtualFile vfFile = server.getVFS().getVirtualFile(
137: "/" + server.getVFS().getRootPathSegment() + "/")
138: .getResource();
139: List children = vfFile.getChildren();
140: Iterator itor2 = children.iterator();
141: while (itor2.hasNext()) {
142: VirtualFile vfDir = server.getVFS().getVirtualFile(
143: (String) itor2.next()).getResource();
144: if (vfDir.isDirectory()
145: && !this .isPathHiddenRoot(vfDir.getFullPath())) {
146: this .m_tree.addCollection(vfDir);
147: }
148: }
149: }
150:
151: /* (non-Javadoc)
152: * @see java.awt.Component#getPreferredSize()
153: */
154: public Dimension getPreferredSize() {
155: return new Dimension(this .getParent().getSize().width, 200);
156: }
157:
158: /* (non-Javadoc)
159: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
160: */
161: public boolean applyChanges() {
162: if (this .m_bChanged) {
163:
164: ConfigStore.getInstance().setProperty("SEARCHPATHS",
165: (ArrayList) this .m_tree.getPathValues());
166:
167: this .m_bChanged = false;
168: }
169: return true;
170: }
171:
172: /* (non-Javadoc)
173: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
174: */
175: public void layoutContainer(Container arg0) {
176: int nHeight = 0;
177:
178: this .m_tree.setSize(this .getParent().getSize().width - 20, 280);
179: this .m_tree.setLocation(10, nHeight + 20);
180:
181: }
182:
183: /* (non-Javadoc)
184: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
185: */
186: public Dimension minimumLayoutSize(Container arg0) {
187: return this .getPreferredSize();
188: }
189:
190: /* (non-Javadoc)
191: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
192: */
193: public Dimension preferredLayoutSize(Container arg0) {
194: return this .getPreferredSize();
195: }
196:
197: /* (non-Javadoc)
198: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
199: */
200: public void removeLayoutComponent(Component arg0) {
201: }
202:
203: /* (non-Javadoc)
204: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
205: */
206: public void addLayoutComponent(String arg0, Component arg1) {
207: }
208:
209: /**
210: * @param arg0
211: */
212: private SearchInOptions(boolean arg0) {
213: super (arg0);
214: }
215:
216: /**
217: * @param arg0
218: */
219: private SearchInOptions(LayoutManager arg0) {
220: super (arg0);
221: }
222:
223: /**
224: * @param arg0
225: * @param arg1
226: */
227: private SearchInOptions(LayoutManager arg0, boolean arg1) {
228: super (arg0, arg1);
229: }
230:
231: /* (non-Javadoc)
232: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
233: */
234: public void discardChanges() {
235:
236: }
237:
238: /* (non-Javadoc)
239: * @see com.simulacramedia.contentmanager.swing.resourcetree.formresourcetree.FormResourceTreeListener#pathValuesChanged(java.util.List)
240: */
241: public void pathValuesChanged(List pathValues) {
242: this .m_bChanged = true;
243: }
244:
245: }
|