svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / ViewsDocumentStoresRepository.java @ 47585
History | View | Annotate | Download (5.5 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.app.project.documents.view; |
7 |
|
8 |
import java.util.ArrayList; |
9 |
import java.util.Collection; |
10 |
import java.util.Collections; |
11 |
import java.util.HashMap; |
12 |
import java.util.List; |
13 |
import java.util.Map; |
14 |
import org.gvsig.app.project.Project; |
15 |
import org.gvsig.app.project.ProjectManager; |
16 |
import org.gvsig.app.project.documents.Document; |
17 |
import org.gvsig.fmap.dal.AbstractStoresRepository; |
18 |
import org.gvsig.fmap.dal.DALLocator; |
19 |
import org.gvsig.fmap.dal.DataManager; |
20 |
import org.gvsig.fmap.dal.DataStoreParameters; |
21 |
import org.gvsig.fmap.dal.StoresRepository; |
22 |
import org.gvsig.fmap.dal.feature.FeatureType; |
23 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
24 |
|
25 |
/**
|
26 |
*
|
27 |
* @author jjdelcerro
|
28 |
*/
|
29 |
class ViewsDocumentStoresRepository extends AbstractStoresRepository { |
30 |
|
31 |
public ViewsDocumentStoresRepository(String name) { |
32 |
super(name);
|
33 |
} |
34 |
|
35 |
@Override
|
36 |
public Collection<StoresRepository> getSubrepositories() { |
37 |
this.subrepositories = new ArrayList<>(); |
38 |
Map<String, ViewDocumentStoresRepository> subrepos = this.getAll(); |
39 |
if( subrepos!=null ) { |
40 |
for (ViewDocumentStoresRepository repo : subrepos.values()) {
|
41 |
this.subrepositories.add(repo);
|
42 |
} |
43 |
} |
44 |
return this.subrepositories; |
45 |
} |
46 |
|
47 |
private List<ViewDocument> getOrderedViews() { |
48 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
49 |
if( project==null ) { |
50 |
return null; |
51 |
} |
52 |
List<Document> allViews = project.getDocuments(ViewManager.TYPENAME); |
53 |
List<Document> openViews = project.getOpenDocuments(ViewManager.TYPENAME); |
54 |
List<ViewDocument> views = new ArrayList<>(); |
55 |
for (Document view : openViews) { |
56 |
views.add((ViewDocument) view); |
57 |
} |
58 |
for (Document view : allViews) { |
59 |
if (!openViews.contains(view)) {
|
60 |
views.add((ViewDocument) view); |
61 |
} |
62 |
} |
63 |
return views;
|
64 |
} |
65 |
|
66 |
private Map<String, ViewDocumentStoresRepository> getAll() { |
67 |
Map<String, ViewDocumentStoresRepository> all = new HashMap<>(); |
68 |
List<ViewDocument> views = getOrderedViews();
|
69 |
if( views == null ) { |
70 |
return null; |
71 |
} |
72 |
for (ViewDocument view : views) {
|
73 |
String theName = view.getName();
|
74 |
if (all.containsKey(theName)) {
|
75 |
theName = theName + "$" + view.getName();
|
76 |
int counter = 1; |
77 |
while (all.containsKey(theName + counter)) {
|
78 |
counter++; |
79 |
} |
80 |
theName = theName + counter; |
81 |
} |
82 |
all.put(theName, new ViewDocumentStoresRepository(theName, view));
|
83 |
} |
84 |
if (all.isEmpty()) {
|
85 |
return null; |
86 |
} |
87 |
return all;
|
88 |
} |
89 |
|
90 |
// private Map<String, Pair<FeatureType, FeatureStore>> getAllFeatureTypes() {
|
91 |
// Map<String, Pair<FeatureType, FeatureStore>> all = new HashMap<>();
|
92 |
// Project project = ProjectManager.getInstance().getCurrentProject();
|
93 |
// List<Document> views = project.getDocuments(ViewManager.TYPENAME);
|
94 |
// // MutablePair<DataStore,String> storeAndName = new MutablePair<>();
|
95 |
// for (Document view : views) {
|
96 |
// for (FLayer layer : ((ViewDocument) view).layers()) {
|
97 |
// if (layer instanceof FLyrVect) {
|
98 |
// FeatureStore store = ((FLyrVect) layer).getFeatureStore();
|
99 |
// if (store != null) {
|
100 |
// String theName = layer.getName();
|
101 |
// if (all.containsKey(theName)) {
|
102 |
// theName = theName + "$";
|
103 |
// int counter = 1;
|
104 |
// while (all.containsKey(theName + counter)) {
|
105 |
// counter++;
|
106 |
// }
|
107 |
// theName = theName + counter;
|
108 |
// }
|
109 |
// // storeAndName.setLeft(store);
|
110 |
// // storeAndName.setRight(theName);
|
111 |
// // if( filter == null || filter.test(storeAndName) ) {
|
112 |
// all.put(theName, new ImmutablePair<>(store.getDefaultFeatureTypeQuietly(), store));
|
113 |
// // }
|
114 |
// }
|
115 |
// }
|
116 |
// // if (limit > 0 && all.size() >= limit) {
|
117 |
// // break;
|
118 |
// // }
|
119 |
// }
|
120 |
// }
|
121 |
// if (all.isEmpty()) {
|
122 |
// return null;
|
123 |
// }
|
124 |
// return all;
|
125 |
// }
|
126 |
|
127 |
@Override
|
128 |
protected DataStoreParameters getMyParameters(final String name) { |
129 |
return null; |
130 |
} |
131 |
|
132 |
@Override
|
133 |
protected FeatureType getMyFeatureType(String name) { |
134 |
return null; |
135 |
} |
136 |
|
137 |
|
138 |
@Override
|
139 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
140 |
return null; |
141 |
} |
142 |
|
143 |
@Override
|
144 |
protected boolean isEmptyMyRepository() { |
145 |
return true; |
146 |
} |
147 |
|
148 |
@Override
|
149 |
protected int getMySize() { |
150 |
return 0; |
151 |
} |
152 |
|
153 |
public static void selfRegister() { |
154 |
DataManager dataManager = DALLocator.getDataManager(); |
155 |
dataManager.getStoresRepository().addRepository(new ViewsDocumentStoresRepository("Project Views")); |
156 |
} |
157 |
|
158 |
} |