aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2013-07-29 03:21:08 (EDT)
committerDirk Fauth2013-07-29 03:21:08 (EDT)
commit7bedb43ef912e7914c59547f10d297a785925324 (patch)
treeac34ff328f3f29a90b50b50b0b5b3613ee74d2bf
parent8486827c14147aaedfbad2f014ed610216a9b7ac (diff)
downloadorg.eclipse.nebula-7bedb43ef912e7914c59547f10d297a785925324.zip
org.eclipse.nebula-7bedb43ef912e7914c59547f10d297a785925324.tar.gz
org.eclipse.nebula-7bedb43ef912e7914c59547f10d297a785925324.tar.bz2
Bug 413822 - Improvements to undo/redo capabilities like adding delete
commands for events and sections and several corrections in handling.
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java186
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/GanttUndoRedoManager.java7
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/ClusteredCommand.java48
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventDeleteCommand.java100
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventMoveCommand.java54
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/SectionDeleteCommand.java78
6 files changed, 355 insertions, 118 deletions
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
index 56f69e6..df065df 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
@@ -27,6 +27,7 @@ import java.util.Set;
import org.eclipse.nebula.widgets.ganttchart.dnd.VerticalDragDropManager;
import org.eclipse.nebula.widgets.ganttchart.undoredo.GanttUndoRedoManager;
import org.eclipse.nebula.widgets.ganttchart.undoredo.commands.ClusteredCommand;
+import org.eclipse.nebula.widgets.ganttchart.undoredo.commands.EventMoveCommand;
import org.eclipse.nebula.widgets.ganttchart.undoredo.commands.IUndoRedoCommand;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
@@ -5872,20 +5873,6 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
_tracker.dispose();
}
- if (!_dragEvents.isEmpty()) {
- if (_resizing) {
- for (int i = 0; i < _eventListeners.size(); i++) {
- ((IGanttEventListener) _eventListeners.get(i)).eventsResizeFinished(_dragEvents, event);
- }
- }
- if (_dragging) {
- for (int i = 0; i < _eventListeners.size(); i++) {
- ((IGanttEventListener) _eventListeners.get(i)).eventsMoveFinished(_dragEvents, event);
- }
- }
-
- }
-
// vertical dragging "end"
if (_freeDragging) {
// clear any temporary DND events held in the sections
@@ -5906,6 +5893,20 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
_vDNDManager.clear();
}
+ if (!_dragEvents.isEmpty()) {
+ if (_resizing) {
+ for (int i = 0; i < _eventListeners.size(); i++) {
+ ((IGanttEventListener) _eventListeners.get(i)).eventsResizeFinished(_dragEvents, event);
+ }
+ }
+ if (_dragging) {
+ for (int i = 0; i < _eventListeners.size(); i++) {
+ ((IGanttEventListener) _eventListeners.get(i)).eventsMoveFinished(_dragEvents, event);
+ }
+ }
+ needsRedraw = true;
+ }
+
// put all undo/redo commands into one command as any user would expect a multi-DND to undo with all events, not just one at a time
final ClusteredCommand cc = new ClusteredCommand();
@@ -5947,6 +5948,20 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
final IUndoRedoCommand undoCommand = ge.getPostMoveOrResizeUndoCommand();
cc.addCommand(undoCommand);
}
+
+ //sort the commands by index before to keep the stair effect
+ Collections.sort(cc.getCommandList(), new Comparator<IUndoRedoCommand>() {
+
+ public int compare(IUndoRedoCommand o1, IUndoRedoCommand o2) {
+ if (o1 instanceof EventMoveCommand && o2 instanceof EventMoveCommand) {
+ int thisVal = ((EventMoveCommand)o1).getIndexBefore();
+ int anotherVal = ((EventMoveCommand)o2).getIndexBefore();
+ return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
+ }
+ return 0;
+ }
+ });
+
if (cc.size() > 0) {
_undoRedoManager.record(cc);
}
@@ -6006,109 +6021,136 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
return;
}
+ //sort the events descending dependent on their start date
+ //this is necessary to keep the stair effect correctly on drag and drop
+ Collections.sort(_dragEvents, new Comparator<GanttEvent>() {
+ public int compare(GanttEvent o1, GanttEvent o2) {
+ Calendar compareDate1 = o1.getRevisedStart() != null ? o1.getRevisedStart() : o1.getStartDate();
+ Calendar compareDate2 = o2.getRevisedStart() != null ? o2.getRevisedStart() : o2.getStartDate();
+ return compareDate2.compareTo(compareDate1);
+ }
+ });
+
final int vDragMode = _settings.getVerticalEventDragging();
- // loop all dragged events
- for (int i = 0; i < _dragEvents.size(); i++) {
- final GanttEvent ge = (GanttEvent) _dragEvents.get(i);
-
final GanttEvent top = _vDNDManager.getTopEvent();
final GanttEvent bottom = _vDNDManager.getBottomEvent();
GanttSection targetSection = _vDNDManager.getTargetSection();
- //System.err.println(ge + " is getting retargeted from " + ge.getGanttSection() + " to " + targetSection + " between " + top + " and " + bottom);
-
// only allow DND across sections?
- if (ge.getGanttSection() != null && targetSection != null && ge.getGanttSection() == targetSection && vDragMode == VerticalDragModes.CROSS_SECTION_VERTICAL_DRAG) {
+ List ignoreDrag = new ArrayList();
+ if (vDragMode == VerticalDragModes.CROSS_SECTION_VERTICAL_DRAG) {
+ for (int i = 0; i < _dragEvents.size(); i++) {
+ final GanttEvent ge = (GanttEvent) _dragEvents.get(i);
+ if (ge.getGanttSection() != null && targetSection != null && ge.getGanttSection() == targetSection) {
ge.undoVerticalDragging();
- continue;
+ ignoreDrag.add(ge);
}
-
- // notify listeners
- if (ge.getGanttSection() != targetSection && hasGanttSections()) {
- for (int x = 0; x < _eventListeners.size(); x++) {
- ((IGanttEventListener) _eventListeners.get(x)).eventMovedToNewSection(ge, ge.getGanttSection(), targetSection);
- }
- } else {
- for (int x = 0; x < _eventListeners.size(); x++) {
- ((IGanttEventListener) _eventListeners.get(x)).eventReordered(ge);
}
}
if (top == null && bottom == null) {
// it'll be alone in a section
if (targetSection != null) {
+ for (int i = 0; i < _dragEvents.size(); i++) {
+ final GanttEvent ge = (GanttEvent) _dragEvents.get(i);
+ final GanttSection fromSection = ge.getGanttSection();
+
ge.reparentToNewGanttSection(0, targetSection);
+
+ for (int x = 0; x < _eventListeners.size(); x++) {
+ ((IGanttEventListener) _eventListeners.get(x)).eventMovedToNewSection(ge, fromSection, targetSection);
+ }
+ }
}
+ }
+ else {
+ //if we come here, do further processing
+ //first remove the dragged events, so we don't have to deal with a changing
+ //list order when adding them again
+ for (int i = 0; i < _dragEvents.size(); i++) {
+ final GanttEvent ge = (GanttEvent) _dragEvents.get(i);
+ final GanttSection fromSection = ge.getGanttSection();
- continue;
- }
+ if (hasGanttSections()) {
+ fromSection.removeGanttEvent(ge);
- int index = 0;
+ } else {
+ _ganttEvents.remove(ge);
+ }
+ }
+
+ //calculate the insertion index for the event in the drag events that was dragged
+ //on multi select, only the event that was dragged has information about the drag information
+ //the others should rely on that index instead of calculating it over and over again
+ GanttEvent event = null;
+ for (GanttEvent ev : (List<GanttEvent>) _dragEvents) {
+ if (ev.getPreVerticalDragBounds() != null) {
+ event = ev;
+ }
+ }
- // event was moved nowhere vertically, same place
- if (ge.getPreVerticalDragBounds() != null) {
- if (ge.getY() == ge.getPreVerticalDragBounds().y) {
- continue;
- }
+ if (event == null) {
+ //this should never happen, but who knows if there is still some bugs around
+ event = (GanttEvent) _dragEvents.get(0);
}
+ final GanttSection fromSection = event.getGanttSection();
+ int index = 0;
+
if (hasGanttSections()) {
- final GanttSection fromSection = ge.getGanttSection();
//List fromEvents = fromSection.getEvents();
if (targetSection == null) {
// TODO: This seems to happen when user drops event on border between two, uncomment line below and do a drop on border, see if we can handle differently
targetSection = fromSection;
}
final List toEvents = targetSection.getEvents();
-
- if (top == null) {
- index = 0;
- }
- if (bottom == null) {
- index = toEvents.size();
- }
-
- if (top != null && bottom != null) {
+ if (top != null) {
index = toEvents.indexOf(top);
+ index++;
}
- // if moved up we need to push the index by 1, unless it was moved to the top of a section, then we don't push it or it'd never go to the top
- if (ge.wasVerticallyMovedUp() && ge.getGanttSection() == targetSection) {
+ } else {
if (top != null) {
+ index = _ganttEvents.indexOf(top);
+ }
+ if (event.wasVerticallyMovedUp()) {
index++;
}
}
- // moved up from a section to inbetween two events (not at top)
- else if (ge.wasVerticallyMovedUp() && ge.getGanttSection() != targetSection && top != null) {
- index++;
- }
- // moved down from one section to another, push it down (unless at the top of the new section, same reasoning as before)
- if (!ge.wasVerticallyMovedUp() && ge.getGanttSection() != targetSection && top != null) {
- index++;
+ // loop all dragged events
+ for (int i = 0; i < _dragEvents.size(); i++) {
+ final GanttEvent ge = (GanttEvent) _dragEvents.get(i);
+
+ //if the GanttEvent was moved to a new section, remember the origin section for later use of the listeners
+ //needed because the event should be fired at the end not at the beginning of the move
+ GanttSection originSection = (ge.getGanttSection() != targetSection && hasGanttSections()) ? ge.getGanttSection() : null;
+
+ // event was moved nowhere vertically, same place
+ if (ge.getPreVerticalDragBounds() != null) {
+ if (ge.getY() == ge.getPreVerticalDragBounds().y) {
+ continue;
}
-
- if (index < 0) {
- index = 0;
}
- //System.err.println("Index " + index);
-
- fromSection.removeGanttEvent(ge);
+ if (hasGanttSections()) {
targetSection.addGanttEvent(index, ge);
} else {
- if (top != null) {
- index = _ganttEvents.indexOf(top);
+ _ganttEvents.add(index, ge);
+ }
+
+ // notify listeners
+ if (originSection != null) {
+ for (int x = 0; x < _eventListeners.size(); x++) {
+ ((IGanttEventListener) _eventListeners.get(x)).eventMovedToNewSection(ge, originSection, targetSection);
+ }
+ } else {
+ for (int x = 0; x < _eventListeners.size(); x++) {
+ ((IGanttEventListener) _eventListeners.get(x)).eventReordered(ge);
}
- if (ge.wasVerticallyMovedUp()) {
- index++;
}
-
- // get the index of the top event
- _ganttEvents.remove(ge);
- _ganttEvents.add(index, ge);
}
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/GanttUndoRedoManager.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/GanttUndoRedoManager.java
index 13dff7a..8750340 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/GanttUndoRedoManager.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/GanttUndoRedoManager.java
@@ -185,6 +185,13 @@ public class GanttUndoRedoManager {
}
/**
+ * @param currentIndex The current index of where the undo/redo marker is
+ */
+ public void setCurrentIndex(int currentIndex) {
+ _currentIndex = currentIndex;
+ }
+
+ /**
* Clears up the stack of undo/redo events and keeps its size in check.
*/
private void fixStack() {
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/ClusteredCommand.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/ClusteredCommand.java
index 8bd6735..55cc23f 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/ClusteredCommand.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/ClusteredCommand.java
@@ -72,6 +72,21 @@ public class ClusteredCommand extends AbstractUndoRedoCommand {
return _commands.size();
}
+ /**
+ * Simple getter for the list of commands that are transported by this
+ * ClusteredCommand.
+ * <p>
+ * Note that this will only return the list of commands as is. There is
+ * no transformation made to the list.
+ *
+ * @return The list of commands that are transported by this ClusteredCommand.
+ *
+ * @see ClusteredCommand#getFlattenedCommands()
+ */
+ public List getCommandList() {
+ return _commands;
+ }
+
public void dispose() {
for (int i = 0; i < _commands.size(); i++) {
((IUndoRedoCommand)_commands.get(i)).dispose();
@@ -89,18 +104,41 @@ public class ClusteredCommand extends AbstractUndoRedoCommand {
((IUndoRedoCommand)_commands.get(i)).undo();
}
}
- /**
+
+ /**
* Return the individual commands that are clustered in this command.
+ * If this ClusteredCommand also contains other ClusteredCommands,
+ * they will get unpacked so there will be one flat list of
+ * IUndoRedoCommands.
*
* @return A unmodifiable list of participating {@link EventMoveCommand}s.
+ *
+ * @deprecated Because the name of this method is not unique and might me interpreted wrong.
+ *
+ * @see ClusteredCommand#getCommandList()
+ * @see ClusteredCommand#getFlattenedCommands()
+ */
+ public List getCommands() {
+ return this.getFlattenedCommands();
+ }
+
+ /**
+ * Return the individual commands that are clustered in this command.
+ * If this ClusteredCommand also contains other ClusteredCommands,
+ * they will get unpacked so there will be one flat list of
+ * IUndoRedoCommands.
+ *
+ * @return A unmodifiable list of participating {@link EventMoveCommand}s.
+ *
+ * @see ClusteredCommand#getCommandList()
*/
- public List getCommands() {
+ public List getFlattenedCommands() {
ArrayList result = new ArrayList();
for (Object command : _commands) {
if (command instanceof EventMoveCommand)
result.add((EventMoveCommand) command);
else if (command instanceof ClusteredCommand)
- result.addAll(((ClusteredCommand) command).getCommands());
+ result.addAll(((ClusteredCommand) command).getFlattenedCommands());
}
return Collections.unmodifiableList(result);
}
@@ -112,9 +150,11 @@ public class ClusteredCommand extends AbstractUndoRedoCommand {
*/
public List getEvents() {
ArrayList result = new ArrayList();
- for (Object command : getCommands()) {
+ for (Object command : getFlattenedCommands()) {
if (command instanceof EventMoveCommand)
result.add(((EventMoveCommand) command).getEvent());
+ else if (command instanceof EventDeleteCommand)
+ result.add(((EventDeleteCommand) command).getEvent());
}
return Collections.unmodifiableList(result);
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventDeleteCommand.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventDeleteCommand.java
new file mode 100644
index 0000000..9f1897a
--- /dev/null
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventDeleteCommand.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Dirk Fauth and others.
+ * 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:
+ * Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.ganttchart.undoredo.commands;
+
+import org.eclipse.nebula.widgets.ganttchart.GanttEvent;
+import org.eclipse.nebula.widgets.ganttchart.GanttSection;
+import org.eclipse.nebula.widgets.ganttchart.IGanttEventListener;
+import org.eclipse.nebula.widgets.ganttchart.undoredo.commands.IUndoRedoCommand;
+
+/**
+ * Represents one GanttEvent delete action that can be undone/redone.
+ * <p>
+ * Note that this command is not added internally. But you are able to
+ * create and add this type of command within your custom
+ * {@link IGanttEventListener#eventsDeleteRequest(java.util.List, org.eclipse.swt.events.MouseEvent)}
+ */
+public class EventDeleteCommand implements IUndoRedoCommand {
+
+ private GanttEvent _event;
+ private int _index;
+ private GanttSection _section;
+
+ /**
+ * Creates a new undoable/redoable delete Event.
+ *
+ * @param event {@link GanttEvent} being deleted
+ * @param section {@link GanttSection} index (of all GanttSections) prior to delete
+ * @param index Index of event in {@link GanttSection} section prior to delete
+ */
+ public EventDeleteCommand(final GanttEvent event, final GanttSection section, final int index) {
+ _event = event;
+ _index = index;
+ _section = section;
+ }
+
+ public void undo() {
+ _event.getParentComposite().addEvent(_event, _index);
+
+ if (_section != null) {
+ _section.addGanttEvent(_index, _event);
+ }
+ }
+
+ public void redo() {
+ _event.getParentComposite().removeEvent(_event);
+
+ if (_section != null) {
+ _section.removeGanttEvent(_event);
+ }
+ }
+
+ public void dispose() {
+ }
+
+ public GanttEvent getEvent() {
+ return _event;
+ }
+
+ public void setEvent(final GanttEvent event) {
+ _event = event;
+ }
+
+ public int getIndex() {
+ return _index;
+ }
+
+ public void setIndex(final int index) {
+ _index = index;
+ }
+
+ public GanttSection getSection() {
+ return _section;
+ }
+
+ public void setSection(final GanttSection section) {
+ _section = section;
+ }
+
+ @SuppressWarnings("nls")
+ public String toString() {
+ final StringBuffer buf = new StringBuffer(200);
+ buf.append("[EventDelete: ");
+ buf.append(_event);
+ buf.append(" was deleted from section ");
+ buf.append(_section);
+ buf.append(" at index ");
+ buf.append(_index);
+ buf.append(']');
+ return buf.toString();
+ }
+
+}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventMoveCommand.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventMoveCommand.java
index c82e9a5..2dc4117 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventMoveCommand.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/EventMoveCommand.java
@@ -34,8 +34,8 @@ public class EventMoveCommand extends AbstractUndoRedoCommand {
private Calendar _revisedEndDateAfter;
private int _indexBefore;
private int _indexAfter;
- private int _sectionBefore;
- private int _sectionAfter;
+ private GanttSection _sectionBefore;
+ private GanttSection _sectionAfter;
/**
* Creates a new undoable/redoable Move Event.
@@ -79,19 +79,9 @@ public class EventMoveCommand extends AbstractUndoRedoCommand {
_indexBefore = indexBefore;
_indexAfter = indexAfter;
- if (sectionBefore == null) {
- _sectionBefore = -1;
- }
- else {
- _sectionBefore = _event.getParentComposite().getGanttSections().indexOf(sectionBefore);
- }
+ _sectionBefore = sectionBefore;
+ _sectionAfter = sectionAfter;
- if (sectionAfter == null) {
- _sectionAfter = -1;
- }
- else {
- _sectionAfter = _event.getParentComposite().getGanttSections().indexOf(sectionAfter);
- }
}
public void dispose() {
@@ -102,19 +92,8 @@ public class EventMoveCommand extends AbstractUndoRedoCommand {
_event.setNoUpdatePlannedDates(_startDateAfter, _endDateAfter);
_event.setNoUpdateRevisedDates(_revisedStartDateAfter, _revisedEndDateAfter);
-/* _event.setStartDate(_startDateAfter);
- _event.setEndDate(_endDateAfter);
-*/
- // we know we're setting valid dates, so force validation to off or we'll get funky results
-/* if (_revisedStartDateAfter != null) {
- _event.setRevisedStart(_revisedStartDateAfter, false);
- }
- if (_revisedEndDateAfter != null) {
- _event.setRevisedEnd(_revisedEndDateAfter, false);
- }
-*/
- if (_sectionAfter != -1 && _indexAfter > -1) {
- _event.reparentToNewGanttSection(_indexAfter, (GanttSection)_event.getParentComposite().getGanttSections().get(_sectionAfter));
+ if (_sectionAfter != null && _indexAfter > -1) {
+ _event.reparentToNewGanttSection(_indexAfter, _sectionAfter);
}
if (_event.getGanttSection() == null && _indexAfter != -1) {
@@ -126,17 +105,8 @@ public class EventMoveCommand extends AbstractUndoRedoCommand {
_event.setNoUpdatePlannedDates(_startDateBefore, _endDateBefore);
_event.setNoUpdateRevisedDates(_revisedStartDateBefore, _revisedEndDateBefore);
- // we know we're setting valid dates, so force validation to off or we'll get funky results
- /* if (_revisedStartDateBefore != null) {
- _event.setRevisedStart(_revisedStartDateBefore, false);
- }
-
- if (_revisedEndDateBefore != null) {
- _event.setRevisedEnd(_revisedEndDateBefore, false);
- }*/
-
- if (_sectionBefore != -1 && _indexBefore > -1) {
- _event.reparentToNewGanttSection(_indexBefore, (GanttSection)_event.getParentComposite().getGanttSections().get(_sectionBefore));
+ if (_sectionBefore != null && _indexBefore > -1) {
+ _event.reparentToNewGanttSection(_indexBefore, _sectionBefore);
}
// reparent in chart itself as there are no sections
@@ -203,19 +173,19 @@ public class EventMoveCommand extends AbstractUndoRedoCommand {
_indexAfter = indexAfter;
}
- public int getSectionBefore() {
+ public GanttSection getSectionBefore() {
return _sectionBefore;
}
- public void setSectionBefore(final int sectionBefore) {
+ public void setSectionBefore(final GanttSection sectionBefore) {
_sectionBefore = sectionBefore;
}
- public int getSectionAfter() {
+ public GanttSection getSectionAfter() {
return _sectionAfter;
}
- public void setSectionAfter(final int sectionAfter) {
+ public void setSectionAfter(final GanttSection sectionAfter) {
_sectionAfter = sectionAfter;
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/SectionDeleteCommand.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/SectionDeleteCommand.java
new file mode 100644
index 0000000..e010f54
--- /dev/null
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/undoredo/commands/SectionDeleteCommand.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Dirk Fauth and others.
+ * 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:
+ * Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.ganttchart.undoredo.commands;
+
+import org.eclipse.nebula.widgets.ganttchart.GanttSection;
+import org.eclipse.nebula.widgets.ganttchart.undoredo.commands.IUndoRedoCommand;
+
+/**
+ * Represents one GanttSection delete action that can be undone/redone.
+ * <p>
+ * Note that this command is not added internally. This is because there is
+ * no code that automatically deletes sections from your GanttComposite.
+ * You need to create and record this command together with the code that
+ * removes the section from your composite.
+ */
+public class SectionDeleteCommand implements IUndoRedoCommand {
+
+ private GanttSection _section;
+ private int _index;
+
+ /**
+ * Creates a new undoable/redoable delete Event.
+ *
+ * @param section {@link GanttSection} being deleted
+ * @param index Index of {@link GanttSection} prior to delete
+ */
+ public SectionDeleteCommand(final GanttSection section, final int index) {
+ _section = section;
+ _index = index;
+ }
+
+ public void undo() {
+ _section.getParentComposite().addSection(_section, _index);
+ }
+
+ public void redo() {
+ _section.getParentComposite().removeSection(_section);
+ }
+
+ public void dispose() {
+ }
+
+ public GanttSection getSection() {
+ return _section;
+ }
+
+ public void setSection(final GanttSection section) {
+ _section = section;
+ }
+
+ public int getIndex() {
+ return _index;
+ }
+
+ public void setIndex(final int index) {
+ _index = index;
+ }
+
+ @SuppressWarnings("nls")
+ public String toString() {
+ final StringBuffer buf = new StringBuffer(200);
+ buf.append("[SectionDelete: ");
+ buf.append(_section);
+ buf.append(" was deleted at index ");
+ buf.append(_index);
+ buf.append(']');
+ return buf.toString();
+ }
+
+}