blob: 39f1a6a0a484d063209868c5a268817bf5a2e041 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 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.jdt.internal.ui.actions;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.JavaUIMessages;
import org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog2;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
public class OpenTypeAction extends Action implements IWorkbenchWindowActionDelegate {
public OpenTypeAction() {
super();
setText(JavaUIMessages.OpenTypeAction_label);
setDescription(JavaUIMessages.OpenTypeAction_description);
setToolTipText(JavaUIMessages.OpenTypeAction_tooltip);
setImageDescriptor(JavaPluginImages.DESC_TOOL_OPENTYPE);
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_TYPE_ACTION);
}
public void run() {
Shell parent= JavaPlugin.getActiveWorkbenchShell();
OpenTypeSelectionDialog2 dialog= new OpenTypeSelectionDialog2(parent, false,
PlatformUI.getWorkbench().getProgressService(),
null, IJavaSearchConstants.TYPE);
dialog.setTitle(JavaUIMessages.OpenTypeAction_dialogTitle);
dialog.setMessage(JavaUIMessages.OpenTypeAction_dialogMessage);
int result= dialog.open();
if (result != IDialogConstants.OK_ID)
return;
Object[] types= dialog.getResult();
if (types != null && types.length > 0) {
IType type= (IType)types[0];
try {
IEditorPart part= EditorUtility.openInEditor(type, true);
EditorUtility.revealInEditor(part, type);
} catch (CoreException x) {
String title= JavaUIMessages.OpenTypeAction_errorTitle;
String message= JavaUIMessages.OpenTypeAction_errorMessage;
ExceptionHandler.handle(x, title, message);
}
}
}
//---- IWorkbenchWindowActionDelegate ------------------------------------------------
public void run(IAction action) {
run();
}
public void dispose() {
// do nothing.
}
public void init(IWorkbenchWindow window) {
// do nothing.
}
public void selectionChanged(IAction action, ISelection selection) {
// do nothing. Action doesn't depend on selection.
}
}