svn-gvsig-desktop / tags / v2_0_0_Build_2058 / 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 @ 39255
History | View | Annotate | Download (11.5 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 |
IconThemeHelper.registerIcon("document", "document-table-icon-small", TableManager.class); |
163 |
|
164 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
165 |
manager.registerFactory(factory); |
166 |
|
167 |
if (factory.persistenceDefinition == null) { |
168 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
169 |
factory.persistenceDefinition = |
170 |
dynman.createDynClass(PersistenceManager.PERSISTENCE_NAMESPACE, |
171 |
PERSISTENCE_TABLE_DOCUMENT_DEFINITION_NAME, |
172 |
"Table document Persistence definition");
|
173 |
factory.persistenceDefinition.extend(manager |
174 |
.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
175 |
|
176 |
factory.persistenceDefinition.addDynFieldObject("store")
|
177 |
.setClassOfValue(FeatureStore.class).setMandatory(true);
|
178 |
factory.persistenceDefinition.addDynFieldString("featureTypeId")
|
179 |
.setMandatory(false);
|
180 |
factory.persistenceDefinition.addDynFieldArray("attributeNames")
|
181 |
.setClassOfItems(String.class).setMandatory(false); |
182 |
factory.persistenceDefinition.addDynFieldObject("associatedLayer")
|
183 |
.setClassOfValue(FLyrVect.class).setMandatory(false);
|
184 |
factory.persistenceDefinition.addDynFieldObject("query")
|
185 |
.setClassOfValue(FeatureQuery.class).setMandatory(false);
|
186 |
factory.persistenceDefinition.addDynFieldObject("baseFilter")
|
187 |
.setClassOfValue(Evaluator.class).setMandatory(false);
|
188 |
factory.persistenceDefinition.addDynFieldObject("baseOrder")
|
189 |
.setClassOfValue(FeatureQueryOrder.class).setMandatory(false);
|
190 |
factory.persistenceDefinition.addDynFieldList("linkTable")
|
191 |
.setClassOfItems(TableLink.class).setMandatory(false);
|
192 |
} |
193 |
|
194 |
|
195 |
//Register also the TableLink
|
196 |
if (manager.getDefinition(PERSISTENCE_TABLELINK_DEFINITION_NAME) == null){ |
197 |
DynStruct tableLinkDefinition = |
198 |
manager.addDefinition(TableLink.class, |
199 |
PERSISTENCE_TABLELINK_DEFINITION_NAME, |
200 |
"TableLink Persistence definition", null, null); |
201 |
|
202 |
tableLinkDefinition.addDynFieldObject("source")
|
203 |
.setClassOfValue(TableDocument.class).setMandatory(true);
|
204 |
tableLinkDefinition.addDynFieldObject("target")
|
205 |
.setClassOfValue(TableDocument.class).setMandatory(true);
|
206 |
tableLinkDefinition.addDynFieldString("fieldSource").setMandatory(true); |
207 |
tableLinkDefinition.addDynFieldString("fieldTarget").setMandatory(true); |
208 |
tableLinkDefinition.addDynFieldBoolean("enabled").setMandatory(true); |
209 |
} |
210 |
|
211 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Create a new table document.
|
216 |
*
|
217 |
* @return TableDocument.
|
218 |
*/
|
219 |
public AbstractDocument createDocument() { |
220 |
return new TableDocument(this); |
221 |
} |
222 |
|
223 |
public Class<? extends IDocumentWindow> getMainWindowClass() { |
224 |
return FeatureTableDocumentPanel.class;
|
225 |
} |
226 |
|
227 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
228 |
IDocumentWindow tablePanel; |
229 |
tablePanel = |
230 |
(IDocumentWindow) PluginServices.getMDIManager() |
231 |
.getSingletonWindow(getMainWindowClass(), doc); |
232 |
if (tablePanel != null) { |
233 |
// The table window document is already created, return it.
|
234 |
return tablePanel;
|
235 |
} |
236 |
|
237 |
tablePanel = (IDocumentWindow) this.createDocumentWindow(doc);
|
238 |
if (layout != null && tablePanel != null) { |
239 |
tablePanel.setWindowLayout(layout); |
240 |
} |
241 |
return tablePanel;
|
242 |
} |
243 |
|
244 |
public IWindow getPropertiesWindow(Document doc) { |
245 |
|
246 |
// IWindow mainwin =
|
247 |
// PluginServices.getMDIManager().getSingletonWindow(FeatureTableDocumentPanel.class,
|
248 |
// doc);
|
249 |
return new TableProperties((TableDocument) doc); |
250 |
} |
251 |
|
252 |
protected Class<? extends Document> getDocumentClass() { |
253 |
return TableDocument.class;
|
254 |
} |
255 |
|
256 |
public DynStruct getDefinition(String className) { |
257 |
|
258 |
if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
259 |
return this.persistenceDefinition; |
260 |
} |
261 |
if (this.persistenceDefinition.getFullName() |
262 |
.equalsIgnoreCase(className)) { |
263 |
return this.persistenceDefinition; |
264 |
} |
265 |
if (this.getDocumentClass().getName().equals(className)) { |
266 |
return this.persistenceDefinition; |
267 |
} |
268 |
return null; |
269 |
} |
270 |
|
271 |
public boolean manages(Object object) { |
272 |
return object instanceof TableDocument; |
273 |
} |
274 |
|
275 |
public TableDocument getTableDocument(VectorLayer layer) {
|
276 |
if (layer == null) { |
277 |
return null; |
278 |
} |
279 |
List<Document> tableDocs = |
280 |
getProject().getDocuments(TableManager.TYPENAME); |
281 |
for (Document document : tableDocs) { |
282 |
if (layer == ((TableDocument) document).getAssociatedLayer()) {
|
283 |
return (TableDocument) document;
|
284 |
} |
285 |
} |
286 |
return null; |
287 |
} |
288 |
|
289 |
public void removeTableDocument(VectorLayer layer) { |
290 |
TableDocument doc = getTableDocument(layer); |
291 |
// Only remove it if it exists
|
292 |
if (doc != null) { |
293 |
PluginServices.getMDIManager().closeSingletonWindow(doc); |
294 |
getProject().remove(doc); |
295 |
} |
296 |
} |
297 |
|
298 |
private Project getProject() {
|
299 |
return ProjectManager.getInstance().getCurrentProject();
|
300 |
} |
301 |
} |