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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*******************************************************************************
* 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.ICategory;
import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
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.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.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.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.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.equals(Boolean.valueOf(canDelete));
}
// ***** Categories related properties *****
if ("isCategoryID".equals(property) && receiver instanceof ICategory) { //$NON-NLS-1$
String id = ((ICategory)receiver).getId();
return id.equals(expectedValue);
}
if ("isMyTargets".equals(property) && receiver instanceof ICategory) { //$NON-NLS-1$
String id = ((ICategory)receiver).getId();
return expectedValue.equals(Boolean.valueOf(id.equals(IUIConstants.ID_CAT_MY_TARGETS)));
}
if ("isFavorites".equals(property) && receiver instanceof ICategory) { //$NON-NLS-1$
String id = ((ICategory)receiver).getId();
return expectedValue.equals(Boolean.valueOf(id.equals(IUIConstants.ID_CAT_FAVORITES)));
}
if ("isNeighborhood".equals(property) && receiver instanceof ICategory) { //$NON-NLS-1$
String id = ((ICategory)receiver).getId();
return expectedValue.equals(Boolean.valueOf(id.equals(IUIConstants.ID_CAT_NEIGHBORHOOD)));
}
return false;
}
}
|