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;
26 * Action to open the Web broswer on a resource.
28 public class OpenWithBrowserActionDelegate implements IActionDelegate {
29 private IResource resource;
32 * OpenBrowserAction constructor comment.
34 public OpenWithBrowserActionDelegate() {
39 * Performs this action.
41 * This method is called when the delegating action has been triggered.
42 * Implement this method to do the actual work.
46 * the action proxy that handles the presentation portion of the
49 public void run(IAction action) {
52 url = new URL("file://" + resource.getFullPath());
53 WebBrowser.openURL(new WebBrowserEditorInput(url,
54 WebBrowserEditorInput.SHOW_ALL
55 | WebBrowserEditorInput.FORCE_NEW_PAGE));
56 } catch (Exception e) {
57 Trace.trace(Trace.SEVERE, "Error opening browser on file", e);
62 * Notifies this action delegate that the selection in the workbench has
65 * Implementers can use this opportunity to change the availability of the
66 * action or to modify other presentation properties.
70 * the action proxy that handles presentation portion of the
73 * the current selection in the workbench
75 public void selectionChanged(IAction action, ISelection sel) {
76 if (sel.isEmpty() || !(sel instanceof IStructuredSelection)) {
77 action.setEnabled(false);
81 IStructuredSelection select = (IStructuredSelection) sel;
82 Iterator iterator = select.iterator();
83 Object selection = iterator.next();
84 if (iterator.hasNext()) { // more than one selection (should never
86 action.setEnabled(false);
90 if (!(selection instanceof IResource)) {
91 action.setEnabled(false);
95 resource = (IResource) selection;
96 action.setEnabled(true);