Revision 893
org.gvsig.tools/library/trunk/org.gvsig.tools/dynform/src/org/gvsig/tools/dynform/impl/dynformfield/URI/JDynFormFieldURI.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.dynform.impl.dynformfield.URI; |
2 | 2 |
|
3 |
import java.io.File; |
|
3 | 4 |
import java.net.URI; |
4 | 5 |
import java.net.URISyntaxException; |
5 | 6 |
|
6 |
import javax.swing.JTextField;
|
|
7 |
import javax.swing.JFileChooser;
|
|
7 | 8 |
|
8 |
import org.gvsig.tools.dynform.impl.dynformfield.AbstractJDynFormFieldWithValueList;
|
|
9 |
import org.gvsig.tools.dynform.impl.dynformfield.File.JDynFormFieldFile;
|
|
9 | 10 |
import org.gvsig.tools.dynobject.DynObject; |
10 | 11 |
import org.gvsig.tools.service.spi.ServiceManager; |
11 | 12 |
|
12 |
public class JDynFormFieldURI extends AbstractJDynFormFieldWithValueList {
|
|
13 |
public class JDynFormFieldURI extends JDynFormFieldFile {
|
|
13 | 14 |
|
15 |
protected URI assignedValue = null; |
|
16 |
protected URI currentValue = null; |
|
14 | 17 |
|
15 | 18 |
public JDynFormFieldURI(DynObject parameters, |
16 | 19 |
ServiceManager serviceManager) { |
17 | 20 |
super(parameters, serviceManager); |
21 |
this.assignedValue = (URI) this.getParameterValue(); |
|
18 | 22 |
} |
19 | 23 |
|
20 |
protected String getDefaultValue(){ |
|
21 |
return ""; |
|
22 |
} |
|
23 |
|
|
24 | 24 |
public Object getValue() { |
25 |
Object value = null;
|
|
25 |
URI value = null;
|
|
26 | 26 |
String s = ""; |
27 |
if( this.contents instanceof JTextField ) { |
|
28 |
s = this.getJTextField().getText(); |
|
29 |
} else { |
|
30 |
s = this.getJComboBox().getSelectedItem().toString(); |
|
31 |
} |
|
27 |
s = this.jtext.getText(); |
|
32 | 28 |
if( s.trim().length()==0 ) { |
33 | 29 |
Object x = this.getDefinition().getDefaultValue(); |
34 | 30 |
if( x == null ) { |
35 |
value = "";
|
|
31 |
value = null;
|
|
36 | 32 |
} else { |
37 | 33 |
try { |
38 | 34 |
value = new URI(x.toString()); |
39 | 35 |
} catch (URISyntaxException e) { |
40 | 36 |
logger.info("Error. URI Syntax: "+x.toString()); |
37 |
value = null; |
|
41 | 38 |
} |
42 | 39 |
} |
43 | 40 |
} else { |
... | ... | |
45 | 42 |
value = new URI(s); |
46 | 43 |
} catch (URISyntaxException e) { |
47 | 44 |
logger.info("Error. URI Syntax: "+s); |
45 |
value = null; |
|
48 | 46 |
} |
49 | 47 |
} |
50 | 48 |
return value; |
51 | 49 |
} |
52 | 50 |
|
51 |
public void setValue(Object value) { |
|
52 |
if( value == null ) { |
|
53 |
this.jtext.setText(""); |
|
54 |
} else { |
|
55 |
if( !(value instanceof URI) ) { |
|
56 |
logger.info("setValue invoked with non URI value ("+value.toString()+")."); |
|
57 |
return; |
|
58 |
} |
|
59 |
this.jtext.setText(((URI)value).getPath()); |
|
60 |
} |
|
61 |
try { |
|
62 |
this.assignedValue = new URI(((URI)value).getPath()); |
|
63 |
} catch (URISyntaxException e) { |
|
64 |
logger.info("Error in URI creation."); |
|
65 |
this.assignedValue = null; |
|
66 |
} |
|
67 |
this.currentValue = this.assignedValue; |
|
68 |
} |
|
69 |
|
|
70 |
public File[] showOpenFileDialog(String title, File initialPath) { |
|
71 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_AND_DIRECTORIES, false, initialPath, null, false); |
|
72 |
} |
|
73 |
|
|
53 | 74 |
} |
Also available in: Unified diff