Search in sources :

Example 1 with PasteUndoableEdit

use of org.apache.cayenne.modeler.undo.PasteUndoableEdit 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 instanceof DataMap) {
            currentObject = getProjectController().getProject().getRootNode();
        }
        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)

Aggregations

UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 List (java.util.List)1 UndoableEdit (javax.swing.undo.UndoableEdit)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataMap (org.apache.cayenne.map.DataMap)1 PasteCompoundUndoableEdit (org.apache.cayenne.modeler.undo.PasteCompoundUndoableEdit)1 PasteUndoableEdit (org.apache.cayenne.modeler.undo.PasteUndoableEdit)1