blob: db7e16232474522a645ed44fd01f46a18facbd35 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* 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:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.ide.tools.developer;
import java.util.Iterator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.slf4j.LoggerFactory;
public class UpdateArtifactVersions implements IObjectActionDelegate {
private static final org.slf4j.Logger log = LoggerFactory
.getLogger(UpdateArtifactVersions.class);
private ISelection selection;
public void run(IAction action) {
if (selection instanceof IStructuredSelection) {
for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
.hasNext();) {
Object element = it.next();
IProject project = null;
if (element instanceof IProject) {
project = (IProject) element;
} else if (element instanceof IAdaptable) {
project = (IProject) ((IAdaptable) element)
.getAdapter(IProject.class);
}
if (project != null) {
executeUpdate(project);
}
}
}
}
public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
public void executeUpdate(IProject project) {
try {
new ArtifactVersionUpdate().execute(project);
} catch (Exception e) {
log.error("{}", e);
ErrorDialog
.openError(
Display.getCurrent().getActiveShell(),
"Error",
e.toString(),
new Status(IStatus.ERROR,
"org.eclipse.osbp.ide.tools.developer", e
.toString(), e));
}
}
}