001: package org.openwfe.gpe.actions;
002:
003: import org.eclipse.jface.action.IAction;
004: import org.eclipse.jface.viewers.ISelection;
005: import org.eclipse.jface.viewers.IStructuredSelection;
006: import org.eclipse.swt.SWT;
007: import org.eclipse.swt.widgets.FileDialog;
008: import org.eclipse.swt.widgets.Shell;
009: import org.eclipse.ui.IObjectActionDelegate;
010: import org.eclipse.ui.IWorkbenchPart;
011: import org.eclipse.ui.IWorkbenchWindow;
012: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
013: import org.openwfe.gpe.xml.XMLCreation;
014:
015: /**
016: * Our sample action implements workbench action delegate.
017: * The action proxy will be created by the workbench and
018: * shown in the UI. When the user tries to use the action,
019: * this delegate will be created and execution will be
020: * delegated to it.
021: * @see IWorkbenchWindowActionDelegate
022: */
023: public class ExportXMLAction implements IWorkbenchWindowActionDelegate,
024: IObjectActionDelegate {
025:
026: /**
027: *
028: * @uml.property name="window"
029: * @uml.associationEnd multiplicity="(0 1)"
030: */
031: private IWorkbenchWindow window;
032: private IStructuredSelection selection;
033:
034: /**
035: * @param model
036: */
037:
038: /**
039: * The constructor.
040: */
041:
042: public ExportXMLAction() {
043: super ();
044: }
045:
046: /**
047: * The action has been activated. The argument of the
048: * method represents the 'real' action sitting
049: * in the workbench UI.
050: * @see IWorkbenchWindowActionDelegate#run
051: */
052:
053: public void run(IAction action) {
054: Shell shell = new Shell();
055: // creates a new "Save as .." window
056: FileDialog page = new FileDialog(shell, SWT.SAVE);
057: //files should end with .xml
058: String[] extensions = new String[] { new String(".xml") };
059: page.setFilterExtensions(extensions);
060: //now we have the file path
061: String path = page.open();
062: //we create a new XML document at the given path
063: XMLCreation xmlimport = new XMLCreation();
064: xmlimport.makeElements(path);
065: }
066:
067: public void selectionChanged(IAction action, ISelection selection) {
068: if (selection instanceof IStructuredSelection)
069: this .selection = (IStructuredSelection) selection;
070: }
071:
072: /**
073: *
074: * Selection in the workbench has been changed. We
075: * can change the state of the 'real' action here
076: * if we want, but this can only happen after
077: * the delegate has been created.
078: * @see IWorkbenchWindowActionDelegate#selectionChanged
079: */
080:
081: /**
082: * We can use this method to dispose of any system
083: * resources we previously allocated.
084: * @see IWorkbenchWindowActionDelegate#dispose
085: */
086: public void dispose() {
087: }
088:
089: /**
090: * We will cache window object in order to
091: * be able to provide parent shell for the message dialog.
092: * @see IWorkbenchWindowActionDelegate#init
093: *
094: * @uml.property name="window"
095: */
096: public void init(IWorkbenchWindow window) {
097: this .window = window;
098: }
099:
100: /* (non-Javadoc)
101: * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
102: */
103: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
104: // TODO Auto-generated method stub
105:
106: }
107:
108: }
|