svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.metadata.basic / org.gvsig.metadata.basic.swing / org.gvsig.metadata.swing.basic.impl / src / main / java / org / gvsig / metadata / swing / basic / impl / BasicJMetadataPanel.java @ 40769
History | View | Annotate | Download (5.83 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.metadata.swing.basic.impl; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Component; |
28 |
import java.util.HashMap; |
29 |
import java.util.Map; |
30 |
|
31 |
import javax.swing.JComponent; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JPanel; |
34 |
import javax.swing.JScrollPane; |
35 |
|
36 |
import org.gvsig.metadata.Metadata; |
37 |
import org.gvsig.metadata.MetadataLocator; |
38 |
import org.gvsig.metadata.MetadataManager; |
39 |
import org.gvsig.metadata.exceptions.MetadataException; |
40 |
import org.gvsig.metadata.swing.basic.api.AbstractSimpleMetadataPanel; |
41 |
import org.gvsig.metadata.swing.basic.api.JMetadataPanel; |
42 |
import org.gvsig.metadata.swing.basic.api.MetadataSwingManager; |
43 |
import org.gvsig.tools.dynobject.DynStruct; |
44 |
import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
45 |
import org.gvsig.tools.service.ServiceException; |
46 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
47 |
|
48 |
public class BasicJMetadataPanel extends JMetadataPanel { |
49 |
|
50 |
private static final long serialVersionUID = 6514865354393558940L; |
51 |
private JLabel lblName; |
52 |
private MetadataManager manager;
|
53 |
private JDynObjectComponent component;
|
54 |
private JComponent inputComponent; |
55 |
private Map nodeList; |
56 |
private Map nodeComponentsList; |
57 |
|
58 |
public BasicJMetadataPanel(MetadataSwingManager uiManager,
|
59 |
Metadata metadata, boolean editable) {
|
60 |
super(uiManager, metadata, editable);
|
61 |
} |
62 |
|
63 |
protected void initManagers() { |
64 |
manager = MetadataLocator.getMetadataManager(); |
65 |
} |
66 |
|
67 |
protected void initData() { |
68 |
String metadataName = ""; |
69 |
if (!this.hasMetadata()) |
70 |
return;
|
71 |
|
72 |
try {
|
73 |
|
74 |
metadataName = getMetadata().getMetadataName(); |
75 |
this.lblName.setText("Metadata Layer of " + metadataName + ":"); |
76 |
|
77 |
} catch (MetadataException e) {
|
78 |
// TODO Auto-generated catch block
|
79 |
e.printStackTrace(); |
80 |
} |
81 |
} |
82 |
|
83 |
|
84 |
protected void initUI() { |
85 |
this.setLayout(new BorderLayout()); |
86 |
this.lblName = new JLabel(); |
87 |
|
88 |
this.add(this.lblName, BorderLayout.NORTH); |
89 |
} |
90 |
|
91 |
public void saveMetadata() throws DynObjectValidateException { |
92 |
try {
|
93 |
this.component.saveStatus();
|
94 |
Metadata theNewMetadata = (Metadata) this.component.getValue();
|
95 |
this.getMetadata().getDynClass().validate(theNewMetadata);
|
96 |
manager.storeMetadata(this.getMetadata());
|
97 |
} catch (MetadataException e) {
|
98 |
e.printStackTrace(); |
99 |
} |
100 |
} |
101 |
|
102 |
public void setMetadata(Metadata metadata) { |
103 |
|
104 |
// Metadata ids must be different if both are not null
|
105 |
// if (((this.hasMetadata()) && (this.getMetadata() != null) && (this.getMetadata()
|
106 |
// .getDynClass().getFullName().equals(metadata.getDynClass()
|
107 |
// .getFullName())))) {
|
108 |
// return;
|
109 |
// }
|
110 |
if (inputComponent != null) { |
111 |
this.remove(inputComponent);
|
112 |
} |
113 |
|
114 |
super.setMetadata(metadata);
|
115 |
|
116 |
createMetadataComponent(metadata, true);
|
117 |
|
118 |
} |
119 |
|
120 |
|
121 |
protected AbstractSimpleMetadataPanel createMetadataComponent(Metadata metadata, boolean refresh) { |
122 |
if (metadata == null){ |
123 |
metadata = getMetadata(); |
124 |
} |
125 |
|
126 |
try {
|
127 |
|
128 |
component = (JDynObjectComponent) getNodeElements().get(metadata.getDynClass()); |
129 |
inputComponent = |
130 |
(JComponent) getComponentElements().get(metadata.getDynClass());
|
131 |
|
132 |
if (!((component != null)&&(refresh==false))) { |
133 |
component = createJDynObjectComponent( |
134 |
getMetadata().getDynClass(), getMetadata(), true);
|
135 |
|
136 |
}else{
|
137 |
component.setValue(metadata); |
138 |
} |
139 |
inputComponent = component.asJComponent(); |
140 |
putElement(getMetadata().getDynClass(), component); |
141 |
putComponent(getMetadata().getDynClass(), inputComponent); |
142 |
|
143 |
if (getMetadata() != null) { |
144 |
this.add(createJScrollPane(inputComponent));
|
145 |
} |
146 |
|
147 |
this.updateUI();
|
148 |
} catch (ServiceException e) {
|
149 |
// TODO Auto-generated catch block
|
150 |
e.printStackTrace(); |
151 |
} |
152 |
return this; |
153 |
} |
154 |
|
155 |
private Component createJScrollPane(JComponent inputComponent) { |
156 |
if (inputComponent instanceof JPanel) { |
157 |
return new JScrollPane(inputComponent); |
158 |
} |
159 |
return inputComponent;
|
160 |
} |
161 |
|
162 |
private Map getNodeElements() { |
163 |
if (nodeList == null) { |
164 |
nodeList = new HashMap(); |
165 |
} |
166 |
return nodeList;
|
167 |
} |
168 |
|
169 |
private void putElement(DynStruct metadata, JDynObjectComponent component) { |
170 |
|
171 |
getNodeElements().put(metadata, component); |
172 |
} |
173 |
|
174 |
private void putComponent(DynStruct metadata, JComponent component) { |
175 |
|
176 |
getComponentElements().put(metadata, component); |
177 |
} |
178 |
|
179 |
private Map getComponentElements() { |
180 |
if (nodeComponentsList == null) { |
181 |
nodeComponentsList = new HashMap(); |
182 |
} |
183 |
return nodeComponentsList;
|
184 |
} |
185 |
} |