Revision 44304 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/project/documents/table/TableManager.java
TableManager.java | ||
---|---|---|
27 | 27 |
import java.util.Collections; |
28 | 28 |
import java.util.Iterator; |
29 | 29 |
import java.util.List; |
30 |
import java.util.Map; |
|
31 | 30 |
import java.util.function.Function; |
32 | 31 |
|
33 | 32 |
import javax.swing.ImageIcon; |
34 |
import org.apache.commons.lang3.StringUtils; |
|
35 | 33 |
|
36 | 34 |
import org.gvsig.andami.IconThemeHelper; |
37 | 35 |
import org.gvsig.andami.PluginServices; |
... | ... | |
53 | 51 |
import org.gvsig.app.project.documents.table.TableDocument.TableLink; |
54 | 52 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
55 | 53 |
import org.gvsig.app.project.documents.table.gui.TableProperties; |
54 |
import org.gvsig.fmap.dal.AbstractStoresRepository; |
|
56 | 55 |
import org.gvsig.fmap.dal.DALLocator; |
57 | 56 |
import org.gvsig.fmap.dal.DataManager; |
58 | 57 |
import org.gvsig.fmap.dal.DataStoreParameters; |
... | ... | |
68 | 67 |
import org.gvsig.tools.evaluator.Evaluator; |
69 | 68 |
import org.gvsig.tools.persistence.PersistenceManager; |
70 | 69 |
import org.gvsig.tools.util.MappedIterator; |
71 |
import org.gvsig.tools.util.UnmodifiableBasicMap; |
|
72 | 70 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
73 |
import org.gvsig.tools.util.UnmodifiableBasicSetMapped; |
|
74 | 71 |
|
75 | 72 |
/** |
76 | 73 |
* Factory of Table. |
... | ... | |
81 | 78 |
*/ |
82 | 79 |
public class TableManager extends AbstractDocumentManager { |
83 | 80 |
|
84 |
private static class TableDocumentStoresRepository implements UnmodifiableBasicMap<String,DataStoreParameters> {
|
|
81 |
private static class TableDocumentStoresRepository extends AbstractStoresRepository {
|
|
85 | 82 |
|
83 |
public TableDocumentStoresRepository(String name) { |
|
84 |
super(name); |
|
85 |
} |
|
86 |
|
|
86 | 87 |
@Override |
87 |
public DataStoreParameters get(String name) {
|
|
88 |
protected DataStoreParameters getMyParameters(String name) {
|
|
88 | 89 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
89 | 90 |
TableDocument tableDoc = (TableDocument) project.getDocument(name, TYPENAME); |
90 | 91 |
if( tableDoc==null ) { |
... | ... | |
94 | 95 |
} |
95 | 96 |
|
96 | 97 |
@Override |
97 |
public boolean containsKey(String key) {
|
|
98 |
protected boolean isEmptyMyRepository() {
|
|
98 | 99 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
99 |
for (Document document : project.getDocuments(TableManager.TYPENAME)) { |
|
100 |
if( StringUtils.equalsIgnoreCase(key, document.getName()) ) { |
|
101 |
return true; |
|
102 |
} |
|
103 |
} |
|
104 |
return false; |
|
100 |
return project.getDocuments(TableManager.TYPENAME).isEmpty(); |
|
105 | 101 |
} |
106 | 102 |
|
107 | 103 |
@Override |
108 |
public UnmodifiableBasicSet<String> keySet() {
|
|
104 |
protected int getMySize() {
|
|
109 | 105 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
110 |
List<Document> docs = project.getDocuments(TableManager.TYPENAME); |
|
106 |
int sz = project.getDocuments(TableManager.TYPENAME).size(); |
|
107 |
return sz; |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
|
112 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
113 |
final List<Document> docs = project.getDocuments(TableManager.TYPENAME); |
|
111 | 114 |
if( docs==null ) { |
112 | 115 |
return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET; |
113 | 116 |
} |
114 |
return new UnmodifiableBasicSetMapped<>(docs, new Function<Document, String>() {
|
|
117 |
UnmodifiableBasicSet<String> x = new UnmodifiableBasicSet<String>() {
|
|
115 | 118 |
@Override |
116 |
public String apply(Document t) {
|
|
117 |
return t.getName();
|
|
119 |
public boolean isEmpty() {
|
|
120 |
return docs.isEmpty();
|
|
118 | 121 |
} |
119 |
}); |
|
120 |
} |
|
121 | 122 |
|
122 |
@Override |
|
123 |
public Map<String, DataStoreParameters> toMap() {
|
|
124 |
return null;
|
|
125 |
} |
|
123 |
@Override
|
|
124 |
public int size() {
|
|
125 |
return docs.size();
|
|
126 |
}
|
|
126 | 127 |
|
127 |
@Override |
|
128 |
public boolean isEmpty() { |
|
129 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
130 |
return project.getDocuments(TableManager.TYPENAME).isEmpty(); |
|
128 |
@Override |
|
129 |
public Iterator<String> iterator() { |
|
130 |
return new MappedIterator<>(docs.iterator(), new Function<Document, String>() { |
|
131 |
@Override |
|
132 |
public String apply(Document t) { |
|
133 |
return ((TableDocument)t).getName(); |
|
134 |
} |
|
135 |
}); |
|
136 |
} |
|
137 |
}; |
|
138 |
return x; |
|
131 | 139 |
} |
132 | 140 |
|
141 |
|
|
133 | 142 |
@Override |
134 |
public int size() { |
|
135 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
136 |
int sz = project.getDocuments(TableManager.TYPENAME).size(); |
|
137 |
return sz; |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 | 143 |
public Iterator<DataStoreParameters> iterator() { |
142 | 144 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
143 | 145 |
List<Document> docs = project.getDocuments(TableManager.TYPENAME); |
... | ... | |
294 | 296 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction()); |
295 | 297 |
|
296 | 298 |
DataManager dataManager = DALLocator.getDataManager(); |
297 |
dataManager.addStoresRepository("TableDocuments", new TableDocumentStoresRepository());
|
|
299 |
dataManager.getStoresRepository().addRepository(new TableDocumentStoresRepository("Tables"));
|
|
298 | 300 |
} |
299 | 301 |
|
300 | 302 |
/** |
... | ... | |
302 | 304 |
* |
303 | 305 |
* @return TableDocument. |
304 | 306 |
*/ |
307 |
@Override |
|
305 | 308 |
public AbstractDocument createDocument() { |
306 | 309 |
AbstractDocument doc = new TableDocument(this); |
307 | 310 |
if( this.notifyObservers(NOTIFY_AFTER_CREATEDOCUMENT,doc).isCanceled() ) { |
Also available in: Unified diff