View Javadoc

1   package org.eparapher.rcp;
2   
3   import org.apache.log4j.Logger;
4   import org.eclipse.swt.graphics.Point;
5   import org.eclipse.ui.application.ActionBarAdvisor;
6   import org.eclipse.ui.application.IActionBarConfigurer;
7   import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
8   import org.eclipse.ui.application.WorkbenchWindowAdvisor;
9   import org.eparapher.core.EParapherManager;
10  import org.eparapher.core.crypto.EPCryptoProviderManager;
11  import org.eparapher.core.crypto.EPKeystoreManager;
12  import org.eparapher.core.crypto.JCEPolicyTest;
13  import org.eparapher.core.tools.JVMSettings;
14  import org.eparapher.core.tools.OODaemonManager;
15  import org.eparapher.rcp.tools.RCPGUI;
16  import org.eparapher.rcp.tools.RCPSettings;
17  import org.eparapher.rcp.tools.eParapherTools;
18  import org.eparapher.rcp.tray.TrayIconManager;
19  
20  
21  public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
22  
23  	private static Logger log = Logger.getLogger(ApplicationWorkbenchWindowAdvisor.class);
24  
25  	private TrayIconManager trayIcon;
26  	private EPKeystoreManager epkeystoremgr;
27  
28  	private boolean inittks;
29  	
30      public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
31          super(configurer);
32      }
33  
34      public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
35          return new ApplicationActionBarAdvisor(configurer);
36      }
37      
38      public void preWindowOpen() {
39      	
40          IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
41          configurer.setInitialSize(new Point(1024,768));
42          configurer.setShowCoolBar(true);
43          configurer.setShowProgressIndicator(true);
44          configurer.setShowPerspectiveBar(true);
45          configurer.setShowStatusLine(true);
46          configurer.setShowMenuBar(true);
47          configurer.setShowFastViewBars(false);
48          configurer.setTitle("eParapher");
49  
50          //Setting eParapher Core Settings and UI
51          EParapherManager.getInstance().setUI(new RCPGUI());
52          EParapherManager.getInstance().setSettings(new RCPSettings());
53          
54          EPReferences.getInstance().setWindowConfigurer(getWindowConfigurer());
55      	
56          trayIcon = new TrayIconManager(getWindowConfigurer());
57          
58  		// initialize Crypto providers
59          EPCryptoProviderManager.initCryptoProviders();
60          
61          //initialize Crypto providers and Keystores
62          epkeystoremgr = EPKeystoreManager.getInstance();
63          inittks = epkeystoremgr.initTrustKeystore();
64  
65      }
66  
67  	public void postWindowOpen() {
68  
69  		//test JCE Unlimited Crypto
70          if (!JCEPolicyTest.QuickJCEPolicyTest())
71          	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.");
72  
73          //Hot reset for Log4J
74      	EParapherManager.setLogLevel(EParapherManager.getInstance().getSettings().getEPLogLevel());
75      	
76  		// Setting status line
77  		EPReferences.getInstance().setStatusline(getWindowConfigurer().getActionBarConfigurer().getStatusLineManager());
78  		
79  		//Init user keystore and prompt if errors
80          /*
81          if (!epkeystoremgr.initUserKeystore())
82          	eParapherTools.errorMessage("Failed to initialize your Personal Keystore.\r\nPlease change it in configuration.");
83          if (inittks == false)
84          	eParapherTools.errorMessage("Failed to initialize your TrustKeystore.\r\nPlease change it in configuration.");
85          
86          //Load Keystore : Create keystore and certificates if not exists.
87          IUserKeystore userks  = epkeystoremgr.getUserkeystore();
88          if (!userks.exists()) {
89          	userks.initialize();
90          }*/
91          
92          // Find if there is a usable alias/certificate for signing operations
93          /* else {
94          	if ( userks.hasSignatureAlias() ) {
95          		userks.generatesignaturecertificate();
96          		}
97          	}
98          */
99  		
100         //Create PDF Image
101         eParapherTools.createSignatureImage();
102         
103         if (!JVMSettings.isJava16Min())
104         	RCPGUI.infoMessage("Java 1.5 limitation", "XML digital signatures are not avalaible with Java 1.5");
105 
106 		//Start tracking thread for PKCS11 devices
107 		epkeystoremgr.startTrackingThread();
108 		
109     	//Start OpenOffice if needed
110     	if (EParapherManager.getInstance().getSettings().isOpenOfficeAutostart()) {
111 				OODaemonManager.getInstance().start();
112     	}
113     	
114     	EPReferences.getInstance().getStatusline().setMessage(null, "eParapher is ready");
115 	}
116 
117 	  /*
118 	   * (non-Javadoc)
119 	   * 
120 	   * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowCreate()
121 	   */
122 	  public void postWindowCreate() {
123 		  
124 
125 		  trayIcon.StartupFinished();
126 	  }
127 	 
128 	/**
129 	 * Hide the main window but stay in system tray
130 	 */
131 	public boolean preWindowShellClose() {
132 		getWindowConfigurer().getWindow().getShell().setVisible(false);
133 		return false;
134 	}
135 
136 	@Override
137 	public void postWindowClose() {
138 		super.postWindowClose();
139     	if (EParapherManager.getInstance().getSettings().isOpenOfficeAutostart())
140     		OODaemonManager.getInstance().stop();
141 	}
142 	
143 }