blob: cd9de094fcdebb341338a268c3a556b5f064f027 (
plain) (
blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package org.eclipse.cdt.make.ui.views;
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.SelectionListenerAction;
public class DeleteTargetAction extends SelectionListenerAction {
Shell shell;
IResource resource;
public DeleteTargetAction(Shell shell) {
super("Delete Build Target");
this.shell = shell;
setToolTipText("Delete Build Target");
MakeUIImages.setImageDescriptors(this, "tool16", MakeUIImages.IMG_TOOLS_MAKE_TARGET_DELETE);
}
/**
* Asks the user to confirm a delete operation.
*
* @return <code>true</code> if the user says to go ahead, and <code>false</code>
* if the deletion should be abandoned
*/
boolean confirmDelete() {
List targets = getTargetsToDelete();
String title;
String msg;
if (targets.size() == 1) {
title = "Confirm Target Deletion";
IMakeTarget target = (IMakeTarget) targets.get(0);
msg = MessageFormat.format("Are you sure you want to delete ''{0}''?", new Object[] { target.getName()});
} else {
title = "Confirm Multiple Target Deletion";
msg = MessageFormat.format("Are you sure you want to delete these {0} targets?", new Object[] { new Integer(targets.size())});
}
return MessageDialog.openQuestion(shell, title, msg);
}
public void run() {
if (canDelete() && confirmDelete() == false)
return;
}
protected boolean updateSelection(IStructuredSelection selection) {
return super.updateSelection(selection) && canDelete();
}
/**
* @return
*/
private List getTargetsToDelete() {
return getStructuredSelection().toList();
}
/**
* @return
*/
private boolean canDelete() {
List elements = getStructuredSelection().toList();
if (elements.size() > 0) {
Iterator iterator = elements.iterator();
while (iterator.hasNext()) {
if (!(iterator.next() instanceof IMakeTarget)) {
return false;
}
}
return true;
}
return false;
}
}
|