| /******************************************************************************* |
| * Copyright (c) 2003, 2004 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.jst.j2ee.internal.actions; |
| |
| |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.swt.widgets.Event; |
| import org.eclipse.ui.IActionDelegate2; |
| import org.eclipse.ui.IEditorDescriptor; |
| import org.eclipse.ui.IEditorRegistry; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.actions.SelectionListenerAction; |
| |
| /** |
| * Action for opening a J2EE resource from the J2EE navigator. |
| */ |
| public abstract class AbstractOpenAction extends SelectionListenerAction implements IActionDelegate2 { |
| // //$NON-NLS-1$ |
| protected IEditorDescriptor currentDescriptor; |
| protected Object srcObject; |
| |
| protected AbstractOpenAction(String text) { |
| super(text); |
| } |
| |
| protected static IEditorDescriptor findEditorDescriptor(String id) { |
| IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); |
| return registry.findEditor(id); |
| } |
| |
| protected void setAttributesFromDescriptor() { |
| if (currentDescriptor == null) |
| return; |
| setText(currentDescriptor.getLabel()); |
| setToolTipText(currentDescriptor.getLabel()); |
| setImageDescriptor(currentDescriptor.getImageDescriptor()); |
| } |
| |
| /** |
| * The structured selection has changed in the workbench. Subclasses should override this method |
| * to react to the change. Returns true if the action should be enabled for this selection, and |
| * false otherwise. |
| * |
| * When this method is overridden, the super method must always be invoked. If the super method |
| * returns false, this method must also return false. |
| * |
| * @param sel |
| * the new structured selection |
| */ |
| public boolean updateSelection(IStructuredSelection s) { |
| srcObject = null; |
| if (!super.updateSelection(s)) |
| return false; |
| |
| if (s.size() != 1) |
| return false; |
| |
| return true; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.IActionDelegate2#dispose() |
| */ |
| public void dispose() { |
| //Dispose |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) |
| */ |
| public void init(IAction action) { |
| //init |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, |
| * org.eclipse.swt.widgets.Event) |
| */ |
| public void runWithEvent(IAction action, Event event) { |
| runWithEvent(event); |
| |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) |
| */ |
| public void run(IAction action) { |
| // TODO Auto-generated method stub |
| run(); |
| |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, |
| * org.eclipse.jface.viewers.ISelection) |
| */ |
| public void selectionChanged(IAction action, ISelection selection) { |
| // TODO HACK! |
| updateSelection((IStructuredSelection) selection); |
| } |
| |
| } |