View Javadoc

1   package org.dbe.studio.tools.accounting.metering.actions;
2   
3   
4   
5   import org.dbe.studio.tools.accounting.metering.wizards.AccountingWizard;
6   import org.eclipse.core.resources.IFile;
7   import org.eclipse.jface.action.IAction;
8   import org.eclipse.jface.viewers.ISelection;
9   import org.eclipse.jface.viewers.IStructuredSelection;
10  import org.eclipse.jface.wizard.WizardDialog;
11  import org.eclipse.swt.widgets.FileDialog;
12  import org.eclipse.ui.IActionDelegate;
13  import org.eclipse.ui.IObjectActionDelegate;
14  import org.eclipse.ui.IWorkbenchPart;
15  import org.eclipse.ui.PlatformUI;
16  
17  public class AddMeteringAction implements IObjectActionDelegate {
18      IFile darFile;
19  	/***
20  	 * Constructor for Action1.
21  	 */
22  	public AddMeteringAction() {
23  		super();
24  	}
25  
26  	/***
27  	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
28  	 */
29  	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
30  	}
31  
32  	/***
33  	 * @see IActionDelegate#run(IAction)
34  	 */
35  	public void run(IAction action) {
36          if (this.darFile == null) {
37              FileDialog fd = new FileDialog(PlatformUI.getWorkbench()
38                      .getActiveWorkbenchWindow().getShell());
39              fd.setFilterExtensions(new String[] { "*.dar" });
40              fd.setText("Select DAR File to regsiter");
41              String fileName = fd.open();
42              if (fileName != null)
43                  this.openWizard(fileName);
44  
45          } else {
46              this.openWizard(darFile.getLocation().toString());
47          }
48          this.darFile = null;
49  	}
50  
51  	/***
52       * @param fileName
53       */
54      private void openWizard(String fileName) {
55          try{
56          	
57          AccountingWizard wizard = new AccountingWizard(fileName);
58  
59          WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench()
60                  .getActiveWorkbenchWindow().getShell(), wizard);
61          dialog.create();
62          dialog.open();
63          }catch(Exception e){
64              e.printStackTrace();
65          }
66      }
67  
68      /***
69  	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
70  	 */
71  	public void selectionChanged(IAction action, ISelection selection) {
72          this.darFile = null;
73          if (selection instanceof IStructuredSelection) {
74              IStructuredSelection structuredSelection = (IStructuredSelection) selection;
75              if (structuredSelection.size() == 1) {
76                  Object selectedResource = structuredSelection.getFirstElement();
77                  if (selectedResource instanceof IFile) {
78                      this.darFile = (IFile) selectedResource;
79                  }
80              }
81          }
82      }
83  	
84  
85  }