KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.core.ILaunchConfigurationType;
16 import org.eclipse.debug.ui.IDebugUIConstants;
17 import org.eclipse.jface.viewers.Viewer;
18 import org.eclipse.jface.viewers.ViewerFilter;
19 import org.eclipse.ui.activities.WorkbenchActivityHelper;
20
21 /**
22  * This class extends <code>LaunchGroupFilter</code> by allowing more than one launch group to be used in
23  * the filtering
24  *
25  * @since 3.2
26  */

27 public class MultiLaunchGroupFilter extends ViewerFilter {
28
29     /**
30      * array of launchgroup extensions to test for filtering against
31      */

32     private LaunchGroupExtension[] fGroups;
33     
34     public MultiLaunchGroupFilter(LaunchGroupExtension[] groups) {
35         fGroups = groups;
36     }
37     
38     /* (non-Javadoc)
39      * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
40      */

41     public boolean select(Viewer viewer, Object JavaDoc parentElement, Object JavaDoc element) {
42         ILaunchConfigurationType type = null;
43         ILaunchConfiguration config = null;
44         boolean priv = false;
45         if (parentElement instanceof ILaunchConfigurationType) {
46             type = (ILaunchConfigurationType)parentElement;
47         }
48         if (element instanceof ILaunchConfigurationType) {
49             type = (ILaunchConfigurationType)element;
50             priv = !type.isPublic();
51         }
52         if (element instanceof ILaunchConfiguration) {
53             config = (ILaunchConfiguration)element;
54             try {
55                 type = config.getType();
56                 priv = config.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false);
57             }
58             catch (CoreException e) {}
59         }
60         if (type != null) {
61             return !priv && equalModes(type) && equalCategories(type.getCategory()) && !WorkbenchActivityHelper.filterItem(new LaunchConfigurationTypeContribution(type));
62         }
63         return false;
64     }
65
66     /**
67      * compares a mode against the modes form the list of group modes
68      * @param mode the mode to compare
69      * @return true if the mode matches any one of the modes in the listing, false otherwise
70      */

71     private boolean equalModes(ILaunchConfigurationType type) {
72         for(int i = 0; i < fGroups.length; i++) {
73             if(type.supportsMode(fGroups[i].getMode())) {
74                 return true;
75             }
76         }
77         return false;
78     }
79     
80     /**
81      * compares a category against those passed in the creation of the filter
82      * @param category the category to compare
83      * @return true if the category matches any one fo the categories in the listing, false otherwise
84      */

85     private boolean equalCategories(String JavaDoc category) {
86         String JavaDoc lcat = null;
87         for(int i = 0; i < fGroups.length; i++) {
88             lcat = fGroups[i].getCategory();
89             if(category == null || lcat == null) {
90                 if(category == lcat) {
91                     return true;
92                 }
93             }
94             else {
95                 if(category.equals(lcat)) {
96                     return true;
97                 }
98             }
99         }
100         return false;
101     }
102     
103 }
104
Popular Tags