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 @ 41081
History | View | Annotate | Download (10.9 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.fmap.mapcontext.MapContext; |
48 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
49 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
50 |
import org.gvsig.tools.ToolsLocator; |
51 |
import org.gvsig.tools.dynobject.DynStruct; |
52 |
import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
53 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
54 |
import org.gvsig.tools.persistence.PersistenceManager; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
/**
|
59 |
* Factory of View.
|
60 |
*
|
61 |
* @author 2005- Vicente Caballero
|
62 |
* @author 2009- Joaquin del Cerro
|
63 |
*
|
64 |
*/
|
65 |
public class ViewManager extends AbstractDocumentManager { |
66 |
private static final Logger logger = LoggerFactory.getLogger(ViewManager.class); |
67 |
|
68 |
private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME = |
69 |
"DefaultViewDocument";
|
70 |
public static String TYPENAME = "project.document.view2d"; |
71 |
private DynStruct persistenceDefinition;
|
72 |
|
73 |
public ViewManager() {
|
74 |
// Do nothing
|
75 |
} |
76 |
|
77 |
public int getPriority() { |
78 |
return 0; |
79 |
} |
80 |
|
81 |
public ImageIcon getIcon() { |
82 |
return PluginServices.getIconTheme().get("document-view-icon"); |
83 |
} |
84 |
|
85 |
public ImageIcon getIconSelected() { |
86 |
return PluginServices.getIconTheme().get("document-view-icon-sel"); |
87 |
} |
88 |
|
89 |
public String getTitle() { |
90 |
return PluginServices.getText(this, "Vista"); |
91 |
} |
92 |
|
93 |
public String getTypeName() { |
94 |
return TYPENAME;
|
95 |
} |
96 |
|
97 |
public Class getMainWindowClass() { |
98 |
return DefaultViewPanel.class;
|
99 |
} |
100 |
|
101 |
public AbstractDocument createDocument() { |
102 |
return new DefaultViewDocument(this); |
103 |
} |
104 |
|
105 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
106 |
IDocumentWindow view; |
107 |
|
108 |
view = (IDocumentWindow) PluginServices.getMDIManager().getSingletonWindow(getMainWindowClass(), doc); |
109 |
if( view != null ) { |
110 |
// The view window document is already created, return it.
|
111 |
return view;
|
112 |
} |
113 |
view = this.createDocumentWindow(doc);
|
114 |
if ( layout != null && view != null ) { |
115 |
view.setWindowLayout(layout); |
116 |
} |
117 |
((AbstractDocument) doc).raiseEventCreateWindow(view);
|
118 |
return view;
|
119 |
} |
120 |
|
121 |
public IWindow getPropertiesWindow(Document doc) { |
122 |
return new ViewProperties((DefaultViewDocument) doc); |
123 |
} |
124 |
|
125 |
public void addTOCContextAction(String theAction) { |
126 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
127 |
ActionInfo action = actionManager.getAction(theAction); |
128 |
if( action==null ) { |
129 |
String errmsg = "Action '"+theAction+"' not found"; |
130 |
logger.info(errmsg); |
131 |
throw new RuntimeException(errmsg); |
132 |
} |
133 |
this.addTOCContextAction(action);
|
134 |
} |
135 |
|
136 |
public void addTOCContextAction(ActionInfo action) { |
137 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action)); |
138 |
} |
139 |
|
140 |
class ActionInfoAdapterToContextMenuAction implements IContextMenuAction { |
141 |
ActionInfo action = null;
|
142 |
ActionInfoAdapterToContextMenuAction(ActionInfo action) { |
143 |
this.action = action;
|
144 |
} |
145 |
public boolean isVisible(Object item, Object[] selectedItems) { |
146 |
return this.action.isVisible(); |
147 |
} |
148 |
public boolean isEnabled(Object item, Object[] selectedItems) { |
149 |
return this.action.isEnabled(); |
150 |
} |
151 |
public void execute(Object item, Object[] selectedItems) { |
152 |
this.action.execute(selectedItems);
|
153 |
} |
154 |
public String getGroup() { |
155 |
return null; |
156 |
} |
157 |
public int getGroupOrder() { |
158 |
return 0; |
159 |
} |
160 |
public int getOrder() { |
161 |
return (int) this.action.getPosition(); |
162 |
} |
163 |
public String getText() { |
164 |
return this.action.getLabel(); |
165 |
} |
166 |
public String getDescription() { |
167 |
return this.action.getTooltip(); |
168 |
} |
169 |
} |
170 |
|
171 |
public void addTOCContextAction(String id, IContextMenuAction action) { |
172 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add( |
173 |
"View_TocActions", ""); |
174 |
if( action instanceof ExtensionBuilder ) { |
175 |
exPoint.append(id, "", (ExtensionBuilder)action);
|
176 |
return;
|
177 |
} |
178 |
exPoint.append(id, "", new ContextMenuActionAdapterToExtensionBuilder(action)); |
179 |
} |
180 |
|
181 |
class ContextMenuActionAdapterToExtensionBuilder implements ExtensionBuilder { |
182 |
IContextMenuAction menuAction = null;
|
183 |
ContextMenuActionAdapterToExtensionBuilder(IContextMenuAction menuAction) { |
184 |
this.menuAction = menuAction;
|
185 |
} |
186 |
public Object create() { |
187 |
return this.menuAction; |
188 |
} |
189 |
public Object create(Object[] args) { |
190 |
return this.menuAction; |
191 |
} |
192 |
public Object create(Map args) { |
193 |
return this.menuAction; |
194 |
} |
195 |
} |
196 |
|
197 |
/**
|
198 |
* Registers in the points of extension the Factory with alias.
|
199 |
*
|
200 |
*/
|
201 |
public static void register() { |
202 |
ViewManager factory = new ViewManager();
|
203 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
204 |
|
205 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
206 |
manager.registerFactory(factory); |
207 |
|
208 |
|
209 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
210 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
211 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
212 |
|
213 |
IconThemeHelper.registerIcon("document", "document-view-icon", ViewManager.class); |
214 |
IconThemeHelper.registerIcon("document", "document-view-icon-sel", ViewManager.class); |
215 |
|
216 |
IconThemeHelper.registerIcon("cursor", "cursor-crux", ViewManager.class); |
217 |
IconThemeHelper.registerIcon("cursor", "cursor-info-by-point", ViewManager.class); |
218 |
IconThemeHelper.registerIcon("cursor", "cursor-pan", ViewManager.class); |
219 |
IconThemeHelper.registerIcon("cursor", "cursor-query-area", ViewManager.class); |
220 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", ViewManager.class); |
221 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
222 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
223 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
224 |
|
225 |
IconThemeHelper.registerIcon("layer", "layer-icon", ViewManager.class); |
226 |
IconThemeHelper.registerIcon("layer", "layer-icon-group", ViewManager.class); |
227 |
IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", ViewManager.class); |
228 |
IconThemeHelper.registerIcon("layer", "layer-icon-dgn", ViewManager.class); |
229 |
IconThemeHelper.registerIcon("layer", "layer-icon-dxf", ViewManager.class); |
230 |
IconThemeHelper.registerIcon("layer", "layer-icon-postgresql", ViewManager.class); |
231 |
IconThemeHelper.registerIcon("layer", "layer-icon-mysql", ViewManager.class); |
232 |
IconThemeHelper.registerIcon("layer", "layer-icon-jdbc", ViewManager.class); |
233 |
IconThemeHelper.registerIcon("layer", "layer-icon-unavailable", ViewManager.class); |
234 |
|
235 |
IconThemeHelper.registerIcon("legend", "legend-overview-single-symbol", ViewManager.class); |
236 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-interval", ViewManager.class); |
237 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-unique-value", ViewManager.class); |
238 |
|
239 |
MapContextManager mapContextMgr = MapContextLocator.getMapContextManager(); |
240 |
mapContextMgr.registerIconLayer("DGN", "layer-icon-dgn"); |
241 |
mapContextMgr.registerIconLayer("DXF", "layer-icon-dxf"); |
242 |
mapContextMgr.registerIconLayer("jdbc", "layer-icon-jdbc"); |
243 |
mapContextMgr.registerIconLayer("PostgreSQL", "layer-icon-postgresql"); |
244 |
mapContextMgr.registerIconLayer("MySQL", "layer-icon-mysql"); |
245 |
|
246 |
if (factory.persistenceDefinition == null){ |
247 |
factory.persistenceDefinition = manager.addDefinition( |
248 |
ViewDocument.class, |
249 |
PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
250 |
"Default view document persistence definition",
|
251 |
null,
|
252 |
null
|
253 |
); |
254 |
factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
255 |
|
256 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
257 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
258 |
factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
259 |
|
260 |
} |
261 |
|
262 |
|
263 |
} |
264 |
|
265 |
@SuppressWarnings("rawtypes") |
266 |
public DynStruct getDefinition(String className) { |
267 |
|
268 |
if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
269 |
return this.persistenceDefinition; |
270 |
} |
271 |
if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
272 |
return this.persistenceDefinition; |
273 |
} |
274 |
if( this.getDocumentClass().getName().equals(className) ) { |
275 |
return this.persistenceDefinition; |
276 |
} |
277 |
|
278 |
return null; |
279 |
} |
280 |
|
281 |
@SuppressWarnings("rawtypes") |
282 |
protected Class getDocumentClass() { |
283 |
return DefaultViewDocument.class;
|
284 |
} |
285 |
|
286 |
public boolean manages(Object object) { |
287 |
return object instanceof ViewDocument; |
288 |
} |
289 |
} |