KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > DebugModelPropertyTester


1 /*******************************************************************************
2  * Copyright (c) 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;
12
13 import org.eclipse.core.expressions.PropertyTester;
14 import org.eclipse.debug.core.model.IDebugElement;
15 import org.eclipse.debug.core.model.IDebugTarget;
16 import org.eclipse.debug.core.model.IDisconnect;
17 import org.eclipse.debug.core.model.IProcess;
18 import org.eclipse.debug.core.model.ITerminate;
19
20 /**
21  * This class is used to check properties of a debug model. Two properties can be checked.
22  * Using "getModelIdentifier" compares the debug model identifier of the receiver against the
23  * expected value passed as an argument. The "isTerminatedOrDisconnected" property checks if
24  * the receiver is terminated or disconnected.
25  *
26  * @since 3.3
27  */

28 public class DebugModelPropertyTester extends PropertyTester {
29
30     public static final String JavaDoc MODEL_TYPE_PROPERTY = "getModelIdentifier"; //$NON-NLS-1$
31
public static final String JavaDoc IS_TERMINATED_OR_DISCONNECTED_PROPERTY = "isTerminatedOrDisconnected"; //$NON-NLS-1$
32

33     /* (non-Javadoc)
34      * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
35      */

36     public boolean test(Object JavaDoc receiver, String JavaDoc property, Object JavaDoc[] args, Object JavaDoc expectedValue) {
37         if (MODEL_TYPE_PROPERTY.equals(property)){
38             IDebugTarget target = null;
39             if(receiver instanceof IProcess) {
40                 target = (IDebugTarget) ((IProcess)receiver).getAdapter(IDebugTarget.class);
41             }
42             else if(receiver instanceof IDebugElement) {
43                 target = (IDebugTarget) ((IDebugElement)receiver).getAdapter(IDebugTarget.class);
44             }
45             if(target != null) {
46                 // check that the expected value argument is valid
47
if (expectedValue == null || expectedValue.equals("")){ //$NON-NLS-1$
48
return false;
49                 }
50                 //!target.isTerminated() && !target.isDisconnected()
51
if(expectedValue.equals(target.getModelIdentifier())) {
52                     return true;
53                 }
54             }
55             return false;
56         } else if (IS_TERMINATED_OR_DISCONNECTED_PROPERTY.equals(property)){
57             if (receiver instanceof ITerminate && ((ITerminate)receiver).isTerminated()){
58                 return true;
59             } if (receiver instanceof IDisconnect && ((IDisconnect)receiver).isDisconnected()){
60                 return true;
61             } else {
62                 return false;
63             }
64         } else {
65             return false;
66         }
67     }
68 }
69
Popular Tags