Search in sources :

Example 1 with TransAction

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;
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction)

Example 2 with TransAction

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;
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Point(org.pentaho.di.core.gui.Point)

Example 3 with TransAction

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);
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Matchers.anyObject(org.mockito.Matchers.anyObject) Point(org.pentaho.di.core.gui.Point) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 4 with TransAction

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;
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction)

Example 5 with TransAction

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();
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) TableItem(org.eclipse.swt.widgets.TableItem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point)

Aggregations

TransAction (org.pentaho.di.core.undo.TransAction)22 Point (org.eclipse.swt.graphics.Point)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)7 TableItem (org.eclipse.swt.widgets.TableItem)6 Point (org.pentaho.di.core.gui.Point)4 JobMeta (org.pentaho.di.job.JobMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2 JobGraph (org.pentaho.di.ui.spoon.job.JobGraph)2 TransGraph (org.pentaho.di.ui.spoon.trans.TransGraph)2 Clipboard (org.eclipse.swt.dnd.Clipboard)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1 Test (org.junit.Test)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)1