Search in sources :

Example 6 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project cayenne by apache.

the class PasteAction method performAction.

/**
 * Performs pasting items from the system buffer
 */
@Override
public void performAction(ActionEvent e) {
    try {
        Object content = Toolkit.getDefaultToolkit().getSystemClipboard().getData(CayenneTransferable.CAYENNE_FLAVOR);
        Object currentObject = getProjectController().getCurrentObject();
        if (content != null && currentObject != null) {
            DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject().getRootNode();
            DataMap map = getProjectController().getCurrentDataMap();
            UndoableEdit undoableEdit;
            if (content instanceof List) {
                undoableEdit = new PasteCompoundUndoableEdit();
                for (Object o : (List) content) {
                    paste(currentObject, o);
                    undoableEdit.addEdit(new PasteUndoableEdit(domain, map, currentObject, o));
                }
            } else {
                paste(currentObject, content);
                undoableEdit = new PasteUndoableEdit(domain, map, currentObject, content);
            }
            application.getUndoManager().addEdit(undoableEdit);
        }
    } catch (UnsupportedFlavorException ufe) {
    // do nothing
    } catch (Exception ex) {
        ErrorDebugDialog.guiException(ex);
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) PasteUndoableEdit(org.apache.cayenne.modeler.undo.PasteUndoableEdit) PasteUndoableEdit(org.apache.cayenne.modeler.undo.PasteUndoableEdit) UndoableEdit(javax.swing.undo.UndoableEdit) PasteCompoundUndoableEdit(org.apache.cayenne.modeler.undo.PasteCompoundUndoableEdit) PasteCompoundUndoableEdit(org.apache.cayenne.modeler.undo.PasteCompoundUndoableEdit) List(java.util.List) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) DataMap(org.apache.cayenne.map.DataMap)

Example 7 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project cayenne by apache.

the class RemoveAction method removeLastPathComponent.

/**
 * Removes an object, depending on its type
 */
private UndoableEdit removeLastPathComponent(ConfigurationNode object, ConfigurationNode parentObject) {
    UndoableEdit undo = null;
    if (object instanceof DataMap) {
        if (parentObject != null && parentObject instanceof DataNodeDescriptor) {
            undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) parentObject, (DataMap) object);
            removeDataMapFromDataNode((DataNodeDescriptor) parentObject, (DataMap) object);
        } else {
            // Not under Data Node, remove completely
            undo = new RemoveUndoableEdit(application, (DataMap) object);
            removeDataMap((DataMap) object);
        }
    } else if (object instanceof DataNodeDescriptor) {
        undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) object);
        removeDataNode((DataNodeDescriptor) object);
    } else if (object instanceof DbEntity) {
        undo = new RemoveUndoableEdit(((DbEntity) object).getDataMap(), (DbEntity) object);
        removeDbEntity(((DbEntity) object).getDataMap(), (DbEntity) object);
    } else if (object instanceof ObjEntity) {
        undo = new RemoveUndoableEdit(((ObjEntity) object).getDataMap(), (ObjEntity) object);
        removeObjEntity(((ObjEntity) object).getDataMap(), (ObjEntity) object);
    } else if (object instanceof QueryDescriptor) {
        undo = new RemoveUndoableEdit(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
        removeQuery(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
    } else if (object instanceof Procedure) {
        undo = new RemoveUndoableEdit(((Procedure) object).getDataMap(), (Procedure) object);
        removeProcedure(((Procedure) object).getDataMap(), (Procedure) object);
    } else if (object instanceof Embeddable) {
        undo = new RemoveUndoableEdit(((Embeddable) object).getDataMap(), (Embeddable) object);
        removeEmbeddable(((Embeddable) object).getDataMap(), (Embeddable) object);
    }
    return undo;
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) RemoveCallbackMethodUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit) UndoableEdit(javax.swing.undo.UndoableEdit) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) RemoveCompoundUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Procedure(org.apache.cayenne.map.Procedure) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable)

Example 8 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project jdk8u_jdk by JetBrains.

the class GapContent method remove.

/**
     * Removes part of the content.
     *
     * @param where the starting position >= 0, where + nitems < length()
     * @param nitems the number of characters to remove >= 0
     * @return an UndoableEdit object for undoing
     * @exception BadLocationException if the specified position is invalid
     * @see AbstractDocument.Content#remove
     */
