KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > breakpointGroups > ToggleDefaultGroupAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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 implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.actions.breakpointGroups;
12
13 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
14 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer;
15 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointSetOrganizer;
16 import org.eclipse.debug.internal.ui.views.breakpoints.WorkingSetCategory;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.ui.IWorkingSet;
21
22 /**
23  * Toggles the default breakpoint group based on selection.
24  */

25 public class ToggleDefaultGroupAction extends AbstractBreakpointsViewAction {
26     
27     private IWorkingSet fSelectedSet;
28     
29     /* (non-Javadoc)
30      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
31      */

32     public void run(IAction action) {
33         IWorkingSet defaultWorkingSet = BreakpointSetOrganizer.getDefaultWorkingSet();
34         IWorkingSet set = null;
35         if (!fSelectedSet.equals(defaultWorkingSet)) {
36             set = fSelectedSet;
37         }
38         BreakpointSetOrganizer.setDefaultWorkingSet(set);
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
43      */

44     public void selectionChanged(IAction action, ISelection sel) {
45         fSelectedSet = null;
46         if (sel instanceof IStructuredSelection) {
47             IStructuredSelection selection = (IStructuredSelection) sel;
48             if (selection.size() == 1) {
49                 Object JavaDoc firstElement = selection.getFirstElement();
50                 if (firstElement instanceof BreakpointContainer) {
51                     BreakpointContainer container = (BreakpointContainer) firstElement;
52                     if (container.getCategory() instanceof WorkingSetCategory) {
53                         WorkingSetCategory category = (WorkingSetCategory)container.getCategory();
54                         if (IInternalDebugUIConstants.ID_BREAKPOINT_WORKINGSET.equals(category.getWorkingSet().getId())) {
55                             IWorkingSet set = category.getWorkingSet();
56                             action.setEnabled(true);
57                             boolean isDefault = set == BreakpointSetOrganizer.getDefaultWorkingSet();
58                             action.setChecked(isDefault);
59                             fSelectedSet = set;
60                             return;
61                         }
62                     }
63                 }
64             }
65         }
66         action.setEnabled(false);
67         action.setChecked(false);
68     }
69 }
70
Popular Tags