Revision 35986

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/tools/swing/serv/field/crs/JCRSDynFieldComponent.java
77 77
     * ()
78 78
     */
79 79
    public void saveStatus() {
80
    	setFieldValue(this.getValue());
80
    	if (isValid()){
81
        	setFieldValue(this.getValue());    		
82
    	}
81 83
    }
82 84

  
83 85
    /*
......
93 95
     * (non-Javadoc)
94 96
     * 
95 97
     * @see
96
     * org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java
98
     * org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setNullValue(java
97 99
     * .lang.Object)
98 100
     */
99 101
    public void setNullValue() {
......
110 112

  
111 113
    public void setCurProj(IProjection projection) {
112 114
        panel.setCurProj(projection);
115
        this.fireValueChangedEvent();
113 116
    }
114 117

  
115 118
    public IProjection getCurProj() {
......
130 133
    protected void setJDynFieldComponentListeners() {
131 134

  
132 135
    }
136
    
137
    public void setValue(Object value){
138
    	Object oldValue = getValue();
139
    	if (value == null){
140
    		setNullValue();
141
    	}else{
142
    		setNonNullValue(value);
143
    	}
144
    	if (oldValue!=value){
145
        	this.fireValueChangedEvent();    		
146
    	}
147
    }
133 148

  
134 149
    @Override
135 150
    protected void afterUI() {
......
178 193
        return WindowInfo.DIALOG_PROFILE;
179 194
    }
180 195

  
181
    @Override
182
    public void setValue(Object value) {
183
        if (value instanceof IProjection)
184
            setCurProj((IProjection) value);
185
        else
186
            setNullValue();
187
    }
188

  
189 196
    public JComponent asJComponent() {
190 197
        return panel;
191 198
    }
......
204 211
                public void actionPerformed(java.awt.event.ActionEvent e) {
205 212
                    if (panel.isOkPressed()) {
206 213
                        setValue(panel.getCurProj());
214
                        fireValueChangedEvent();
207 215
                    }
208 216
                }
209 217
            });
210 218
        }
211 219
        return panel;
212 220
    }
221
    
222
	@Override
223
	public boolean isValid() {
224
		return this.getValue()!=null;
225
	}
213 226

  
214 227
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/view/metadata/gui/MetadataInfoManager.java
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
}

Also available in: Unified diff