Revision 42940
tags/org.gvsig.desktop-2.0.148/org.gvsig.desktop.library/org.gvsig.newlayer/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.newlayer</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<description>newlayer project</description> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<artifactId>org.gvsig.desktop.library</artifactId> |
|
12 |
<version>2.0.148</version> |
|
13 |
</parent> |
|
14 |
|
|
15 |
<dependencies> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
19 |
</dependency> |
|
20 |
<dependency> |
|
21 |
<groupId>org.gvsig</groupId> |
|
22 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
23 |
<type>test-jar</type> |
|
24 |
<scope>test</scope> |
|
25 |
</dependency> |
|
26 |
</dependencies> |
|
27 |
|
|
28 |
<modules> |
|
29 |
<module>org.gvsig.newlayer.lib</module> |
|
30 |
<module>org.gvsig.newlayer.prov</module> |
|
31 |
</modules> |
|
32 |
</project> |
|
0 | 33 |
tags/org.gvsig.desktop-2.0.148/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2013 gvSIG Association. |
|
7 |
|
|
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License |
|
10 |
as published by the Free Software Foundation; either version 3 |
|
11 |
of the License, or (at your option) any later version. |
|
12 |
|
|
13 |
This program is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
GNU General Public License for more details. |
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
|
19 |
along with this program; if not, write to the Free Software |
|
20 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
MA 02110-1301, USA. |
|
22 |
|
|
23 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
28 |
|
|
29 |
<!-- |
|
30 |
Log4J configuration file for unit tests execution. |
|
31 |
--> |
|
32 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
33 |
|
|
34 |
<!-- Appender configuration to show logging messages through the console --> |
|
35 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
36 |
<layout class="org.apache.log4j.PatternLayout"> |
|
37 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
38 |
</layout> |
|
39 |
</appender> |
|
40 |
|
|
41 |
<!-- |
|
42 |
Activate logging messages of DEBUG level of higher only for the |
|
43 |
org.gvsig.tools packages. |
|
44 |
You can put full classes names or packages instead, to configure |
|
45 |
logging for all the classes and subpackages of the package. |
|
46 |
--> |
|
47 |
<category name="org.gvsig.tools"> |
|
48 |
<priority value="DEBUG" /> |
|
49 |
</category> |
|
50 |
<category name="org.gvsig.newlayer"> |
|
51 |
<priority value="DEBUG" /> |
|
52 |
</category> |
|
53 |
|
|
54 |
<!-- |
|
55 |
By default, show only logging messages of INFO level or higher, |
|
56 |
through the previously configured CONSOLE appender. |
|
57 |
--> |
|
58 |
<root> |
|
59 |
<priority value="INFO" /> |
|
60 |
<appender-ref ref="CONSOLE" /> |
|
61 |
</root> |
|
62 |
</log4j:configuration> |
|
0 | 63 |
tags/org.gvsig.desktop-2.0.148/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
|
0 | 9 |
tags/org.gvsig.desktop-2.0.148/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/DefaultNewLayerService.java | ||
---|---|---|
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.newlayer.impl; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DALLocator; |
|
31 |
import org.gvsig.fmap.dal.DataManager; |
|
32 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
33 |
import org.gvsig.fmap.dal.DataStore; |
|
34 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
35 |
import org.gvsig.fmap.dal.exception.DataException; |
|
36 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
37 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
38 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
39 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
40 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
41 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
42 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
43 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
44 |
import org.gvsig.newlayer.NewLayerManager; |
|
45 |
import org.gvsig.newlayer.NewLayerProvider; |
|
46 |
import org.gvsig.newlayer.NewLayerProviderFactory; |
|
47 |
import org.gvsig.newlayer.NewLayerService; |
|
48 |
import org.gvsig.newlayer.NewLayerServiceException; |
|
49 |
import org.gvsig.tools.service.ServiceException; |
|
50 |
|
|
51 |
/** |
|
52 |
* Default {@link NewLayerService} implementation. |
|
53 |
* |
|
54 |
* @author gvSIG Team |
|
55 |
* @version $Id$ |
|
56 |
*/ |
|
57 |
public class DefaultNewLayerService implements NewLayerService { |
|
58 |
|
|
59 |
private NewLayerManager newLayerManager; |
|
60 |
private NewLayerProviderFactory type; |
|
61 |
private NewLayerProvider provider; |
|
62 |
private boolean addLayerToView = true; |
|
63 |
private MapContext mapContext; |
|
64 |
|
|
65 |
/** |
|
66 |
* {@link DefaultNewLayerService} constructor |
|
67 |
*/ |
|
68 |
public DefaultNewLayerService(NewLayerManager manager, MapContext mapContext) { |
|
69 |
this.newLayerManager = manager; |
|
70 |
this.mapContext = mapContext; |
|
71 |
} |
|
72 |
|
|
73 |
public NewLayerProvider getProvider() { |
|
74 |
return provider; |
|
75 |
} |
|
76 |
|
|
77 |
public void createLayer() throws NewLayerServiceException { |
|
78 |
try { |
|
79 |
this.getExplorer().add(this.getStoreName(), |
|
80 |
this.getNewStoreParameters(), true); |
|
81 |
} catch (DataException e) { |
|
82 |
throw new CantCreateNewLayerException(e); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
public void loadLayer() throws NewLayerServiceException { |
|
87 |
try { |
|
88 |
String storeName = this.getStoreName(); |
|
89 |
DataStoreParameters storeParameters = |
|
90 |
this.getOpenStoreParameters(); |
|
91 |
DataManager dataManager = DALLocator.getDataManager(); |
|
92 |
DataStore store = dataManager.openStore(storeName, storeParameters); |
|
93 |
String layerName = store.getName(); |
|
94 |
|
|
95 |
MapContextManager mapContextManager = |
|
96 |
MapContextLocator.getMapContextManager(); |
|
97 |
FLayer lyr = mapContextManager.createLayer(layerName, store); |
|
98 |
lyr.setActive(true); |
|
99 |
lyr.setVisible(true); |
|
100 |
mapContext.getLayers().addLayer(lyr); |
|
101 |
|
|
102 |
lyr.dispose(); |
|
103 |
} catch (DataException e) { |
|
104 |
throw new CantOpenStoreException(e); |
|
105 |
} catch (ValidateDataParametersException e) { |
|
106 |
throw new CantOpenStoreException(e); |
|
107 |
} catch (LoadLayerException e) { |
|
108 |
throw new CantLoadNewLayerException(e); |
|
109 |
} |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
public class CantCreateNewLayerException extends NewLayerServiceException { |
|
114 |
|
|
115 |
/** |
|
116 |
* |
|
117 |
*/ |
|
118 |
private static final long serialVersionUID = 4208215791054246118L; |
|
119 |
|
|
120 |
public CantCreateNewLayerException(Throwable cause) { |
|
121 |
super("Can't create the layer", cause, "_cant_create_the_layer", |
|
122 |
serialVersionUID); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
public class CantOpenStoreException extends NewLayerServiceException { |
|
127 |
|
|
128 |
/** |
|
129 |
* |
|
130 |
*/ |
|
131 |
private static final long serialVersionUID = -2245228621032918630L; |
|
132 |
|
|
133 |
public CantOpenStoreException(Throwable cause) { |
|
134 |
super("Can't open store", cause, "_cant_open_store", |
|
135 |
serialVersionUID); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
public class CantLoadNewLayerException extends NewLayerServiceException { |
|
140 |
|
|
141 |
/** |
|
142 |
* |
|
143 |
*/ |
|
144 |
private static final long serialVersionUID = -1711950651766745963L; |
|
145 |
|
|
146 |
public CantLoadNewLayerException(Throwable cause) { |
|
147 |
super("Can't load the new layer", cause, |
|
148 |
"_cant_load_the_new_layer", serialVersionUID); |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
public void setType(String type) { |
|
153 |
try { |
|
154 |
setProviderFactory(this.newLayerManager |
|
155 |
.getNewLayerProviderFactory(type)); |
|
156 |
} catch (ServiceException e) { |
|
157 |
throw new RuntimeException(e); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
public DataServerExplorer getExplorer() { |
|
162 |
return getProvider().getExplorer(); |
|
163 |
} |
|
164 |
|
|
165 |
public String getStoreName() { |
|
166 |
return getProvider().getStoreName(); |
|
167 |
} |
|
168 |
|
|
169 |
public EditableFeatureType getFeatureType() { |
|
170 |
return getProvider().getFeatureType(); |
|
171 |
} |
|
172 |
|
|
173 |
public NewFeatureStoreParameters getNewStoreParameters() { |
|
174 |
return getProvider().getNewStoreParameters(); |
|
175 |
} |
|
176 |
|
|
177 |
public DataStoreParameters getOpenStoreParameters() { |
|
178 |
return getProvider().getOpenStoreParameters(); |
|
179 |
} |
|
180 |
|
|
181 |
public List<String> getTypes() { |
|
182 |
List<String> types = new ArrayList<String>(); |
|
183 |
List<NewLayerProviderFactory> providers = getProviderFactories(); |
|
184 |
Iterator<NewLayerProviderFactory> it = providers.iterator(); |
|
185 |
while (it.hasNext()) { |
|
186 |
NewLayerProviderFactory newLayerProviderFactory = it.next(); |
|
187 |
types.add(newLayerProviderFactory.getName()); |
|
188 |
} |
|
189 |
return types; |
|
190 |
} |
|
191 |
|
|
192 |
public String getType() { |
|
193 |
return this.type.getName(); |
|
194 |
} |
|
195 |
|
|
196 |
public void addLayerToView(boolean b) { |
|
197 |
this.addLayerToView = b; |
|
198 |
} |
|
199 |
|
|
200 |
public MapContext getMapContext() { |
|
201 |
return mapContext; |
|
202 |
} |
|
203 |
|
|
204 |
public void setProviderFactory(NewLayerProviderFactory type) { |
|
205 |
this.type = type; |
|
206 |
this.provider = type.create(this); |
|
207 |
} |
|
208 |
|
|
209 |
public NewLayerProviderFactory getProviderFactory() { |
|
210 |
return type; |
|
211 |
} |
|
212 |
|
|
213 |
public List<NewLayerProviderFactory> getProviderFactories() { |
|
214 |
|
|
215 |
List<NewLayerProviderFactory> providers = |
|
216 |
new ArrayList<NewLayerProviderFactory>( |
|
217 |
this.newLayerManager |
|
218 |
.getProviders(NewLayerManager.STORETYPE.ANY)); |
|
219 |
|
|
220 |
for (Iterator<NewLayerProviderFactory> iterator = providers.iterator(); iterator |
|
221 |
.hasNext();) { |
|
222 |
NewLayerProviderFactory newLayerProviderFactory = iterator.next(); |
|
223 |
if (!newLayerProviderFactory.isEnabled()) { |
|
224 |
iterator.remove(); |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
return providers; |
|
229 |
} |
|
230 |
|
|
231 |
} |
|
0 | 232 |
tags/org.gvsig.desktop-2.0.148/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/DefaultNewLayerWizard.java | ||
---|---|---|
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.newlayer.impl; |
|
25 |
|
|
26 |
import java.awt.Dimension; |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import javax.swing.ImageIcon; |
|
31 |
import javax.swing.JOptionPane; |
|
32 |
import javax.swing.JPanel; |
|
33 |
|
|
34 |
import jwizardcomponent.CancelAction; |
|
35 |
import jwizardcomponent.DefaultJWizardComponents; |
|
36 |
import jwizardcomponent.FinishAction; |
|
37 |
import jwizardcomponent.JWizardComponents; |
|
38 |
|
|
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
|
|
42 |
import org.gvsig.fmap.dal.DALLocator; |
|
43 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
45 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
|
46 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
|
47 |
import org.gvsig.i18n.Messages; |
|
48 |
import org.gvsig.newlayer.NewLayerException; |
|
49 |
import org.gvsig.newlayer.NewLayerProviderFactory; |
|
50 |
import org.gvsig.newlayer.NewLayerProviderPanel; |
|
51 |
import org.gvsig.newlayer.NewLayerService; |
|
52 |
import org.gvsig.newlayer.NewLayerServiceException; |
|
53 |
import org.gvsig.newlayer.NewLayerWizard; |
|
54 |
|
|
55 |
public class DefaultNewLayerWizard extends NewLayerWizard { |
|
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
*/ |
|
60 |
private static final long serialVersionUID = -5827106636136663823L; |
|
61 |
private NewLayerService service; |
|
62 |
private AddNewLayerQuestionPanel addNewLayerQuestionPanel; |
|
63 |
private static final Logger LOG = |
|
64 |
LoggerFactory.getLogger(DefaultNewLayerWizard.class); |
|
65 |
|
|
66 |
public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) { |
|
67 |
super(logo); |
|
68 |
setPreferredSize(new Dimension(800, 400)); |
|
69 |
this.service = service; |
|
70 |
this.getWizardComponents().setFinishAction( |
|
71 |
new MyFinishAction(this.getWizardComponents())); |
|
72 |
this.getWizardComponents().setCancelAction( |
|
73 |
new MyCancelAction(this.getWizardComponents())); |
|
74 |
this.createTypeSelector(); |
|
75 |
|
|
76 |
// ================ disable at the start |
|
77 |
this.setFinishButtonEnabled(false); |
|
78 |
this.setBackButtonEnabled(false); |
|
79 |
this.setNextButtonEnabled(false); |
|
80 |
} |
|
81 |
|
|
82 |
public NewLayerService getService() { |
|
83 |
return this.service; |
|
84 |
} |
|
85 |
|
|
86 |
private void createTypeSelector() { |
|
87 |
|
|
88 |
TypeSelectorPanel panel = new TypeSelectorPanel(this); |
|
89 |
this.addOptionPanel(panel); |
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
private void createFeatureTypePanel() { |
|
94 |
|
|
95 |
FeatureTypePanel panel = new FeatureTypePanel(service); |
|
96 |
this.addOptionPanel(panel); |
|
97 |
} |
|
98 |
|
|
99 |
private void createProviderPanels() { |
|
100 |
DefaultJWizardComponents wizardComponents = this.getWizardComponents(); |
|
101 |
for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) { |
|
102 |
wizardComponents.removeWizardPanel(i); |
|
103 |
} |
|
104 |
List<NewLayerProviderPanel> panels = service.getProvider().getPanels(); |
|
105 |
Iterator<NewLayerProviderPanel> it = panels.iterator(); |
|
106 |
while (it.hasNext()) { |
|
107 |
NewLayerProviderPanel panel = it.next(); |
|
108 |
this.addOptionPanel(new OptionPanelWrapper(panel)); |
|
109 |
} |
|
110 |
this.createFeatureTypePanel(); |
|
111 |
this.createAddNewLayerQuestionPanel(); |
|
112 |
} |
|
113 |
|
|
114 |
private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() { |
|
115 |
if (this.addNewLayerQuestionPanel == null) { |
|
116 |
this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this); |
|
117 |
} |
|
118 |
return this.addNewLayerQuestionPanel; |
|
119 |
} |
|
120 |
|
|
121 |
private void createAddNewLayerQuestionPanel() { |
|
122 |
this.addOptionPanel(getAddNewLayerQuestionPanel()); |
|
123 |
} |
|
124 |
|
|
125 |
private boolean getAddLayerToView() { |
|
126 |
return getAddNewLayerQuestionPanel().getAddLayerToView(); |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public void setType(NewLayerProviderFactory currentType) { |
|
131 |
this.service.setProviderFactory(currentType); |
|
132 |
createProviderPanels(); |
|
133 |
} |
|
134 |
|
|
135 |
private class OptionPanelWrapper implements OptionPanel { |
|
136 |
|
|
137 |
private NewLayerProviderPanel panel; |
|
138 |
|
|
139 |
public OptionPanelWrapper(NewLayerProviderPanel panel) { |
|
140 |
this.panel = panel; |
|
141 |
} |
|
142 |
|
|
143 |
public String getPanelTitle() { |
|
144 |
return this.panel.getTitle(); |
|
145 |
} |
|
146 |
|
|
147 |
public void nextPanel() throws NotContinueWizardException { |
|
148 |
|
|
149 |
try { |
|
150 |
if (!this.panel.isValidPanel()) { |
|
151 |
throw new NotContinueWizardException("Error validating the form", panel, false); |
|
152 |
} |
|
153 |
} catch (NewLayerException e) { |
|
154 |
LOG.info("Error validating the form", e); |
|
155 |
throw new NotContinueWizardException("Error validating the form", |
|
156 |
e, panel); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
public void lastPanel() { |
|
161 |
} |
|
162 |
|
|
163 |
public void updatePanel() { |
|
164 |
this.panel.updatePanel(); |
|
165 |
} |
|
166 |
|
|
167 |
public JPanel getJPanel() { |
|
168 |
return this.panel; |
|
169 |
} |
|
170 |
|
|
171 |
} |
|
172 |
|
|
173 |
private class MyFinishAction extends FinishAction { |
|
174 |
|
|
175 |
public MyFinishAction(JWizardComponents arg0) { |
|
176 |
super(arg0); |
|
177 |
} |
|
178 |
|
|
179 |
public void performAction() { |
|
180 |
|
|
181 |
if (getService().getStoreName() == null) { |
|
182 |
JOptionPane |
|
183 |
.showMessageDialog( |
|
184 |
null, |
|
185 |
Messages.getText("new_layer_not_store_name"), |
|
186 |
Messages.getText("new_layer"), |
|
187 |
JOptionPane.WARNING_MESSAGE); |
|
188 |
return; |
|
189 |
} |
|
190 |
if (getService().getNewStoreParameters() == null) { |
|
191 |
JOptionPane |
|
192 |
.showMessageDialog( |
|
193 |
null, |
|
194 |
Messages.getText("new_layer_parameters_missing"), |
|
195 |
Messages.getText("new_layer"), |
|
196 |
JOptionPane.WARNING_MESSAGE); |
|
197 |
return; |
|
198 |
} |
|
199 |
getService().addLayerToView(getAddLayerToView()); |
|
200 |
try { |
|
201 |
getService().createLayer(); |
|
202 |
} catch (NewLayerServiceException e) { |
|
203 |
LOG.info("Cannot create the new layer", e); |
|
204 |
JOptionPane |
|
205 |
.showMessageDialog( |
|
206 |
null, |
|
207 |
Messages.getText("cant_create_new_layer") + "\n" + e.getMessageStack(), |
|
208 |
Messages.getText("new_layer"), |
|
209 |
JOptionPane.ERROR_MESSAGE); |
|
210 |
return; |
|
211 |
} |
|
212 |
|
|
213 |
try { |
|
214 |
getService().loadLayer(); |
|
215 |
} catch (NewLayerServiceException e) { |
|
216 |
JOptionPane |
|
217 |
.showMessageDialog( |
|
218 |
null, |
|
219 |
"The new layer has been succesfully created but can't load the new layer.\n Try load it yourshelf, please.", |
|
220 |
"Can't create a new layer", |
|
221 |
JOptionPane.WARNING_MESSAGE); |
|
222 |
} |
|
223 |
setVisible(false); |
|
224 |
return; |
|
225 |
} |
|
226 |
|
|
227 |
} |
|
228 |
|
|
229 |
private class MyCancelAction extends CancelAction { |
|
230 |
|
|
231 |
public MyCancelAction(DefaultJWizardComponents wizardComponents) { |
|
232 |
super(wizardComponents); |
|
233 |
} |
|
234 |
|
|
235 |
public void performAction() { |
|
236 |
setVisible(false); |
|
237 |
} |
|
238 |
|
|
239 |
} |
|
240 |
} |
|
0 | 241 |
tags/org.gvsig.desktop-2.0.148/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/FeatureTypePanel.java | ||
---|---|---|
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.newlayer.impl; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.Component; |
|
28 |
import java.awt.GridBagConstraints; |
|
29 |
import java.awt.GridBagLayout; |
|
30 |
import java.awt.Insets; |
|
31 |
import java.awt.event.ActionEvent; |
|
32 |
import java.awt.event.ActionListener; |
|
33 |
import java.awt.event.ItemEvent; |
|
34 |
import java.awt.event.ItemListener; |
|
35 |
import java.util.ArrayList; |
|
36 |
import java.util.Iterator; |
|
37 |
import java.util.List; |
|
38 |
|
|
39 |
import javax.swing.ComboBoxModel; |
|
40 |
import javax.swing.DefaultCellEditor; |
|
41 |
import javax.swing.JButton; |
|
42 |
import javax.swing.JCheckBox; |
|
43 |
import javax.swing.JComboBox; |
|
44 |
import javax.swing.JLabel; |
|
45 |
import javax.swing.JOptionPane; |
|
46 |
import javax.swing.JPanel; |
|
47 |
import javax.swing.JScrollPane; |
|
48 |
import javax.swing.JTable; |
|
49 |
import javax.swing.JTextField; |
|
50 |
import javax.swing.ListSelectionModel; |
|
51 |
import javax.swing.UIManager; |
|
52 |
import javax.swing.event.ListDataListener; |
|
53 |
import javax.swing.event.ListSelectionEvent; |
|
54 |
import javax.swing.event.ListSelectionListener; |
|
55 |
import javax.swing.event.TableModelEvent; |
|
56 |
import javax.swing.event.TableModelListener; |
|
57 |
import javax.swing.table.DefaultTableCellRenderer; |
|
58 |
import javax.swing.table.DefaultTableModel; |
|
59 |
import javax.swing.table.TableCellRenderer; |
|
60 |
import javax.swing.table.TableColumn; |
|
61 |
import javax.swing.table.TableModel; |
|
62 |
|
|
63 |
import org.cresques.cts.IProjection; |
|
64 |
import org.slf4j.Logger; |
|
65 |
import org.slf4j.LoggerFactory; |
|
66 |
|
|
67 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
|
68 |
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
|
69 |
import org.gvsig.fmap.dal.DALLocator; |
|
70 |
import org.gvsig.fmap.dal.DataManager; |
|
71 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
|
72 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
73 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
74 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
75 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
76 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
77 |
import org.gvsig.fmap.geom.DataTypes; |
|
78 |
import org.gvsig.fmap.geom.Geometry; |
|
79 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
80 |
import org.gvsig.fmap.geom.GeometryManager; |
|
81 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
82 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
|
83 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
|
84 |
import org.gvsig.i18n.Messages; |
|
85 |
import org.gvsig.newlayer.NewLayerService; |
|
86 |
import org.gvsig.tools.dataTypes.DataType; |
|
87 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
88 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
89 |
|
|
90 |
public class FeatureTypePanel extends JPanel implements OptionPanel { |
|
91 |
private static final int COLUMN_FIELD = 0; |
|
92 |
private static final int COLUMN_TYPE = 1; |
|
93 |
private static final int COLUMN_LENGTH = 2; |
|
94 |
private static final int COLUMN_GEOMETRYTYPE = 3; |
|
95 |
private static final int COLUMN_GEOMETRYSUBTYPE = 4; |
|
96 |
private static final int COLUMN_CRS = 5; |
|
97 |
private static final int COLUMN_PRIMARYKEY = 6; |
|
98 |
private static final int COLUMN_MANDATORY = 7; |
|
99 |
|
|
100 |
private static final long serialVersionUID = 263541873998597624L; |
|
101 |
|
|
102 |
private FeatureType defaultFeatType = null; |
|
103 |
|
|
104 |
private NewLayerService newLayer_Service = null; |
|
105 |
private int inDefaultFeatTypeFieldCount = 0; |
|
106 |
private String inStoreName = null; |
|
107 |
private IProjection inProjection = null; |
|
108 |
private FeatureStoreProviderFactory spFactory = null; |
|
109 |
private boolean defaultHasGeometry = false; |
|
110 |
|
|
111 |
private static final Logger logger = LoggerFactory |
|
112 |
.getLogger(FeatureTypePanel.class); |
|
113 |
|
|
114 |
private JLabel jLabel = null; |
|
115 |
private JScrollPane jScrollPane = null; |
|
116 |
protected JTable jTable = null; |
|
117 |
private JPanel jPanelEast = null; |
|
118 |
private JButton addFieldButton = null; |
|
119 |
private JButton deleteFieldButton = null; |
|
120 |
protected int MAX_FIELD_LENGTH = 254; |
|
121 |
|
|
122 |
// we dont need this list |
|
123 |
// we'll clear and rebuild featureType each time |
|
124 |
// the user clicks next |
|
125 |
// private List removedFields; |
|
126 |
|
|
127 |
// private DataServerExplorer explorer = null; |
|
128 |
|
|
129 |
public FeatureTypePanel(NewLayerService new_layer_service) { |
|
130 |
|
|
131 |
/* |
|
132 |
service.getFeatureType(), |
|
133 |
service.getStoreName(), |
|
134 |
service.getMapContext().getProjection(); |
|
135 |
*/ |
|
136 |
newLayer_Service = new_layer_service; |
|
137 |
} |
|
138 |
|
|
139 |
private boolean fieldsInited = false; |
|
140 |
|
|
141 |
private void initFields() { |
|
142 |
|
|
143 |
if (newLayer_Service == null) { |
|
144 |
return; |
|
145 |
} |
|
146 |
|
|
147 |
fieldsInited = true; |
|
148 |
|
|
149 |
inStoreName = newLayer_Service.getStoreName(); |
|
150 |
inProjection = newLayer_Service.getMapContext().getProjection(); |
|
151 |
|
|
152 |
DataStoreProviderFactory dspf = |
|
153 |
DALLocator.getDataManager().getStoreProviderFactory(inStoreName); |
|
154 |
spFactory = (FeatureStoreProviderFactory) dspf; |
|
155 |
defaultFeatType = spFactory.createDefaultFeatureType(); |
|
156 |
if (defaultFeatType != null) { |
|
157 |
inDefaultFeatTypeFieldCount = |
|
158 |
defaultFeatType.getAttributeDescriptors().length; |
|
159 |
int def_geom_fld_index = defaultFeatType.getDefaultGeometryAttributeIndex(); |
|
160 |
if (def_geom_fld_index >= 0 && |
|
161 |
def_geom_fld_index < inDefaultFeatTypeFieldCount && |
|
162 |
defaultFeatType. |
|
163 |
getAttributeDescriptor(def_geom_fld_index). |
|
164 |
getDataType().getType() == DataTypes.GEOMETRY) { |
|
165 |
|
|
166 |
defaultHasGeometry = true; |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
private void initializeComponents() { |
|
172 |
jLabel = new JLabel(); |
|
173 |
jLabel.setText(Messages.getText("define_fields")); |
|
174 |
this.setLayout(new BorderLayout(5, 5)); |
|
175 |
this.setSize(new java.awt.Dimension(499, 232)); |
|
176 |
this.add(jLabel, java.awt.BorderLayout.NORTH); |
|
177 |
this.add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
|
178 |
this.add(getJPanelSouth(), java.awt.BorderLayout.SOUTH); |
|
179 |
|
|
180 |
} |
|
181 |
|
|
182 |
/** |
|
183 |
* This method initializes jScrollPane |
|
184 |
* |
|
185 |
* @return javax.swing.JScrollPane |
|
186 |
*/ |
|
187 |
private JScrollPane getJScrollPane() { |
|
188 |
if (jScrollPane == null) { |
|
189 |
jScrollPane = new JScrollPane(); |
|
190 |
jScrollPane.setViewportView(getJTable()); |
|
191 |
} |
|
192 |
return jScrollPane; |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* This method initializes jTable |
|
197 |
* |
|
198 |
* @return javax.swing.JTable |
|
199 |
*/ |
|
200 |
private JTable getJTable() { |
|
201 |
if (jTable == null) { |
|
202 |
jTable = new JTable(){ |
|
203 |
public boolean isCellEditable(int row,int column){ |
|
204 |
|
|
205 |
|
|
206 |
if (row < inDefaultFeatTypeFieldCount) { |
|
207 |
// default fields |
|
208 |
Object o = getValueAt(row,COLUMN_TYPE); |
|
209 |
if (o instanceof ComboItemDataType) { |
|
210 |
|
|
211 |
ComboItemDataType ot = (ComboItemDataType) o; |
|
212 |
return (ot.dataType.getType() == DataTypes.GEOMETRY) |
|
213 |
&& |
|
214 |
(column == COLUMN_GEOMETRYTYPE || |
|
215 |
column == COLUMN_GEOMETRYSUBTYPE); |
|
216 |
|
|
217 |
} else { |
|
218 |
return false; |
|
219 |
} |
|
220 |
|
|
221 |
} else { |
|
222 |
// fields added by user |
|
223 |
if (column == COLUMN_PRIMARYKEY) { |
|
224 |
return spFactory.allowsPrimaryKeyAttributes(); |
|
225 |
} |
|
226 |
|
|
227 |
if (column == COLUMN_MANDATORY) { |
|
228 |
return spFactory.allowsMandatoryAttributes(); |
|
229 |
} |
|
230 |
|
|
231 |
if (column == COLUMN_LENGTH) { |
|
232 |
|
|
233 |
Object o = getValueAt(row,COLUMN_TYPE); |
|
234 |
if (o instanceof ComboItemDataType) { |
|
235 |
|
|
236 |
ComboItemDataType ot = (ComboItemDataType) o; |
|
237 |
return dataTypeNeedsSize(ot.dataType.getType()); |
|
238 |
|
|
239 |
} else { |
|
240 |
return false; |
|
241 |
} |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
if (defaultHasGeometry && |
|
246 |
(column == COLUMN_GEOMETRYTYPE |
|
247 |
|| column == COLUMN_GEOMETRYSUBTYPE |
|
248 |
|| column == COLUMN_CRS)) { |
|
249 |
// geom-related columns not editable |
|
250 |
return false; |
|
251 |
} else { |
|
252 |
return true; |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
/* |
|
257 |
if ((column == COLUMN_GEOMETRYTYPE) || |
|
258 |
(column == COLUMN_GEOMETRYSUBTYPE) || |
|
259 |
(column == COLUMN_CRS)) { |
|
260 |
DataType dataType = |
|
261 |
((ComboItemDataType) getValueAt(row, COLUMN_TYPE)).dataType; |
|
262 |
return dataType.getType() == DataTypes.GEOMETRY; |
|
263 |
} |
|
264 |
*/ |
|
265 |
} |
|
266 |
}; |
|
267 |
|
|
268 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
|
269 |
|
|
270 |
tm.addColumn(Messages.getText("_Name")); |
|
271 |
tm.addColumn(Messages.getText("type")); |
|
272 |
tm.addColumn(Messages.getText("length")); |
|
273 |
tm.addColumn(Messages.getText("_Geometry_type")); |
|
274 |
tm.addColumn(Messages.getText("_Dimensions")); |
|
275 |
tm.addColumn(Messages.getText("CRS")); |
|
276 |
tm.addColumn("PK"); |
|
277 |
tm.addColumn(Messages.getText("_Mandatory_(short_text)")); |
|
278 |
|
|
279 |
// Ask to be notified of selection changes. |
|
280 |
ListSelectionModel rowSM = jTable.getSelectionModel(); |
|
281 |
rowSM.addListSelectionListener(new ListSelectionListener() { |
|
282 |
public void valueChanged(ListSelectionEvent e) { |
|
283 |
// Ignore extra messages. |
|
284 |
if (e.getValueIsAdjusting()) |
|
285 |
return; |
|
286 |
|
|
287 |
ListSelectionModel lsm = (ListSelectionModel) e.getSource(); |
|
288 |
if (lsm.isSelectionEmpty()) { |
|
289 |
// no rows are selected |
|
290 |
deleteFieldButton.setEnabled(false); |
|
291 |
} else { |
|
292 |
int min_sele = lsm.getMinSelectionIndex(); |
|
293 |
if (min_sele > -1 && |
|
294 |
min_sele < inDefaultFeatTypeFieldCount) { |
|
295 |
deleteFieldButton.setEnabled(false); |
|
296 |
} else { |
|
297 |
deleteFieldButton.setEnabled(allowEditableFeatureType()); |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
} |
|
302 |
}); |
|
303 |
jTable.getColumnModel().getColumn(0).setPreferredWidth(100); |
|
304 |
// PK column |
|
305 |
jTable.getColumnModel().getColumn(6).setPreferredWidth(30); |
|
306 |
// Oblig column |
|
307 |
jTable.getColumnModel().getColumn(7).setPreferredWidth(50); |
|
308 |
|
|
309 |
jTable.getModel().addTableModelListener(new TableModelListener() { |
|
310 |
public void tableChanged(TableModelEvent e) { |
|
311 |
if (e.getColumn() == COLUMN_TYPE){ |
|
312 |
jTable.repaint(); |
|
313 |
} |
|
314 |
} |
|
315 |
}); |
|
316 |
|
|
317 |
|
|
318 |
if (!fieldsInited) { |
|
319 |
initFields(); |
|
320 |
} |
|
321 |
|
|
322 |
// Rellenado de la tabla |
|
323 |
if (defaultFeatType != null) { |
|
324 |
|
|
325 |
Iterator it = defaultFeatType.iterator(); |
|
326 |
boolean some_error = false; |
|
327 |
while (it.hasNext()) { |
|
328 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) it |
|
329 |
.next(); |
|
330 |
|
|
331 |
if (!addRowToFieldTable( |
|
332 |
jTable, |
|
333 |
null, |
|
334 |
inProjection, |
|
335 |
descriptor)) { |
|
336 |
|
|
337 |
some_error = true; |
|
338 |
} |
|
339 |
/* |
|
340 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD); |
|
341 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE); |
|
342 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH); |
|
343 |
tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE); |
|
344 |
tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE); |
|
345 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS); |
|
346 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY); |
|
347 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY); |
|
348 |
*/ |
|
349 |
} |
|
350 |
|
|
351 |
if (some_error) { |
|
352 |
String tit = Messages.getText("_Default_fields"); |
|
353 |
String msg = Messages.getText("_Unable_to_add_fields"); |
|
354 |
JOptionPane.showMessageDialog( |
|
355 |
jTable, msg, tit, |
|
356 |
JOptionPane.ERROR_MESSAGE); |
|
357 |
} |
|
358 |
} |
|
359 |
|
|
360 |
} |
|
361 |
jTable.setEnabled(allowEditableFeatureType()); |
|
362 |
return jTable; |
|
363 |
} |
|
364 |
|
|
365 |
/** |
|
366 |
* This method initializes jPanelWest |
|
367 |
* |
|
368 |
* @return javax.swing.JPanel |
|
369 |
*/ |
|
370 |
private JPanel getJPanelSouth() { |
|
371 |
if (jPanelEast == null) { |
|
372 |
jPanelEast = new JPanel(); |
|
373 |
jPanelEast.setLayout(new BorderLayout()); |
|
374 |
|
|
375 |
JPanel south_east = new JPanel(new GridBagLayout()); |
|
376 |
// south_east.setPreferredSize(new java.awt.Dimension(170, 50)); |
|
377 |
GridBagConstraints c = new GridBagConstraints(); |
|
378 |
c.fill = GridBagConstraints.HORIZONTAL; |
|
379 |
c.insets = new Insets(8,10,8,0); //top padding |
|
380 |
c.gridx = 0; |
|
381 |
c.gridwidth = 1; |
|
382 |
c.gridy = 0; |
|
383 |
south_east.add(getJButtonAddField(), c); |
|
384 |
c.gridx = 1; |
|
385 |
south_east.add(getJButtonDeleteField(), c); |
|
386 |
|
|
387 |
jPanelEast.add(south_east, BorderLayout.EAST); |
|
388 |
} |
|
389 |
return jPanelEast; |
|
390 |
} |
|
391 |
|
|
392 |
/** |
|
393 |
* This method initializes jButtonAddField |
|
394 |
* |
|
395 |
* @return javax.swing.JButton |
|
396 |
*/ |
|
397 |
private JButton getJButtonAddField() { |
|
398 |
if (addFieldButton == null) { |
|
399 |
addFieldButton = new JButton(); |
|
400 |
addFieldButton.setText(Messages.getText("add_field")); |
|
401 |
addFieldButton.setLocation(new java.awt.Point(7, 5)); |
|
402 |
addFieldButton.setSize(new java.awt.Dimension(180, 23)); |
|
403 |
addFieldButton.setPreferredSize(new java.awt.Dimension(180, 23)); |
|
404 |
addFieldButton |
|
405 |
.addActionListener(new java.awt.event.ActionListener() { |
|
406 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
407 |
DefaultTableModel tm = (DefaultTableModel) jTable |
|
408 |
.getModel(); |
|
409 |
|
|
410 |
// Figure out a suitable field name |
|
411 |
ArrayList fieldNames = new ArrayList(); |
|
412 |
for (int i = 0; i < jTable.getRowCount(); i++) { |
|
413 |
fieldNames.add(tm.getValueAt(i, COLUMN_FIELD)); |
|
414 |
} |
|
415 |
String[] currentFieldNames = (String[]) fieldNames |
|
416 |
.toArray(new String[0]); |
|
417 |
String newField = Messages.getText("field") |
|
418 |
.replaceAll(" +", "_"); |
|
419 |
int index = 0; |
|
420 |
for (int i = 0; i < currentFieldNames.length; i++) { |
|
421 |
if (currentFieldNames[i].startsWith(newField)) { |
|
422 |
try { |
|
423 |
index = Integer |
|
424 |
.parseInt(currentFieldNames[i] |
|
425 |
.replaceAll(newField, |
|
426 |
"")); |
|
427 |
} catch (Exception ex) { /* we don't care */ |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
431 |
String newFieldName = newField + (++index); |
|
432 |
|
|
433 |
// Esto lo a?ado aqu? porque si no tiene registros, |
|
434 |
// no hace caso. (Por eso no |
|
435 |
// lo pongo en getJTable() |
|
436 |
if (!addRowToFieldTable( |
|
437 |
jTable, |
|
438 |
newFieldName, |
|
439 |
inProjection, |
|
440 |
null)) { |
|
441 |
|
|
442 |
String tit = Messages.getText("_Default_fields"); |
|
443 |
String msg = Messages.getText("_Unable_to_add_fields"); |
|
444 |
JOptionPane.showMessageDialog( |
|
445 |
jTable, msg, tit, |
|
446 |
JOptionPane.ERROR_MESSAGE); |
|
447 |
} |
|
448 |
} |
|
449 |
}); |
|
450 |
|
|
451 |
} |
|
452 |
addFieldButton.setEnabled(allowEditableFeatureType()); |
|
453 |
return addFieldButton; |
|
454 |
} |
|
455 |
|
|
456 |
private boolean allowEditableFeatureType(){ |
|
457 |
|
|
458 |
if (!fieldsInited) { |
|
459 |
initFields(); |
|
460 |
} |
|
461 |
|
|
462 |
DataManager dataManager = DALLocator.getDataManager(); |
|
463 |
FeatureStoreProviderFactory factory = |
|
464 |
(FeatureStoreProviderFactory) dataManager. |
|
465 |
getStoreProviderFactory(inStoreName); |
|
466 |
if (factory.allowEditableFeatureType()==FeatureStoreProviderFactory.NO) { |
|
467 |
return false; |
|
468 |
} |
|
469 |
return true; |
|
470 |
} |
|
471 |
|
|
472 |
private class ComboItemDataType { |
|
473 |
private DataType dataType; |
|
474 |
|
|
475 |
public ComboItemDataType(DataType dataType) { |
|
476 |
this.dataType = dataType; |
|
477 |
} |
|
478 |
|
|
479 |
@Override |
|
480 |
public String toString() { |
|
481 |
return this.dataType.getName(); |
|
482 |
} |
|
483 |
} |
|
484 |
|
|
485 |
private class ComboModelDataType implements ComboBoxModel { |
|
486 |
|
|
487 |
private List<ComboItemDataType> dataTypes; |
|
488 |
private ComboItemDataType selected; |
|
489 |
|
|
490 |
public ComboModelDataType(List<DataType> dataTypes, int sel_type) { |
|
491 |
|
|
492 |
this.dataTypes = new ArrayList<ComboItemDataType>(); |
|
493 |
ComboItemDataType item = null; |
|
494 |
for (Iterator iterator = dataTypes.iterator(); iterator.hasNext();) { |
|
495 |
DataType dataType = (DataType) iterator.next(); |
|
496 |
item = new ComboItemDataType(dataType); |
|
497 |
this.dataTypes.add(item); |
|
498 |
if (sel_type == dataType.getType()) { |
|
499 |
this.setSelectedItem(item); |
|
500 |
} |
|
501 |
} |
|
502 |
} |
|
503 |
|
|
504 |
public void addListDataListener(ListDataListener arg0) { |
|
505 |
// DO NOTHING |
|
506 |
} |
|
507 |
|
|
508 |
public Object getElementAt(int arg0) { |
|
509 |
return this.dataTypes.get(arg0); |
|
510 |
} |
|
511 |
|
|
512 |
public int getSize() { |
|
513 |
return this.dataTypes.size(); |
|
514 |
} |
|
515 |
|
|
516 |
public void removeListDataListener(ListDataListener arg0) { |
|
517 |
// DO NOTHING |
|
518 |
} |
|
519 |
|
|
520 |
public Object getSelectedItem() { |
|
521 |
return this.selected; |
|
522 |
} |
|
523 |
|
|
524 |
public void setSelectedItem(Object anItem) { |
|
525 |
this.selected = (ComboItemDataType) anItem; |
|
526 |
} |
|
527 |
|
|
528 |
} |
|
529 |
|
|
530 |
class CrsRenderer extends JButton implements TableCellRenderer { |
|
531 |
private static final long serialVersionUID = -573793294070515376L; |
|
532 |
private JLabel label = null; |
|
533 |
|
|
534 |
public CrsRenderer() { |
|
535 |
setOpaque(true); |
|
536 |
label = new JLabel(Messages.getText("not_applicable")); |
|
537 |
this.setMargin(new Insets(2, 0, 2, 0)); |
|
538 |
this.setFont(this.getFont().deriveFont(9f)); |
|
539 |
} |
|
540 |
|
|
541 |
public Component getTableCellRendererComponent(JTable table, |
|
542 |
Object value, boolean isSelected, boolean hasFocus, int row, |
|
543 |
int column) { |
|
544 |
|
|
545 |
ComboItemDataType item = |
|
546 |
(ComboItemDataType) table.getValueAt(row, COLUMN_TYPE); |
|
547 |
|
|
548 |
if (item == null) { |
|
549 |
// happens sometimes. perhaps an early rendering? |
|
550 |
return new JLabel(); |
|
551 |
} |
|
552 |
|
|
553 |
DataType dataType = item.dataType; |
|
554 |
|
|
555 |
if (dataType.getType() != DataTypes.GEOMETRY) { |
|
556 |
return label; |
|
557 |
} |
|
558 |
|
|
559 |
if (isSelected) { |
|
560 |
setForeground(table.getSelectionForeground()); |
|
561 |
setBackground(table.getSelectionBackground()); |
|
562 |
} else { |
|
563 |
setForeground(table.getForeground()); |
|
564 |
setBackground(UIManager.getColor("Button.background")); |
|
565 |
} |
|
566 |
setText((value == null) ? "" : ((IProjection) value).getFullCode()); |
|
567 |
return this; |
|
568 |
} |
|
569 |
} |
|
570 |
|
|
571 |
private class GeometryComboCellRenderer extends JLabel implements TableCellRenderer{ |
|
572 |
|
|
573 |
public Component getTableCellRendererComponent(JTable table, |
|
574 |
Object value, boolean isSelected, boolean hasFocus, int row, |
|
575 |
int column) { |
|
576 |
|
|
577 |
ComboItemDataType item = (ComboItemDataType) table.getValueAt(row, COLUMN_TYPE); |
|
578 |
DataType dataType = item.dataType; |
|
579 |
|
|
580 |
if (dataType.getType() == DataTypes.GEOMETRY) { |
|
581 |
ComboItemGeomType geomType = (ComboItemGeomType)value; |
|
582 |
if (geomType != null) { |
|
583 |
this.setText(geomType.toString()); |
|
584 |
} |
|
585 |
} else { |
|
586 |
this.setText(Messages.getText("not_applicable")); |
|
587 |
} |
|
588 |
|
|
589 |
return this; |
|
590 |
} |
|
591 |
|
|
592 |
} |
|
593 |
|
|
594 |
class ButtonEditor extends DefaultCellEditor { |
|
595 |
/** |
|
596 |
* |
|
597 |
*/ |
|
598 |
private static final long serialVersionUID = -2820892672026188802L; |
|
599 |
|
|
600 |
protected JButton button; |
|
601 |
|
|
602 |
private String label; |
|
603 |
|
|
604 |
private boolean isPushed; |
|
605 |
|
|
606 |
private Object value; |
|
607 |
|
|
608 |
public ButtonEditor(JCheckBox checkBox) { |
|
609 |
super(checkBox); |
|
610 |
button = new JButton(); |
|
611 |
button.setOpaque(true); |
|
612 |
button.addActionListener(new ActionListener() { |
|
613 |
public void actionPerformed(ActionEvent e) { |
|
614 |
fireEditingStopped(); |
|
615 |
} |
|
616 |
}); |
|
617 |
} |
|
618 |
|
|
619 |
public Component getTableCellEditorComponent(JTable table, |
|
620 |
Object value, boolean isSelected, int row, int column) { |
|
621 |
if (isSelected) { |
|
622 |
button.setForeground(table.getSelectionForeground()); |
|
623 |
button.setBackground(table.getSelectionBackground()); |
|
624 |
} else { |
|
625 |
button.setForeground(table.getForeground()); |
|
626 |
button.setBackground(table.getBackground()); |
|
627 |
} |
|
628 |
label = (value == null) ? "" : ((IProjection) value).getFullCode();// .toString(); |
|
629 |
button.setText(label); |
|
630 |
isPushed = true; |
|
631 |
this.value = value; |
|
632 |
return button; |
|
633 |
} |
|
634 |
|
|
635 |
public Object getCellEditorValue() { |
|
636 |
IProjection curProj = (IProjection) this.value; |
|
637 |
if (isPushed) { |
|
638 |
ISelectCrsPanel csSelect = CRSSelectPanel.getUIFactory() |
|
639 |
.getSelectCrsPanel(curProj, true); |
|
640 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
|
641 |
wm.showWindow((JPanel) csSelect, "Projection", |
|
642 |
WindowManager.MODE.DIALOG); |
|
643 |
curProj = csSelect.getProjection(); |
|
644 |
} |
|
645 |
isPushed = false; |
|
646 |
return curProj; |
|
647 |
} |
|
648 |
|
|
649 |
public boolean stopCellEditing() { |
|
650 |
isPushed = false; |
|
651 |
return super.stopCellEditing(); |
|
652 |
} |
|
653 |
|
|
654 |
protected void fireEditingStopped() { |
|
655 |
super.fireEditingStopped(); |
|
656 |
} |
|
657 |
} |
|
658 |
|
|
659 |
private class ComboItemGeomType { |
|
660 |
private int type; |
|
661 |
private String name; |
|
662 |
|
|
663 |
public ComboItemGeomType(String name, int type) { |
|
664 |
this.type = type; |
|
665 |
this.name = name; |
|
666 |
} |
|
667 |
|
|
668 |
@Override |
|
669 |
public String toString() { |
|
670 |
return this.name; |
|
671 |
} |
|
672 |
|
|
673 |
public int getGeomType() { |
|
674 |
return type; |
|
675 |
} |
|
676 |
} |
|
677 |
|
|
678 |
private class ComboModelGeomType implements ComboBoxModel { |
|
679 |
|
|
680 |
private List<ComboItemGeomType> geomTypes; |
|
681 |
private ComboItemGeomType selected; |
|
682 |
|
|
683 |
public ComboModelGeomType( |
|
684 |
List<ComboItemGeomType> geomTypes, int sel_geom_type) { |
|
685 |
|
|
686 |
this.geomTypes = geomTypes; |
|
687 |
int len = geomTypes.size(); |
|
688 |
ComboItemGeomType item = null; |
|
689 |
for (int i=0; i<len; i++) { |
|
690 |
item = geomTypes.get(i); |
|
691 |
if (item.getGeomType() == sel_geom_type) { |
|
692 |
setSelectedItem(item); |
|
693 |
} |
|
694 |
} |
|
695 |
} |
|
696 |
|
|
697 |
public void addListDataListener(ListDataListener arg0) { |
|
698 |
// DO NOTHING |
|
699 |
} |
|
700 |
|
|
701 |
public Object getElementAt(int arg0) { |
|
702 |
return this.geomTypes.get(arg0); |
|
703 |
} |
|
704 |
|
|
705 |
public int getSize() { |
|
706 |
return this.geomTypes.size(); |
|
707 |
} |
|
708 |
|
|
709 |
public void removeListDataListener(ListDataListener arg0) { |
|
710 |
// DO NOTHING |
|
711 |
} |
|
712 |
|
|
713 |
public Object getSelectedItem() { |
|
714 |
return this.selected; |
|
715 |
} |
|
716 |
|
|
717 |
public void setSelectedItem(Object anItem) { |
|
718 |
this.selected = (ComboItemGeomType) anItem; |
|
719 |
} |
|
720 |
|
|
721 |
} |
|
722 |
|
|
723 |
private List<ComboItemGeomType> getGeomTypes() { |
|
724 |
List<ComboItemGeomType> geomTypes = new ArrayList<ComboItemGeomType>(); |
|
725 |
geomTypes |
|
726 |
.add(new ComboItemGeomType("GEOMETRY", Geometry.TYPES.GEOMETRY)); |
|
727 |
geomTypes.add(new ComboItemGeomType("POINT", Geometry.TYPES.POINT)); |
|
728 |
geomTypes.add(new ComboItemGeomType("CURVE", Geometry.TYPES.CURVE)); |
|
729 |
geomTypes.add(new ComboItemGeomType("SURFACE", Geometry.TYPES.SURFACE)); |
|
730 |
geomTypes.add(new ComboItemGeomType("SOLID", Geometry.TYPES.SOLID)); |
|
731 |
geomTypes.add(new ComboItemGeomType("AGGREGATE", |
|
732 |
Geometry.TYPES.AGGREGATE)); |
|
733 |
geomTypes.add(new ComboItemGeomType("MULTIPOINT", |
|
734 |
Geometry.TYPES.MULTIPOINT)); |
|
735 |
geomTypes.add(new ComboItemGeomType("MULTICURVE", |
|
736 |
Geometry.TYPES.MULTICURVE)); |
|
737 |
geomTypes.add(new ComboItemGeomType("MULTISURFACE", |
|
738 |
Geometry.TYPES.MULTISURFACE)); |
|
739 |
geomTypes.add(new ComboItemGeomType("MULTISOLID", |
|
740 |
Geometry.TYPES.MULTISOLID)); |
|
741 |
|
|
742 |
return geomTypes; |
|
743 |
} |
|
744 |
|
|
745 |
private List<ComboItemGeomType> getGeomSubtypes() { |
|
746 |
List<ComboItemGeomType> geomSubtypes = new ArrayList<ComboItemGeomType>(); |
|
747 |
geomSubtypes.add(new ComboItemGeomType("GEOM2D", |
|
748 |
Geometry.SUBTYPES.GEOM2D)); |
|
749 |
geomSubtypes.add(new ComboItemGeomType("GEOM2DM", |
|
750 |
Geometry.SUBTYPES.GEOM2DM)); |
|
751 |
geomSubtypes.add(new ComboItemGeomType("GEOM3D", |
|
752 |
Geometry.SUBTYPES.GEOM3D)); |
|
753 |
geomSubtypes.add(new ComboItemGeomType("GEOM3DM", |
|
754 |
Geometry.SUBTYPES.GEOM3DM)); |
|
755 |
geomSubtypes.add(new ComboItemGeomType("UNKNOWN", |
|
756 |
Geometry.SUBTYPES.UNKNOWN)); |
|
757 |
return geomSubtypes; |
|
758 |
} |
|
759 |
|
|
760 |
class CheckBoxRenderer extends JCheckBox implements TableCellRenderer { |
|
761 |
|
|
762 |
/** |
|
763 |
* |
|
764 |
*/ |
|
765 |
private static final long serialVersionUID = 5093448776058027505L; |
|
766 |
|
|
767 |
public CheckBoxRenderer() { |
|
768 |
setHorizontalAlignment(JLabel.CENTER); |
|
769 |
} |
|
770 |
|
|
771 |
public Component getTableCellRendererComponent(JTable table, |
|
772 |
Object value, boolean isSelected, boolean hasFocus, int row, |
|
773 |
int column) { |
|
774 |
if (isSelected) { |
|
775 |
setForeground(table.getSelectionForeground()); |
|
776 |
setBackground(table.getSelectionBackground()); |
|
777 |
} else { |
|
778 |
setForeground(table.getForeground()); |
|
779 |
setBackground(table.getBackground()); |
|
780 |
} |
|
781 |
setSelected((value != null && ((Boolean) value).booleanValue())); |
|
782 |
return this; |
|
783 |
} |
|
784 |
} |
|
785 |
|
|
786 |
/** |
|
787 |
* This method initializes jButton |
|
788 |
* |
|
789 |
* @return javax.swing.JButton |
|
790 |
*/ |
|
791 |
private JButton getJButtonDeleteField() { |
|
792 |
if (deleteFieldButton == null) { |
|
793 |
deleteFieldButton = new JButton(); |
|
794 |
deleteFieldButton.setText(Messages.getText("delete_field")); |
|
795 |
deleteFieldButton.setLocation(new java.awt.Point(7, 33)); |
|
796 |
deleteFieldButton.setSize(new java.awt.Dimension(180, 23)); |
|
797 |
deleteFieldButton.setPreferredSize(new java.awt.Dimension(180, 23)); |
|
798 |
deleteFieldButton.setEnabled(false); |
|
799 |
deleteFieldButton |
|
800 |
.addActionListener(new java.awt.event.ActionListener() { |
|
801 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
802 |
int[] selecteds = jTable.getSelectedRows(); |
|
803 |
DefaultTableModel tm = (DefaultTableModel) jTable |
|
804 |
.getModel(); |
|
805 |
|
|
806 |
for (int i = selecteds.length - 1; i >= 0; i--) { |
|
807 |
/* |
|
808 |
* |
|
809 |
removedFields.add((String) tm.getValueAt(i, 0)); |
|
810 |
*/ |
|
811 |
tm.removeRow(selecteds[i]); |
|
812 |
} |
|
813 |
} |
|
814 |
}); |
|
815 |
} |
|
816 |
deleteFieldButton.setEnabled(false); |
|
817 |
return deleteFieldButton; |
|
818 |
} |
|
819 |
|
|
820 |
public String getPanelTitle() { |
|
821 |
return Messages.getText("_Field_definitions"); |
|
822 |
} |
|
823 |
|
|
824 |
public void nextPanel() throws NotContinueWizardException { |
|
825 |
if (allowEditableFeatureType()){ |
|
826 |
fillFeatureType(); |
|
827 |
} |
|
828 |
} |
|
829 |
|
|
830 |
private void fillFeatureType() throws NotContinueWizardException { |
|
831 |
|
|
832 |
if (!fieldsInited) { |
|
833 |
initFields(); |
|
834 |
} |
|
835 |
|
|
836 |
/* |
|
837 |
* Coge los datos del formulario y los guarda en |
|
838 |
* this.service.getFeatureType() |
|
839 |
*/ |
|
840 |
|
|
841 |
EditableFeatureType edft = newLayer_Service.getFeatureType(); |
|
842 |
|
|
843 |
// Clean and rebuild featureType everytime we click next |
|
844 |
removeAllFields(edft); |
|
845 |
edft.setDefaultGeometryAttributeName(null); |
|
846 |
|
|
847 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
|
848 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
|
849 |
|
|
850 |
for (int i = 0; i < tm.getRowCount(); i++) { |
|
851 |
DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType; |
|
852 |
|
|
853 |
int fieldLength = 20; |
|
854 |
if (dataTypeNeedsSize(dataType.getType())) { |
|
855 |
fieldLength = |
|
856 |
Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH)); |
|
857 |
} |
|
858 |
|
|
859 |
EditableFeatureAttributeDescriptor efad1 = |
|
860 |
edft.add( |
|
861 |
(String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(), |
|
862 |
fieldLength); |
|
863 |
|
|
864 |
if (dataType.getType() == DataTypes.DOUBLE || |
|
865 |
dataType.getType() == DataTypes.FLOAT) { |
|
866 |
// TODO Improve this? |
Also available in: Unified diff