1   /**
2    * QJ-Pro
3    * Copyright (c) 2004, http://qjpro.sourceforge.net
4    *
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful, but WITHOUT
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13   * details.
14   *
15   * You should have received a copy of the GNU General Public License along with
16   * this program; if not, write to the Free Software Foundation, Inc.,
17   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18   */
19  package com.qasystems.qstudio.java.integration.eclipse.actions;
20  
21  import com.qasystems.qstudio.java.integration.eclipse.EclipseEnvironment;
22  
23  import org.eclipse.jdt.core.IJavaProject;
24  import org.eclipse.jface.action.IAction;
25  import org.eclipse.jface.viewers.ISelectionProvider;
26  import org.eclipse.jface.viewers.StructuredSelection;
27  import org.eclipse.ui.IObjectActionDelegate;
28  import org.eclipse.ui.IWorkbenchPage;
29  import org.eclipse.ui.IWorkbenchPart;
30  import org.eclipse.ui.IWorkbenchPartSite;
31  import org.eclipse.ui.actions.ActionDelegate;
32  
33  public class SaveAsProjectAction extends ActionDelegate
34    implements IObjectActionDelegate {
35    /** The page containing the part target. */
36    private IWorkbenchPage page;
37  
38    /** The part target. */
39    private IWorkbenchPart part;
40  
41    /**
42     * DOCUMENT ME!
43     *
44     * @param iAction DOCUMENT ME!
45     * @param iWorkbenchPart DOCUMENT ME!
46     */
47    public void setActivePart(IAction iAction, IWorkbenchPart iWorkbenchPart) {
48      part = iWorkbenchPart;
49      page = part.getSite().getPage();
50    }
51  
52    /**
53     * DOCUMENT ME!
54     *
55     * @param action DOCUMENT ME!
56     */
57    public void run(final IAction action) {
58      IJavaProject ideProject = null;
59  
60      final IWorkbenchPartSite site = part.getSite();
61      final ISelectionProvider provider = site.getSelectionProvider();
62      final StructuredSelection selection =
63        (StructuredSelection) provider.getSelection();
64      final Object object = selection.getFirstElement();
65  
66      if (object instanceof IJavaProject) {
67        ideProject = (IJavaProject) object;
68        EclipseEnvironment.saveQSJavaProject(
69          EclipseEnvironment.toQSJavaProject(ideProject)
70        );
71      }
72    }
73  }
74