KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > LaunchablePropertyTester


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.actions;
12
13 import org.eclipse.core.expressions.PropertyTester;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
20 import org.eclipse.debug.ui.actions.ILaunchable;
21
22 /**
23  * Tests if an object is launchable.
24  */

25 public class LaunchablePropertyTester extends PropertyTester {
26
27     /**
28      * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
29      */

30     public boolean test(Object JavaDoc receiver, String JavaDoc property, Object JavaDoc[] args, Object JavaDoc expectedValue) {
31         if ("launchable".equals(property)) { //$NON-NLS-1$
32
if (DebugUIPlugin.getDefault().getLaunchConfigurationManager().launchModeAvailable((String JavaDoc)expectedValue)) {
33                     return Platform.getAdapterManager().hasAdapter(receiver, ILaunchable.class.getName());
34                 }
35         }
36         if("contextlaunch".equals(property)) { //$NON-NLS-1$
37
if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH)) {
38                 IResource res = getResource(receiver);
39                 if(res != null) {
40                     return res.isAccessible() && getLaunchConfiguraitonManager().getLaunchShortcuts(getResource(receiver)).size() > 0 && getLaunchConfiguraitonManager().isSharedConfig(receiver) == null;
41                 }
42                 return false;
43             }
44         }
45         return false;
46     }
47
48     /**
49      * Returns the launch configuration manager
50      * @return the launch configuration manager
51      */

52     protected LaunchConfigurationManager getLaunchConfiguraitonManager() {
53         return DebugUIPlugin.getDefault().getLaunchConfigurationManager();
54     }
55     
56     /**
57      * Returns the resource this property page is open on.
58      *
59      * @return resource
60      */

61     protected IResource getResource(Object JavaDoc element) {
62         IResource resource = null;
63         if (element instanceof IResource) {
64             resource = (IResource) element;
65         } else if (element instanceof IAdaptable) {
66             resource = (IResource) ((IAdaptable)element).getAdapter(IResource.class);
67         }
68         return resource;
69     }
70 }
71
Popular Tags