18 |
18 |
* You should have received a copy of the GNU General Public License
|
19 |
19 |
* along with this program; if not, write to the Free Software
|
20 |
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
|
*/
|
|
21 |
*/
|
22 |
22 |
|
23 |
23 |
package org.gvsig.app.project.documents.view.metadata.gui;
|
24 |
24 |
|
25 |
25 |
import java.awt.BorderLayout;
|
26 |
26 |
|
|
27 |
import javax.swing.JOptionPane;
|
|
28 |
|
27 |
29 |
import org.gvsig.andami.PluginServices;
|
28 |
30 |
import org.gvsig.andami.messages.NotificationManager;
|
29 |
31 |
import org.gvsig.app.project.documents.view.legend.gui.AbstractThemeManagerPage;
|
... | ... | |
31 |
33 |
import org.gvsig.metadata.swing.basic.api.JMetadataPanel;
|
32 |
34 |
import org.gvsig.metadata.swing.basic.api.MetadataSwingLocator;
|
33 |
35 |
import org.gvsig.metadata.swing.basic.api.MetadataSwingManager;
|
|
36 |
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
|
34 |
37 |
|
35 |
|
|
36 |
38 |
public class MetadataInfoManager extends AbstractThemeManagerPage {
|
37 |
39 |
|
38 |
|
/**
|
|
40 |
/**
|
39 |
41 |
*
|
40 |
42 |
*/
|
41 |
43 |
private static final long serialVersionUID = 7432962479048597376L;
|
42 |
|
private JMetadataPanel metadataPanel;
|
43 |
|
|
44 |
|
/**
|
|
44 |
private JMetadataPanel metadataPanel;
|
|
45 |
|
|
46 |
/**
|
45 |
47 |
* This is the default constructor.
|
46 |
48 |
*/
|
47 |
49 |
public MetadataInfoManager() {
|
48 |
50 |
super();
|
49 |
51 |
}
|
50 |
|
|
|
52 |
|
51 |
53 |
/**
|
52 |
|
* Sets the necessary properties in the panel. This properties are
|
53 |
|
* extracted from the layer. With this properties fills the TextFields,
|
54 |
|
* ComboBoxes and the rest of GUI components.
|
55 |
|
* @param FLayer layer,
|
|
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,
|
56 |
60 |
*/
|
57 |
61 |
public void setModel(FLayer layer) {
|
58 |
62 |
try {
|
59 |
|
MetadataSwingManager manager = MetadataSwingLocator.getMetadataSwingManager();
|
60 |
|
this.metadataPanel = manager.createJMetadataPanel(layer);
|
61 |
|
|
|
63 |
MetadataSwingManager manager = MetadataSwingLocator
|
|
64 |
.getMetadataSwingManager();
|
|
65 |
this.metadataPanel = manager.createJMetadataPanel(layer);
|
|
66 |
|
62 |
67 |
this.setLayout(new BorderLayout());
|
63 |
68 |
this.add(metadataPanel, BorderLayout.NORTH);
|
64 |
69 |
this.setSize(500, 360);
|
65 |
|
|
|
70 |
|
66 |
71 |
} catch (Exception e) {
|
67 |
|
NotificationManager.addError("Can't assign model", e);
|
|
72 |
NotificationManager.addError("Can't assign model", e);
|
68 |
73 |
}
|
69 |
74 |
}
|
70 |
75 |
|
71 |
|
public void acceptAction() {
|
72 |
|
if (metadataPanel == null){
|
73 |
|
return;
|
74 |
|
}
|
75 |
|
try {
|
76 |
|
this.metadataPanel.saveMetadata();
|
77 |
|
} catch (Exception e) {
|
78 |
|
NotificationManager.addError("Can't save metadata", e);
|
79 |
|
}
|
|
76 |
public void acceptAction() {
|
|
77 |
if (metadataPanel == null) {
|
|
78 |
return;
|
|
79 |
}
|
|
80 |
saveMetadata();
|
80 |
81 |
}
|
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 |
|
82 |
122 |
public void cancelAction() {
|
83 |
123 |
// does nothing
|
84 |
124 |
}
|
85 |
125 |
|
86 |
126 |
/**
|
87 |
|
* When we press the apply button, sets the new properties of the layer that the
|
88 |
|
* user modified using the UI components
|
|
127 |
* When we press the apply button, sets the new properties of the layer that
|
|
128 |
* the user modified using the UI components
|
89 |
129 |
*/
|
90 |
130 |
public void applyAction() {
|
91 |
|
if (metadataPanel == null){
|
92 |
|
return;
|
93 |
|
}
|
94 |
|
try {
|
95 |
|
this.metadataPanel.saveMetadata();
|
96 |
|
} catch (Exception e) {
|
97 |
|
NotificationManager.addError("Can't save metadata", e);
|
98 |
|
}
|
|
131 |
if (metadataPanel == null) {
|
|
132 |
return;
|
|
133 |
}
|
|
134 |
saveMetadata();
|
99 |
135 |
}
|
100 |
|
|
|
136 |
|
101 |
137 |
/*
|
102 |
|
* (non-Javadoc)
|
|
138 |
* (non-Javadoc)
|
|
139 |
*
|
103 |
140 |
* @see java.awt.Component#getName()
|
104 |
141 |
*/
|
105 |
142 |
public String getName() {
|
106 |
|
return PluginServices.getText(this,"Metadata");
|
|
143 |
return PluginServices.getText(this, "Metadata");
|
107 |
144 |
}
|
108 |
145 |
|
109 |
146 |
}
|