Search in sources :

Example 6 with UndoRedo

use of org.openide.awt.UndoRedo in project netbeans-rcp-lite by outersky.

the class NbDocument method getEditToBeUndoneRedoneOfType.

private static <T extends UndoableEdit> T getEditToBeUndoneRedoneOfType(EditorCookie ec, Class<T> type, boolean redone) {
    UndoRedo ur;
    if (ec instanceof CloneableEditorSupport && ((ur = ((CloneableEditorSupport) ec).getUndoRedo()) instanceof UndoRedoManager)) {
        UndoRedoManager urManager = (UndoRedoManager) ur;
        UndoableEdit edit = urManager.editToBeUndoneRedone(redone);
        if (type.isInstance(edit)) {
            return type.cast(edit);
        } else if (edit instanceof List) {
            @SuppressWarnings("unchecked") List<UndoableEdit> listEdit = (List<UndoableEdit>) edit;
            for (int i = listEdit.size() - 1; i >= 0; i--) {
                // Go from most wrapped back
                edit = listEdit.get(i);
                if (type.isInstance(edit)) {
                    @SuppressWarnings("unchecked") T inst = (T) edit;
                    return inst;
                }
            }
        }
    }
    return null;
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit) UndoRedo(org.openide.awt.UndoRedo) List(java.util.List)

Aggregations

UndoRedo (org.openide.awt.UndoRedo)6 List (java.util.List)1 UndoableEdit (javax.swing.undo.UndoableEdit)1