View Javadoc

1   /*
2    * $Id: LibraryRefreshAction.java,v 1.3 2005/05/31 21:57:12 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.ui;
10  
11  import java.util.ArrayList;
12  import java.util.Iterator;
13  import java.util.List;
14  
15  import org.eclipse.jface.viewers.IStructuredSelection;
16  import org.eclipse.ui.actions.SelectionListenerAction;
17  
18  import com.bbn.swede.core.IOWLLibrary;
19  import com.bbn.swede.core.libraries.RefreshLibraryJob;
20  
21  /***
22   * An action to encapsulate the refresh operation for libraries.
23   * When this action is run, it creates a {@link RefreshLibraryJob} to 
24   * accomplish th actual work.
25   * 
26   * @see com.bbn.swede.core.libraries.RefreshLibraryJob
27   * @author aperezlo
28   */
29  public class LibraryRefreshAction extends SelectionListenerAction
30  {
31     private List _libraryElements = new ArrayList(); 
32     
33     /***
34      * Creates an action to refresh an Ontology Library.
35      * @param text The label for the action
36      */
37     public LibraryRefreshAction(String text)
38     {
39        super(text);
40     }
41     
42     /*
43      *  (non-Javadoc)
44      * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(
45      *    org.eclipse.jface.viewers.IStructuredSelection)
46      */
47     protected boolean updateSelection(IStructuredSelection selection)
48     {
49        Iterator i = selection.iterator();
50        Object obj = null;
51        boolean isAllGood = true;
52  
53        _libraryElements.clear();
54        
55        if(super.updateSelection(selection))
56        {
57           while(i.hasNext())
58           {
59              obj = i.next();
60              if(!(obj instanceof IOWLLibrary))
61              {
62                 _libraryElements.clear();
63                 isAllGood = false;
64                 break;
65              } 
66              else
67              {
68                 _libraryElements.add((IOWLLibrary) obj);
69              }
70           }
71        }
72        else
73        {
74           isAllGood = false;
75        }
76        
77        setEnabled(isAllGood);
78  
79        return isAllGood;
80     }
81     
82     /*
83      *  (non-Javadoc)
84      * @see org.eclipse.jface.action.IAction#run()
85      */
86     public void run()
87     {
88        super.run();
89        Iterator i = _libraryElements.iterator();
90        IOWLLibrary libElement = null;
91        RefreshLibraryJob rlj = null; 
92        String nowString = "Library Refesh - " + Long.toString(System.currentTimeMillis());
93        while(i.hasNext())
94        {
95           libElement = (IOWLLibrary) i.next();
96           rlj = new RefreshLibraryJob(libElement.getLibrary(), nowString);
97           rlj.schedule();
98        }
99     }
100 }