Revision 21390 branches/v10/extensions/extPublish/src/org/gvsig/publish/infoproject/FilterProjectInfo.java
FilterProjectInfo.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package org.gvsig.publish.infoproject; |
42 | 42 |
|
43 |
import java.util.ArrayList; |
|
44 |
import java.util.HashSet; |
|
45 |
import java.util.Iterator; |
|
46 |
import java.util.Set; |
|
43 | 47 |
|
48 |
|
|
44 | 49 |
/** |
45 | 50 |
* This class define a filter in the project information. You can filter layers with |
46 | 51 |
* a specific datasource, avoid grouped layers, ... |
... | ... | |
50 | 55 |
*/ |
51 | 56 |
public class FilterProjectInfo { |
52 | 57 |
private boolean groupedLayers=true; |
58 |
private Set datasources= new HashSet(); |
|
53 | 59 |
/** |
54 | 60 |
* Filter grouped layers. All the layers will be at the same level. |
55 | 61 |
* @param groupedLayers must be false in order to remove all grouped layers |
56 | 62 |
*/ |
57 |
public void setGroupedLayers(boolean groupedLayers) { |
|
63 |
public void setGroupedLayersEnabled(boolean groupedLayers) {
|
|
58 | 64 |
this.groupedLayers = groupedLayers; |
59 | 65 |
} |
60 | 66 |
/** |
61 | 67 |
* @return the groupedLayers |
62 | 68 |
*/ |
63 |
public boolean isGroupedLayers() { |
|
69 |
public boolean isGroupedLayersEnabled() {
|
|
64 | 70 |
return groupedLayers; |
65 | 71 |
} |
72 |
/** |
|
73 |
* |
|
74 |
* @param datasourceType which will be enable like IDataSourceInfo.POSTGIS_TYPE, ... |
|
75 |
* @see org.gvsig.publish.infoproject.IDataSourceInfo |
|
76 |
*/ |
|
77 |
public void addAllowedDatasource(String datasourceType ){ |
|
78 |
datasources.add(datasourceType); |
|
79 |
} |
|
80 |
/** |
|
81 |
* Check if a datasource is in the white list of datasources |
|
82 |
* @param datasourceType |
|
83 |
* @return |
|
84 |
*/ |
|
85 |
public boolean isAllowedDatasource(IDataSourceInfo ds){ |
|
86 |
if (ds == null){ |
|
87 |
return false; |
|
88 |
}else{ |
|
89 |
return datasources.contains(ds.getType()); |
|
90 |
} |
|
91 |
|
|
92 |
} |
|
93 |
/** |
|
94 |
* Utility for convert a tree of LayerInfos in a list of them. It delete the grouped layers. |
|
95 |
* @param layers |
|
96 |
* @return |
|
97 |
*/ |
|
98 |
public ILayerInfo[] toList(ILayerInfo[] layers){ |
|
99 |
ArrayList list = new ArrayList(); |
|
100 |
for (int i = 0; i < layers.length; i++){ |
|
101 |
ILayerInfo[] childs = layers[i].getChilds(); |
|
102 |
if (childs == null){ |
|
103 |
list.add(layers[i]); |
|
104 |
}else{ |
|
105 |
ILayerInfo[] aux2 = toList(childs); |
|
106 |
for (int j=0; j< aux2.length; j++){ |
|
107 |
list.add(aux2[j]); |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
ILayerInfo[] res = new ILayerInfo[list.size()]; |
|
112 |
for (int k = 0; k < list.size(); k++){ |
|
113 |
res[k] = (ILayerInfo)list.get(k); |
|
114 |
} |
|
115 |
return res; |
|
116 |
} |
|
66 | 117 |
|
118 |
public boolean isFiltered(ILayerInfo layer){ |
|
119 |
//a group is not filtered |
|
120 |
if(layer.getDataSource() == null){ |
|
121 |
return false; |
|
122 |
}else{ |
|
123 |
boolean aux = false; |
|
124 |
Iterator i = datasources.iterator(); |
|
125 |
while (i.hasNext()){ |
|
126 |
String dstype = i.next().toString(); |
|
127 |
aux = aux || dstype == layer.getDataSource().getDataType(); |
|
128 |
} |
|
129 |
return aux; |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
67 | 133 |
} |
Also available in: Unified diff