Revision 41844

View differences:

tags/org.gvsig.desktop-2.0.69/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.69</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
    </dependency>  
25
  </dependencies>
26
  
27
  <modules>
28
    <module>org.gvsig.newlayer.lib</module>
29
    <module>org.gvsig.newlayer.prov</module>
30
  </modules>
31
</project>
0 32

  
tags/org.gvsig.desktop-2.0.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" output="target/classes" path="src/main/java">
4
		<attributes>
5
			<attribute name="optional" value="true"/>
6
			<attribute name="maven.pomderived" value="true"/>
7
		</attributes>
8
	</classpathentry>
9
	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10
		<attributes>
11
			<attribute name="maven.pomderived" value="true"/>
12
		</attributes>
13
	</classpathentry>
14
	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15
		<attributes>
16
			<attribute name="optional" value="true"/>
17
			<attribute name="maven.pomderived" value="true"/>
18
		</attributes>
19
	</classpathentry>
20
	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21
		<attributes>
22
			<attribute name="maven.pomderived" value="true"/>
23
		</attributes>
24
	</classpathentry>
25
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
26
		<attributes>
27
			<attribute name="maven.pomderived" value="true"/>
28
		</attributes>
29
	</classpathentry>
30
	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
31
		<attributes>
32
			<attribute name="maven.pomderived" value="true"/>
33
		</attributes>
34
	</classpathentry>
35
	<classpathentry kind="output" path="target/classes"/>
36
</classpath>
0 37

  
tags/org.gvsig.desktop-2.0.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.gvsig.newlayer.lib.impl</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.m2e.core.maven2Builder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
	</buildSpec>
19
	<natures>
20
		<nature>org.eclipse.jdt.core.javanature</nature>
21
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
22
	</natures>
23
</projectDescription>
0 24

  
tags/org.gvsig.desktop-2.0.69/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.69/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.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/resources/org/gvsig/newlayer/lib/impl/i18n/text.properties
1
cant_create_new_layer=No se puede crear la nueva capa
2
new_layers_parameters_missing=No se puede crear una nueva capa.\nFaltan los par?metros.\nVuelva atr?s e introd?zcalos.
3
new_layer_not_store_name=No se puede crear la nueva capa.\nEl nombre del store no existe.\nVuelva atr?s e introd?zcalo.
4
not_applicable=No aplicable
5
_Invalid_geometry_type=Tipo de geometr?a no v?lido
6
_Add_layer_to_view=A?adir capa a la vista
7
_Field_definitions=Definiciones de campos
8
_Output_format=Formato de salida
9
_Adding_layer=A?adir capa
10
_Name=Nombre
11
_Geometry_type=Tipo geom.
12
_Dimensions=Dimensiones
13
_Primary_key=Clave primaria
14
_Mandatory=Obligatorio
15
_Mandatory_(short_text)=Oblig.
16

  
17

  
0 18

  
tags/org.gvsig.desktop-2.0.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/resources/org/gvsig/newlayer/lib/impl/i18n/text_en.properties
1
cant_create_new_layer=Can't create the new layer
2
new_layer_parameters_missing=Can't create a new layer.\n The store paremeters are missing.\n Go back and enter it, please.
3
new_layer_not_store_name=Can't create a new layer.\n The store name is missing.\n Go back and enter it, please.
4
not_applicable=Not applicable
5
_Invalid_geometry_type=Invalid geometry type
6
_Add_layer_to_view=Add layer to view
7
_Field_definitions=Field definitions
8
_Output_format=Output format
9
_Adding_layer=Adding layer
10
_Name=Name
11
_Geometry_type=Geom. type
12
_Dimensions=Dimensions
13
_Primary_key=Primary key
14
_Mandatory=Mandatory
15
_Mandatory_(short_text)=Mand.
16

  
0 17

  
tags/org.gvsig.desktop-2.0.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/resources/org/gvsig/newlayer/lib/impl/newlayerfilters.properties
1
#point_geometries_only=
2
#curve_geometries_only=
3
#surface_geometries_only=
4
prov_demo=PROV < '10'
0 5

  
tags/org.gvsig.desktop-2.0.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.newlayer.impl.NewLayerDefaultImplLibrary
tags/org.gvsig.desktop-2.0.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/DefaultNewLayerManager.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.net.URL;
27
import java.util.ArrayList;
28
import java.util.HashMap;
29
import java.util.Iterator;
30
import java.util.List;
31
import java.util.Map;
32

  
33
import javax.swing.ImageIcon;
34

  
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

  
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.newlayer.NewLayerManager;
40
import org.gvsig.newlayer.NewLayerProviderFactory;
41
import org.gvsig.newlayer.NewLayerService;
42
import org.gvsig.newlayer.NewLayerWizard;
43
import org.gvsig.newlayer.impl.preferences.DefaultNewLayerPreferencesComponent;
44
import org.gvsig.newlayer.preferences.NewLayerPreferencesComponent;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.extensionpoint.ExtensionPoint;
47
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
48
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
49
import org.gvsig.tools.service.ServiceException;
50

  
51
/**
52
 * Default {@link NewLayerManager} implementation.
53
 * 
54
 * @author gvSIG Team
55
 * @version $Id$
56
 */
