|
1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.tmw.core.internal.projects; |
|
20 |
|
21 import org.eclipse.core.expressions.EvaluationContext; |
|
22 import org.eclipse.core.expressions.EvaluationResult; |
|
23 import org.eclipse.core.expressions.Expression; |
|
24 import org.eclipse.core.expressions.ExpressionConverter; |
|
25 import org.eclipse.core.resources.IProject; |
|
26 import org.eclipse.core.runtime.CoreException; |
|
27 import org.eclipse.core.runtime.IConfigurationElement; |
|
28 import org.symbian.tools.tmw.core.TMWCore; |
|
29 import org.symbian.tools.tmw.core.projects.IMTWProject; |
|
30 import org.symbian.tools.tmw.core.projects.IMTWProjectProvider; |
|
31 |
|
32 public class ProjectProvider implements IMTWProjectProvider { |
|
33 private final IConfigurationElement element; |
|
34 private final Expression expression; |
|
35 private IMTWProjectProvider provider; |
|
36 |
|
37 public ProjectProvider(IConfigurationElement element) throws CoreException { |
|
38 this.element = element; |
|
39 IConfigurationElement[] children = element.getChildren("enablement"); |
|
40 if (children.length == 1) { |
|
41 expression = ExpressionConverter.getDefault().perform(children[0]); |
|
42 } else { |
|
43 expression = null; |
|
44 if (children.length > 1) { |
|
45 TMWCore.log( |
|
46 "Project extension in plugin %s has several <enablement> elements. All expressions will be ignored.", |
|
47 element.getNamespaceIdentifier()); |
|
48 } |
|
49 } |
|
50 } |
|
51 |
|
52 public IMTWProject create(IProject project) { |
|
53 return getProvider().create(project); |
|
54 } |
|
55 |
|
56 private IMTWProjectProvider getProvider() { |
|
57 if (provider == null) { |
|
58 try { |
|
59 provider = (IMTWProjectProvider) element.createExecutableExtension("class"); |
|
60 } catch (CoreException e) { |
|
61 throw new RuntimeException(e); |
|
62 } |
|
63 } |
|
64 return provider; |
|
65 } |
|
66 |
|
67 public boolean isSupportedProject(final IProject project) { |
|
68 try { |
|
69 final EvaluationResult result = expression.evaluate(new EvaluationContext(null, project)); |
|
70 if (!EvaluationResult.FALSE.equals(result)) { |
|
71 return getProvider().isSupportedProject(project); |
|
72 } |
|
73 } catch (CoreException e) { |
|
74 TMWCore.log(null, e); |
|
75 } |
|
76 return false; |
|
77 } |
|
78 } |