Revision 1947

View differences:

org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingSwingManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
package org.gvsig.vectorediting.swing.api;
26

  
27
import java.awt.Component;
28
import java.util.List;
29

  
30
import org.gvsig.fmap.mapcontrol.MapControl;
31
import org.gvsig.tools.service.Manager;
32
import org.gvsig.utils.console.ResponseListener;
33
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
34
import org.gvsig.vectorediting.swing.api.console.EditingConsole;
35
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener;
36
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu;
37

  
38
/**
39
 * @author gvSIG team.
40
 */
41
public interface EditingSwingManager extends Manager {
42

  
43
    /**
44
     * @param mapControl
45
     * @return
46
     */
47
    EditingContext getEditingContext(MapControl mapControl);
48

  
49
    /**
50
     *
51
     * @param mapControl
52
     */
53
    public void registerEditingContext(MapControl mapControl);
54

  
55
    /**
56
     *
57
     * @param layerName
58
     * @return
59
     */
60
    int showPanelExportOrDiscard(MapControl parent, String layerName);
61

  
62
    /**
63
     *
64
     * @param layerName
65
     * @return
66
     */
67
    int showPanelSaveOrDiscard(MapControl parent, String layerName);
68

  
69
    /**
70
     * Gets an instance of current parameter contextual menu. To show it, invoke
71
     * {@link EditingContextMenu#show(java.awt.Component, int, int)}.
72
     *
73
     * @param parent
74
     *            of contextual menu
75
     * @param parameter
76
     *            to build contextual menu according to it types.
77
     * @return contextual menu of parameter
78
     */
79
    EditingContextMenu getContextualMenu(Component parent,
80
        AcceptValueListener listener, EditingServiceParameter parameter);
81

  
82
    /**
83
     * Gets and instance of {@link EditingConsole}.
84
     * The response listener will receive the response typed
85
     * by user when ENTER key is pressed.
86
     * 
87
     * @param listener
88
     *            Object that will received the response
89
     * @return An instance of {@link EditingConsole}
90
     */
91
    EditingConsole getEditingConsole(ResponseListener listener);
92

  
93
    /**
94
     * Gets and instance of {@link EditingConsole}.
95
     * Response listener list will receive the response
96
     * typed by user when ENTER key is pressed.
97
     * 
98
     * @param listener
99
     *            Object that will received the response
100
     * @return An instance of {@link EditingConsole}
101
     */
102
    EditingConsole getEditingConsole(List<ResponseListener> liteners);
103
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingContext.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
package org.gvsig.vectorediting.swing.api;
26

  
27
import java.lang.ref.WeakReference;
28

  
29
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
30
import org.gvsig.fmap.mapcontrol.MapControl;
31
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
32
import org.gvsig.tools.observer.Observable;
33

  
34
public interface EditingContext extends Observable {
35

  
36
    static final int CANCEL = 0;
37
    static final int DISCARD_CHANGES = 1;
38
    static final int EXPORT_LAYER = 2;
39
    static final int SAVE_CHANGES = 3;
40
    static final String DEFAULT_TOOL = "default_tool";
41

  
42
    static final String CHANGE_SELECTED_TOOL_NOTIFICATION = "EditingContext.changeSelectedTool";
43
    static final String REFRESH_TOOLS_NOTIFICATION = "EditingContext.refreshTools";
44
    static final String EXPORT_LAYER_NOTIFICATION = "EditingContext.exportLayer";
45
    /**
46
     * Activates service as of name and {@link MapControl}
47
     *
48
     * @param name
49
     *            of service
50
     * @param mapControl
51
     *            of
52
     */
53
    public void activateService(String name);
54

  
55
    /**
56
      * @deprecated Use {@link EditingContext#beginEdition(FLyrVect)}
57
     */
58
    public void beginEdition(FLyrVect layer, Behavior[] additionalBehaviors);
59
    
60
    /**
61
     * Begins edition of a layer
62
     *
63
     * @param layer
64
     *            to begin edition
65
     */
66
    public void beginEdition(FLyrVect layer);
67

  
68
    /**
69
     * Ends edition of a layer 
70
     *
71
     * @param layer
72
     *            to end edition
73
     */
74
    public void endEdition(FLyrVect layer);
75

  
76
    /**
77
     * Gets mapControl object. It is referenced by {@link WeakReference}.
78
     *
79
     * @return
80
     */
81
    public MapControl getMapControl();
82

  
83
    /**
84
     *
85
     * @param name
86
     * @return
87
     */
88
    public boolean isServiceCompatible(String name);
89

  
90
    /**
91
     * Updates the weak reference at editing context.
92
     *
93
     * @param mapControl
94
     */
95
    public void setMapControl(MapControl mapControl);
96

  
97

  
98
    public Behavior[] getDefaultBehaviors();
99

  
100
    public void setDefaultBehaviors(Behavior[] defaultBehaviors);
101
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/contextmenu/EditingContextMenu.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
package org.gvsig.vectorediting.swing.api.contextmenu;
26

  
27
import java.awt.Component;
28

  
29
/**
30
 * @author llmarques
31
 *
32
 */
33
public interface EditingContextMenu {
34

  
35
    /**
36
     * @param mapControl
37
     * @param x
38
     * @param y
39
     */
40
    public void show(Component mapControl, int x, int y);
41

  
42
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/contextmenu/AcceptValueListener.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
/* gvSIG. Desktop Geographic Information System.
26
 *
27
 * Copyright ? 2007-2014 gvSIG Association
28
 *
29
 * This program is free software; you can redistribute it and/or
30
 * modify it under the terms of the GNU General Public License
31
 * as published by the Free Software Foundation; either version 2
32
 * of the License, or (at your option) any later version.
33
 *
34
 * This program is distributed in the hope that it will be useful,
35
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
 * GNU General Public License for more details.
38
 *
39
 * You should have received a copy of the GNU General Public License
40
 * along with this program; if not, write to the Free Software
41
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
 * MA  02110-1301, USA.
43
 *
44
 * For any additional information, do not hesitate to contact us
45
 * at info AT gvsig.com, or visit our website www.gvsig.com.
46
 */
47
package org.gvsig.vectorediting.swing.api.contextmenu;
48

  
49
/**
50
 * @author llmarques
51
 *
52
 */
53
public interface AcceptValueListener {
54

  
55
    public void acceptValue(Object value);
56

  
57
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingSwingLocator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
package org.gvsig.vectorediting.swing.api;
26

  
27
import org.gvsig.tools.locator.BaseLocator;
28
import org.gvsig.tools.locator.Locator;
29
import org.gvsig.tools.locator.LocatorException;
30

  
31
public class EditingSwingLocator extends BaseLocator {
32

  
33
    private static final String LOCATOR_NAME = "EditingSwingLocator";
34

  
35
    public static final String MANAGER_NAME = "VectorEditingSwing.manager";
36

  
37
    private static final String MANAGER_DESCRIPTION =
38
        "Editing Swing Manager of gvSIG";
39

  
40
    private static final EditingSwingLocator instance =
41
        new EditingSwingLocator();
42

  
43
    private EditingSwingLocator() {
44

  
45
    }
46

  
47
    /**
48
     * Return the singleton instance.
49
     *
50
     * @return the singleton instance
51
     */
52
    public static EditingSwingLocator getInstance() {
53
        return instance;
54
    }
55

  
56
    @Override
57
    public String getLocatorName() {
58
        return LOCATOR_NAME;
59
    }
60

  
61
    /**
62
     * Return a reference to EditingSwingManager.
63
     *
64
     * @return a reference to EditingSwingManager
65
     * @throws LocatorException
66
     *             if there is no access to the class or the class
67
     *             cannot be instantiated
68
     * @see Locator#get(String)
69
     */
70
    public static EditingSwingManager getSwingManager() throws LocatorException {
71
        return (EditingSwingManager) getInstance().get(MANAGER_NAME);
72
    }
73

  
74
    /**
75
     * Registers the Class implementing the EditingSwingLocator interface.
76
     *
77
     * @param clazz
78
     *            implementing the EeditingSwingManager interface
79
     */
80
    public static void registerManager(Class clazz) {
81
        getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
82
    }
83

  
84
    public static void registerDefaultManager(Class clazz) {
85
        getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
86
    }
87

  
88
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingSwingLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
package org.gvsig.vectorediting.swing.api;
26

  
27
import org.gvsig.fmap.dal.DALLibrary;
28
import org.gvsig.fmap.geom.GeometryLibrary;
29
import org.gvsig.tools.library.AbstractLibrary;
30
import org.gvsig.tools.library.LibraryException;
31
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
32

  
33
public class EditingSwingLibrary extends AbstractLibrary {
34

  
35
    @Override
36
    public void doRegistration() {
37
        registerAsAPI(EditingSwingLibrary.class);
38
        require(DALLibrary.class);
39
        require(GeometryLibrary.class);
40
    }
41

  
42
    @Override
43
    protected void doInitialize() throws LibraryException {
44
        // TODO Auto-generated method stub
45

  
46
    }
47

  
48
    @Override
49
    protected void doPostInitialize() throws LibraryException {
50
        EditingSwingManager manager = EditingSwingLocator.getSwingManager();
51
        if (manager == null) {
52
            throw new ReferenceNotRegisteredException(
53
                EditingSwingLocator.MANAGER_NAME,
54
                EditingSwingLocator.getInstance());
55
        }
56

  
57
    }
58

  
59
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/console/EditingConsole.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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 2
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

  
25
package org.gvsig.vectorediting.swing.api.console;
26

  
27
import org.gvsig.utils.console.ResponseListener;
28

  
29

  
30
/**
31
 * 
32
 * @author llmarques
33
 *
34
 */
35
public interface EditingConsole {
36
    
37
    /**
38
     * Gets response text typed by user
39
     * 
40
     * @return
41
     */
42
    public String getResponseText();
43
    
44
    /**
45
     * Clears console
46
     */
47
    public void clear();
48
    
49
    /**
50
     * Adds text to console
51
     * 
52
     * @param text
53
     */
54
    public void addText(String text);
55
    
56
    /**
57
     * Add text that is taken like text typed by user
58
     * 
59
     * @param responseText
60
     */
61
    public void addResponseText(String responseText);
62
    
63
    /**
64
     * Adds the listener
65
     * 
66
     * @param listener
67
     */
68
    public void addResponseListener(ResponseListener listener);
69
    
70
    /**
71
     * Removes the listener
72
     * 
73
     * @param listener
74
     */
75
    public void removeResponseListener(ResponseListener listener);
76
    
77
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.vectorediting.swing.api.EditingSwingLibrary
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
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/maven-v4_0_0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.vectorediting.swing.api</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.vectorediting.swing.api</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.vectorediting.swing</artifactId>
10
		<version>1.0.111</version>
11
	</parent>
12
	<build>
13
		<plugins>
14
			<plugin>
15
				<groupId>org.apache.maven.plugins</groupId>
16
				<artifactId>maven-jar-plugin</artifactId>
17
				<configuration>
18
				</configuration>
19
				<executions>
20
					<!-- Generates a jar file only with the test classes -->
21
					<execution>
22
						<goals>
23
							<goal>test-jar</goal>
24
						</goals>
25
					</execution>
26
				</executions>
27
			</plugin>
28
		</plugins>
29
	</build>
30
	<dependencies>
31
		<dependency>
32
			<groupId>org.gvsig</groupId>
33
			<artifactId>org.gvsig.vectorediting.lib.api</artifactId>
34
		</dependency>
35
	</dependencies>
36
</project>
0 37

  
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
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.vectorediting.swing</artifactId>
6
	<packaging>pom</packaging>
7
	<name>org.gvsig.vectorediting.swing</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.vectorediting</artifactId>
11
		<version>1.0.111</version>
12
	</parent>
13

  
14

  
15
	<modules>
16
		<module>org.gvsig.vectorediting.swing.api</module>
17
		<module>org.gvsig.vectorediting.swing.impl</module>
18
	</modules>
19
</project>
20

  
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/test/resources/README.txt
1
====
2
    gvSIG. Desktop Geographic Information System.
3

  
4
    Copyright (C) 2007-2012 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 2
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

  
25
Put into this folder the resources needed by your test classes.
26

  
27
This folder is added to the Tests classpath, so you can load any resources 
28
through the ClassLoader.
29

  
30
By default, in this folder you can find an example of log4j configuration,
31
prepared to log messages through the console, so logging works when you
32
run your tests classes.
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.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-2012 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 2
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.vectorediting">
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>
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.vectorediting.swing.impl.DefaultEditingSwingLibrary
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingSwingManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
package org.gvsig.vectorediting.swing.impl;
26

  
27
import java.awt.BorderLayout;
28
import java.awt.Component;
29
import java.awt.Font;
30
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
32
import java.awt.Insets;
33
import java.util.List;
34
import java.util.Map;
35
import java.util.WeakHashMap;
36

  
37
import javax.swing.JLabel;
38
import javax.swing.JOptionPane;
39
import javax.swing.JPanel;
40

  
41
import org.gvsig.fmap.mapcontext.MapContext;
42
import org.gvsig.fmap.mapcontrol.MapControl;
43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dynobject.DynObject;
45
import org.gvsig.tools.i18n.I18nManager;
46
import org.gvsig.tools.service.AbstractManager;
47
import org.gvsig.tools.service.Service;
48
import org.gvsig.tools.service.ServiceException;
49
import org.gvsig.utils.console.ResponseListener;
50
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
51
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator;
52
import org.gvsig.vectorediting.swing.api.EditingContext;
53
import org.gvsig.vectorediting.swing.api.EditingSwingManager;
54
import org.gvsig.vectorediting.swing.api.console.EditingConsole;
55
import org.gvsig.vectorediting.swing.api.contextmenu.AcceptValueListener;
56
import org.gvsig.vectorediting.swing.api.contextmenu.EditingContextMenu;
57
import org.gvsig.vectorediting.swing.impl.console.DefaultEditingConsole;
58
import org.gvsig.vectorediting.swing.impl.contextmenu.DefaultEditingContextMenu;
59

  
60
public class DefaultEditingSwingManager extends AbstractManager implements
61
EditingSwingManager {
62

  
63
    Map<MapContext, EditingContext> editingContexts =
64
        new WeakHashMap<MapContext, EditingContext>();
65

  
66
    public DefaultEditingSwingManager() {
67
        super(EditingProviderLocator.getProviderManager());
68
    }
69

  
70
    public EditingContext getEditingContext(MapControl mapControl) {
71
        MapContext mapContext = mapControl.getMapContext();
72

  
73
        if (editingContexts.containsKey(mapContext)) {
74
            EditingContext editingContext = editingContexts.get(mapContext);
75

  
76
            if (editingContext.getMapControl() != null) {
77
                return editingContext;
78
            } else {
79
                editingContexts.remove(mapContext);
80
            }
81

  
82
        }
83
        return null;
84
    }
85

  
86
    private JPanel getExplanationPanel(String question, String action,
87
        String description) {
88

  
89
        I18nManager i18nManager = ToolsLocator.getI18nManager();
90

  
91
        JPanel resp = new JPanel(new BorderLayout(10, 10));
92

  
93
        JLabel topLabel = new JLabel(question);
94

  
95
        JPanel mainPanel = new JPanel(new GridBagLayout());
96
        GridBagConstraints cc = new GridBagConstraints();
97

  
98
        cc.gridx = 0;
99
        cc.gridy = 0;
100
        cc.anchor = GridBagConstraints.WEST;
101

  
102
        cc.insets = new Insets(3, 6, 3, 6);
103

  
104
        Font boldf = mainPanel.getFont().deriveFont(Font.BOLD);
105

  
106
        JLabel lbl = new JLabel(action);
107
        lbl.setFont(boldf);
108
        mainPanel.add(lbl, cc);
109
        cc.gridx = 1;
110
        mainPanel.add(new JLabel(description), cc);
111

  
112
        cc.gridx = 0;
113
        cc.gridy = 1;
114
        lbl = new JLabel(i18nManager.getTranslation("discard"));
115
        lbl.setFont(boldf);
116
        mainPanel.add(lbl, cc);
117
        cc.gridx = 1;
118
        mainPanel
119
        .add(
120
            new JLabel(i18nManager
121
                .getTranslation("discard_and_loose_changes")), cc);
122

  
123
        cc.gridx = 0;
124
        cc.gridy = 2;
125
        lbl = new JLabel(i18nManager.getTranslation("continue"));
126
        lbl.setFont(boldf);
127
        mainPanel.add(lbl, cc);
128
        cc.gridx = 1;
129
        mainPanel.add(
130
            new JLabel(i18nManager
131
                .getTranslation("do_not_save_yet_stay_in_editing_mode")), cc);
132

  
133
        resp.add(mainPanel, BorderLayout.CENTER);
134
        resp.add(topLabel, BorderLayout.NORTH);
135
        return resp;
136
    }
137

  
138
    public Service getService(DynObject parameters) throws ServiceException {
139
        return null;
140
    }
141

  
142
    public void registerEditingContext(MapControl mapControl) {
143
        MapContext mapContext = mapControl.getMapContext();
144
        if (!editingContexts.containsKey(mapContext)) {
145
            EditingContext editingContext =
146
                new DefaultEditingContext(mapControl);
147
            editingContexts.put(mapContext, editingContext);
148
        } else {
149
            // MapContext registered. Update mapControl reference of editing
150
            // context
151
            EditingContext editingContext = editingContexts.get(mapContext);
152
            editingContext.setMapControl(mapControl);
153
        }
154
    }
155

  
156
    public int showPanelExportOrDiscard(MapControl parent, String name) {
157

  
158
        I18nManager i18nManager = ToolsLocator.getI18nManager();
159

  
160
        Object[] options =
161
        { i18nManager.getTranslation("export"),
162
            "       " + i18nManager.getTranslation("discard") + "       ",
163
            i18nManager.getTranslation("continue") };
164

  
165
        String question = i18nManager.getTranslation("can_not_write_layer");
166
        String firstLabel = i18nManager.getTranslation("export");
167
        String firstDesc =
168
            i18nManager.getTranslation("export_to_another_format");
169

  
170
        JPanel explanation_panel =
171
            getExplanationPanel(question, firstLabel, firstDesc);
172

  
173
        int resp =
174
            JOptionPane.showOptionDialog(parent, explanation_panel,
175
                i18nManager.getTranslation("end_editing"),
176
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
177
                null, options, options[2]);
178

  
179
        if (resp == JOptionPane.NO_OPTION) {
180
            return EditingContext.DISCARD_CHANGES;
181
        } else if (resp == JOptionPane.YES_OPTION) {
182
            return EditingContext.EXPORT_LAYER;
183
        }
184
        return EditingContext.CANCEL;
185
    }
186

  
187
    public int showPanelSaveOrDiscard(MapControl parent, String name) {
188

  
189
        I18nManager i18nManager = ToolsLocator.getI18nManager();
190

  
191
        Object[] options =
192
        { i18nManager.getTranslation("save"),
193
            "       " + i18nManager.getTranslation("discard") + "       ",
194
            i18nManager.getTranslation("continue") };
195

  
196
        String question = i18nManager.getTranslation("ask_save_layer");
197
        question = question + " '" + name + "'?";
198
        String firstLabel = i18nManager.getTranslation("save");
199
        String firstDesc = i18nManager.getTranslation("save_changes_performed");
200
        JPanel explanation_panel =
201
            getExplanationPanel(question, firstLabel, firstDesc);
202

  
203
        int resp =
204
            JOptionPane.showOptionDialog(parent, explanation_panel,
205
                i18nManager.getTranslation("end_editing"),
206
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
207
                null, options, options[2]);
208

  
209
        if (resp == JOptionPane.YES_OPTION) {
210
            return EditingContext.SAVE_CHANGES;
211
        } else if (resp == JOptionPane.NO_OPTION) {
212
            return EditingContext.DISCARD_CHANGES;
213
        }
214
        return EditingContext.CANCEL;
215
    }
216

  
217
    public EditingContextMenu getContextualMenu(Component parent,
218
        AcceptValueListener listener, EditingServiceParameter parameter) {
219

  
220
        EditingContextMenu contextMenu =
221
            new DefaultEditingContextMenu(parent, listener, parameter);
222

  
223
        return contextMenu;
224
    }
225

  
226
    public EditingConsole getEditingConsole(ResponseListener listener) {
227
        return new DefaultEditingConsole(listener);
228
    }
229

  
230
    public EditingConsole getEditingConsole(List<ResponseListener> listeners) {
231
        return new DefaultEditingConsole(listeners);
232
    }
233
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.111/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingContext.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2014 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 2
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

  
25
package org.gvsig.vectorediting.swing.impl;
26

  
27
import java.awt.BorderLayout;
28
import java.awt.Component;
29
import java.lang.ref.WeakReference;
30
import java.lang.reflect.InvocationTargetException;
31
import java.util.ArrayList;
32
import java.util.Set;
33
import java.util.Stack;
34
import java.util.logging.Level;
35
import java.util.prefs.PreferenceChangeEvent;
36
import java.util.prefs.PreferenceChangeListener;
37
import java.util.prefs.Preferences;
38

  
39
import javax.swing.JComponent;
40
import javax.swing.JOptionPane;
41
import javax.swing.SwingUtilities;
42

  
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.feature.FeatureSelection;
45
import org.gvsig.fmap.dal.feature.FeatureStore;
46
import org.gvsig.fmap.geom.Geometry;
47
import org.gvsig.fmap.geom.GeometryLocator;
48
import org.gvsig.fmap.geom.GeometryManager;
49
import org.gvsig.fmap.geom.primitive.Point;
50
import org.gvsig.fmap.geom.type.GeometryType;
51
import org.gvsig.fmap.mapcontext.MapContext;
52
import org.gvsig.fmap.mapcontext.layers.CancelationException;
53
import org.gvsig.fmap.mapcontext.layers.FLayer;
54
import org.gvsig.fmap.mapcontext.layers.FLayers;
55
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
56
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
57
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
58
import org.gvsig.fmap.mapcontext.layers.LayerListener;
59
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
60
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
61
import org.gvsig.fmap.mapcontrol.MapControl;
62
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior;
63
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
64
import org.gvsig.tools.ToolsLocator;
65
import org.gvsig.tools.i18n.I18nManager;
66
import org.gvsig.tools.observer.BaseNotification;
67
import org.gvsig.tools.observer.Notification;
68
import org.gvsig.tools.observer.ObservableHelper;
69
import org.gvsig.tools.observer.Observer;
70
import org.gvsig.utils.console.JDockPanel;
71
import org.gvsig.utils.console.ResponseListener;
72
import org.gvsig.vectorediting.lib.api.EditingLocator;
73
import org.gvsig.vectorediting.lib.api.EditingManager;
74
import org.gvsig.vectorediting.lib.api.EditingService;
75
import org.gvsig.vectorediting.lib.api.EditingServiceInfo;
76
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
77
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE;
78
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException;
79
import org.gvsig.vectorediting.lib.api.exceptions.EndEditingException;
80
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException;
81
import org.gvsig.vectorediting.lib.api.exceptions.ParsePointException;
82
import org.gvsig.vectorediting.lib.api.exceptions.ParseValueException;
83
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException;
84
import org.gvsig.vectorediting.lib.api.exceptions.StartEditingException;
85
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException;
86
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException;
87
import org.gvsig.vectorediting.lib.api.exceptions.VectorEditingException;
88
import org.gvsig.vectorediting.swing.api.EditingContext;
89
import org.gvsig.vectorediting.swing.api.EditingSwingLocator;
90
import org.gvsig.vectorediting.swing.api.EditingSwingManager;
91
import org.gvsig.vectorediting.swing.api.console.EditingConsole;
92
import org.gvsig.vectorediting.swing.impl.console.DefaultEditingConsole;
93
import org.gvsig.fmap.geom.primitive.Point;
94

  
95
import org.apache.commons.lang3.StringUtils;
96
import org.gvsig.expressionevaluator.ExpressionUtils;
97
import org.gvsig.expressionevaluator.MutableSymbolTable;
98
import org.gvsig.fmap.dal.DataTypes;
99

  
100
import org.gvsig.fmap.dal.EditingNotification;
101
import org.gvsig.fmap.dal.EditingNotificationManager;
102
import org.gvsig.fmap.dal.swing.DALSwingLocator;
103
import org.gvsig.temporarystorage.TemporaryStorageGroup;
104
import org.gvsig.temporarystorage.TemporaryStorageLocator;
105
import org.gvsig.temporarystorage.TemporaryStorageManager;
106
import org.gvsig.tools.dataTypes.Coercion;
107
import org.gvsig.tools.dataTypes.DataTypesManager;
108
import org.gvsig.tools.swing.api.ToolsSwingLocator;
109
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
110

  
111
import org.slf4j.Logger;
112
import org.slf4j.LoggerFactory;
113

  
114
public class DefaultEditingContext implements EditingContext {
115

  
116
    private static final Logger logger = LoggerFactory
117
        .getLogger(EditingManager.class);
118

  
119
    private WeakReference<MapControl> mapControlReference;
120

  
121
    private WeakReference<MapContext> mapContextReference;
122

  
123
    private EditingCompoundBehavior editingCompoundBehavior;
124

  
125
    private Behavior[] lastAdditionalBehaviors;
126

  
127
    private ObservableHelper observableHelper;
128

  
129
    private EditingConsole console;
130

  
131
    private JDockPanel dockConsole = null;
132

  
133
    private boolean isShowConsole = false;
134

  
135
    private Stack<EditingService> serviceStack;
136

  
137
    private FLyrVect currentLayer;
138

  
139
    private EditingServiceParameter currentParam;
140

  
141
    private Behavior[] defaultBehaviors;
142

  
143
    private LayerListener layerListener = new LayerListener() {
144

  
145
        @Override
146
        public void activationChanged(final LayerEvent e) {
147
            if( !SwingUtilities.isEventDispatchThread() ) {
148
                SwingUtilities.invokeLater(new Runnable() {
149

  
150
                    @Override
151
                    public void run() {
152
                        activationChanged(e);
153
                    }
154
                });
155
                return;
156
            }
157

  
158
            FLayer layer = e.getSource();
159

  
160
            FLayer[] activeLayers =
161
                layer.getMapContext().getLayers().getActives();
162

  
163
            if ((activeLayers.length == 1) && (layer instanceof FLyrVect)) {
164
                if (layer.isActive() && layer.isEditing()) {
165
                    getMapControl().setTool("VectorEditing");
166
                    setCurrentLayer((FLyrVect) layer);
167
                    showConsole();
168
                    return;
169
                }
170
            }
171

  
172
            hideConsole();
173
            if ((getMapControl().getCurrentTool() != null)
174
                && getMapControl().getCurrentTool().equals("VectorEditing")) {
175
                getMapControl().setPrevTool();
176
            }
177
        }
178

  
179
        public void drawValueChanged(LayerEvent e) {
180
        }
181

  
182
        @Override
183
        public void editionChanged(final LayerEvent e) {
184
            if( !SwingUtilities.isEventDispatchThread() ) {
185
                SwingUtilities.invokeLater(new Runnable() {
186

  
187
                    @Override
188
                    public void run() {
189
                        editionChanged(e);
190
                    }
191
                });
192
                return;
193
            }
194
            FLayer layer = e.getSource();
195

  
196
            if (layer instanceof FLyrVect) {
197
                if (layer.isEditing()) {
198
                    synchronized (DefaultEditingContext.this) {
199
                        beginEdition((FLyrVect) layer);
200
                        showConsole();
201
                    }
202
                } else {
203
                    hideConsole();
204
                }
205
            }
206

  
207
        }
208

  
209
        public void nameChanged(LayerEvent e) {
210
        }
211

  
212
        public void visibilityChanged(LayerEvent e) {
213
        }
214
    };
215

  
216
    private PreferenceChangeListener preferenceChangeListener =
217
        new PreferenceChangeListener() {
218

  
219
            public void preferenceChange(PreferenceChangeEvent evt) {
220
                String key = evt.getKey();
221
                if (key.equalsIgnoreCase("apply-snappers")) {
222
                    boolean newValue = Boolean.parseBoolean(evt.getNewValue());
223
                    getMapControl().setRefentEnabled(newValue);
224
                }
225
            }
226
        };
227

  
228
    public DefaultEditingContext(MapControl mapControl) {
229

  
230
        this.mapControlReference = new WeakReference<MapControl>(mapControl);
231
        this.mapContextReference =
232
            new WeakReference<MapContext>(mapControl.getMapContext());
233
        this.observableHelper = new ObservableHelper();
234

  
235
        this.serviceStack = new Stack<EditingService>();
236

  
237
        addLayerListeners();
238
        addPreferenceListener();
239
    }
240

  
241
    private void addPreferenceListener() {
242
        Preferences prefs = Preferences.userRoot().node("snappers");
243
        prefs.addPreferenceChangeListener(preferenceChangeListener);
244
    }
245

  
246
    public void activateService(String name) {
247

  
248
        if ((getMapControl() != null)
249
            && getMapControl().hasTool("VectorEditing")) {
250

  
251
            CompoundBehavior editingCompoundBehavior =
252
                getEditingCompoundBehavior();
253
            getMapControl().setTool("VectorEditing");
254
            editingCompoundBehavior.setDrawnBehavior(
255
                EditingCompoundBehavior.EDITING_INDEX, true);
256

  
257
            EditingManager manager = EditingLocator.getManager();
258

  
259
            if (currentLayer != null) {
260

  
261
                EditingService service =
262
                    manager.getEditingService(name,
263
                        currentLayer.getFeatureStore(),
264
                        mapContextReference.get());
265

  
266
                if (service != null) {
267

  
268
                    this.enableSelection(false);
269

  
270
                    try {
271
                        service.start();
272
                    } catch (StartServiceException e) {
273

  
274
                        logger.info(String.format(
275
                            "Can't start the service %1$s", service.getName()),
276
                            e);
277
                        cleanEditingContext();
278
                        return;
279

  
280
                    } catch (InvalidEntryException e) {
281

  
282
                        I18nManager i18nManager = ToolsLocator.getI18nManager();
283
                        showConsoleMessage("\n"
284
                            + i18nManager.getTranslation("invalid_option"));
285
                    }
286

  
287
                    if (!serviceStack.isEmpty()
288
                        && !getActiveService().next().getTypes()
289
                            .contains(TYPE.GEOMETRY)) {
290
                        serviceStack.pop();
291
                    }
292

  
293
                    setActiveService(service);
294

  
295
                    getNextParameter();
296
                }
297
            }
298
        }
299
    }
300

  
301
    private void addBehaviors(Behavior[] additionalBehavior)
302
        throws CreateEditingBehaviorException {
303

  
304
        DefaultEditingBehavior editingBehavior;
305
        EditingCompoundBehavior editingCompoundBehavior;
306

  
307
        if (!getMapControl().hasTool("VectorEditing")) {
308

  
309
            editingBehavior = new DefaultEditingBehavior(this);
310
            editingCompoundBehavior =
311
                new EditingCompoundBehavior(editingBehavior);
312
            setCompoundBehavior(editingCompoundBehavior);
313

  
314
            if (additionalBehavior != null) {
315

  
316
                Behavior[] behaviors =
317
                    new Behavior[additionalBehavior.length + 1];
318
                behaviors[0] = editingCompoundBehavior;
319

  
320
                for (int i = 0; i < additionalBehavior.length; i++) {
321
                    behaviors[i + 1] = additionalBehavior[i];
322
                }
323

  
324
                getMapControl().addBehavior("VectorEditing", behaviors);
325

  
326
                lastAdditionalBehaviors = additionalBehavior;
327

  
328
            } else {
329
                getMapControl().addBehavior("VectorEditing",
330
                    editingCompoundBehavior);
331
            }
332

  
333
        } else {
334
            editingCompoundBehavior = getEditingCompoundBehavior();
335
            editingBehavior =
336
                (DefaultEditingBehavior) editingCompoundBehavior
337
                    .getBehavior(EditingCompoundBehavior.EDITING_INDEX);
338
            setCompoundBehavior(editingCompoundBehavior);
339
            cleanEditingContext();
340
        }
341

  
342
    }
343

  
344
    private void addLayerListeners() {
345

  
346
        FLayers layers = mapContextReference.get().getLayers();
347

  
348
        layers.addLayerListener(layerListener);
349

  
350
        layers.addLayerCollectionListener(new LayerCollectionListener() {
351

  
352
            public void addLayer(FLayer layer) {
353
                if (layer instanceof FLayers) {
354
                    FLayers layers = (FLayers) layer;
355
                    for (int i = 0; i < layers.getLayersCount(); i++) {
356
                        addLayer(layers.getLayer(i));
357
                    }
358
                } else if (layer instanceof FLyrVect) {
359
                    ((FLyrVect) layer).addLayerListener(layerListener);
360
                }
361
            }
362

  
363
            public void layerAdded(LayerCollectionEvent e) {
364
                addLayer(e.getLayers());
365
            }
366

  
367
            public void layerAdding(LayerCollectionEvent e)
368
                throws CancelationException {
369
            }
370

  
371
            public void layerMoved(LayerPositionEvent e) {
372
            }
373

  
374
            public void layerMoving(LayerPositionEvent e)
375
                throws CancelationException {
376
            }
377

  
378
            public void removeLayer(FLayer layer) {
379
                if (layer instanceof FLayers) {
380
                    FLayers layers = (FLayers) layer;
381
                    for (int i = 0; i < layers.getLayersCount(); i++) {
382
                        addLayer(layers.getLayer(i));
383
                    }
384
                } else if (layer instanceof FLyrVect) {
385
                    ((FLyrVect) layer).removeLayerListener(layerListener);
386
                }
387
            }
388

  
389
            public void layerRemoved(LayerCollectionEvent e) {
390
                removeLayer(e.getLayers());
391
            }
392

  
393
            public void layerRemoving(LayerCollectionEvent e)
394
                throws CancelationException {
395
            }
396

  
397
            public void visibilityChanged(LayerCollectionEvent e)
398
                throws CancelationException {
399
            }
400
        });
401
    }
402

  
403
    public void addObserver(Observer o) {
404
        this.observableHelper.addObserver(o);
405
    }
406

  
407
    private void askQuestion(EditingServiceParameter param) {
408
        I18nManager i18nManager = ToolsLocator.getI18nManager();
409
        String translation = i18nManager.getTranslation(param.getDescription());
410
        String activeServiceName =
411
            i18nManager.getTranslation(getActiveService().getName());
412

  
413
        Object defaultValue = param.getDefaultValue();
414
        String strDefaultValue;
415

  
416
        if (defaultValue != null) {
417
            if (defaultValue instanceof String) {
418
                strDefaultValue = (String) defaultValue;
419
                strDefaultValue =
420
                    i18nManager.getTranslation((String) defaultValue);
421
            } else {
422
                if(defaultValue instanceof Point){
423
                    Point point = (Point)defaultValue;
424
                    StringBuilder builder = new StringBuilder();
425
                    for(int i=0; i<point.getDimension(); i++){
426
                        builder.append(point.getCoordinateAt(i));
427
                        if(i < point.getDimension()-1){
428
                            builder.append(" , ");
429
                        }
430
                    }
431
                    strDefaultValue = builder.toString();
432
                } else {
433
                    strDefaultValue = defaultValue.toString();
434
                }
435
            }
436
            showConsoleMessage("\n" + activeServiceName + "# " + translation
437
                + "<" + strDefaultValue + "> : ");
438
        } else {
439
            showConsoleMessage("\n" + activeServiceName + "# " + translation
440
                + " : ");
441
        }
442
    }
443

  
444
    public synchronized void beginEdition(FLyrVect layer,
445
        Behavior[] additionalBehaviors) {
446

  
447
        try{
448
            throw new Exception("Deprecated method");
449
        } catch (Exception e){
450
            logger.info("Deprecated method", e);
451
        }
452

  
453
        beginEdition(layer);
454
        try {
455
            addBehaviors(additionalBehaviors);
456
        } catch (CreateEditingBehaviorException e1) {
457
            logger.info("Problems adding behaviors to editing context", e1);
458
            getMapControl().setTool("pan");
459
            return;
460
        }
461
    }
462

  
463
    public synchronized void beginEdition(FLyrVect layer) {
464

  
465
        EditingNotificationManager editingNotificationManager =
466
            DALSwingLocator.getEditingNotificationManager();
467

  
468
        EditingNotification notification =
469
            editingNotificationManager.notifyObservers(this,
470
                EditingNotification.BEFORE_ENTER_EDITING_STORE, null, layer,layer.getFeatureStore());
471

  
472
        if (notification.isCanceled()) {
473
            String msg =
474
                String.format("Edit layer %1$s canceled by somme observer.",
475
                    layer.getName());
476
            logger.info(msg, new StartEditingException(msg, null));
477
            return;
478
        }
479

  
480
        setCurrentLayer(layer);
481

  
482
        FeatureStore featureStore = layer.getFeatureStore();
483
        if (!featureStore.isEditing()) {
484
            try {
485
                featureStore.edit();
486
            } catch (Exception e) {
487
                String msg =
488
                    String.format("Can't set %1$s in edit mode",
489
                        featureStore.getName());
490
                logger.info(msg, new VectorEditingException(e));
491
                cleanEditingContext();
492
                return;
493
            }
494
        }
495

  
496
        featureStore.addObserver(getMapControl());
497

  
498
        editingNotificationManager.notifyObservers(this,
499
            EditingNotification.AFTER_ENTER_EDITING_STORE, null, layer, layer.getFeatureStore());
500

  
501
        enableSnapping();
502
    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff