KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > PreviewReferenceAction


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.pde.internal.ui.search;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.pde.internal.core.ischema.ISchema;
18 import org.eclipse.pde.internal.core.schema.SchemaDescriptor;
19 import org.eclipse.ui.IObjectActionDelegate;
20 import org.eclipse.ui.IWorkbenchPart;
21
22 public class PreviewReferenceAction implements IObjectActionDelegate {
23     private IFile fFile;
24     private ShowDescriptionAction fDelegate;
25     
26     /**
27      * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
28      */

29     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
30     }
31
32     /**
33      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
34      */

35     public void run(IAction action) {
36         if (fFile == null)
37             return;
38         SchemaDescriptor sd = new SchemaDescriptor(fFile, false);
39         ISchema schema = sd.getSchema(false);
40         if (fDelegate == null) {
41             fDelegate = new ShowDescriptionAction(schema);
42         } else
43             fDelegate.setSchema(schema);
44         fDelegate.run();
45     }
46
47     /**
48      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
49      */

50     public void selectionChanged(IAction action, ISelection selection) {
51         fFile = null;
52         if (selection instanceof IStructuredSelection) {
53             Object JavaDoc obj = ((IStructuredSelection)selection).getFirstElement();
54             if (obj instanceof IFile)
55                 fFile = (IFile)obj;
56         }
57     }
58 }
59
Popular Tags