View Javadoc

1   /*
2    * $Id: CodeGenerationAction.java,v 1.2 2005/05/31 20:25:08 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   package com.bbn.swede.tools.codegenerator;
9   
10  import org.eclipse.jface.action.Action;
11  import org.eclipse.jface.viewers.ISelection;
12  import org.eclipse.jface.viewers.IStructuredSelection;
13  import org.eclipse.ui.PlatformUI;
14  
15  import com.bbn.swede.core.IOWLDocument;
16  
17  /***
18   * A generic action class for running code generators.  This action will work
19   * for any extender of com.bbn.swede.ui.codeGenerator by utilizing the interface
20   * provided by AbstractCodeGenerator.
21   * @author jlerner
22   */
23  public class CodeGenerationAction extends Action
24  {
25     private String _sDisplayName;
26     private String _sID;
27     private AbstractCodeGenerator _codeGenerator;
28     /***
29      * Creates an action for a specific code generator.
30      * @param sLabel The display name of the generator.
31      * @param codeGen The class to perform the actual generation.
32      * @param sGeneratorID The unique identifier of the code generator.
33      */
34     public CodeGenerationAction(String sLabel, AbstractCodeGenerator codeGen, String sGeneratorID)
35     {
36        super(sLabel);
37        _sDisplayName = sLabel;
38        _sID = sGeneratorID;
39        _codeGenerator = codeGen;
40        _codeGenerator.setDisplayName(sLabel);
41        _codeGenerator.setID(sGeneratorID);
42     }
43  
44     /***
45      * Retrieves the display name of the code generator attached to this action.
46      * @return The action's display name.
47      */
48     public String getDisplayName()
49     {
50        return _sDisplayName;
51     }
52  
53     /***
54      * Sets the display name of the code generator attached to this action.
55      * @param sDisplayName The new display name for the action.
56      */
57     public void setDisplayName(String sDisplayName)
58     {
59        _sDisplayName = sDisplayName;
60     }
61  
62     /*
63      *  (non-Javadoc)
64      * @see org.eclipse.jface.action.IAction#run()
65      */
66     public void run()
67     {
68        super.run();
69  
70        ISelection sel =
71           PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
72        if (sel instanceof IStructuredSelection)
73        {
74           IStructuredSelection selection = (IStructuredSelection) sel;
75           IOWLDocument doc = (IOWLDocument)selection.getFirstElement();
76           _codeGenerator.generate(doc);
77        }
78     }
79  
80  }