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
9
* Elliott Baron <ebaron@redhat.com> - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.linuxtools.internal.valgrind.launch;
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;
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;
35
public class ValgrindExportWizard extends Wizard implements IExportWizard {
37
protected ValgrindExportWizardPage exportPage;
40
public boolean performFinish() {
41
final File[] logs = exportPage.getSelectedFiles();
42
final IPath outputPath = exportPage.getOutputPath();
44
IProgressService ps = PlatformUI.getWorkbench().getProgressService();
46
ps.busyCursorWhile(new IRunnableWithProgress() {
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;
56
for (File log : logs) {
57
monitor.subTask(NLS.bind(Messages.getString("ValgrindExportWizard.Export_subtask"), log.getName())); //$NON-NLS-1$
59
File outLog = new File(outputDir, log.getName());
60
inChan = new FileInputStream(log).getChannel();
61
outChan = new FileOutputStream(outLog).getChannel();
63
outChan.transferFrom(inChan, 0, inChan.size());
70
} catch (IOException e) {
71
throw new InvocationTargetException(e);
74
if (inChan != null && inChan.isOpen()) {
77
if (outChan != null && outChan.isOpen()) {
80
} catch (IOException e) {
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);
95
} catch (InterruptedException e) {
101
public void init(IWorkbench workbench, IStructuredSelection selection) {
102
setWindowTitle(ExportWizardConstants.WIZARD_WINDOW_TITLE);
103
exportPage = getWizardPage();
104
exportPage.setDescription(ExportWizardConstants.WIZARD_DESCRIPTION);
108
protected ValgrindExportWizardPage getWizardPage() {
109
return new ValgrindExportWizardPage(Messages.getString("ValgrindExportWizard.Page_name"), ExportWizardConstants.WIZARD_TITLE, null); //$NON-NLS-1$