Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2031 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / metadata / gui / MetadataInfoManager.java @ 36052

History | View | Annotate | Download (4.27 KB)

1
/*
2
 * Created on 31-ene-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 */
22

    
23
package org.gvsig.app.project.documents.view.metadata.gui;
24

    
25
import java.awt.BorderLayout;
26

    
27
import javax.swing.JOptionPane;
28

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

    
38
public class MetadataInfoManager extends AbstractThemeManagerPage {
39

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

    
46
        /**
47
         * This is the default constructor.
48
         */
49
        public MetadataInfoManager() {
50
                super();
51
        }
52

    
53
        /**
54
         * Sets the necessary properties in the panel. This properties are extracted
55
         * from the layer. With this properties fills the TextFields, ComboBoxes and
56
         * the rest of GUI components.
57
         * 
58
         * @param FLayer
59
         *            layer,
60
         */
61
        public void setModel(FLayer layer) {
62
                try {
63
                        MetadataSwingManager manager = MetadataSwingLocator
64
                                        .getMetadataSwingManager();
65
                        this.metadataPanel = manager.createJMetadataPanel(layer);
66

    
67
                        this.setLayout(new BorderLayout());
68
                        this.add(metadataPanel, BorderLayout.NORTH);
69
                        this.setSize(500, 360);
70

    
71
                } catch (Exception e) {
72
                        NotificationManager.addError("Can't assign model", e);
73
                }
74
        }
75

    
76
        public void acceptAction() {
77
                if (metadataPanel == null) {
78
                        return;
79
                }
80
                saveMetadata();
81
        }
82

    
83
        private void saveMetadata() {
84
                try {
85
                        this.metadataPanel.saveMetadata();
86
                } catch (DynObjectValidateException e) {
87
                        JOptionPane.showMessageDialog(null, getInfoString(e),
88
                                        "Metadata Validation Errors",
89
                                         JOptionPane.WARNING_MESSAGE);
90
                }
91
        }
92

    
93
        private String getInfoString(DynObjectValidateException e) {
94
                StringBuffer buffer = new StringBuffer();
95

    
96
                buffer.append("<html>");
97
                buffer.append("<body>");
98
                buffer.append("<h2>Metadata values could not be stored due to the following errors:'")
99
                                .append(this.metadataPanel.getMetadata().getDynClass()
100
                                                .getName()).append("'</h2>");
101
                buffer.append("<p>");
102
                buffer.append("<br>");
103
                buffer.append("<ol>");
104
                buffer.append("  " + e.getLocalizedMessageStack());
105
                buffer.append("</ol>");
106
                buffer.append("</p>");
107
                buffer.append("<br>");
108
                buffer.append("<br><p>Total errors: ")
109
                                .append(e.getStackTrace().length - 1).append("</p>");
110
                buffer.append("</body>");
111
                buffer.append("</html>");
112

    
113
                return buffer.toString().replace("\n", "<br/>");
114
        }
115

    
116
//        private void showInfoPanel(Metadata metadata) {
117
//                IWindow win = new JMetadataInfoPanel("Metadata validation info",
118
//                                JMetadataInfoPanel.MODE_WINDOW, metadata);
119
//                ApplicationLocator.getManager().getUIManager().addCentredWindow(win);
120
//        }
121

    
122
        public void cancelAction() {
123
                // does nothing
124
        }
125

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

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

    
146
}