Revision 1222

View differences:

org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/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
    <modelVersion>4.0.0</modelVersion>
4
    <artifactId>org.gvsig.hyperlink.app</artifactId>
5
    <packaging>pom</packaging>
6
    <version>1.0.237</version>
7
    <name>${project.artifactId}</name>
8
    <description>View. Hyperlink support</description>
9
	
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.desktop</artifactId>
13
        <version>2.0.435</version>
14
    </parent>
15
        
16
    <url>https://devel.gvsig.org/redmine/projects/gvsig-hyperlink</url>
17
	
18
    <scm>
19
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237</connection>
20
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237</developerConnection>
21
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237</url>
22
    </scm>
23
    
24
    <developers>
25
        <developer>
26
            <id>jjdelcerro</id>
27
            <name>Joaqu?n Jos? del Cerro</name>
28
            <email>jjdelcerro@gvsig.org</email>
29
            <roles>
30
                <role>Architect</role>
31
                <role>Developer</role>
32
            </roles>
33
        </developer>
34
        <developer>
35
            <id>cordinyana</id>
36
            <name>C?sar Ordi?ana</name>
37
            <email>cordinyana@gvsig.com</email>
38
            <roles>
39
                <role>Architect</role>
40
                <role>Developer</role>
41
            </roles>
42
        </developer>
43
    </developers>
44
    <distributionManagement>
45
        <site>
46
            <id>gvsig-repository</id>
47
            <url>dav:https://devel.gvsig.org/sites/org.gvsig.hyperlink.app/${project.version}</url>
48
        </site>
49
    </distributionManagement>
50
    <repositories>
51
        <repository>
52
            <id>gvsig-public-http-repository</id>
53
            <name>gvSIG maven public HTTP repository</name>
54
            <url>http://devel.gvsig.org/m2repo/j2se</url>
55
            <releases>
56
                <enabled>true</enabled>
57
                <updatePolicy>daily</updatePolicy>
58
                <checksumPolicy>warn</checksumPolicy>
59
            </releases>
60
            <snapshots>
61
                <enabled>true</enabled>
62
                <updatePolicy>daily</updatePolicy>
63
                <checksumPolicy>warn</checksumPolicy>
64
            </snapshots>
65
        </repository>
66
    </repositories>
67

  
68
    <build>
69
        <plugins>
70
            <plugin>
71
                <artifactId>maven-release-plugin</artifactId>
72
                <configuration>
73
                    <tagBase>https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags</tagBase>
74
                </configuration>
75
            </plugin>			
76
     
77
        </plugins>   
78
    </build>
79
                
80
    <dependencyManagement>
81
        <dependencies>
82
            <dependency>
83
                <groupId>org.gvsig</groupId>
84
                <artifactId>org.gvsig.pdf.swing.api</artifactId>
85
                <version>${org.gvsig.pdf.version}</version>
86
                <scope>compile</scope>
87
            </dependency>
88

  
89
        </dependencies>
90
    </dependencyManagement>
91
    <properties>
92
        <org.gvsig.pdf.version>1.0.142</org.gvsig.pdf.version>
93
    </properties>
94
        
95
    <modules>
96
        <module>org.gvsig.hyperlink.app.extension</module>
97
    </modules>
98
</project>
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/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/maven-v4_0_0.xsd">
4
  <modelVersion>4.0.0</modelVersion>
5
  <artifactId>org.gvsig.hyperlink.app.extension</artifactId>
6
  <packaging>jar</packaging>
7
  <name>${project.artifactId}</name>
8
  <parent>
9
    <groupId>org.gvsig</groupId>
10
    <artifactId>org.gvsig.hyperlink.app</artifactId>
11
    <version>1.0.237</version>
12
  </parent>
13

  
14
  <dependencies>
15
    <dependency>
16
      <groupId>org.gvsig</groupId>
17
      <artifactId>org.gvsig.andami</artifactId>
18
      <scope>compile</scope>
19
    </dependency>
20
    <dependency>
21
      <groupId>org.gvsig</groupId>
22
      <artifactId>org.gvsig.i18n</artifactId>
23
      <scope>compile</scope>
24
    </dependency>
25
    <dependency>
26
      <groupId>org.gvsig</groupId>
27
      <artifactId>org.gvsig.tools.lib</artifactId>
28
      <scope>compile</scope>
29
    </dependency>
30

  
31
    <dependency>
32
      <groupId>org.gvsig</groupId>
33
      <artifactId>org.gvsig.fmap.control</artifactId>
34
      <scope>compile</scope>
35
    </dependency>
36
    <dependency>
37
      <groupId>org.gvsig</groupId>
38
      <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
39
      <scope>compile</scope>
40
    </dependency>
41

  
42
    <dependency>
43
      <groupId>org.gvsig</groupId>
44
      <artifactId>org.gvsig.fmap.geometry.api</artifactId>
45
      <scope>compile</scope>
46
    </dependency>
47

  
48
    <dependency>
49
      <groupId>org.gvsig</groupId>
50
      <artifactId>org.gvsig.app.mainplugin</artifactId>
51
      <scope>compile</scope>
52
    </dependency>
53

  
54
    <dependency>
55
      <groupId>org.gvsig</groupId>
56
      <artifactId>org.gvsig.fmap.dal.api</artifactId>
57
      <scope>compile</scope>
58
    </dependency>
59
    <dependency>
60
      <groupId>org.gvsig</groupId>
61
      <artifactId>org.gvsig.projection.api</artifactId>
62
      <scope>compile</scope>
63
    </dependency>
64
    <dependency>
65
      <groupId>org.gvsig</groupId>
66
      <artifactId>org.gvsig.utils</artifactId>
67
      <scope>compile</scope>
68
    </dependency>
69
    <dependency>
70
      <groupId>org.gvsig</groupId>
71
      <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
72
      <scope>compile</scope>
73
    </dependency>
74
    <dependency>
75
      <groupId>org.gvsig</groupId>
76
      <artifactId>org.gvsig.ui</artifactId>
