svn-gvsig-desktop / tags / v2_0_0_Build_2040 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / metadata / gui / MetadataInfoManager.java @ 37235
History | View | Annotate | Download (4.06 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.gui.beans.swing.JBlank; |
34 |
import org.gvsig.metadata.swing.basic.api.JMetadataPanel; |
35 |
import org.gvsig.metadata.swing.basic.api.MetadataSwingLocator; |
36 |
import org.gvsig.metadata.swing.basic.api.MetadataSwingManager; |
37 |
import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
38 |
|
39 |
public class MetadataInfoManager extends AbstractThemeManagerPage { |
40 |
|
41 |
/**
|
42 |
*
|
43 |
*/
|
44 |
private static final long serialVersionUID = 7432962479048597376L; |
45 |
private JMetadataPanel metadataPanel;
|
46 |
|
47 |
/**
|
48 |
* This is the default constructor.
|
49 |
*/
|
50 |
public MetadataInfoManager() {
|
51 |
super();
|
52 |
initialize(); |
53 |
} |
54 |
|
55 |
private void initialize() { |
56 |
this.setLayout(new BorderLayout()); |
57 |
this.add(new JBlank(5, 10), BorderLayout.WEST); |
58 |
this.add(new JBlank(5, 10), BorderLayout.EAST); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Sets the necessary properties in the panel. This properties are extracted
|
63 |
* from the layer. With this properties fills the TextFields, ComboBoxes and
|
64 |
* the rest of GUI components.
|
65 |
*
|
66 |
* @param FLayer
|
67 |
* layer,
|
68 |
*/
|
69 |
public void setModel(FLayer layer) { |
70 |
try {
|
71 |
MetadataSwingManager manager = MetadataSwingLocator |
72 |
.getMetadataSwingManager(); |
73 |
this.metadataPanel = manager.createJMetadataPanel(layer);
|
74 |
this.add(metadataPanel, BorderLayout.CENTER); |
75 |
|
76 |
} catch (Exception e) { |
77 |
NotificationManager.addError("Can't assign model", e);
|
78 |
} |
79 |
} |
80 |
|
81 |
public void acceptAction() { |
82 |
if (metadataPanel == null) { |
83 |
return;
|
84 |
} |
85 |
saveMetadata(); |
86 |
} |
87 |
|
88 |
private void saveMetadata() { |
89 |
try {
|
90 |
this.metadataPanel.saveMetadata();
|
91 |
} catch (DynObjectValidateException e) {
|
92 |
JOptionPane.showMessageDialog(null, getInfoString(e), |
93 |
"Metadata Validation Errors",
|
94 |
JOptionPane.WARNING_MESSAGE);
|
95 |
} |
96 |
} |
97 |
|
98 |
private String getInfoString(DynObjectValidateException e) { |
99 |
StringBuffer buffer = new StringBuffer(); |
100 |
|
101 |
buffer.append("<html>");
|
102 |
buffer.append("<body>");
|
103 |
buffer.append("<h2>Metadata values could not be stored due to the following errors:'")
|
104 |
.append(this.metadataPanel.getMetadata().getDynClass()
|
105 |
.getName()).append("'</h2>");
|
106 |
buffer.append("<p>");
|
107 |
buffer.append("<br>");
|
108 |
buffer.append("<ol>");
|
109 |
buffer.append(" " + e.getLocalizedMessageStack());
|
110 |
buffer.append("</ol>");
|
111 |
buffer.append("</p>");
|
112 |
buffer.append("</body>");
|
113 |
buffer.append("</html>");
|
114 |
|
115 |
return buffer.toString().replace("\n", "<br/>"); |
116 |
} |
117 |
|
118 |
public void cancelAction() { |
119 |
// does nothing
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* When we press the apply button, sets the new properties of the layer that
|
124 |
* the user modified using the UI components
|
125 |
*/
|
126 |
public void applyAction() { |
127 |
if (metadataPanel == null) { |
128 |
return;
|
129 |
} |
130 |
saveMetadata(); |
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
*
|
136 |
* @see java.awt.Component#getName()
|
137 |
*/
|
138 |
public String getName() { |
139 |
return PluginServices.getText(this, "_Metadata"); |
140 |
} |
141 |
|
142 |
} |