View Javadoc

1   package org.eparapher.rcp.editors;
2   
3   import org.apache.log4j.Logger;
4   import org.eclipse.swt.SWT;
5   import org.eclipse.swt.events.SelectionEvent;
6   import org.eclipse.swt.events.SelectionListener;
7   import org.eclipse.swt.layout.FillLayout;
8   import org.eclipse.swt.layout.GridData;
9   import org.eclipse.swt.widgets.Composite;
10  import org.eclipse.swt.widgets.Text;
11  import org.eclipse.swt.widgets.Tree;
12  import org.eclipse.swt.widgets.TreeItem;
13  import org.eclipse.ui.forms.widgets.ColumnLayout;
14  import org.eclipse.ui.forms.widgets.Form;
15  import org.eclipse.ui.forms.widgets.FormText;
16  import org.eclipse.ui.forms.widgets.FormToolkit;
17  import org.eclipse.ui.forms.widgets.Section;
18  import org.eclipse.ui.forms.widgets.TableWrapLayout;
19  import org.eparapher.core.EParapherManager;
20  import org.eparapher.rcp.tools.GUIIcons;
21  
22  /**
23   * 
24   * resources : 
25   *   http://www.ibm.com/developerworks/opensource/library/os-eclipse-forms/
26   *   http://www.eclipse.org/articles/Article-Forms/article.html
27   *   
28   * @author arnault
29   *
30   */
31  public class SignatureTabEditor {
32  
33  	private static Logger log = Logger.getLogger(SignatureTabEditor.class);
34  	
35  	private FormToolkit signTK;
36  	private Form        signForm;
37  	
38  	private Tree signerCertChain;
39  	private Tree signerList;
40  
41  	private Text timeStampValue;
42  	public SignatureTabEditor() {
43  		super();
44  	}
45  
46  	/**
47  	 * Creates page 2 of the multi-page editor,
48  	 * which allows you to change the font used in page 2.
49  	 * @param parent 
50  	 */
51  	protected Composite createSignatureForm(Composite parent) {
52  
53  		Composite composite = new Composite(parent, SWT.NONE);
54  		FillLayout layout = new FillLayout();
55  		composite.setLayout(layout);
56  		
57  		//Use eclipse Forms
58  		signTK   = new FormToolkit(composite.getDisplay());
59  		signForm = signTK.createForm(composite);
60  		signForm.setLayoutData(new GridData(GridData.FILL_BOTH));
61  		
62  		//Set title
63  		signForm.setText("Signature informations");
64  		signForm.setImage(GUIIcons.CERTIFICATE_SEL_ICON_IMAGE);
65  		signTK.decorateFormHeading(signForm);
66  		
67  		//Set Layout
68  		ColumnLayout cl = new ColumnLayout();
69  		cl.minNumColumns = 2;
70  		cl.maxNumColumns = 2;
71  		signForm.getBody().setLayout(cl);
72  		
73  		buildSignatureList();
74  		showSignerX509Chain();
75  		//showCRLs();
76  		buildSignatureDetails();
77  		showTimestamp();
78        	
79        	return composite;
80  	}
81  
82  	private void buildSignatureList() {
83  
84      	Section section = signTK.createSection(signForm.getBody(), Section.DESCRIPTION | Section.TITLE_BAR| Section.TWISTIE|Section.EXPANDED);
85        	section.setText("Signatures");
86        	section.setDescription("List of signatures :");
87  		
88        	Composite sectionClient = signTK.createComposite(section);
89        	sectionClient.setLayout(new FillLayout());
90        	//sectionClient.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
91        	
92        	signerList = signTK.createTree(sectionClient, SWT.BORDER );
93        	//signerList.setLayout()
94        	// Build tree items
95        	for (int i = 13; i >=0 ; i--) {
96        		TreeItem item = new TreeItem(signerList,SWT.NONE);
97        		item.setImage(GUIIcons.FILE_ICON_CMS);
98      		item.setText("Signature n°"+i);
99      		item.setData(new Integer(i));
100     		item.setExpanded(true);
101 		}
102       	signerList.addSelectionListener(new SignatureSelection());
103       	
104       	section.setClient(sectionClient);
105 	}
106 
107 	private void showSignerX509Chain() {
108 		Section section = signTK.createSection(signForm.getBody(), Section.TITLE_BAR| Section.TWISTIE|Section.EXPANDED);
109 		//section.setLayoutData(new GridData(GridData.FILL_BOTH));
110 		//section.addExpansionListener(new ExpAdaptor());
111 		section.setText("Signer certificate chain");
112 		section.setDescription("Signer certificate chain :");
113 
114 		Composite sectionClient = signTK.createComposite(section);
115 		sectionClient.setLayout(new FillLayout());
116 		//sectionClient.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
117 
118       	signerCertChain = signTK.createTree(sectionClient, SWT.BORDER | SWT.BORDER_DASH);
119       	//signerCertChain.setLayout(new ColumnLayoutData());
120 		// Build tree items
121 		TreeItem lastItem = null;
122       	for (int i = 3; i >=0 ; i--) {
123       		TreeItem item;
124       		if (i == 3)
125       			item = new TreeItem(signerCertChain,SWT.NONE);
126       		else
127       			item = new TreeItem(lastItem,SWT.NONE);
128       		item.setImage(GUIIcons.CERTIFICATE_ICON_IMAGE);
129     		item.setText("certificate "+i);
130     		item.setData(new Integer(i));
131     		if (lastItem!=null)
132     			lastItem.setExpanded(true);
133     		lastItem = item;
134 		}
135 	    signerCertChain.addSelectionListener(new SignatureSelection());
136 	    signTK.paintBordersFor(sectionClient);
137 	    
138 	    section.setClient(sectionClient);
139 	}
140 	private void buildSignatureDetails() {
141 		
142     	Section section = signTK.createSection(signForm.getBody(), Section.DESCRIPTION | Section.TITLE_BAR| Section.TWISTIE|Section.EXPANDED);
143     	//section.setLayoutData(new ColumnLayoutData());
144       	section.setText("Signature Details");
145       	section.setDescription("signatures fields :");
146 
147 		
148       	Composite sectionComposite = signTK.createComposite(section);
149       	sectionComposite.setLayout(new FillLayout());
150       	
151       	String text = "<form>";
152       	text += "<li>Delivered to : <b>test</b></li>";
153       	text += "</form>";
154       	
155       	FormText formText = signTK.createFormText(sectionComposite, true);
156       	formText.setText(text, true, false);
157       	//formText.setLayoutData(new TableWrapData(TableWrapData.FILL));
158       	
159       	section.setClient(sectionComposite);
160 		
161 	}
162 
163 	private void showTimestamp() {
164 		
165     	Section section = signTK.createSection(signForm.getBody(), Section.DESCRIPTION | Section.TITLE_BAR| Section.TWISTIE|Section.EXPANDED);
166     	//section.setLayoutData(new ColumnLayoutData());
167       	section.setText("Timestamp");
168       	section.setDescription("time information :");
169 
170 		
171       	Composite sectionComposite = signTK.createComposite(section);
172       	sectionComposite.setLayout(new TableWrapLayout());
173       	
174       	String text = "<form>";
175       	text += "<li>signature date : <b>date</b></li>";
176       	text += "<li>certified by : <b>TSA Name/DN/URL</b></li>";
177       	text += "</form>";
178       	
179       	FormText formText = signTK.createFormText(sectionComposite, true);
180       	formText.setText(text, true, false);
181       	/*
182       	ExpandableComposite expcomposite = signTK.createExpandableComposite(
183       			sectionComposite, 
184     			ExpandableComposite.TREE_NODE|
185     			ExpandableComposite.CLIENT_INDENT);
186     	expcomposite.setText("Timestamp Binary Value");
187       	signTK.paintBordersFor(expcomposite);
188       	TableWrapData td = new TableWrapData();
189     	td.maxHeight = 200;
190     	td.maxWidth = 400;
191     	expcomposite.setLayout(new TableWrapLayout());
192     	expcomposite.setLayoutData(td);
193 
194     	
195     	timeStampValue = signTK.createText(expcomposite, "", SWT.BORDER|SWT.READ_ONLY|SWT.WRAP|SWT.H_SCROLL);
196     	expcomposite.setClient(timeStampValue);
197     	expcomposite.addExpansionListener(new ExpansionAdapter() {
198     		public void expansionStateChanged(ExpansionEvent e) {
199     			signForm.update();
200     		}
201     	});
202       	
203     	String tsvalue = "303e02010106022a033021300906052b0e03021a050004140000000000000000000000000000000000000000"
204     		+ "020118180f32303035313130313038313732315a";
205     	timeStampValue.setText(tsvalue);
206     	timeStampValue.setLayoutData(td);
207       	*/
208       	section.setClient(sectionComposite);
209 	}
210 	public void dispose() {
211 		signForm.dispose();
212 		signTK.dispose();
213 	}
214 	/**
215 	 * Change Signature details while selecting a new signature
216 	 * @author arnault
217 	 *
218 	 */
219 	class SignatureSelection implements SelectionListener {
220 		public void widgetSelected(SelectionEvent e) {
221 			log.info("Signature details not implemented Yet! " + (e.item));
222 		}
223 
224 		public void widgetDefaultSelected(SelectionEvent e) {
225 			//change things
226 			EParapherManager.getInstance().getUI().infoMessage("Not implemented Yet! Come back later...");
227 		}
228 	}
229 
230 	/**
231 	 * Show certificate details on double click
232 	 * @author arnault
233 	 *
234 	 */
235 	class CertificateSelection implements SelectionListener {
236 		public void widgetSelected(SelectionEvent e) {
237 		}
238 
239 		public void widgetDefaultSelected(SelectionEvent e) {
240 			EParapherManager.getInstance().getUI().infoMessage("Not implemented Yet! Come back later...");
241 			/*
242 			int selCertindex =  ((Integer) e.item.getData()).intValue();
243 			if (selCertindex!=0) {
244 				X509Certificate[] newcertchaintoview = new X509Certificate[certchain.length-selCertindex];
245 				for (int i = selCertindex; i <certchain.length ; i++) {
246 					newcertchaintoview[i-selCertindex] = certchain[i];
247 				}
248 				CertificateViewerDialog cvg = new CertificateViewerDialog(newcertchaintoview);
249 				cvg.open();
250 			}*/
251 		}
252 	}
253 	
254 }