use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.
the class AbstractMeta method previousUndo.
// get previous undo, change position
/*
* (non-Javadoc)
*
* @see org.pentaho.di.core.gui.UndoInterface#previousUndo()
*/
@Override
public TransAction previousUndo() {
if (undo.isEmpty() || undo_position < 0) {
// No undo left!
return null;
}
TransAction retval = undo.get(undo_position);
undo_position--;
return retval;
}
use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.
the class AbstractMeta method nextUndo.
/*
* (non-Javadoc)
*
* @see org.pentaho.di.core.gui.UndoInterface#nextUndo()
*/
@Override
public TransAction nextUndo() {
int size = undo.size();
if (size == 0 || undo_position >= size - 1) {
// no redo left...
return null;
}
undo_position++;
TransAction retval = undo.get(undo_position);
return retval;
}
use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.
the class AbstractMetaTest method testAddRemoveViewUndo.
@Test
public void testAddRemoveViewUndo() throws Exception {
// addUndo() right now will fail with an NPE
assertEquals(0, meta.getUndoSize());
meta.clearUndo();
assertEquals(0, meta.getUndoSize());
assertEquals(0, meta.getMaxUndo());
meta.setMaxUndo(3);
assertEquals(3, meta.getMaxUndo());
// viewThisUndo() and viewPreviousUndo() have the same logic
assertNull(meta.viewThisUndo());
assertNull(meta.viewPreviousUndo());
assertNull(meta.viewNextUndo());
assertNull(meta.previousUndo());
assertNull(meta.nextUndo());
StepMeta fromMeta = mock(StepMeta.class);
StepMeta toMeta = mock(StepMeta.class);
Object[] from = new Object[] { fromMeta };
Object[] to = new Object[] { toMeta };
int[] pos = new int[0];
Point[] prev = new Point[0];
Point[] curr = new Point[0];
meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_NEW, false);
assertNotNull(meta.viewThisUndo());
assertNotNull(meta.viewPreviousUndo());
assertNull(meta.viewNextUndo());
meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_CHANGE, false);
assertNotNull(meta.viewThisUndo());
assertNotNull(meta.viewPreviousUndo());
assertNull(meta.viewNextUndo());
TransAction action = meta.previousUndo();
assertNotNull(action);
assertEquals(AbstractMeta.TYPE_UNDO_CHANGE, action.getType());
assertNotNull(meta.viewThisUndo());
assertNotNull(meta.viewPreviousUndo());
assertNotNull(meta.viewNextUndo());
meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_DELETE, false);
meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_POSITION, false);
assertNotNull(meta.previousUndo());
assertNotNull(meta.nextUndo());
meta.setMaxUndo(1);
assertEquals(1, meta.getUndoSize());
meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_NEW, false);
}
use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.
the class TableView method previousUndo.
// get previous undo, change position
private TransAction previousUndo() {
if (undo.isEmpty() || undoPosition < 0) {
// No undo left!
return null;
}
TransAction retval = undo.get(undoPosition);
undoPosition--;
return retval;
}
use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.
the class TableView method delSelected.
private void delSelected() {
if (nrNonEmpty() == 0) {
return;
}
// Which items do we delete?
int[] items = table.getSelectionIndices();
if (items.length == 0) {
return;
}
// Save undo information
String[][] before = new String[items.length][];
for (int i = 0; i < items.length; i++) {
TableItem ti = table.getItem(items[i]);
before[i] = getItemText(ti);
}
TransAction ta = new TransAction();
ta.setDelete(before, items);
addUndo(ta);
TableItem row = activeTableItem;
if (row == null) {
return;
}
int rowbefore = table.indexOf(row);
// Delete selected items.
table.remove(items);
if (table.getItemCount() == 0) {
TableItem item = new TableItem(table, SWT.NONE);
// Save undo infomation!
String[] stritem = getItemText(item);
ta = new TransAction();
ta.setNew(new String[][] { stritem }, new int[] { 0 });
addUndo(ta);
}
// If the last row is gone, put the selection back on last-1!
if (rowbefore >= table.getItemCount()) {
rowbefore = table.getItemCount() - 1;
}
// After the delete, we put the cursor on the same row as before (if we can)
if (rowbefore < table.getItemCount() && table.getItemCount() > 0) {
setPosition(rowbefore, 1);
table.setSelection(rowbefore);
activeTableRow = rowbefore;
}
tableViewModifyListener.delete(items);
setRowNums();
setModified();
}
Aggregations