blob: 1d0753259d64e228463a52a593654aee16eb5ed1 (
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
|
/*****************************************************************************
* Copyright (c) 2013, 2017 CEA LIST.
*
* 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:
* CEA LIST - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.cdo.internal.ui.expressions;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.dawn.spi.DawnState;
import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
import org.eclipse.papyrus.cdo.internal.ui.decorators.CDOStateAdapter;
/**
* This is the EObjectPropertyTester type. Enjoy.
*/
public class CDOObjectPropertyTester
extends PropertyTester {
public static final String CAN_LOCK = "canLock"; //$NON-NLS-1$
public static final String IS_LOCKED_LOCALLY = "isLockedLocally"; //$NON-NLS-1$
public static final String IS_LOCKED_REMOTELY = "isLockedRemotely"; //$NON-NLS-1$
public static final String IS_CONFLICTED = "isConflicted"; //$NON-NLS-1$
public CDOObjectPropertyTester() {
super();
}
@Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
boolean result = false;
CDOObject cdoObject = (CDOObject) receiver;
if (cdoObject != null) {
if (CAN_LOCK.equals(property)) {
result = canLock(cdoObject);
} else if (IS_LOCKED_LOCALLY.equals(property)) {
result = isLockedLocally(cdoObject);
} else if (IS_LOCKED_REMOTELY.equals(property)) {
result = isLockedRemotely(cdoObject);
} else if (IS_CONFLICTED.equals(property)) {
result = isConflicted(cdoObject);
}
}
return result;
}
private boolean canLock(CDOObject object) {
boolean result = CDOUtils.isLockable(object);
if (result) {
DawnState state = CDOStateAdapter.getState(object);
result = (state != DawnState.LOCKED_LOCALLY)
&& (state != DawnState.LOCKED_REMOTELY);
}
return result;
}
private boolean isLockedLocally(CDOObject object) {
return CDOStateAdapter.getState(object) == DawnState.LOCKED_LOCALLY;
}
private boolean isLockedRemotely(CDOObject object) {
return CDOStateAdapter.getState(object) == DawnState.LOCKED_REMOTELY;
}
private boolean isConflicted(CDOObject object) {
return CDOStateAdapter.getState(object) == DawnState.CONFLICT;
}
}
|