package org.eparapher.rcp; import org.apache.log4j.Logger; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; import org.eparapher.core.EParapherManager; import org.eparapher.core.crypto.EPCryptoProviderManager; import org.eparapher.core.crypto.EPKeystoreManager; import org.eparapher.core.crypto.JCEPolicyDetection; import org.eparapher.core.tools.JVMSettings; import org.eparapher.core.tools.OODaemonManager; import org.eparapher.rcp.tools.RCPGUI; import org.eparapher.rcp.tools.RCPSettings; import org.eparapher.rcp.tools.eParapherTools; import org.eparapher.rcp.tray.TrayIconManager; public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { private static Logger log = Logger.getLogger(ApplicationWorkbenchWindowAdvisor.class); private TrayIconManager trayIcon; private EPKeystoreManager epkeystoremgr; private boolean inittks; public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { super(configurer); EPReferences.getInstance().setAppadvisor(this); } public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) { return new ApplicationActionBarAdvisor(configurer); } public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize(new Point(1024,768)); configurer.setShowCoolBar(true); configurer.setShowProgressIndicator(true); configurer.setShowPerspectiveBar(true); configurer.setShowStatusLine(true); configurer.setShowMenuBar(true); configurer.setShowFastViewBars(false); configurer.setTitle("eParapher"); //Setting eParapher Core Settings and UI EParapherManager.getInstance().setUI(new RCPGUI()); EParapherManager.getInstance().setSettings(new RCPSettings()); EPReferences.getInstance().setWindowConfigurer(getWindowConfigurer()); trayIcon = new TrayIconManager(getWindowConfigurer()); // initialize Crypto providers EPCryptoProviderManager.initCryptoProviders(); //initialize Crypto providers and Keystores epkeystoremgr = EPKeystoreManager.getInstance(); inittks = epkeystoremgr.initTrustKeystore(); } public void postWindowOpen() { //test JCE Unlimited Crypto if (!JCEPolicyDetection.QuickJCEPolicyTest()) EParapherManager.getInstance().getUI().warnMessage("The Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files has not been applied on the JRE/JDK.\r\nPlease Download it and install it if you want to use strong cryptograpy algorithms and/or keys."); // Setting status line EPReferences.getInstance().setStatusline(getWindowConfigurer().getActionBarConfigurer().getStatusLineManager()); //Initialize the PDF Image in eParapher directory eParapherTools.createSignatureImage(); if (!JVMSettings.isJava16Min()) RCPGUI.infoMessage("Java 1.5 limitation", "XML digital signatures are not avalaible with Java 1.5"); //Start tracking thread for PKCS11 devices epkeystoremgr.startTrackingThread(); //Start OpenOffice if needed if ( EParapherManager.getInstance().getSettings().useLocalOpenOffice() && EParapherManager.getInstance().getSettings().isOpenOfficeAutostart() ) { try { OODaemonManager.getInstance().start(); } catch (Exception e) { EParapherManager.getInstance().getUI().errorMessage("Could not start OpenOffice Deamon for PDF convertion",e); } } //execute files setted in command line EPReferences.getInstance().getRcpsingleton().executeCommandsFromCommandLine(null); EPReferences.getInstance().getStatusline().setMessage(null, "eParapher is ready"); } /* * (non-Javadoc) * * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowCreate() */ public void postWindowCreate() { trayIcon.StartupFinished(); } /** * Hide the main window but stay in system tray */ public boolean preWindowShellClose() { getWindowConfigurer().getWindow().getShell().setVisible(false); return false; } @Override public void postWindowClose() { super.postWindowClose(); if (EParapherManager.getInstance().getSettings().isOpenOfficeAutostart()) OODaemonManager.getInstance().stop(); } public TrayIconManager getTrayIcon() { return trayIcon; } /* Call from new instances. * * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) */ public void handleEvent(Event event, String message) { Shell workbenchWindowShell = getWindowConfigurer().getWindow().getShell(); workbenchWindowShell.setVisible(true); workbenchWindowShell.setActive(); workbenchWindowShell.setFocus(); workbenchWindowShell.setMinimized(true); String[] args = message.split("\\r\\n"); EPReferences.getInstance().getRcpsingleton().executeCommandsFromCommandLine(args); } }