| /******************************************************************************* |
| * Copyright (c) 2014-2015 Red Hat Inc., and others |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Mickael Istria (Red Hat Inc.) - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.ui.internal.wizards.datatransfer; |
| |
| import java.util.HashSet; |
| import java.util.Set; |
| |
| import org.eclipse.core.commands.AbstractHandler; |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.IAdaptable; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.swt.widgets.Shell; |
| import org.eclipse.ui.IWorkingSet; |
| import org.eclipse.ui.PlatformUI; |
| |
| public class ConfigureProjectHandler extends AbstractHandler { |
| |
| @Override |
| public Object execute(ExecutionEvent arg0) throws ExecutionException { |
| IProject project = null; |
| ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); |
| if (selection instanceof IStructuredSelection) { |
| Object item = ((IStructuredSelection)selection).getFirstElement(); |
| if (item instanceof IProject) { |
| project = (IProject)item; |
| } else if (item instanceof IAdaptable) { |
| project = ((IAdaptable)item).getAdapter(IProject.class); |
| } |
| } |
| if (project == null) { |
| return null; |
| } |
| Set<IWorkingSet> workingSets = new HashSet<>(); |
| for (IWorkingSet workingSet : PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets()) { |
| for (IAdaptable element : workingSet.getElements()) { |
| if (project.getAdapter(element.getClass()) == element) { |
| workingSets.add(workingSet); |
| } |
| } |
| } |
| Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| EasymportJob job = new EasymportJob(project.getLocation().toFile(), workingSets, true); |
| EasymportJobReportDialog dialog = new EasymportJobReportDialog(shell, job); |
| job.schedule(); |
| return dialog.open(); |
| } |
| |
| } |