Statistics
| Revision:

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
/**
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 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
 *
11
 * 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
 *
16
 * 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
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.app.extension;
24

    
25
import javax.swing.JOptionPane;
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.app.ApplicationLocator;
29
import org.gvsig.app.ApplicationManager;
30
import org.gvsig.app.project.ProjectManager;
31
import org.gvsig.app.project.documents.view.ViewDocument;
32
import org.gvsig.app.project.documents.view.ViewManager;
33
import org.gvsig.app.project.documents.view.gui.IView;
34
import org.gvsig.app.project.documents.view.gui.LayerProperties;
35
import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu;
36
import org.gvsig.fmap.dal.DataStore;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.i18n.I18nManager;
41
import org.gvsig.tools.swing.api.ToolsSwingLocator;
42
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
43
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
44

    
45
public class LayerPropertiesExtension extends Extension {
46

    
47
    @Override
48
    public void initialize() {
49
    }
50

    
51
    @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
    @Override
61
    public void execute(String s) {
62

    
63
        ApplicationManager application = ApplicationLocator.getManager();
64

    
65
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
66
        if (view == null) {
67
            return;
68
        }
69
        ViewDocument document = view.getViewDocument();
70
        if (!document.getMapContext().hasActiveLayers()) {
71
            return;
72
        }
73

    
74
        if (s.equalsIgnoreCase("layer-properties")) {
75
            I18nManager i18n = ToolsLocator.getI18nManager();
76
            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
            String title = null;
100
            if( layer instanceof SingleLayer ) {
101
                DataStore store = ((SingleLayer) layer).getDataStore();
102
                if( store != null ) {
103
                    title = application.makeTitle(i18n.getTranslation("propiedades_de_la_capa"), layer.getName(), store.getName());
104
                }
105
            }
106
            if( title == null ) {
107
                title = application.makeTitle(i18n.getTranslation("propiedades_de_la_capa"), layer.getName(), null);
108
            }
109
            LayerProperties dlg = new LayerProperties(layer);
110
            WindowManager wm = ToolsSwingLocator.getWindowManager();
111
            wm.showWindow(
112
                    dlg.asJComponent(),
113
                    title,
114
                    WindowManager.MODE.WINDOW
115
            );
116
        }
117
    }
118

    
119
    @Override
120
    public boolean isEnabled() {
121
        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
        return document.getMapContext().hasActiveLayers();
129
    }
130

    
131
    @Override
132
    public boolean isVisible() {
133
        ApplicationManager application = ApplicationLocator.getManager();
134

    
135
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
136
        if (view == null) {
137
            return false;
138
        }
139
        ViewDocument document = view.getViewDocument();
140
        return document.getMapContext().hasLayers();
141
    }
142

    
143
}