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