Revision 45564

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/NewLayerException.java
30 30
 * may be dealt by the program or the user of the program which is a client of
31 31
 * the NewLayer API.
32 32
 * 
33
 * @see {@link NewLayerService}
34
 * @see {@link NewLayerManager}
35 33
 * @author gvSIG team.
36
 * @version $Id$
37 34
 */
38 35
public class NewLayerException extends BaseException {
39 36

  
......
71 68
    }
72 69

  
73 70
    /**
74
     * @see BaseException#BaseException(String, String, long).
75 71
     * @param message
76 72
     *            the default messageFormat to describe the exception
77 73
     * @param key
......
84 80
    }
85 81

  
86 82
    /**
87
     * @see BaseException#BaseException(String, Throwable, String, long).
88 83
     * @param message
89 84
     *            the default messageFormat to describe the exception
90 85
     * @param cause
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/NewLayerServiceException.java
28 28

  
29 29
/**
30 30
 * Exception thrown when there is an error getting a NewLayer message.
31
 * 
31
 *
32 32
 * @author gvSIG team
33 33
 * @version $Id$
34 34
 */
35 35
public class NewLayerServiceException extends ServiceException {
36

  
36 37
    /**
37
	 * 
38
	 */
39
	private static final long serialVersionUID = -4395786952326742397L;
38
     *
39
     */
40
    private static final long serialVersionUID = -4395786952326742397L;
40 41

  
41
	private static final String MESSAGE =
42
        "An error has been produced creating a store";
42
    private static final String MESSAGE
43
            = "An error has been produced creating a store";
43 44

  
44 45
    private static final String KEY = "_NewLayerServiceException";
45
    
46
	/**
47
	 * @see BaseException#BaseException(String, String, long)
48
	 */
49
	protected NewLayerServiceException(String message, String key, long code) {
50
		super(message, key, code);
51
	}
52 46

  
53
	/**
54
	 * @see BaseException#BaseException(String, Throwable, String, long)
55
	 */
56
	protected NewLayerServiceException(String message, Throwable cause, String key,
57
			long code) {
58
		super(message, cause, key, code);
59
	}
47
    /**
48
     * @param message
49
     * @param key
50
     * @param code
51
     * @see BaseException#BaseException(String, String, long)
52
     */
53
    protected NewLayerServiceException(String message, String key, long code) {
54
        super(message, key, code);
55
    }
60 56

  
61 57
    /**
62
     * Creates a new {@link NewLayerServiceException}.
63
     * 
58
     * @param message
64 59
     * @param cause
65
     *            the original cause
60
     * @param key
61
     * @param code
62
     * @see BaseException#BaseException(String, Throwable, String, long)
66 63
     */
64
    protected NewLayerServiceException(String message, Throwable cause, String key,
65
            long code) {
66
        super(message, cause, key, code);
67
    }
68

  
69
    /**
70
     * Creates a new {@link NewLayerServiceException}.
71
     *
72
     * @param cause the original cause
73
     */
67 74
    public NewLayerServiceException(Throwable cause) {
68 75
        super(MESSAGE, cause, KEY, serialVersionUID);
69 76
    }
70
    
77

  
71 78
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/NewLayerService.java
43 43
public interface NewLayerService {
44 44

  
45 45
    /**
46
     * @param type
46 47
     * @deprecated use {@link #setProviderFactory(NewLayerProviderFactory)}
47 48
     *             instead
48 49
     */
49 50
    public void setType(String type);
50 51

  
51 52
    /**
53
     * @return 
52 54
     * @deprecated use {@link #getProviderFactory()} instead
53 55
     */
54 56
    public String getType();
55 57

  
56 58
    /**
59
     * @return 
57 60
     * @deprecated use {@link #getProviderFactories()} instead
58 61
     */
59 62
    public List<String> getTypes();
......
64 67

  
65 68
    public List<NewLayerProviderFactory> getProviderFactories();
66 69
    
67
    public void createLayer() throws NewLayerServiceException;
70
    public void createTable() throws NewLayerServiceException;
68 71

  
69
	public void loadLayer() throws NewLayerServiceException;
72
    public void loadTable() throws NewLayerServiceException;
70 73

  
71
    public DataServerExplorer getExplorer();
74
    public DataServerExplorer getExplorer() throws NewLayerException;
72 75
    
73 76
    public String getStoreName();
74 77
    
75 78
    public EditableFeatureType getFeatureType();
76 79
    
77
    public NewFeatureStoreParameters getNewStoreParameters();
80
    public NewFeatureStoreParameters getNewStoreParameters() throws NewLayerException;
78 81
    
79
    public DataStoreParameters getOpenStoreParameters();
82
    public DataStoreParameters getOpenStoreParameters() throws NewLayerException;
80 83
    
84
    public NewFeatureStoreParameters getNewStoreParametersQuietly();
85
    
86
    public DataStoreParameters getOpenStoreParametersQuietly();
87
    
81 88
    public NewLayerProvider getProvider();
82 89
    
83 90
    public void addLayerToView(boolean b);
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/NewLayerWizard.java
27 27

  
28 28
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo;
29 29

  
30
public abstract class NewLayerWizard extends WizardPanelWithLogo {
30 31

  
31
public abstract class NewLayerWizard extends WizardPanelWithLogo{
32
    private static final long serialVersionUID = -9070328984844239279L;
32 33

  
33
	private static final long serialVersionUID = -9070328984844239279L;
34
    public static final int BUTTON_BACK = 0;
35
    public static final int BUTTON_NEXT = 1;
36
    public static final int BUTTON_FINISH = 2;
37
    public static final int BUTTON_CANCEL = 3;
34 38

  
35
	public NewLayerWizard(ImageIcon logo) {
36
		super(logo);
37
	}
39
    public NewLayerWizard(ImageIcon logo) {
40
        super(logo);
41
    }
38 42

  
39
	public abstract NewLayerService getService();
43
    public abstract NewLayerService getService();
40 44

  
41 45
    public abstract void setType(NewLayerProviderFactory currentType);
42 46

  
47
    public abstract NewLayerProviderPanel createFeatureTypePanel();
48
    
49
    public abstract void setButtonEnabled(int button, boolean enabled);
50

  
51
    public abstract void setButtonText(int button, String text);
52

  
53
    public abstract boolean isButtonEnabled(int button);
54

  
55
    public abstract String getButtonText(int button);
43 56
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/spi/AbstractNewLayerProviderFactory.java
31 31
import org.gvsig.tools.service.spi.Provider;
32 32
import org.gvsig.tools.service.spi.ProviderServices;
33 33

  
34
public abstract class AbstractNewLayerProviderFactory implements NewLayerProviderFactory{
34
public abstract class AbstractNewLayerProviderFactory implements NewLayerProviderFactory {
35 35

  
36
	public final Provider doCreate(DynObject parameters, ProviderServices services) {
37
		throw new UnsupportedOperationException();
38
	}
36
    public final Provider doCreate(DynObject parameters, ProviderServices services) {
37
        throw new UnsupportedOperationException();
38
    }
39 39

  
40
	public DynObject createParameters() {
41
		throw new UnsupportedOperationException();
42
	}
40
    @Override
41
    public DynObject createParameters() {
42
        throw new UnsupportedOperationException();
43
    }
43 44

  
44
	public void initialize() {
45
		throw new UnsupportedOperationException();
46
	}
45
    @Override
46
    public void initialize() {
47
        throw new UnsupportedOperationException();
48
    }
47 49

  
48
	protected DynClass createParametersDynClass() {
49
		throw new UnsupportedOperationException();
50
	}
50
    protected DynClass createParametersDynClass() {
51
        throw new UnsupportedOperationException();
52
    }
51 53

  
52
	public Provider create(DynObject parameters, ProviderServices services)
53
	throws ServiceException {
54
		throw new UnsupportedOperationException();
55
	}
54
    @Override
55
    public Provider create(DynObject parameters, ProviderServices services)
56
            throws ServiceException {
57
        throw new UnsupportedOperationException();
58
    }
56 59

  
60
    @Override
57 61
    public boolean isEnabled() {
58 62
        return NewLayerLocator.getManager().isProviderEnabled(this);
59 63
    }
60 64

  
65
    @Override
61 66
    public void setEnabled(boolean value) {
62 67
        NewLayerLocator.getManager().enableProvider(this, value);
63 68
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/spi/NewLayerPanelValidationException.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.spi;
25

  
26
import org.gvsig.newlayer.NewLayerException;
27

  
28

  
29
/**
30
 * @author gvSIG Team
31
 * @version $Id$
32
 * 
33
 */
34
public class NewLayerPanelValidationException extends NewLayerException {
35

  
36
    private static final long serialVersionUID = 236599587467526356L;
37

  
38
    private static final String MESSAGE = "The panel is not valid";
39

  
40
    private static final String KEY = "_NewLayerPanelValidationException";
41

  
42
    /**
43
     * @see BaseException#BaseException
44
     * @param message
45
     *            the default messageFormat to describe the exception
46
     * @param cause
47
     *            the original cause of the exception
48
     */
49
    public NewLayerPanelValidationException(String message, Throwable cause) {
50
        super(message, cause, KEY, serialVersionUID);
51
    }
52

  
53
    /**
54
     * @see BaseException#BaseException(String, Throwable, String, long).
55
     * @param message
56
     *            the default messageFormat to describe the exception
57
     */
58
    public NewLayerPanelValidationException(String message) {
59
        super(message, KEY, serialVersionUID);
60
    }
61

  
62
    public NewLayerPanelValidationException() {
63
        super(MESSAGE, KEY, serialVersionUID);
64
    }
65
}
0 66

  
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/spi/AbstractNewLayerProvider.java
27 27
import org.gvsig.newlayer.NewLayerProvider;
28 28
import org.gvsig.newlayer.NewLayerService;
29 29
import org.gvsig.tools.service.spi.ProviderServices;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
30 32

  
31
public abstract class AbstractNewLayerProvider implements NewLayerProvider{
33
public abstract class AbstractNewLayerProvider implements NewLayerProvider {
32 34

  
33
	private NewLayerService service;
34
	protected DataServerExplorer explorer;
35
	protected String storeName;
35
    protected static final Logger LOG = LoggerFactory.getLogger(AbstractNewLayerProvider.class);
36 36

  
37
	protected AbstractNewLayerProvider(NewLayerService service){
38
		this.service = service;
39
	}
40
	
41
	public NewLayerService getService() {
42
		return service;
43
	}
44
	
45
	public DataServerExplorer getExplorer() {
46
		return explorer;
47
	}
48
	
49
	public String getStoreName() {
50
		return storeName;
51
	}
52
	
53
	public void setProviderServices(ProviderServices services) {
54
		throw new UnsupportedOperationException();
55
	}
56
	
57
	
37
    private final NewLayerService service;
58 38

  
39
    protected AbstractNewLayerProvider(NewLayerService service) {
40
        this.service = service;
41
    }
42

  
43
    @Override
44
    public NewLayerService getService() {
45
        return service;
46
    }
47

  
48
    @Override
49
    public final void setProviderServices(ProviderServices services) {
50
        throw new UnsupportedOperationException();
51
    }
52

  
59 53
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/spi/AbstractNewLayerProviderPanel.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.spi;
25

  
26
import javax.swing.JComponent;
27
import javax.swing.JPanel;
28
import org.gvsig.newlayer.NewLayerProvider;
29
import org.gvsig.newlayer.NewLayerProviderPanel;
30

  
31
public abstract class AbstractNewLayerProviderPanel extends JPanel implements NewLayerProviderPanel {
32

  
33
    protected NewLayerProvider provider;
34

  
35
    protected AbstractNewLayerProviderPanel(NewLayerProvider provider) {
36
        this.provider = provider;
37
    }
38

  
39
    @Override
40
    public JComponent asJComponent() {
41
        return this;
42
    }
43

  
44
    @Override
45
    public void nextPanel() {
46
    }
47

  
48
    @Override
49
    public void previousPanel() {
50

  
51
    }
52

  
53
    @Override
54
    public String getIdPanel() {
55
        return this.getClass().getCanonicalName();
56
    }
57

  
58
}
0 59

  
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/NewLayerManager.java
45 45

  
46 46
    /**
47 47
     * Create an instance of a {@link NewLayerService}.
48
     * @param mapContext
48 49
     * @return {@link NewLayerService}
49
     * @throws ServiceException
50
     *             if there is an error getting the service
51 50
     */
52 51
    public NewLayerService createNewLayerService(MapContext mapContext);
53 52
    
......
62 61
    /**
63 62
     * Returns the provider factory with the given name.
64 63
     * 
65
     * @param name
66
     *            of the provider
64
     * @param providerName
67 65
     * @return the provider factory
68 66
     * @throws ServiceException
69 67
     *             if there is an error getting the provider factory
......
76 74
     * 
77 75
     * @param factory
78 76
     *            of the provider to enable or disable
79
     * @param value
80
     *            if the provider must be enabled or disabled
77
     * @param false1
81 78
     */
82 79
    public void enableProvider(NewLayerProviderFactory factory, Boolean false1);
83 80

  
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/NewLayerProvider.java
35 35
	
36 36
	public NewLayerService getService();
37 37
	
38
	public DataServerExplorer getExplorer();
38
	public DataServerExplorer getExplorer() throws NewLayerException;
39 39
	
40 40
	public String getStoreName();
41 41

  
42 42
	public EditableFeatureType getFeatureType();
43 43
	
44
	public NewFeatureStoreParameters getNewStoreParameters();
44
	public NewFeatureStoreParameters getNewStoreParameters() throws NewLayerException;
45 45
	
46
	public DataStoreParameters getOpenStoreParameters();
46
	public DataStoreParameters getOpenStoreParameters() throws NewLayerException;
47 47

  
48
	public List<NewLayerProviderPanel> getPanels();
48
	public List<NewLayerProviderPanel> createPanels(NewLayerWizard wizard);
49 49
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.api/src/main/java/org/gvsig/newlayer/NewLayerProviderPanel.java
1
/**
1
/*
2 2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6 6
 * This program is free software; you can redistribute it and/or
7 7
 * modify it under the terms of the GNU General Public License
8 8
 * as published by the Free Software Foundation; either version 3
9 9
 * of the License, or (at your option) any later version.
10
 *
10
 * 
11 11
 * This program is distributed in the hope that it will be useful,
12 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 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
 *
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
21 19
 * For any additional information, do not hesitate to contact us
22 20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23 21
 */
24 22
package org.gvsig.newlayer;
25 23

  
26
import javax.swing.JPanel;
24
import org.gvsig.newlayer.spi.NewLayerPanelValidationException;
25
import org.gvsig.tools.swing.api.Component;
27 26

  
27
/**
28
 *
29
 * @author gvSIG Team
30
 */
31
public interface NewLayerProviderPanel extends Component {
28 32

  
29
public abstract class NewLayerProviderPanel extends JPanel{
30 33

  
34
    public String getIdPanel();
35
    
36
    public String getTitlePanel();
31 37

  
32
	protected NewLayerProvider provider;
38
    /**
39
     * Este metodo se llamo para comprobar si los datos del panel son coherentes
40
     * y se pueden aceptar.
41
     * Se invoca antes de invocar al metodo "nextPanel".
42
     * Devolvera false en caso de que no se deba abandonar el panel, normalmente
43
     * por que los datos no estan completos. En caso de que se desee presentar un
44
     * mensaje al usuario se podra lanzar la excecion NewLayerPanelValidationException
45
     * indicando en ella el mensaje.
46
     * 
47
     * @return true si va todo bien, false si no se debe abandonar el panel.
48
     * @throws NewLayerPanelValidationException 
49
     */
50
    public boolean validatePanel() throws NewLayerPanelValidationException;
51
    
52
    /**
53
     * Este metodo se llama cada vez que se va a presenta un panel al usuario,
54
     * indistintamente si llego a el por ir hacia delante o hacia atras.
55
     */
56
    public void enterPanel();
33 57

  
34
	protected NewLayerProviderPanel(NewLayerProvider provider){
35
		this.provider = provider;
36
	}
37

  
38
	public abstract String getTitle();
39
	
40
	public abstract boolean isValidPanel() throws NewLayerException;
41
	
42
	public abstract void updatePanel();
43
	
44
	
45
	
58
    /**
59
     * Este metodo se llama sobre el panel que abandona el usuario cuando
60
     * pulsa en el boton "siguiente".
61
     */
62
    public void nextPanel();
63
    
64
    /**
65
     * Este metodo se llama sobre el panel que abandona el usuario cuando pulsa
66
     * en el boton "anterior".
67
     */
68
    public void previousPanel();
69
    
46 70
}
trunk/org.gvsig.desktop/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.add(new ComboItemGeomType("GEOMETRY", Geometry.TYPES.GEOMETRY));
726
		geomTypes.add(new ComboItemGeomType("POINT", Geometry.TYPES.POINT));
727
		geomTypes.add(new ComboItemGeomType("LINE", Geometry.TYPES.LINE));
728
		geomTypes.add(new ComboItemGeomType("POLYGON", Geometry.TYPES.POLYGON));
729
		geomTypes.add(new ComboItemGeomType("SOLID", Geometry.TYPES.SOLID));
730
		geomTypes.add(new ComboItemGeomType("AGGREGATE", Geometry.TYPES.AGGREGATE));
731
		geomTypes.add(new ComboItemGeomType("MULTIPOINT", Geometry.TYPES.MULTIPOINT));
732
		geomTypes.add(new ComboItemGeomType("MULTILINE", Geometry.TYPES.MULTILINE));
733
		geomTypes.add(new ComboItemGeomType("MULTIPOLYGON", Geometry.TYPES.MULTIPOLYGON));
734
		geomTypes.add(new ComboItemGeomType("MULTISOLID", Geometry.TYPES.MULTISOLID));
735

  
736
		return geomTypes;
737
	}
738

  
739
	private List<ComboItemGeomType> getGeomSubtypes() {
740
		List<ComboItemGeomType> geomSubtypes = new ArrayList<ComboItemGeomType>();
741
		geomSubtypes.add(new ComboItemGeomType("GEOM2D",
742
				Geometry.SUBTYPES.GEOM2D));
743
		geomSubtypes.add(new ComboItemGeomType("GEOM2DM",
744
				Geometry.SUBTYPES.GEOM2DM));
745
		geomSubtypes.add(new ComboItemGeomType("GEOM3D",
746
				Geometry.SUBTYPES.GEOM3D));
747
		geomSubtypes.add(new ComboItemGeomType("GEOM3DM",
748
				Geometry.SUBTYPES.GEOM3DM));
749
		geomSubtypes.add(new ComboItemGeomType("UNKNOWN",
750
				Geometry.SUBTYPES.UNKNOWN));
751
		return geomSubtypes;
752
	}
753

  
754
	class CheckBoxRenderer extends JCheckBox implements TableCellRenderer {
755

  
756
		/**
757
		 * 
758
		 */
759
		private static final long serialVersionUID = 5093448776058027505L;
760

  
761
		public CheckBoxRenderer() {
762
			setHorizontalAlignment(JLabel.CENTER);
763
		}
764

  
765
		public Component getTableCellRendererComponent(JTable table,
766
				Object value, boolean isSelected, boolean hasFocus, int row,
767
				int column) {
768
			if (isSelected) {
769
				setForeground(table.getSelectionForeground());
770
				setBackground(table.getSelectionBackground());
771
			} else {
772
				setForeground(table.getForeground());
773
				setBackground(table.getBackground());
774
			}
775
			setSelected((value != null && ((Boolean) value).booleanValue()));
776
			return this;
777
		}
778
	}
779

  
780
	/**
781
	 * This method initializes jButton
782
	 * 
783
	 * @return javax.swing.JButton
784
	 */
785
	private JButton getJButtonDeleteField() {
786
		if (deleteFieldButton == null) {
787
		    deleteFieldButton = new JButton();
788
		    deleteFieldButton.setText(Messages.getText("delete_field"));
789
		    deleteFieldButton.setLocation(new java.awt.Point(7, 33));
790
		    deleteFieldButton.setSize(new java.awt.Dimension(180, 23));
791
		    deleteFieldButton.setPreferredSize(new java.awt.Dimension(180, 23));
792
		    deleteFieldButton.setEnabled(false);
793
		    deleteFieldButton
794
					.addActionListener(new java.awt.event.ActionListener() {
795
						public void actionPerformed(java.awt.event.ActionEvent e) {
796
							int[] selecteds = jTable.getSelectedRows();
797
							DefaultTableModel tm = (DefaultTableModel) jTable
798
									.getModel();
799

  
800
							for (int i = selecteds.length - 1; i >= 0; i--) {
801
							    /*
802
							     * 
803
								removedFields.add((String) tm.getValueAt(i, 0));
804
                                 */
805
								tm.removeRow(selecteds[i]);
806
							}
807
						}
808
					});
809
		}
810
		deleteFieldButton.setEnabled(false);
811
		return deleteFieldButton;
812
	}
813

  
814
	public String getPanelTitle() {
815
		return Messages.getText("_Field_definitions");
816
	}
817

  
818
	public void nextPanel() throws NotContinueWizardException {
819
		if (allowEditableFeatureType()){
820
			fillFeatureType();
821
		}
822
	}
823

  
824
	private void fillFeatureType() throws NotContinueWizardException {
825
	    
826
	    if (!fieldsInited) {
827
	        initFields();
828
	    }
829

  
830
		/*
831
		 * Coge los datos del formulario y los guarda en
832
		 * this.service.getFeatureType()
833
		 */
834

  
835
	    EditableFeatureType edft = newLayer_Service.getFeatureType();
836

  
837
		// Clean and rebuild featureType everytime we click next
838
		removeAllFields(edft);
839
		edft.setDefaultGeometryAttributeName(null);
840

  
841
		GeometryManager gm = GeometryLocator.getGeometryManager();
842
		DefaultTableModel tm = (DefaultTableModel) jTable.getModel();
843
		
844
		for (int i = 0; i < tm.getRowCount(); i++) {
845
			DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType;
846

  
847
			int fieldLength = 20;
848
			if (dataTypeNeedsSize(dataType.getType())) {
849
	            fieldLength = 
850
	                Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH));
851
			}
852

  
853
			EditableFeatureAttributeDescriptor efad1 =
854
			    edft.add(
855
					(String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(),
856
					fieldLength);
857

  
858
			if (dataType.getType() == DataTypes.DOUBLE ||
859
			    dataType.getType() == DataTypes.FLOAT) {
860
			    // TODO Improve this?
861
			    // Half of the size dedicated
862
			    // to precision (at least 1) 
863
              efad1.setPrecision(fieldLength);
864
	            efad1.setScale(Math.max(1, fieldLength/2));
865
			}
866

  
867
			if (dataType.getType() == DataTypes.GEOMETRY) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff