svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / LayerPropertiesExtension.java @ 47388
History | View | Annotate | Download (5.74 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 41248 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40435 | jjdelcerro | *
|
11 | 41248 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40435 | jjdelcerro | *
|
16 | 41248 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40435 | jjdelcerro | *
|
20 | 41248 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | 46573 | jjdelcerro | import javax.swing.JOptionPane; |
26 | 42506 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
27 | 40435 | jjdelcerro | import org.gvsig.andami.plugins.Extension; |
28 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
29 | import org.gvsig.app.ApplicationManager; |
||
30 | 42506 | jjdelcerro | import org.gvsig.app.project.ProjectManager; |
31 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
32 | 42506 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewManager; |
33 | 41264 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
34 | 42175 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.LayerProperties; |
35 | 42506 | jjdelcerro | import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
36 | 46412 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
37 | 42175 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 | 46412 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
39 | 42175 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
40 | 45812 | jjdelcerro | import org.gvsig.tools.i18n.I18nManager; |
41 | 42175 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
42 | 46573 | jjdelcerro | import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
43 | 42175 | jjdelcerro | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
44 | 40435 | jjdelcerro | |
45 | 42175 | jjdelcerro | public class LayerPropertiesExtension extends Extension { |
46 | 41248 | jjdelcerro | |
47 | 43147 | jjdelcerro | @Override
|
48 | 40435 | jjdelcerro | public void initialize() { |
49 | } |
||
50 | |||
51 | 42506 | jjdelcerro | @Override
|
52 | public void postInitialize() { |
||
53 | FPopupMenu.registerExtensionPoint(); |
||
54 | IconThemeHelper.registerIcon("action", "layer-properties", this); |
||
55 | ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
||
56 | ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
||
57 | viewManager.addTOCContextAction("layer-properties","group-last",10000,900); |
||
58 | } |
||
59 | |||
60 | 43147 | jjdelcerro | @Override
|
61 | 40435 | jjdelcerro | public void execute(String s) { |
62 | 42175 | jjdelcerro | |
63 | 41248 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
64 | 40435 | jjdelcerro | |
65 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
66 | if (view == null) { |
||
67 | 41248 | jjdelcerro | return;
|
68 | 40435 | jjdelcerro | } |
69 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
70 | 43147 | jjdelcerro | if (!document.getMapContext().hasActiveLayers()) {
|
71 | 42175 | jjdelcerro | return;
|
72 | } |
||
73 | 41264 | jjdelcerro | |
74 | 42175 | jjdelcerro | if (s.equalsIgnoreCase("layer-properties")) { |
75 | 45812 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
76 | 46573 | jjdelcerro | FLayer[] activeLayers = document.getMapContext().getLayers().getActives();
|
77 | FLayer layer = activeLayers[0];
|
||
78 | |||
79 | if( activeLayers.length>1 ) { |
||
80 | ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
||
81 | int n = dialogs.confirmDialog(
|
||
82 | i18n.getTranslation("_There_is_more_than_one_active_layer") +
|
||
83 | "\n" +
|
||
84 | i18n.getTranslation( |
||
85 | "_If_you_continue_the_properties_of_layer_0_will_be_displayed",
|
||
86 | new String[] { layer.getName() } |
||
87 | ) + |
||
88 | "\n" +
|
||
89 | i18n.getTranslation("_Do_you_wish_to_continue"),
|
||
90 | i18n.getTranslation("_Show_properties"),
|
||
91 | JOptionPane.YES_NO_OPTION,
|
||
92 | JOptionPane.QUESTION_MESSAGE,
|
||
93 | "_If_you_continue_the_properties_of_layer_0_will_be_displayed"
|
||
94 | ); |
||
95 | if( n != JOptionPane.YES_OPTION ) { |
||
96 | return;
|
||
97 | } |
||
98 | } |
||
99 | 46412 | jjdelcerro | String title = null; |
100 | if( layer instanceof SingleLayer ) { |
||
101 | DataStore store = ((SingleLayer) layer).getDataStore(); |
||
102 | if( store != null ) { |
||
103 | 47388 | fdiaz | title = application.makeTitle(i18n.getTranslation("propiedades_de_la_capa"), layer.getName(), store.getName());
|
104 | 46412 | jjdelcerro | } |
105 | } |
||
106 | if( title == null ) { |
||
107 | 47388 | fdiaz | title = application.makeTitle(i18n.getTranslation("propiedades_de_la_capa"), layer.getName(), null); |
108 | 46412 | jjdelcerro | } |
109 | 42175 | jjdelcerro | LayerProperties dlg = new LayerProperties(layer);
|
110 | WindowManager wm = ToolsSwingLocator.getWindowManager(); |
||
111 | wm.showWindow( |
||
112 | dlg.asJComponent(), |
||
113 | 46412 | jjdelcerro | title, |
114 | 42175 | jjdelcerro | WindowManager.MODE.WINDOW |
115 | ); |
||
116 | 41248 | jjdelcerro | } |
117 | 40435 | jjdelcerro | } |
118 | |||
119 | 43147 | jjdelcerro | @Override
|
120 | 41248 | jjdelcerro | public boolean isEnabled() { |
121 | 42175 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
122 | |||
123 | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
||
124 | if (view == null) { |
||
125 | return false; |
||
126 | } |
||
127 | ViewDocument document = view.getViewDocument(); |
||
128 | 43147 | jjdelcerro | return document.getMapContext().hasActiveLayers();
|
129 | 40435 | jjdelcerro | } |
130 | |||
131 | 43147 | jjdelcerro | @Override
|
132 | 40435 | jjdelcerro | public boolean isVisible() { |
133 | 41248 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
134 | |||
135 | 42175 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
136 | if (view == null) { |
||
137 | return false; |
||
138 | } |
||
139 | ViewDocument document = view.getViewDocument(); |
||
140 | 43147 | jjdelcerro | return document.getMapContext().hasLayers();
|
141 | 40435 | jjdelcerro | } |
142 | |||
143 | } |