1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/*******************************************************************************
* 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 org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osee.framework.access.AccessControlManager;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactPersistenceManager;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.ui.plugin.util.CommandHandler;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
import org.eclipse.swt.widgets.Display;
/**
* @author Jeff C. Phillips
*/
public class DeleteArtifactHandler extends CommandHandler {
private List<Artifact> artifacts;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!artifacts.isEmpty()) {
try {
MessageDialog dialog =
new MessageDialog(Display.getCurrent().getActiveShell(), "Confirm Artifact Deletion", null,
" Are you sure you want to delete this artifact and all of the default hierarchy children?",
MessageDialog.QUESTION, new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 1);
if (dialog.open() == 0) {
Artifact[] artifactsArray = artifacts.toArray(new Artifact[artifacts.size()]);
SkynetTransaction transaction =
new SkynetTransaction(artifactsArray[0].getBranch(), "Delete artifact handler");
ArtifactPersistenceManager.deleteArtifact(transaction, false, artifactsArray);
transaction.execute();
}
} catch (Exception ex) {
OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
}
}
return null;
}
@Override
public boolean isEnabledWithException(IStructuredSelection structuredSelection) throws OseeCoreException {
artifacts = Handlers.getArtifactsFromStructuredSelection(structuredSelection);
return AccessControlManager.checkObjectListPermission(artifacts, PermissionEnum.WRITE);
}
}
|