org.symbian.tools.mtw.ui/src/org/symbian/tools/tmw/internal/util/OpenFilesRunnable.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 17 Aug 2010 13:40:28 -0700
changeset 466 129c94e78375
permissions -rw-r--r--
Project creation from the templates was implemented

/**
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Symbian Foundation - initial contribution.
 * Contributors:
 * Description:
 * Overview:
 * Details:
 * Platforms/Drives/Compatibility:
 * Assumptions/Requirement/Pre-requisites:
 * Failures and causes:
 */
package org.symbian.tools.tmw.internal.util;

import java.lang.reflect.InvocationTargetException;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.symbian.tools.tmw.ui.TMWCoreUI;

public class OpenFilesRunnable implements IRunnableWithProgress {
    private final IFile[] openFiles;

    public OpenFilesRunnable(Set<IFile> openFiles) {
        this.openFiles = openFiles.toArray(new IFile[openFiles.size()]);
    }

    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
        monitor.beginTask("Opening files in editors", openFiles.length);
        for (IFile file : openFiles) {
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            try {
                IDE.openEditor(page, file);
            } catch (PartInitException e) {
                TMWCoreUI.log(e);
            }
            monitor.worked(1);
        }
        monitor.done();
    }
}