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 @ 41559
History | View | Annotate | Download (11.6 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 |
return new DefaultViewDocument(this); |
106 |
} |
107 |
|
108 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
109 |
IDocumentWindow view; |
110 |
|
111 |
view = (IDocumentWindow) PluginServices.getMDIManager().getSingletonWindow(getMainWindowClass(), doc); |
112 |
if( view != null ) { |
113 |
// The view window document is already created, return it.
|
114 |
return view;
|
115 |
} |
116 |
view = this.createDocumentWindow(doc);
|
117 |
if ( layout != null && view != null ) { |
118 |
view.setWindowLayout(layout); |
119 |
} |
120 |
((AbstractDocument) doc).raiseEventCreateWindow(view);
|
121 |
return view;
|
122 |
} |
123 |
|
124 |
public IWindow getPropertiesWindow(Document doc) { |
125 |
return new ViewProperties((DefaultViewDocument) doc); |
126 |
} |
127 |
|
128 |
public void addTOCContextAction(String theAction) { |
129 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
130 |
ActionInfo action = actionManager.getAction(theAction); |
131 |
if( action==null ) { |
132 |
String errmsg = "Action '"+theAction+"' not found"; |
133 |
logger.info(errmsg); |
134 |
throw new RuntimeException(errmsg); |
135 |
} |
136 |
this.addTOCContextAction(action);
|
137 |
} |
138 |
|
139 |
public void addTOCContextAction(ActionInfo action) { |
140 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, "default", 10000)); |
141 |
} |
142 |
|
143 |
public void addTOCContextAction(ActionInfo action, String group, int groupOrder) { |
144 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, group, groupOrder)); |
145 |
} |
146 |
|
147 |
class ActionInfoAdapterToContextMenuAction extends AbstractActionInfoAdapterToTocContextMenuAction { |
148 |
|
149 |
ActionInfoAdapterToContextMenuAction(ActionInfo action, String group, int groupOrder) { |
150 |
super(action, group, groupOrder);
|
151 |
} |
152 |
} |
153 |
|
154 |
/**
|
155 |
* @deprecated use addTOCContextAction(ActionInfo action, String group, int groupOrder)
|
156 |
* @param id
|
157 |
* @param action
|
158 |
*/
|
159 |
public void addTOCContextAction(String id, IContextMenuAction action) { |
160 |
initializeRegisterTOCActions(); |
161 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add( |
162 |
"View_TocActions", ""); |
163 |
if( action instanceof ExtensionBuilder ) { |
164 |
exPoint.append(id, "", (ExtensionBuilder)action);
|
165 |
return;
|
166 |
} |
167 |
exPoint.append(id, "", new ContextMenuActionAdapterToExtensionBuilder(action)); |
168 |
} |
169 |
|
170 |
class ContextMenuActionAdapterToExtensionBuilder implements ExtensionBuilder { |
171 |
IContextMenuAction menuAction = null;
|
172 |
ContextMenuActionAdapterToExtensionBuilder(IContextMenuAction menuAction) { |
173 |
this.menuAction = menuAction;
|
174 |
} |
175 |
public Object create() { |
176 |
return this.menuAction; |
177 |
} |
178 |
public Object create(Object[] args) { |
179 |
return this.menuAction; |
180 |
} |
181 |
public Object create(Map args) { |
182 |
return this.menuAction; |
183 |
} |
184 |
} |
185 |
|
186 |
private static void initializeRegisterTOCActions() { |
187 |
ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
188 |
|
189 |
if (!epManager.has("View_TocActions")) { |
190 |
epManager.add( |
191 |
"View_TocActions",
|
192 |
"Context menu options of the TOC " +
|
193 |
" in the view window "+
|
194 |
"(register instances of " +
|
195 |
"org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
196 |
); |
197 |
} |
198 |
} |
199 |
|
200 |
/**
|
201 |
* Registers in the points of extension the Factory with alias.
|
202 |
*
|
203 |
*/
|
204 |
public static void register() { |
205 |
ViewManager factory = new ViewManager();
|
206 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
207 |
|
208 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
209 |
manager.registerFactory(factory); |
210 |
|
211 |
initializeRegisterTOCActions(); |
212 |
|
213 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
214 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
215 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
216 |
|
217 |
IconThemeHelper.registerIcon("document", "document-view-icon", ViewManager.class); |
218 |
IconThemeHelper.registerIcon("document", "document-view-icon-sel", ViewManager.class); |
219 |
|
220 |
IconThemeHelper.registerIcon("cursor", "cursor-crux", ViewManager.class); |
221 |
IconThemeHelper.registerIcon("cursor", "cursor-info-by-point", ViewManager.class); |
222 |
IconThemeHelper.registerIcon("cursor", "cursor-pan", ViewManager.class); |
223 |
IconThemeHelper.registerIcon("cursor", "cursor-query-area", ViewManager.class); |
224 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", ViewManager.class); |
225 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
226 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-rectangle", ViewManager.class); |
227 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
228 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
229 |
|
230 |
IconThemeHelper.registerIcon("layer", "layer-icon", ViewManager.class); |
231 |
IconThemeHelper.registerIcon("layer", "layer-icon-group", ViewManager.class); |
232 |
IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", ViewManager.class); |
233 |
IconThemeHelper.registerIcon("layer", "layer-icon-dgn", ViewManager.class); |
234 |
IconThemeHelper.registerIcon("layer", "layer-icon-dxf", ViewManager.class); |
235 |
IconThemeHelper.registerIcon("layer", "layer-icon-postgresql", ViewManager.class); |
236 |
IconThemeHelper.registerIcon("layer", "layer-icon-mysql", ViewManager.class); |
237 |
IconThemeHelper.registerIcon("layer", "layer-icon-jdbc", ViewManager.class); |
238 |
IconThemeHelper.registerIcon("layer", "layer-icon-unavailable", ViewManager.class); |
239 |
|
240 |
IconThemeHelper.registerIcon("legend", "legend-overview-single-symbol", ViewManager.class); |
241 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-interval", ViewManager.class); |
242 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-unique-value", ViewManager.class); |
243 |
|
244 |
MapContextManager mapContextMgr = MapContextLocator.getMapContextManager(); |
245 |
mapContextMgr.registerIconLayer("DGN", "layer-icon-dgn"); |
246 |
mapContextMgr.registerIconLayer("DXF", "layer-icon-dxf"); |
247 |
mapContextMgr.registerIconLayer("jdbc", "layer-icon-jdbc"); |
248 |
mapContextMgr.registerIconLayer("PostgreSQL", "layer-icon-postgresql"); |
249 |
mapContextMgr.registerIconLayer("MySQL", "layer-icon-mysql"); |
250 |
|
251 |
if (factory.persistenceDefinition == null){ |
252 |
factory.persistenceDefinition = manager.addDefinition( |
253 |
ViewDocument.class, |
254 |
PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
255 |
"Default view document persistence definition",
|
256 |
null,
|
257 |
null
|
258 |
); |
259 |
factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
260 |
|
261 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
262 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
263 |
factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
264 |
factory.persistenceDefinition.addDynFieldObject("propertiesHelper").setClassOfValue(ExtendedPropertiesHelper.class)
|
265 |
.setMandatory(false);
|
266 |
|
267 |
} |
268 |
|
269 |
|
270 |
} |
271 |
|
272 |
@SuppressWarnings("rawtypes") |
273 |
public DynStruct getDefinition(String className) { |
274 |
|
275 |
if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
276 |
return this.persistenceDefinition; |
277 |
} |
278 |
if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
279 |
return this.persistenceDefinition; |
280 |
} |
281 |
if( this.getDocumentClass().getName().equals(className) ) { |
282 |
return this.persistenceDefinition; |
283 |
} |
284 |
|
285 |
return null; |
286 |
} |
287 |
|
288 |
@SuppressWarnings("rawtypes") |
289 |
protected Class getDocumentClass() { |
290 |
return DefaultViewDocument.class;
|
291 |
} |
292 |
|
293 |
public boolean manages(Object object) { |
294 |
return object instanceof ViewDocument; |
295 |
} |
296 |
} |