2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
11 package net.sourceforge.phpeclipse.webbrowser.internal;
14 import java.util.Iterator;
16 import net.sourceforge.phpeclipse.webbrowser.WebBrowser;
17 import net.sourceforge.phpeclipse.webbrowser.WebBrowserEditorInput;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.ui.IActionDelegate;
25 * Action to open the Web broswer on a resource.
27 public class OpenWithBrowserActionDelegate implements IActionDelegate {
28 private IResource resource;
31 * OpenBrowserAction constructor comment.
33 public OpenWithBrowserActionDelegate() {
38 * Performs this action.
40 * This method is called when the delegating action has been triggered.
41 * Implement this method to do the actual work.
44 * @param action the action proxy that handles the presentation portion of the
47 public void run(IAction action) {
50 url = new URL("file://" + resource.getLocation());
51 WebBrowser.openURL(new WebBrowserEditorInput(url, WebBrowserEditorInput.SHOW_ALL | WebBrowserEditorInput.FORCE_NEW_PAGE));
52 } catch (Exception e) {
53 Trace.trace(Trace.SEVERE, "Error opening browser on file", e);
58 * Notifies this action delegate that the selection in the workbench has changed.
60 * Implementers can use this opportunity to change the availability of the
61 * action or to modify other presentation properties.
64 * @param action the action proxy that handles presentation portion of the action
65 * @param selection the current selection in the workbench
67 public void selectionChanged(IAction action, ISelection sel) {
68 if (sel.isEmpty() || !(sel instanceof IStructuredSelection)) {
69 action.setEnabled(false);
73 IStructuredSelection select = (IStructuredSelection) sel;
74 Iterator iterator = select.iterator();
75 Object selection = iterator.next();
76 if (iterator.hasNext()) { // more than one selection (should never happen)
77 action.setEnabled(false);
81 if (!(selection instanceof IResource)) {
82 action.setEnabled(false);
86 resource = (IResource) selection;
87 action.setEnabled(true);