KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationType;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.jface.viewers.ViewerFilter;
20
21 /**
22  *
23  * This implementation is used to filter closed projects from the launch configuration dialog.
24  * It is (de)activated via the <code>IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED</code> preference, and is
25  * provided to fix bug 19521.
26  *
27  * @since 3.2
28  *
29  */

30 public class ClosedProjectFilter extends ViewerFilter {
31
32     /**
33      * Constructor
34      */

35     public ClosedProjectFilter() {
36         super();
37     }
38
39     /* (non-Javadoc)
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 parent, Object JavaDoc element) {
43         //always let through types, we only care about configs
44
if(element instanceof ILaunchConfigurationType) {
45             return true;
46         }
47         if(element instanceof ILaunchConfiguration) {
48             try {
49                 ILaunchConfiguration config = (ILaunchConfiguration)element;
50                 IResource[] resources = config.getMappedResources();
51                 //if it has no mapping, it might not have migration delegate, so let it pass
52
if(resources == null) {
53                     return true;
54                 }
55                 for(int i = 0; i < resources.length; i++) {
56                     IProject project= resources[i].getProject();
57                     //we don't want overlap with the deleted projects filter, so we need to allow projects that don't exist through
58
if(project != null && (project.isOpen() || !project.exists())) {
59                         return true;
60                     }
61                 }
62             }
63             catch (CoreException e) {}
64         }
65         return false;
66     }
67 }
68
Popular Tags