use of javax.swing.undo.CompoundEdit in project jabref by JabRef.
the class EntryFromFileCreatorManager method addEntriesFromFiles.
/**
* Tries to add a entry for each file in the List.
*
* @param files
* @param database
* @param panel
* @param entryType
* @param generateKeywordsFromPathToFile
* @param changeListener
* @param importGUIMessages list of unexpected import event - Messages including
* failures
* @return Returns The number of entries added
*/
public int addEntriesFromFiles(List<File> files, BibDatabase database, BasePanel panel, EntryType entryType, boolean generateKeywordsFromPathToFile, ChangeListener changeListener, List<String> importGUIMessages) {
int count = 0;
CompoundEdit ce = new CompoundEdit();
for (File f : files) {
EntryFromFileCreator creator = getEntryCreator(f);
if (creator == null) {
importGUIMessages.add("Problem importing " + f.getPath() + ": Unknown filetype.");
} else {
Optional<BibEntry> entry = creator.createEntry(f, generateKeywordsFromPathToFile);
if (!entry.isPresent()) {
importGUIMessages.add("Problem importing " + f.getPath() + ": Entry could not be created.");
continue;
}
if (entryType != null) {
entry.get().setType(entryType);
}
if (entry.get().getId() == null) {
entry.get().setId(IdGenerator.next());
}
/*
* TODO: database.insertEntry(BibEntry) is not sensible. Why
* does 'true' mean "There were duplicates", while 'false' means
* "Everything alright"?
*/
if (!database.containsEntryWithId(entry.get().getId())) {
// Therefore, we only insert the entry if it is not already present
if (database.insertEntry(entry.get())) {
importGUIMessages.add("Problem importing " + f.getPath() + ": Insert into BibDatabase failed.");
} else {
count++;
if (panel != null) {
ce.addEdit(new UndoableInsertEntry(database, entry.get(), panel));
}
}
}
}
if (changeListener != null) {
changeListener.stateChanged(new ChangeEvent(this));
}
}
if ((count > 0) && (panel != null)) {
ce.end();
panel.getUndoManager().addEdit(ce);
}
return count;
}
use of javax.swing.undo.CompoundEdit in project cayenne by apache.
the class RemoveAction method performAction.
/**
* Performs delete action
*
* @param allowAsking If false, no question will be asked no matter what settings are
*/
public void performAction(ActionEvent e, boolean allowAsking) {
ProjectController mediator = getProjectController();
ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
if (mediator.getCurrentObjEntity() != null) {
if (dialog.shouldDelete("ObjEntity", mediator.getCurrentObjEntity().getName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentObjEntity()));
removeObjEntity(mediator.getCurrentDataMap(), mediator.getCurrentObjEntity());
}
} else if (mediator.getCurrentDbEntity() != null) {
if (dialog.shouldDelete("DbEntity", mediator.getCurrentDbEntity().getName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentDbEntity()));
removeDbEntity(mediator.getCurrentDataMap(), mediator.getCurrentDbEntity());
}
} else if (mediator.getCurrentQuery() != null) {
if (dialog.shouldDelete("query", mediator.getCurrentQuery().getName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentQuery()));
removeQuery(mediator.getCurrentDataMap(), mediator.getCurrentQuery());
}
} else if (mediator.getCurrentProcedure() != null) {
if (dialog.shouldDelete("procedure", mediator.getCurrentProcedure().getName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentProcedure()));
removeProcedure(mediator.getCurrentDataMap(), mediator.getCurrentProcedure());
}
} else if (mediator.getCurrentEmbeddable() != null) {
if (dialog.shouldDelete("embeddable", mediator.getCurrentEmbeddable().getClassName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentEmbeddable()));
removeEmbeddable(mediator.getCurrentDataMap(), mediator.getCurrentEmbeddable());
}
} else if (mediator.getCurrentDataMap() != null) {
if (dialog.shouldDelete("data map", mediator.getCurrentDataMap().getName())) {
// In context of Data node just remove from Data Node
if (mediator.getCurrentDataNode() != null) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataNode(), mediator.getCurrentDataMap()));
removeDataMapFromDataNode(mediator.getCurrentDataNode(), mediator.getCurrentDataMap());
} else {
// Not under Data Node, remove completely
application.getUndoManager().addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataMap()));
removeDataMap(mediator.getCurrentDataMap());
}
}
} else if (mediator.getCurrentDataNode() != null) {
if (dialog.shouldDelete("data node", mediator.getCurrentDataNode().getName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataNode()));
removeDataNode(mediator.getCurrentDataNode());
}
} else if (mediator.getCurrentPaths() != null) {
// multiple deletion
if (dialog.shouldDelete("selected objects")) {
ConfigurationNode[] paths = mediator.getCurrentPaths();
ConfigurationNode parentPath = mediator.getCurrentParentPath();
CompoundEdit compoundEdit = new RemoveCompoundUndoableEdit();
for (ConfigurationNode path : paths) {
compoundEdit.addEdit(removeLastPathComponent(path, parentPath));
}
compoundEdit.end();
application.getUndoManager().addEdit(compoundEdit);
}
} else if (mediator.getCurrentCallbackMethods().length > 0) {
removeMethods(mediator, dialog, getProjectController().getCurrentCallbackMethods());
} else if (mediator.getCurrentObjRelationships().length > 0) {
removeObjRelationships(mediator, dialog, getProjectController().getCurrentObjRelationships());
} else if (mediator.getCurrentDbRelationships().length > 0) {
removeDBRelationships(mediator, dialog, getProjectController().getCurrentDbRelationships());
} else if (mediator.getCurrentObjAttributes().length > 0) {
removeObjAttributes(mediator, dialog, getProjectController().getCurrentObjAttributes());
} else if (mediator.getCurrentEmbAttributes().length > 0) {
removeEmbAttributes(mediator, dialog, getProjectController().getCurrentEmbAttributes());
} else if (mediator.getCurrentDbAttributes().length > 0) {
removeDbAttributes(mediator, dialog, getProjectController().getCurrentDbAttributes());
} else if (mediator.getCurrentProcedureParameters().length > 0) {
removeProcedureParameters(mediator.getCurrentProcedure(), mediator.getCurrentProcedureParameters());
}
}
use of javax.swing.undo.CompoundEdit in project languagetool by languagetool-org.
the class UndoRedoSupport method startCompoundEdit.
/**
* Notify manager to start merging undoable edits.
*
* Calling startCompoundEdit when already in compound mode is an error
* and will throw a RuntimeException.
*
* @since 2.7
*/
void startCompoundEdit() {
if (compoundMode) {
throw new RuntimeException("already in compound mode");
}
ce = new CompoundEdit();
compoundMode = true;
}
Aggregations