77
      <scope>compile</scope>
78
    </dependency>
79
    <dependency>
80
      <groupId>org.slf4j</groupId>
81
      <artifactId>slf4j-api</artifactId>
82
      <scope>compile</scope>
83
    </dependency>
84

  
85
    <!-- External libraries -->
86
    <!--
87
    <dependency>
88
      <groupId>org.jpedal</groupId>
89
      <artifactId>jpedal_lgpl</artifactId>
90
      <scope>compile</scope>
91
    </dependency>
92
    <dependency>
93
      <groupId>com.sun</groupId>
94
      <artifactId>jimi</artifactId>
95
      <scope>compile</scope>
96
    </dependency>
97
    -->
98
    <dependency>
99
      <groupId>org.apache.xmlgraphics</groupId>
100
      <artifactId>batik-gvt</artifactId>
101
      <scope>compile</scope>
102
    </dependency>
103
    <dependency>
104
      <groupId>org.apache.xmlgraphics</groupId>
105
      <artifactId>batik-bridge</artifactId>
106
      <scope>compile</scope>
107
    </dependency>
108
    <dependency>
109
      <groupId>org.apache.xmlgraphics</groupId>
110
      <artifactId>batik-script</artifactId>
111
      <scope>compile</scope>
112
    </dependency>
113
    <dependency>
114
      <groupId>xml-apis</groupId>
115
      <artifactId>xml-apis-ext</artifactId>
116
      <scope>compile</scope>
117
    </dependency>
118
    <dependency>
119
      <groupId>org.gvsig</groupId>
120
      <artifactId>org.gvsig.pdf.swing.api</artifactId>
121
      <scope>compile</scope>
122
    </dependency>
123
    <dependency>
124
      <groupId>org.gvsig</groupId>
125
      <artifactId>org.gvsig.tools.util.api</artifactId>
126
      <scope>compile</scope>
127
    </dependency>
128
  </dependencies>
129

  
130
  <build>
131
    <plugins>
132
      <plugin>
133
        <!-- Set java compatibility -->
134
        <groupId>org.apache.maven.plugins</groupId>
135
        <artifactId>maven-compiler-plugin</artifactId>
136
        <configuration>
137
          <source>1.6</source>
138
          <target>1.6</target>
139
          <encoding>ISO-8859-1</encoding>
140
        </configuration>
141
      </plugin>
142

  
143
<!--
144
      <plugin>
145
        <groupId>org.codehaus.mojo</groupId>
146
        <artifactId>animal-sniffer-maven-plugin</artifactId>
147
        <executions>
148
          <execution>
149
            <id>check-java-api</id>
150
            <phase>package</phase>
151
            <goals>
152
              <goal>check</goal>
153
            </goals>
154
            <configuration>
155
              <skip>false</skip>
156
              <signature>
157
                <groupId>org.codehaus.mojo.signature</groupId>
158
                <artifactId>java16</artifactId>
159
                <version>1.0</version>
160
              </signature>
161
            </configuration>
162
          </execution>
163
        </executions>
164
      </plugin>
165
-->
166
    </plugins>
167
  </build>
168

  
169

  
170

  
171
  <properties>
172
    <gvsig.package.info.name>Tools: Hyperlink</gvsig.package.info.name>
173
    <gvsig.package.info.state>testing</gvsig.package.info.state>
174
    <gvsig.package.info.categories>View</gvsig.package.info.categories>
175
    <gvsig.package.info.official>true</gvsig.package.info.official>
176
    <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2</gvsig.package.info.dependencies>
177
    <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-hyperlink/pool</gvsig.package.info.poolURL>
178
    <gvsig.package.info.javaVM>j1_6</gvsig.package.info.javaVM>
179

  
180
  </properties>
181

  
182

  
183
</project>
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/buildNumber.properties
1
#Wed Oct 18 19:45:00 CEST 2023
2
buildNumber=2327
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25
<!-- org.gvsig.app.mainplugin provides these libraries
26
  <dependencySets>
27
  
28
    <dependencySet>
29
      <useProjectArtifact>false</useProjectArtifact>
30
      <useTransitiveDependencies>false</useTransitiveDependencies>
31
      <outputDirectory>lib</outputDirectory>
32
      <includes>
33
            <include>org.jpedal:jpedal_lgpl</include>
34
            <include>com.sun:jimi</include>
35
            <include>org.apache.xmlgraphics:batik-gvt</include>
36
            <include>org.apache.xmlgraphics:batik-bridge</include>
37
            <include>org.apache.xmlgraphics:batik-script</include>
38
            <include>xml-apis:xml-apis-ext</include>
39
      </includes>
40
    </dependencySet>
41
  </dependencySets>
42
-->
43

  
44
</assembly>
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/HyperlinkExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22
package org.gvsig.hyperlink.app.extension;
23

  
24
import java.util.Map;
25

  
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.documents.view.ViewDocument;
33
import org.gvsig.app.project.documents.view.gui.IView;
34
import org.gvsig.app.project.documents.view.legend.gui.ThemeManagerWindow;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.FLayers;
38
import org.gvsig.fmap.mapcontext.layers.LayersIterator;
39
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
40
import org.gvsig.fmap.mapcontrol.MapControl;
41
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
42
import org.gvsig.hyperlink.app.extension.actions.ExternTxtFormat;
43
import org.gvsig.hyperlink.app.extension.actions.FolderFormat;
44
import org.gvsig.hyperlink.app.extension.actions.ImgFormat;
45
import org.gvsig.hyperlink.app.extension.actions.PdfFormat;
46
import org.gvsig.hyperlink.app.extension.actions.SvgFormat;
47
import org.gvsig.hyperlink.app.extension.actions.TxtFormat;
48
import org.gvsig.hyperlink.app.extension.config.LayerLinkConfig;
49
import org.gvsig.hyperlink.app.extension.config.LinkConfig;
50
import org.gvsig.hyperlink.app.extension.config.gui.ConfigTab;
51
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry;
52
import org.gvsig.hyperlink.app.extension.layers.VectLayerManager;
53
import org.gvsig.tools.ToolsLocator;
54
import org.gvsig.tools.extensionpoint.ExtensionPoint;
55
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
56
import org.gvsig.tools.library.LibraryException;
57
import org.gvsig.tools.util.Caller;
58
import org.gvsig.tools.util.impl.DefaultCaller;
59

  
60
/**
61
 * Andami extension to show Hyperlink in the application.
62
 *
63
 * @author gvSIG Team
64
 * @version $Id$
65
 */
