KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Provides implementation to filter unavailable projects form the launch configuration dialog.
24  * It is (de) activated via the <code>IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED</code> preference.
25  *
26  * @since 3.2
27  *
28  */

29 public class DeletedProjectFilter extends ViewerFilter {
30
31     /**
32      * Constructor
33      */

34     public DeletedProjectFilter() {
35         super();
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         //always let through types, we only care about configs
43
if (element instanceof ILaunchConfigurationType) {
44             return true;
45         }
46         if(element instanceof ILaunchConfiguration) {
47             try {
48                 ILaunchConfiguration config = (ILaunchConfiguration)element;
49                 IResource[] resources = config.getMappedResources();
50                 if(resources == null) {
51                     return true;
52                 }
53                 for(int i = 0; i < resources.length; i++) {
54                     IProject project= resources[i].getProject();
55                     if(project != null && project.exists()) {
56                         return true;
57                     }
58                 }
59             }
60             catch(CoreException e) {}
61         }
62         return false;
63     }
64
65 }
66
Popular Tags