Revision 41314 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ProjectExtension.java
ProjectExtension.java | ||
---|---|---|
106 | 106 |
initializeDocumentActionsExtensionPoint(); |
107 | 107 |
registerDocuments(); |
108 | 108 |
registerIcons(); |
109 |
PluginsLocator.getManager().addStartupTask( |
|
109 |
|
|
110 |
File projectFile = getProjectFileFromArguments(); |
|
111 |
if( projectFile!=null ) { |
|
112 |
// Posponemos la apertura del proyecto ya que en este momento |
|
113 |
// puede que no este inicializado algun plugin que precise el |
|
114 |
// proyecto para poderse cargar. |
|
115 |
PluginsLocator.getManager().addStartupTask( |
|
110 | 116 |
"Open project", |
111 |
new OpenInitialProjectTask(), true, 1000); |
|
117 |
new OpenInitialProjectTask(projectFile), true, 1000); |
|
118 |
} |
|
112 | 119 |
} |
113 | 120 |
|
114 | 121 |
private void registerIcons() { |
... | ... | |
123 | 130 |
IconThemeHelper.registerIcon("project", "project-icon", this); |
124 | 131 |
} |
125 | 132 |
|
133 |
/** |
|
134 |
* Returns the file to be opened or null if no parameter |
|
135 |
* or file does not exist |
|
136 |
* |
|
137 |
* @return |
|
138 |
*/ |
|
139 |
private File getProjectFileFromArguments() { |
|
140 |
String[] theArgs = PluginServices.getArguments(); |
|
141 |
if( theArgs.length< 3 ) { |
|
142 |
// application-name and extensions-folder are fixed arguments |
|
143 |
return null; |
|
144 |
} |
|
145 |
String lastArg = theArgs[theArgs.length - 1]; |
|
146 |
if ( StringUtils.isEmpty(lastArg) ) { |
|
147 |
return null; |
|
148 |
} |
|
149 |
if( lastArg.startsWith("-") ) { |
|
150 |
// Args starts with "-" are flags |
|
151 |
return null; |
|
152 |
} |
|
153 |
if (!lastArg.toLowerCase().endsWith(Project.FILE_EXTENSION.toLowerCase())) { |
|
154 |
LOG.info("Do not open project file, does not have the expected extension '" + |
|
155 |
Project.FILE_EXTENSION +"' ("+lastArg+")."); |
|
156 |
return null; |
|
157 |
} |
|
158 |
File projectFile = new File(lastArg); |
|
159 |
if ( !projectFile.exists()) { |
|
160 |
LOG.info("Do not open project file, '" +projectFile.getAbsolutePath() + "' do not exist."); |
|
161 |
return null; |
|
162 |
} |
|
163 |
return projectFile; |
|
164 |
} |
|
165 |
|
|
126 | 166 |
private class OpenInitialProjectTask implements Runnable { |
167 |
private File projectFile; |
|
168 |
public OpenInitialProjectTask(File projectFile) { |
|
169 |
this.projectFile = projectFile; |
|
170 |
} |
|
127 | 171 |
public void run() { |
128 |
File pf = getInitialProjectFile(); |
|
129 |
if (pf == null) { |
|
130 |
LOG.info("No initial file opened."); |
|
172 |
if (this.projectFile == null) { |
|
131 | 173 |
return; |
132 | 174 |
} |
133 | 175 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
134 | 176 |
ActionInfo action = actionManager.getAction("application-project-open"); |
135 |
action.execute(pf);
|
|
177 |
action.execute(this.projectFile);
|
|
136 | 178 |
} |
137 |
/** |
|
138 |
* Returns the file to be opened or null if no parameter |
|
139 |
* or file does not exist |
|
140 |
* |
|
141 |
* @return |
|
142 |
*/ |
|
143 |
private File getInitialProjectFile() { |
|
144 |
String[] theArgs = PluginServices.getArguments(); |
|
145 |
String lastArg = theArgs[theArgs.length - 1]; |
|
146 |
if ( StringUtils.isEmpty(lastArg) ) { |
|
147 |
return null; |
|
148 |
} |
|
149 |
if( lastArg.startsWith("-") ) { |
|
150 |
return null; |
|
151 |
} |
|
152 |
if (!lastArg.toLowerCase().endsWith(Project.FILE_EXTENSION.toLowerCase())) { |
|
153 |
LOG.info("Do not open project file, does not have the expected extension '" + |
|
154 |
Project.FILE_EXTENSION +"' ("+lastArg+")."); |
|
155 |
return null; |
|
156 |
} |
|
157 |
File projectFile = new File(lastArg); |
|
158 |
if ( !projectFile.exists()) { |
|
159 |
LOG.info("Do not open project file, '" +projectFile.getAbsolutePath() + "' do not exist."); |
|
160 |
return null; |
|
161 |
} |
|
162 |
return projectFile; |
|
163 |
} |
|
164 | 179 |
} |
165 | 180 |
|
166 | 181 |
public ProjectWindow getProjectFrame() { |
Also available in: Unified diff