gvsig-desktop-customize / trunk / org.gvsig.customize.app / org.gvsig.customize.app.mainplugin / src / main / java / org / gvsig / customize / locale / JDynFormFieldLocale.java @ 1
History | View | Annotate | Download (2.89 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.customize.locale; |
25 |
|
26 |
import java.util.Locale; |
27 |
import java.util.Set; |
28 |
import javax.swing.JComboBox; |
29 |
import org.apache.commons.lang3.StringUtils; |
30 |
import org.gvsig.andami.LocaleManager; |
31 |
import org.gvsig.andami.PluginsLocator; |
32 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
33 |
import org.gvsig.tools.dynobject.DynObject; |
34 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
35 |
import org.gvsig.tools.service.spi.ServiceManager; |
36 |
|
37 |
public class JDynFormFieldLocale extends AbstractJDynFormFieldWithValueList { |
38 |
|
39 |
public JDynFormFieldLocale(DynObject parameters,
|
40 |
ServiceManager serviceManager) { |
41 |
super(parameters, serviceManager);
|
42 |
} |
43 |
|
44 |
protected String getDefaultValue(){ |
45 |
return ""; |
46 |
} |
47 |
|
48 |
public Object getValue() { |
49 |
Object value = null; |
50 |
String s = this.getValueFromJComponent(); |
51 |
if( StringUtils.isBlank(s) ) {
|
52 |
Object x = this.getDefinition().getDefaultValue(); |
53 |
if( x != null ) { |
54 |
value = x.toString(); |
55 |
} |
56 |
} else {
|
57 |
value = s; |
58 |
} |
59 |
return value;
|
60 |
} |
61 |
|
62 |
@Override
|
63 |
public void initComponent() { |
64 |
LocaleManager localeManager = PluginsLocator.getLocaleManager(); |
65 |
Set<Locale> localesSet = localeManager.getInstalledLocales(); |
66 |
DynObjectValueItem[] locales = new DynObjectValueItem[localesSet.size()]; |
67 |
int i=0; |
68 |
for( Locale locale : localesSet ) { |
69 |
locales[i++] = new DynObjectValueItem(
|
70 |
locale.toString(), |
71 |
localeManager.getLocaleDisplayName(locale) |
72 |
); |
73 |
} |
74 |
this.contents = new JComboBox(locales); |
75 |
if( locales.length>0 ) { |
76 |
this.getJComboBox().setSelectedIndex(0); |
77 |
} |
78 |
this.contents.addFocusListener(this); |
79 |
if( this.getDefinition().isReadOnly() ) { |
80 |
this.getJComboBox().setEditable(false); |
81 |
} |
82 |
this.setValue(this.assignedValue); |
83 |
} |
84 |
|
85 |
} |