15
15
You should have received a copy of the GNU General Public License
16
16
along with this program; if not, write to the Free Software
17
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
package net.sourceforge.ganttproject.action.task;
21
21
import java.awt.event.ActionEvent;
22
22
import java.util.ArrayList;
23
23
import java.util.List;
25
import net.sourceforge.ganttproject.GanttTree2;
26
import net.sourceforge.ganttproject.action.ActionDelegate;
27
import net.sourceforge.ganttproject.action.ActionStateChangedListener;
25
28
import net.sourceforge.ganttproject.action.GPAction;
26
29
import net.sourceforge.ganttproject.gui.UIFacade;
27
30
import net.sourceforge.ganttproject.task.Task;
28
31
import net.sourceforge.ganttproject.task.TaskManager;
29
32
import net.sourceforge.ganttproject.task.TaskSelectionManager;
30
import net.sourceforge.ganttproject.task.TaskSelectionManager.Listener;
33
import net.sourceforge.ganttproject.task.dependency.TaskDependencyException;
32
abstract class TaskActionBase extends GPAction implements Listener {
35
public abstract class TaskActionBase extends GPAction implements TaskSelectionManager.Listener, ActionDelegate {
36
private final List<ActionStateChangedListener> myListeners = new ArrayList<ActionStateChangedListener>();
33
37
private final TaskManager myTaskManager;
38
private final UIFacade myUIFacade;
39
private final TaskSelectionManager mySelectionManager;
40
private final GanttTree2 myTree;
34
41
private List<Task> mySelection;
35
private final UIFacade myUIFacade;
36
private TaskSelectionManager mySelectionManager;
38
protected TaskActionBase(String name, TaskManager taskManager, TaskSelectionManager selectionManager, UIFacade uiFacade) {
43
protected TaskActionBase(String name, TaskManager taskManager, TaskSelectionManager selectionManager,
44
UIFacade uiFacade, GanttTree2 tree) {
45
this(name, taskManager, selectionManager, uiFacade, tree, IconSize.MENU);
47
protected TaskActionBase(String name, TaskManager taskManager, TaskSelectionManager selectionManager,
48
UIFacade uiFacade, GanttTree2 tree, IconSize size) {
40
50
myTaskManager = taskManager;
41
51
mySelectionManager = selectionManager;
52
myUIFacade = uiFacade;
42
54
selectionManager.addSelectionListener(this);
43
55
selectionChanged(selectionManager.getSelectedTasks());
44
myUIFacade = uiFacade;
59
public void addStateChangedListener(ActionStateChangedListener l) {
47
64
public void actionPerformed(ActionEvent e) {
48
65
final List<Task> selection = new ArrayList<Task>(mySelection);
49
myUIFacade.getUndoManager().undoableEdit(getLocalizedName(), new Runnable() {
52
TaskActionBase.this.run(selection);
53
} catch (Exception e) {
54
getUIFacade().showErrorDialog(e);
66
if(isEnabled() && askUserPermission(selection)) {
67
myUIFacade.getUndoManager().undoableEdit(getLocalizedDescription(), new Runnable() {
71
TaskActionBase.this.run(selection);
72
} catch (Exception e) {
73
getUIFacade().showErrorDialog(e);
81
* @param selection of tasks for which permission is required
82
* @return true if the operation is accepted by the user
84
protected boolean askUserPermission(List<Task> selection) {
85
// Accept operation by default
60
90
public void selectionChanged(List<Task> currentSelection) {
61
91
setEnabled(isEnabled(currentSelection));
62
92
mySelection = currentSelection;
96
public void setEnabled(boolean newValue) {
97
super.setEnabled(newValue);
98
for(ActionStateChangedListener l: myListeners) {
99
l.actionStateChanged();
65
104
public void userInputConsumerChanged(Object newConsumer) {
77
116
return myUIFacade;
119
protected GanttTree2 getTree() {
123
protected void forwardScheduling() throws TaskDependencyException {
124
// TODO 07 Sep 2011: It does seem necessary to reset() the charts: remove if this indeed is the case
125
// // TODO Find out which chart is opened and only reset that one (maybe add a resetChart to UIFacade?)
126
// myUIFacade.getGanttChart().reset();
127
// myUIFacade.getResourceChart().reset();
128
myTaskManager.getAlgorithmCollection().getRecalculateTaskScheduleAlgorithm().run();
129
getUIFacade().getTaskTree().getTreeComponent().repaint();
80
132
protected abstract boolean isEnabled(List<Task> selection);
81
133
protected abstract void run(List<Task> selection) throws Exception ;