Search in sources :

Example 6 with TransAction

use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.

the class TableView method pasteSelected.

private void pasteSelected() {
    int rownr = getCurrentRownr();
    if (clipboard != null) {
        clipboard.dispose();
        clipboard = null;
    }
    clipboard = new Clipboard(getDisplay());
    TextTransfer tran = TextTransfer.getInstance();
    String text = (String) clipboard.getContents(tran);
    if (text != null) {
        String[] lines = text.split(Const.CR);
        if (lines.length > 1) {
            // ALlocate complete paste grid!
            String[][] grid = new String[lines.length - 1][];
            int[] idx = new int[lines.length - 1];
            for (int i = 1; i < lines.length; i++) {
                grid[i - 1] = lines[i].split("\t");
                idx[i - 1] = rownr + i;
                addItem(idx[i - 1], grid[i - 1]);
            }
            TransAction ta = new TransAction();
            ta.setNew(grid, idx);
            addUndo(ta);
        }
        if (rownr == 0 && table.getItemCount() > rownr + 1) {
            if (isEmpty(rownr, -1)) {
                table.remove(rownr);
            }
        }
        setRowNums();
        unEdit();
        setModified();
    }
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Clipboard(org.eclipse.swt.dnd.Clipboard) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 7 with TransAction

use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.

the class TableView method copyToAll.

private void copyToAll() {
    TableItem row = activeTableItem;
    if (row == null || row.isDisposed()) {
        return;
    }
    int colnr = activeTableColumn;
    if (colnr == 0) {
        return;
    }
    String str = row.getText(colnr);
    // Get undo information: all columns
    int size = table.getItemCount();
    String[][] before = new String[size][];
    String[][] after = new String[size][];
    int[] index = new int[size];
    for (int i = 0; i < table.getItemCount(); i++) {
        TableItem item = table.getItem(i);
        index[i] = i;
        before[i] = getItemText(item);
        item.setText(colnr, str);
        after[i] = getItemText(item);
    }
    // Add the undo information!
    TransAction ta = new TransAction();
    ta.setChanged(before, after, index);
    addUndo(ta);
}
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)

Example 8 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 9 with TransAction

use of org.pentaho.di.core.undo.TransAction in project pentaho-kettle by pentaho.

the class TableView method insertRow.

private void insertRow(int ronr) {
    TableItem item = new TableItem(table, SWT.NONE, ronr);
    item.setText(1, "");
    // Add undo information
    TransAction ta = new TransAction();
    String[] str = getItemText(item);
    ta.setNew(new String[][] { str }, new int[] { ronr });
    addUndo(ta);
    setRowNums();
    edit(ronr, 1);
    tableViewModifyListener.insertRow(ronr);
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) TableItem(org.eclipse.swt.widgets.TableItem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 10 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