org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/PageContributions.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Mon, 16 Aug 2010 16:23:25 -0700
changeset 465 87920e15f8eb
permissions -rw-r--r--
Added a way to contribute wizard pages for templates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
/**
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
 *
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
 * Symbian Foundation - initial contribution.
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
 * Contributors:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
 * Description:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
 * Overview:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
 * Details:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
 * Platforms/Drives/Compatibility:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
 * Failures and causes:
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
 */
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
package org.symbian.tools.tmw.internal.ui.wizard;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import java.util.LinkedList;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import java.util.List;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import java.util.Map;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import java.util.TreeMap;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
import org.eclipse.core.runtime.CoreException;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
import org.eclipse.core.runtime.IConfigurationElement;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
import org.eclipse.core.runtime.Platform;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
import org.symbian.tools.tmw.ui.TMWCoreUI;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
import org.symbian.tools.tmw.ui.project.INewApplicationWizardPage;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
public class PageContributions {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
    private Map<String, List<IConfigurationElement>> templatePages;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
    public INewApplicationWizardPage[] createPages(final String id) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
        if (templatePages == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
            walkExtensions();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
        final List<IConfigurationElement> pages = templatePages.get(id);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
        if (pages == null || pages.size() == 0) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
            return new INewApplicationWizardPage[0];
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
        final INewApplicationWizardPage[] newPages = new INewApplicationWizardPage[pages.size()];
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
        for (int i = 0; i < pages.size(); i++) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
            IConfigurationElement element = pages.get(i);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
            try {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
                newPages[i] = (INewApplicationWizardPage) element.createExecutableExtension("class");
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
            } catch (CoreException e) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
                TMWCoreUI.log(e);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
            }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
        return newPages;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
    private void walkExtensions() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    56
        final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
                TMWCoreUI.PLUGIN_ID, "wizardPages");
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    58
        templatePages = new TreeMap<String, List<IConfigurationElement>>();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
        for (IConfigurationElement element : elements) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
            final String id = element.getAttribute("template-id");
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
            List<IConfigurationElement> extensions = templatePages.get(id);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
            if (extensions == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
                extensions = new LinkedList<IConfigurationElement>();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
                templatePages.put(id, extensions);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
            }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
            extensions.add(element);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    69
}