Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f543511391778266ef9ac21c6fa57a822366781f (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
93
94
95
96
97
98
99
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, Inc. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.ui.views.expressions;

import org.eclipse.core.runtime.Platform;
import org.eclipse.tcf.te.ui.views.editor.EditorInput;
import org.eclipse.tcf.te.ui.views.extensions.EditorPageBindingExtensionPointManager;
import org.eclipse.tcf.te.ui.views.interfaces.handler.IDeleteHandlerDelegate;
import org.eclipse.tcf.te.ui.views.interfaces.handler.IRefreshHandlerDelegate;
import org.eclipse.ui.IEditorInput;


/**
 * Property tester implementation.
 */
public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {

	/* (non-Javadoc)
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
	 */
	@Override
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {

		if ("hasApplicableEditorBindings".equals(property)) { //$NON-NLS-1$
			// Create a fake editor input object
			IEditorInput input = new EditorInput(receiver);
			return (expectedValue != null ? expectedValue : Boolean.TRUE).equals(Boolean.valueOf(EditorPageBindingExtensionPointManager.getInstance().getApplicableEditorPageBindings(input).length > 0));
		}

		if ("isRefreshableElement".equals(property)) { //$NON-NLS-1$
			// An element is refreshable if it implements or adapt to IRefreshHandlerDelegate
			//
			// Note: This test will force the load of the adapter.

			boolean refreshable = receiver instanceof IRefreshHandlerDelegate;
			if (!refreshable) {
				IRefreshHandlerDelegate delegate = (IRefreshHandlerDelegate)Platform.getAdapterManager().loadAdapter(receiver, IRefreshHandlerDelegate.class.getName());
				refreshable = delegate != null;
			}

			return (expectedValue != null ? expectedValue : Boolean.TRUE).equals(Boolean.valueOf(refreshable));
		}

		if ("canRefresh".equals(property)) { //$NON-NLS-1$
			// Test if the receiver can be refreshed
			IRefreshHandlerDelegate delegate = receiver instanceof IRefreshHandlerDelegate ? (IRefreshHandlerDelegate)receiver : null;
			if (delegate == null) {
				delegate = (IRefreshHandlerDelegate)Platform.getAdapterManager().loadAdapter(receiver, IRefreshHandlerDelegate.class.getName());
			}

			boolean canRefresh = false;
			if (delegate != null) {
				canRefresh = delegate.canRefresh(receiver);
			}

			return (expectedValue != null ? expectedValue : Boolean.TRUE).equals(Boolean.valueOf(canRefresh));
		}


		if ("isDeletableElement".equals(property)) { //$NON-NLS-1$
			// An element is deletable if it implements or adapt to IDeleteHandlerDelegate
			//
			// Note: This test will force the load of the adapter.

			boolean deletable = receiver instanceof IDeleteHandlerDelegate;
			if (!deletable) {
				IDeleteHandlerDelegate delegate = (IDeleteHandlerDelegate)Platform.getAdapterManager().loadAdapter(receiver, IDeleteHandlerDelegate.class.getName());
				deletable = delegate != null;
			}

			return (expectedValue != null ? expectedValue : Boolean.TRUE).equals(Boolean.valueOf(deletable));
		}

		if ("canDelete".equals(property)) { //$NON-NLS-1$
			// Test if the receiver can be deleted
			IDeleteHandlerDelegate delegate = receiver instanceof IDeleteHandlerDelegate ? (IDeleteHandlerDelegate)receiver : null;
			if (delegate == null) {
				delegate = (IDeleteHandlerDelegate)Platform.getAdapterManager().loadAdapter(receiver, IDeleteHandlerDelegate.class.getName());
			}

			boolean canDelete = false;
			if (delegate != null) {
				canDelete = delegate.canDelete(receiver);
			}

			return (expectedValue != null ? expectedValue : Boolean.TRUE).equals(Boolean.valueOf(canDelete));
		}

		return false;
	}

}

Back to the top