378b4206af5aa7d26ec77e42dcc975bdbae42967
[FinalKeyGui.git] / src / fkgui / MainWin.java
1 package fkgui;
2
3
4 import java.util.Locale;
5 import  java.util.prefs.*;
6 import java.awt.*;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9
10 import javax.swing.UIManager;
11 import javax.swing.UnsupportedLookAndFeelException;
12
13 import org.eclipse.jface.viewers.DoubleClickEvent;
14 import org.eclipse.jface.viewers.IDoubleClickListener;
15 import org.eclipse.jface.viewers.ISelectionChangedListener;
16 import org.eclipse.jface.viewers.ListViewer;
17 import org.eclipse.jface.viewers.SelectionChangedEvent;
18 import org.eclipse.jface.viewers.StructuredSelection;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.swt.widgets.Listener;
21 import org.eclipse.swt.widgets.MessageBox;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.KeyEvent;
26 import org.eclipse.swt.events.KeyListener;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.events.SelectionListener;
30 import org.eclipse.swt.events.ShellEvent;
31 import org.eclipse.swt.events.ShellListener;
32 import org.eclipse.swt.widgets.Text;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.wb.swt.SWTResourceManager;
36
37 import fkgui.FkManager.Account;
38 import fkgui.SerialWorker.SerialState;
39 import fkgui.UpdateChecker.AutoUpdaterResultListener;
40
41 import org.eclipse.swt.widgets.TabFolder;
42 import org.eclipse.swt.widgets.TabItem;
43 import org.eclipse.swt.widgets.Composite;
44 import org.eclipse.swt.layout.FormLayout;
45 import org.eclipse.swt.layout.FormData;
46 import org.eclipse.swt.layout.FormAttachment;
47 import org.eclipse.swt.layout.FillLayout;
48 import org.eclipse.swt.widgets.List;
49
50
51 public class MainWin implements ConsoleMsg, AutoUpdaterResultListener {
52
53         protected Shell shell;
54         private Text txtPsw;
55         public TrayIcon trayIcon;
56         public PopupMenu popup;
57         public MenuItem showMain;
58         public MenuItem hideMain;
59
60         public Text txtLog;
61         public Button btnConnect;
62         public Button chkAutoHide;
63         public Label lblPort;
64         public Label lblPassword;
65         
66         public Animation animation;
67         
68         public TabFolder tabFolder;
69
70         private Text txtDev;
71         Preferences prefs;
72         MainWin mySelf;
73         private SerialState lastState = SerialState.Disconnected;
74         
75         SerialWorker fkSerial;
76         private boolean sysTrayIconVisible;
77         
78         Button btnActivateAccount;
79
80         
81         static final String PREF_PORT ="lastUsedPortPref"; //$NON-NLS-1$
82         static final String DEFAULT_DEVICE = "/dev/FinalKey"; //$NON-NLS-1$
83         static final String PREF_AUTOHIDE = "hideMainWinAfterConnect"; //$NON-NLS-1$
84         public Composite cmpConnect;
85         private Composite cmpAccounts;
86         ListViewer lstAccounts;
87         Label lblNumFree;
88         Button btnNewAccoount;
89  
90         
91         /**
92          * Launch the application.
93          * @param args
94          */
95         public static void main(String[] args) {
96
97                 try {
98                         MainWin window = new MainWin();
99                         window.open();
100                 } catch (Exception e) {
101                         e.printStackTrace();
102                 }
103                 
104         }
105
106         /**
107          * Open the window.
108          */
109         public void open() {
110                 Display display = Display.getDefault();
111                 createContents();
112                 addAccountsTab();
113                 shell.open();
114                 shell.layout();
115                 createSysTrayIcon();
116                 serialEvent(SerialState.Disconnected);
117                 new Thread(new UpdateChecker(this)).start();
118
119                 while (!shell.isDisposed()) {
120                         if (!display.readAndDispatch()) {
121                                 display.sleep();                                
122                         }
123                 }
124         }
125         
126         public void log( String str )
127         {
128                 txtLog.append(str+"\n"); //$NON-NLS-1$
129                 if( tabFolder.getSelectionIndex() == 0 )
130                 {
131                         txtLog.redraw();
132                         shell.redraw();
133                 }
134                 System.out.println(str);
135
136         }
137
138         /**
139          * Create a systemTray icon
140          */
141         private void createSysTrayIcon()
142         {
143                 sysTrayIconVisible=true;
144         //Check the SystemTray is supported
145         if (!SystemTray.isSupported()) {
146             log("SystemTray is not supported, app is useless"); //$NON-NLS-1$
147             return;
148         }
149         
150         try {
151                         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
152                 } catch (Exception e1) {
153                         e1.printStackTrace();
154                 } 
155
156         popup = new PopupMenu();
157         trayIcon =
158                 new TrayIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("gfx/finalkey.png"))); //$NON-NLS-1$
159         trayIcon.setToolTip("The Final Key - Hardware password manager"); //$NON-NLS-1$
160         trayIcon.setImageAutoSize(true);
161         final SystemTray tray = SystemTray.getSystemTray();
162        
163         // Create a pop-up menu components
164         showMain = new MenuItem(Messages.MainWin_7);
165         hideMain = new MenuItem(Messages.MainWin_8);
166
167         showMain.addActionListener(new ActionListener() {
168                         @Override
169                         public void actionPerformed(ActionEvent e) {
170                                 Display.getDefault().syncExec( new Runnable(){
171                                         
172                                         public void run()
173                                         {
174                                                 showFromTray();
175                                         }
176                                 } );
177                         }
178                                 
179                 });
180         
181         hideMain.addActionListener(new ActionListener() {
182                         @Override
183                         public void actionPerformed(ActionEvent e) {
184                                 Display.getDefault().syncExec( new Runnable(){
185                                         
186                                         public void run()
187                                         {
188                                                 hideToTray();
189                                         }
190                                 } );
191                         }
192                                 
193                 });
194
195         clearSystray();
196
197
198         trayIcon.setPopupMenu(popup);
199        
200         try {
201             tray.add(trayIcon);
202         } catch (AWTException e) {
203                 log("TrayIcon could not be added."); //$NON-NLS-1$
204         }       
205         
206         }
207         
208         private void hideToTray()
209         {
210                 popup.remove(0);
211                 popup.insert(showMain, 0);
212                 shell.setVisible(false);
213         }
214         
215         private void showFromTray()
216         {
217                 popup.remove(0);
218                 popup.insert(hideMain, 0);
219                 shell.setVisible(true);
220                 shell.forceActive();
221         }
222         
223         private void destroySysTrayIcon()
224         {
225                 sysTrayIconVisible=false;
226                 SystemTray.getSystemTray().remove(trayIcon);
227         }
228         
229         private void clearSystray() {
230                         popup.removeAll();
231                 //Add components to pop-up menu
232                         if(shell.isVisible()==true)
233                         {
234                                 popup.add(hideMain);
235                         } else {
236                                 popup.add(showMain);
237                         }
238                 popup.addSeparator();
239         }
240
241         public void shutDownApp()
242         {
243                 if(fkSerial != null)
244                 {
245                         fkSerial.disconnect();
246                 }
247                 if(sysTrayIconVisible == true)
248                 {
249                         destroySysTrayIcon();
250                 }
251                 System.exit(0);
252         }
253         
254         /**
255          * Create contents of the window.
256          */
257         protected void createContents() {
258                 
259                 
260                 shell = new Shell();
261                 shell.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/finalkey.png")); //$NON-NLS-1$
262                 shell.setSize(711, 655);
263
264
265                 
266                 
267                 prefs = Preferences.userNodeForPackage(this.getClass());
268                 
269
270                 mySelf = this;
271                 shell.setLayout(new FillLayout(SWT.HORIZONTAL));
272                 
273                 tabFolder = new TabFolder(shell, SWT.NONE);
274                 tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
275                 
276                 TabItem tbtmConnection = new TabItem(tabFolder, SWT.NONE);
277                 tbtmConnection.setText(Messages.MainWin_12);
278                 
279                 cmpConnect = new Composite(tabFolder, SWT.BORDER);
280                 tbtmConnection.setControl(cmpConnect);
281                 cmpConnect.setLayout(new FormLayout());
282                 
283
284                 btnConnect = new Button(cmpConnect, SWT.CENTER);
285                 btnConnect.setImage( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/lightning.png") ); //$NON-NLS-1$
286                 FormData fd_btnConnect = new FormData();
287                 fd_btnConnect.left = new FormAttachment(100, -125);
288                 fd_btnConnect.right = new FormAttachment(100, -10);
289                 btnConnect.setLayoutData(fd_btnConnect);
290
291                 btnConnect.addSelectionListener(new SelectionAdapter() {
292                         public void widgetSelected(SelectionEvent e) {
293                                 
294                                 
295                                 if( fkSerial!=null && fkSerial.state == SerialState.Connected )
296                                 {
297                                         fkSerial.disconnect();
298                                 } else {
299                                         
300                                         connect();
301                                 }
302                         }
303
304                 });
305                 btnConnect.setText(Messages.MainWin_15);
306                 
307                 txtPsw = new Text(cmpConnect, SWT.BORDER | SWT.PASSWORD);
308                 fd_btnConnect.bottom = new FormAttachment(txtPsw, 0, SWT.BOTTOM);
309                 FormData fd_txtPsw = new FormData();
310                 fd_txtPsw.bottom = new FormAttachment(0, 52);
311                 fd_txtPsw.right = new FormAttachment(0, 501);
312                 fd_txtPsw.top = new FormAttachment(0, 29);
313                 fd_txtPsw.left = new FormAttachment(0, 102);
314                 txtPsw.setLayoutData(fd_txtPsw);
315                 txtPsw.setFocus();
316                 txtPsw.addKeyListener( new KeyListener() {
317                         
318                         @Override
319                         public void keyReleased(KeyEvent arg0) {
320
321                                 
322                         }
323                         
324                         @Override
325                         public void keyPressed(KeyEvent arg0) {
326                                 if( arg0.character==(char)13 )
327                                 {
328                                         connect();
329                                 }
330                         }
331                 });
332                 
333                 txtLog = new Text(cmpConnect, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
334                 FormData fd_txtLog = new FormData();
335                 fd_txtLog.left = new FormAttachment(0, 10);
336                 fd_txtLog.right = new FormAttachment(100, -10);
337                 fd_txtLog.bottom = new FormAttachment(100, -10);
338                 fd_txtLog.top = new FormAttachment(0, 58);
339                 txtLog.setLayoutData(fd_txtLog);
340                 txtLog.setEditable(false);
341                 
342                 lblPort = new Label(cmpConnect, SWT.NONE);
343                 fd_btnConnect.top = new FormAttachment(lblPort, 0, SWT.TOP);
344                 FormData fd_lblPort = new FormData();
345                 fd_lblPort.right = new FormAttachment(0, 86);
346                 fd_lblPort.top = new FormAttachment(0);
347                 fd_lblPort.left = new FormAttachment(0, 10);
348                 lblPort.setLayoutData(fd_lblPort);
349                 lblPort.setText("Port"); //$NON-NLS-1$
350                 
351                 txtDev = new Text(cmpConnect, SWT.BORDER);
352                 FormData fd_txtDev = new FormData();
353                 fd_txtDev.bottom = new FormAttachment(0, 23);
354                 fd_txtDev.right = new FormAttachment(0, 256);
355                 fd_txtDev.top = new FormAttachment(0);
356                 fd_txtDev.left = new FormAttachment(0, 102);
357                 txtDev.setLayoutData(fd_txtDev);
358                 txtDev.setFont(SWTResourceManager.getFont("Cantarell", 9, SWT.NORMAL)); //$NON-NLS-1$
359                 txtDev.setText( prefs.get(PREF_PORT, DEFAULT_DEVICE));
360                 lblPassword = new Label(cmpConnect, SWT.NONE);
361                 FormData fd_lblPassword = new FormData();
362                 fd_lblPassword.right = new FormAttachment(0, 95);
363                 fd_lblPassword.top = new FormAttachment(0, 29);
364                 fd_lblPassword.left = new FormAttachment(0, 10);
365                 lblPassword.setLayoutData(fd_lblPassword);
366                 lblPassword.setText(Messages.MainWin_18);
367                 
368                 chkAutoHide = new Button(cmpConnect, SWT.CHECK);
369                 FormData fd_chkAutoHide = new FormData();
370                 fd_chkAutoHide.right = new FormAttachment(0, 501);
371                 fd_chkAutoHide.top = new FormAttachment(0);
372                 fd_chkAutoHide.left = new FormAttachment(0, 262);
373                 chkAutoHide.setLayoutData(fd_chkAutoHide);
374                 chkAutoHide.setText(Messages.MainWin_19);
375                 
376                 chkAutoHide.setSelection( prefs.getBoolean(PREF_AUTOHIDE, false)) ;
377                 
378                 animation = new Animation(cmpConnect, SWT.NONE, 4);
379
380                 FormData fd_animation = new FormData();
381                 fd_animation.right = new FormAttachment(0, 86);
382                 fd_animation.top = new FormAttachment(0);
383                 fd_animation.left = new FormAttachment(0, 10);          
384                 
385                 animation.setLayoutData(fd_animation);
386
387
388                 
389                 animation.setVisible(false);
390                 animation.addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/finalkey1.png") ); //$NON-NLS-1$
391                 animation.addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/finalkey2.png") ); //$NON-NLS-1$
392                 animation.setPlaying(false);
393                 cmpConnect.setTabList(new Control[]{txtPsw, btnConnect});
394                 
395         
396                 
397                 log(Messages.MainWin_22);
398
399
400                 shell.addShellListener( new ShellListener() {
401                         
402                         public void shellIconified(ShellEvent e) {
403                                 // TODO Auto-generated method stub
404
405                         }
406
407                         public void shellDeiconified(ShellEvent e) {
408                                 // TODO Auto-generated method stub
409                                 
410                         }
411                         
412                         public void shellDeactivated(ShellEvent e) {
413                                 // TODO Auto-generated method stub
414                         }
415                         
416                         public void shellClosed(ShellEvent e) {
417                                 shutDownApp();
418                         }
419                         
420                         public void shellActivated(ShellEvent e) {
421                                 // TODO Auto-generated method stub
422                                 
423                         }
424                 } );
425                 
426
427
428         }
429
430         
431         private void connect() {
432                 prefs.putBoolean(PREF_AUTOHIDE, chkAutoHide.getSelection() );
433                 fkSerial = new SerialWorker(mySelf);
434                 prefs.put(PREF_PORT, txtDev.getText() );
435                 fkSerial.connect(txtDev.getText(),txtPsw.getText());
436                 txtPsw.setText(""); //$NON-NLS-1$
437         }
438         
439         
440         @Override
441         public void updateAccountList()
442         {
443                 int free=256;
444                 clearSystray();
445                 lstAccounts.getList().removeAll();
446                 
447                 for( FkManager.Account a : FkManager.getInstance().getList() )
448                 {
449                         free--;
450                         lstAccounts.add( a );
451                                                         
452                         Menu menu = new Menu(a.name+" ["+a.num+"]"); //$NON-NLS-1$ //$NON-NLS-1$
453                         MenuItem both = new MenuItem(Messages.MainWin_25);
454                         MenuItem usr = new MenuItem(Messages.MainWin_26);
455                         MenuItem psw = new MenuItem(Messages.MainWin_27);
456                         menu.add(both);
457                         menu.add(usr);
458                         menu.add(psw);
459
460
461                         both.addActionListener(FkManager.getInstance());
462                         both.setActionCommand( "%"+a.num ); //$NON-NLS-1$
463
464
465
466                         psw.addActionListener(FkManager.getInstance()); 
467                         psw.setActionCommand( "p"+a.num); //$NON-NLS-1$
468
469
470                         usr.addActionListener(FkManager.getInstance()); 
471                         usr.setActionCommand( "u"+a.num ); //$NON-NLS-1$
472
473                         popup.add(menu);
474                 }
475                 
476                 lblNumFree.setText(" "+free+Messages.MainWin_32); //$NON-NLS-1$
477                 lblNumFree.pack();
478                 if( free == 0 )
479                 {
480                         btnNewAccoount.setVisible(false);
481                 } else {
482                         btnNewAccoount.setVisible(true);
483                 }
484                 
485         }
486
487         @Override
488         public void serialEvent(SerialState state) {
489                 switch(state)
490                 {
491                 case Connected:
492                         shell.setText(Messages.MainWin_33);
493                         
494                         animation.setVisible(false);
495                         animation.setPlaying(false);
496
497
498                         btnConnect.setText(Messages.MainWin_34);
499                         btnConnect.setVisible(true);
500                         
501                         //Should we hide?
502                         if( prefs.getBoolean(PREF_AUTOHIDE, false) == true)
503                         {
504                                 hideToTray();
505                         }
506                         
507                         addAccountsTab();
508                         
509                         
510                         tabFolder.setSelection(1);
511                         
512                         updateAccountList();
513                         
514                         
515                         int numAccounts=FkManager.getInstance().getList().size();
516                         if( numAccounts>0 )
517                         {
518                                 trayIcon.displayMessage("FinalKey", numAccounts + Messages.MainWin_36+(( numAccounts >1)?"s":Messages.MainWin_38)+Messages.MainWin_39,  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
519                                     TrayIcon.MessageType.INFO);
520                         }
521
522                         
523                         log(Messages.MainWin_40);
524                         break;
525                 case Connecting:
526                         shell.setText(Messages.MainWin_41);
527                         animation.setVisible(true);
528                         animation.setPlaying(true);
529
530                         txtPsw.setVisible(false);
531                         txtDev.setVisible(false);
532                         btnConnect.setVisible(false);
533                         lblPort.setVisible(false);
534                         lblPassword.setVisible(false);
535                         chkAutoHide.setVisible(false);
536                         break;
537                 case Disconnected:
538                         fkSerial=null;
539                         animation.setVisible(false);
540                         animation.setPlaying(false);
541
542                         remAccountsTab();
543                         
544                         tabFolder.setSelection(0);
545
546                         shell.setText(Messages.MainWin_42);
547                         txtPsw.setVisible(true);
548                         txtDev.setVisible(true);
549                         btnConnect.setText(Messages.MainWin_43);
550                         btnConnect.setVisible(true);
551                         lblPort.setVisible(true);
552                         lblPassword.setVisible(true);
553                         chkAutoHide.setVisible(true);
554                         clearSystray();
555                         if(lastState != state)
556                         {
557                                 log(Messages.MainWin_44);
558                         }
559                         break;
560                 
561                 case Working:
562                         animation.setPlaying(false);
563                         animation.setVisible(false);
564                         break;
565                         
566                 default:
567                         break;
568                 }
569                 lastState=state;
570                 cmpConnect.layout();
571         }
572
573         private void remAccountsTab() {
574                 if( tabFolder.getItemCount() > 1 )
575                 {
576                         tabFolder.getItem(1).dispose();
577                 }
578                 
579         }
580
581         private void addAccountsTab() {
582                 TabItem tbtmAccounts = new TabItem(tabFolder, SWT.NONE);
583                 tbtmAccounts.setText(Messages.MainWin_45);
584                 
585                 cmpAccounts = new Composite(tabFolder, SWT.BORDER);
586                 tbtmAccounts.setControl(cmpAccounts);
587                 cmpAccounts.setLayout(new FormLayout());
588                 
589                 btnNewAccoount = new Button(cmpAccounts, SWT.NONE);
590                 btnNewAccoount.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/new.png")); //$NON-NLS-1$
591                 btnNewAccoount.addSelectionListener(new SelectionAdapter() {
592                         @Override
593                         public void widgetSelected(SelectionEvent e) {
594                                 NewAccountDialog dialog = new NewAccountDialog(shell, shell.getStyle() );
595                                 shell.setEnabled(false);
596                                 dialog.open();
597                                 shell.setEnabled(true);
598                                 updateAccountList();
599                                 
600                         }
601                 });
602                 FormData fd_btnNewAccoount = new FormData();
603                 fd_btnNewAccoount.left = new FormAttachment(0, 530);
604                 fd_btnNewAccoount.right = new FormAttachment(100, -10);
605                 fd_btnNewAccoount.bottom = new FormAttachment(100, -10);
606                 btnNewAccoount.setLayoutData(fd_btnNewAccoount);
607                 btnNewAccoount.setText(Messages.MainWin_47);
608                 
609                 lblNumFree = new Label(cmpAccounts, SWT.NONE);
610                 lblNumFree.setText("Hello World!"); //$NON-NLS-1$
611                 
612                 FormData fd_lblNumFree = new FormData();
613                 fd_lblNumFree.left = new FormAttachment(0,0);
614                 fd_lblNumFree.bottom = new FormAttachment(100,-10);
615                 lblNumFree.setLayoutData(fd_lblNumFree);
616                 
617                 
618                 lstAccounts = new ListViewer(cmpAccounts, SWT.BORDER | SWT.V_SCROLL);
619                 List list = lstAccounts.getList();
620                 list.setLayoutData(new FormData());
621                 FormData fd_lstAccounts = new FormData();
622                 fd_lstAccounts.bottom = new FormAttachment(btnNewAccoount, -6);
623                 
624                 btnActivateAccount = new Button(cmpAccounts, SWT.NONE);
625                 btnActivateAccount.setImage(SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/lightbulb.png"));
626                 FormData fd_btnActivateAccount = new FormData();
627                 fd_btnActivateAccount.right = new FormAttachment(btnNewAccoount, -71);
628                 fd_btnActivateAccount.left = new FormAttachment(lblNumFree, 78);
629                 fd_btnActivateAccount.top = new FormAttachment(btnNewAccoount, 0, SWT.TOP);
630                 btnActivateAccount.setLayoutData(fd_btnActivateAccount);
631                 btnActivateAccount.setText(Messages.MainWin_btnNewButton_text);
632                 fd_lstAccounts.top = new FormAttachment(0, 10);
633                 fd_lstAccounts.left = new FormAttachment(0, 10);
634                 fd_lstAccounts.right = new FormAttachment(100, -10);
635                 btnActivateAccount.setVisible(false);
636                 
637                 
638                 //lstAccounts.setLayoutData(fd_lstAccounts);
639                 lstAccounts.getControl().setLayoutData(fd_lstAccounts);
640                 lstAccounts.addDoubleClickListener( new IDoubleClickListener() {
641                         
642                         @Override
643                         public void doubleClick(DoubleClickEvent arg0) {
644                                 // TODO Auto-generated method stub
645                                 StructuredSelection selection = (StructuredSelection) arg0.getSelection();
646                                 if( !selection.isEmpty() )
647                                 {
648                                         Account acc = (Account)selection.getFirstElement();
649                                         TriggerDialog diag = new TriggerDialog(shell, shell.getStyle(), acc, mySelf );
650
651                                         shell.setMinimized(true);
652                                         shell.setEnabled(false);
653                                         if( !((Boolean)diag.open()) )
654                                         {
655                                                 shell.setMinimized(false);
656                                         }
657                                         
658                                         shell.setEnabled(true);
659                                 } else {
660                                         System.out.println("Selected nothing."); //$NON-NLS-1$
661                                 }
662                                 
663                                 
664                         }
665                 });
666                 
667                 lstAccounts.addSelectionChangedListener( new ISelectionChangedListener() {
668                         
669                         @Override
670                         public void selectionChanged(SelectionChangedEvent arg0) {
671                                 StructuredSelection selection = (StructuredSelection) arg0.getSelection();
672                                 if( !selection.isEmpty() )
673                                 {
674                                         Account acc = (Account)selection.getFirstElement();
675                                         btnActivateAccount.setVisible(true);
676                                         btnActivateAccount.setText(acc.name);
677                                         
678                                         for( Listener s :btnActivateAccount.getListeners(SWT.Selection) )
679                                         {
680                                                 btnActivateAccount.removeListener(SWT.Selection, s);
681
682                                         }
683                                         
684                                         btnActivateAccount.addSelectionListener( new SelectionListener() {
685                                                 
686                                                 @Override
687                                                 public void widgetSelected(SelectionEvent arg0) {
688                                                         
689                                                         StructuredSelection selection = (StructuredSelection) lstAccounts.getSelection();
690                                                         Account acc = (Account)selection.getFirstElement();
691                                                         TriggerDialog diag = new TriggerDialog(shell, shell.getStyle(), acc, mySelf );
692
693                                                         shell.setMinimized(true);
694                                                         shell.setEnabled(false);
695                                                         if( !((Boolean)diag.open()) )
696                                                         {
697                                                                 shell.setMinimized(false);
698                                                         }
699                                                         
700                                                         shell.setEnabled(true);
701                                                 }
702                                                 
703                                                 @Override
704                                                 public void widgetDefaultSelected(SelectionEvent arg0) {
705                                                         // TODO Auto-generated method stub
706                                                         
707                                                 }
708                                         });
709                                         
710                                 }
711                         }
712                 });
713                 
714                                 
715         }
716
717
718         @Override
719         public void updateCheckFinished(AutoUpdaterResultEvent event) {
720                 switch(event.result)
721                 {
722                 case CHECK_FAILED:
723                         System.out.println("Trouble checking for updates."); //$NON-NLS-1$
724                         break;
725                 case NO_UPDATE:
726                         System.out.println("No update avaiable at this time."); //$NON-NLS-1$
727                         break;
728                 case UPDATE_AVAILABLE:
729                         MessageBox dialog = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
730                         dialog.setText(Messages.MainWin_52+event.version+Messages.MainWin_53);
731                         dialog.setMessage(Messages.MainWin_54+event.message);
732                         dialog.open();  
733                         break;
734                 }
735                 
736         }
737 }