Revision 41219

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/OpenInitialProjectExtension.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.extension;
25

  
26
import java.io.File;
27

  
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.PluginsLocator;
33
import org.gvsig.andami.plugins.Extension;
34
import org.gvsig.app.project.Project;
35

  
36
/**
37
 * This class simply adds a task to the list of additional
38
 * tasks to be executed by the plugins manager. The task consists
39
 * in opening the project found in the parameters list.
40
 * 
41
 * The Launcher will call the correct method to start the tasks
42
 * after all plugins have been loaded
43
 * 
44
 * @author jldominguez
45
 *
46
 */
47
public class OpenInitialProjectExtension extends Extension {
48

  
49
    private static final Logger LOG = LoggerFactory
50
        .getLogger(OpenInitialProjectExtension.class);
51
            
52
    public void initialize() {
53
        PluginsLocator.getManager().addTask(
54
            new OpenInitialProjectTask(), true, 0);
55
    }
56

  
57
    public void execute(String actionCommand) {
58
    }
59

  
60
    public boolean isEnabled() {
61
        return false;
62
    }
63

  
64
    public boolean isVisible() {
65
        return false;
66
    }
67
    
68
    
69
    
70
    
71
    private class OpenInitialProjectTask implements Runnable {
72

  
73
        public void run() {
74
            
75
            File pf = getInitialProjectFile();
76
            if (pf != null) {
77
                
78
                ProjectExtension pext = null;
79
                pext = (ProjectExtension)
80
                    PluginsLocator.getManager().getExtension(ProjectExtension.class);
81
                
82
                Object[] args = new Object[1];
83
                args[0] = pf;
84
                pext.execute("application-project-open", args);
85
            } else {
86
                LOG.info("No initial file opened.");
87
            }            
88
        }
89
        
90
        
91
        /**
92
         * Returns file to be opened or null if no parameter
93
         * or file does not exist
94
         * 
95
         * @return
96
         */
97
        private File getInitialProjectFile() {
98
            String[] theArgs = PluginServices.getArguments();
99
            String lastArg = theArgs[theArgs.length - 1];
100
            if (lastArg != null) {
101
                if (lastArg.toLowerCase().endsWith(
102
                        Project.FILE_EXTENSION.toLowerCase())) {
103

  
104
                    File projectFile = new File(lastArg);
105
                    if (projectFile.exists()) {
106
                        return projectFile;
107
                    } else {
108
                        LOG.info("initial file des not exist: " + lastArg);
109
                        return null;
110
                    }
111
                }
112
            }
113
            return null;
114
            
115
        }   
116
        
117
    }
118

  
119
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/config.xml
70 70
      priority="99999">
71 71
    </extension>
72 72

  
73
    <extension class-name="org.gvsig.app.extension.OpenInitialProjectExtension"
74
      description="Open initial project"
75
      active="true"
76
      priority="1">
77
    </extension>
78

  
73 79
    <extension class-name="org.gvsig.app.extension.ProjectExtension"
74 80
      description="Extensi?n encargada de gestionar los proyectos."
75 81
      active="true"

Also available in: Unified diff