plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/facets/FProjSupportImpl.java
changeset 470 d4809db37847
parent 463 aea4c83725d8
child 477 b616697678bf
equal deleted inserted replaced
469:4d198a32ac7d 470:d4809db37847
       
     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.facets;
       
    20 
       
    21 import java.util.HashSet;
       
    22 import java.util.Set;
       
    23 
       
    24 import org.eclipse.core.runtime.CoreException;
       
    25 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
       
    26 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
       
    27 import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
       
    28 import org.eclipse.wst.common.project.facet.core.VersionFormatException;
       
    29 import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
       
    30 import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
       
    31 import org.symbian.tools.tmw.core.projects.IFProjSupport;
       
    32 import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime;
       
    33 
       
    34 public final class FProjSupportImpl implements IFProjSupport {
       
    35     public IRuntime getRuntime(IMobileWebRuntime runtime) {
       
    36         return RuntimeManager.getRuntime(getRuntimeId(runtime));
       
    37     }
       
    38 
       
    39     public Set<IProjectFacet> getFixedFacets(IMobileWebRuntime runtime) {
       
    40         final Set<IProjectFacet> facets = new HashSet<IProjectFacet>();
       
    41         for (IProjectFacetVersion facetVersion : getFixedFacetsVersions(runtime)) {
       
    42             facets.add(facetVersion.getProjectFacet());
       
    43         }
       
    44         return facets;
       
    45     }
       
    46 
       
    47     private IProjectFacetVersion getFacet(String id, String version) {
       
    48         final IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(id);
       
    49         try {
       
    50             return version != null ? projectFacet.getVersion(version) : projectFacet.getLatestVersion();
       
    51         } catch (VersionFormatException e) {
       
    52             throw new RuntimeException(e);
       
    53         } catch (CoreException e) {
       
    54             throw new RuntimeException(e);
       
    55         }
       
    56     }
       
    57 
       
    58     public String getRuntimeId(IMobileWebRuntime runtime) {
       
    59         return runtime != null ? runtime.getId() + ":" + runtime.getVersion() : null;
       
    60     }
       
    61 
       
    62     public Set<IProjectFacetVersion> getFixedFacetsVersions(IMobileWebRuntime runtime) {
       
    63         final Set<IProjectFacetVersion> facets = new HashSet<IProjectFacetVersion>();
       
    64         facets.add(getFacet("wst.jsdt.web", null));
       
    65         facets.add(getFacet("tmw.core", null));
       
    66         //        facets.add(getFacet("wst.jsdt.web", "1.0"));
       
    67         return facets;
       
    68     }
       
    69 
       
    70     public IProjectFacet getTMWFacet() {
       
    71         return getFacet("tmw.core", null).getProjectFacet();
       
    72     }
       
    73 }