public void testTrivialChunk() throws Exception { content = ""; StyledDocument d = support.openDocument(); // same operations as testSingleChunk, // but don't test modified/canUndo/canRedo state CompoundEdit ce = beginChunk(d); d.insertString(d.getLength(), "a", null); d.insertString(d.getLength(), "b", null); endChunk(d, ce); assertEquals("data", "ab", d.getText(0, d.getLength())); ur().undo(); assertEquals("after undo data", "", d.getText(0, d.getLength())); ur().redo(); assertEquals("after redo data", "ab", d.getText(0, d.getLength())); }
@Override public void hookableActionPerformed(ActionEvent e) { final Record r = getEditor().currentRecord(); final Tier<PhoneMap> alignmentTier = r.getPhoneAlignment(); final CompoundEdit edit = new CompoundEdit(); final PhoneAligner aligner = new PhoneAligner(); for(int i = 0; i < r.numberOfGroups(); i++) { final Group group = r.getGroup(i); final PhoneMap newPm = aligner.calculatePhoneMap(group.getIPATarget(), group.getIPAActual()); final TierEdit<PhoneMap> ed = new TierEdit<PhoneMap>(getEditor(), alignmentTier, i, newPm); ed.doIt(); edit.addEdit(ed); } final EditorEvent ee = new EditorEvent(EditorEventType.TIER_CHANGED_EVT, getView(), SystemTierType.SyllableAlignment.getName()); getEditor().getEventManager().queueEvent(ee); edit.end(); getEditor().getUndoSupport().postEdit(edit); }
@Override public void hookableActionPerformed(ActionEvent e) { final SyllabifierInfo info = getEditor().getSession().getExtension(SyllabifierInfo.class); final Record r = getEditor().currentRecord(); final Tier<IPATranscript> tier = r.getTier(ipaTier, IPATranscript.class); if(tier == null) return; final SyllabifierLibrary library = SyllabifierLibrary.getInstance(); Language syllabifierLanguage = info.getSyllabifierLanguageForTier(tier.getName()); if(syllabifierLanguage == null) syllabifierLanguage = library.defaultSyllabifierLanguage(); final Syllabifier syllabifier = library.getSyllabifierForLanguage(syllabifierLanguage); final CompoundEdit edit = new CompoundEdit(); for(int i = 0; i < tier.numberOfGroups(); i++) { final SyllabifyEdit ed = new SyllabifyEdit(getEditor(), tier, i, syllabifier); ed.doIt(); edit.addEdit(ed); } edit.end(); getEditor().getUndoSupport().postEdit(edit); }
@Override public void hookableActionPerformed(ActionEvent e) { final SessionEditor editor = getEditor(); final Session session = editor.getSession(); final CompoundEdit edit = new CompoundEdit(); final RemoveParticipantEdit removePartEdit = new RemoveParticipantEdit(editor, participant); removePartEdit.doIt(); edit.addEdit(removePartEdit); for(Record r:session.getRecords()) { if(r.getSpeaker() == participant) { final ChangeSpeakerEdit chSpeakerEdit = new ChangeSpeakerEdit(editor, r, null); chSpeakerEdit.doIt(); edit.addEdit(chSpeakerEdit); } } edit.end(); editor.getUndoSupport().postEdit(edit); }
@Override public void hookableActionPerformed(ActionEvent e) { final CompoundEdit edit = new CompoundEdit(); for(int i = 0; i < tier.numberOfGroups(); i++) { final IPATranscript grp = tier.getGroup(i); final AlternativeTranscript alts = grp.getExtension(AlternativeTranscript.class); if(alts != null && alts.get(transcriber.getUsername()) != null) { final IPATranscript ipa = alts.get(transcriber.getUsername()); alts.setSelected(transcriber.getUsername()); ipa.putExtension(AlternativeTranscript.class, alts); final TierEdit<IPATranscript> tierEdit = new TierEdit<IPATranscript>(getEditor(), tier, i, ipa); tierEdit.doIt(); edit.addEdit(tierEdit); } } edit.end(); getEditor().getUndoSupport().postEdit(edit); }
/** * Unabbreviate the journal name of the given entry. * * @param entry The entry to be treated. * @param fieldName The field name (e.g. "journal") * @param ce If the entry is changed, add an edit to this compound. * @return true if the entry was changed, false otherwise. */ public boolean unabbreviate(BibDatabase database, BibEntry entry, String fieldName, CompoundEdit ce) { if (!entry.hasField(fieldName)) { return false; } String text = entry.getField(fieldName).get(); String origText = text; if (database != null) { text = database.resolveForStrings(text); } if (!journalAbbreviationRepository.isKnownName(text)) { return false; // cannot do anything if it is not known } if (!journalAbbreviationRepository.isAbbreviatedName(text)) { return false; // cannot unabbreviate unabbreviated name. } Abbreviation abbreviation = journalAbbreviationRepository.getAbbreviation(text).get(); // must be here String newText = abbreviation.getName(); entry.setField(fieldName, newText); ce.addEdit(new UndoableFieldChange(entry, fieldName, origText, newText)); return true; }
/** * Abbreviate the journal name of the given entry. * * @param database The database the entry belongs to, or null if no database. * @param entry The entry to be treated. * @param fieldName The field name (e.g. "journal") * @param ce If the entry is changed, add an edit to this compound. * @return true if the entry was changed, false otherwise. */ public boolean abbreviate(BibDatabase database, BibEntry entry, String fieldName, CompoundEdit ce) { if (!entry.hasField(fieldName)) { return false; } String text = entry.getField(fieldName).get(); String origText = text; if (database != null) { text = database.resolveForStrings(text); } if (!journalAbbreviationRepository.isKnownName(text)) { return false; // unknown, cannot un/abbreviate anything } String newText = getAbbreviatedName(journalAbbreviationRepository.getAbbreviation(text).get()); if (newText.equals(origText)) { return false; } entry.setField(fieldName, newText); ce.addEdit(new UndoableFieldChange(entry, fieldName, origText, newText)); return true; }
/** * Adds the specified node as a child of the current root. The group contained in <b>newGroups </b> must not be of * type AllEntriesGroup, since every tree has exactly one AllEntriesGroup (its root). The <b>newGroups </b> are * inserted directly, i.e. they are not deepCopy()'d. */ private static void addGroups(GroupTreeNode newGroups, CompoundEdit ce) { // paranoia: ensure that there are never two instances of AllEntriesGroup if (newGroups.getGroup() instanceof AllEntriesGroup) { return; // this should be impossible anyway } Globals.stateManager.getActiveDatabase() .map(BibDatabaseContext::getMetaData) .flatMap(MetaData::getGroups) .ifPresent(newGroups::moveTo); //UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, // new GroupTreeNodeViewModel(newGroups), UndoableAddOrRemoveGroup.ADD_NODE); //ce.addEdit(undo); }
public void beginCompoundEdit(final String name) { CompoundEdit edit = new CompoundEdit() { private static final long serialVersionUID = 2894975385303438798L; @Override public String getPresentationName() { return name; } }; compoundEdits.push(edit); }
private UndoableEditDelegate(UndoableEdit ed, DataObject dob, RefactoringSession session) { undoManager = UndoManager.getDefault(); ces = dob.getLookup().lookup(CloneableEditorSupport.class); //this.delegate = ed; this.inner = new CompoundEdit(); inner.addEdit(ed); delegate = ed; this.session = session; }
public void testSingleChunk() throws Exception { content = ""; StyledDocument d = support.openDocument(); assertFalse("initially: not modified", support.isModified()); assertFalse("initially: no undo", ur().canUndo()); assertFalse("initially: no redo", ur().canRedo()); CompoundEdit ce = beginChunk(d); assertFalse("start chunk: not modified", support.isModified()); assertFalse("start chunk: no undo", ur().canUndo()); assertFalse("start chunk: no redo", ur().canRedo()); d.insertString(d.getLength(), "a", null); assertTrue("insert: modified", support.isModified()); assertTrue("insert: can undo", ur().canUndo()); assertFalse("insert: no redo", ur().canRedo()); d.insertString(d.getLength(), "b", null); endChunk(d, ce); assertEquals("chunk: data", "ab", d.getText(0, d.getLength())); assertTrue("endChunk: modified", support.isModified()); assertTrue("endChunk: can undo", ur().canUndo()); assertFalse("endChunk: no redo", ur().canRedo()); ur().undo(); assertEquals("after undo: data", "", d.getText(0, d.getLength())); assertFalse("undo: not modified", support.isModified()); assertFalse("undo: no undo", ur().canUndo()); assertTrue("undo: can redo", ur().canRedo()); ur().redo(); assertEquals("after redo: data", "ab", d.getText(0, d.getLength())); assertTrue("redo: modified", support.isModified()); assertTrue("redo: can undo", ur().canUndo()); assertFalse("redo: no redo", ur().canRedo()); }
public void testNestedChunks() throws Exception { content = ""; StyledDocument d = support.openDocument(); CompoundEdit ce1 = beginChunk(d); d.insertString(d.getLength(), "a", null); d.insertString(d.getLength(), "b", null); CompoundEdit ce2 = beginChunk(d); // creates a separate undoable chunk d.insertString(d.getLength(), "c", null); d.insertString(d.getLength(), "d", null); endChunk(d, ce1); d.insertString(d.getLength(), "e", null); d.insertString(d.getLength(), "f", null); endChunk(d, ce2); assertEquals("data", "abcdef", d.getText(0, d.getLength())); // following fails if nesting not supported ur().undo(); assertEquals("undo1", "abcd", d.getText(0, d.getLength())); ur().undo(); assertEquals("undo2", "ab", d.getText(0, d.getLength())); ur().undo(); assertEquals("undo3", "", d.getText(0, d.getLength())); }
private UndoableEditDelegate(UndoableEdit ed, BaseDocument doc, InstantRefactoringPerformer performer) { DataObject dob = (DataObject) doc.getProperty(BaseDocument.StreamDescriptionProperty); this.ces = dob.getLookup().lookup(CloneableEditorSupport.class); this.inner = new CompoundEdit(); this.inner.addEdit(ed); this.delegate = ed; this.performer = performer; }
/** * This is called as part of {@link #syncSill} to add needed panels undoably. */ private void fillIn(final int loop, final Sill sill, final CompoundEdit compoundEdit) { if (loop>sill.size()-1) { Sill addition = new Sill(); addition.setName(AbstractNamed.NAMES_TEXT.getString("panelLabel")+" "+(loop+1)); MysteryAddEdit createEdit = new MysteryAddEdit(sill, addition); createEdit.execute(); compoundEdit.addEdit(createEdit); } }
/** * This is called as part of {@link #syncSill} to remove unneeded panels undoably. */ private void trimFat(final Sill sill, final CompoundEdit compoundEdit) { if (sill.size()>=apertureQuantity) // TODO move this outside optimization loop { TrimExcessItemsEdit trimEdit = new TrimExcessItemsEdit(sill, apertureQuantity); trimEdit.execute(); compoundEdit.addEdit(trimEdit); } }
/** * Adds all of the accumulated edits from this sill reconstruction to the * designated compound edit. */ public void addAllTo(CompoundEdit designatedCompoundEdit) { Iterator walk = map.values().iterator(); while (walk.hasNext()) { RebuildSillEdit rebuildSillEdit = (RebuildSillEdit) walk.next(); designatedCompoundEdit.addEdit(rebuildSillEdit); } }
public void testAddChildren() throws Exception { SQLTable table = new SQLTable(new StubSQLObject(), "table", "", "", true); int childCount = table.getChildCount(); CompoundEdit transaction = new CompEdit(); SQLColumn column1 = new SQLColumn(); column1.setName("cow"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column1, 0, EventType.ADDED))); SQLColumn column2 = new SQLColumn(); column2.setName("chicken"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column2, 1, EventType.ADDED))); SQLColumn column3 = new SQLColumn(); column3.setName("fish"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column3, 2, EventType.ADDED))); SQLColumn column4 = new SQLColumn(); column4.setName("sheep"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column4, 3, EventType.ADDED))); SQLColumn column5 = new SQLColumn(); column5.setName("dog"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column5, 4, EventType.ADDED))); SQLColumn column6 = new SQLColumn(); column6.setName("cat"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column6, 5, EventType.ADDED))); SQLColumn column7 = new SQLColumn(); column7.setName("bear"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column7, 6, EventType.ADDED))); transaction.redo(); assertEquals(childCount + 7, table.getChildCount()); assertEquals(column1, table.getChild(0)); assertEquals(column2, table.getChild(1)); }
public void testAllowCompoundEdit() { UndoableEdit stubEdit1 = new AbstractUndoableEdit(); UndoableEdit stubEdit2 = new AbstractUndoableEdit(); UndoableEdit stubEdit3 = new AbstractUndoableEdit(); CompoundEdit ce = new CompoundEdit(); ce.addEdit(stubEdit1); ce.addEdit(stubEdit2); ce.addEdit(stubEdit3); ce.end(); undoManager.addEdit(ce); assertTrue(undoManager.canUndo()); }
/** * Begins a compound edit. Compound edits can be nested, so every call * to this method has to be balanced with a call to * {@link #compoundGroupEnd()}. * * fires a state changed event when a new compound edit is created */ private void compoundGroupStart() { undoCount++; if (undoCount == 1) { ce = new CompoundEdit(); } if (logger.isDebugEnabled()) { logger.debug("compoundGroupStart: edit stack =" + undoCount); } }
@Override public void propertyChanged(PropertyChangeEvent evt) { hasChanged = true; logger.debug("Watcher: " + this + ", Property: " + evt.getPropertyName() + " from " + evt.getSource().toString() + " has changed."); logger.debug("old value: " + evt.getOldValue() + ", new value: " + evt.getNewValue()); if (((SPObject)evt.getSource()).isMagicEnabled()) { UndoableEdit ue = new MMOPropertyChangeUndoableEdit(evt); if ("UNDOSTATE".equals(evt.getPropertyName())) { boolean undoing = (Boolean) evt.getNewValue(); if (undoing) { logger.debug("Starting new compound edit with undoCount: " + undoCount); undoCount++; if (undoCount == 1) { ce = new CompoundEdit(); } } else { logger.debug("Ending compound edit with undoCount: " + undoCount); undoCount--; if (undoCount == 0) { ce.end(); undo.addEdit(ce); ce = null; } } } else if (undoCount > 0) { ce.addEdit(ue); } else { undo.addEdit(ue); } } else { if (!undo.canUndo()) { hasChanged = false; } pane.undoEventFired(evt); } swingSession.refreshUndoAction(); }
@Override public void actionPerformed(ActionEvent e) { final Record r = getRecord(); if(r.numberOfGroups() > 1) { // confirm final MessageDialogProperties props = new MessageDialogProperties(); props.setRunAsync(false); props.setTitle("Merge All Groups"); props.setHeader("Merge all groups"); props.setMessage("Merge all groups for current record?"); props.setOptions(MessageDialogProperties.okCancelOptions); final int retVal = NativeDialogs.showMessageDialog(props); if(retVal != 0) return; final CompoundEdit cmpEdit = new CompoundEdit(){ @Override public String getUndoPresentationName() { return "Undo merge all groups"; } @Override public String getRedoPresentationName() { return "Redo merge all groups"; } }; while(r.numberOfGroups() > 1) { final MergeGroupEdit edit = new MergeGroupEdit(getEditorView().getEditor(), r, 0); edit.doIt(); cmpEdit.addEdit(edit); } cmpEdit.end(); getEditorView().getEditor().getUndoSupport().postEdit(cmpEdit); } }
@Override public void actionPerformed(ActionEvent e) { int[] sel = table.getSelectedRows(); if (sel.length > 0) { // Make sure no cell is being edited, as caused by the // keystroke. This makes the content hang on the screen. assureNotEditing(); String msg = (sel.length > 1 ? Localization.lang("Really delete the %0 selected entries?", Integer.toString(sel.length)) : Localization.lang("Really delete the selected entry?")); int answer = JOptionPane.showConfirmDialog(parent, msg, Localization.lang("Delete strings"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.YES_OPTION) { CompoundEdit ce = new CompoundEdit(); for (int i = sel.length - 1; i >= 0; i--) { // Delete the strings backwards to avoid moving indexes. BibtexString subject = strings.get(sel[i]); // Store undo information: ce.addEdit(new UndoableRemoveString(panel, base, subject)); base.removeString(subject.getId()); } ce.end(); panel.getUndoManager().addEdit(ce); refreshTable(); if (!base.hasNoStrings()) { table.setRowSelectionInterval(0, 0); } } } }
/** * 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; }
private void moveItems(JDragDropList<? extends T> sourceList, JDragDropList<? super T> targetList, int[] sourceIndices, int destIndex) { StandardListModel<? extends T> sourceModel = sourceList.getModel(); StandardListModel<? super T> targetModel = targetList.getModel(); CompoundEdit edit = new CompoundEdit() { private static final long serialVersionUID = -8658162613932247385L; @Override public String getPresentationName() { return "Move"; } }; sourceModel.beginCompoundEdit(edit); try { targetModel.beginCompoundEdit(edit); try { for (int i = 0; i < sourceIndices.length; i++) { int index = sourceIndices[i]; T item = sourceModel.get(index); sourceModel.remove(index); for (int j = i + 1; j < sourceIndices.length; j++) { int value = sourceIndices[j]; if (value > index) { sourceIndices[j]--; } if (sourceModel == targetModel) { if (value >= destIndex) { sourceIndices[j]++; } } } if ((sourceModel == targetModel) && (index < destIndex)) { destIndex--; } targetModel.add(destIndex, item); destIndex++; } } finally { targetModel.endCompoundEdit(); } } finally { sourceModel.endCompoundEdit(); } targetList.setSelectionInterval(destIndex - sourceIndices.length, destIndex - 1); sourceList.updateUI(); targetList.updateUI(); }
public void beginCompoundEdit(CompoundEdit edit) { compoundEdits.push(edit); }
public void endCompoundEdit() { CompoundEdit edit = compoundEdits.pop(); edit.end(); addEdit(edit); }
public void testDeleteEachTenthCharFromDocument() throws Exception { StringBuffer sb = new StringBuffer(); for (int i = 0; i < 20; i++) { for (int j = 0; j < 10; j++) { sb.append((char)('0' + j)); } } content = sb.toString(); StyledDocument doc = support.openDocument(); assertEquals("200 chars there", 200, doc.getLength()); CompoundEdit bigEdit = new CompoundEdit(); support.getUndoRedo().undoableEditHappened(new UndoableEditEvent(doc, bigEdit)); assertTrue("Big edit will consume other edits", bigEdit.isInProgress()); for (int i = 199; i >= 0; i -= 10) { doc.remove(i, 1); } assertTrue("Big edit was still in consume mode", bigEdit.isInProgress()); bigEdit.end(); assertFalse("Big edit is over", bigEdit.isInProgress()); assertTrue("Document is modified", modified); assertTrue("We can undo", support.getUndoRedo().canUndo()); if (doc.getText(0, doc.getLength()).indexOf('9') != -1) { fail("There should be no 9 in the doc:\n" + doc.getText(0, doc.getLength())); } support.getUndoRedo().undo(); assertEquals("Again 200", 200, doc.getLength()); assertFalse("Not modified anymore", modified); assertTrue("We can redo", support.getUndoRedo().canRedo()); support.getUndoRedo().redo(); assertTrue("Document is modified", modified); assertTrue("We can undo", support.getUndoRedo().canUndo()); if (doc.getText(0, doc.getLength()).indexOf('9') != -1) { fail("There should be no 9 in the doc:\n" + doc.getText(0, doc.getLength())); } }
public void testDeleteEachTenthCharOnModifiedDocument() throws Exception { StyledDocument doc = support.openDocument(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < 20; i++) { for (int j = 0; j < 10; j++) { sb.append((char)('0' + j)); } } assertEquals("empty", 0, doc.getLength()); doc.insertString(0, sb.toString(), null); assertEquals("200 chars there", 200, doc.getLength()); CompoundEdit bigEdit = new CompoundEdit(); support.getUndoRedo().undoableEditHappened(new UndoableEditEvent(doc, bigEdit)); assertTrue("Big edit will consume other edits", bigEdit.isInProgress()); for (int i = 199; i >= 0; i -= 10) { doc.remove(i, 1); } assertTrue("Big edit was still in consume mode", bigEdit.isInProgress()); bigEdit.end(); assertFalse("Big edit is over", bigEdit.isInProgress()); assertTrue("Document is modified", modified); assertTrue("We can undo", support.getUndoRedo().canUndo()); if (doc.getText(0, doc.getLength()).indexOf('9') != -1) { fail("There should be no 9 in the doc:\n" + doc.getText(0, doc.getLength())); } support.getUndoRedo().undo(); assertEquals("Again 200", 200, doc.getLength()); assertTrue("Still modified", modified); assertTrue("We can redo", support.getUndoRedo().canRedo()); support.getUndoRedo().redo(); assertTrue("Document is modified", modified); assertTrue("We can undo", support.getUndoRedo().canUndo()); if (doc.getText(0, doc.getLength()).indexOf('9') != -1) { fail("There should be no 9 in the doc:\n" + doc.getText(0, doc.getLength())); } }
CompoundEdit beginChunk(Document d) { sendUndoableEdit(d, CloneableEditorSupport.BEGIN_COMMIT_GROUP); return null; }
void endChunk(Document d, CompoundEdit ce) { sendUndoableEdit(d, CloneableEditorSupport.END_COMMIT_GROUP); }
/** this also tests mixing regular and chunks */ public void testExtraEndChunk() throws Exception { content = ""; StyledDocument d = support.openDocument(); CompoundEdit ce = beginChunk(d); d.insertString(d.getLength(), "a", null); d.insertString(d.getLength(), "b", null); endChunk(d, ce); assertEquals("chunk: data", "ab", d.getText(0, d.getLength())); Level level = disableWarning(); try { endChunk(d, ce); endChunk(d, ce); assertEquals("extraEnd: data", "ab", d.getText(0, d.getLength())); assertTrue("extraEnd: modified", support.isModified()); assertTrue("extraEnd: can undo", ur().canUndo()); assertFalse("extraEnd: no redo", ur().canRedo()); d.insertString(d.getLength(), "c", null); d.insertString(d.getLength(), "d", null); endChunk(d, ce); assertEquals("extraEnd2: data", "abcd", d.getText(0, d.getLength())); ur().undo(); endChunk(d, ce); if (!documentSupportsUndoMergingOfWords()) { assertEquals("undo1: data", "abc", d.getText(0, d.getLength())); ur().undo(); } assertEquals("undo2: data", "ab", d.getText(0, d.getLength())); ur().undo(); endChunk(d, ce); assertEquals("undo3: data", "", d.getText(0, d.getLength())); ur().redo(); assertEquals("redo1: data", "ab", d.getText(0, d.getLength())); ur().redo(); endChunk(d, ce); if (!documentSupportsUndoMergingOfWords()) { assertEquals("redo2: data", "abc", d.getText(0, d.getLength())); ur().redo(); } assertEquals("redo3: data", "abcd", d.getText(0, d.getLength())); } finally { enableWarning(level); } }
public void testUndoRedoWhileActiveChunk() throws Exception { content = ""; StyledDocument d = support.openDocument(); CompoundEdit ce = beginChunk(d); d.insertString(d.getLength(), "a", null); d.insertString(d.getLength(), "b", null); assertEquals("before undo: data", "ab", d.getText(0, d.getLength())); ur().undo(); // These asserts assume that an undo in the middle of a chunk // is an undo on the whole chunk so far. assertEquals("after undo: data", "", d.getText(0, d.getLength())); assertFalse("after undo: not modified", support.isModified()); assertFalse("after undo: no undo", ur().canUndo()); assertTrue("after undo: can redo", ur().canRedo()); // note still in the chunk. ur().redo(); assertEquals("after redo: data", "ab", d.getText(0, d.getLength())); assertTrue("after redo: modified", support.isModified()); assertTrue("after redo: can undo", ur().canUndo()); assertFalse("after redo: no redo", ur().canRedo()); ur().undo(); assertEquals("after undo: data", "", d.getText(0, d.getLength())); // note still in the chunk. d.insertString(d.getLength(), "c", null); d.insertString(d.getLength(), "d", null); endChunk(d, ce); assertEquals("after endChunk: data", "cd", d.getText(0, d.getLength())); assertTrue("after endChunk: modified", support.isModified()); assertTrue("after endChunk: can undo", ur().canUndo()); assertFalse("after endChunk: no redo", ur().canRedo()); ur().undo(); assertEquals("undo after endChunk: data", "", d.getText(0, d.getLength())); assertFalse("undo after endChunk: not modified", support.isModified()); assertFalse("undo after endChunk: no undo", ur().canUndo()); assertTrue("undo after endChunk: can redo", ur().canRedo()); }
public void testSaveDocumentWhileActiveChunkCommon(boolean doFailCase) throws Exception { content = ""; StyledDocument d = support.openDocument(); CompoundEdit ce = beginChunk(d); d.insertString(d.getLength(), "a", null); d.insertString(d.getLength(), "b", null); support.saveDocument (); // creates a separate undoable chunk assertFalse("save: not modified", support.isModified()); assertTrue("save: can undo", ur().canUndo()); assertFalse("save: no redo", ur().canRedo()); d.insertString(d.getLength(), "c", null); d.insertString(d.getLength(), "d", null); endChunk(d, ce); assertEquals("insert, after save: data", "abcd", d.getText(0, d.getLength())); assertTrue("insert, after save: modified", support.isModified()); assertTrue("insert, after save: can undo", ur().canUndo()); assertFalse("insert, after save: no redo", ur().canRedo()); ur().undo(); assertEquals("undo, at save: data", "ab", d.getText(0, d.getLength())); assertFalse("undo, at save: not modified", support.isModified()); assertTrue("undo, at save: can undo", ur().canUndo()); assertTrue("undo, at save: can redo", ur().canRedo()); ur().undo(); assertEquals("undo, before save: data", "", d.getText(0, d.getLength())); if(doFailCase) { // **************************************************************** // CES BUG??? assertTrue("undo, before save: modified", support.isModified()); // **************************************************************** } assertFalse("undo, before save: can undo", ur().canUndo()); assertTrue("undo, before save: can redo", ur().canRedo()); ur().redo(); assertEquals("redo, at save: data", "ab", d.getText(0, d.getLength())); assertFalse("redo, at save: not modified", support.isModified()); assertTrue("redo, at save: can undo", ur().canUndo()); assertTrue("redo, at save: can redo", ur().canRedo()); }
protected CompoundEdit createModelUndoableEdit() { return new ModelUndoableEdit(); }
@Override protected CompoundEdit createCompoundEdit() { return createModelUndoableEdit(); }
protected void delete() { CompoundEdit deletes = new CompoundEdit(); for (GraphNode selNode : selectedNodes) { if (!selNode.isStartNode() && !selNode.isEndNode()) { //sterg nodul for (GraphNode graphNode : currentGraph.getGraphNodes().values()) {//sterg toate pathurile spre el if (!graphNode.getChildNodesIndexes().contains(selNode.getIndex())) continue; DeletePathCommand deletePathCommand = new DeletePathCommand(); deletePathCommand.start = graphNode; deletePathCommand.end = selNode; deletePathCommand.priorityIndex = graphNode.getChildNodesIndexes().indexOf(selNode.getIndex()); graphNode.getChildNodesIndexes().remove(deletePathCommand.priorityIndex); deletes.addEdit(deletePathCommand); } for (String clause : renderingInfos.get(selNode).matchingClauses) if (clause.startsWith(":")) { GrammarEditor.theEditor.mustRefreshGraphsTree = true; break; } selNode.getParentGraph().getGraphNodes().remove(selNode.getIndex()); DeleteNodeCommand deleteCommand = new DeleteNodeCommand(); deleteCommand.gn = selNode; deletes.addEdit(deleteCommand); } else { Toolkit.getDefaultToolkit().beep(); } } SelectNodesCommand selectCommand = new SelectNodesCommand(); selectCommand.editor = this; selectCommand.curentSelection = selectedNodes; selectCommand.prevSelection = new ArrayList<GraphNode>(selectedNodes); selectedNodes.clear(); selectCommand.nextSelection = new ArrayList<GraphNode>(); deletes.addEdit(selectCommand); deletes.end(); undoSupport.postEdit(deletes); updateUI(); }
protected GraphNode insertNode(int x, int y) { CompoundEdit compCommand = new CompoundEdit(); InsertNodeCommand insertCommand = new InsertNodeCommand(); GraphNode newGraphNode = new GraphNode(currentGraph.grammar); newGraphNode.setTokenMatchingCode("<<E>>"); x = x - 9; boolean ok; do { ok = true; for (GraphNode node : currentGraph.getGraphNodes().values()) { if (node.getX() == x && node.getY() == y) { x = x - 10; y = y - 10; ok = false; } } } while (!ok); newGraphNode.setX(x); newGraphNode.setY(y); newGraphNode.setParentGraph(currentGraph); renderingInfos.put(newGraphNode, new GraphNodeRenderingInfo(newGraphNode)); insertCommand.gn = newGraphNode; insertCommand.renderingInfos = renderingInfos; compCommand.addEdit(insertCommand); SelectNodesCommand selectCommand = new SelectNodesCommand(); selectCommand.editor = this; selectCommand.prevSelection = new ArrayList<GraphNode>(selectedNodes); selectCommand.curentSelection = selectedNodes; selectedNodes.clear(); selectedNodes.add(newGraphNode); selectCommand.nextSelection = new ArrayList<GraphNode>(selectedNodes); compCommand.addEdit(selectCommand); compCommand.end(); undoSupport.postEdit(compCommand); return newGraphNode; }
private HomeController(final Home home, final UserPreferences preferences, ViewFactory viewFactory, ContentManager contentManager, HomeApplication application) { this.home = home; this.preferences = preferences; this.viewFactory = viewFactory; this.contentManager = contentManager; this.application = application; this.undoSupport = new UndoableEditSupport() { @Override protected void _postEdit(UndoableEdit edit) { // Ignore not significant compound edit if (!(edit instanceof CompoundEdit) || edit.isSignificant()) { super._postEdit(edit); } } }; this.undoManager = new UndoManager(); this.undoSupport.addUndoableEditListener(this.undoManager); // Update recent homes list if (home.getName() != null) { List<String> recentHomes = new ArrayList<String>(this.preferences.getRecentHomes()); recentHomes.remove(home.getName()); recentHomes.add(0, home.getName()); updateUserPreferencesRecentHomes(recentHomes); // If home version is more recent than current version if (home.getVersion() > Home.CURRENT_VERSION) { // Warn the user that view will display a home created with a more recent version getView().invokeLater(new Runnable() { public void run() { String message = preferences.getLocalizedString(HomeController.class, "moreRecentVersionHome", home.getName()); getView().showMessage(message); } }); } } }
public void testRemoveChildren() throws Exception { SQLTable table = new SQLTable(new StubSQLObject(), "table", "", "", true); int childCount = table.getChildCount(); CompoundEdit transaction = new CompEdit(); SQLColumn column1 = new SQLColumn(); column1.setName("cow"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column1, 0, EventType.ADDED))); SQLColumn column2 = new SQLColumn(); column2.setName("chicken"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column2, 1, EventType.ADDED))); SQLColumn column3 = new SQLColumn(); column3.setName("fish"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column3, 2, EventType.ADDED))); SQLColumn column4 = new SQLColumn(); column4.setName("sheep"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column4, 3, EventType.ADDED))); SQLColumn column5 = new SQLColumn(); column5.setName("dog"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column5, 4, EventType.ADDED))); SQLColumn column6 = new SQLColumn(); column6.setName("cat"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column6, 5, EventType.ADDED))); SQLColumn column7 = new SQLColumn(); column7.setName("bear"); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column7, 6, EventType.ADDED))); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column2, 1, EventType.REMOVED))); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column3, 1, EventType.REMOVED))); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column6, 3, EventType.REMOVED))); transaction.addEdit(new SPObjectChildEdit(new SPChildEvent(table, SQLColumn.class, column7, 3, EventType.REMOVED))); transaction.redo(); assertEquals(childCount + 3, table.getChildCount()); assertEquals(column1, table.getChild(0)); assertEquals(column4, table.getChild(1)); assertEquals(column5, table.getChild(2)); }
private CompoundEdit startCompoundEdit(UndoableEdit anEdit) { // Track Caret and Document information of this compound edit AbstractDocument.DefaultDocumentEvent docEvt = (DefaultDocumentEvent) anEdit; // The compound edit is used to store incremental edits compoundEdit = new MyCompoundEdit(); compoundEdit.addEdit(anEdit); // The compound edit is added to the UndoManager. All incremental // edits stored in the compound edit will be undone/redone at once addEdit(compoundEdit); return compoundEdit; }