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