org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/PageContributions.java
changeset 465 87920e15f8eb
equal deleted inserted replaced
464:0b02f3d6f52c 465:87920e15f8eb
       
     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.internal.ui.wizard;
       
    20 
       
    21 import java.util.LinkedList;
       
    22 import java.util.List;
       
    23 import java.util.Map;
       
    24 import java.util.TreeMap;
       
    25 
       
    26 import org.eclipse.core.runtime.CoreException;
       
    27 import org.eclipse.core.runtime.IConfigurationElement;
       
    28 import org.eclipse.core.runtime.Platform;
       
    29 import org.symbian.tools.tmw.ui.TMWCoreUI;
       
    30 import org.symbian.tools.tmw.ui.project.INewApplicationWizardPage;
       
    31 
       
    32 public class PageContributions {
       
    33     private Map<String, List<IConfigurationElement>> templatePages;
       
    34 
       
    35     public INewApplicationWizardPage[] createPages(final String id) {
       
    36         if (templatePages == null) {
       
    37             walkExtensions();
       
    38         }
       
    39         final List<IConfigurationElement> pages = templatePages.get(id);
       
    40         if (pages == null || pages.size() == 0) {
       
    41             return new INewApplicationWizardPage[0];
       
    42         }
       
    43         final INewApplicationWizardPage[] newPages = new INewApplicationWizardPage[pages.size()];
       
    44         for (int i = 0; i < pages.size(); i++) {
       
    45             IConfigurationElement element = pages.get(i);
       
    46             try {
       
    47                 newPages[i] = (INewApplicationWizardPage) element.createExecutableExtension("class");
       
    48             } catch (CoreException e) {
       
    49                 TMWCoreUI.log(e);
       
    50             }
       
    51         }
       
    52         return newPages;
       
    53     }
       
    54 
       
    55     private void walkExtensions() {
       
    56         final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
       
    57                 TMWCoreUI.PLUGIN_ID, "wizardPages");
       
    58         templatePages = new TreeMap<String, List<IConfigurationElement>>();
       
    59         for (IConfigurationElement element : elements) {
       
    60             final String id = element.getAttribute("template-id");
       
    61             List<IConfigurationElement> extensions = templatePages.get(id);
       
    62             if (extensions == null) {
       
    63                 extensions = new LinkedList<IConfigurationElement>();
       
    64                 templatePages.put(id, extensions);
       
    65             }
       
    66             extensions.add(element);
       
    67         }
       
    68     }
       
    69 }