KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > BreakpointWorkingSetElementAdapter


1 /*******************************************************************************
2  * Copyright (c) 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.debug.internal.ui.views.breakpoints;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.debug.core.model.IBreakpoint;
18 import org.eclipse.ui.IWorkingSet;
19 import org.eclipse.ui.IWorkingSetElementAdapter;
20
21 /**
22  * Consulted by workbench pull down actions that add/remove selected elements to/from
23  * working sets. Allows breakpoint working sets to select which elements are applicable
24  * for adding/removing.
25  *
26  * @since 3.3
27  */

28 public class BreakpointWorkingSetElementAdapter implements IWorkingSetElementAdapter {
29
30     /* (non-Javadoc)
31      * @see org.eclipse.ui.IWorkingSetElementAdapter#adaptElements(org.eclipse.ui.IWorkingSet, org.eclipse.core.runtime.IAdaptable[])
32      */

33     public IAdaptable[] adaptElements(IWorkingSet ws, IAdaptable[] elements) {
34         for (int i = 0; i < elements.length; i++) {
35             IAdaptable adaptable = elements[i];
36             if (!(adaptable instanceof IBreakpoint)) {
37                 return selectBreakpoints(elements);
38             }
39         }
40         return elements;
41     }
42     
43     private IAdaptable[] selectBreakpoints(IAdaptable[] elements) {
44         List JavaDoc breakpoints = new ArrayList JavaDoc(elements.length);
45         for (int i = 0; i < elements.length; i++) {
46             IAdaptable adaptable = elements[i];
47             if (adaptable instanceof IBreakpoint) {
48                 breakpoints.add(adaptable);
49             }
50         }
51         return (IAdaptable[]) breakpoints.toArray(new IAdaptable[breakpoints.size()]);
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.ui.IWorkingSetElementAdapter#dispose()
56      */

57     public void dispose() {
58     }
59
60 }
61
Popular Tags