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.swing.resourcetree;
020:
021: import org.openharmonise.vfs.*;
022:
023: /**
024: * Base class to use when building resource filters for resource trees. A
025: * resource filter will check each resource before it is added to the resource
026: * tree.
027: *
028: * @author Matthew Large
029: * @version $Revision: 1.1 $
030: *
031: */
032: public abstract class AbstractResourceFilter {
033:
034: /**
035: * True to show collections only.
036: */
037: private boolean m_bShowCollectionsOnly = false;
038:
039: /**
040: * True to show published resources only.
041: */
042: private boolean m_bShowLiveResourcesOnly = false;
043:
044: /**
045: * Construcs a new abstract resource filter.
046: */
047: public AbstractResourceFilter() {
048: super ();
049: }
050:
051: /**
052: * Sets whether only collections should be shown.
053: *
054: * @param bShowCollectionsOnly true to only show collections.
055: */
056: public void setShowCollectionsOnly(boolean bShowCollectionsOnly) {
057: this .m_bShowCollectionsOnly = bShowCollectionsOnly;
058: }
059:
060: /**
061: * Checks if only collections are to be shown.
062: *
063: * @return true if only collections are to be shown.
064: */
065: public boolean isShowCollectionsOnly() {
066: return this .m_bShowCollectionsOnly;
067: }
068:
069: /**
070: * Sets whether only published resources should be shown.
071: *
072: * @param bShowLiveResourcesOnly true if only published resources are to be shown.
073: */
074: public void setShowLiveResourcesOnly(boolean bShowLiveResourcesOnly) {
075: this .m_bShowLiveResourcesOnly = bShowLiveResourcesOnly;
076: }
077:
078: /**
079: * Checks if only published resources are to be shown.
080: *
081: * @return true if only published resources are to be shown.
082: */
083: public boolean isShowLiveResourcesOnly() {
084: return this .m_bShowLiveResourcesOnly;
085: }
086:
087: /**
088: * Checks whether a resource should be shown.
089: *
090: * @param vfFile resource to check.
091: * @return true if the resource should be shown.
092: */
093: public boolean showResource(VirtualFile vfFile) {
094: boolean bShowResource = true;
095:
096: if (this .m_bShowCollectionsOnly && !vfFile.isDirectory()) {
097: bShowResource = false;
098: }
099:
100: if (bShowResource && this .m_bShowLiveResourcesOnly
101: && vfFile.isVersionable()
102: && !vfFile.getState().equals(VirtualFile.STATE_LIVE)) {
103: bShowResource = false;
104: }
105:
106: if (bShowResource && !this .checkResource(vfFile)) {
107: bShowResource = false;
108: }
109:
110: return bShowResource;
111: }
112:
113: /**
114: * Checks whether a resource should be shown.
115: *
116: * @param vfFile resource to check.
117: * @return true if the resource should be shown.
118: */
119: protected abstract boolean checkResource(VirtualFile vfFile);
120: }
|