blob: 0aa5cffd5f5736d7f33eccef14391f990c491060 (
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
|
/*****************************************************************************
* Copyright (c) 2014 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:
* Patrick Tessier (CEA LIST) - Initial API and implementation
/*****************************************************************************/
package org.eclipse.papyrus.infra.constraints.constraints;
import org.eclipse.papyrus.infra.constraints.Activator;
import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
import org.eclipse.papyrus.infra.constraints.constraints.JavaQuery.FalseQuery;
import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
/**
* This constraint allows to define a Java Query (without parameters) without
* defining it in an environment file.
*
* The constraint takes one parameter ("className"), which defines the
* qualified name of the Java class used to implement the constraint.
*
* The Java class must implement the {@link JavaQuery} interface
*
* @author Camille Letavernier
*/
public class JavaQueryConstraint extends AbstractConstraint {
/**
* The Java Class property
*/
public final static String QUERY_CLASS_NAME_PROPERTY = "className"; //$NON-NLS-1$
private JavaQuery query = new FalseQuery();
@Override
protected void setDescriptor(SimpleConstraint descriptor) {
String queryClassName = getValue(QUERY_CLASS_NAME_PROPERTY);
query = ClassLoaderHelper.newInstance(queryClassName, JavaQuery.class);
if (query == null) {
Activator.log.warn("Cannot load the JavaQuery for this constraint : " + descriptor.getName());
}
}
@Override
public boolean match(Object selection) {
return query.match(selection);
}
@Override
protected boolean equivalent(Constraint constraint) {
if (constraint instanceof JavaQueryConstraint) {
return ((JavaQueryConstraint) constraint).query.getClass().equals(query.getClass());
}
return false;
}
}
|