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.JavaDetailFormattersManager;
23 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression;
24 import org.eclipse.jface.action.IAction;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26 
27 public class RemoveDetailFormatterAction extends ObjectActionDelegate {
28 
29 	/**
30 	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
31 	 */
32 	@Override
run(IAction action)33 	public void run(IAction action) {
34 		IStructuredSelection selection= getCurrentSelection();
35 		if (selection == null || selection.size() != 1) {
36 			return;
37 		}
38 		Object element= selection.getFirstElement();
39 		IJavaType type;
40 		try {
41 			IJavaValue value;
42 			if (element instanceof IJavaVariable) {
43 				value = ((IJavaValue)((IJavaVariable) element).getValue());
44 			} else if (element instanceof JavaInspectExpression) {
45 				value = ((IJavaValue)((JavaInspectExpression) element).getValue());
46 			} else {
47 				return;
48 			}
49 			type= value.getJavaType();
50 		} catch (DebugException e) {
51 			return;
52 		}
53 		JavaDetailFormattersManager detailFormattersManager= JavaDetailFormattersManager.getDefault();
54 		DetailFormatter detailFormatter= detailFormattersManager.getAssociatedDetailFormatter(type);
55 		detailFormattersManager.removeAssociatedDetailFormatter(detailFormatter);
56 	}
57 
58 }
59