2
GanttProject is an opensource project management tool.
3
Copyright (C) 2011 GanttProject Team
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
package net.sourceforge.ganttproject.action;
21
import java.awt.Toolkit;
22
import java.awt.event.ActionEvent;
23
import java.awt.event.KeyEvent;
26
import javax.swing.AbstractAction;
27
import javax.swing.Action;
28
import javax.swing.ImageIcon;
29
import javax.swing.KeyStroke;
31
import net.sourceforge.ganttproject.GanttProject;
32
import net.sourceforge.ganttproject.gui.UIFacade;
33
import net.sourceforge.ganttproject.gui.UIFacade.Choice;
34
import net.sourceforge.ganttproject.language.GanttLanguage;
35
import net.sourceforge.ganttproject.resource.HumanResource;
36
import net.sourceforge.ganttproject.resource.HumanResourceManager;
37
import net.sourceforge.ganttproject.resource.ResourceContext;
40
* Action connected to the menu item for delete a resource
42
public class DeleteHumanAction extends ResourceAction {
43
private final UIFacade myUIFacade;
45
private final ResourceContext myContext;
47
private static final String ICON_URL = "icons/delete_16.gif";
49
private final int MENU_MASK = Toolkit.getDefaultToolkit()
50
.getMenuShortcutKeyMask();
52
private GanttProject myProjectFrame;
54
public DeleteHumanAction(HumanResourceManager hrManager,
55
ResourceContext context, GanttProject projectFrame, UIFacade uiFacade) {
57
myUIFacade = uiFacade;
58
myProjectFrame = projectFrame;
59
this.putValue(AbstractAction.NAME, GanttLanguage.getInstance()
60
.correctLabel(getLanguage().getText("deleteHuman")));
61
this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
62
KeyEvent.VK_J, MENU_MASK));
63
URL iconUrl = this.getClass().getClassLoader().getResource(ICON_URL);
64
if (iconUrl != null) {
65
this.putValue(Action.SMALL_ICON, new ImageIcon(iconUrl));
70
public void actionPerformed(ActionEvent event) {
71
final HumanResource[] context = getContext().getResources();
72
if (context.length > 0) {
73
final String message = getLanguage().getText("msg6") + " "
74
+ getDisplayName(context) + "?";
75
final String title = getLanguage().getText("question");
76
Choice choice = myUIFacade.showConfirmationDialog(message, title);
77
if (choice == Choice.YES) {
78
myUIFacade.getUndoManager().undoableEdit("Resource removed",
81
deleteResources(context);
82
getProjectFrame().repaint2();
89
private GanttProject getProjectFrame() {
90
return myProjectFrame;
93
private void deleteResources(HumanResource[] resources) {
94
for (HumanResource resource : resources) {
99
private String getDisplayName(HumanResource[] resources) {
100
if (resources.length == 1) {
101
return resources[0].toString();
103
StringBuffer result = new StringBuffer();
104
for (int i = 0; i < resources.length; i++) {
105
result.append(resources[i].toString());
106
if (i < resources.length - 1) {
110
return result.toString();
113
private ResourceContext getContext() {