org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/NewApplicationWizard.java
changeset 463 aea4c83725d8
child 465 87920e15f8eb
equal deleted inserted replaced
462:cdc4995b1677 463:aea4c83725d8
       
     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.Collections;
       
    22 import java.util.Set;
       
    23 
       
    24 import org.eclipse.core.databinding.DataBindingContext;
       
    25 import org.eclipse.core.runtime.IPath;
       
    26 import org.eclipse.jface.viewers.IStructuredSelection;
       
    27 import org.eclipse.jface.wizard.IWizardPage;
       
    28 import org.eclipse.ui.INewWizard;
       
    29 import org.eclipse.ui.IWorkbench;
       
    30 import org.eclipse.wst.common.project.facet.core.IFacetedProject;
       
    31 import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
       
    32 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
       
    33 import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
       
    34 import org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard;
       
    35 import org.symbian.tools.tmw.core.TMWCore;
       
    36 import org.symbian.tools.tmw.core.projects.IFProjSupport;
       
    37 
       
    38 /**
       
    39  * @author Eugene Ostroukhov (eugeneo@symbian.org)
       
    40  */
       
    41 public final class NewApplicationWizard extends ModifyFacetedProjectWizard implements INewWizard {
       
    42     private final DataBindingContext databindingContext = new DataBindingContext();
       
    43     private NewApplicationDetailsWizardPage firstPage;
       
    44     private IStructuredSelection selection;
       
    45     private final WizardContext wizardContext = new WizardContext();
       
    46     private IWorkbench workbench;
       
    47     private FacetsSelectionPage facetsPage;
       
    48     private NewApplicationTemplateWizardPage templatesPage;
       
    49 
       
    50     public NewApplicationWizard() {
       
    51         setShowFacetsSelectionPage(false);
       
    52     }
       
    53 
       
    54     public void addPages() {
       
    55         this.firstPage = createFirstPage();
       
    56         addPage(this.firstPage);
       
    57         final IFacetedProject project = getFacetedProject();
       
    58         final Set<IProjectFacetVersion> facets;
       
    59         if (project == null) {
       
    60             facets = Collections.emptySet();
       
    61         } else {
       
    62             facets = project.getProjectFacets();
       
    63         }
       
    64         facetsPage = new FacetsSelectionPage(facets, getFacetedProjectWorkingCopy());
       
    65         addPage(facetsPage);
       
    66         templatesPage = new NewApplicationTemplateWizardPage(wizardContext, databindingContext);
       
    67         addPage(templatesPage);
       
    68         super.addPages();
       
    69     }
       
    70 
       
    71     public boolean canFinish() {
       
    72         return this.firstPage.isPageComplete() && super.canFinish();
       
    73     }
       
    74 
       
    75     protected NewApplicationDetailsWizardPage createFirstPage() {
       
    76         firstPage = new NewApplicationDetailsWizardPage(wizardContext, databindingContext);
       
    77         return firstPage;
       
    78     }
       
    79 
       
    80     @Override
       
    81     public IWizardPage getNextPage(final IWizardPage page) {
       
    82         if (page == this.firstPage) {
       
    83             final IFacetedProjectWorkingCopy fpjwc = getFacetedProjectWorkingCopy();
       
    84             fpjwc.setProjectName(getProjectName());
       
    85             fpjwc.setProjectLocation(getProjectLocation());
       
    86             final IFProjSupport fprojSupport = TMWCore.getFProjSupport();
       
    87             IRuntime runtime = fprojSupport.getRuntime(wizardContext.getRuntime());
       
    88             fpjwc.setTargetedRuntimes(Collections.singleton(runtime));
       
    89             fpjwc.setPrimaryRuntime(runtime);
       
    90             fpjwc.setProjectFacets(fprojSupport.getFixedFacetsVersions(wizardContext.getRuntime()));
       
    91             fpjwc.setFixedProjectFacets(fprojSupport.getFixedFacets(wizardContext.getRuntime()));
       
    92             fpjwc.setProjectFacetActionConfig(fprojSupport.getTMWFacet(), wizardContext);
       
    93         }
       
    94 
       
    95         IWizardPage nextPage = super.getNextPage(page);
       
    96         return nextPage;
       
    97     }
       
    98 
       
    99     public IWizardPage[] getPages() {
       
   100         final IWizardPage[] base = super.getPages();
       
   101         final IWizardPage[] pages = new IWizardPage[base.length + 3];
       
   102 
       
   103         pages[0] = this.firstPage;
       
   104         pages[1] = this.templatesPage;
       
   105         pages[2] = this.facetsPage;
       
   106         System.arraycopy(base, 0, pages, 2, base.length);
       
   107 
       
   108         return pages;
       
   109     }
       
   110 
       
   111     protected IPath getProjectLocation() {
       
   112         return firstPage.getLocationPath();
       
   113     }
       
   114 
       
   115     protected String getProjectName() {
       
   116         return wizardContext.getProjectName();
       
   117     }
       
   118 
       
   119     /**
       
   120      * Returns the selection that this wizard was launched from.
       
   121      * 
       
   122      * @return the selection that this wizard was launched from
       
   123      * @since 1.4
       
   124      */
       
   125 
       
   126     public IStructuredSelection getSelection() {
       
   127         return this.selection;
       
   128     }
       
   129 
       
   130     /**
       
   131      * Returns the workbench that this wizard belongs to.
       
   132      * 
       
   133      * @return the workbench that this wizard belongs to
       
   134      * @since 1.4
       
   135      */
       
   136 
       
   137     public IWorkbench getWorkbench() {
       
   138         return this.workbench;
       
   139     }
       
   140 
       
   141     public void init(final IWorkbench workbench, final IStructuredSelection selection) {
       
   142         this.workbench = workbench;
       
   143         this.selection = selection;
       
   144     }
       
   145 
       
   146     public boolean performFinish() {
       
   147         super.performFinish();
       
   148         return true;
       
   149     }
       
   150 }