Revision 47552

View differences:

tags/org.gvsig.desktop-2.0.436/license.txt
1
gvSIG. Desktop Geographic Information System.
2

  
3
Copyright (C) 2007-2023 gvSIG Association.
4

  
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 3
8
of the License, or (at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

  
15
 You should have received a copy of the GNU General Public License 
16
along with this program. If not, see <https://www.gnu.org/licenses/>. 
17

  
18
For any additional information, do not hesitate to contact us
19
at info AT gvsig.com, or visit our website www.gvsig.com.
tags/org.gvsig.desktop-2.0.436/org.gvsig.desktop.library/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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">
3

  
4
    <modelVersion>4.0.0</modelVersion>
5
    <artifactId>org.gvsig.desktop.library</artifactId>
6
    <packaging>pom</packaging>
7
    <name>${project.artifactId}</name>
8
    <description>This project group all librerias in the core of gvSIG that not havent java compatibility with JVM CDC.</description>
9
    <parent>
10
        <groupId>org.gvsig</groupId>
11
        <artifactId>org.gvsig.desktop</artifactId>
12
        <version>2.0.436</version>
13
    </parent>
14

  
15
    <modules>
16
        <module>org.gvsig.utils</module>
17
        <module>org.gvsig.annotation</module>
18
        <module>org.gvsig.exportto</module>
19
        <module>org.gvsig.fmap.control</module>
20
        <module>org.gvsig.ui</module>
21
        <module>org.gvsig.installer</module>
22
        <module>org.gvsig.newlayer</module>
23
        <module>org.gvsig.symbology</module>
24
        <module>org.gvsig.tools.evaluator.sqljep</module>
25
        <module>org.gvsig.about</module>
26
        <module>org.gvsig.timesupport</module>
27
        <module>org.gvsig.expressionevaluator</module>
28
        <module>org.gvsig.temporarystorage</module>
29
        
30
        <module>org.gvsig.raster</module>
31
        <module>org.gvsig.raster.legend</module>
32
        <module>org.gvsig.fmap.mapcontext.swing</module>
33
        <module>org.gvsig.raster.tools</module>
34
      </modules>
35
</project>
0 36

  
tags/org.gvsig.desktop-2.0.436/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.436</version>
13
  </parent>
14

  
15
  <dependencies>
16
    <dependency>
17
      <groupId>org.gvsig</groupId>
18
      <artifactId>org.gvsig.tools.lib</artifactId>
19
    </dependency>
20
    <dependency>
21
      <groupId>org.gvsig</groupId>
22
      <artifactId>org.gvsig.tools.lib</artifactId>
23
      <type>test-jar</type>
24
      <scope>test</scope>
25
    </dependency>  
26
  </dependencies>
27
  
28
  <modules>
29
    <module>org.gvsig.newlayer.lib</module>
30
    <module>org.gvsig.newlayer.prov</module>
31
  </modules>
32
</project>
0 33

  
tags/org.gvsig.desktop-2.0.436/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.436/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.436/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/preferences/DefaultNewLayerPreferencesComponent.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.preferences;
25

  
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.Insets;
29
import java.util.ArrayList;
30
import java.util.HashSet;
31
import java.util.List;
32
import java.util.Set;
33

  
34
import javax.swing.JCheckBox;
35
import javax.swing.JComponent;
36
import javax.swing.JPanel;
37
import javax.swing.event.ChangeEvent;
38
import javax.swing.event.ChangeListener;
39

  
40
import org.gvsig.newlayer.NewLayerLocator;
41
import org.gvsig.newlayer.NewLayerProviderFactory;
42
import org.gvsig.newlayer.preferences.NewLayerPreferencesComponent;
43

  
44
/**
45
 * Default implementation for the {@link NewLayerPreferencesComponent}.
46
 * 
47
 * @author gvSIG Team
48
 * @version $Id$
49
 */
50
public class DefaultNewLayerPreferencesComponent extends JPanel implements
51
    NewLayerPreferencesComponent, ChangeListener {
52

  
53
    private static final long serialVersionUID = -4392838062470171181L;
54

  
55
    private JCheckBox[] providerChecks;
56
    private List<NewLayerProviderFactory> providers;
57
    private boolean valueChanged = false;
58

  
59
    /**
60
     * Creates a new DefaultNewLayerPreferencesComponent.
61
     * 
62
     * @see JPanel#JPanel()
63
     */
64
    public DefaultNewLayerPreferencesComponent() {
65
        this(true);
66
    }
67

  
68
    /**
69
     * Creates a new DefaultNewLayerPreferencesComponent.
70
     * 
71
     * @param isDoubleBuffered
72
     *            a boolean, true for double-buffering, which
73
     *            uses additional memory space to achieve fast, flicker-free
74
     *            updates
75
     * @see JPanel#JPanel(boolean)
76
     */
77
    public DefaultNewLayerPreferencesComponent(boolean isDoubleBuffered) {
78
        super(isDoubleBuffered);
79
        initialize();
80
    }
81

  
82
    private void initialize() {
83
        this.setLayout(new GridBagLayout());
84

  
85
        Insets insets = new Insets(1, 0, 1, 0);
86

  
87
        GridBagConstraints gbc = new GridBagConstraints();
88
        gbc.gridx = 0;
89
        gbc.gridy = 1;
90
        gbc.gridheight = 1;
91
        gbc.gridwidth = GridBagConstraints.REMAINDER;
92
        gbc.fill = GridBagConstraints.NONE;
93
        gbc.anchor = GridBagConstraints.WEST;
94
        gbc.weightx = 1.0f;
95
        gbc.insets = insets;
96

  
97
        providers =
98
            new ArrayList<NewLayerProviderFactory>(NewLayerLocator.getManager()
99
                .getProviders());
100
        providerChecks = new JCheckBox[providers.size()];
101
        for (int i = 0; i < providers.size(); i++) {
102
            NewLayerProviderFactory factory = providers.get(i);
103
            providerChecks[i] =
104
                new JCheckBox(factory.getLabel(), factory.isEnabled());
105
            providerChecks[i].addChangeListener(this);
106
            providerChecks[i].setToolTipText(factory.getDescription());
107
            add(providerChecks[i], gbc);
108
            gbc.gridy++;
109
        }
110
    }
111

  
112
    public JComponent asJComponent() {
113
        return this;
114
    }
115

  
116
    public void initializeDefaults() {
117
        for (int i = 0; i < providers.size(); i++) {
118
            NewLayerProviderFactory factory = providers.get(i);
119
            providerChecks[i].setSelected(factory.isEnabled());
120
        }
121
        valueChanged = false;
122
        validate();
123
    }
124

  
125
    public Set<NewLayerProviderFactory> getDisabledProviders() {
126
        Set<NewLayerProviderFactory> disabledFactories =
127
            new HashSet<NewLayerProviderFactory>();
128

  
129
        for (int i = 0; i < providerChecks.length; i++) {
130
            if (!providerChecks[i].isSelected()) {
131
                disabledFactories.add(providers.get(i));
132
            }
133
        }
134

  
135
        return disabledFactories;
136
    }
137

  
138
    public boolean isValueChanged() {
139
        return valueChanged;
140
    }
141

  
142
    public void setChangesApplied() {
143
        valueChanged = false;
144
    }
145

  
146
    public void stateChanged(ChangeEvent e) {
147
        valueChanged = true;
148
    }
149
}
0 150

  
tags/org.gvsig.desktop-2.0.436/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/NewLayerDefaultImplLibrary.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.Locale;
27

  
28
import org.gvsig.i18n.Messages;
29
import org.gvsig.newlayer.NewLayerLibrary;
30
import org.gvsig.newlayer.NewLayerLocator;
31
import org.gvsig.tools.library.AbstractLibrary;
32
import org.gvsig.tools.library.LibraryException;
33

  
34
/**
35
 * Library for default implementation initialization and configuration.
36
 * 
37
 * @author gvSIG team
38
 * @version $Id$
39
 */
40
public class NewLayerDefaultImplLibrary extends AbstractLibrary {
41
    
42
    @Override
43
    public void doRegistration() {
44
        registerAsImplementationOf(NewLayerLibrary.class);
45
    }
46

  
47
    @Override
48
    protected void doInitialize() throws LibraryException {
49
        NewLayerLocator.registerManager(DefaultNewLayerManager.class);
50
        if (!Messages.hasLocales()) {
51
            Messages.addLocale(Locale.getDefault());
52
        }
53
        Messages.addResourceFamily("org.gvsig.newlayer.lib.impl.i18n.text",
54
            NewLayerDefaultImplLibrary.class.getClassLoader(),
55
            NewLayerDefaultImplLibrary.class.getClass().getName());
56
    }
57

  
58
    @Override
59
    protected void doPostInitialize() throws LibraryException {
60
        // Do nothing
61
    }
62

  
63
}
0 64

  
tags/org.gvsig.desktop-2.0.436/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/TypeSelectorPanel.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.DefaultListSelectionModel;
29
import javax.swing.JList;
30
import javax.swing.JPanel;
31
import javax.swing.JScrollPane;
32
import javax.swing.ListModel;
33
import javax.swing.event.ListSelectionEvent;
34
import javax.swing.event.ListSelectionListener;
35

  
36
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
37
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
38
import org.gvsig.i18n.Messages;
39
import org.gvsig.newlayer.NewLayerProviderFactory;
40
import org.gvsig.newlayer.NewLayerService;
41
import org.gvsig.newlayer.NewLayerWizard;
42

  
43
public class TypeSelectorPanel extends JPanel implements OptionPanel{
44
	
45
	/**
46
	 * 
47
	 */
48
	private static final long serialVersionUID = 419873365484240927L;
49
	private NewLayerWizard wizard;
50
    private NewLayerProviderFactory currentType;
51

  
52
	public TypeSelectorPanel(NewLayerWizard wizard){
53
		this.wizard = wizard;
54
		initializeComponents();
55
	}
56

  
57
	public String getPanelTitle() {
58
		return Messages.getText("_Output_format");
59
	}
60

  
61
	public void nextPanel() throws NotContinueWizardException {
62
		if (currentType!=null){
63
			this.wizard.setType(currentType);
64
			return;
65
		}
66
		throw new NotContinueWizardException("", null, false);
67
	}
68

  
69
	public void lastPanel() {
70
		// do nothing
71
		
72
	}
73

  
74
	public void updatePanel() {
75
		initializeComponents();
76
	}
77

  
78
	public JPanel getJPanel() {
79
		return this;
80
	}
81

  
82
    private void initializeComponents() {
83
        this.setLayout(new BorderLayout());
84

  
85
        JList types = new JList();     
86
        ListModel model =
87
            new org.gvsig.utils.DefaultListModel(this.getService()
88
                .getProviderFactories());
89
       
90
        types.setModel(model);
91
        types.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
92
        
93
        types.addListSelectionListener(new ListSelectionListener() {
94
			public void valueChanged(ListSelectionEvent e) {
95
				if (e.getValueIsAdjusting() == false) {
96
					JList list = (JList) e.getSource();
97
					
98
			        if (list.getSelectedIndex() > -1) {
99
                        currentType =
100
                            (NewLayerProviderFactory) list.getSelectedValue();
101
                        
102
                        wizard.setNextButtonEnabled(true);
103
			        } else {
104
			            wizard.setNextButtonEnabled(false);
105
			        }
106
			    }
107
			}
108
		});
109
        
110
        JScrollPane scrollPane = new JScrollPane();
111
        scrollPane.setViewportView(types);
112
        this.add(scrollPane, BorderLayout.CENTER);        
113
    }
114

  
115
	private NewLayerService getService() {
116
		return this.wizard.getService();
117
	} 
118
}
0 119

  
tags/org.gvsig.desktop-2.0.436/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/panels/FeatureTypePanel.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 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, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22

  
23
package org.gvsig.newlayer.impl.panels;
24

  
25
import javax.swing.JComponent;
26
import javax.swing.JOptionPane;
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.feature.EditableFeatureType;
30
import org.gvsig.fmap.dal.swing.DALSwingLocator;
31
import org.gvsig.fmap.dal.swing.DataSwingManager;
32
import static org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel.MODE_EDIT_ALL;
33
import org.gvsig.newlayer.NewLayerProvider;
34
import org.gvsig.newlayer.NewLayerProviderPanel;
35
import org.gvsig.newlayer.NewLayerWizard;
36
import org.gvsig.newlayer.spi.NewLayerPanelValidationException;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.i18n.I18nManager;
39
import org.gvsig.tools.swing.api.ToolsSwingLocator;
40
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
41

  
42
/**
43
 *
44
 * @author gvSIG Team
45
 */
46
public class FeatureTypePanel implements NewLayerProviderPanel {
47

  
48
    private final NewLayerProvider provider;
49
    private final NewLayerWizard wizard;
50
    private org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel featureTypeEditor;
51

  
52
    public FeatureTypePanel(NewLayerWizard wizard, NewLayerProvider provider) {
53
        this.provider = provider;
54
        this.wizard = wizard;
55
        initComponents();
56
    }
57

  
58
    private void initComponents() {
59
        DataManager dataManager = DALLocator.getDataManager();
60
        DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager();
61
        EditableFeatureType ft = dataManager.createFeatureType();
62
        this.featureTypeEditor = dataSwingManager.createFeatureTypePanel();
63
        this.featureTypeEditor.setDefaultProjection(this.wizard.getService().getDefaultProjection());
64
        this.featureTypeEditor.setMode(MODE_EDIT_ALL);
65
        this.featureTypeEditor.put(ft);
66
    }
67

  
68
    @Override
69
    public void previousPanel() {
70
        EditableFeatureType ft = this.provider.getFeatureType();
71
        this.featureTypeEditor.fetch(ft);
72
    }
73

  
74
    @Override
75
    public void enterPanel() {
76
        this.featureTypeEditor.setDefaultProjection(this.wizard.getService().getDefaultProjection());
77
        EditableFeatureType ft = this.provider.getFeatureType();
78
        if (ft!= null) {
79
            this.featureTypeEditor.put(ft);
80
        }
81
    }
82

  
83
    @Override
84
    public String getIdPanel() {
85
        return this.getClass().getCanonicalName();
86
    }
87

  
88
    @Override
89
    public String getTitlePanel() {
90
        I18nManager i18n = ToolsLocator.getI18nManager();
91
        return i18n.getTranslation("_Columns_definition");
92
    }
93

  
94
    @Override
95
    public void nextPanel() {
96
        EditableFeatureType ft = this.provider.getFeatureType();
97
        this.featureTypeEditor.fetch(ft);
98
    }
99

  
100
    @Override
101
    public boolean validatePanel() throws NewLayerPanelValidationException {
102
        try { 
103
            if( this.featureTypeEditor.isEditing()) {
104
                ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
105
                I18nManager i18n = ToolsLocator.getI18nManager();
106
                dialogs.messageDialog(
107
                        i18n.getTranslation("_Accept_o_discard_the_attribute_changes_to_continue"), 
108
                        i18n.getTranslation("_Columns_definition"), 
109
                        JOptionPane.INFORMATION_MESSAGE
110
                );
111
                return false;
112
            }
113
            EditableFeatureType ft = this.provider.getFeatureType();
114
            this.featureTypeEditor.fetch(ft);
115
            if( ft.size()==0 ) {
116
                return false;
117
            }
118
            return true;
119
        } catch (Exception ex) {
120
            return false;
121
        }
122
    }
123

  
124
    @Override
125
    public JComponent asJComponent() {
126
        return this.featureTypeEditor.asJComponent();
127
    }
128

  
129
}
tags/org.gvsig.desktop-2.0.436/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() {
75
        return new DefaultNewLayerService(this);
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.436/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.newlayer.NewLayerService;
34
import org.gvsig.newlayer.NewLayerWizard;
35

  
36
public class AddNewLayerQuestionPanel extends JPanel implements OptionPanel {
37

  
38
    private static final long serialVersionUID = -5251910576017225307L;
39
    private final NewLayerWizard wizard;
40
    private JCheckBox questionCheckBox = null;
41
    private final String title;
42
    private final String label;
43

  
44
    public AddNewLayerQuestionPanel(NewLayerWizard wizard, String title, String label) {
45
        this.wizard = wizard;
46
        this.title = title;
47
        this.label = label;
48
        initializeComponents();
49
    }
50

  
51
    @Override
52
    public String getPanelTitle() {
53
        return this.title;
54
    }
55

  
56
    @Override
57
    public void nextPanel() throws NotContinueWizardException {
58
        getService().setAddTableToProject(getAddTableToProject());
59
    }
60

  
61
    @Override
62
    public void lastPanel() {
63
        // do nothing
64

  
65
    }
66

  
67
    @Override
68
    public void updatePanel() {
69
        initializeComponents();
70
    }
71

  
72
    @Override
73
    public JPanel getJPanel() {
74
        return this;
75
    }
76

  
77
    private void initializeComponents() {
78
        this.setLayout(new BorderLayout());
79
        this.add(getQuestionCheckBox(), BorderLayout.NORTH);
80
    }
81

  
82
    private JCheckBox getQuestionCheckBox() {
83
        if (this.questionCheckBox == null) {
84
            this.questionCheckBox = new JCheckBox(this.label, true);
85
        }
86
        return this.questionCheckBox;
87
    }
88

  
89
    private NewLayerService getService() {
90
        return this.wizard.getService();
91
    }
92

  
93
    public boolean getAddTableToProject() {
94
        return getQuestionCheckBox().isSelected();
95
    }
96
}
0 97

  
tags/org.gvsig.desktop-2.0.436/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.LinkedHashSet;
29
import java.util.List;
30
import java.util.Set;
31
import org.cresques.cts.IProjection;
32

  
33
import org.gvsig.fmap.dal.DataServerExplorer;
34
import org.gvsig.fmap.dal.DataStoreParameters;
35
import org.gvsig.fmap.dal.feature.EditableFeatureType;
36
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
37
import org.gvsig.newlayer.NewLayerException;
38
import org.gvsig.newlayer.NewLayerManager;
39
import org.gvsig.newlayer.NewLayerProvider;
40
import org.gvsig.newlayer.NewLayerProviderFactory;
41
import org.gvsig.newlayer.NewLayerService;
42
import org.gvsig.newlayer.NewLayerServiceException;
43
import org.gvsig.tools.service.ServiceException;
44

  
45
/**
46
 * Default {@link NewLayerService} implementation.
47
 *
48
 * @author gvSIG Team
49
 */
50
@SuppressWarnings("UseSpecificCatch")
51
public class DefaultNewLayerService implements NewLayerService {
52

  
53
    private final NewLayerManager newLayerManager;
54
    private NewLayerProviderFactory type;
55
    private NewLayerProvider provider;
56
    private boolean addTableToProject = true;
57
    private IProjection defaultProjection;
58

  
59
    /**
60
     * {@link DefaultNewLayerService} constructor
61
     * @param manager
62
     */
63
    public DefaultNewLayerService(NewLayerManager manager) {
64
        this.newLayerManager = manager;
65
    }
66

  
67
    @Override
68
    public NewLayerProvider getProvider() {
69
        return provider;
70
    }
71

  
72
    @Override
73
    public void createTable() throws NewLayerServiceException {
74
        try {
75
            this.getExplorer().add(
76
                    this.getStoreProviderName(),
77
                    this.getNewStoreParameters(), 
78
                    true
79
            );
80
            firePostCreateTable();
81
        } catch (Exception e) {
82
            throw new CantCreateNewLayerException(e);
83
        }
84
    }
85

  
86
//    @Override
87
//    public void loadTable() throws NewLayerServiceException {
88
//        try {
89
//            if( this.getFeatureType().getDefaultGeometryAttribute()==null ) {
90
//                return;
91
//            }
92
//            String providerName = this.getStoreProviderName();
93
//            DataStoreParameters storeParameters = this.getOpenStoreParameters();
94
//            DataManager dataManager = DALLocator.getDataManager();
95
//            DataStore store = dataManager.openStore(providerName, storeParameters);
96
//            String layerName = store.getName();
97
//
98
//                MapContextManager mapContextManager = MapContextLocator.getMapContextManager();
99
//                FLayer lyr = mapContextManager.createLayer(layerName, store);
100
//                lyr.setActive(true);
101
//                lyr.setVisible(true);
102
//                mapContext.getLayers().addLayer(lyr);
103
//
104
//                lyr.dispose();
105
//        } catch (DataException | ValidateDataParametersException e) {
106
//            throw new CantOpenStoreException(e);
107
//        } catch (LoadLayerException e) {
108
//            throw new CantLoadNewLayerException(e);
109
//        } catch (Exception e) {
110
//            throw new NewLayerServiceException(e);
111
//        }
112
//
113
//    }
114

  
115
    public class CantCreateNewLayerException extends NewLayerServiceException {
116

  
117
        /**
118
         *
119
         */
120
        private static final long serialVersionUID = 4208215791054246118L;
121

  
122
        public CantCreateNewLayerException(Throwable cause) {
123
            super("Can't create the layer", cause, "_cant_create_the_layer",
124
                    serialVersionUID);
125
        }
126
    }
127

  
128
    public class CantOpenStoreException extends NewLayerServiceException {
129

  
130
        /**
131
         *
132
         */
133
        private static final long serialVersionUID = -2245228621032918630L;
134

  
135
        public CantOpenStoreException(Throwable cause) {
136
            super("Can't open store", cause, "_cant_open_store",
137
                    serialVersionUID);
138
        }
139
    }
140

  
141
    public class CantLoadNewLayerException extends NewLayerServiceException {
142

  
143
        /**
144
         *
145
         */
146
        private static final long serialVersionUID = -1711950651766745963L;
147

  
148
        public CantLoadNewLayerException(Throwable cause) {
149
            super("Can't load the new layer", cause,
150
                    "_cant_load_the_new_layer", serialVersionUID);
151
        }
152
    }
153

  
154
    @Override
155
    public void setType(String type) {
156
        try {
157
            setProviderFactory(this.newLayerManager.getNewLayerProviderFactory(type));
158
        } catch (ServiceException e) {
159
            throw new RuntimeException(e);
160
        }
161
    }
162

  
163
    @Override
164
    public DataServerExplorer getExplorer() throws NewLayerException {
165
        return getProvider().getExplorer();
166
    }
167

  
168
    @Override
169
    public String getStoreProviderName() {
170
        return getProvider().getStoreName();
171
    }
172

  
173
    @Override
174
    public EditableFeatureType getFeatureType() {
175
        return getProvider().getFeatureType();
176
    }
177

  
178
    @Override
179
    public NewFeatureStoreParameters getNewStoreParameters() throws NewLayerException {
180
        return getProvider().getNewStoreParameters();
181
    }
182

  
183
    @Override
184
    public DataStoreParameters getOpenStoreParameters() throws NewLayerException {
185
        return getProvider().getOpenStoreParameters();
186
    }
187

  
188
    @Override
189
    public NewFeatureStoreParameters getNewStoreParametersQuietly() {
190
        try {
191
            return getProvider().getNewStoreParameters();
192
        } catch(Exception ex) {   
193
            return null;
194
        }
195
    }
196

  
197
    @Override
198
    public DataStoreParameters getOpenStoreParametersQuietly() {
199
        try {
200
            return getProvider().getOpenStoreParameters();
201
        } catch(Exception ex) {
202
            return null;
203
        }
204
    }
205

  
206
    @Override
207
    public List<String> getTypes() {
208
        List<String> types = new ArrayList<>();
209
        List<NewLayerProviderFactory> providers = getProviderFactories();
210
        Iterator<NewLayerProviderFactory> it = providers.iterator();
211
        while (it.hasNext()) {
212
            NewLayerProviderFactory newLayerProviderFactory = it.next();
213
            types.add(newLayerProviderFactory.getName());
214
        }
215
        return types;
216
    }
217

  
218
    @Override
219
    public String getType() {
220
        return this.type.getName();
221
    }
222

  
223
    @Override
224
    public void setAddTableToProject(boolean b) {
225
        this.addTableToProject = b;
226
    }
227

  
228
    @Override
229
    public boolean isAddTableToProject() {
230
        return this.addTableToProject;
231
    }
232

  
233
    @Override
234
    public void setProviderFactory(NewLayerProviderFactory type) {
235
        this.type = type;
236
        this.provider = type.create(this);
237
    }
238

  
239
    @Override
240
    public NewLayerProviderFactory getProviderFactory() {
241
        return type;
242
    }
243

  
244
    @Override
245
    public List<NewLayerProviderFactory> getProviderFactories() {
246

  
247
        List<NewLayerProviderFactory> providers = new ArrayList<>(
248
                this.newLayerManager.getProviders(NewLayerManager.STORETYPE.ANY)
249
        );
250
        for (Iterator<NewLayerProviderFactory> iterator = providers.iterator(); iterator.hasNext();) {
251
            NewLayerProviderFactory newLayerProviderFactory = iterator.next();
252
            if (!newLayerProviderFactory.isEnabled()) {
253
                iterator.remove();
254
            }
255
        }
256
        return providers;
257
    }
258

  
259
    private Set<NewLayerServiceListener> listeners = null;
260
    
261
    @Override
262
    public void addNewLayerServiceListener(NewLayerServiceListener listener) {
263
        if( listener == null ) {
264
            return;
265
        }
266
        if( this.listeners==null ) {
267
            this.listeners = new LinkedHashSet<>();
268
        }
269
        this.listeners.add(listener);
270
    }
271

  
272
    protected void firePostCreateTable() {
273
        if( this.listeners==null ) {
274
            return;
275
        }
276
        for (NewLayerServiceListener listener : this.listeners) {
277
            if( listener==null ) {
278
                continue;
279
            }
280
            try {
281
                listener.postCreateTable(this);
282
            } catch(Throwable t) {
283
                // Do nothing.
284
            }
285
        }
286
    }
287

  
288
    @Override
289
    public void setDefaultProjection(IProjection projection) {
290
        this.defaultProjection = projection;
291
    }
292

  
293
    @Override
294
    public IProjection getDefaultProjection() {
295
        return this.defaultProjection;
296
    }
297
    
298
    
299
}
0 300

  
tags/org.gvsig.desktop-2.0.436/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.JButton;
32
import javax.swing.JOptionPane;
33
import javax.swing.JPanel;
34

  
35
import jwizardcomponent.CancelAction;
36
import jwizardcomponent.DefaultJWizardComponents;
37
import jwizardcomponent.FinishAction;
38
import jwizardcomponent.JWizardComponents;
39

  
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

  
43
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
44
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
45
import org.gvsig.i18n.Messages;
46
import org.gvsig.newlayer.NewLayerException;
47
import org.gvsig.newlayer.NewLayerProviderFactory;
48
import org.gvsig.newlayer.NewLayerProviderPanel;
49
import org.gvsig.newlayer.NewLayerService;
50
import org.gvsig.newlayer.NewLayerServiceException;
51
import org.gvsig.newlayer.NewLayerWizard;
52
import org.gvsig.newlayer.impl.panels.FeatureTypePanel;
53
import org.gvsig.tools.swing.api.ToolsSwingUtils;
54

  
55
public class DefaultNewLayerWizard extends NewLayerWizard {
56

  
57
    /**
58
     *
59
     */
60
    private static final long serialVersionUID = -5827106636136663823L;
61
    private final NewLayerService service;
62
    private AddNewLayerQuestionPanel addNewLayerQuestionPanel;
63
    private static final Logger LOG
64
            = LoggerFactory.getLogger(DefaultNewLayerWizard.class);
65
    private String addTableToProjectTitle;
66
    private String addTableToProjectLabel;
67

  
68
    @SuppressWarnings("OverridableMethodCallInConstructor")
69
    public DefaultNewLayerWizard(ImageIcon logo, NewLayerService service) {
70
        super(logo);
71
        
72
        this.service = service;
73
        this.getWizardComponents().setFinishAction(
74
                new MyFinishAction(this.getWizardComponents()));
75
        this.getWizardComponents().setCancelAction(
76
                new MyCancelAction(this.getWizardComponents()));
77
        this.createTypeSelector();
78

  
79
        // ================ disable at the start
80
        this.setFinishButtonEnabled(false);
81
        this.setBackButtonEnabled(false);
82
        this.setNextButtonEnabled(false);
83
//        ToolsSwingUtils.ensureRowsCols(this, 25, 100, 35, 140);
84
        
85
        Dimension screensize = ToolsSwingUtils.getDesktopPanelSize();
86
        ToolsSwingUtils.ensureHeightWitdh(
87
                this, 
88
                Math.max(3*(screensize.height/4), ToolsSwingUtils.rows2px(35)),
89
                Math.max(2*(screensize.width/4), ToolsSwingUtils.cols2px(140)), 
90
                7*(screensize.height/8), 
91
                3*(screensize.width/4)
92
        );           
93
    }
94

  
95
    @Override
96
    public NewLayerService getService() {
97
        return this.service;
98
    }
99

  
100
    private void createTypeSelector() {
101

  
102
        TypeSelectorPanel panel = new TypeSelectorPanel(this);
103
        this.addOptionPanel(panel);
104

  
105
    }
106

  
107
    @Override
108
    public NewLayerProviderPanel createFeatureTypePanel() {
109
        FeatureTypePanel panel = new FeatureTypePanel(this, service.getProvider());
110
        return panel;
111
    }
112

  
113
    private void createProviderPanels() {
114
        DefaultJWizardComponents wizardComponents = this.getWizardComponents();
115
        for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) {
116
            wizardComponents.removeWizardPanel(i);
117
        }
118
        List<NewLayerProviderPanel> panels = service.getProvider().createPanels(this);
119
        Iterator<NewLayerProviderPanel> it = panels.iterator();
120
        while (it.hasNext()) {
121
            NewLayerProviderPanel panel = it.next();
122
            this.addOptionPanel(new OptionPanelWrapper(panel));
123
        }
124
        this.createAddNewLayerQuestionPanel();
125
    }
126

  
127
    private AddNewLayerQuestionPanel getAddNewLayerQuestionPanel() {
128
        if (this.addNewLayerQuestionPanel == null) {
129
            this.addNewLayerQuestionPanel = new AddNewLayerQuestionPanel(this, this.addTableToProjectTitle, this.addTableToProjectLabel);
130
        }
131
        return this.addNewLayerQuestionPanel;
132
    }
133

  
134
    private void createAddNewLayerQuestionPanel() {
135
        this.addOptionPanel(getAddNewLayerQuestionPanel());
136
    }
137

  
138
    private boolean getAddLayerToView() {
139
        return getAddNewLayerQuestionPanel().getAddTableToProject();
140
    }
141

  
142
    @Override
143
    public void setType(NewLayerProviderFactory currentType) {
144
        this.service.setProviderFactory(currentType);
145
        createProviderPanels();
146
    }
147

  
148
    private class OptionPanelWrapper implements OptionPanel {
149

  
150
        private final NewLayerProviderPanel panel;
151

  
152
        public OptionPanelWrapper(NewLayerProviderPanel panel) {
153
            this.panel = panel;
154
        }
155

  
156
        @Override
157
        public String getPanelTitle() {
158
            return this.panel.getTitlePanel();
159
        }
160

  
161
        @Override
162
        public void nextPanel() throws NotContinueWizardException {
163

  
164
            try {
165
                if (!this.panel.validatePanel()) {
166
                    throw new NotContinueWizardException("Error validating the form", panel.asJComponent(), false);
167
                }
168
            } catch (NewLayerException e) {
169
                LOG.info("Error validating the form", e);
170
                throw new NotContinueWizardException("Error validating the form", e, panel.asJComponent());
171
            }
172
        }
173

  
174
        @Override
175
        public void lastPanel() {
176
        }
177

  
178
        @Override
179
        public void updatePanel() {
180
            this.panel.enterPanel();
181
        }
182

  
183
        @Override
184
        public JPanel getJPanel() {
185
            return (JPanel) this.panel.asJComponent();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff