01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.search;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.jface.action.IAction;
14: import org.eclipse.jface.viewers.ISelection;
15: import org.eclipse.jface.viewers.IStructuredSelection;
16: import org.eclipse.pde.internal.core.ischema.ISchema;
17: import org.eclipse.pde.internal.core.schema.SchemaDescriptor;
18: import org.eclipse.ui.IObjectActionDelegate;
19: import org.eclipse.ui.IWorkbenchPart;
20:
21: public class PreviewReferenceAction implements IObjectActionDelegate {
22: private IFile fFile;
23: private ShowDescriptionAction fDelegate;
24:
25: /**
26: * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
27: */
28: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
29: }
30:
31: /**
32: * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
33: */
34: public void run(IAction action) {
35: if (fFile == null)
36: return;
37: SchemaDescriptor sd = new SchemaDescriptor(fFile, false);
38: ISchema schema = sd.getSchema(false);
39: if (fDelegate == null) {
40: fDelegate = new ShowDescriptionAction(schema);
41: } else
42: fDelegate.setSchema(schema);
43: fDelegate.run();
44: }
45:
46: /**
47: * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
48: */
49: public void selectionChanged(IAction action, ISelection selection) {
50: fFile = null;
51: if (selection instanceof IStructuredSelection) {
52: Object obj = ((IStructuredSelection) selection)
53: .getFirstElement();
54: if (obj instanceof IFile)
55: fFile = (IFile) obj;
56: }
57: }
58: }
|