comparison org.eclipse.jface/src/org/eclipse/jface/operation/IRunnableWithProgress.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.jface.operation.IRunnableWithProgress;
14
15 import org.eclipse.core.runtime.IProgressMonitor;
16
17 import java.lang.all;
18
19 import tango.core.Tuple;
20 import tango.core.Traits;
21
22 /**
23 * The <code>IRunnableWithProgress</code> interface should be implemented by any
24 * class whose instances are intended to be executed as a long-running operation.
25 * Long-running operations are typically presented at the UI via a modal dialog
26 * showing a progress indicator and a Cancel button.
27 * The class must define a <code>run</code> method that takes a progress monitor.
28 * The <code>run</code> method is usually not invoked directly, but rather by
29 * passing the <code>IRunnableWithProgress</code> to the <code>run</code> method of
30 * an <code>IRunnableContext</code>, which provides the UI for the progress monitor
31 * and Cancel button.
32 *
33 * @see IRunnableContext
34 */
35 public interface IRunnableWithProgress {
36 /**
37 * Runs this operation. Progress should be reported to the given progress monitor.
38 * This method is usually invoked by an <code>IRunnableContext</code>'s <code>run</code> method,
39 * which supplies the progress monitor.
40 * A request to cancel the operation should be honored and acknowledged
41 * by throwing <code>InterruptedException</code>.
42 *
43 * @param monitor the progress monitor to use to display progress and receive
44 * requests for cancelation
45 * @exception InvocationTargetException if the run method must propagate a checked exception,
46 * it should wrap it inside an <code>InvocationTargetException</code>; runtime exceptions are automatically
47 * wrapped in an <code>InvocationTargetException</code> by the calling context
48 * @exception InterruptedException if the operation detects a request to cancel,
49 * using <code>IProgressMonitor.isCanceled()</code>, it should exit by throwing
50 * <code>InterruptedException</code>
51 *
52 * @see IRunnableContext#run
53 */
54 public void run(IProgressMonitor monitor);
55 }
56
57 class _DgIRunnableWithProgressT(Dg,T...) : IRunnableWithProgress {
58
59 alias ParameterTupleOf!(Dg) DgArgs;
60 static assert( is(DgArgs == Tuple!(T))
61 || is(DgArgs == Tuple!(IProgressMonitor,T)),
62 "Delegate args not correct" );
63
64 Dg dg;
65 T t;
66
67 private this( Dg dg, T t ){
68 this.dg = dg;
69 static if( T.length > 0 ){
70 this.t = t;
71 }
72 }
73
74 void run( IProgressMonitor pm ){
75 static if( is( typeof(dg(pm,t)))){
76 dg(pm,t);
77 }
78 else static if( is( typeof(dg(t)))){
79 dg(t);
80 }
81 else{
82 static assert( false, "Delegate type is incorrect for arguments supplied");
83 }
84 }
85 }
86
87 _DgIRunnableWithProgressT!(Dg,T) dgIRunnableWithProgress(Dg,T...)( Dg dg, T args ){
88 return new _DgIRunnableWithProgressT!(Dg,T)(dg,args);
89 }
90
91