1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
.importtrace
;
15 import java
.lang
.reflect
.InvocationTargetException
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.SubMonitor
;
21 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
22 import org
.eclipse
.jface
.wizard
.IWizard
;
23 import org
.eclipse
.jface
.wizard
.IWizardPage
;
24 import org
.eclipse
.jface
.wizard
.ProgressMonitorPart
;
25 import org
.eclipse
.jface
.wizard
.WizardDialog
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Shell
;
31 * Non-modal wizard allows background jobs to work in tandem with modal jobs.
33 * @author Matthew Khouzam
36 public class NonModalWizardDialog
extends WizardDialog
{
38 private ProgressMonitorPart fProgressMonitor
;
39 private IWizardPage fWizardPage
;
40 private List
<HelperThread
> fHelpers
= new ArrayList
<HelperThread
>();
43 * Creates a new non modal wizard dialog for the given wizard.
48 * the wizard this dialog is working on
50 public NonModalWizardDialog(Shell parentShell
, IWizard newWizard
) {
51 super(parentShell
, newWizard
);
55 * Copy constructor (be careful)
60 public NonModalWizardDialog(WizardDialog wiz
) {
61 super(wiz
.getShell(), wiz
.getCurrentPage().getWizard());
65 public boolean close() {
66 for(HelperThread t
: fHelpers
){
69 for(HelperThread t
: fHelpers
){
72 } catch (InterruptedException e
) {
78 * Gets the progress monitor, can be null
80 * @return a progress monitor that can be null
82 public IProgressMonitor
getMonitor() {
83 return super.getProgressMonitor();
87 public void updateButtons() {
88 super.updateButtons();
89 if (fProgressMonitor
!= null) {
90 fProgressMonitor
.setVisible(this.getCurrentPage().equals(fWizardPage
));
91 fProgressMonitor
.getMonitor();
96 * Background job to run
99 * the page to display the job on
101 * the runnable that is a background job
103 public void backgroundRun(IWizardPage pageForJob
, IRunnableWithProgress runnable
) {
104 // create progress monitor;
105 fWizardPage
= pageForJob
;
106 IProgressMonitor x
= getProgressMonitor();
107 SubMonitor y
= SubMonitor
.convert(x
);
108 // make a new thread with the runnable
109 HelperThread h
= new HelperThread(runnable
, y
);
117 protected ProgressMonitorPart
createProgressMonitorPart(Composite composite
, GridLayout pmlayout
) {
118 fProgressMonitor
= new ProgressMonitorPart(composite
, pmlayout
);
119 return fProgressMonitor
;
122 private class HelperThread
extends Thread
{
123 private IRunnableWithProgress runnable
;
124 private IProgressMonitor monitor
;
126 public HelperThread(IRunnableWithProgress i
, IProgressMonitor s
) {
134 runnable
.run(monitor
);
135 } catch (InvocationTargetException e
) {
137 } catch (InterruptedException e
) {