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 / ViewManager.java @ 43215
History | View | Annotate | Download (13.1 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 |
package org.gvsig.app.project.documents.view; |
25 |
|
26 |
import java.util.Map; |
27 |
|
28 |
import javax.swing.ImageIcon; |
29 |
|
30 |
import org.gvsig.andami.IconThemeHelper; |
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.PluginsLocator; |
33 |
import org.gvsig.andami.actioninfo.ActionInfo; |
34 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
36 |
import org.gvsig.app.project.ProjectManager; |
37 |
import org.gvsig.app.project.documents.AbstractDocument; |
38 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
39 |
import org.gvsig.app.project.documents.Document; |
40 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
41 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
42 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
43 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
44 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
45 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
46 |
import org.gvsig.app.project.documents.view.gui.ViewProperties; |
47 |
import org.gvsig.app.project.documents.view.toc.AbstractActionInfoAdapterToTocContextMenuAction; |
48 |
import org.gvsig.fmap.mapcontext.MapContext; |
49 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
50 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
51 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesHelper; |
52 |
import org.gvsig.tools.ToolsLocator; |
53 |
import org.gvsig.tools.dynobject.DynStruct; |
54 |
import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
55 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
56 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
57 |
import org.gvsig.tools.persistence.PersistenceManager; |
58 |
import org.slf4j.Logger; |
59 |
import org.slf4j.LoggerFactory; |
60 |
|
61 |
/**
|
62 |
* Factory of View.
|
63 |
*
|
64 |
* @author 2005- Vicente Caballero
|
65 |
* @author 2009- Joaquin del Cerro
|
66 |
*
|
67 |
*/
|
68 |
public class ViewManager extends AbstractDocumentManager { |
69 |
private static final Logger logger = LoggerFactory.getLogger(ViewManager.class); |
70 |
|
71 |
private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME = |
72 |
"DefaultViewDocument";
|
73 |
public static String TYPENAME = "project.document.view2d"; |
74 |
private DynStruct persistenceDefinition;
|
75 |
|
76 |
public ViewManager() {
|
77 |
// Do nothing
|
78 |
} |
79 |
|
80 |
public int getPriority() { |
81 |
return 0; |
82 |
} |
83 |
|
84 |
public ImageIcon getIcon() { |
85 |
return PluginServices.getIconTheme().get("document-view-icon"); |
86 |
} |
87 |
|
88 |
public ImageIcon getIconSelected() { |
89 |
return PluginServices.getIconTheme().get("document-view-icon-sel"); |
90 |
} |
91 |
|
92 |
public String getTitle() { |
93 |
return PluginServices.getText(this, "Vista"); |
94 |
} |
95 |
|
96 |
public String getTypeName() { |
97 |
return TYPENAME;
|
98 |
} |
99 |
|
100 |
public Class getMainWindowClass() { |
101 |
return DefaultViewPanel.class;
|
102 |
} |
103 |
|
104 |
public AbstractDocument createDocument() { |
105 |
AbstractDocument doc = new DefaultViewDocument(this); |
106 |
if( this.notifyObservers(NOTIFY_AFTER_CREATEDOCUMENT,doc).isCanceled() ) { |
107 |
return null; |
108 |
} |
109 |
return doc;
|
110 |
|
111 |
} |
112 |
|
113 |
@Override
|
114 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
115 |
IDocumentWindow win = (IDocumentWindow) super.getMainWindow(doc, layout);
|
116 |
if ( win == null ) { |
117 |
win = this.createDocumentWindow(doc);
|
118 |
if ( layout != null && win != null ) { |
119 |
win.setWindowLayout(layout); |
120 |
} |
121 |
} |
122 |
if( this.notifyObservers(NOTIFY_AFTER_GETMAINWINDOW,win).isCanceled() ) { |
123 |
return null; |
124 |
} |
125 |
((AbstractDocument) doc).raiseEventCreateWindow(win);
|
126 |
return win;
|
127 |
} |
128 |
|
129 |
@Override
|
130 |
public IWindow getPropertiesWindow(Document doc) { |
131 |
IWindow win = super.getPropertiesWindow(doc);
|
132 |
if( win == null ) { |
133 |
win = new ViewProperties((DefaultViewDocument) doc);
|
134 |
} |
135 |
if( this.notifyObservers(NOTIFY_AFTER_GETPROPERTIESWINDOW,win).isCanceled() ) { |
136 |
return null; |
137 |
} |
138 |
return win;
|
139 |
} |
140 |
|
141 |
public void addTOCContextAction(String theAction) { |
142 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
143 |
ActionInfo action = actionManager.getAction(theAction); |
144 |
if( action==null ) { |
145 |
String errmsg = "Action '"+theAction+"' not found"; |
146 |
logger.info(errmsg); |
147 |
throw new RuntimeException(errmsg); |
148 |
} |
149 |
this.addTOCContextAction(action);
|
150 |
} |
151 |
|
152 |
public void addTOCContextAction(String theAction, String group, int groupOrder, int order) { |
153 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
154 |
ActionInfo action = actionManager.getAction(theAction); |
155 |
if( action==null ) { |
156 |
String errmsg = "Action '"+theAction+"' not found"; |
157 |
logger.info(errmsg); |
158 |
throw new RuntimeException(errmsg); |
159 |
} |
160 |
this.addTOCContextAction(
|
161 |
action.getName(), |
162 |
new ActionInfoAdapterToContextMenuAction(action, group, groupOrder,0) |
163 |
); |
164 |
} |
165 |
|
166 |
public void addTOCContextAction(ActionInfo action) { |
167 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, "default", 9000)); |
168 |
} |
169 |
|
170 |
public void addTOCContextAction(ActionInfo action, String group, int groupOrder) { |
171 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, group, groupOrder)); |
172 |
} |
173 |
|
174 |
class ActionInfoAdapterToContextMenuAction extends AbstractActionInfoAdapterToTocContextMenuAction { |
175 |
|
176 |
ActionInfoAdapterToContextMenuAction(ActionInfo action, String group, int groupOrder) { |
177 |
super(action, group, groupOrder);
|
178 |
} |
179 |
ActionInfoAdapterToContextMenuAction(ActionInfo action, String group, int groupOrder, int order) { |
180 |
super(action, group, groupOrder,order);
|
181 |
} |
182 |
} |
183 |
|
184 |
/**
|
185 |
* @deprecated use addTOCContextAction(ActionInfo action, String group, int groupOrder)
|
186 |
* @param id
|
187 |
* @param action
|
188 |
*/
|
189 |
public void addTOCContextAction(String id, IContextMenuAction action) { |
190 |
initializeRegisterTOCActions(); |
191 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add( |
192 |
"View_TocActions", ""); |
193 |
if( action instanceof ExtensionBuilder ) { |
194 |
exPoint.append(id, "", (ExtensionBuilder)action);
|
195 |
return;
|
196 |
} |
197 |
exPoint.append(id, "", new ContextMenuActionAdapterToExtensionBuilder(action)); |
198 |
} |
199 |
|
200 |
class ContextMenuActionAdapterToExtensionBuilder implements ExtensionBuilder { |
201 |
IContextMenuAction menuAction = null;
|
202 |
ContextMenuActionAdapterToExtensionBuilder(IContextMenuAction menuAction) { |
203 |
this.menuAction = menuAction;
|
204 |
} |
205 |
public Object create() { |
206 |
return this.menuAction; |
207 |
} |
208 |
public Object create(Object[] args) { |
209 |
return this.menuAction; |
210 |
} |
211 |
public Object create(Map args) { |
212 |
return this.menuAction; |
213 |
} |
214 |
} |
215 |
|
216 |
private static void initializeRegisterTOCActions() { |
217 |
ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
218 |
|
219 |
if (!epManager.has("View_TocActions")) { |
220 |
epManager.add( |
221 |
"View_TocActions",
|
222 |
"Context menu options of the TOC " +
|
223 |
" in the view window "+
|
224 |
"(register instances of " +
|
225 |
"org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
226 |
); |
227 |
} |
228 |
} |
229 |
|
230 |
/**
|
231 |
* Registers in the points of extension the Factory with alias.
|
232 |
*
|
233 |
*/
|
234 |
public static void register() { |
235 |
ViewManager factory = new ViewManager();
|
236 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
237 |
|
238 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
239 |
manager.registerFactory(factory); |
240 |
|
241 |
initializeRegisterTOCActions(); |
242 |
|
243 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
244 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
245 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
246 |
|
247 |
IconThemeHelper.registerIcon("document", "document-view-icon", ViewManager.class); |
248 |
IconThemeHelper.registerIcon("document", "document-view-icon-sel", ViewManager.class); |
249 |
|
250 |
IconThemeHelper.registerIcon("cursor", "cursor-crux", ViewManager.class); |
251 |
IconThemeHelper.registerIcon("cursor", "cursor-info-by-point", ViewManager.class); |
252 |
IconThemeHelper.registerIcon("cursor", "cursor-pan", ViewManager.class); |
253 |
IconThemeHelper.registerIcon("cursor", "cursor-query-area", ViewManager.class); |
254 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", ViewManager.class); |
255 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
256 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-rectangle", ViewManager.class); |
257 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
258 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
259 |
|
260 |
IconThemeHelper.registerIcon("layer", "layer-icon", ViewManager.class); |
261 |
IconThemeHelper.registerIcon("layer", "layer-icon-group", ViewManager.class); |
262 |
IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", ViewManager.class); |
263 |
IconThemeHelper.registerIcon("layer", "layer-icon-csv", ViewManager.class); |
264 |
IconThemeHelper.registerIcon("layer", "layer-icon-dgn", ViewManager.class); |
265 |
IconThemeHelper.registerIcon("layer", "layer-icon-dxf", ViewManager.class); |
266 |
IconThemeHelper.registerIcon("layer", "layer-icon-postgresql", ViewManager.class); |
267 |
IconThemeHelper.registerIcon("layer", "layer-icon-mysql", ViewManager.class); |
268 |
IconThemeHelper.registerIcon("layer", "layer-icon-jdbc", ViewManager.class); |
269 |
//IconThemeHelper.registerIcon("layer", "layer-icon-unavailable", ViewManager.class);
|
270 |
IconThemeHelper.registerIcon("layer", "layer-chk-unavailable", ViewManager.class); |
271 |
IconThemeHelper.registerIcon("layer", "layer-chk-temporary", ViewManager.class); |
272 |
|
273 |
IconThemeHelper.registerIcon("legend", "legend-overview-single-symbol", ViewManager.class); |
274 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-interval", ViewManager.class); |
275 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-unique-value", ViewManager.class); |
276 |
|
277 |
MapContextManager mapContextMgr = MapContextLocator.getMapContextManager(); |
278 |
mapContextMgr.registerIconLayer("CSV", "layer-icon-csv"); |
279 |
mapContextMgr.registerIconLayer("DGN", "layer-icon-dgn"); |
280 |
mapContextMgr.registerIconLayer("DXF", "layer-icon-dxf"); |
281 |
mapContextMgr.registerIconLayer("jdbc", "layer-icon-jdbc"); |
282 |
mapContextMgr.registerIconLayer("PostgreSQL", "layer-icon-postgresql"); |
283 |
mapContextMgr.registerIconLayer("MySQL", "layer-icon-mysql"); |
284 |
|
285 |
if (factory.persistenceDefinition == null){ |
286 |
factory.persistenceDefinition = manager.addDefinition( |
287 |
ViewDocument.class, |
288 |
PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
289 |
"Default view document persistence definition",
|
290 |
null,
|
291 |
null
|
292 |
); |
293 |
factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
294 |
|
295 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
296 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
297 |
factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
298 |
factory.persistenceDefinition.addDynFieldObject("propertiesHelper").setClassOfValue(ExtendedPropertiesHelper.class)
|
299 |
.setMandatory(false);
|
300 |
|
301 |
} |
302 |
|
303 |
|
304 |
} |
305 |
|
306 |
@SuppressWarnings("rawtypes") |
307 |
public DynStruct getDefinition(String className) { |
308 |
|
309 |
if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
310 |
return this.persistenceDefinition; |
311 |
} |
312 |
if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
313 |
return this.persistenceDefinition; |
314 |
} |
315 |
if( this.getDocumentClass().getName().equals(className) ) { |
316 |
return this.persistenceDefinition; |
317 |
} |
318 |
|
319 |
return null; |
320 |
} |
321 |
|
322 |
@SuppressWarnings("rawtypes") |
323 |
protected Class getDocumentClass() { |
324 |
return DefaultViewDocument.class;
|
325 |
} |
326 |
|
327 |
public boolean manages(Object object) { |
328 |
return object instanceof ViewDocument; |
329 |
} |
330 |
} |