KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaType;
16 import org.eclipse.jdt.debug.core.IJavaValue;
17 import org.eclipse.jdt.debug.core.IJavaVariable;
18 import org.eclipse.jdt.internal.debug.ui.DetailFormatter;
19 import org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog;
20 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
21 import org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager;
22 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression;
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.viewers.IStructuredSelection;
25 import org.eclipse.jface.window.Window;
26
27 public class NewDetailFormatterAction extends ObjectActionDelegate {
28
29     /**
30      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
31      */

32     public void run(IAction action) {
33         IStructuredSelection selection= getCurrentSelection();
34         if (selection == null || selection.size() != 1) {
35             return;
36         }
37         Object JavaDoc element= selection.getFirstElement();
38         String JavaDoc typeName;
39         try {
40             IJavaType type;
41             if (element instanceof IJavaVariable) {
42                 type = ((IJavaValue)((IJavaVariable) element).getValue()).getJavaType();
43             } else if (element instanceof JavaInspectExpression) {
44                 type = ((IJavaValue)((JavaInspectExpression) element).getValue()).getJavaType();
45             } else {
46                 return;
47             }
48             if (type == null) {
49                 return;
50             }
51             typeName= type.getName();
52         } catch (DebugException e) {
53             return;
54         }
55         JavaDetailFormattersManager detailFormattersManager= JavaDetailFormattersManager.getDefault();
56         DetailFormatter detailFormatter= new DetailFormatter(typeName, "", true); //$NON-NLS-1$
57
if (new DetailFormatterDialog(JDIDebugUIPlugin.getActivePage().getWorkbenchWindow().getShell(), detailFormatter, null, true, false).open() == Window.OK) {
58             detailFormattersManager.setAssociatedDetailFormatter(detailFormatter);
59         }
60     }
61
62 }
63
Popular Tags