Skip to main content
summaryrefslogtreecommitdiffstats
blob: 39b92de6558aa2f34b39c74ff99a7714f60930cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2006, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Wind River Systems (Pawel Piech) - added support for IDebugModelProvider (Bug 212314)
 *******************************************************************************/
package org.eclipse.debug.internal.ui;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugModelProvider;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IDisconnect;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.ITerminate;
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;

/**
 * This class is used to check properties of a debug model.  Two properties can be checked.
 * Using "getModelIdentifier" compares the debug model identifier of the receiver against the
 * expected value passed as an argument.  The "isTerminatedOrDisconnected" property checks if
 * the receiver is terminated or disconnected.
 *
 *	@since 3.3
 */
public class DebugModelPropertyTester extends PropertyTester {

	public static final String MODEL_TYPE_PROPERTY = "getModelIdentifier"; //$NON-NLS-1$
	public static final String IS_TERMINATED_OR_DISCONNECTED_PROPERTY = "isTerminatedOrDisconnected"; //$NON-NLS-1$
	
	/* (non-Javadoc)
	 * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
	 */
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
		if (MODEL_TYPE_PROPERTY.equals(property)){
			IDebugTarget target = null;
			if(receiver instanceof IProcess) {
				target = (IDebugTarget) ((IProcess)receiver).getAdapter(IDebugTarget.class);
			}
			else if(receiver instanceof IDebugElement) { 
				target = (IDebugTarget) ((IDebugElement)receiver).getAdapter(IDebugTarget.class);
			}
			if(target != null) {
				// check that the expected value argument is valid
				if (expectedValue == null || expectedValue.equals(IInternalDebugCoreConstants.EMPTY_STRING)){
					return false;
				}
				//!target.isTerminated() && !target.isDisconnected() 
				if(expectedValue.equals(target.getModelIdentifier())) {
					return true;
				}
			}
			IDebugModelProvider modelProvider = null;
			if (receiver instanceof IAdaptable) {
				modelProvider = (IDebugModelProvider) ((IAdaptable)receiver).getAdapter(IDebugModelProvider.class);
			} else {
				modelProvider =
					(IDebugModelProvider) Platform.getAdapterManager().
						getAdapter(receiver, IDebugModelProvider.class);
			}
		    if (modelProvider != null) {
		        String[] ids = modelProvider.getModelIdentifiers();
		        for (int i = 0; i < ids.length; i++) {
		            if (ids[i].equals(expectedValue)) {
		                return true;
		            }
		        }
		        return false;
		    }
			// There is no element selected with an associated debug model.  
			// Return true iff the expected value is an empty string.  
			return "".equals(expectedValue); //$NON-NLS-1$
		} else if (IS_TERMINATED_OR_DISCONNECTED_PROPERTY.equals(property)){
			if (receiver instanceof ITerminate && ((ITerminate)receiver).isTerminated()){
				return true;
			} if (receiver instanceof IDisconnect && ((IDisconnect)receiver).isDisconnected()){
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}

Back to the top