KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdt.debug.core.IJavaBreakpoint;
15 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.ISelectionChangedListener;
19 import org.eclipse.jface.viewers.ISelectionProvider;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.jface.window.IShellProvider;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.ui.IObjectActionDelegate;
25 import org.eclipse.ui.IWorkbenchPart;
26 import org.eclipse.ui.dialogs.PropertyDialogAction;
27
28 /**
29  * Presents the standard properties dialog to configure
30  * the attributes of a Java Breakpoint.
31  */

32 public class JavaBreakpointPropertiesAction implements IObjectActionDelegate {
33     
34     private IWorkbenchPart fPart;
35     private IJavaBreakpoint fBreakpoint;
36
37     /**
38      * @see IActionDelegate#run(IAction)
39      */

40     public void run(IAction action) {
41         if(fBreakpoint != null) {
42             IShellProvider provider;
43             if (fPart != null) {
44                 provider = fPart.getSite();
45             } else {
46                 provider = new IShellProvider() {
47                     public Shell getShell() {
48                         return JDIDebugUIPlugin.getActiveWorkbenchShell();
49                     }
50                 };
51             }
52             PropertyDialogAction propertyAction=
53                 new PropertyDialogAction(provider, new ISelectionProvider() {
54                     public void addSelectionChangedListener(ISelectionChangedListener listener) {
55                     }
56                     public ISelection getSelection() {
57                         return new StructuredSelection(fBreakpoint);
58                     }
59                     public void removeSelectionChangedListener(ISelectionChangedListener listener) {
60                     }
61                     public void setSelection(ISelection selection) {
62                     }
63                 });
64             propertyAction.run();
65         }
66     }
67
68     /**
69      * @see IActionDelegate#selectionChanged(IAction, ISelection)
70      */

71     public void selectionChanged(IAction action, ISelection selection) {
72         if (selection instanceof IStructuredSelection) {
73             IStructuredSelection ss= (IStructuredSelection)selection;
74             if (ss.isEmpty() || ss.size() > 1) {
75                 return;
76             }
77             Object JavaDoc element= ss.getFirstElement();
78             if (element instanceof IJavaBreakpoint) {
79                 setBreakpoint((IJavaBreakpoint)element);
80             }
81             else {
82                 setBreakpoint(null);
83             }
84         }
85     }
86
87     /**
88      * Allows the underlying breakpoint for the properties page to be set
89      * @param breakpoint
90      */

91     public void setBreakpoint(IJavaBreakpoint breakpoint) {
92         fBreakpoint = breakpoint;
93     }
94     
95     /**
96      * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
97      */

98     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
99         fPart = targetPart;
100     }
101 }
102
Popular Tags