blob: 9311c4cc0052cc075f6fe64be30ef551243eb8a8 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.commandHandlers;
import java.util.List;
import java.util.logging.Level;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osee.framework.db.connection.DbTransaction;
import org.eclipse.osee.framework.db.connection.OseeConnection;
import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.plugin.core.util.Jobs;
import org.eclipse.osee.framework.skynet.core.access.AccessControlManager;
import org.eclipse.osee.framework.skynet.core.access.PermissionEnum;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.plugin.util.CommandHandler;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
import org.eclipse.ui.PlatformUI;
/**
* @author Jeff C. Phillips
*/
public class PurgeArtifactHandler extends CommandHandler {
private List<Artifact> artifacts;
/*
* (non-Javadoc)
*
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (MessageDialog.openConfirm(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
"Confirm Artifact Purge ",
" Are you sure you want to purge this artifact, all of " + "its children and all history associated with these artifacts from the database ?")) {
Job job = new Job("Purge artifact") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
IStatus toReturn = Status.CANCEL_STATUS;
monitor.beginTask("Purge artifact", artifacts.size());
try {
new DbTransaction() {
@Override
protected void handleTxWork(OseeConnection connection) throws OseeCoreException {
for (Artifact artifactToPurge : artifacts) {
monitor.setTaskName("Purge: " + artifactToPurge.getDescriptiveName());
artifactToPurge.purgeFromBranch(connection);
monitor.worked(1);
}
}
}.execute();
toReturn = Status.OK_STATUS;
} catch (Exception ex) {
OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
toReturn = new Status(Status.ERROR, SkynetGuiPlugin.PLUGIN_ID, -1, ex.getMessage(), ex);
} finally {
monitor.done();
}
return toReturn;
}
};
Jobs.startJob(job);
}
return null;
}
@Override
public boolean isEnabledWithException() throws OseeCoreException {
if (PlatformUI.getWorkbench().isClosing()) {
return false;
}
boolean isEnabled = false;
ISelectionProvider selectionProvider =
AWorkbench.getActivePage().getActivePart().getSite().getSelectionProvider();
if (selectionProvider != null && selectionProvider.getSelection() instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selectionProvider.getSelection();
artifacts = Handlers.getArtifactsFromStructuredSelection(structuredSelection);
isEnabled =
AccessControlManager.isOseeAdmin() && AccessControlManager.getInstance().checkObjectListPermission(
artifacts, PermissionEnum.WRITE);
}
return isEnabled;
}
}