KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > LaunchGroupFilter


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.debug.internal.ui.launchConfigurations;
12
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationType;
17 import org.eclipse.debug.ui.IDebugUIConstants;
18 import org.eclipse.debug.ui.ILaunchGroup;
19 import org.eclipse.jface.viewers.Viewer;
20 import org.eclipse.jface.viewers.ViewerFilter;
21 import org.eclipse.ui.activities.WorkbenchActivityHelper;
22
23 /**
24  * Displays launch configurations for a specific launch group
25  */

26 public class LaunchGroupFilter extends ViewerFilter {
27     
28     private ILaunchGroup fGroup;
29     
30     /**
31      * Constructor
32      * @param groupExtension
33      */

34     public LaunchGroupFilter(ILaunchGroup groupExtension) {
35         super();
36         fGroup = groupExtension;
37     }
38
39     /**
40      * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
41      */

42     public boolean select(Viewer viewer, Object JavaDoc parentElement, Object JavaDoc element) {
43             ILaunchConfigurationType type = null;
44             ILaunchConfiguration config = null;
45             if (parentElement instanceof ILaunchConfigurationType) {
46                 type = (ILaunchConfigurationType)parentElement;
47             }
48             if (element instanceof ILaunchConfigurationType) {
49                 type = (ILaunchConfigurationType)element;
50             }
51             if (element instanceof ILaunchConfiguration) {
52                 config = (ILaunchConfiguration)element;
53                 try {
54                     type = config.getType();
55                 }
56                 catch (CoreException e) {}
57             }
58             boolean priv = false;
59             if (config != null) {
60                 try {
61                     priv = config.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false);
62                 } catch (CoreException e) {
63                 }
64             }
65             if (type != null) {
66                 return !priv && type.supportsMode(fGroup.getMode()) && equalCategories(type.getCategory(), fGroup.getCategory()) && !WorkbenchActivityHelper.filterItem(new LaunchConfigurationTypeContribution(type));
67             }
68             return false;
69     }
70     
71     /**
72      * Returns whether the given categories are equal.
73      *
74      * @param c1 category identifier or <code>null</code>
75      * @param c2 category identifier or <code>null</code>
76      * @return boolean
77      */

78     private boolean equalCategories(String JavaDoc c1, String JavaDoc c2) {
79         if (c1 == null || c2 == null) {
80             return c1 == c2;
81         }
82         return c1.equals(c2);
83     }
84
85 }
86
Popular Tags