org.symbian.tools.mtw.ui/src/org/symbian/tools/mtw/ui/deployment/DeployWizard.java
changeset 461 7a8f9fa8d278
parent 460 c0bff5ed874c
child 462 cdc4995b1677
equal deleted inserted replaced
460:c0bff5ed874c 461:7a8f9fa8d278
     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.mtw.ui.deployment;
       
    20 
       
    21 import java.lang.reflect.InvocationTargetException;
       
    22 
       
    23 import org.eclipse.core.runtime.CoreException;
       
    24 import org.eclipse.core.runtime.IProgressMonitor;
       
    25 import org.eclipse.core.runtime.IStatus;
       
    26 import org.eclipse.core.runtime.jobs.ISchedulingRule;
       
    27 import org.eclipse.core.runtime.jobs.Job;
       
    28 import org.eclipse.core.runtime.jobs.MultiRule;
       
    29 import org.eclipse.jface.operation.IRunnableWithProgress;
       
    30 import org.eclipse.jface.wizard.Wizard;
       
    31 import org.eclipse.ui.statushandlers.StatusManager;
       
    32 import org.symbian.tools.mtw.core.MTWCore;
       
    33 import org.symbian.tools.mtw.core.projects.IMTWProject;
       
    34 import org.symbian.tools.mtw.core.runtimes.IPackager;
       
    35 import org.symbian.tools.mtw.internal.deployment.DeployWizardContext;
       
    36 import org.symbian.tools.mtw.internal.deployment.DeploymentTargetWizardPage;
       
    37 import org.symbian.tools.mtw.internal.deployment.DeploymentTargetWrapper;
       
    38 import org.symbian.tools.mtw.ui.MTWCoreUI;
       
    39 import org.symbian.tools.mtw.ui.ProjectMemo;
       
    40 
       
    41 public final class DeployWizard extends Wizard {
       
    42     private final DeployWizardContext context;
       
    43     private final IMTWProject project;
       
    44 
       
    45     public DeployWizard(IMTWProject project) {
       
    46         this.project = project;
       
    47         setNeedsProgressMonitor(true);
       
    48         setWindowTitle("Deploy WRT Application");
       
    49         context = new DeployWizardContext(project);
       
    50     }
       
    51 
       
    52     @Override
       
    53     public void addPages() {
       
    54         addPage(new DeploymentTargetWizardPage(context, MTWCoreUI.getMemo(project)));
       
    55     }
       
    56 
       
    57     @Override
       
    58     public boolean performFinish() {
       
    59         final DeploymentTargetWrapper target = context.getTarget();
       
    60         if (target.getType().isLongRunning()) {
       
    61             DeployJob job = new DeployJob(context.getProject(), target);
       
    62             job.schedule();
       
    63             return true;
       
    64         } else {
       
    65             final IStatus[] retval = new IStatus[1];
       
    66             try {
       
    67                 getContainer().run(false, true, new IRunnableWithProgress() {
       
    68                     public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
       
    69                         retval[0] = doDeploy(target, context.getProject(), monitor);
       
    70                     }
       
    71                 });
       
    72             } catch (InvocationTargetException e) {
       
    73                 MTWCoreUI.log(e);
       
    74             } catch (InterruptedException e) {
       
    75                 MTWCoreUI.log(e);
       
    76             }
       
    77             switch (retval[0].getSeverity()) {
       
    78             case IStatus.ERROR:
       
    79                 StatusManager.getManager().handle(retval[0], StatusManager.SHOW | StatusManager.BLOCK);
       
    80                 return false;
       
    81             case IStatus.WARNING:
       
    82                 StatusManager.getManager().handle(retval[0], StatusManager.SHOW | StatusManager.BLOCK);
       
    83             default:
       
    84                 return true;
       
    85             }
       
    86         }
       
    87     }
       
    88 
       
    89     @Override
       
    90     public boolean needsPreviousAndNextButtons() {
       
    91         return false;
       
    92     }
       
    93 
       
    94     private IStatus doDeploy(DeploymentTargetWrapper target, IMTWProject project, IProgressMonitor monitor) {
       
    95         IStatus status;
       
    96         try {
       
    97             IPackager packager = MTWCore.getDefault().getRuntimesManager().getPackager(project);
       
    98             status = target.deploy(project, packager, monitor);
       
    99         } catch (CoreException e) {
       
   100             status = e.getStatus();
       
   101         }
       
   102         ProjectMemo memo = MTWCoreUI.getMemo(project);
       
   103         memo.setDeploymentTarget(target.getProviderId(), target);
       
   104         return status;
       
   105     }
       
   106 
       
   107     private final class DeployJob extends Job {
       
   108         private final DeploymentTargetWrapper target;
       
   109         private final IMTWProject project;
       
   110 
       
   111         private DeployJob(IMTWProject project, DeploymentTargetWrapper deploymentTarget) {
       
   112             super(String.format("Deploying %s to %s", project.getName(), deploymentTarget.getName()));
       
   113             ISchedulingRule rule = deploymentTarget.getType().getSchedulingRule(deploymentTarget.getActualTarget());
       
   114             if (rule != null) {
       
   115                 rule = MultiRule.combine(rule, project.getProject());
       
   116             } else {
       
   117                 rule = project.getProject();
       
   118             }
       
   119             setRule(rule);
       
   120             setUser(true);
       
   121             this.project = project;
       
   122             this.target = deploymentTarget;
       
   123         }
       
   124 
       
   125         public IStatus run(IProgressMonitor monitor) {
       
   126             final IStatus status = doDeploy(target, project, monitor);
       
   127             if (status.getSeverity() != IStatus.ERROR && status.getSeverity() != IStatus.WARNING) {
       
   128                 StatusManager.getManager().handle(status, StatusManager.SHOW);
       
   129             }
       
   130             return status;
       
   131         }
       
   132 
       
   133     }
       
   134 }