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);
}
}
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;
}
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;
}
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 >= 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();
}
}
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();
}
}
Aggregations