66
public class HyperlinkExtension extends Extension {
67

  
68
    private static final Logger LOG = LoggerFactory
69
        .getLogger(HyperlinkExtension.class);
70
    ManagerRegistry layerManager;
71
    public static final String LAYERPROPERTYNAME = "org.gvsig.hyperlink.config";
72
    public static final String TOOLNAME = "org.gvsig.hyperlink.tool";
73
    public static final String ACTIONSEXTENSIONPOINT = "HyperLinkAction";
74

  
75
    private static final int LEGACY_IMAGE_TYPE = 0;
76
    private static final int LEGACY_HTML_TYPE = 1;
77
    private static final int LEGACY_PDF_TYPE = 2;
78
    private static final int LEGACY_SVG_TYPE = 3;
79

  
80
    /**
81
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
82
     */
83
    public void execute(String s) {
84
        IView view = (IView) PluginServices.getMDIManager().getActiveWindow();
85
        MapControl mapCtrl = view.getMapControl();
86
        LOG.debug("Comand : " + s);
87

  
88
        if (s.compareTo("view-show-hyperlink") == 0) {
89
            initTool(view);
90
            mapCtrl.setTool(TOOLNAME);
91
        }
92
    }
93

  
94
    /**
95
     * Inits the tool for the provided view.
96
     *
97
     * @param view
98
     */
99
    public void initTool(IView view) {
100
        MapControl mapCtrl = view.getMapControl();
101
        if (view.getMapControl().getNamesMapTools().get(TOOLNAME) == null) {
102
            mapCtrl.addBehavior(TOOLNAME,
103
                new PointBehavior(new LinkListener(mapCtrl, layerManager)));
104
            loadLegacyConfig(view);
105
        }
106
    }
107

  
108
    public void loadLegacyConfig(IView view) {
109
        LayersIterator iterator =
110
            new LayersIterator(view.getMapControl().getMapContext().getLayers());
111
        while (iterator.hasNext()) {
112
            FLayer layer = iterator.nextLayer();
113
            loadLegacyConfig(layer);
114
        }
115
    }
116

  
117
    /**
118
     * Returns a LayerLinkConfig object if an old-style or new-style hyperlink
119
     * was found and configured,
120
     * or null otherwise.
121
     *
122
     * @param layer
123
     */
124
    public LayerLinkConfig loadLegacyConfig(FLayer layer) {
125
        LayerLinkConfig layerConfig =
126
            (LayerLinkConfig) layer.getProperty(LAYERPROPERTYNAME);
127
        if (layerConfig != null) { // don't apply compatibility if the layer
128
                                   // already has new 1.9.0 configuration
129
            return layerConfig;
130
        }
131
        Object fName = layer.getProperty("legacy.hyperlink.selectedField");
132
        if (fName != null && fName instanceof String) {
133
            Map properties = layer.getExtendedProperties();
134
            properties.remove("legacy.hyperlink.selectedField");
135
            // remove it from layer to don't keep legacy properties for ever
136
            // in the project
137

  
138
            String fieldName = (String) fName;
139
            Object extObj = layer.getProperty("legacy.hyperlink.extension");
140
            String extension = null;
141
            if (extObj != null && extObj instanceof String) {
142
                properties.remove("legacy.hyperlink.extension");
143
                // remove it from layer to don't keep legacy properties for ever
144
                // in the project
145
                extension = (String) extObj;
146
            }
147
            Object typeObj = layer.getProperty("legacy.hyperlink.type");
148
            int type = -1;
149
            if (typeObj != null && typeObj instanceof Integer) {
150
                properties.remove("legacy.hyperlink.type");
151
                // remove it from layer to don't keep legacy properties for ever
152
                // in the project
153
                type = ((Integer) typeObj).intValue();
154
            }
155
            LayerLinkConfig config = new LayerLinkConfig();
156
            config.setEnabled(true);
157
            config.addLink(getLegacyActionCode(type), fieldName, extension);
158
            layer.setProperty(LAYERPROPERTYNAME, config);
159
            return config;
160
        }
161
        return null;
162
    }
163

  
164
    private String getLegacyActionCode(int type) {
165
        switch (type) {
166
        case LEGACY_IMAGE_TYPE:
167
            return ImgFormat.ACTION_CODE;
168
        case LEGACY_PDF_TYPE:
169
            return PdfFormat.ACTION_CODE;
170
        case LEGACY_SVG_TYPE:
171
            return SvgFormat.ACTION_CODE;
172
        case LEGACY_HTML_TYPE:
173
        default:
174
            return TxtFormat.ACTION_CODE;
175
        }
176
    }
177

  
178
    /**
179
     * @see com.iver.mdiApp.plugins.IExtension#isVisible()
180
     */
181
    public boolean isVisible() {
182
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
183

  
184
        if (f == null) {
185
            return false;
186
        }
187

  
188
        if (f instanceof IView) {
189

  
190
            MapContext mapa = ((IView) f).getViewDocument().getMapContext();
191

  
192
            return mapa.getLayers().getLayersCount() > 0;
193
        } else {
194
            return false;
195
        }
196
    }
197

  
198
    /**
199
     * @see com.iver.andami.plugins.IExtension#isEnabled()
200
     */
201
    public boolean isEnabled() {
202
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
203

  
204
        if (window == null) {
205
            return false;
206
        }
207

  
208
        if (window instanceof IView) {
209
            IView view = (IView) window;
210
            ViewDocument viewDocument = view.getViewDocument();
211

  
212
            if (viewDocument != null
213
                && viewDocument.getMapContext() != null
214
                && viewDocument.getMapContext().getLayers().getVisibles().length > 0) {
215
            	FLayers lyrs = viewDocument.getMapContext().getLayers();
216
            	FLayer[] lyrsSelected = lyrs.getActives();
217
            	for (int i = 0; i < lyrsSelected.length; i++) {
218
            		Object obj = lyrsSelected[i].getProperty(HyperlinkExtension.LAYERPROPERTYNAME);
219
					if(obj != null)
220
						return true;
221
				}
222
            }
223
        }
224
        return false;
225
    }
226

  
227
    public void postInitialize() {
228
        Caller caller = new DefaultCaller();
229

  
230
        caller.add(new LinkConfig.RegisterPersistence());
231
        caller.add(new LayerLinkConfig.RegisterPersistence());
232
        if( !caller.call() ) {
233
            throw new LibraryException(HyperlinkExtension.class, caller.getExceptions());
234
        }
235

  
236
        registerLayers();
237
        registerActions();
238
        registerConfigPanel();
239
    }
240

  
241
    private void registerLayers() {
242
        layerManager = new ManagerRegistry();
243
        layerManager.put(FLyrVect.class, VectLayerManager.class);
244
    }
245

  
246
    public ManagerRegistry getLayerManager() {
247
        return layerManager;
248
    }
249

  
250
    private void registerActions() {
251
        ExtensionPointManager epm = ToolsLocator.getExtensionPointManager();
252
        ExtensionPoint ep =
253
            epm.add(ACTIONSEXTENSIONPOINT,
254
                "Registers Actions that are able to manage specific format types.");
255

  
256
        ep.append(TxtFormat.ACTION_CODE, "", TxtFormat.class);
257
        ep.append(ExternTxtFormat.ACTION_CODE, "", ExternTxtFormat.class);
258
        ep.append(ImgFormat.ACTION_CODE, "", ImgFormat.class);
259
        ep.append(PdfFormat.ACTION_CODE, "", PdfFormat.class);
260
        ep.append(SvgFormat.ACTION_CODE, "", SvgFormat.class);
261
        ep.append(FolderFormat.ACTION_CODE, "", FolderFormat.class);
262

  
263
    }
264

  
265
    private void registerConfigPanel() {
266
        // pages
267
        ThemeManagerWindow.addPage(ConfigTab.class);
268

  
269
        ThemeManagerWindow.setTabEnabledForLayer(ConfigTab.class,
270
            FLyrVect.class,
271
            true);
272
    }
273

  
274
    public void initialize() {
275
        IconThemeHelper.registerIcon("action",
276
            "view-show-hyperlink", this);
277
        IconThemeHelper.registerIcon("cursor",
278
            "cursor-view-show-hyperlink", this);
279

  
280
    }
281

  
282
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/LinkListener.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22

  
23
package org.gvsig.hyperlink.app.extension;
24

  
25
import java.awt.Cursor;
26
import java.awt.Image;
27
import java.awt.Point;
28
import java.awt.Toolkit;
29
import java.awt.geom.Point2D;
30
import java.net.URI;
31

  
32
import org.gvsig.andami.IconThemeHelper;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.app.project.documents.view.toolListeners.InfoListener;
35
import org.gvsig.fmap.mapcontext.layers.FLayer;
36
import org.gvsig.fmap.mapcontrol.MapControl;
37
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
38
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
39
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
40
import org.gvsig.hyperlink.app.extension.config.LayerLinkConfig;
41
import org.gvsig.hyperlink.app.extension.config.LinkConfig;
42
import org.gvsig.hyperlink.app.extension.layers.ILinkLayerManager;
43
import org.gvsig.hyperlink.app.extension.layers.IncompatibleLayerException;
44
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.extensionpoint.ExtensionPoint;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

  
50
/**
51
 * Listener that implements PointListener to show the information of the
52
 * HyperLink of the layer,
53
 * if the actual layer allows it. When the user selects the tool and make one
54
 * clic with
55
 * the mouse throws an event to create Panels with the information of the
56
 * associated HyperLink
57
 * to the layer. Creates one panel for URI provided, to load the information.
58
 * 
59
 * @author Vicente Caballero Navarro
60
 * @author Cesar Martinez Izqueirdo
61
 * 
62
 */
63
public class LinkListener implements PointListener {
64

  
65
    private static Logger logger = LoggerFactory.getLogger(InfoListener.class);
66
    private Cursor cur = null;
67
    private MapControl mapCtrl;
68
    private ManagerRegistry registry;
69
//    private Image imageCursor = null;
70
    public static final int TYPELINKIMAGE = 0;
71
    public static final int TYPELINKTEXT = 1;
72
    public ExtensionPoint formatManagers;
73

  
74
    /**
75
     * Creates a new LinkListener
76
     * 
77
     * @param mc
78
     *            mapControl
79
     */
80
    public LinkListener(MapControl mc, ManagerRegistry registry) {
81
        this.mapCtrl = mc;
82
        this.registry = registry;
83
        formatManagers =
84
            ToolsLocator.getExtensionPointManager()
85
                .get(HyperlinkExtension.ACTIONSEXTENSIONPOINT);
86
        initialize();
87
    }
88

  
89
    private void initialize() {
90
        cur = Toolkit.getDefaultToolkit().createCustomCursor(this.getImageCursor(),
91
                    new Point(16, 16),
92
                    "Hyperlink");
93
    }
94

  
95
    /**
96
     * Creates one LinkPanel for URI provided. Gets the active layers and
97
     * invokes getLink
98
     * with the catched point and the allowed tolerance if these layers allows
99
     * HyperLinks.
100
     * getLink provides an array of URIs, this method is invoked for all active
101
     * layers.
102
     * 
103
     * @param event
104
     *            PointEvent
105
     * @throws BehaviorException
106
     * 
107
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
108
     */
109
    @Override
110
    public void point(PointEvent event) throws BehaviorException {
111
        Point2D pReal =
112
            mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
113
        FLayer[] sel = mapCtrl.getMapContext().getLayers().getVisibles();
114

  
115
        LinkTarget[] links = null;
116
        LinkConfig linkConfig;
117
        ILinkLayerManager layerManager;
118
        ILinkActionManager actionManager;
119

  
120
        for (int layerCount = 0; layerCount < sel.length; layerCount++) {
121
            FLayer theLayer = sel[layerCount];
122
            if (!registry.hasManager(theLayer)) {
123
                continue;
124
            }
125
            try {
126
                layerManager = registry.get(theLayer);
127
                if (theLayer.getProperty(HyperlinkExtension.LAYERPROPERTYNAME) != null
128
                    && theLayer.getProperty(HyperlinkExtension.LAYERPROPERTYNAME) instanceof LayerLinkConfig) {
129
                    LayerLinkConfig layerLink =
130
                        (LayerLinkConfig) theLayer.getProperty(HyperlinkExtension.LAYERPROPERTYNAME);
131
                    if (layerLink.isEnabled() && layerLink.linkCount() > 0) { 
132
                        // there is
133
                                                                              // some
134
                                                                              // link
135
                                                                              // configured
136
                                                                              // for
137
                                                                              // this
138
                                                                              // layer
139

  
140
                        double tol = mapCtrl.getViewPort().toMapDistance(3);
141
                        for (int actionCount = 0; actionCount < layerLink.linkCount(); actionCount++) {
142
                            linkConfig = layerLink.getLink(actionCount);
143
                            links = layerManager.getLink(pReal,
144
                                    tol,
145
                                    linkConfig.getFieldName(),
146
                                    linkConfig.getExtension()
147
                            );
148
                            for (int i = 0; i < links.length; i++) {
149
                                if (links[i] != null) {
150

  
151
                                    actionManager =
152
                                        (ILinkActionManager) formatManagers.get(linkConfig.getActionCode())
153
                                            .getExtension()
154
                                            .newInstance();
155
                                    if (actionManager == null) {
156
                                        logger.warn("Hyperlink error -- invalid action code: "
157
                                            + linkConfig.getActionCode());
158
                                        continue;
159
                                    }
160
                                    if (actionManager.hasPanel()) {
161
                                        ShowPanel lpanel =
162
                                            new ShowPanel(actionManager.createPanel(links[i]));
163
                                        // show the panel
164
                                        PluginServices.getMDIManager()
165
                                            .addWindow(lpanel);
166
                                    } else { // delegate in the format manager
167
                                             // to show the file
168
                                        actionManager.showDocument(links[i]);
169
                                    }
170
                                }
171
                            }
172
                        }
173
                    }
174
                }
175
            } catch (ClassNotFoundException e) {
176
                throw new BehaviorException("Hyperlink: There is no manager for this layer type",
177
                    e);
178
            } catch (InstantiationException e) {
179
                logger.error("Hyperlink error: " + e.getMessage(), e);
180
            } catch (IllegalAccessException e) {
181
                logger.error("Hyperlink error: " + e.getMessage(), e);
182
            } catch (IncompatibleLayerException e) {
183
                throw new BehaviorException("Hyperlink: There is no manager for this layer type",
184
                    e);
185
            }
186
        }
187
    }
188

  
189
    /**
190
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
191
     */
192
    public Cursor getCursor() {
193
        return cur;
194
    }
195

  
196
    /**
197
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
198
     */
199
    @Override
200
    public boolean cancelDrawing() {
201
        return false;
202
    }
203

  
204
    @Override
205
    public void pointDoubleClick(PointEvent event) throws BehaviorException {
206
        // TODO Auto-generated method stub
207

  
208
    }
209

  
210
    @Override
211
    public Image getImageCursor() {
212
    	return IconThemeHelper.getImage("cursor-view-show-hyperlink");
213
    }
214
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/LinkTarget.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.hyperlink.app.extension;
7

  
8
import java.io.File;
9
import java.net.URI;
10
import java.net.URL;
11

  
12
/**
13
 *
14
 * @author osc
15
 */
16
public interface LinkTarget {
17
    
18
    public URL getURL();
19
    
20
    public void setURL(URL url);
21
    
22
    public Object getFromProfile();
23
    
24
    public String getProfileName();
25
    
26
    public File toFile();
27
    
28
    public URI toURI();
29
    
30
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/config/LayerLinkConfig.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22

  
23
package org.gvsig.hyperlink.app.extension.config;
24

  
25
import java.util.ArrayList;
26
import java.util.List;
27

  
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynobject.DynStruct;
30
import org.gvsig.tools.persistence.PersistenceManager;
31
import org.gvsig.tools.persistence.Persistent;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34
import org.gvsig.tools.util.Callable;
35

  
36
public class LayerLinkConfig implements Persistent {
37

  
38
    protected List<LinkConfig> linkList;
39
    protected boolean enabled;
40
    public static final String LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME = "LayerLinkConfig";
41

  
42
    public LayerLinkConfig() {
43
        linkList = new ArrayList<LinkConfig>();
44
    }
45

  
46
    public void addLink(LinkConfig config) {
47
        linkList.add(config);
48
    }
49

  
50
    public void addLink(int position, LinkConfig config) {
51
        linkList.add(position, config);
52
    }
53

  
54
    public void addLink(String actionCode, String fieldName) {
55
        linkList.add(new LinkConfig(actionCode, fieldName));
56
    }
57

  
58
    public void addLink(String actionCode, String fieldName, String extension) {
59
        linkList.add(new LinkConfig(actionCode, fieldName, extension));
60
    }
61

  
62
    public LinkConfig removeLink(int linkIndex) {
63
        try {
64
            return linkList.remove(linkIndex);
65
        } catch (IndexOutOfBoundsException ex) {
66
            return null;
67
        }
68
    }
69

  
70
    public LinkConfig getLink(int index) {
71
        return linkList.get(index);
72
    }
73

  
74
    public int linkCount() {
75
        return linkList.size();
76
    }
77

  
78
    public String getClassName() {
79
        return this.getClass().getName();
80
    }
81

  
82
    public boolean isEnabled() {
83
        return enabled;
84
    }
85

  
86
    public void setEnabled(boolean enabled) {
87
        this.enabled = enabled;
88
    }
89

  
90
    public void saveToState(PersistentState state) throws PersistenceException {
91
        state.set("enabled", this.enabled);
92
        state.set("linkList", this.linkList);
93
    }
94

  
95
    @SuppressWarnings("unchecked")
96
    public void loadFromState(PersistentState state) throws PersistenceException {
97
        this.enabled = state.getBoolean("enabled");
98
        this.linkList = new ArrayList<LinkConfig>();
99
        this.linkList.addAll(state.getList("linkList"));
100
    }
101
    
102
    public static class RegisterPersistence implements Callable {
103

  
104
        public Object call() throws Exception {
105
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
106
            if( manager.getDefinition(LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME)==null ) {
107
                DynStruct definition = manager.addDefinition(
108
                        LayerLinkConfig.class,
109
                        LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME,
110
                        LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
111
                        null, 
112
                        null
113
                );
114

  
115
                definition.addDynFieldBoolean("enabled").setMandatory(true);
116
                definition.addDynFieldList("linkList").setMandatory(false).setClassOfItems(LinkConfig.class);
117
            }
118
            return Boolean.TRUE;
119
        }
120
        
121
    }
122

  
123
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/config/LinkConfig.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22

  
23
package org.gvsig.hyperlink.app.extension.config;
24

  
25
import org.gvsig.tools.ToolsLocator;
26
import org.gvsig.tools.dynobject.DynStruct;
27
import org.gvsig.tools.persistence.PersistenceManager;
28
import org.gvsig.tools.persistence.Persistent;
29
import org.gvsig.tools.persistence.PersistentState;
30
import org.gvsig.tools.persistence.exception.PersistenceException;
31
import org.gvsig.tools.util.Callable;
32

  
33
public class LinkConfig implements Persistent {
34

  
35
    private String fieldName;
36
    private String extension = "";
37
    private String actionCode;
38
    public static final String LINKCONFIG_PERSISTENCE_DEFINITION_NAME = "LinkConfig";
39

  
40
    public LinkConfig() {
41
    }
42

  
43
    public LinkConfig(String actionCode, String fieldName) {
44
        this.actionCode = actionCode;
45
        this.fieldName = fieldName;
46
    }
47

  
48
    public LinkConfig(String actionCode, String fieldName, String extension) {
49
        this.actionCode = actionCode;
50
        this.fieldName = fieldName;
51
        this.extension = extension;
52
    }
53

  
54
    public String getFieldName() {
55
        return fieldName;
56
    }
57

  
58
    public String getActionCode() {
59
        return actionCode;
60
    }
61

  
62
    public void setFieldName(String fieldName) {
63
        this.fieldName = fieldName;
64
    }
65

  
66
    public void setActionCode(String actionCode) {
67
        this.actionCode = actionCode;
68
    }
69

  
70
    public void setExtension(String extension) {
71
        this.extension = extension;
72
    }
73

  
74
    public String getExtension() {
75
        return extension;
76
    }
77

  
78
    public String getClassName() {
79
        return this.getClass().getName();
80
    }
81

  
82
    public void saveToState(PersistentState state) throws PersistenceException {
83
        state.set("fieldName", this.fieldName);
84
        state.set("extension", this.extension);
85
        state.set("actionCode", this.actionCode);
86
    }
87

  
88
    public void loadFromState(PersistentState state) throws PersistenceException {
89
        this.fieldName = state.getString("fieldName");
90
        this.extension = state.getString("extension");
91
        this.actionCode = state.getString("actionCode");
92
    }
93
    
94
    public static class RegisterPersistence implements Callable {
95

  
96
        public Object call() throws Exception {
97
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
98
            if( manager.getDefinition(LINKCONFIG_PERSISTENCE_DEFINITION_NAME)==null ) {
99
                DynStruct definition = manager.addDefinition(
100
                        LinkConfig.class,
101
                        LINKCONFIG_PERSISTENCE_DEFINITION_NAME,
102
                        LINKCONFIG_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
103
                        null, 
104
                        null
105
                );
106

  
107
                definition.addDynFieldString("fieldName").setMandatory(true);
108
                definition.addDynFieldString("extension").setMandatory(false);
109
                definition.addDynFieldString("actionCode").setMandatory(true);
110
            }
111
            return Boolean.TRUE;
112
        }
113
        
114
    }
115

  
116
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.237/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/config/gui/ConfigTab.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22

  
23
package org.gvsig.hyperlink.app.extension.config.gui;
24

  
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.awt.event.ItemEvent;
31
import java.awt.event.ItemListener;
32
import java.util.ArrayList;
33

  
34
import javax.swing.BorderFactory;
35
import javax.swing.JButton;
36
import javax.swing.JCheckBox;
37
import javax.swing.JPanel;
38
import javax.swing.JScrollPane;
39
import javax.swing.border.EtchedBorder;
40
import javax.swing.border.TitledBorder;
41

  
42
import org.gvsig.andami.PluginServices;
43
import org.gvsig.andami.ui.mdiManager.IWindow;
44
import org.gvsig.andami.ui.mdiManager.WindowInfo;
45
import org.gvsig.app.project.documents.view.legend.gui.AbstractThemeManagerPage;
46
import org.gvsig.fmap.mapcontext.layers.FLayer;
47
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
48
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
49
import org.gvsig.hyperlink.app.extension.HyperlinkExtension;
50
import org.gvsig.hyperlink.app.extension.config.LayerLinkConfig;
51
import org.gvsig.hyperlink.app.extension.config.LinkConfig;
52
import org.gvsig.hyperlink.app.extension.layers.ILinkLayerManager;
53
import org.gvsig.hyperlink.app.extension.layers.IncompatibleLayerException;
54
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry;
55
import org.gvsig.tools.ToolsLocator;
56
import org.gvsig.tools.extensionpoint.ExtensionPoint;
57

  
58
public class ConfigTab extends AbstractThemeManagerPage implements IWindow,
59
    ActionListener, ItemListener {
60

  
61
    FLayer layer;
62
    ArrayList rows = new ArrayList();
63
    JPanel rowList = null;
64
    GridBagLayout listLayout = null;
65
    private String[] actionCodes = null;
66
    private String[] actionNames = null;
67
    WindowInfo _windowInfo = null;
68
    JButton jbt_accept = null, jbt_cancel = null;
69
    JPanel emptyRow;
70
    JCheckBox jcb_enabled = null;
71
    JPanel borderPanel = null;
72
    JButton jbt_addAction = null, jbt_removeAction = null;
73

  
74
    public ConfigTab() {
75
        super();
76
        initialize();
77
    }
78

  
79
    private void initialize() {
80
        this.setLayout(new GridBagLayout());
81

  
82
        Insets insets = new Insets(8, 8, 8, 8);
83
        GridBagConstraints constraints = new GridBagConstraints();
84
        constraints.gridx = 0;
85
        constraints.gridy = 0;
86
        constraints.weightx = 1.0;
87
        constraints.fill = GridBagConstraints.NONE;
88
        constraints.insets = insets;
89
        constraints.anchor = GridBagConstraints.NORTHWEST;
90
        this.add(getEnabledCheckBox(), constraints);
91

  
92
        borderPanel = new JPanel(new GridBagLayout());
93
        borderPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
94
            PluginServices.getText(this, "Actions"),
95
            TitledBorder.DEFAULT_JUSTIFICATION,
96
            TitledBorder.DEFAULT_POSITION,
97
            null,
98
            null));
99

  
100
        insets = new Insets(8, 8, 8, 8);
101
        constraints = new GridBagConstraints();
102
        constraints.gridx = 0;
103
        constraints.gridy = 0;
104
        constraints.weightx = 1.0;
105
        constraints.fill = GridBagConstraints.NONE;
106
        constraints.insets = insets;
107
        constraints.anchor = GridBagConstraints.NORTHWEST;
108
        borderPanel.add(getAddRemoveActionsPanel(), constraints);
109

  
110
        listLayout = new GridBagLayout();
111
        rowList = new JPanel(listLayout);
112

  
113
        constraints.gridx = 0;
114
        constraints.gridy = 0;
115
        constraints.weightx = 1.0;
116
        constraints.weighty = 1.0;
117
        constraints.fill = GridBagConstraints.NONE;
118
        constraints.insets = insets;
119
        constraints.anchor = GridBagConstraints.SOUTH;
120
        emptyRow = new JPanel();
121
        rowList.add(emptyRow, constraints);
122

  
123
        JScrollPane scrolledList = new JScrollPane();
124
        scrolledList.setBorder(null);
125
        scrolledList.setViewportView(rowList);
126

  
127
        constraints.gridx = 0;
128
        constraints.gridy = 1;
129
        constraints.weightx = 1.0;
130
        constraints.weighty = 1.0;
131
        constraints.fill = GridBagConstraints.BOTH;
132
        constraints.insets = insets;
133
        constraints.anchor = GridBagConstraints.CENTER;
134
        borderPanel.add(scrolledList, constraints);
135

  
136
        constraints.gridx = 0;
137
        constraints.gridy = 1;
138
        constraints.weightx = 1.0;
139
        constraints.weighty = 1.0;
140
        constraints.fill = GridBagConstraints.BOTH;
141
        constraints.insets = insets;
142
        constraints.anchor = GridBagConstraints.NORTHWEST;
143
        this.add(borderPanel, constraints);
144

  
145
        // initAcceptCancelButtons(); uncomment this if you want to use this
146
        // window outside the ThemeManager
147
    }
148

  
149
    private void initAcceptCancelButtons() {
150
        JPanel acceptCancelButtons = new JPanel(new GridBagLayout());
151
        Insets insets = new Insets(14, 4, 8, 8);
152
        GridBagConstraints constraints = new GridBagConstraints();
153
        constraints.gridx = 0;
154
        constraints.gridy = 0;
155
        constraints.weightx = 1.0;
156
        constraints.fill = GridBagConstraints.NONE;
157
        constraints.insets = insets;
158
        constraints.anchor = GridBagConstraints.EAST;
159
        acceptCancelButtons.add(getAcceptButton(), constraints);
160

  
161
        constraints.gridx = 1;
162
        constraints.gridy = 0;
163
        constraints.weightx = 0.0;
164
        constraints.fill = GridBagConstraints.NONE;
165
        constraints.insets = insets;
166
        constraints.anchor = GridBagConstraints.EAST;
167
        acceptCancelButtons.add(getCancelButton(), constraints);
168

  
169
        constraints.gridx = 0;
170
        constraints.gridy = 2;
171
        constraints.weightx = 0.0;
172
        constraints.fill = GridBagConstraints.NONE;
173
        constraints.insets = insets;
174
        constraints.anchor = GridBagConstraints.SOUTHEAST;
175
        this.add(acceptCancelButtons, constraints);
176
    }
177

  
178
    private String[] getActionNames() {
179
        if (actionNames == null) {
180
            ExtensionPoint actions =
181
                ToolsLocator.getExtensionPointManager()
182
                    .get(HyperlinkExtension.ACTIONSEXTENSIONPOINT);
183

  
184
            String[] actionArray = new String[actions.getCount()];
185
            String[] codes = getActionCodes();
186
            for (int i = 0; i < codes.length; i++) {
187
                try {
188
                    AbstractActionManager aam =
189
                        (AbstractActionManager) actions.get(codes[i])
190
                            .getExtension()
191
                            .newInstance();
192
                    actionArray[i] = aam.getName();
193
                } catch (InstantiationException e) {
194
                    // TODO Auto-generated catch block
195
                    e.printStackTrace();
196
                } catch (IllegalAccessException e) {
197
                    // TODO Auto-generated catch block
198
                    e.printStackTrace();
199
                }
200
            }
201
            actionNames = actionArray;
202
        }
203
        return actionNames;
204
    }
205

  
206
    private String[] getActionCodes() {
207
        if (actionCodes == null) {
208
            ExtensionPoint actions =
209
                ToolsLocator.getExtensionPointManager()
210
                    .get(HyperlinkExtension.ACTIONSEXTENSIONPOINT);
211
            String[] actionArray = new String[actions.getCount()];
212
            actionArray = (String[]) actions.getNames().toArray(actionArray);
213
            actionCodes = actionArray;
214
        }
215
        return actionCodes;
216
    }
217

  
218
    private String[] getCandidateFields() {
219
        HyperlinkExtension ext =
220
            (HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class);
221
        ManagerRegistry registry = ext.getLayerManager();
222
        try {
223
            ILinkLayerManager manager;
224
            manager = registry.get(layer);
225
            manager.setLayer(layer);
226
            return manager.getFieldCandidates();
227
        } catch (InstantiationException e) {
228
            PluginServices.getLogger()
229
                .warn("Hyperlink: error getting candidate fields", e);
230
        } catch (IllegalAccessException e) {
231
            PluginServices.getLogger()
232
                .warn("Hyperlink: error getting candidate fields", e);
233
        } catch (ClassNotFoundException e) {
234
            PluginServices.getLogger()
235
                .warn("Hyperlink: error getting candidate fields", e);
236
        } catch (IncompatibleLayerException e) {
237
            PluginServices.getLogger()
238
                .warn("Hyperlink: error getting candidate fields", e);
239
        } catch (NullPointerException e) {
240
            PluginServices.getLogger().warn("Hyperlink: error getting manager", e);
241
        }
242
        return new String[0];
243
    }
244

  
245
    public void acceptAction() {
246
        applyAction();
247
    }
248

  
249
    public void applyAction() {
250
        LayerLinkConfig config = new LayerLinkConfig();
251
        for (int i = 0; i < rows.size(); i++) {
252
            LinkRow row = (LinkRow) rows.get(i);
253
            
254
            if (row.getSelectedField() != null
255
                && row.getSelectedAction() != -1) {
256
                
257
                config.addLink(getActionCodes()[row.getSelectedAction()],
258
                    row.getSelectedField(),
259
                    row.getExtension());
260
            }
261
        }
262
        config.setEnabled(getEnabledCheckBox().isSelected());
263
        layer.setProperty(HyperlinkExtension.LAYERPROPERTYNAME, config);
264
    }
265

  
266
    public void cancelAction() {
267
    }
268

  
269
    public String getName() {
270
        return PluginServices.getText(this, "Hyperlink");
271
    }
272

  
273
    public void setModel(FLayer layer) {
274
        this.layer = layer;
275
        if( layer!=null && !layer.isAvailable() ) {
276
            setLinkEnabled(false);
277
            getEnabledCheckBox().setEnabled(false);
278
            return;
279
        }
280
        synchronized (rows) {
281
            HyperlinkExtension ext =
282
                (HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class);
283
            LayerLinkConfig layerConfig = ext.loadLegacyConfig(layer);
284
            for (int i = rows.size() - 1; i >= 0; i--) { // clean rows
285
                LinkRow row = (LinkRow) rows.remove(i);
286
                rowList.remove(row);
287
            }
288

  
289
            if (layerConfig != null) {
290
                for (int i = 0; i < layerConfig.linkCount(); i++) {
291
                    LinkRow row = addRow();
292
                    LinkConfig config = layerConfig.getLink(i);
293
                    String selectedAction = config.getActionCode();
294
                    String[] actions = getActionCodes();
295
                    for (int j = 0; j < actions.length; j++) {
296
                        if (actions[j].equals(selectedAction)) {
297
                            row.setSelectedAction(j);
298
                        }
299
                    }
300
                    row.setSelectedField(config.getFieldName());
301
                    row.setExtension(config.getExtension());
302
                }
303
                if (layerConfig.linkCount() < 1) {
304
                    addRow(); // just one row by default
305
                }
306
                setLinkEnabled(layerConfig.isEnabled());
307
            } else {
308
                addRow(); // just one row by default
309
                setLinkEnabled(false);
310
            }
311
        }
312
    }
313

  
314
    protected JPanel getAddRemoveActionsPanel() {
315
        JPanel container = new JPanel();
316
        container.add(getAddActionButton());
317
        container.add(getRemoveActionButton());
318
        return container;
319
    }
320

  
321
    protected LinkRow addRow() {
322
        LinkRow row = new LinkRow();
323
        row.setFields(getCandidateFields());
324
        row.setActions(getActionNames());
325
        synchronized (rows) {
326
            rows.add(row);
327

  
328
            GridBagConstraints constraints = new GridBagConstraints();
329
            constraints.gridx = 0;
330
            constraints.gridy = rows.size() - 1;
331
            constraints.weightx = 1.0;
332
            constraints.weighty = 0.0;
333
            constraints.fill = GridBagConstraints.HORIZONTAL;
334
            constraints.insets = new Insets(2, 4, 2, 4);
335
            constraints.anchor = GridBagConstraints.NORTH;
336
            rowList.add(row, constraints);
337

  
338
            constraints = new GridBagConstraints();
339
            constraints.gridx = 0;
340
            constraints.gridy = rows.size();
341
            constraints.weightx = 1.0;
342
            constraints.weighty = 1.0;
343
            constraints.fill = GridBagConstraints.NONE;
344
            constraints.anchor = GridBagConstraints.CENTER;
345
            listLayout.setConstraints(emptyRow, constraints);
346
        }
347
        validate();
348
        return row;
349
    }
350

  
351
    protected boolean removeBottomRow() {
352
        LinkRow row;
353
        synchronized (rows) {
354
            if (rows.size() <= 1)
355
                return false;
356
            row = (LinkRow) rows.get(rows.size() - 1);
357
            rows.remove(rows.size() - 1);
358
        }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff