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