KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > swing > resourcetree > AbstractResourceFilter


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.swing.resourcetree;
20
21 import org.openharmonise.vfs.*;
22
23 /**
24  * Base class to use when building resource filters for resource trees. A
25  * resource filter will check each resource before it is added to the resource
26  * tree.
27  *
28  * @author Matthew Large
29  * @version $Revision: 1.1 $
30  *
31  */

32 public abstract class AbstractResourceFilter {
33     
34     /**
35      * True to show collections only.
36      */

37     private boolean m_bShowCollectionsOnly = false;
38     
39     /**
40      * True to show published resources only.
41      */

42     private boolean m_bShowLiveResourcesOnly = false;
43
44     /**
45      * Construcs a new abstract resource filter.
46      */

47     public AbstractResourceFilter() {
48         super();
49     }
50     
51     /**
52      * Sets whether only collections should be shown.
53      *
54      * @param bShowCollectionsOnly true to only show collections.
55      */

56     public void setShowCollectionsOnly(boolean bShowCollectionsOnly) {
57         this.m_bShowCollectionsOnly = bShowCollectionsOnly;
58     }
59     
60     /**
61      * Checks if only collections are to be shown.
62      *
63      * @return true if only collections are to be shown.
64      */

65     public boolean isShowCollectionsOnly() {
66         return this.m_bShowCollectionsOnly;
67     }
68
69     /**
70      * Sets whether only published resources should be shown.
71      *
72      * @param bShowLiveResourcesOnly true if only published resources are to be shown.
73      */

74     public void setShowLiveResourcesOnly(boolean bShowLiveResourcesOnly) {
75         this.m_bShowLiveResourcesOnly = bShowLiveResourcesOnly;
76     }
77     
78     /**
79      * Checks if only published resources are to be shown.
80      *
81      * @return true if only published resources are to be shown.
82      */

83     public boolean isShowLiveResourcesOnly() {
84         return this.m_bShowLiveResourcesOnly;
85     }
86     
87     /**
88      * Checks whether a resource should be shown.
89      *
90      * @param vfFile resource to check.
91      * @return true if the resource should be shown.
92      */

93     public boolean showResource(VirtualFile vfFile) {
94         boolean bShowResource = true;
95         
96         if(this.m_bShowCollectionsOnly && !vfFile.isDirectory()) {
97             bShowResource = false;
98         }
99         
100         if(bShowResource
101                 && this.m_bShowLiveResourcesOnly
102                 && vfFile.isVersionable()
103                 && !vfFile.getState().equals(VirtualFile.STATE_LIVE)) {
104             bShowResource = false;
105         }
106         
107         if(bShowResource
108                 && !this.checkResource(vfFile)) {
109             bShowResource = false;
110         }
111         
112         return bShowResource;
113     }
114     
115     /**
116      * Checks whether a resource should be shown.
117      *
118      * @param vfFile resource to check.
119      * @return true if the resource should be shown.
120      */

121     protected abstract boolean checkResource(VirtualFile vfFile);
122 }
123
Popular Tags