KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > EditDetailFormatterAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.jdt.debug.core.IJavaClassType;
16 import org.eclipse.jdt.debug.core.IJavaType;
17 import org.eclipse.jdt.debug.core.IJavaValue;
18 import org.eclipse.jdt.debug.core.IJavaVariable;
19 import org.eclipse.jdt.internal.debug.ui.DetailFormatter;
20 import org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog;
21 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
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 import org.eclipse.jface.window.Window;
27
28 public class EditDetailFormatterAction extends ObjectActionDelegate {
29
30     /**
31      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
32      */

33     public void run(IAction action) {
34         IStructuredSelection selection = getCurrentSelection();
35         if(selection != null && selection.size() == 1) {
36             Object JavaDoc element = selection.getFirstElement();
37             IJavaType type;
38             try {
39                 IJavaValue value;
40                 if (element instanceof IJavaVariable) {
41                     value = ((IJavaValue)((IJavaVariable) element).getValue());
42                 } else if (element instanceof JavaInspectExpression) {
43                     value = ((IJavaValue)((JavaInspectExpression) element).getValue());
44                 } else {
45                     return;
46                 }
47                 type= value.getJavaType();
48             } catch (DebugException e) {
49                 return;
50             }
51             JavaDetailFormattersManager fm = JavaDetailFormattersManager.getDefault();
52             DetailFormatter formatter = fm.getAssociatedDetailFormatter(type);
53             if(formatter == null & type instanceof IJavaClassType) {
54                 formatter = fm.getDetailFormatterFromInterface((IJavaClassType) type);
55                 if(formatter == null) {
56                     formatter = fm.getDetailFormatterFromSuperclass((IJavaClassType) type);
57                 }
58             }
59             if (new DetailFormatterDialog(JDIDebugUIPlugin.getActivePage().getWorkbenchWindow().getShell(), formatter, null, false, true).open() == Window.OK) {
60                 fm.setAssociatedDetailFormatter(formatter);
61             }
62         }
63     }
64
65 }
66
Popular Tags