svn-gvsig-desktop / 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 @ 40596
History | View | Annotate | Download (11.5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.app.project.documents.table; |
26 |
|
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
import javax.swing.ImageIcon; |
31 |
|
32 |
import org.gvsig.andami.IconThemeHelper; |
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.messages.NotificationManager; |
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
36 |
import org.gvsig.app.ApplicationLocator; |
37 |
import org.gvsig.app.addlayer.AddLayerDialog; |
38 |
import org.gvsig.app.gui.WizardPanel; |
39 |
import org.gvsig.app.project.Project; |
40 |
import org.gvsig.app.project.ProjectManager; |
41 |
import org.gvsig.app.project.documents.AbstractDocument; |
42 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
43 |
import org.gvsig.app.project.documents.Document; |
44 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
45 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
46 |
import org.gvsig.app.project.documents.table.TableDocument.TableLink; |
47 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
48 |
import org.gvsig.app.project.documents.table.gui.TableProperties; |
49 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
50 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
51 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
52 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel; |
53 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
54 |
import org.gvsig.fmap.mapcontext.layers.vectorial.VectorLayer; |
55 |
import org.gvsig.tools.ToolsLocator; |
56 |
import org.gvsig.tools.dynobject.DynObjectManager; |
57 |
import org.gvsig.tools.dynobject.DynStruct; |
58 |
import org.gvsig.tools.evaluator.Evaluator; |
59 |
import org.gvsig.tools.persistence.PersistenceManager; |
60 |
|
61 |
/**
|
62 |
* Factory of Table.
|
63 |
*
|
64 |
* @author 2005- Vicente Caballero
|
65 |
* @author 2009- Joaquin del Cerro
|
66 |
*
|
67 |
*/
|
68 |
public class TableManager extends AbstractDocumentManager { |
69 |
|
70 |
public static final String PERSISTENCE_TABLE_DOCUMENT_DEFINITION_NAME = |
71 |
"TableDocument";
|
72 |
public static final String PERSISTENCE_TABLELINK_DEFINITION_NAME = |
73 |
"TableLink";
|
74 |
|
75 |
public static String TYPENAME = "project.document.table"; |
76 |
|
77 |
private DynStruct persistenceDefinition = null; |
78 |
|
79 |
public ImageIcon getIcon() { |
80 |
return IconThemeHelper.getImageIcon("document-table-icon"); |
81 |
} |
82 |
|
83 |
public ImageIcon getIconSelected() { |
84 |
return IconThemeHelper.getImageIcon("document-table-icon-sel"); |
85 |
} |
86 |
|
87 |
public String getTitle() { |
88 |
return PluginServices.getText(this, "Tabla"); |
89 |
} |
90 |
|
91 |
public String getTypeName() { |
92 |
return TYPENAME;
|
93 |
} |
94 |
|
95 |
public int getPriority() { |
96 |
return 1; |
97 |
} |
98 |
|
99 |
public Iterator<? extends Document> createDocumentsByUser() { |
100 |
AddLayerDialog fopen = null;
|
101 |
try {
|
102 |
fopen = |
103 |
new AddLayerDialog(PluginServices.getText(this, "Nueva_tabla")); |
104 |
List<WizardPanel> wizards =
|
105 |
ApplicationLocator.getManager().getWizardPanels(); |
106 |
WizardPanel panel; |
107 |
Iterator<WizardPanel> iter = wizards.iterator();
|
108 |
while (iter.hasNext()) {
|
109 |
panel = iter.next(); |
110 |
fopen.addWizardTab(panel.getTabName(), panel); |
111 |
panel.initWizard(); |
112 |
} |
113 |
PluginServices.getMDIManager().addWindow(fopen); |
114 |
if (fopen.isAccepted()) {
|
115 |
panel = (WizardPanel) fopen.getSelectedTab(); |
116 |
@SuppressWarnings("unchecked") |
117 |
List<TableDocument> docs =
|
118 |
(List<TableDocument>) panel.executeWizard();
|
119 |
return docs.iterator();
|
120 |
} |
121 |
} catch (Exception e) { |
122 |
NotificationManager.addError(e); |
123 |
} finally {
|
124 |
if (fopen != null) { |
125 |
fopen.dispose(); |
126 |
fopen = null;
|
127 |
} |
128 |
} |
129 |
return null; |
130 |
} |
131 |
|
132 |
public AbstractDocument createDocumentByUser() { |
133 |
return (AbstractDocument) createDocumentsByUser().next(); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Registers in the points of extension the Factory with alias.
|
138 |
*
|
139 |
*/
|
140 |
public static void register() { |
141 |
|
142 |
TableManager factory = new TableManager();
|
143 |
// A?adimos nuestra extension para el tratamiento de la apertura de
|
144 |
// ficheros
|
145 |
// dentro de gvSIG
|
146 |
ToolsLocator.getExtensionPointManager().add("FileTableOpenDialog", "") |
147 |
.append("FileOpenTable", "", FilesystemExplorerWizardPanel.class); |
148 |
|
149 |
// ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"copy",new
|
150 |
// CopyDocumentContextMenuAction());
|
151 |
// ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"cut",new
|
152 |
// CutDocumentContextMenuAction());
|
153 |
// ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"paste",new
|
154 |
// PasteDocumentContextMenuAction());
|
155 |
|
156 |
IconThemeHelper.registerIcon("document", "document-table-icon", TableManager.class); |
157 |
IconThemeHelper.registerIcon("document", "document-table-icon-sel", TableManager.class); |
158 |
IconThemeHelper.registerIcon("document", "document-table-icon-small", TableManager.class); |
159 |
|
160 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
161 |
manager.registerFactory(factory); |
162 |
|
163 |
if (factory.persistenceDefinition == null) { |
164 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
165 |
factory.persistenceDefinition = |
166 |
dynman.createDynClass(PersistenceManager.PERSISTENCE_NAMESPACE, |
167 |
PERSISTENCE_TABLE_DOCUMENT_DEFINITION_NAME, |
168 |
"Table document Persistence definition");
|
169 |
factory.persistenceDefinition.extend(manager |
170 |
.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
171 |
|
172 |
factory.persistenceDefinition.addDynFieldObject("store")
|
173 |
.setClassOfValue(FeatureStore.class).setMandatory(true);
|
174 |
factory.persistenceDefinition.addDynFieldString("featureTypeId")
|
175 |
.setMandatory(false);
|
176 |
factory.persistenceDefinition.addDynFieldArray("attributeNames")
|
177 |
.setClassOfItems(String.class).setMandatory(false); |
178 |
factory.persistenceDefinition.addDynFieldObject("associatedLayer")
|
179 |
.setClassOfValue(FLyrVect.class).setMandatory(false);
|
180 |
factory.persistenceDefinition.addDynFieldObject("query")
|
181 |
.setClassOfValue(FeatureQuery.class).setMandatory(false);
|
182 |
factory.persistenceDefinition.addDynFieldObject("baseFilter")
|
183 |
.setClassOfValue(Evaluator.class).setMandatory(false);
|
184 |
factory.persistenceDefinition.addDynFieldObject("baseOrder")
|
185 |
.setClassOfValue(FeatureQueryOrder.class).setMandatory(false);
|
186 |
factory.persistenceDefinition.addDynFieldList("linkTable")
|
187 |
.setClassOfItems(TableLink.class).setMandatory(false);
|
188 |
} |
189 |
|
190 |
|
191 |
//Register also the TableLink
|
192 |
if (manager.getDefinition(PERSISTENCE_TABLELINK_DEFINITION_NAME) == null){ |
193 |
DynStruct tableLinkDefinition = |
194 |
manager.addDefinition(TableLink.class, |
195 |
PERSISTENCE_TABLELINK_DEFINITION_NAME, |
196 |
"TableLink Persistence definition", null, null); |
197 |
|
198 |
tableLinkDefinition.addDynFieldObject("source")
|
199 |
.setClassOfValue(TableDocument.class).setMandatory(true);
|
200 |
tableLinkDefinition.addDynFieldObject("target")
|
201 |
.setClassOfValue(TableDocument.class).setMandatory(true);
|
202 |
tableLinkDefinition.addDynFieldString("fieldSource").setMandatory(true); |
203 |
tableLinkDefinition.addDynFieldString("fieldTarget").setMandatory(true); |
204 |
tableLinkDefinition.addDynFieldBoolean("enabled").setMandatory(true); |
205 |
} |
206 |
|
207 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
208 |
} |
209 |
|
210 |
/**
|
211 |
* Create a new table document.
|
212 |
*
|
213 |
* @return TableDocument.
|
214 |
*/
|
215 |
public AbstractDocument createDocument() { |
216 |
return new TableDocument(this); |
217 |
} |
218 |
|
219 |
public Class<? extends IDocumentWindow> getMainWindowClass() { |
220 |
return FeatureTableDocumentPanel.class;
|
221 |
} |
222 |
|
223 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
224 |
IDocumentWindow tablePanel; |
225 |
tablePanel = |
226 |
(IDocumentWindow) PluginServices.getMDIManager() |
227 |
.getSingletonWindow(getMainWindowClass(), doc); |
228 |
if (tablePanel != null) { |
229 |
// The table window document is already created, return it.
|
230 |
return tablePanel;
|
231 |
} |
232 |
|
233 |
tablePanel = (IDocumentWindow) this.createDocumentWindow(doc);
|
234 |
if (layout != null && tablePanel != null) { |
235 |
tablePanel.setWindowLayout(layout); |
236 |
} |
237 |
return tablePanel;
|
238 |
} |
239 |
|
240 |
public IWindow getPropertiesWindow(Document doc) { |
241 |
|
242 |
// IWindow mainwin =
|
243 |
// PluginServices.getMDIManager().getSingletonWindow(FeatureTableDocumentPanel.class,
|
244 |
// doc);
|
245 |
return new TableProperties((TableDocument) doc); |
246 |
} |
247 |
|
248 |
protected Class<? extends Document> getDocumentClass() { |
249 |
return TableDocument.class;
|
250 |
} |
251 |
|
252 |
public DynStruct getDefinition(String className) { |
253 |
|
254 |
if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
255 |
return this.persistenceDefinition; |
256 |
} |
257 |
if (this.persistenceDefinition.getFullName() |
258 |
.equalsIgnoreCase(className)) { |
259 |
return this.persistenceDefinition; |
260 |
} |
261 |
if (this.getDocumentClass().getName().equals(className)) { |
262 |
return this.persistenceDefinition; |
263 |
} |
264 |
return null; |
265 |
} |
266 |
|
267 |
public boolean manages(Object object) { |
268 |
return object instanceof TableDocument; |
269 |
} |
270 |
|
271 |
public TableDocument getTableDocument(VectorLayer layer) {
|
272 |
if (layer == null) { |
273 |
return null; |
274 |
} |
275 |
List<Document> tableDocs = |
276 |
getProject().getDocuments(TableManager.TYPENAME); |
277 |
for (Document document : tableDocs) { |
278 |
if (layer == ((TableDocument) document).getAssociatedLayer()) {
|
279 |
return (TableDocument) document;
|
280 |
} |
281 |
} |
282 |
return null; |
283 |
} |
284 |
|
285 |
public void removeTableDocument(VectorLayer layer) { |
286 |
TableDocument doc = getTableDocument(layer); |
287 |
// Only remove it if it exists
|
288 |
if (doc != null) { |
289 |
PluginServices.getMDIManager().closeSingletonWindow(doc); |
290 |
getProject().remove(doc); |
291 |
} |
292 |
} |
293 |
|
294 |
private Project getProject() {
|
295 |
return ProjectManager.getInstance().getCurrentProject();
|
296 |
} |
297 |
} |