-
Notifications
You must be signed in to change notification settings - Fork 96
/
SectionDeleteCommand.java
81 lines (68 loc) · 2.36 KB
/
SectionDeleteCommand.java
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
/*******************************************************************************
* Copyright (c) 2013 Dirk Fauth and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* 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();
}
}