57
public class DefaultNewLayerManager implements NewLayerManager {
58

  
59
    private static final Logger LOG = LoggerFactory
60
        .getLogger(DefaultNewLayerManager.class);
61

  
62
    final static private String EP_NEWLAYER_NAME = "NewLayer.manager.providers";
63
    final static private String EP_NEWLAYER_DESCRIPTION = "NewLayer providers";
64

  
65
    private Map<NewLayerProviderFactory, Boolean> providerStatus;
66

  
67
    /**
68
     * Empty constructor.
69
     */
70
    public DefaultNewLayerManager() {
71
        providerStatus = new HashMap<NewLayerProviderFactory, Boolean>();
72
    }
73

  
74
    public NewLayerService createNewLayerService(MapContext mapContext) {
75
        return new DefaultNewLayerService(this, mapContext);
76
    }
77

  
78
    public void registerProvider(NewLayerProviderFactory factory) {
79
        ExtensionPoint ep = getNewLayerProvidersExtensionPoint();
80
        ep.append(factory.getName(), factory.getDescription(), factory);
81
    }
82

  
83
    public NewLayerWizard createNewLayerWizard(NewLayerService service) {
84
        
85
        URL iconURL =
86
            getClass().getClassLoader().getResource(
87
                "org/gvsig/newlayer/lib/impl/images/panel/view-new-layer-illustration.png");
88
        ImageIcon logo = null;
89
        if (iconURL != null) {
90
            logo = new ImageIcon(iconURL);
91
        }
92

  
93
        return new DefaultNewLayerWizard(logo, service);
94
    }
95

  
96
    public NewLayerProviderFactory getNewLayerProviderFactory(
97
        String providerName) throws ServiceException {
98
        ExtensionPoint ep = getNewLayerProvidersExtensionPoint();
99
        try {
100
            return (NewLayerProviderFactory) ep.create(providerName);
101
        } catch (InstantiationException e) {
102
            throw new RuntimeException(e);
103
        } catch (IllegalAccessException e) {
104
            throw new RuntimeException(e);
105
        }
106
    }
107

  
108
    public void enableProvider(NewLayerProviderFactory factory, Boolean value) {
109
        providerStatus.put(factory, Boolean.valueOf(value));
110
    }
111

  
112
    public NewLayerPreferencesComponent createNewLayerProvidersPreferences() {
113
        return new DefaultNewLayerPreferencesComponent();
114
    }
115

  
116
    public List<NewLayerProviderFactory> getProviders() {
117
        ExtensionPoint ep = getNewLayerProvidersExtensionPoint();
118
        List<NewLayerProviderFactory> providers =
119
            new ArrayList<NewLayerProviderFactory>();
120
        @SuppressWarnings("unchecked")
121
        Iterator<Extension> it = ep.iterator();
122

  
123
        while (it.hasNext()) {
124
            Extension extension = (Extension) it.next();
125
            NewLayerProviderFactory factory;
126
            try {
127
                factory = (NewLayerProviderFactory) extension.create();
128
            } catch (InstantiationException e) {
129
                LOG.warn(
130
                    "Can't create NewLayerProviderFactory "
131
                        + extension.getName(), e);
132
                continue;
133
            } catch (IllegalAccessException e) {
134
                LOG.warn(
135
                    "Can't create NewLayerProviderFactory "
136
                        + extension.getName(), e);
137
                continue;
138
            }
139
            providers.add(factory);
140
        }
141

  
142
        return providers;
143
    }
144

  
145
    private ExtensionPoint getNewLayerProvidersExtensionPoint() {
146
        ExtensionPointManager epmgr = ToolsLocator.getExtensionPointManager();
147
        return
148
            epmgr.add(EP_NEWLAYER_NAME, EP_NEWLAYER_DESCRIPTION);
149
    }
150

  
151
    public List<NewLayerProviderFactory> getProviders(STORETYPE filter) {
152
        // TODO use filters
153
        // if (filter == STORETYPE.TABULAR){
154
        // if (!factory.isSpatial()){
155
        // providers.add(factory);
156
        // }
157
        // } else {
158
        // }
159
        return getProviders();
160
    }
161

  
162
    public boolean isProviderEnabled(NewLayerProviderFactory factory) {
163
        Boolean status = providerStatus.get(factory);
164
        return status == null ? true : status.booleanValue();
165
    }
166

  
167
}
0 168

  
tags/org.gvsig.desktop-2.0.69/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/AddNewLayerQuestionPanel.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

  
28
import javax.swing.JCheckBox;
29
import javax.swing.JPanel;
30

  
31
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
32
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
33
import org.gvsig.i18n.Messages;
34
import org.gvsig.newlayer.NewLayerService;
35
import org.gvsig.newlayer.NewLayerWizard;
36

  
37
public class AddNewLayerQuestionPanel extends JPanel implements OptionPanel{
38
	
39
    private static final long serialVersionUID = -5251910576017225307L;
40
    private NewLayerWizard wizard;
41
	private JCheckBox questionCheckBox = null;
42
	
43
	public AddNewLayerQuestionPanel(NewLayerWizard wizard){
44
		this.wizard = wizard;
45
		initializeComponents();
46
	}
47

  
48
	public String getPanelTitle() {
49
		return Messages.getText("_Adding_layer");
50
	}
51

  
52
	public void nextPanel() throws NotContinueWizardException {
53
		getService().addLayerToView(getAddLayerToView());
54
	}
55

  
56
	public void lastPanel() {
57
		// do nothing
58
		
59
	}
60

  
61
	public void updatePanel() {
62
		initializeComponents();
63
	}
64

  
65
	public JPanel getJPanel() {
66
		return this;
67
	}
68

  
69
    private void initializeComponents() {
70
        this.setLayout(new BorderLayout());
71
        this.add(getQuestionCheckBox(), BorderLayout.NORTH);        
72
    }
73
    
74
    private JCheckBox getQuestionCheckBox(){
75
    	if (this.questionCheckBox == null){
76
    		this.questionCheckBox = new JCheckBox(
77
    		    Messages.getText("_Add_layer_to_view"), true);
78
    	}
79
    	return this.questionCheckBox;
80
    }
81

  
82
	private NewLayerService getService() {
83
		return this.wizard.getService();
84
	} 
85
	
86
	public boolean getAddLayerToView(){
87
		return getQuestionCheckBox().isSelected();
88
	}
89
}
0 90

  
tags/org.gvsig.desktop-2.0.69/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.69/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.69/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(145, 23));
403
		    addFieldButton.setPreferredSize(new java.awt.Dimension(100, 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)) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff