KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > jarpackager > JarPackageActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.jarpackager;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.eclipse.core.resources.IFile;
16
17 import org.eclipse.swt.widgets.Shell;
18
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.jface.viewers.StructuredSelection;
23
24 import org.eclipse.ui.IObjectActionDelegate;
25 import org.eclipse.ui.IWorkbench;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.eclipse.ui.IWorkbenchPartSite;
28 import org.eclipse.ui.PlatformUI;
29
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31
32 /**
33  * This abstract action delegate offers base functionality used by
34  * other JAR Package based action delegates.
35  */

36 abstract class JarPackageActionDelegate implements IObjectActionDelegate {
37
38     private IStructuredSelection fSelection;
39     private Shell fShell;
40
41     /**
42      * Returns the active shell.
43      */

44     protected Shell getShell() {
45         if (fShell != null)
46             return fShell;
47         return JavaPlugin.getActiveWorkbenchShell();
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
52      */

53     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
54         IWorkbenchPartSite site= targetPart.getSite();
55         fShell= site != null ? site.getShell() : null;
56     }
57
58     /*
59      * @see IActionDelegate
60      */

61     public void selectionChanged(IAction action, ISelection selection) {
62         if (selection instanceof IStructuredSelection)
63             fSelection= (IStructuredSelection)selection;
64         else
65             fSelection= StructuredSelection.EMPTY;
66     }
67
68     /**
69      * Returns the description file for the first description file in
70      * the selection. Use this method if this action is only active if
71      * one single file is selected.
72      */

73     protected IFile getDescriptionFile(IStructuredSelection selection) {
74         return (IFile)selection.getFirstElement();
75     }
76
77     /**
78      * Returns a description file for each description file in
79      * the selection. Use this method if this action allows multiple
80      * selection.
81      */

82     protected IFile[] getDescriptionFiles(IStructuredSelection selection) {
83         IFile[] files= new IFile[selection.size()];
84         Iterator JavaDoc iter= selection.iterator();
85         int i= 0;
86         while (iter.hasNext())
87             files[i++]= (IFile)iter.next();
88         return files;
89     }
90
91     protected IWorkbench getWorkbench() {
92         return PlatformUI.getWorkbench();
93     }
94
95     protected IStructuredSelection getSelection() {
96         return fSelection;
97     }
98 }
99
Popular Tags