~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindExportWizard.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2009 Red Hat, Inc.
 
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
 *    Elliott Baron <ebaron@redhat.com> - initial API and implementation
 
10
 *******************************************************************************/ 
 
11
package org.eclipse.linuxtools.internal.valgrind.launch;
 
12
 
 
13
import java.io.File;
 
14
import java.io.FileInputStream;
 
15
import java.io.FileOutputStream;
 
16
import java.io.IOException;
 
17
import java.lang.reflect.InvocationTargetException;
 
18
import java.nio.channels.FileChannel;
 
19
 
 
20
import org.eclipse.core.runtime.IPath;
 
21
import org.eclipse.core.runtime.IProgressMonitor;
 
22
import org.eclipse.core.runtime.IStatus;
 
23
import org.eclipse.core.runtime.Status;
 
24
import org.eclipse.jface.dialogs.ErrorDialog;
 
25
import org.eclipse.jface.operation.IRunnableWithProgress;
 
26
import org.eclipse.jface.viewers.IStructuredSelection;
 
27
import org.eclipse.jface.wizard.Wizard;
 
28
import org.eclipse.linuxtools.internal.valgrind.core.PluginConstants;
 
29
import org.eclipse.osgi.util.NLS;
 
30
import org.eclipse.ui.IExportWizard;
 
31
import org.eclipse.ui.IWorkbench;
 
32
import org.eclipse.ui.PlatformUI;
 
33
import org.eclipse.ui.progress.IProgressService;
 
34
 
 
35
public class ValgrindExportWizard extends Wizard implements IExportWizard {
 
36
 
 
37
        protected ValgrindExportWizardPage exportPage;
 
38
 
 
39
        @Override
 
40
        public boolean performFinish() {
 
41
                final File[] logs = exportPage.getSelectedFiles();
 
42
                final IPath outputPath = exportPage.getOutputPath();
 
43
                
 
44
                IProgressService ps = PlatformUI.getWorkbench().getProgressService();
 
45
                try {
 
46
                        ps.busyCursorWhile(new IRunnableWithProgress() {
 
47
 
 
48
                                public void run(IProgressMonitor monitor)
 
49
                                throws InvocationTargetException, InterruptedException {
 
50
                                        if (logs.length > 0) {
 
51
                                                File outputDir = outputPath.toFile();
 
52
                                                monitor.beginTask(NLS.bind(Messages.getString("ValgrindExportWizard.Export_task"), outputPath.toOSString()), logs.length); //$NON-NLS-1$
 
53
                                                FileChannel inChan = null;
 
54
                                                FileChannel outChan = null;
 
55
                                                try {
 
56
                                                        for (File log : logs) {
 
57
                                                                monitor.subTask(NLS.bind(Messages.getString("ValgrindExportWizard.Export_subtask"), log.getName())); //$NON-NLS-1$
 
58
 
 
59
                                                                File outLog = new File(outputDir, log.getName());
 
60
                                                                inChan = new FileInputStream(log).getChannel();
 
61
                                                                outChan = new FileOutputStream(outLog).getChannel();
 
62
                                                                
 
63
                                                                outChan.transferFrom(inChan, 0, inChan.size());
 
64
                                                                
 
65
                                                                inChan.close();
 
66
                                                                outChan.close();
 
67
                                                                
 
68
                                                                monitor.worked(1);
 
69
                                                        }
 
70
                                                } catch (IOException e) {
 
71
                                                        throw new InvocationTargetException(e);
 
72
                                                } finally {
 
73
                                                        try {
 
74
                                                                if (inChan != null && inChan.isOpen()) {
 
75
                                                                        inChan.close();
 
76
                                                                }
 
77
                                                                if (outChan != null && outChan.isOpen()) {
 
78
                                                                        outChan.close();
 
79
                                                                }
 
80
                                                        } catch (IOException e) {
 
81
                                                                e.printStackTrace();
 
82
                                                        }
 
83
                                                        monitor.done();
 
84
                                                }
 
85
                                        }
 
86
                                }
 
87
 
 
88
                        });
 
89
 
 
90
                } catch (InvocationTargetException e) {
 
91
                        IStatus status = new Status(IStatus.ERROR, PluginConstants.LAUNCH_PLUGIN_ID, Messages.getString("ValgrindExportWizard.Export_fail"), e); //$NON-NLS-1$
 
92
                        ErrorDialog.openError(getShell(), ExportWizardConstants.WIZARD_TITLE, null, status);
 
93
                        e.printStackTrace();
 
94
                        return false;
 
95
                } catch (InterruptedException e) {
 
96
                }
 
97
 
 
98
                return true;
 
99
        }
 
100
 
 
101
        public void init(IWorkbench workbench, IStructuredSelection selection) {
 
102
                setWindowTitle(ExportWizardConstants.WIZARD_WINDOW_TITLE);
 
103
                exportPage = getWizardPage();
 
104
                exportPage.setDescription(ExportWizardConstants.WIZARD_DESCRIPTION);
 
105
                addPage(exportPage);
 
106
        }
 
107
 
 
108
        protected ValgrindExportWizardPage getWizardPage() {
 
109
                return new ValgrindExportWizardPage(Messages.getString("ValgrindExportWizard.Page_name"), ExportWizardConstants.WIZARD_TITLE, null); //$NON-NLS-1$
 
110
        }
 
111
 
 
112
}