~vil/pydev/upstream

« back to all changes in this revision

Viewing changes to org.python.pydev/src/org/python/pydev/utils/ProgressOperation.java

  • Committer: Vladimír Lapáček
  • Date: 2006-08-30 18:38:44 UTC
  • Revision ID: vladimir.lapacek@gmail.com-20060830183844-f4d82c1239a7770a
Initial import of upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on Oct 18, 2004
 
3
 *
 
4
 * @author Fabio Zadrozny
 
5
 */
 
6
package org.python.pydev.utils;
 
7
 
 
8
import java.lang.reflect.InvocationTargetException;
 
9
 
 
10
import org.eclipse.core.runtime.CoreException;
 
11
import org.eclipse.core.runtime.IProgressMonitor;
 
12
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
 
13
import org.eclipse.jface.operation.IRunnableWithProgress;
 
14
import org.eclipse.swt.widgets.Shell;
 
15
import org.eclipse.ui.actions.WorkspaceModifyOperation;
 
16
 
 
17
/**
 
18
 * Helper class for executing an action and showing its progress.
 
19
 * 
 
20
 * @author Fabio Zadrozny
 
21
 */
 
22
public class ProgressOperation extends WorkspaceModifyOperation {
 
23
    private final ProgressAction action;
 
24
 
 
25
    public IProgressMonitor monitor;
 
26
    public int estimatedTaskUnits = 10000;
 
27
 
 
28
    public ProgressOperation(ProgressAction action) {
 
29
        super();
 
30
        this.action = action;
 
31
    }
 
32
 
 
33
    protected void execute(IProgressMonitor monitor) throws CoreException,
 
34
            InvocationTargetException, InterruptedException {
 
35
 
 
36
        try {
 
37
            this.monitor = monitor;
 
38
            action.monitor = monitor;
 
39
            monitor.beginTask("Action being executed...", estimatedTaskUnits);
 
40
            action.run();
 
41
            monitor.done();
 
42
        } catch (Exception e) {
 
43
            e.printStackTrace();
 
44
        }
 
45
 
 
46
    }
 
47
    
 
48
    /**
 
49
     * @param shell
 
50
     * 
 
51
     */
 
52
    public static void startAction(Shell shell, ProgressAction action) {
 
53
        ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(
 
54
                shell);
 
55
        monitorDialog.setBlockOnOpen(false);
 
56
        try {
 
57
            IRunnableWithProgress operation = new ProgressOperation(action);
 
58
            monitorDialog.run(false, false, operation);
 
59
            // Perform the action
 
60
        } catch (InvocationTargetException e) {
 
61
            e.printStackTrace();
 
62
        } catch (InterruptedException e) {
 
63
            e.printStackTrace();
 
64
        }
 
65
 
 
66
    }
 
67
}
 
68
 
 
69