88 |
88 |
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
|
89 |
89 |
|
90 |
90 |
private boolean installPreferenceRestored;
|
91 |
|
|
|
91 |
|
92 |
92 |
private IOConsoleOutputStream stream;
|
93 |
|
|
|
93 |
|
94 |
94 |
private IOConsoleInputStream streamInput;
|
95 |
|
|
|
95 |
|
96 |
96 |
/*
|
97 |
97 |
* (non-Javadoc)
|
98 |
98 |
* @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
|
... | ... | |
101 |
101 |
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
|
102 |
102 |
return new ApplicationWorkbenchWindowAdvisor(configurer);
|
103 |
103 |
}
|
104 |
|
|
|
104 |
|
105 |
105 |
@Override
|
106 |
106 |
public IAdaptable getDefaultPageInput() {
|
107 |
107 |
// MD test 02022023
|
108 |
108 |
//org.eclipse.core.resources.IWorkspace workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace();
|
109 |
109 |
return null;
|
110 |
110 |
}
|
111 |
|
|
|
111 |
|
112 |
112 |
/**
|
113 |
113 |
* initialization code done after the splash screen.
|
114 |
114 |
*
|
... | ... | |
117 |
117 |
@Override
|
118 |
118 |
public void initialize(IWorkbenchConfigurer configurer) {
|
119 |
119 |
org.eclipse.ui.ide.IDE.registerAdapters();
|
120 |
|
|
|
120 |
|
121 |
121 |
PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_PROGRESS_ON_STARTUP, true);
|
122 |
|
|
|
122 |
|
123 |
123 |
InitializeLogger();
|
124 |
|
|
|
124 |
|
125 |
125 |
configurer.setSaveAndRestore(true);
|
126 |
126 |
}
|
127 |
|
|
|
127 |
|
128 |
128 |
@Override
|
129 |
129 |
public void preStartup() {
|
130 |
|
|
|
130 |
|
131 |
131 |
}
|
132 |
|
|
133 |
|
|
134 |
|
|
|
132 |
|
|
133 |
|
|
134 |
|
135 |
135 |
/**
|
136 |
136 |
* Set Eclipse Theme depending on the OS
|
137 |
137 |
*/
|
... | ... | |
139 |
139 |
private void setDefaultTheme() {
|
140 |
140 |
Bundle b = FrameworkUtil.getBundle(getClass());
|
141 |
141 |
BundleContext context = b.getBundleContext();
|
142 |
|
|
|
142 |
|
143 |
143 |
ServiceReference serviceRef = context.getServiceReference(IThemeManager.class.getName());
|
144 |
144 |
@SuppressWarnings("unchecked")
|
145 |
145 |
IThemeManager themeManager = (IThemeManager) context.getService(serviceRef);
|
146 |
146 |
IThemeEngine engine = themeManager.getEngineForDisplay(Display.getDefault());
|
147 |
|
|
|
147 |
|
148 |
148 |
String theme = "org.txm.rcp.theme.default.linux"; //$NON-NLS-1$
|
149 |
|
|
|
149 |
|
150 |
150 |
if (Util.isWindows()) {
|
151 |
151 |
theme = "org.txm.rcp.theme.default.windows"; //$NON-NLS-1$
|
152 |
152 |
}
|
153 |
153 |
else if (Util.isMac()) {
|
154 |
154 |
theme = "org.txm.rcp.theme.default.mac"; //$NON-NLS-1$
|
155 |
155 |
}
|
156 |
|
|
|
156 |
|
157 |
157 |
engine.setTheme(theme, true);
|
158 |
158 |
}
|
159 |
|
|
|
159 |
|
160 |
160 |
/**
|
161 |
161 |
* initialization code done after the splash screen call a job which does the
|
162 |
162 |
* post installation the TXMHOME, checks the TreeTagger and finally
|
... | ... | |
164 |
164 |
*/
|
165 |
165 |
@Override
|
166 |
166 |
public void postStartup() {
|
167 |
|
|
|
167 |
|
168 |
168 |
try {
|
169 |
169 |
// create the Toolbox initialization job
|
170 |
170 |
JobHandler jobhandler = new JobHandler(TXMUIMessages.initializationOfThePlatform, true) {
|
171 |
|
|
|
171 |
|
172 |
172 |
@Override
|
173 |
173 |
protected IStatus run(final IProgressMonitor monitor) {
|
174 |
174 |
JobsTimer.start();
|
175 |
175 |
this.runInit(monitor);
|
176 |
176 |
try {
|
177 |
|
|
|
177 |
|
178 |
178 |
monitor.beginTask(TXMUIMessages.startingTxm, 100);
|
179 |
|
|
|
179 |
|
180 |
180 |
monitor.setTaskName(TXMUIMessages.loadingTXMInstallPreferences);
|
181 |
181 |
Log.fine(TXMUIMessages.startJobColonLoadInstallPreferences);
|
182 |
182 |
if (!checkInstallDirectory(this)) {
|
... | ... | |
185 |
185 |
return Status.CANCEL_STATUS;
|
186 |
186 |
}
|
187 |
187 |
monitor.worked(10);
|
188 |
|
|
|
188 |
|
189 |
189 |
monitor.setTaskName(TXMUIMessages.checkingForExistingWorkspaceDirectory);
|
190 |
190 |
Log.warning(TXMUIMessages.startJobColonCheckTXMHOME);
|
191 |
191 |
if (!checkTXMHOME(this, monitor)) {
|
... | ... | |
194 |
194 |
return Status.CANCEL_STATUS;
|
195 |
195 |
}
|
196 |
196 |
monitor.worked(30);
|
197 |
|
|
|
197 |
|
198 |
198 |
// INITIALIZE TBX AND UI
|
199 |
199 |
monitor.setTaskName(TXMUIMessages.initializingPlatform);
|
200 |
200 |
Log.warning(TXMUIMessages.startJobColonInitializeUI);
|
... | ... | |
202 |
202 |
monitor.done();
|
203 |
203 |
return Status.CANCEL_STATUS;
|
204 |
204 |
}
|
205 |
|
|
|
205 |
|
206 |
206 |
// CREATE THE CLOSE CONTROL FILE
|
207 |
207 |
String rootPath = Platform.getInstanceLocation().getURL().toURI().getPath();
|
208 |
208 |
File lockFile = new File(rootPath, "txm_was_not_closed_correctly.lock");
|
209 |
209 |
if (lockFile.exists()) { // the close control file was not deleted //$NON-NLS-1$
|
|
210 |
lockFile.delete(); //$NON-NLS-1$
|
210 |
211 |
|
211 |
212 |
File checkupResultFile = new File(rootPath, "startup_diagnostic_"+Toolbox.dateformat.format(new Date())+".txt"); //$NON-NLS-1$ //$NON-NLS-2$
|
212 |
|
this.syncExec(new Runnable() {
|
213 |
|
@Override
|
214 |
|
public void run() {
|
215 |
|
int choice = MessageDialog.open(MessageDialog.QUESTION_WITH_CANCEL, Display.getDefault().getActiveShell(),
|
216 |
|
TXMUIMessages.warning,
|
217 |
|
TXMUIMessages.TXMWasNotCorrectlyStopped+"\n"+NLS.bind(TXMUIMessages.DoYouWantToStartADiagnosticOfYourCorporaEtc, checkupResultFile)
|
218 |
|
, SWT.NONE, new String[] {TXMUIMessages.Cancel, TXMUIMessages.OK, TXMUIMessages.OKOpenTheDiagnosticFile});
|
219 |
|
|
220 |
|
if (choice != 0) {
|
221 |
|
Toolbox.writeStartupCorporaDiagnostics(checkupResultFile);
|
|
213 |
checkupResultFile.delete();
|
|
214 |
try {
|
|
215 |
Toolbox.writeStartupCorporaDiagnostics(checkupResultFile);
|
|
216 |
} catch(Exception e) {e.printStackTrace();}
|
|
217 |
|
|
218 |
if (checkupResultFile.exists()) { // ask the user only if errors have been detected
|
|
219 |
this.syncExec(new Runnable() {
|
|
220 |
@Override
|
|
221 |
public void run() {
|
|
222 |
int choice = MessageDialog.open(MessageDialog.QUESTION_WITH_CANCEL, Display.getDefault().getActiveShell(),
|
|
223 |
TXMUIMessages.warning,
|
|
224 |
TXMUIMessages.TXMWasNotCorrectlyStopped+"\n"+NLS.bind(TXMUIMessages.DoYouWantToStartADiagnosticOfYourCorporaEtc, checkupResultFile)
|
|
225 |
, SWT.NONE, new String[] {TXMUIMessages.Cancel, TXMUIMessages.OK, TXMUIMessages.OKOpenTheDiagnosticFile});
|
|
226 |
|
|
227 |
if (choice != 0) {
|
|
228 |
|
|
229 |
}
|
|
230 |
|
|
231 |
if (choice == 2) {
|
|
232 |
org.txm.rcp.handlers.files.EditFile.openfile(checkupResultFile);
|
|
233 |
}
|
222 |
234 |
}
|
223 |
|
|
224 |
|
if (choice == 2) {
|
225 |
|
org.txm.rcp.handlers.files.EditFile.openfile(checkupResultFile);
|
226 |
|
}
|
227 |
|
}
|
228 |
|
});
|
229 |
|
lockFile.delete(); //$NON-NLS-1$
|
|
235 |
});
|
|
236 |
}
|
230 |
237 |
}
|
231 |
238 |
lockFile.createNewFile(); //$NON-NLS-1$
|
232 |
|
|
|
239 |
|
233 |
240 |
Log.info(TXMUIMessages.info_txmIsReady);
|
234 |
241 |
monitor.done();
|
235 |
242 |
}
|
... | ... | |
240 |
247 |
catch (ThreadDeath td) {
|
241 |
248 |
System.out.println(TXMUIMessages.TXMInitializationHasBeenCanceledByUserDotPleaseRestartTXM);
|
242 |
249 |
}
|
243 |
|
|
|
250 |
|
244 |
251 |
JobsTimer.stopAndPrint();
|
245 |
252 |
return Status.OK_STATUS;
|
246 |
253 |
}
|
247 |
254 |
};
|
248 |
255 |
jobhandler.startJob();
|
249 |
|
|
|
256 |
|
250 |
257 |
// start update NOT IN A JOB
|
251 |
258 |
startUpdateLookUpJob(false);
|
252 |
|
|
|
259 |
|
253 |
260 |
}
|
254 |
261 |
catch (Exception e) {
|
255 |
262 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.startupFailedPleaseCheckTXMPreferencesInTheFileSupPreferencesMenuOrContactTxmusersMailingListMenuColonHelpSup, e.getMessage()));
|
... | ... | |
257 |
264 |
Log.printStackTrace(e);
|
258 |
265 |
}
|
259 |
266 |
}
|
260 |
|
|
|
267 |
|
261 |
268 |
public static void closeEmptyEditors(boolean closeOthersEditors) {
|
262 |
269 |
Log.fine("Closing empty editors..."); //$NON-NLS-1$
|
263 |
270 |
String REF = "org.eclipse.ui.internal.emptyEditorTab"; //$NON-NLS-1$
|
264 |
|
|
|
271 |
|
265 |
272 |
for (final IWorkbenchPage page : SWTEditorsUtils.getPages()) {
|
266 |
273 |
ArrayList<IEditorReference> editorRefsList = new ArrayList<>();
|
267 |
274 |
for (IEditorReference editorref : page.getEditorReferences()) {
|
... | ... | |
270 |
277 |
editorRefsList.add(editorref);
|
271 |
278 |
}
|
272 |
279 |
}
|
273 |
|
|
|
280 |
|
274 |
281 |
final IEditorReference[] editorRefs = editorRefsList.toArray(new IEditorReference[editorRefsList.size()]);
|
275 |
282 |
Display.getDefault().syncExec(new Runnable() {
|
276 |
|
|
|
283 |
|
277 |
284 |
@Override
|
278 |
285 |
public void run() {
|
279 |
286 |
page.closeEditors(editorRefs, false);
|
... | ... | |
281 |
288 |
});
|
282 |
289 |
}
|
283 |
290 |
}
|
284 |
|
|
|
291 |
|
285 |
292 |
public static String getTXMStartMessage() {
|
286 |
|
|
|
293 |
|
287 |
294 |
String pretty_version = getTXMVersionPrettyString();
|
288 |
295 |
return NLS.bind(TXMUIMessages.startingUpP0, pretty_version);
|
289 |
|
|
|
296 |
|
290 |
297 |
}
|
291 |
|
|
|
298 |
|
292 |
299 |
public static String getTXMVersion() {
|
293 |
300 |
Version version = Activator.getDefault().getBundle().getVersion();
|
294 |
301 |
return version.getMajor() + "." + version.getMinor() + "." + version.getMicro(); //$NON-NLS-1$ //$NON-NLS-2$
|
295 |
302 |
}
|
296 |
|
|
|
303 |
|
297 |
304 |
public static String getTXMVersionPrettyString() {
|
298 |
|
|
|
305 |
|
299 |
306 |
Version version = getBuildVersion();
|
300 |
307 |
String build_date = getBuildDate(version);
|
301 |
|
|
|
308 |
|
302 |
309 |
String txm_date = getUpdateDate();
|
303 |
310 |
version = Activator.getDefault().getBundle().getVersion();
|
304 |
|
|
|
311 |
|
305 |
312 |
if (txm_date.equals(build_date)) {
|
306 |
313 |
return (NLS.bind(TXMUIMessages.prettyVersionP0P1,
|
307 |
314 |
version.getMajor() + "." + version.getMinor() + "." + version.getMicro(), build_date)); //$NON-NLS-1$ //$NON-NLS-2$
|
... | ... | |
311 |
318 |
version.getMajor() + "." + version.getMinor() + "." + version.getMicro(), "install " + build_date + " - update " + txm_date)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
312 |
319 |
}
|
313 |
320 |
}
|
314 |
|
|
|
321 |
|
315 |
322 |
public static Version getBuildVersion() {
|
316 |
323 |
String version = null;
|
317 |
|
|
|
324 |
|
318 |
325 |
// try finding build date from the p2 artifacts file in installation directory
|
319 |
326 |
String path = BundleUtils.getInstallDirectory();
|
320 |
327 |
if (path != null) {
|
... | ... | |
349 |
356 |
}
|
350 |
357 |
}
|
351 |
358 |
}
|
352 |
|
|
|
359 |
|
353 |
360 |
if (version == null) {
|
354 |
361 |
version = Activator.getDefault().getBundle().getVersion().toString();
|
355 |
362 |
}
|
356 |
|
|
|
363 |
|
357 |
364 |
Version v2 = new Version(version);
|
358 |
365 |
return v2;
|
359 |
366 |
}
|
360 |
|
|
|
367 |
|
361 |
368 |
public static String getBuildDate(Version version) {
|
362 |
369 |
return version.getQualifier().replaceAll("(....)(..)(..)(..)(..)", "$1-$2-$3 $4h$5"); //$NON-NLS-1$ //$NON-NLS-2$
|
363 |
370 |
}
|
364 |
|
|
|
371 |
|
365 |
372 |
public static String getUpdateDate() {
|
366 |
373 |
Version version = Activator.getDefault().getBundle().getVersion();
|
367 |
374 |
return version.getQualifier().replaceAll("(....)(..)(..)(..)(..)", "$1-$2-$3 $4h$5"); //$NON-NLS-1$ //$NON-NLS-2$
|
368 |
375 |
}
|
369 |
|
|
|
376 |
|
370 |
377 |
private void setPreferencesConfiguration() {
|
371 |
378 |
PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();
|
372 |
|
|
|
379 |
|
373 |
380 |
// Remove RCP Update preference page
|
374 |
381 |
if (!TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
375 |
382 |
Log.fine(TXMUIMessages.removeUnusedEclipseRCPPreferencePage);
|
376 |
383 |
pm.remove("org.eclipse.equinox.internal.p2.ui.sdk.ProvisioningPreferencePage"); //$NON-NLS-1$
|
377 |
|
|
|
384 |
|
378 |
385 |
// Remove the Team menu
|
379 |
386 |
pm.remove("org.eclipse.team.ui.TeamPreferences"); //$NON-NLS-1$
|
380 |
|
|
|
387 |
|
381 |
388 |
// XML
|
382 |
389 |
// pm.remove("org.eclipse.wst.xml.ui.preferences.xml"); //$NON-NLS-1$
|
383 |
|
|
|
390 |
|
384 |
391 |
// Validation
|
385 |
392 |
// pm.remove("ValidationPreferencePage"); //$NON-NLS-1$
|
386 |
|
|
|
393 |
|
387 |
394 |
// Debug
|
388 |
395 |
// pm.remove("org.eclipse.debug.ui.DebugPreferencePage"); //$NON-NLS-1$
|
389 |
396 |
}
|
... | ... | |
400 |
407 |
}
|
401 |
408 |
}
|
402 |
409 |
}
|
403 |
|
|
|
410 |
|
404 |
411 |
public void startUpdateLookUpJob(boolean updateCalledFromCommandLine) {
|
405 |
412 |
if (needToRestoreTXMHOME) return; // don't call for update for the first run of TXM
|
406 |
|
|
|
413 |
|
407 |
414 |
try {
|
408 |
415 |
boolean doUpdate = TBXPreferences.getInstance().getBoolean(TBXPreferences.FETCH_UPDATES_AT_STARTUP);
|
409 |
416 |
if (!doUpdate) return;
|
... | ... | |
411 |
418 |
// this.syncExec(new Runnable() {
|
412 |
419 |
// @Override
|
413 |
420 |
// public void run() {
|
414 |
|
|
|
421 |
|
415 |
422 |
try {
|
416 |
423 |
URL url = new URL("https://gitlab.huma-num.fr/txm/txm-software/-/raw/master/dist/index.html"); //$NON-NLS-1$
|
417 |
424 |
Log.fine(TXMCoreMessages.bind("Testing if update site is available: {0}...", url)); //$NON-NLS-1$
|
... | ... | |
424 |
431 |
doUpdate = false;
|
425 |
432 |
return;
|
426 |
433 |
}
|
427 |
|
|
|
434 |
|
428 |
435 |
Log.info(TXMUIMessages.startingUpdateFetch);
|
429 |
|
|
|
436 |
|
430 |
437 |
Display.getDefault().syncExec(new Runnable() {
|
431 |
|
|
|
438 |
|
432 |
439 |
@Override
|
433 |
440 |
public void run() {
|
434 |
441 |
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
|
... | ... | |
456 |
463 |
System.out.println(TXMUIMessages.updateCanceled);
|
457 |
464 |
}
|
458 |
465 |
}
|
459 |
|
|
|
466 |
|
460 |
467 |
public static boolean testTXMHOMEPreferenceAndDirectory() {
|
461 |
468 |
String path = Toolbox.getTxmHomePath();
|
462 |
|
|
|
469 |
|
463 |
470 |
if (path == null || path.trim().equals("")) { //$NON-NLS-1$
|
464 |
471 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsNotSetP0PreferenceIsNotSet, TBXPreferences.USER_TXM_HOME));
|
465 |
472 |
return true;
|
... | ... | |
477 |
484 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsSetToP0ButTXMCantCdInThisDirectory, dir));
|
478 |
485 |
return true;
|
479 |
486 |
}
|
480 |
|
|
|
487 |
|
481 |
488 |
return false;
|
482 |
489 |
}
|
483 |
|
|
|
490 |
|
484 |
491 |
public static boolean testTXMINSTALLPreferenceAndDirectory() {
|
485 |
492 |
// TxmPreferences.dump();
|
486 |
493 |
if (Toolbox.getInstallDirectory() == null) {
|
487 |
494 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.TXMInstallDirectoryIsNotSetP0PreferenceIsNotSet, TBXPreferences.INSTALL_DIR));
|
488 |
495 |
return true;
|
489 |
496 |
}
|
490 |
|
|
|
497 |
|
491 |
498 |
File installdir = new File(Toolbox.getInstallDirectory().trim());
|
492 |
499 |
if (Toolbox.getInstallDirectory().equals("")) { //$NON-NLS-1$
|
493 |
500 |
Log.warning(TXMUIMessages.TXMInstallDirectoryIsSetToQuoteQuote);
|
... | ... | |
507 |
514 |
}
|
508 |
515 |
return false;
|
509 |
516 |
}
|
510 |
|
|
|
517 |
|
511 |
518 |
/**
|
512 |
519 |
* shutdown code.
|
513 |
520 |
*/
|
514 |
521 |
@Override
|
515 |
522 |
public void postShutdown() {
|
516 |
523 |
callPreStopScript();
|
517 |
|
|
|
524 |
|
518 |
525 |
Toolbox.shutdown();
|
519 |
|
|
|
526 |
|
520 |
527 |
callStopScript();
|
521 |
|
|
|
528 |
|
522 |
529 |
new File("txm_was_not_closed_correctly.lock").delete(); //$NON-NLS-1$
|
523 |
530 |
}
|
524 |
|
|
|
531 |
|
525 |
532 |
/**
|
526 |
533 |
* shutdown code.
|
527 |
534 |
*/
|
... | ... | |
533 |
540 |
catch (Exception e) {
|
534 |
541 |
e.printStackTrace();
|
535 |
542 |
}
|
536 |
|
|
|
543 |
|
537 |
544 |
return continueShutDownForPersistedResults();
|
538 |
545 |
}
|
539 |
|
|
|
546 |
|
540 |
547 |
private boolean continueShutDownForPersistedResults() {
|
541 |
548 |
if (Toolbox.workspace == null) return true; // nothing to do
|
542 |
|
|
|
549 |
|
543 |
550 |
StringBuffer messages = new StringBuffer();
|
544 |
551 |
for (Project project : Toolbox.workspace.getProjects()) {
|
545 |
552 |
ArrayList<String> bugs = new ArrayList<>();
|
... | ... | |
552 |
559 |
messages.append("- " + project.getName() + ": " + bugs + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
553 |
560 |
}
|
554 |
561 |
}
|
555 |
|
|
|
562 |
|
556 |
563 |
if (messages.length() > 0) {
|
557 |
564 |
return MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "", NLS.bind(TXMUIMessages.warning_popup_editedResultsWillBelostP0, messages)); //$NON-NLS-1$
|
558 |
565 |
}
|
559 |
566 |
return true;
|
560 |
567 |
}
|
561 |
|
|
|
568 |
|
562 |
569 |
/*
|
563 |
570 |
* (non-Javadoc)
|
564 |
571 |
* @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
|
... | ... | |
567 |
574 |
public String getInitialWindowPerspectiveId() {
|
568 |
575 |
return TXMPerspective.ID;
|
569 |
576 |
}
|
570 |
|
|
|
577 |
|
571 |
578 |
/**
|
572 |
579 |
* initialize TXM log in console by redirecting stderr and stdout.
|
573 |
580 |
*/
|
574 |
581 |
private void InitializeLogger() {
|
575 |
582 |
IOConsole console = new IOConsole(TXMUIMessages.systemOutput, null);
|
576 |
583 |
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
|
577 |
|
|
|
584 |
|
578 |
585 |
// Enable or disable the outputs redirection to the RCP console according to the command line argument "-noredirection"
|
579 |
586 |
boolean outputsRedirection = true;
|
580 |
587 |
String[] args = Platform.getCommandLineArgs();
|
... | ... | |
587 |
594 |
if (outputsRedirection) {
|
588 |
595 |
stream = console.newOutputStream();
|
589 |
596 |
streamInput = console.getInputStream();
|
590 |
|
|
|
597 |
|
591 |
598 |
System.setOut(new PrintStream(stream));
|
592 |
599 |
System.setErr(new PrintStream(stream));
|
593 |
600 |
System.setIn(streamInput);
|
594 |
601 |
}
|
595 |
602 |
// System.out.println(Messages.ApplicationWorkbenchAdvisor_3);
|
596 |
603 |
}
|
597 |
|
|
|
604 |
|
598 |
605 |
public void setConsoleOutputColor(Color newColor) {
|
599 |
606 |
if (stream != null) stream.setColor(newColor);
|
600 |
607 |
}
|
601 |
|
|
|
608 |
|
602 |
609 |
/**
|
603 |
610 |
* if INSTALLDIR preference is not set or empty, read the install.prefs file and set the
|
604 |
611 |
*
|
... | ... | |
617 |
624 |
boolean needTosetInstallPreference = testTXMINSTALLPreferenceAndDirectory();
|
618 |
625 |
// check if the install preference file has been loaded
|
619 |
626 |
if (needTosetInstallPreference) {
|
620 |
|
|
|
627 |
|
621 |
628 |
installPreferenceRestored = false; // reset and finally set true if the process ended correctly
|
622 |
|
|
|
629 |
|
623 |
630 |
// set the install directory preference
|
624 |
631 |
String installpath = Platform.getInstallLocation().getURL().getFile(); // the TXM.exe file path
|
625 |
632 |
File installDirectory = new File(installpath);
|
626 |
633 |
// installDirectory = installDirectory.getCanonicalFile();
|
627 |
|
|
|
634 |
|
628 |
635 |
// TODO: ensure all preferences of install.prefs file are now stored in the default preferences
|
629 |
636 |
// File preferenceFile = new File(installDirectory, "install.prefs"); //$NON-NLS-1$
|
630 |
637 |
// if (preferenceFile.exists()) {
|
... | ... | |
660 |
667 |
// }
|
661 |
668 |
// }
|
662 |
669 |
// }
|
663 |
|
|
|
670 |
|
664 |
671 |
installPreferenceRestored = true;
|
665 |
|
|
|
672 |
|
666 |
673 |
if (installDirectory == null || !installDirectory.exists()) {
|
667 |
674 |
Log.severe(TXMUIMessages.errorTheProvidedInstallDirectoryDoesNotExistAborting);
|
668 |
675 |
return false;
|
669 |
676 |
}
|
670 |
|
|
|
677 |
|
671 |
678 |
TBXPreferences.getInstance().put(TBXPreferences.INSTALL_DIR, installDirectory.getAbsolutePath());
|
672 |
679 |
TBXPreferences.getInstance().flush();
|
673 |
680 |
return true;
|
... | ... | |
680 |
687 |
}
|
681 |
688 |
return true;
|
682 |
689 |
}
|
683 |
|
|
|
690 |
|
684 |
691 |
boolean go = false;
|
685 |
|
|
|
692 |
|
686 |
693 |
File backup;
|
687 |
|
|
|
694 |
|
688 |
695 |
File oldbackup;
|
689 |
|
|
|
696 |
|
690 |
697 |
File errorbackup;
|
691 |
|
|
|
698 |
|
692 |
699 |
File corporaDir;
|
693 |
|
|
|
700 |
|
694 |
701 |
/**
|
695 |
702 |
* if TXMHOME path is not set or wrong
|
696 |
703 |
* - set default theme
|
... | ... | |
701 |
708 |
*
|
702 |
709 |
*/
|
703 |
710 |
private static boolean needToRestoreTXMHOME;
|
704 |
|
|
|
711 |
|
705 |
712 |
public static boolean getWasFirstLaunch() {
|
706 |
713 |
return needToRestoreTXMHOME;
|
707 |
714 |
}
|
708 |
|
|
|
715 |
|
709 |
716 |
File txmhomedir = null;
|
710 |
|
|
|
717 |
|
711 |
718 |
File installDirectory = null;
|
712 |
|
|
|
719 |
|
713 |
720 |
private Handler severeDialobBoxHandler = new Handler() {
|
714 |
|
|
|
721 |
|
715 |
722 |
@Override
|
716 |
723 |
public void publish(final LogRecord record) {
|
717 |
724 |
// System.out.println("severeDialobBoxHandler.publish()");
|
718 |
725 |
boolean showSevereDialobBox = RCPPreferences.getInstance().getBoolean(RCPPreferences.SHOW_SEVERE_DIALOG);
|
719 |
726 |
if (showSevereDialobBox) {
|
720 |
727 |
if (record.getLevel() != Level.SEVERE) return;
|
721 |
|
|
|
728 |
|
722 |
729 |
final IWorkbench w = PlatformUI.getWorkbench();
|
723 |
730 |
if (w == null) {
|
724 |
731 |
//System.out.println("no workbench"); //$NON-NLS-1$
|
725 |
732 |
return;
|
726 |
733 |
}
|
727 |
|
|
|
734 |
|
728 |
735 |
w.getDisplay().syncExec(new Runnable() {
|
729 |
|
|
|
736 |
|
730 |
737 |
@Override
|
731 |
738 |
public void run() {
|
732 |
|
// try {
|
733 |
|
// IWorkbenchWindow aww = w.getActiveWorkbenchWindow();
|
734 |
|
// if (aww == null) {
|
735 |
|
// System.out.println(TXMUIMessages.noActiveWorkbenchWindow);
|
736 |
|
// return;
|
737 |
|
// }
|
738 |
|
// IWorkbenchPage page = aww.getActivePage();
|
739 |
|
// if (page == null) {
|
740 |
|
// System.out.println(TXMUIMessages.noActivePage);
|
741 |
|
// return;
|
742 |
|
// }
|
743 |
|
// IViewPart view = page.findView("org.eclipse.pde.runtime.LogView"); //$NON-NLS-1$
|
744 |
|
// if (view == null) {
|
745 |
|
// view = page.showView("org.eclipse.pde.runtime.LogView"); //$NON-NLS-1$
|
746 |
|
// }
|
747 |
|
// }
|
748 |
|
// catch (Exception e1) {
|
749 |
|
// System.out.println(TXMUIMessages.partInitializationErrorColon + e1);
|
750 |
|
// e1.printStackTrace();
|
751 |
|
// return;
|
752 |
|
// }
|
|
739 |
// try {
|
|
740 |
// IWorkbenchWindow aww = w.getActiveWorkbenchWindow();
|
|
741 |
// if (aww == null) {
|
|
742 |
// System.out.println(TXMUIMessages.noActiveWorkbenchWindow);
|
|
743 |
// return;
|
|
744 |
// }
|
|
745 |
// IWorkbenchPage page = aww.getActivePage();
|
|
746 |
// if (page == null) {
|
|
747 |
// System.out.println(TXMUIMessages.noActivePage);
|
|
748 |
// return;
|
|
749 |
// }
|
|
750 |
// IViewPart view = page.findView("org.eclipse.pde.runtime.LogView"); //$NON-NLS-1$
|
|
751 |
// if (view == null) {
|
|
752 |
// view = page.showView("org.eclipse.pde.runtime.LogView"); //$NON-NLS-1$
|
|
753 |
// }
|
|
754 |
// }
|
|
755 |
// catch (Exception e1) {
|
|
756 |
// System.out.println(TXMUIMessages.partInitializationErrorColon + e1);
|
|
757 |
// e1.printStackTrace();
|
|
758 |
// return;
|
|
759 |
// }
|
753 |
760 |
MessageDialog.openError(w.getDisplay().getActiveShell(), "Error", record.getMessage());
|
754 |
761 |
}
|
755 |
762 |
});
|
756 |
|
|
757 |
|
// IStatus s = new Status(Status.ERROR, Application.PLUGIN_ID, Status.OK, record.getMessage(), null);
|
758 |
|
// StatusManager.getManager().handle(s, StatusManager.LOG);
|
|
763 |
|
|
764 |
// IStatus s = new Status(Status.ERROR, Application.PLUGIN_ID, Status.OK, record.getMessage(), null);
|
|
765 |
// StatusManager.getManager().handle(s, StatusManager.LOG);
|
759 |
766 |
}
|
760 |
767 |
}
|
761 |
|
|
|
768 |
|
762 |
769 |
@Override
|
763 |
770 |
public void flush() {}
|
764 |
|
|
|
771 |
|
765 |
772 |
@Override
|
766 |
773 |
public void close() throws SecurityException {}
|
767 |
774 |
};
|
768 |
|
|
|
775 |
|
769 |
776 |
/**
|
770 |
777 |
* internal variable to know if the txm home directory has been created
|
771 |
778 |
*/
|
772 |
779 |
private boolean txmHomeRestored;
|
773 |
|
|
|
780 |
|
774 |
781 |
{
|
775 |
782 |
Log.addHandler(severeDialobBoxHandler);
|
776 |
783 |
severeDialobBoxHandler.setLevel(Level.SEVERE);
|
777 |
784 |
}
|
778 |
|
|
|
785 |
|
779 |
786 |
private boolean checkTXMHOME(JobHandler jobHandler, IProgressMonitor monitor) {
|
780 |
787 |
txmhomedir = null;
|
781 |
788 |
installDirectory = null;
|
782 |
|
|
|
789 |
|
783 |
790 |
// check if TXMHOME of the user is set and exists
|
784 |
791 |
needToRestoreTXMHOME = testTXMHOMEPreferenceAndDirectory();
|
785 |
792 |
Log.fine("needToRestoreTXMHOME=" + needToRestoreTXMHOME + " installPreferenceRestored=" + installPreferenceRestored); //$NON-NLS-1$ //$NON-NLS-2$
|
786 |
793 |
if (needToRestoreTXMHOME || installPreferenceRestored) {
|
787 |
|
|
|
794 |
|
788 |
795 |
System.out.println(TXMUIMessages.creatingTXMUserWorkingDirectory);
|
789 |
|
|
|
796 |
|
790 |
797 |
try {
|
791 |
798 |
Log.info(NLS.bind(TXMUIMessages.installPathColonP0, Toolbox.getInstallDirectory()));
|
792 |
|
|
|
799 |
|
793 |
800 |
//MD test 02022023
|
794 |
801 |
//txmhomedir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalFile();
|
795 |
802 |
txmhomedir = Platform.getLocation().toFile().getCanonicalFile();
|
796 |
803 |
txmhomedir.mkdirs(); // creates the directory if needed
|
797 |
|
|
|
804 |
|
798 |
805 |
txmhomedir.mkdirs(); // creates the directory if needed
|
799 |
|
|
|
806 |
|
800 |
807 |
if (!txmhomedir.exists()) {
|
801 |
808 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.errorTheProvidedTXMHOMEDirectoryDoesNotExistsP0Aborting, txmhomedir));
|
802 |
809 |
return false;
|
803 |
810 |
}
|
804 |
|
|
|
811 |
|
805 |
812 |
// save preference if USER_TXM_HOME has changed
|
806 |
813 |
TBXPreferences.getInstance().put(TBXPreferences.USER_TXM_HOME, txmhomedir.getAbsolutePath());
|
807 |
814 |
TBXPreferences.getInstance().flush();
|
808 |
815 |
// TXMPreferences.saveAll();
|
809 |
|
|
|
816 |
|
810 |
817 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.TXMUserDirectoryIsSetToP0, txmhomedir));
|
811 |
|
|
|
818 |
|
812 |
819 |
txmHomeRestored = true;
|
813 |
820 |
}
|
814 |
821 |
catch (Exception e) {
|
... | ... | |
817 |
824 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.failedToBackupExistingCorporaColon, e.getLocalizedMessage()));
|
818 |
825 |
return false;
|
819 |
826 |
}
|
820 |
|
|
|
827 |
|
821 |
828 |
} // end if
|
822 |
|
|
|
829 |
|
823 |
830 |
return true;
|
824 |
831 |
}
|
825 |
|
|
|
832 |
|
826 |
833 |
/**
|
827 |
834 |
* Install the sample corpora and previous TXM version corpora in TXM corpora directory
|
828 |
835 |
*
|
... | ... | |
836 |
843 |
// return; // dev mode
|
837 |
844 |
// }
|
838 |
845 |
monitor.setTaskName(TXMUIMessages.restoringCorpora);
|
839 |
|
|
|
846 |
|
840 |
847 |
RecoverCorporaFromInstalls.restore(true);
|
841 |
|
|
|
848 |
|
842 |
849 |
try {
|
843 |
850 |
Display.getDefault().syncExec(new Runnable() {
|
844 |
|
|
|
851 |
|
845 |
852 |
@Override
|
846 |
853 |
public void run() {
|
847 |
854 |
OpenWelcomePage.openWelcomePage();
|
... | ... | |
851 |
858 |
catch (Exception e2) {
|
852 |
859 |
try {
|
853 |
860 |
Display.getCurrent().syncExec(new Runnable() {
|
854 |
|
|
|
861 |
|
855 |
862 |
@Override
|
856 |
863 |
public void run() {
|
857 |
864 |
OpenWelcomePage.openWelcomePage();
|
... | ... | |
864 |
871 |
} catch (Exception e4) { }
|
865 |
872 |
}
|
866 |
873 |
}
|
867 |
|
|
|
874 |
|
868 |
875 |
monitor.setTaskName(""); //$NON-NLS-1$
|
869 |
876 |
}
|
870 |
|
|
|
877 |
|
871 |
878 |
/**
|
872 |
879 |
* Executes the specified Groovy script file.
|
873 |
880 |
*
|
... | ... | |
884 |
891 |
Log.printStackTrace(e);
|
885 |
892 |
}
|
886 |
893 |
}
|
887 |
|
|
888 |
|
|
|
894 |
|
|
895 |
|
889 |
896 |
/**
|
890 |
897 |
* Called just before the Toolbox is initialized
|
891 |
898 |
*/
|
892 |
899 |
private void callPreStartScript() {
|
893 |
900 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/prestart.groovy")); //$NON-NLS-1$
|
894 |
901 |
}
|
895 |
|
|
|
902 |
|
896 |
903 |
/**
|
897 |
904 |
* Called just after Toolbox is initialized
|
898 |
905 |
*/
|
899 |
906 |
private void callStartScript() {
|
900 |
907 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/start.groovy")); //$NON-NLS-1$
|
901 |
908 |
}
|
902 |
|
|
|
909 |
|
903 |
910 |
/**
|
904 |
911 |
* Called just before Toolbox is stop call
|
905 |
912 |
*/
|
906 |
913 |
private void callPreStopScript() {
|
907 |
914 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/prestop.groovy")); //$NON-NLS-1$
|
908 |
915 |
}
|
909 |
|
|
|
916 |
|
910 |
917 |
/**
|
911 |
918 |
* Called just after Toolbox is stop call
|
912 |
919 |
*/
|
913 |
920 |
private void callStopScript() {
|
914 |
921 |
this.callGroovyScript(new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/stop.groovy")); //$NON-NLS-1$
|
915 |
922 |
}
|
916 |
|
|
|
923 |
|
917 |
924 |
ProgressMonitorDialog initializeUIPMD; // store the state of the initializeUI step
|
918 |
|
|
|
925 |
|
919 |
926 |
/**
|
920 |
927 |
* after TXMHOME AND INSTALLDIR are ok, we can start the Toolbox
|
921 |
928 |
* <p>
|
... | ... | |
932 |
939 |
* @throws Exception
|
933 |
940 |
*/
|
934 |
941 |
private boolean initializeUI(final JobHandler jobHandler) throws Exception {
|
935 |
|
|
|
942 |
|
936 |
943 |
// Fix the freeze at splash screen on Mac OS X/Cocoa because of a deadlock between AWT/SWT threads (bug #894)
|
937 |
944 |
Display.getDefault().syncExec(new Runnable() {
|
938 |
|
|
|
945 |
|
939 |
946 |
@Override
|
940 |
947 |
public void run() {
|
941 |
948 |
try {
|
942 |
949 |
System.out.println(getTXMStartMessage());
|
943 |
|
|
|
950 |
|
944 |
951 |
// ensure some preferences are set
|
945 |
952 |
DefaultScope.INSTANCE.getNode("org.eclipse.ui.workbench").putBoolean(IPreferenceConstants.RUN_IN_BACKGROUND, false); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
946 |
953 |
DefaultScope.INSTANCE.getNode("org.eclipse.ui.workbench").flush(); //$NON-NLS-1$
|
947 |
954 |
BundleDefaultsScope.INSTANCE.getNode("org.eclipse.ui.workbench").putBoolean(IPreferenceConstants.RUN_IN_BACKGROUND, false); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
948 |
955 |
BundleDefaultsScope.INSTANCE.getNode("org.eclipse.ui.workbench").flush(); //$NON-NLS-1$
|
949 |
|
|
|
956 |
|
950 |
957 |
WorkbenchPlugin.getDefault().getPreferenceStore().setValue(IPreferenceConstants.RUN_IN_BACKGROUND, false);
|
951 |
958 |
WorkbenchPlugin.getDefault().getPreferenceStore().setDefault(IPreferenceConstants.RUN_IN_BACKGROUND, false);
|
952 |
959 |
WorkbenchPlugin.getDefault().getPreferenceStore().setValue(IPreferenceConstants.WORKBENCH_SAVE_INTERVAL, 30);
|
953 |
960 |
WorkbenchPlugin.getDefault().getPreferenceStore().setDefault(IPreferenceConstants.WORKBENCH_SAVE_INTERVAL, 30);
|
954 |
|
|
|
961 |
|
955 |
962 |
jobHandler.setTaskName(TXMUIMessages.setDefaultTheme);
|
956 |
963 |
setDefaultTheme();
|
957 |
|
|
|
964 |
|
958 |
965 |
// CLOSE Empty&Error editors
|
959 |
966 |
jobHandler.setTaskName(TXMUIMessages.closingEmptyEditors);
|
960 |
967 |
closeEmptyEditors(false);
|
961 |
|
|
|
968 |
|
962 |
969 |
// remove some preference pages
|
963 |
970 |
setPreferencesConfiguration();
|
964 |
|
|
|
971 |
|
965 |
972 |
initializeUIPMD = new ProgressMonitorDialog(Display.getDefault().getActiveShell()) {
|
966 |
973 |
@Override
|
967 |
974 |
protected void configureShell(final Shell shell) {
|
... | ... | |
969 |
976 |
shell.setText(getTXMStartMessage());
|
970 |
977 |
}
|
971 |
978 |
};
|
972 |
|
|
|
979 |
|
973 |
980 |
initializeUIPMD.run(true, true, new IRunnableWithProgress() {
|
974 |
|
|
|
981 |
|
975 |
982 |
@Override
|
976 |
983 |
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
977 |
|
|
|
984 |
|
978 |
985 |
if (!Toolbox.isInitialized()) {
|
979 |
986 |
try {
|
980 |
987 |
monitor.worked(1);
|
981 |
|
|
|
988 |
|
982 |
989 |
monitor.setTaskName(TXMUIMessages.callingGroovyPrestartScript);
|
983 |
990 |
callPreStartScript();
|
984 |
991 |
monitor.worked(20);
|
985 |
|
|
|
992 |
|
986 |
993 |
monitor.setTaskName(TXMUIMessages.initializingToolboxEnginesAndCorpora);
|
987 |
994 |
if (Toolbox.initialize(TBXPreferences.class, monitor)) {
|
988 |
995 |
// StatusLine.setMessage(TXMUIMessages.ready);
|
... | ... | |
990 |
997 |
else {
|
991 |
998 |
StatusLine.setMessage(TXMUIMessages.startupFailedPleaseCheckTXMPreferencesInTheFileSupPreferencesMenuOrContactTxmusersMailingListMenuColonHelpSup);
|
992 |
999 |
Log.severe(TXMUIMessages.startupFailedPleaseCheckTXMPreferencesInTheFileSupPreferencesMenuOrContactTxmusersMailingListMenuColonHelpSup);
|
993 |
|
|
|
1000 |
|
994 |
1001 |
monitor.done();
|
995 |
1002 |
return;
|
996 |
1003 |
}
|
997 |
1004 |
monitor.worked(20);
|
998 |
|
|
|
1005 |
|
999 |
1006 |
monitor.setTaskName(TXMUIMessages.callingGroovyStartScript);
|
1000 |
1007 |
callStartScript();
|
1001 |
1008 |
monitor.worked(20);
|
1002 |
|
|
|
1009 |
|
1003 |
1010 |
// restore corpora if TXMHOME has been created
|
1004 |
1011 |
if (txmHomeRestored) {
|
1005 |
1012 |
installCorporaDirectory(monitor);
|
1006 |
|
|
|
1013 |
|
1007 |
1014 |
Toolbox.workspace.saveParameters(true);
|
1008 |
1015 |
ResourcesPlugin.getWorkspace().save(true, null);
|
1009 |
1016 |
}
|
1010 |
1017 |
monitor.worked(20);
|
1011 |
|
|
|
1018 |
|
1012 |
1019 |
jobHandler.setTaskName(TXMUIMessages.toolboxReady);
|
1013 |
1020 |
}
|
1014 |
1021 |
catch (Throwable e) {
|
... | ... | |
1016 |
1023 |
e.printStackTrace();
|
1017 |
1024 |
}
|
1018 |
1025 |
}
|
1019 |
|
|
|
1026 |
|
1020 |
1027 |
monitor.done();
|
1021 |
1028 |
}
|
1022 |
1029 |
});
|
1023 |
|
|
|
1030 |
|
1024 |
1031 |
Log.fine(TXMUIMessages.loadingViews);
|
1025 |
1032 |
RestartTXM.reloadViews(); // reload views
|
1026 |
|
|
|
1033 |
|
1027 |
1034 |
}
|
1028 |
1035 |
catch (Exception e) {
|
1029 |
1036 |
Log.severe(TXMCoreMessages.bind(TXMUIMessages.errorDuringUIInitializationP0, e.getLocalizedMessage()));
|
... | ... | |
1031 |
1038 |
}
|
1032 |
1039 |
}
|
1033 |
1040 |
});
|
1034 |
|
|
|
1041 |
|
1035 |
1042 |
jobHandler.setTaskName(""); //$NON-NLS-1$ s
|
1036 |
1043 |
// TxmPreferences.dump();
|
1037 |
1044 |
return initializeUIPMD != null && !initializeUIPMD.getProgressMonitor().isCanceled();
|