Skip to main content
summaryrefslogtreecommitdiffstats
blob: fd62b02ccff1c8bd16420230b528a0f5b1827a50 (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
/******************************************************************************
 * Copyright (c) 2008 BEA 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:
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
 *    Oracle - copied and modified from org.eclipse.wst.common.project.facet.core.internal.FacetedProjectPropertyTester
 ******************************************************************************/
package org.eclipse.jpt.jpa.core.internal;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;

public class JpaTester extends PropertyTester {
	
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
		if (!property.equals("projectFacet")) { //$NON-NLS-1$
			return false;
		}
        if (receiver instanceof IJavaElement) {
        	IProject project = ((IJavaElement) receiver).getResource().getProject();        	
            if (project != null) {

                String val = (String) expectedValue;
                int colon = val.indexOf( ':' );                
                String facetID;
                String facetVer;
                if( colon == -1 || colon == val.length() - 1 )  {
                    facetID = val;
                    facetVer = null;
                } else {
                    facetID = val.substring( 0, colon );
                    facetVer = val.substring( colon + 1 );
                }            	
            	try {            		
            		return FacetedProjectFramework.hasProjectFacet( project, facetID, facetVer );            		
				} catch (CoreException e) {
					JptJpaCorePlugin.log(e.getStatus());
					return false;
				}
            }
        }     
        return false;
	}		
}

Back to the top