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
25
26
27
28
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
48
49
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
58 signTK = new FormToolkit(composite.getDisplay());
59 signForm = signTK.createForm(composite);
60 signForm.setLayoutData(new GridData(GridData.FILL_BOTH));
61
62
63 signForm.setText("Signature informations");
64 signForm.setImage(GUIIcons.CERTIFICATE_SEL_ICON_IMAGE);
65 signTK.decorateFormHeading(signForm);
66
67
68 ColumnLayout cl = new ColumnLayout();
69 cl.minNumColumns = 2;
70 cl.maxNumColumns = 2;
71 signForm.getBody().setLayout(cl);
72
73 buildSignatureList();
74 showSignerX509Chain();
75
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
91
92 signerList = signTK.createTree(sectionClient, SWT.BORDER );
93
94
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
110
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
117
118 signerCertChain = signTK.createTree(sectionClient, SWT.BORDER | SWT.BORDER_DASH);
119
120
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
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
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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 section.setClient(sectionComposite);
209 }
210 public void dispose() {
211 signForm.dispose();
212 signTK.dispose();
213 }
214
215
216
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
226 EParapherManager.getInstance().getUI().infoMessage("Not implemented Yet! Come back later...");
227 }
228 }
229
230
231
232
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
243
244
245
246
247
248
249
250
251 }
252 }
253
254 }