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 / project / documents / view / metadata / gui / MetadataInfoManager.java @ 40558

History | View | Annotate | Download (4.13 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.metadata.gui;
25

    
26
import java.awt.BorderLayout;
27

    
28
import javax.swing.JOptionPane;
29

    
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.messages.NotificationManager;
32
import org.gvsig.app.project.documents.view.legend.gui.AbstractThemeManagerPage;
33
import org.gvsig.fmap.mapcontext.layers.FLayer;
34
import org.gvsig.gui.beans.swing.JBlank;
35
import org.gvsig.metadata.swing.basic.api.JMetadataPanel;
36
import org.gvsig.metadata.swing.basic.api.MetadataSwingLocator;
37
import org.gvsig.metadata.swing.basic.api.MetadataSwingManager;
38
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
39

    
40
public class MetadataInfoManager extends AbstractThemeManagerPage {
41

    
42
        /**
43
         * 
44
         */
45
        private static final long serialVersionUID = 7432962479048597376L;
46
        private JMetadataPanel metadataPanel;
47

    
48
        /**
49
         * This is the default constructor.
50
         */
51
        public MetadataInfoManager() {
52
                super();
53
                initialize();
54
        }
55

    
56
        private void initialize() {
57
                this.setLayout(new BorderLayout());
58
                this.add(new JBlank(5, 10), BorderLayout.WEST);
59
                this.add(new JBlank(5, 10), BorderLayout.EAST);
60
        }
61

    
62
        /**
63
         * Sets the necessary properties in the panel. This properties are extracted
64
         * from the layer. With this properties fills the TextFields, ComboBoxes and
65
         * the rest of GUI components.
66
         * 
67
         * @param FLayer
68
         *            layer,
69
         */
70
        public void setModel(FLayer layer) {
71
                try {
72
                        MetadataSwingManager manager = MetadataSwingLocator
73
                                        .getMetadataSwingManager();
74
                        this.metadataPanel = manager.createJMetadataPanel(layer);                        
75
                        this.add(metadataPanel, BorderLayout.CENTER);
76

    
77
                } catch (Exception e) {
78
                        NotificationManager.addError("Can't assign model", e);
79
                }
80
        }
81

    
82
        public void acceptAction() {
83
                if (metadataPanel == null) {
84
                        return;
85
                }
86
                saveMetadata();
87
        }
88

    
89
        private void saveMetadata() {
90
                try {
91
                        this.metadataPanel.saveMetadata();
92
                } catch (DynObjectValidateException e) {
93
                        JOptionPane.showMessageDialog(null, getInfoString(e),
94
                                        "Metadata Validation Errors",
95
                                         JOptionPane.WARNING_MESSAGE);
96
                }
97
        }
98

    
99
        private String getInfoString(DynObjectValidateException e) {
100
                StringBuffer buffer = new StringBuffer();
101

    
102
                buffer.append("<html>");
103
                buffer.append("<body>");
104
                buffer.append("<h2>Metadata values could not be stored due to the following errors:'")
105
                                .append(this.metadataPanel.getMetadata().getDynClass()
106
                                                .getName()).append("'</h2>");
107
                buffer.append("<p>");
108
                buffer.append("<br>");
109
                buffer.append("<ol>");
110
                buffer.append("  " + e.getLocalizedMessageStack());
111
                buffer.append("</ol>");
112
                buffer.append("</p>");
113
                buffer.append("</body>");
114
                buffer.append("</html>");
115

    
116
                return buffer.toString().replace("\n", "<br/>");
117
        }
118

    
119
        public void cancelAction() {
120
                // does nothing
121
        }
122

    
123
        /**
124
         * When we press the apply button, sets the new properties of the layer that
125
         * the user modified using the UI components
126
         */
127
        public void applyAction() {
128
                if (metadataPanel == null) {
129
                        return;
130
                }
131
                saveMetadata();
132
        }
133

    
134
        /*
135
         * (non-Javadoc)
136
         * 
137
         * @see java.awt.Component#getName()
138
         */
139
        public String getName() {
140
                return PluginServices.getText(this, "_Metadata");
141
        }
142

    
143
}