| package org.eclipse.jdt.internal.debug.ui.actions; |
| |
| /* ******************************************************************** |
| Copyright (c) 2002 IBM Corp. All rights reserved. |
| This file is made available under the terms of the Common Public License v1.0 |
| which accompanies this distribution, and is available at |
| http://www.eclipse.org/legal/cpl-v10.html |
| **********************************************************************/ |
| |
| import org.eclipse.debug.core.DebugException; |
| import org.eclipse.jdt.debug.core.IJavaValue; |
| import org.eclipse.jdt.debug.core.IJavaVariable; |
| import org.eclipse.jdt.internal.debug.ui.DetailFormatter; |
| import org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog; |
| import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
| import org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager; |
| import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; |
| import org.eclipse.jdt.internal.ui.dialogs.StatusDialog; |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| |
| public class NewDetailFormatterAction extends ObjectActionDelegate { |
| |
| /** |
| * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) |
| */ |
| public void run(IAction action) { |
| IStructuredSelection selection= getCurrentSelection(); |
| if (selection.size() != 1) { |
| return; |
| } |
| Object element= selection.getFirstElement(); |
| String typeName; |
| try { |
| IJavaValue value; |
| if (element instanceof IJavaVariable) { |
| value = ((IJavaValue)((IJavaVariable) element).getValue()); |
| } else if (element instanceof JavaInspectExpression) { |
| value = ((IJavaValue)((JavaInspectExpression) element).getValue()); |
| } else { |
| return; |
| } |
| typeName= value.getJavaType().getName(); |
| } catch (DebugException e) { |
| return; |
| } |
| JavaDetailFormattersManager detailFormattersManager= JavaDetailFormattersManager.getDefault(); |
| DetailFormatter detailFormatter= new DetailFormatter(typeName, "", true); //$NON-NLS-1$ |
| if (new DetailFormatterDialog(JDIDebugUIPlugin.getActivePage().getWorkbenchWindow().getShell(), detailFormatter, null, false, true).open() == StatusDialog.OK) { |
| detailFormattersManager.setAssociatedDetailFormatter(detailFormatter); |
| } |
| } |
| |
| } |