1 /******************************************************************************* 2 * Copyright (c) 2000, 2015 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.debug.ui.actions; 15 16 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.jdt.debug.core.IJavaType; 19 import org.eclipse.jdt.debug.core.IJavaValue; 20 import org.eclipse.jdt.debug.core.IJavaVariable; 21 import org.eclipse.jdt.internal.debug.ui.DetailFormatter; 22 import org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog; 23 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 24 import org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager; 25 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; 26 import org.eclipse.jface.action.IAction; 27 import org.eclipse.jface.viewers.IStructuredSelection; 28 import org.eclipse.jface.window.Window; 29 30 public class NewDetailFormatterAction extends ObjectActionDelegate { 31 32 /** 33 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) 34 */ 35 @Override run(IAction action)36 public void run(IAction action) { 37 IStructuredSelection selection= getCurrentSelection(); 38 if (selection == null || selection.size() != 1) { 39 return; 40 } 41 Object element= selection.getFirstElement(); 42 String typeName; 43 try { 44 IJavaType type; 45 if (element instanceof IJavaVariable) { 46 type = ((IJavaValue)((IJavaVariable) element).getValue()).getJavaType(); 47 } else if (element instanceof JavaInspectExpression) { 48 type = ((IJavaValue)((JavaInspectExpression) element).getValue()).getJavaType(); 49 } else { 50 return; 51 } 52 if (type == null) { 53 return; 54 } 55 typeName= type.getName(); 56 } catch (DebugException e) { 57 return; 58 } 59 JavaDetailFormattersManager detailFormattersManager= JavaDetailFormattersManager.getDefault(); 60 DetailFormatter detailFormatter= new DetailFormatter(typeName, "", true); //$NON-NLS-1$ 61 if (new DetailFormatterDialog(JDIDebugUIPlugin.getActivePage().getWorkbenchWindow().getShell(), detailFormatter, null, true, false).open() == Window.OK) { 62 detailFormattersManager.setAssociatedDetailFormatter(detailFormatter); 63 } 64 } 65 66 } 67