public UndoableEdit remove(int where, int nitems) throws BadLocationException {
    if (where + nitems >= length()) {
        throw new BadLocationException("Invalid remove", length() + 1);
    }
    String removedString = getString(where, nitems);
    UndoableEdit edit = new RemoveUndo(where, removedString);
    replace(where, nitems, empty, 0);
    return edit;
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit) AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit)

Example 9 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project jdk8u_jdk by JetBrains.

the class DefaultStyledDocument method insert.

/**
     * Inserts new elements in bulk.  This is useful to allow
     * parsing with the document in an unlocked state and
     * prepare an element structure modification.  This method
     * takes an array of tokens that describe how to update an
     * element structure so the time within a write lock can
     * be greatly reduced in an asynchronous update situation.
     * <p>
     * This method is thread safe, although most Swing methods
     * are not. Please see
     * <A HREF="https://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">Concurrency
     * in Swing</A> for more information.
     *
     * @param offset the starting offset &gt;= 0
     * @param data the element data
     * @exception BadLocationException for an invalid starting offset
     */
protected void insert(int offset, ElementSpec[] data) throws BadLocationException {
    if (data == null || data.length == 0) {
        return;
    }
    try {
        writeLock();
        // install the content
        Content c = getContent();
        int n = data.length;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            ElementSpec es = data[i];
            if (es.getLength() > 0) {
                sb.append(es.getArray(), es.getOffset(), es.getLength());
            }
        }
        if (sb.length() == 0) {
            // Nothing to insert, bail.
            return;
        }
        UndoableEdit cEdit = c.insertString(offset, sb.toString());
        // create event and build the element structure
        int length = sb.length();
        DefaultDocumentEvent evnt = new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.INSERT);
        evnt.addEdit(cEdit);
        buffer.insert(offset, length, data, evnt);
        // update bidi (possibly)
        super.insertUpdate(evnt, null);
        // notify the listeners
        evnt.end();
        fireInsertUpdate(evnt);
        fireUndoableEditUpdate(new UndoableEditEvent(this, evnt));
    } finally {
        writeUnlock();
    }
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit) AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit)

Example 10 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project jdk8u_jdk by JetBrains.

the class DefaultStyledDocument method create.

/**
     * Initialize the document to reflect the given element
     * structure (i.e. the structure reported by the
     * <code>getDefaultRootElement</code> method.  If the
     * document contained any data it will first be removed.
     */
protected void create(ElementSpec[] data) {
    try {
        if (getLength() != 0) {
            remove(0, getLength());
        }
        writeLock();
        // install the content
        Content c = getContent();
        int n = data.length;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            ElementSpec es = data[i];
            if (es.getLength() > 0) {
                sb.append(es.getArray(), es.getOffset(), es.getLength());
            }
        }
        UndoableEdit cEdit = c.insertString(0, sb.toString());
        // build the event and element structure
        int length = sb.length();
        DefaultDocumentEvent evnt = new DefaultDocumentEvent(0, length, DocumentEvent.EventType.INSERT);
        evnt.addEdit(cEdit);
        buffer.create(length, data, evnt);
        // update bidi (possibly)
        super.insertUpdate(evnt, null);
        // notify the listeners
        evnt.end();
        fireInsertUpdate(evnt);
        fireUndoableEditUpdate(new UndoableEditEvent(this, evnt));
    } catch (BadLocationException ble) {
        throw new StateInvariantError("problem initializing");
    } finally {
        writeUnlock();
    }
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit) AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit)

Aggregations

UndoableEdit (javax.swing.undo.UndoableEdit)16 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)4 DataMap (org.apache.cayenne.map.DataMap)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 List (java.util.List)1 UndoableEditEvent (javax.swing.event.UndoableEditEvent)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 DbEntity (org.apache.cayenne.map.DbEntity)1 Embeddable (org.apache.cayenne.map.Embeddable)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 Procedure (org.apache.cayenne.map.Procedure)1 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)1 PasteCompoundUndoableEdit (org.apache.cayenne.modeler.undo.PasteCompoundUndoableEdit)1 PasteUndoableEdit (org.apache.cayenne.modeler.undo.PasteUndoableEdit)1 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)1 RemoveCallbackMethodUndoableEdit (org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit)1 RemoveCompoundUndoableEdit (org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit)1 RemoveRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit)1 RemoveUndoableEdit (org.apache.cayenne.modeler.undo.RemoveUndoableEdit)1