Révision 2556
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/ApplicationWorkbenchAdvisor.java (revision 2556) | ||
|---|---|---|
| 113 | 113 |
import org.txm.rcp.perspective.TXMPerspective; |
| 114 | 114 |
import org.txm.rcp.preferences.RCPPreferences; |
| 115 | 115 |
import org.txm.rcp.utils.JobHandler; |
| 116 |
import org.txm.rcp.utils.SWTEditorsUtils; |
|
| 116 | 117 |
import org.txm.utils.BundleUtils; |
| 117 | 118 |
import org.txm.utils.DeleteDir; |
| 118 | 119 |
import org.txm.utils.io.IOUtils; |
| ... | ... | |
| 122 | 123 |
* Manages the opening and closing of TXM |
| 123 | 124 |
*/ |
| 124 | 125 |
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
|
| 125 |
|
|
| 126 |
|
|
| 126 | 127 |
private boolean installPreferenceRestored; |
| 128 |
|
|
| 127 | 129 |
private IOConsoleOutputStream stream; |
| 130 |
|
|
| 128 | 131 |
private IOConsoleInputStream streamInput; |
| 129 |
|
|
| 130 |
/* (non-Javadoc) |
|
| 132 |
|
|
| 133 |
/* |
|
| 134 |
* (non-Javadoc) |
|
| 131 | 135 |
* @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer) |
| 132 | 136 |
*/ |
| 133 | 137 |
@Override |
| 134 | 138 |
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
|
| 135 | 139 |
return new ApplicationWorkbenchWindowAdvisor(configurer); |
| 136 | 140 |
} |
| 137 |
|
|
| 141 |
|
|
| 138 | 142 |
@Override |
| 139 | 143 |
public IAdaptable getDefaultPageInput() {
|
| 140 | 144 |
org.eclipse.core.resources.IWorkspace workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace(); |
| 141 | 145 |
return workspace.getRoot(); |
| 142 | 146 |
} |
| 143 |
|
|
| 147 |
|
|
| 144 | 148 |
/** |
| 145 | 149 |
* initialization code done after the splash screen. |
| 146 | 150 |
* |
| ... | ... | |
| 149 | 153 |
@Override |
| 150 | 154 |
public void initialize(IWorkbenchConfigurer configurer) {
|
| 151 | 155 |
org.eclipse.ui.ide.IDE.registerAdapters(); |
| 152 |
|
|
| 153 |
//WorkbenchAdapterBuilder.registerAdapters(); // deprecated |
|
| 156 |
|
|
| 157 |
// WorkbenchAdapterBuilder.registerAdapters(); // deprecated
|
|
| 154 | 158 |
PlatformUI.getPreferenceStore().setValue( |
| 155 | 159 |
IWorkbenchPreferenceConstants.SHOW_PROGRESS_ON_STARTUP, true); |
| 156 | 160 |
InitializeLogger(); |
| 157 |
|
|
| 161 |
|
|
| 158 | 162 |
configurer.setSaveAndRestore(true); |
| 159 | 163 |
} |
| 160 |
|
|
| 164 |
|
|
| 161 | 165 |
@Override |
| 162 | 166 |
public void preStartup() {
|
| 163 |
|
|
| 167 |
|
|
| 164 | 168 |
} |
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 168 | 172 |
/** |
| 169 | 173 |
* Set Eclipse Theme depending on the OS |
| 170 | 174 |
*/ |
| ... | ... | |
| 172 | 176 |
private void setDefaultTheme() {
|
| 173 | 177 |
Bundle b = FrameworkUtil.getBundle(getClass()); |
| 174 | 178 |
BundleContext context = b.getBundleContext(); |
| 175 |
|
|
| 179 |
|
|
| 176 | 180 |
ServiceReference serviceRef = context.getServiceReference(IThemeManager.class.getName()); |
| 177 | 181 |
@SuppressWarnings("unchecked")
|
| 178 | 182 |
IThemeManager themeManager = (IThemeManager) context.getService(serviceRef); |
| 179 | 183 |
IThemeEngine engine = themeManager.getEngineForDisplay(Display.getDefault()); |
| 180 |
|
|
| 184 |
|
|
| 181 | 185 |
String theme = "org.txm.rcp.theme.default.linux"; //$NON-NLS-1$ |
| 182 |
|
|
| 183 |
if (Util.isWindows()) { //$NON-NLS-1$
|
|
| 186 |
|
|
| 187 |
if (Util.isWindows()) {
|
|
| 184 | 188 |
theme = "org.txm.rcp.theme.default.windows"; //$NON-NLS-1$ |
| 185 |
} else if (Util.isMac()) { //$NON-NLS-1$
|
|
| 189 |
} |
|
| 190 |
else if (Util.isMac()) {
|
|
| 186 | 191 |
theme = "org.txm.rcp.theme.default.mac"; //$NON-NLS-1$ |
| 187 | 192 |
} |
| 188 |
|
|
| 193 |
|
|
| 189 | 194 |
engine.setTheme(theme, true); |
| 190 | 195 |
} |
| 191 |
|
|
| 196 |
|
|
| 192 | 197 |
/** |
| 193 | 198 |
* initialization code done after the splash screen call a job which does the |
| 194 | 199 |
* post installation the TXMHOME, checks the TreeTagger and finally |
| ... | ... | |
| 196 | 201 |
*/ |
| 197 | 202 |
@Override |
| 198 | 203 |
public void postStartup() {
|
| 199 |
|
|
| 200 |
try {
|
|
| 204 |
|
|
| 205 |
try {
|
|
| 201 | 206 |
// create the Toolbox initialization job |
| 202 | 207 |
JobHandler jobhandler = new JobHandler(TXMUIMessages.initializationOfThePlatform, true) {
|
| 208 |
|
|
| 203 | 209 |
@Override |
| 204 | 210 |
protected IStatus run(final IProgressMonitor monitor) {
|
| 205 | 211 |
JobsTimer.start(); |
| 206 | 212 |
this.runInit(monitor); |
| 207 | 213 |
try {
|
| 208 |
|
|
| 214 |
|
|
| 209 | 215 |
monitor.beginTask(TXMUIMessages.startingTxm, 100); |
| 210 |
|
|
| 216 |
|
|
| 211 | 217 |
monitor.setTaskName(TXMUIMessages.loadingTXMInstallPreferences); |
| 212 | 218 |
Log.fine(TXMUIMessages.startJobColonLoadInstallPreferences); |
| 213 | 219 |
if (!checkInstallDirectory(this)) {
|
| ... | ... | |
| 216 | 222 |
return Status.CANCEL_STATUS; |
| 217 | 223 |
} |
| 218 | 224 |
monitor.worked(10); |
| 219 |
|
|
| 225 |
|
|
| 220 | 226 |
monitor.setTaskName(TXMUIMessages.checkingForExistingWorkspaceDirectory); |
| 221 | 227 |
Log.warning(TXMUIMessages.startJobColonCheckTXMHOME); |
| 222 | 228 |
if (!checkTXMHOME(this, monitor)) {
|
| ... | ... | |
| 224 | 230 |
System.err.println(TXMUIMessages.errorsOccuredDuringTXMPostInstallation); |
| 225 | 231 |
} |
| 226 | 232 |
monitor.worked(30); |
| 227 |
|
|
| 228 |
//INITIALIZE TBX AND UI |
|
| 233 |
|
|
| 234 |
// INITIALIZE TBX AND UI
|
|
| 229 | 235 |
monitor.setTaskName(TXMUIMessages.initializingPlatform); |
| 230 | 236 |
Log.warning(TXMUIMessages.startJobColonInitializeUI); |
| 231 | 237 |
if (!initializeUI(this)) {
|
| 232 | 238 |
monitor.done(); |
| 233 | 239 |
return Status.CANCEL_STATUS; |
| 234 | 240 |
} |
| 235 |
|
|
| 241 |
|
|
| 236 | 242 |
Log.info(TXMUIMessages.info_txmIsReady); |
| 237 | 243 |
monitor.done(); |
| 238 |
} catch (Exception e) {
|
|
| 244 |
} |
|
| 245 |
catch (Exception e) {
|
|
| 239 | 246 |
System.out.println(TXMCoreMessages.bind(TXMUIMessages.errorWhileLoadingTXMColon, e)); |
| 240 | 247 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 241 |
} catch(ThreadDeath td) {
|
|
| 248 |
} |
|
| 249 |
catch (ThreadDeath td) {
|
|
| 242 | 250 |
System.out.println(TXMUIMessages.TXMInitializationHasBeenCanceledByUserDotPleaseRestartTXM); |
| 243 | 251 |
} |
| 244 |
|
|
| 252 |
|
|
| 245 | 253 |
JobsTimer.stopAndPrint(); |
| 246 | 254 |
return Status.OK_STATUS; |
| 247 | 255 |
} |
| 248 | 256 |
}; |
| 249 | 257 |
jobhandler.startJob(); |
| 250 |
|
|
| 258 |
|
|
| 251 | 259 |
// start update NOT IN A JOB |
| 252 | 260 |
startUpdateLookUpJob(false); |
| 253 |
|
|
| 254 |
} catch (Exception e) {
|
|
| 261 |
|
|
| 262 |
} |
|
| 263 |
catch (Exception e) {
|
|
| 255 | 264 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.startupFailedPleaseCheckTXMPreferencesInTheFileSupPreferencesMenuOrContactTxmusersMailingListMenuColonHelpSup, e.getMessage())); |
| 256 | 265 |
System.out.println(TXMCoreMessages.bind(TXMUIMessages.startupFailedPleaseCheckTXMPreferencesInTheFileSupPreferencesMenuOrContactTxmusersMailingListMenuColonHelpSup, e.getMessage())); |
| 257 | 266 |
Log.printStackTrace(e); |
| 258 | 267 |
} |
| 259 | 268 |
} |
| 260 |
|
|
| 269 |
|
|
| 261 | 270 |
public static void closeEmptyEditors(boolean closeOthersEditors) {
|
| 262 | 271 |
Log.fine("Closing empty editors..."); //$NON-NLS-1$
|
| 263 | 272 |
String REF = "org.eclipse.ui.internal.emptyEditorTab"; //$NON-NLS-1$ |
| 264 |
|
|
| 265 |
for (final IWorkbenchPage page : DeleteObject.getPages()) {
|
|
| 266 |
ArrayList<IEditorReference> editorRefsList = new ArrayList<IEditorReference>();
|
|
| 273 |
|
|
| 274 |
for (final IWorkbenchPage page : SWTEditorsUtils.getPages()) {
|
|
| 275 |
ArrayList<IEditorReference> editorRefsList = new ArrayList<>(); |
|
| 267 | 276 |
for (IEditorReference editorref : page.getEditorReferences()) {
|
| 268 | 277 |
if (closeOthersEditors || editorref.getId().equals(REF)) {
|
| 269 |
Log.fine(TXMUIMessages.closingColon+editorref.getId());
|
|
| 278 |
Log.fine(TXMUIMessages.closingColon + editorref.getId());
|
|
| 270 | 279 |
editorRefsList.add(editorref); |
| 271 | 280 |
} |
| 272 | 281 |
} |
| 273 |
|
|
| 282 |
|
|
| 274 | 283 |
final IEditorReference[] editorRefs = editorRefsList.toArray(new IEditorReference[editorRefsList.size()]); |
| 275 | 284 |
Display.getDefault().syncExec(new Runnable() {
|
| 276 |
|
|
| 285 |
|
|
| 277 | 286 |
@Override |
| 278 | 287 |
public void run() {
|
| 279 | 288 |
page.closeEditors(editorRefs, false); |
| ... | ... | |
| 281 | 290 |
}); |
| 282 | 291 |
} |
| 283 | 292 |
} |
| 284 |
|
|
| 293 |
|
|
| 285 | 294 |
public static void printTXMVersion() {
|
| 286 |
|
|
| 295 |
|
|
| 287 | 296 |
String version = null; |
| 288 | 297 |
|
| 289 | 298 |
// try finding build date from the p2 artifacts file in installation directory |
| 290 | 299 |
String path = BundleUtils.getInstallDirectory(); |
| 291 | 300 |
if (path != null) {
|
| 292 | 301 |
File installDirectory = new File(path); |
| 293 |
//println "installDirectory=$installDirectory" |
|
| 302 |
// println "installDirectory=$installDirectory"
|
|
| 294 | 303 |
if (installDirectory.exists()) {
|
| 295 | 304 |
File artifacts = new File(installDirectory, "p2/org.eclipse.equinox.p2.core/cache/artifacts.xml"); |
| 296 |
//println "artifacts=$artifacts" |
|
| 305 |
// println "artifacts=$artifacts"
|
|
| 297 | 306 |
if (artifacts.exists() && artifacts.canRead()) {
|
| 298 | 307 |
try {
|
| 299 | 308 |
String content = IOUtils.getText(artifacts); |
| 300 | 309 |
String ARTIFACT = "<artifact classifier='binary' id='org.txm.rcp.app_root"; |
| 301 | 310 |
int start = content.indexOf(ARTIFACT); |
| 302 |
//println "start=$start" |
|
| 311 |
// println "start=$start"
|
|
| 303 | 312 |
if (start > 0) {
|
| 304 | 313 |
String VERSION = "version='"; |
| 305 |
int versionStart = content.indexOf(VERSION, start+ARTIFACT.length());
|
|
| 306 |
//println "versionStart=$versionStart" |
|
| 314 |
int versionStart = content.indexOf(VERSION, start + ARTIFACT.length());
|
|
| 315 |
// println "versionStart=$versionStart"
|
|
| 307 | 316 |
if (versionStart > 0) {
|
| 308 |
int versionEnd = content.indexOf("'", versionStart+VERSION.length());
|
|
| 317 |
int versionEnd = content.indexOf("'", versionStart + VERSION.length());
|
|
| 309 | 318 |
if (versionEnd > 0) {
|
| 310 |
version = content.substring(versionStart+VERSION.length(), versionEnd);
|
|
| 311 |
// System.out.println("VERSION="+version);
|
|
| 319 |
version = content.substring(versionStart + VERSION.length(), versionEnd);
|
|
| 320 |
// System.out.println("VERSION="+version);
|
|
| 312 | 321 |
} |
| 313 | 322 |
} |
| 314 | 323 |
} |
| 315 |
} catch (IOException e) {
|
|
| 324 |
} |
|
| 325 |
catch (IOException e) {
|
|
| 316 | 326 |
// TODO Auto-generated catch block |
| 317 | 327 |
e.printStackTrace(); |
| 318 | 328 |
} |
| 319 | 329 |
} |
| 320 | 330 |
} |
| 321 | 331 |
} |
| 322 |
|
|
| 323 |
|
|
| 332 |
|
|
| 333 |
|
|
| 324 | 334 |
if (version == null) {
|
| 325 |
version = Activator.getDefault().getBundle().getVersion().toString();
|
|
| 335 |
version = Activator.getDefault().getBundle().getVersion().toString(); |
|
| 326 | 336 |
} |
| 327 | 337 |
|
| 328 | 338 |
String date = version.replaceAll("(.\\..\\..)\\.(....)(..)(..)(..)(..)", "$2-$3-$4 $5h$6"); //$NON-NLS-1$ //$NON-NLS-2$
|
| 329 | 339 |
|
| 330 |
System.out.println(NLS.bind(TXMUIMessages.startingUpP0,
|
|
| 331 |
Activator.getDefault().getBundle().getVersion().toString(), date)); |
|
| 340 |
System.out.println(NLS.bind(TXMUIMessages.startingUpP0, |
|
| 341 |
Activator.getDefault().getBundle().getVersion().toString(), date));
|
|
| 332 | 342 |
} |
| 333 |
|
|
| 343 |
|
|
| 334 | 344 |
private void setPreferencesConfiguration() {
|
| 335 | 345 |
PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager(); |
| 336 |
|
|
| 346 |
|
|
| 337 | 347 |
// Remove RCP Update preference page |
| 338 | 348 |
if (!TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
| 339 | 349 |
Log.fine(TXMUIMessages.removeUnusedEclipseRCPPreferencePage); |
| 340 | 350 |
pm.remove("org.eclipse.equinox.internal.p2.ui.sdk.ProvisioningPreferencePage"); //$NON-NLS-1$
|
| 341 |
|
|
| 351 |
|
|
| 342 | 352 |
// Remove the Team menu |
| 343 | 353 |
pm.remove("org.eclipse.team.ui.TeamPreferences"); //$NON-NLS-1$
|
| 344 |
|
|
| 354 |
|
|
| 345 | 355 |
// XML |
| 346 |
//pm.remove("org.eclipse.wst.xml.ui.preferences.xml"); //$NON-NLS-1$
|
|
| 347 |
|
|
| 356 |
// pm.remove("org.eclipse.wst.xml.ui.preferences.xml"); //$NON-NLS-1$
|
|
| 357 |
|
|
| 348 | 358 |
// Validation |
| 349 |
//pm.remove("ValidationPreferencePage"); //$NON-NLS-1$
|
|
| 350 |
|
|
| 359 |
// pm.remove("ValidationPreferencePage"); //$NON-NLS-1$
|
|
| 360 |
|
|
| 351 | 361 |
// Debug |
| 352 |
//pm.remove("org.eclipse.debug.ui.DebugPreferencePage"); //$NON-NLS-1$
|
|
| 362 |
// pm.remove("org.eclipse.debug.ui.DebugPreferencePage"); //$NON-NLS-1$
|
|
| 353 | 363 |
} |
| 354 | 364 |
// Remove RCP Web browser preference page |
| 355 | 365 |
IPreferenceNode[] arr = pm.getRootSubNodes(); |
| 356 |
for(IPreferenceNode pn : arr){
|
|
| 357 |
// System.out.println("Label:" + pn.getLabelText() + " ID:" + pn.getId()+" Type: "+pn.getClass());
|
|
| 358 |
// for (IPreferenceNode subn : pn.getSubNodes()) {
|
|
| 359 |
// System.out.println(" SLabel:" + subn.getLabelText() + " ID:" + subn.getId());
|
|
| 360 |
// }
|
|
| 366 |
for (IPreferenceNode pn : arr) {
|
|
| 367 |
// System.out.println("Label:" + pn.getLabelText() + " ID:" + pn.getId()+" Type: "+pn.getClass());
|
|
| 368 |
// for (IPreferenceNode subn : pn.getSubNodes()) {
|
|
| 369 |
// System.out.println(" SLabel:" + subn.getLabelText() + " ID:" + subn.getId());
|
|
| 370 |
// }
|
|
| 361 | 371 |
if ("org.eclipse.ui.preferencePages.Workbench".equals(pn.getId())) { //$NON-NLS-1$
|
| 362 |
WorkbenchPreferenceNode pwn = (WorkbenchPreferenceNode)pn; |
|
| 372 |
WorkbenchPreferenceNode pwn = (WorkbenchPreferenceNode) pn;
|
|
| 363 | 373 |
pwn.remove("org.eclipse.ui.browser.preferencePage"); //$NON-NLS-1$
|
| 364 | 374 |
} |
| 365 | 375 |
} |
| 366 | 376 |
} |
| 367 |
|
|
| 377 |
|
|
| 368 | 378 |
public void startUpdateLookUpJob(boolean updateCalledFromCommandLine) {
|
| 369 | 379 |
if (needToRestoreTXMHOME) return; // don't call for update for the first run of TXM |
| 370 |
|
|
| 380 |
|
|
| 371 | 381 |
try {
|
| 372 | 382 |
boolean doUpdate = TBXPreferences.getInstance().getBoolean(TBXPreferences.FETCH_UPDATES_AT_STARTUP); |
| 373 | 383 |
if (!doUpdate) return; |
| 374 | 384 |
// |
| 375 |
// this.syncExec(new Runnable() {
|
|
| 376 |
// @Override
|
|
| 377 |
// public void run() {
|
|
| 378 |
|
|
| 385 |
// this.syncExec(new Runnable() {
|
|
| 386 |
// @Override
|
|
| 387 |
// public void run() {
|
|
| 388 |
|
|
| 379 | 389 |
try {
|
| 380 | 390 |
URL url = new URL("http://textometrie.ens-lyon.fr/dist/index.html"); //$NON-NLS-1$
|
| 381 | 391 |
Log.fine(TXMCoreMessages.bind("Testing if update site is available: {0}...", url)); //$NON-NLS-1$
|
| 382 | 392 |
InputStream data = url.openStream(); |
| 383 | 393 |
data.read(); |
| 384 | 394 |
data.close(); |
| 385 |
} catch(Exception e){
|
|
| 395 |
} |
|
| 396 |
catch (Exception e) {
|
|
| 386 | 397 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMCanNotFetchUpdatesP0, e)); |
| 387 | 398 |
doUpdate = false; |
| 388 | 399 |
return; |
| 389 | 400 |
} |
| 390 |
|
|
| 401 |
|
|
| 391 | 402 |
Log.info(TXMUIMessages.startingUpdateFetch); |
| 392 |
|
|
| 403 |
|
|
| 393 | 404 |
Display.getDefault().syncExec(new Runnable() {
|
| 405 |
|
|
| 394 | 406 |
@Override |
| 395 | 407 |
public void run() {
|
| 396 |
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
|
|
| 408 |
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class); |
|
| 397 | 409 |
if (handlerService != null) {
|
| 398 | 410 |
try {
|
| 399 | 411 |
Event e = new Event(); |
| 400 | 412 |
e.display = Display.getDefault(); |
| 401 | 413 |
handlerService.executeCommand(TXMUpdateHandler.ID, e); |
| 402 |
} catch (Exception e) {
|
|
| 414 |
} |
|
| 415 |
catch (Exception e) {
|
|
| 403 | 416 |
System.out.println(TXMCoreMessages.bind(TXMUIMessages.errorWhileUpdatingTXMColon, e)); |
| 404 | 417 |
Log.printStackTrace(e); |
| 405 | 418 |
} |
| 406 |
} else {
|
|
| 419 |
} |
|
| 420 |
else {
|
|
| 407 | 421 |
System.out.println(TXMUIMessages.errorWhileUpdatingTXMColonNoHandlerServiceFound); |
| 408 | 422 |
} |
| 409 | 423 |
} |
| 410 | 424 |
}); |
| 411 |
} catch(Exception e) {
|
|
| 425 |
} |
|
| 426 |
catch (Exception e) {
|
|
| 412 | 427 |
System.out.println(NLS.bind(TXMUIMessages.errorWhileFetchingUpdatesP0, e)); |
| 413 |
} catch(ThreadDeath td) {
|
|
| 428 |
} |
|
| 429 |
catch (ThreadDeath td) {
|
|
| 414 | 430 |
System.out.println(TXMUIMessages.updateCanceled); |
| 415 | 431 |
} |
| 416 | 432 |
} |
| 417 |
|
|
| 433 |
|
|
| 418 | 434 |
public static boolean testTXMHOMEPreferenceAndDirectory() {
|
| 419 | 435 |
String path = Toolbox.getTxmHomePath(); |
| 420 |
|
|
| 436 |
|
|
| 421 | 437 |
if (path == null || path.trim().equals("")) { //$NON-NLS-1$
|
| 422 | 438 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsNotSetP0PreferenceIsNotSet, TBXPreferences.USER_TXM_HOME)); |
| 423 | 439 |
return true; |
| ... | ... | |
| 426 | 442 |
if (!dir.exists()) {
|
| 427 | 443 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsSetToP0ButDoesNotExist, dir)); |
| 428 | 444 |
return true; |
| 429 |
} else if (!dir.canWrite()) {
|
|
| 445 |
} |
|
| 446 |
else if (!dir.canWrite()) {
|
|
| 430 | 447 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsSetToP0ButTXMCantWriteInThisDirectory, dir)); |
| 431 | 448 |
return true; |
| 432 |
} else if (!dir.canExecute()) {
|
|
| 449 |
} |
|
| 450 |
else if (!dir.canExecute()) {
|
|
| 433 | 451 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsSetToP0ButTXMCantCdInThisDirectory, dir)); |
| 434 | 452 |
return true; |
| 435 | 453 |
} |
| 436 |
|
|
| 454 |
|
|
| 437 | 455 |
return false; |
| 438 | 456 |
} |
| 439 |
|
|
| 457 |
|
|
| 440 | 458 |
public static boolean testTXMINSTALLPreferenceAndDirectory() {
|
| 441 |
// TxmPreferences.dump();
|
|
| 459 |
// TxmPreferences.dump();
|
|
| 442 | 460 |
if (Toolbox.getInstallDirectory() == null) {
|
| 443 | 461 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMInstallDirectoryIsNotSetP0PreferenceIsNotSet, TBXPreferences.INSTALL_DIR)); |
| 444 | 462 |
return true; |
| 445 | 463 |
} |
| 446 |
|
|
| 464 |
|
|
| 447 | 465 |
File installdir = new File(Toolbox.getInstallDirectory().trim()); |
| 448 | 466 |
if (Toolbox.getInstallDirectory().equals("")) { //$NON-NLS-1$
|
| 449 | 467 |
Log.warning(TXMUIMessages.TXMInstallDirectoryIsSetToQuoteQuote); |
| 450 | 468 |
return true; |
| 451 |
} else if (!installdir.exists()) {
|
|
| 469 |
} |
|
| 470 |
else if (!installdir.exists()) {
|
|
| 452 | 471 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMInstallDirectoryIsSetToP0ButDoesNotExist, installdir)); |
| 453 | 472 |
return true; |
| 454 |
} else if (!installdir.canRead()) {
|
|
| 473 |
} |
|
| 474 |
else if (!installdir.canRead()) {
|
|
| 455 | 475 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMInstallDirectoryIsSetToP0ButIsNotReadable, installdir)); |
| 456 | 476 |
return true; |
| 457 |
} else if (!installdir.canExecute()) {
|
|
| 477 |
} |
|
| 478 |
else if (!installdir.canExecute()) {
|
|
| 458 | 479 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMInstallDirectoryIsSetToP0ButTXMCantCdInThisDirectory, installdir)); |
| 459 | 480 |
return true; |
| 460 | 481 |
} |
| 461 | 482 |
return false; |
| 462 | 483 |
} |
| 463 |
|
|
| 484 |
|
|
| 464 | 485 |
/** |
| 465 | 486 |
* shutdown code. |
| 466 | 487 |
*/ |
| 467 | 488 |
@Override |
| 468 | 489 |
public void postShutdown() {
|
| 469 | 490 |
callPreStopScript(); |
| 470 |
|
|
| 491 |
|
|
| 471 | 492 |
Toolbox.shutdown(); |
| 472 |
|
|
| 493 |
|
|
| 473 | 494 |
callStopScript(); |
| 474 | 495 |
} |
| 475 |
|
|
| 496 |
|
|
| 476 | 497 |
/** |
| 477 | 498 |
* shutdown code. |
| 478 | 499 |
*/ |
| ... | ... | |
| 480 | 501 |
public boolean preShutdown() {
|
| 481 | 502 |
try {
|
| 482 | 503 |
closeEmptyEditors(true); |
| 483 |
} catch(Exception e) {
|
|
| 504 |
} |
|
| 505 |
catch (Exception e) {
|
|
| 484 | 506 |
e.printStackTrace(); |
| 485 | 507 |
} |
| 486 | 508 |
|
| 487 | 509 |
return continueShutDownForPersistedResults(); |
| 488 | 510 |
} |
| 489 |
|
|
| 511 |
|
|
| 490 | 512 |
private boolean continueShutDownForPersistedResults() {
|
| 491 | 513 |
if (Toolbox.workspace == null) return true; // nothing to do |
| 492 |
|
|
| 514 |
|
|
| 493 | 515 |
StringBuffer messages = new StringBuffer(); |
| 494 | 516 |
for (Project project : Toolbox.workspace.getProjects()) {
|
| 495 |
ArrayList<String> bugs = new ArrayList<String>();
|
|
| 517 |
ArrayList<String> bugs = new ArrayList<>(); |
|
| 496 | 518 |
for (TXMResult result : project.getDeepChildren()) {
|
| 497 | 519 |
if (result.mustBePersisted() && result.isAltered()) {
|
| 498 | 520 |
bugs.add(result.getSimpleName() + " (" + result.getResultType() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
| ... | ... | |
| 502 | 524 |
messages.append("- " + project.getName() + ": " + bugs + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
| 503 | 525 |
} |
| 504 | 526 |
} |
| 505 |
|
|
| 527 |
|
|
| 506 | 528 |
if (messages.length() > 0) {
|
| 507 | 529 |
return MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "", NLS.bind(TXMUIMessages.warning_popup_editedResultsWillBelostP0, messages)); //$NON-NLS-1$ |
| 508 | 530 |
} |
| 509 | 531 |
return true; |
| 510 | 532 |
} |
| 511 |
|
|
| 512 |
/* (non-Javadoc) |
|
| 533 |
|
|
| 534 |
/* |
|
| 535 |
* (non-Javadoc) |
|
| 513 | 536 |
* @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId() |
| 514 | 537 |
*/ |
| 515 | 538 |
@Override |
| 516 | 539 |
public String getInitialWindowPerspectiveId() {
|
| 517 | 540 |
return TXMPerspective.ID; |
| 518 | 541 |
} |
| 519 |
|
|
| 542 |
|
|
| 520 | 543 |
/** |
| 521 | 544 |
* initialize TXM log in console by redirecting stderr and stdout. |
| 522 | 545 |
*/ |
| 523 | 546 |
private void InitializeLogger() {
|
| 524 | 547 |
IOConsole console = new IOConsole(TXMUIMessages.systemOutput, null); |
| 525 |
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
|
|
| 526 |
|
|
| 548 |
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
|
|
| 549 |
|
|
| 527 | 550 |
// Enable or disable the outputs redirection to the RCP console according to the command line argument "-noredirection" |
| 528 | 551 |
boolean outputsRedirection = true; |
| 529 | 552 |
String[] args = Platform.getCommandLineArgs(); |
| 530 | 553 |
for (int i = 0; i < args.length; i++) {
|
| 531 |
if (args[i].equals("-noredirection")) { //$NON-NLS-1$
|
|
| 554 |
if (args[i].equals("-noredirection")) { //$NON-NLS-1$
|
|
| 532 | 555 |
outputsRedirection = false; |
| 533 | 556 |
break; |
| 534 | 557 |
} |
| 535 | 558 |
} |
| 536 |
if (outputsRedirection) {
|
|
| 559 |
if (outputsRedirection) {
|
|
| 537 | 560 |
stream = console.newOutputStream(); |
| 538 | 561 |
streamInput = console.getInputStream(); |
| 539 |
|
|
| 562 |
|
|
| 540 | 563 |
System.setOut(new PrintStream(stream)); |
| 541 | 564 |
System.setErr(new PrintStream(stream)); |
| 542 | 565 |
System.setIn(streamInput); |
| 543 | 566 |
} |
| 544 | 567 |
// System.out.println(Messages.ApplicationWorkbenchAdvisor_3); |
| 545 | 568 |
} |
| 546 |
|
|
| 569 |
|
|
| 547 | 570 |
public void setConsoleOutputColor(Color newColor) {
|
| 548 | 571 |
if (stream != null) stream.setColor(newColor); |
| 549 | 572 |
} |
| 550 |
|
|
| 573 |
|
|
| 551 | 574 |
/** |
| 552 | 575 |
* if INSTALLDIR preference is not set or empty, read the install.prefs file and set the |
| 553 | 576 |
* |
| ... | ... | |
| 566 | 589 |
boolean needTosetInstallPreference = testTXMINSTALLPreferenceAndDirectory(); |
| 567 | 590 |
// check if the install preference file has been loaded |
| 568 | 591 |
if (needTosetInstallPreference) {
|
| 569 |
|
|
| 592 |
|
|
| 570 | 593 |
installPreferenceRestored = false; // reset and finally set true if the process ended correctly |
| 571 |
|
|
| 594 |
|
|
| 572 | 595 |
try {
|
| 573 | 596 |
Display.getDefault().syncExec(new Runnable() {
|
| 597 |
|
|
| 574 | 598 |
@Override |
| 575 |
public void run() { OpenWelcomePage.openWelcomePage(); }
|
|
| 599 |
public void run() {
|
|
| 600 |
OpenWelcomePage.openWelcomePage(); |
|
| 601 |
} |
|
| 576 | 602 |
}); |
| 577 |
} catch(Exception e2) {}
|
|
| 578 |
|
|
| 603 |
} |
|
| 604 |
catch (Exception e2) {
|
|
| 605 |
} |
|
| 606 |
|
|
| 579 | 607 |
// set the install directory preference |
| 580 | 608 |
String installpath = Platform.getInstallLocation().getURL().getFile(); // the TXM.exe file path |
| 581 | 609 |
File installDirectory = new File(installpath); |
| 582 |
//installDirectory = installDirectory.getCanonicalFile(); |
|
| 583 |
|
|
| 584 |
//TODO: ensure all preferences of install.prefs file are now stored in the default preferences |
|
| 585 |
// File preferenceFile = new File(installDirectory, "install.prefs"); //$NON-NLS-1$
|
|
| 586 |
// if (preferenceFile.exists()) {
|
|
| 587 |
// System.out.println(NLS.bind(RCPMessages.ApplicationWorkbenchAdvisor_25, preferenceFile));
|
|
| 588 |
// if (Util.isWindows()) //NSIS has generated ISO-8859-1 preference file
|
|
| 589 |
// TxmPreferences.importFromFile(preferenceFile, "ISO-8859-1", false); //$NON-NLS-1$
|
|
| 590 |
// else
|
|
| 591 |
// TxmPreferences.importFromFile(preferenceFile);
|
|
| 592 |
// } else {
|
|
| 593 |
// System.out.println("No installation preference file found in the installation directory: "+preferenceFile);
|
|
| 594 |
// installPreferenceRestored = false;
|
|
| 595 |
// return true;
|
|
| 596 |
// }
|
|
| 597 |
// // restore previous TreeTagger preferences
|
|
| 598 |
// File previousPreferenceFile = new File(System.getProperty("java.io.tmpdir"), //$NON-NLS-1$
|
|
| 599 |
// "org.txm.rcp.prefs"); //$NON-NLS-1$
|
|
| 610 |
// installDirectory = installDirectory.getCanonicalFile();
|
|
| 611 |
|
|
| 612 |
// TODO: ensure all preferences of install.prefs file are now stored in the default preferences
|
|
| 613 |
// File preferenceFile = new File(installDirectory, "install.prefs"); //$NON-NLS-1$
|
|
| 614 |
// if (preferenceFile.exists()) {
|
|
| 615 |
// System.out.println(NLS.bind(RCPMessages.ApplicationWorkbenchAdvisor_25, preferenceFile));
|
|
| 616 |
// if (Util.isWindows()) //NSIS has generated ISO-8859-1 preference file
|
|
| 617 |
// TxmPreferences.importFromFile(preferenceFile, "ISO-8859-1", false); //$NON-NLS-1$
|
|
| 618 |
// else
|
|
| 619 |
// TxmPreferences.importFromFile(preferenceFile);
|
|
| 620 |
// } else {
|
|
| 621 |
// System.out.println("No installation preference file found in the installation directory: "+preferenceFile);
|
|
| 622 |
// installPreferenceRestored = false;
|
|
| 623 |
// return true;
|
|
| 624 |
// }
|
|
| 625 |
// // restore previous TreeTagger preferences
|
|
| 626 |
// File previousPreferenceFile = new File(System.getProperty("java.io.tmpdir"), //$NON-NLS-1$
|
|
| 627 |
// "org.txm.rcp.prefs"); //$NON-NLS-1$
|
|
| 600 | 628 |
// |
| 601 |
// if (System.getProperty("os.name").indexOf("Mac") >= 0) { //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 602 |
// previousPreferenceFile = new File("/tmp/org.txm.rcp.prefs"); //$NON-NLS-1$
|
|
| 603 |
// }
|
|
| 629 |
// if (System.getProperty("os.name").indexOf("Mac") >= 0) { //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 630 |
// previousPreferenceFile = new File("/tmp/org.txm.rcp.prefs"); //$NON-NLS-1$
|
|
| 631 |
// }
|
|
| 604 | 632 |
// |
| 605 |
// if (previousPreferenceFile.exists()) {
|
|
| 606 |
// System.out.println("Restoring preferences (from "+previousPreferenceFile+").");
|
|
| 607 |
// Properties previousProperties = new Properties();
|
|
| 608 |
// BufferedReader reader = IOUtils.getReader(previousPreferenceFile, "ISO-8859-1");
|
|
| 609 |
// previousProperties.load(reader);
|
|
| 610 |
// String [] keys= {TBXPreferences.TREETAGGER_INSTALL_PATH,
|
|
| 611 |
// TBXPreferences.TREETAGGER_MODELS_PATH,
|
|
| 612 |
// TBXPreferences.TREETAGGER_OPTIONS};
|
|
| 613 |
// for (String k : keys) {
|
|
| 614 |
// if (previousProperties.getProperty(k) != null) {
|
|
| 615 |
// TxmPreferences.set(k, previousProperties.getProperty(k));
|
|
| 616 |
// }
|
|
| 617 |
// }
|
|
| 618 |
// }
|
|
| 619 |
|
|
| 633 |
// if (previousPreferenceFile.exists()) {
|
|
| 634 |
// System.out.println("Restoring preferences (from "+previousPreferenceFile+").");
|
|
| 635 |
// Properties previousProperties = new Properties();
|
|
| 636 |
// BufferedReader reader = IOUtils.getReader(previousPreferenceFile, "ISO-8859-1");
|
|
| 637 |
// previousProperties.load(reader);
|
|
| 638 |
// String [] keys= {TBXPreferences.TREETAGGER_INSTALL_PATH,
|
|
| 639 |
// TBXPreferences.TREETAGGER_MODELS_PATH,
|
|
| 640 |
// TBXPreferences.TREETAGGER_OPTIONS};
|
|
| 641 |
// for (String k : keys) {
|
|
| 642 |
// if (previousProperties.getProperty(k) != null) {
|
|
| 643 |
// TxmPreferences.set(k, previousProperties.getProperty(k));
|
|
| 644 |
// }
|
|
| 645 |
// }
|
|
| 646 |
// }
|
|
| 647 |
|
|
| 620 | 648 |
installPreferenceRestored = true; |
| 621 |
|
|
| 649 |
|
|
| 622 | 650 |
if (installDirectory == null || !installDirectory.exists()) {
|
| 623 | 651 |
Log.severe(TXMUIMessages.errorTheProvidedInstallDirectoryDoesNotExistAborting); |
| 624 | 652 |
return false; |
| 625 | 653 |
} |
| 626 |
|
|
| 654 |
|
|
| 627 | 655 |
TBXPreferences.getInstance().put(TBXPreferences.INSTALL_DIR, installDirectory.getAbsolutePath()); |
| 628 | 656 |
TBXPreferences.getInstance().flush(); |
| 629 | 657 |
return true; |
| 630 | 658 |
} |
| 631 |
} catch (Exception e) {
|
|
| 659 |
} |
|
| 660 |
catch (Exception e) {
|
|
| 632 | 661 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.couldNotReadInstallPreferencesFile, e)); |
| 633 | 662 |
Log.printStackTrace(e); |
| 634 | 663 |
return false; |
| 635 | 664 |
} |
| 636 | 665 |
return true; |
| 637 | 666 |
} |
| 638 |
|
|
| 667 |
|
|
| 639 | 668 |
boolean go = false; |
| 669 |
|
|
| 640 | 670 |
File backup; |
| 671 |
|
|
| 641 | 672 |
File oldbackup; |
| 673 |
|
|
| 642 | 674 |
File errorbackup; |
| 675 |
|
|
| 643 | 676 |
File corporaDir; |
| 677 |
|
|
| 644 | 678 |
/** |
| 645 | 679 |
* if TXMHOME path is not set or wrong |
| 646 |
* - set default theme
|
|
| 647 |
* - restore old corpora
|
|
| 648 |
* - creates TXMHOME and copy "scripts", "samples" directories from TXMINSTALLDIR and mkdirs workspaces, registry,
|
|
| 649 |
* clipboard plus an empty Workspace (TXMObject) is created then load the sample corpora.
|
|
| 680 |
* - set default theme |
|
| 681 |
* - restore old corpora |
|
| 682 |
* - creates TXMHOME and copy "scripts", "samples" directories from TXMINSTALLDIR and mkdirs workspaces, registry, |
|
| 683 |
* clipboard plus an empty Workspace (TXMObject) is created then load the sample corpora. |
|
| 650 | 684 |
* |
| 651 | 685 |
* |
| 652 | 686 |
*/ |
| 653 | 687 |
private static boolean needToRestoreTXMHOME; |
| 688 |
|
|
| 654 | 689 |
public static boolean getWasFirstLaunch() {
|
| 655 | 690 |
return needToRestoreTXMHOME; |
| 656 | 691 |
} |
| 657 |
|
|
| 692 |
|
|
| 658 | 693 |
File txmhomedir = null; |
| 694 |
|
|
| 659 | 695 |
File installDirectory = null; |
| 696 |
|
|
| 660 | 697 |
private Handler severeDialobBoxHandler = new Handler() {
|
| 661 |
|
|
| 698 |
|
|
| 662 | 699 |
@Override |
| 663 | 700 |
public void publish(final LogRecord record) {
|
| 664 |
//System.out.println("severeDialobBoxHandler.publish()");
|
|
| 701 |
// System.out.println("severeDialobBoxHandler.publish()");
|
|
| 665 | 702 |
boolean showSevereDialobBox = RCPPreferences.getInstance().getBoolean(RCPPreferences.SHOW_SEVERE_DIALOG); |
| 666 | 703 |
if (showSevereDialobBox) {
|
| 667 | 704 |
if (record.getLevel() != Level.SEVERE) return; |
| 668 |
|
|
| 705 |
|
|
| 669 | 706 |
final IWorkbench w = PlatformUI.getWorkbench(); |
| 670 | 707 |
if (w == null) {
|
| 671 | 708 |
System.out.println("no workbench"); //$NON-NLS-1$
|
| 672 | 709 |
return; |
| 673 | 710 |
} |
| 674 |
|
|
| 711 |
|
|
| 675 | 712 |
w.getDisplay().syncExec(new Runnable() {
|
| 713 |
|
|
| 676 | 714 |
@Override |
| 677 | 715 |
public void run() {
|
| 678 | 716 |
try {
|
| 679 | 717 |
IWorkbenchWindow aww = w.getActiveWorkbenchWindow(); |
| 680 |
if (aww == null) {System.out.println(TXMUIMessages.noActiveWorkbenchWindow);return;}
|
|
| 718 |
if (aww == null) {
|
|
| 719 |
System.out.println(TXMUIMessages.noActiveWorkbenchWindow); |
|
| 720 |
return; |
|
| 721 |
} |
|
| 681 | 722 |
IWorkbenchPage page = aww.getActivePage(); |
| 682 |
if (page == null) {System.out.println(TXMUIMessages.noActivePage);return;}
|
|
| 723 |
if (page == null) {
|
|
| 724 |
System.out.println(TXMUIMessages.noActivePage); |
|
| 725 |
return; |
|
| 726 |
} |
|
| 683 | 727 |
IViewPart view = page.findView("org.eclipse.pde.runtime.LogView"); //$NON-NLS-1$
|
| 684 | 728 |
if (view == null) {
|
| 685 | 729 |
view = page.showView("org.eclipse.pde.runtime.LogView"); //$NON-NLS-1$
|
| 686 | 730 |
} |
| 687 |
} catch (Exception e1) {
|
|
| 688 |
System.out.println(TXMUIMessages.partInitializationErrorColon+e1); |
|
| 731 |
} |
|
| 732 |
catch (Exception e1) {
|
|
| 733 |
System.out.println(TXMUIMessages.partInitializationErrorColon + e1); |
|
| 689 | 734 |
e1.printStackTrace(); |
| 690 | 735 |
return; |
| 691 | 736 |
} |
| 692 | 737 |
} |
| 693 | 738 |
}); |
| 694 |
|
|
| 739 |
|
|
| 695 | 740 |
IStatus s = new Status(Status.ERROR, Application.PLUGIN_ID, Status.OK, record.getMessage(), null); |
| 696 | 741 |
StatusManager.getManager().handle(s, StatusManager.LOG); |
| 697 | 742 |
} |
| 698 | 743 |
} |
| 699 |
|
|
| 744 |
|
|
| 700 | 745 |
@Override |
| 701 |
public void flush() { }
|
|
| 702 |
|
|
| 746 |
public void flush() {}
|
|
| 747 |
|
|
| 703 | 748 |
@Override |
| 704 |
public void close() throws SecurityException { }
|
|
| 749 |
public void close() throws SecurityException {}
|
|
| 705 | 750 |
}; |
| 751 |
|
|
| 706 | 752 |
/** |
| 707 | 753 |
* internal variable to know if the txm home directory has been created |
| 708 | 754 |
*/ |
| 709 | 755 |
private boolean txmHomeRestored; |
| 710 |
|
|
| 756 |
|
|
| 711 | 757 |
{
|
| 712 | 758 |
Log.addHandler(severeDialobBoxHandler); |
| 713 | 759 |
severeDialobBoxHandler.setLevel(Level.SEVERE); |
| 714 | 760 |
} |
| 715 |
|
|
| 761 |
|
|
| 716 | 762 |
private boolean checkTXMHOME(JobHandler jobHandler, IProgressMonitor monitor) {
|
| 717 | 763 |
txmhomedir = null; |
| 718 | 764 |
installDirectory = null; |
| 719 |
|
|
| 765 |
|
|
| 720 | 766 |
// check if TXMHOME of the user is set and exists |
| 721 | 767 |
needToRestoreTXMHOME = testTXMHOMEPreferenceAndDirectory(); |
| 722 |
Log.fine("needToRestoreTXMHOME="+needToRestoreTXMHOME+" installPreferenceRestored="+installPreferenceRestored); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 768 |
Log.fine("needToRestoreTXMHOME=" + needToRestoreTXMHOME + " installPreferenceRestored=" + installPreferenceRestored); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 723 | 769 |
if (needToRestoreTXMHOME || installPreferenceRestored) {
|
| 724 |
|
|
| 770 |
|
|
| 725 | 771 |
System.out.println(TXMUIMessages.creatingTXMUserWorkingDirectory); |
| 726 |
|
|
| 772 |
|
|
| 727 | 773 |
try {
|
| 728 | 774 |
Log.info(NLS.bind(TXMUIMessages.installPathColonP0, Toolbox.getInstallDirectory())); |
| 729 |
|
|
| 775 |
|
|
| 730 | 776 |
txmhomedir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalFile(); |
| 731 | 777 |
txmhomedir.mkdirs(); // creates the directory if needed |
| 732 |
|
|
| 778 |
|
|
| 733 | 779 |
txmhomedir.mkdirs(); // creates the directory if needed |
| 734 |
|
|
| 780 |
|
|
| 735 | 781 |
if (!txmhomedir.exists()) {
|
| 736 | 782 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.errorTheProvidedTXMHOMEDirectoryDoesNotExistsP0Aborting, txmhomedir)); |
| 737 | 783 |
return false; |
| 738 | 784 |
} |
| 739 |
|
|
| 785 |
|
|
| 740 | 786 |
// save preference if USER_TXM_HOME has changed |
| 741 | 787 |
TBXPreferences.getInstance().put(TBXPreferences.USER_TXM_HOME, txmhomedir.getAbsolutePath()); |
| 742 | 788 |
DefaultScope.INSTANCE.getNode("org.eclipse.ui.workbench").putBoolean("RUN_IN_BACKGROUND", false); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
| 743 | 789 |
DefaultScope.INSTANCE.getNode("org.eclipse.ui.workbench").flush(); //$NON-NLS-1$
|
| 744 | 790 |
TBXPreferences.getInstance().flush(); |
| 745 |
//TXMPreferences.saveAll(); |
|
| 746 |
|
|
| 791 |
// TXMPreferences.saveAll();
|
|
| 792 |
|
|
| 747 | 793 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsSetToP0, txmhomedir)); |
| 748 |
|
|
| 794 |
|
|
| 749 | 795 |
txmHomeRestored = true; |
| 750 |
} catch (Exception e) {
|
|
| 796 |
} |
|
| 797 |
catch (Exception e) {
|
|
| 751 | 798 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 752 | 799 |
System.out.println(TXMCoreMessages.bind(TXMUIMessages.failedToBackupExistingCorporaColon, e.getLocalizedMessage())); |
| 753 | 800 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.failedToBackupExistingCorporaColon, e.getLocalizedMessage())); |
| 754 | 801 |
return false; |
| 755 | 802 |
} |
| 756 |
|
|
| 757 |
|
|
| 758 |
|
|
| 759 |
|
|
| 760 |
|
|
| 803 |
|
|
| 804 |
|
|
| 805 |
|
|
| 806 |
|
|
| 807 |
|
|
| 761 | 808 |
} // end if |
| 762 |
|
|
| 809 |
|
|
| 763 | 810 |
return true; |
| 764 | 811 |
} |
| 765 |
|
|
| 812 |
|
|
| 766 | 813 |
/** |
| 767 | 814 |
* Install the sample corpora and previous TXM version corpora in TXM corpora directory |
| 815 |
* |
|
| 768 | 816 |
* @param monitor |
| 769 | 817 |
*/ |
| 770 | 818 |
private void installCorporaDirectory(IProgressMonitor monitor) {
|
| 771 |
// if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) {
|
|
| 772 |
// System.out.println("DEV MODE: no corpus restored!");
|
|
| 773 |
// return; // dev mode
|
|
| 774 |
// }
|
|
| 819 |
// if (org.eclipse.core.runtime.Platform.inDevelopmentMode()) {
|
|
| 820 |
// System.out.println("DEV MODE: no corpus restored!");
|
|
| 821 |
// return; // dev mode
|
|
| 822 |
// }
|
|
| 775 | 823 |
monitor.setTaskName(TXMUIMessages.restoringCorpora); |
| 776 | 824 |
String installdirpath = Toolbox.getInstallDirectory(); |
| 777 | 825 |
File sampleCorporaDirectory = new File(installdirpath, "samples"); //$NON-NLS-1$ |
| 778 |
|
|
| 826 |
|
|
| 779 | 827 |
if (txmhomedir == null) {
|
| 780 | 828 |
txmhomedir = new File(Toolbox.getTxmHomePath().trim()); |
| 781 | 829 |
} |
| 782 | 830 |
corporaDir = new File(txmhomedir, "corpora"); //$NON-NLS-1$ |
| 783 | 831 |
corporaDir.mkdir(); |
| 784 |
|
|
| 832 |
|
|
| 785 | 833 |
File previousCorporaDirectory = new File(System.getProperty("user.home"), "TXM/corpora"); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
| 786 |
|
|
| 834 |
|
|
| 787 | 835 |
Version v = Activator.getDefault().getBundle().getVersion(); |
| 788 |
String vv = v.getMajor()+"."+v.getMinor()+"."+v.getMicro(); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
|
| 789 |
String SAMPLES = "1. "+TXMUIMessages.bind(TXMUIMessages.sampleCorporaOfCurrentTXMP0, vv);//$NON-NLS-1$
|
|
| 790 |
String V080 = "2. "+TXMUIMessages.bind(TXMUIMessages.corporaOfPreviousTXMP0, vv);//$NON-NLS-1$
|
|
| 791 |
String V079 = "3. "+TXMUIMessages.bind(TXMUIMessages.corporaOfPreviousTXMP0, "0.7.9"); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
|
| 792 |
String OTHER = "4. "+TXMUIMessages.selectAnotherTXMCorporaToRestore;//$NON-NLS-1$
|
|
| 793 |
|
|
| 794 |
|
|
| 795 |
final ArrayList<Object> corporaDirs = new ArrayList<Object>();
|
|
| 836 |
String vv = v.getMajor() + "." + v.getMinor() + "." + v.getMicro(); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
|
| 837 |
String SAMPLES = "1. " + TXMUIMessages.bind(TXMUIMessages.sampleCorporaOfCurrentTXMP0, vv);//$NON-NLS-1$
|
|
| 838 |
String V080 = "2. " + TXMUIMessages.bind(TXMUIMessages.corporaOfPreviousTXMP0, vv);//$NON-NLS-1$
|
|
| 839 |
String V079 = "3. " + TXMUIMessages.bind(TXMUIMessages.corporaOfPreviousTXMP0, "0.7.9"); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
|
| 840 |
String OTHER = "4. " + TXMUIMessages.selectAnotherTXMCorporaToRestore;//$NON-NLS-1$
|
|
| 841 |
|
|
| 842 |
|
|
| 843 |
final ArrayList<Object> corporaDirs = new ArrayList<>(); |
|
| 796 | 844 |
corporaDirs.add(SAMPLES); |
| 797 | 845 |
corporaDirs.add(V080); |
| 798 | 846 |
corporaDirs.add(V079); |
| 799 | 847 |
corporaDirs.add(OTHER); |
| 800 |
|
|
| 801 |
final ArrayList<Object> initialCorporaDirs = new ArrayList<Object>();
|
|
| 848 |
|
|
| 849 |
final ArrayList<Object> initialCorporaDirs = new ArrayList<>(); |
|
| 802 | 850 |
initialCorporaDirs.add(SAMPLES); |
| 803 | 851 |
initialCorporaDirs.add(V080); |
| 804 | 852 |
initialCorporaDirs.add(V079); |
| 805 |
|
|
| 806 |
|
|
| 853 |
|
|
| 854 |
|
|
| 807 | 855 |
Display.getDefault().syncExec(new Runnable() {
|
| 856 |
|
|
| 808 | 857 |
@Override |
| 809 | 858 |
public void run() {
|
| 810 | 859 |
Display display = Display.getDefault(); |
| 811 | 860 |
Shell shell = display.getActiveShell(); |
| 812 |
ListSelectionDialog dialog = new ListSelectionDialog(shell, corporaDirs,
|
|
| 861 |
ListSelectionDialog dialog = new ListSelectionDialog(shell, corporaDirs, |
|
| 813 | 862 |
new ArrayContentProvider(), new LabelProvider(), TXMUIMessages.corporaWillBeRestoredInTheFollowingOrderCorporaAlreadyRestoredWillNotBeReplaced); |
| 814 | 863 |
dialog.setTitle(TXMUIMessages.selectThecorporaSetsToRestore); |
| 815 | 864 |
dialog.setInitialElementSelections(initialCorporaDirs); |
| ... | ... | |
| 817 | 866 |
corporaDirs.clear(); |
| 818 | 867 |
List<Object> selection = Arrays.asList(dialog.getResult()); |
| 819 | 868 |
corporaDirs.addAll(selection); |
| 820 |
} else {
|
|
| 869 |
} |
|
| 870 |
else {
|
|
| 821 | 871 |
corporaDirs.clear(); |
| 822 | 872 |
} |
| 823 | 873 |
} |
| 824 | 874 |
}); |
| 825 |
|
|
| 875 |
|
|
| 826 | 876 |
// move previous TXM 0.8.0 corpora |
| 827 |
File backupDir = new File(corporaDir.getAbsolutePath()+"-previous"); //$NON-NLS-1$
|
|
| 877 |
File backupDir = new File(corporaDir.getAbsolutePath() + "-previous"); //$NON-NLS-1$
|
|
| 828 | 878 |
if (corporaDir.exists()) {
|
| 829 | 879 |
backupDir.mkdirs(); |
| 830 | 880 |
for (File dir : corporaDir.listFiles(IOUtils.HIDDENFILE_FILTER)) {
|
| ... | ... | |
| 833 | 883 |
dir.renameTo(bdir); |
| 834 | 884 |
} |
| 835 | 885 |
} |
| 836 |
|
|
| 886 |
|
|
| 837 | 887 |
// load TXM-0.8.0 sample corpora (from the install directory) |
| 838 | 888 |
if (corporaDirs.contains(SAMPLES) && sampleCorporaDirectory.exists()) {
|
| 839 |
|
|
| 889 |
|
|
| 840 | 890 |
Log.info(TXMUIMessages.installingSampleCorpus); |
| 841 |
|
|
| 891 |
|
|
| 842 | 892 |
JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(sampleCorporaDirectory, false, true, false); |
| 843 | 893 |
try {
|
| 844 | 894 |
job.join(); |
| 845 |
} catch (InterruptedException e) {
|
|
| 895 |
} |
|
| 896 |
catch (InterruptedException e) {
|
|
| 846 | 897 |
// TODO Auto-generated catch block |
| 847 | 898 |
e.printStackTrace(); |
| 848 | 899 |
} |
| 849 | 900 |
} |
| 850 |
|
|
| 901 |
|
|
| 851 | 902 |
// TXM-0.8.0 previous installation corpora |
| 852 | 903 |
if (corporaDirs.contains(V080) && backupDir.listFiles(IOUtils.HIDDENFILE_FILTER).length > 0) { // not a new install, restore corpus from the corpora-previous directory
|
| 853 | 904 |
Log.info(NLS.bind(TXMUIMessages.installingPreviousCorpusFromP0, "0.8.0", corporaDir)); //$NON-NLS-1$ |
| 854 | 905 |
JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(backupDir, false, false, true); |
| 855 | 906 |
try {
|
| 856 | 907 |
job.join(); |
| 857 |
} catch (InterruptedException e) {
|
|
| 908 |
} |
|
| 909 |
catch (InterruptedException e) {
|
|
| 858 | 910 |
e.printStackTrace(); |
| 859 | 911 |
} |
| 860 | 912 |
} |
| 861 |
|
|
| 913 |
|
|
| 862 | 914 |
// TXM previous installation corpora |
| 863 | 915 |
if (corporaDirs.contains(V079) && previousCorporaDirectory.exists()) { // new installation (empty corpora directory)
|
| 864 | 916 |
Log.info(NLS.bind(TXMUIMessages.installingPreviousCorpusFromP0, "0.7.9", previousCorporaDirectory)); //$NON-NLS-1$ |
| 865 | 917 |
JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(previousCorporaDirectory, false, false, true); |
| 866 | 918 |
try {
|
| 867 | 919 |
job.join(); |
| 868 |
} catch (InterruptedException e) {
|
|
| 920 |
} |
|
| 921 |
catch (InterruptedException e) {
|
|
| 869 | 922 |
e.printStackTrace(); |
| 870 | 923 |
} |
| 871 | 924 |
} |
| 872 |
|
|
| 925 |
|
|
| 873 | 926 |
// TXM previous installation corpora |
| 874 | 927 |
if (corporaDirs.contains(OTHER)) { // new installation (empty corpora directory)
|
| 875 |
final HashMap<String, String> bindings = new HashMap<String, String>();
|
|
| 928 |
final HashMap<String, String> bindings = new HashMap<>(); |
|
| 876 | 929 |
Display.getDefault().syncExec(new Runnable() {
|
| 930 |
|
|
| 877 | 931 |
@Override |
| 878 | 932 |
public void run() {
|
| 879 | 933 |
Display display = Display.getDefault(); |
| ... | ... | |
| 881 | 935 |
DirectoryDialog dialog = new DirectoryDialog(shell); |
| 882 | 936 |
String path = dialog.open(); |
| 883 | 937 |
if (path == null) return; |
| 884 |
|
|
| 938 |
|
|
| 885 | 939 |
bindings.put("path", path); //$NON-NLS-1$
|
| 886 | 940 |
} |
| 887 | 941 |
}); |
| ... | ... | |
| 892 | 946 |
JobHandler job = LoadBinaryCorporaDirectory.loadBinaryCorpusFromCorporaDirectory(dir, true, true, true); |
| 893 | 947 |
try {
|
| 894 | 948 |
job.join(); |
| 895 |
} catch (InterruptedException e) {
|
|
| 949 |
} |
|
| 950 |
catch (InterruptedException e) {
|
|
| 896 | 951 |
e.printStackTrace(); |
| 897 | 952 |
} |
| 898 | 953 |
} |
| 899 | 954 |
} |
| 900 | 955 |
} |
| 901 |
|
|
| 956 |
|
|
| 902 | 957 |
Display.getDefault().syncExec(new Runnable() {
|
| 958 |
|
|
| 903 | 959 |
@Override |
| 904 | 960 |
public void run() {
|
| 905 | 961 |
RestartTXM.reloadViews(); |
| 906 | 962 |
} |
| 907 | 963 |
}); |
| 908 |
|
|
| 964 |
|
|
| 909 | 965 |
monitor.setTaskName(""); //$NON-NLS-1$
|
| 910 | 966 |
} |
| 911 |
|
|
| 967 |
|
|
| 912 | 968 |
/** |
| 913 | 969 |
* Executes the specified Groovy script file. |
| 970 |
* |
|
| 914 | 971 |
* @param script |
| 915 | 972 |
*/ |
| 916 | 973 |
private void callGroovyScript(File script) {
|
| ... | ... | |
| 919 | 976 |
ExecuteGroovyScript.executeScript(script.getAbsolutePath(), null, null, true, ""); //$NON-NLS-1$ |
| 920 | 977 |
} |
| 921 | 978 |
} |
| 922 |
catch(Exception e) {
|
|
| 979 |
catch (Exception e) {
|
|
| 923 | 980 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.failedToExecuteTheP0ScriptColonP1, script, e)); |
| 924 | 981 |
Log.printStackTrace(e); |
| 925 | 982 |
} |
| 926 | 983 |
} |
| 927 |
|
|
| 928 |
|
|
| 984 |
|
|
| 985 |
|
|
| 929 | 986 |
/** |
| 930 | 987 |
* Called just before the Toolbox is initialized |
| 931 | 988 |
*/ |
| 932 | 989 |
private void callPreStartScript() {
|
| 933 | 990 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/prestart.groovy")); //$NON-NLS-1$ |
| 934 | 991 |
} |
| 935 |
|
|
| 992 |
|
|
| 936 | 993 |
/** |
| 937 | 994 |
* Called just after Toolbox is initialized |
| 938 | 995 |
*/ |
| 939 | 996 |
private void callStartScript() {
|
| 940 | 997 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/start.groovy")); //$NON-NLS-1$ |
| 941 | 998 |
} |
| 942 |
|
|
| 999 |
|
|
| 943 | 1000 |
/** |
| 944 | 1001 |
* Called just before Toolbox is stop call |
| 945 | 1002 |
*/ |
| 946 | 1003 |
private void callPreStopScript() {
|
| 947 | 1004 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/prestop.groovy")); //$NON-NLS-1$ |
| 948 | 1005 |
} |
| 949 |
|
|
| 1006 |
|
|
| 950 | 1007 |
/** |
| 951 | 1008 |
* Called just after Toolbox is stop call |
| 952 | 1009 |
*/ |
| 953 | 1010 |
private void callStopScript() {
|
| 954 | 1011 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/stop.groovy")); //$NON-NLS-1$ |
| 955 | 1012 |
} |
| 956 |
|
|
| 1013 |
|
|
| 957 | 1014 |
/** |
| 958 | 1015 |
* after TXMHOME AND INSTALLDIR are ok, we can start the Toolbox |
| 959 | 1016 |
* <p> |
| ... | ... | |
| 970 | 1027 |
* @throws Exception |
| 971 | 1028 |
*/ |
| 972 | 1029 |
private boolean initializeUI(final JobHandler jobHandler) throws Exception {
|
| 973 |
|
|
| 1030 |
|
|
| 974 | 1031 |
// Fix the freeze at splash screen on Mac OS X/Cocoa because of a deadlock between AWT/SWT threads (bug #894) |
| 975 | 1032 |
Display.getDefault().syncExec(new Runnable() {
|
| 1033 |
|
|
| 976 | 1034 |
@Override |
| 977 | 1035 |
public void run() {
|
| 978 | 1036 |
try {
|
| 979 | 1037 |
printTXMVersion(); |
| 980 |
|
|
| 1038 |
|
|
| 981 | 1039 |
jobHandler.setTaskName(TXMUIMessages.setDefaultTheme); |
| 982 | 1040 |
setDefaultTheme(); |
| 983 |
|
|
| 1041 |
|
|
| 984 | 1042 |
// CLOSE Empty&Error editors |
| 985 | 1043 |
jobHandler.setTaskName(TXMUIMessages.closingEmptyEditors); |
| 986 | 1044 |
closeEmptyEditors(false); |
| 987 |
|
|
| 1045 |
|
|
| 988 | 1046 |
// remove some preference pages |
| 989 |
setPreferencesConfiguration();
|
|
| 990 |
|
|
| 1047 |
setPreferencesConfiguration(); |
|
| 1048 |
|
|
| 991 | 1049 |
new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, new IRunnableWithProgress() {
|
| 992 |
|
|
| 1050 |
|
|
| 993 | 1051 |
@Override |
| 994 | 1052 |
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
| 995 |
|
|
| 1053 |
|
|
| 996 | 1054 |
if (!Toolbox.isInitialized()) {
|
| 997 | 1055 |
try {
|
| 998 | 1056 |
monitor.worked(1); |
| 999 |
|
|
| 1057 |
|
|
| 1000 | 1058 |
monitor.setTaskName(TXMUIMessages.callingGroovyPrestartScript); |
| 1001 | 1059 |
callPreStartScript(); |
| 1002 | 1060 |
monitor.worked(20); |
| 1003 |
|
|
| 1061 |
|
|
| 1004 | 1062 |
monitor.setTaskName(TXMUIMessages.initializingToolboxEnginesAndCorpora); |
| 1005 | 1063 |
if (Toolbox.initialize(TBXPreferences.class, monitor)) {
|
| 1006 |
//StatusLine.setMessage(TXMUIMessages.ready); |
|
| 1064 |
// StatusLine.setMessage(TXMUIMessages.ready);
|
|
| 1007 | 1065 |
} |
| 1008 | 1066 |
else {
|
| 1009 | 1067 |
StatusLine.setMessage(TXMUIMessages.startupFailedPleaseCheckTXMPreferencesInTheFileSupPreferencesMenuOrContactTxmusersMailingListMenuColonHelpSup); |
| 1010 | 1068 |
Log.severe(TXMUIMessages.startupFailedPleaseCheckTXMPreferencesInTheFileSupPreferencesMenuOrContactTxmusersMailingListMenuColonHelpSup); |
| 1011 |
|
|
| 1069 |
|
|
| 1012 | 1070 |
monitor.done(); |
| 1013 | 1071 |
return; |
| 1014 | 1072 |
} |
| 1015 | 1073 |
monitor.worked(20); |
| 1016 |
|
|
| 1074 |
|
|
| 1017 | 1075 |
monitor.setTaskName(TXMUIMessages.callingGroovyStartScript); |
| 1018 | 1076 |
callStartScript(); |
| 1019 | 1077 |
monitor.worked(20); |
| 1020 |
|
|
| 1078 |
|
|
| 1021 | 1079 |
// restore corpora if TXMHOME has been created |
| 1022 | 1080 |
if (txmHomeRestored) {
|
| 1023 | 1081 |
installCorporaDirectory(monitor); |
| 1024 |
|
|
| 1082 |
|
|
| 1025 | 1083 |
Toolbox.workspace.saveParameters(true); |
| 1026 | 1084 |
ResourcesPlugin.getWorkspace().save(true, null); |
| 1027 | 1085 |
} |
| 1028 | 1086 |
monitor.worked(20); |
| 1029 |
|
|
| 1087 |
|
|
| 1030 | 1088 |
jobHandler.setTaskName(TXMUIMessages.toolboxReady); |
| 1031 |
} catch (Exception e) {
|
|
| 1089 |
} |
|
| 1090 |
catch (Exception e) {
|
|
| 1032 | 1091 |
// TODO Auto-generated catch block |
| 1033 | 1092 |
e.printStackTrace(); |
| 1034 | 1093 |
} |
| 1035 | 1094 |
} |
| 1036 |
|
|
| 1037 |
monitor.done();
|
|
| 1095 |
|
|
| 1096 |
monitor.done(); |
|
| 1038 | 1097 |
} |
| 1039 |
|
|
| 1040 |
|
|
| 1098 |
|
|
| 1099 |
|
|
| 1041 | 1100 |
}); |
| 1042 |
|
|
| 1101 |
|
|
| 1043 | 1102 |
Log.fine(TXMUIMessages.loadingViews); |
| 1044 | 1103 |
RestartTXM.reloadViews(); // reload views |
| 1045 |
|
|
| 1046 |
|
|
| 1104 |
|
|
| 1105 |
|
|
| 1047 | 1106 |
} |
| 1048 |
catch(Exception e) {
|
|
| 1107 |
catch (Exception e) {
|
|
| 1049 | 1108 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.errorDuringUIInitializationP0, e.getLocalizedMessage())); |
| 1050 | 1109 |
e.printStackTrace(); |
| 1051 | 1110 |
} |
| 1052 | 1111 |
} |
| 1053 | 1112 |
}); |
| 1054 |
|
|
| 1055 |
jobHandler.setTaskName(""); //$NON-NLS-1$s
|
|
| 1056 |
//TxmPreferences.dump(); |
|
| 1113 |
|
|
| 1114 |
jobHandler.setTaskName(""); //$NON-NLS-1$ s
|
|
| 1115 |
// TxmPreferences.dump();
|
|
| 1057 | 1116 |
return true; |
| 1058 | 1117 |
} |
| 1059 |
} |
|
| 1118 |
} |
|
Formats disponibles : Unified diff