Java Code Examples for javax.swing.undo.UndoManager#redo()
The following examples show how to use
javax.swing.undo.UndoManager#redo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewHierarchyTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testLongLineUndo() throws Exception { loggingOn(); JEditorPane pane = ViewUpdatesTesting.createPane(); Document doc = pane.getDocument(); UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc); int lineLen = 4000; StringBuilder sb = new StringBuilder(lineLen + 10); for (int i = 0; i < lineLen; i++) { sb.append('a'); } sb.append('\n'); doc.insertString(0, sb.toString(), null); pane.modelToView(0); doc.remove(0, lineLen); pane.modelToView(0); undoManager.undo(); undoManager.redo(); }
Example 2
Source File: AbstractModelTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSyncUndoRedo() throws Exception { defaultSetup(); UndoManager urListener = new UndoManager(); mModel.addUndoableEditListener(urListener); assertEquals("setup: initial", 1, mModel.getRootComponent().getChildren(C.class).size()); Util.setDocumentContentTo(mDoc, "resources/test2.xml"); mModel.sync(); assertEquals("setup: sync", 0, mModel.getRootComponent().getChildren(C.class).size()); urListener.undo(); assertEquals("undo sync", 1, mModel.getRootComponent().getChildren(C.class).size()); urListener.redo(); assertEquals("undo sync", 0, mModel.getRootComponent().getChildren(C.class).size()); }
Example 3
Source File: AbstractModelTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testMultipleMutationUndoRedo() throws Exception { mModel = Util.loadModel("resources/Empty.xml"); UndoManager urListener = new UndoManager(); mModel.addUndoableEditListener(urListener); //setup mModel.startTransaction(); B b2 = new B(mModel, 2); mModel.getRootComponent().addAfter(b2.getName(), b2, TestComponent3._A); String v = "testComponentListener.b2"; b2.setValue(v); mModel.endTransaction(); b2 = mModel.getRootComponent().getChild(B.class); assertEquals(v, b2.getAttribute(TestAttribute3.VALUE)); urListener.undo(); b2 = mModel.getRootComponent().getChild(B.class); assertNull(b2); urListener.redo(); b2 = mModel.getRootComponent().getChild(B.class); assertEquals(v, b2.getAttribute(TestAttribute3.VALUE)); }
Example 4
Source File: AbstractModelTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testUndoRedoWithIdentity() throws Exception { mModel = Util.loadModel("resources/test1_name.xml"); UndoManager ur = new UndoManager(); mModel.addUndoableEditListener(ur); E e1 = mModel.getRootComponent().getChild(E.class); assertNull(e1.getValue()); mModel.startTransaction(); String v = "new test value"; e1.setValue(v); mModel.endTransaction(); assertEquals(v, e1.getValue()); ur.undo(); assertNull("expect null, get "+e1.getValue(), e1.getValue()); ur.redo(); assertEquals(v, e1.getValue()); }
Example 5
Source File: SyncTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSyncUndo() throws Exception { SchemaModel model = Util.loadSchemaModel(TEST_XSD); UndoManager um = new UndoManager(); model.addUndoableEditListener(um); GlobalComplexType gct = (GlobalComplexType)Util.findComponent( model.getSchema(), "/schema/complexType[@name='PurchaseOrderType']"); assertEquals(3, gct.getDefinition().getChildren().size()); Util.setDocumentContentTo(model, "resources/PurchaseOrder_SyncUndo.xsd"); model.sync(); um.undo(); assertEquals(3, gct.getDefinition().getChildren().size()); um.redo(); assertEquals(2, gct.getDefinition().getChildren().size()); }
Example 6
Source File: SyncTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSetAttributeOnGlobalComplexTypeUndoRedo() throws Exception { SchemaModel model = Util.loadSchemaModel("resources/PurchaseOrder.xsd"); UndoManager ur = new UndoManager(); model.addUndoableEditListener(ur); GlobalComplexType potype = model.getSchema().getComplexTypes().iterator().next(); assertEquals("PurchaseOrderType", potype.getName()); model.startTransaction(); potype.setAbstract(Boolean.TRUE); model.endTransaction(); ur.undo(); assertNull(potype.getAttribute(SchemaAttributes.ABSTRACT)); ur.redo(); assertNotNull(potype.getAttribute(SchemaAttributes.ABSTRACT)); }
Example 7
Source File: SyncTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testCreateGlobalElementUndoRedo() throws Exception { SchemaModel model = Util.loadSchemaModel("resources/Empty.xsd"); UndoManager ur = new UndoManager(); model.addUndoableEditListener(ur); SchemaComponentFactory fact = model.getFactory(); GlobalElement ge = fact.createGlobalElement(); model.startTransaction(); model.getSchema().addElement(ge); ge.setName("Foo"); // edit #1 LocalComplexType lct = fact.createLocalComplexType(); Sequence seq = fact.createSequence(); lct.setDefinition(seq); ge.setInlineType(lct); model.endTransaction(); assertEquals(1, model.getSchema().getElements().size()); ur.undo(); assertEquals(0, model.getSchema().getElements().size()); ur.redo(); ge = model.getSchema().getElements().iterator().next(); assertEquals("Foo", ge.getName()); assertNotNull(ge.getInlineType()); assertNotNull(((LocalComplexType)ge.getInlineType()).getDefinition()); }
Example 8
Source File: DefinitionsTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSetTypes() throws Exception { UndoManager um = new UndoManager(); WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.ECHOCONCAT); model.addUndoableEditListener(um); TestComponentListener cl = new TestComponentListener(); PropertyListener pl = new PropertyListener(); model.addComponentListener(cl); model.addPropertyChangeListener(pl); Definitions d = model.getDefinitions(); int childCount = d.getChildren().size(); Types types = d.getTypes(); assertNotNull(types); model.startTransaction(); d.setTypes(null); model.endTransaction(); cl.assertEvent(ComponentEvent.EventType.CHILD_REMOVED, d); pl.assertEvent(Definitions.TYPES_PROPERTY, types, null); um.undo(); assertEquals(childCount, d.getChildren().size()); um.redo(); assertEquals(childCount-1, d.getChildren().size()); }
Example 9
Source File: AbstractModelTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testUndoRedoWithoutIdentity() throws Exception { mModel = Util.loadModel("resources/test1_noname.xml"); UndoManager ur = new UndoManager(); mModel.addUndoableEditListener(ur); E e1 = mModel.getRootComponent().getChild(E.class); assertNull(e1.getValue()); mModel.startTransaction(); String v = "new test value"; e1.setValue(v); mModel.endTransaction(); assertEquals(v, e1.getValue()); ur.undo(); assertNull("expect null, get "+e1.getValue(), e1.getValue()); ur.redo(); assertEquals(v, e1.getValue()); }
Example 10
Source File: SchemaTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testDeleteRollback() throws Exception { UndoManager um = new UndoManager(); schema.getModel().addUndoableEditListener(um); GlobalElement stick = schema.getModel().getFactory().createGlobalElement(); stick.setName("stickAfterRollbackElement"); model.startTransaction(); schema.addElement(stick); model.endTransaction(); model.startTransaction(); ArrayList<GlobalComplexType> types = new ArrayList(schema.getComplexTypes()); ArrayList<GlobalElement> elements = new ArrayList(schema.getElements()); GlobalElement element = elements.get(0); if(element.getName().equals("purchaseOrder")) { schema.removeElement(element); String text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("purchaseOrder")== -1); ( (AbstractModel)model).rollbackTransaction(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("purchaseOrder") > 0); assertTrue(text.indexOf("stickAfterRollbackElement") > 0); um.undo(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("stickAfterRollbackElement") == -1); um.redo(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("stickAfterRollbackElement") > 0); } }
Example 11
Source File: SchemaTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testRollback() throws Exception { UndoManager um = new UndoManager(); schema.getModel().addUndoableEditListener(um); GlobalElement stick = schema.getModel().getFactory().createGlobalElement(); stick.setName("stickAfterRollbackElement"); model.startTransaction(); schema.addElement(stick); model.endTransaction(); GlobalElement ge = schema.getModel().getFactory().createGlobalElement(); ge.setName("newElement"); int initialCount = schema.getElements().size(); model.startTransaction(); schema.addElement(ge); assertEquals(initialCount+1, schema.getElements().size()); String text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("newElement") > 0); ( (AbstractModel)model).rollbackTransaction(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("newElement") == -1); assertEquals(initialCount, schema.getElements().size()); assertTrue(text.indexOf("stickAfterRollbackElement") > 0); um.undo(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("stickAfterRollbackElement") == -1); um.redo(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("stickAfterRollbackElement") > 0); }
Example 12
Source File: RedoAction.java From PIPE with MIT License | 5 votes |
@Override public void actionPerformed(ActionEvent actionEvent) { PetriNetController controller = applicationController.getActivePetriNetController(); UndoManager manager = controller.getUndoManager(); manager.redo(); this.setEnabled(manager.canRedo()); undoAction.setEnabled(manager.canUndo()); }
Example 13
Source File: SyncTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testSyncUndoUndo() throws Exception { SchemaModel model = Util.loadSchemaModel("resources/undoredotest.xsd"); UndoManager um = new UndoManager(); model.addUndoableEditListener(um); GlobalComplexType gct = (GlobalComplexType)Util.findComponent( model.getSchema(), "/schema/complexType[@name='USAddress']"); java.util.List<SchemaComponent> seqChildren = gct.getDefinition().getChildren(); assertEquals(3, seqChildren.size()); Util.setDocumentContentTo(model, "resources/undoredotest1.xsd"); model.sync(); assertEquals(3, seqChildren.size()); um.undo(); assertEquals(3, seqChildren.size()); um.redo(); assertEquals(3, seqChildren.size()); Util.setDocumentContentTo(model, "resources/undoredotest2.xsd"); model.sync(); assertEquals(3, seqChildren.size()); um.undo(); assertEquals(3, seqChildren.size()); um.undo(); assertEquals(3, seqChildren.size()); }
Example 14
Source File: UndoRedoTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testIssue83963_1() throws Exception { SchemaModel model = Util.loadSchemaModel("resources/undoredo.xsd"); BaseDocument doc = (BaseDocument) model.getModelSource(). getLookup().lookup(BaseDocument.class); Schema s = model.getSchema(); TestComponentListener listener = new TestComponentListener(); model.addComponentListener(listener); UndoManager ur = new UndoManager(); model.addUndoableEditListener(ur); doc.removeUndoableEditListener(ur); //System.out.println("doc before add ComplexType"+doc.getText(0, doc.getLength())); GlobalComplexType gct = model.getFactory().createGlobalComplexType(); doc.insertString(271, "<complexType/>",null); //System.out.println("doc after add ComplexType"+doc.getText(0, doc.getLength())); String stStr = " <xsd:simpleType name=\"lend\">\n <xsd:list>\n <xsd:simpleType>\n <xsd:restriction base=\"xsd:string\"/>\n </xsd:simpleType>\n </xsd:list>\n </xsd:simpleType>"; model.sync(); doc.insertString(285, "\n", null); model.sync(); doc.insertString(286, stStr, null); model.sync(); //System.out.println("doc after insert simpleType"+doc.getText(0, doc.getLength())); ur.undo(); //System.out.println("doc after first undo"+doc.getText(0, doc.getLength())); ur.undo(); //System.out.println("doc after second undo"+doc.getText(0, doc.getLength())); ur.undo(); //System.out.println("doc after third undo"+doc.getText(0, doc.getLength())); ur.redo(); //System.out.println("doc after first redo"+doc.getText(0, doc.getLength())); ur.redo(); //System.out.println("doc after second redo"+doc.getText(0, doc.getLength())); ur.redo(); //System.out.println("doc after third redo"+doc.getText(0, doc.getLength())); }
Example 15
Source File: SchemaTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testRenameRollback() throws Exception { UndoManager um = new UndoManager(); schema.getModel().addUndoableEditListener(um); GlobalElement stick = schema.getModel().getFactory().createGlobalElement(); stick.setName("stickAfterRollbackElement"); model.startTransaction(); schema.addElement(stick); model.endTransaction(); int initialCount = schema.getElements().size(); model.startTransaction(); ArrayList<GlobalComplexType> types = new ArrayList(schema.getComplexTypes()); ArrayList<GlobalElement> elements = new ArrayList(schema.getElements()); GlobalElement element = elements.get(0); if(element.getName().equals("purchaseOrder")) { element.setName("TestPurchaseOrder"); String text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("purchaseOrder")== -1); assertTrue(text.indexOf("TestPurchaseOrder") > 0); assertEquals(initialCount, schema.getElements().size()); ( (AbstractModel)model).rollbackTransaction(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("purchaseOrder") > 0); assertTrue(text.indexOf("TestPurchaseOrder") == -1); assertTrue(text.indexOf("stickAfterRollbackElement") > 0); assertEquals(initialCount, schema.getElements().size()); assertEquals("purchaseOrder", element.getName()); um.undo(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("stickAfterRollbackElement") == -1); um.redo(); text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText(); assertTrue(text.indexOf("stickAfterRollbackElement") > 0); } }
Example 16
Source File: SyncTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testCutAndPasteUndoRedo() throws Exception { SchemaModel model = Util.loadSchemaModel("resources/PurchaseOrder.xsd"); TestComponentListener listener = new TestComponentListener(); model.addComponentListener(listener); UndoManager ur = new UndoManager(); model.addUndoableEditListener(ur); ArrayList<GlobalComplexType> types = new ArrayList(model.getSchema().getComplexTypes()); GlobalComplexType type = types.get(1); assertEquals("USAddress", type.getName()); Sequence seq = (Sequence) type.getDefinition(); java.util.List<SequenceDefinition> content = seq.getContent(); LocalElement name = (LocalElement) content.get(0); assertEquals("name", name.getName()); LocalElement street = (LocalElement) content.get(1); assertEquals("street", street.getName()); Node nameNode = name.getPeer(); Node streetNode = street.getPeer(); SequenceDefinition copyName = (SequenceDefinition) name.copy(seq); SequenceDefinition copyStreet = (SequenceDefinition) street.copy(seq); model.startTransaction(); seq.removeContent(name); seq.removeContent(street); seq.addContent(copyStreet, 0); seq.addContent(copyName, 1); model.endTransaction(); content = seq.getContent(); name = (LocalElement) content.get(1); street = (LocalElement) content.get(0); assertEquals("name", name.getName()); assertEquals("street", street.getName()); Node nameNode1 = name.getPeer(); Node streetNode1 = street.getPeer(); ur.undo(); content = seq.getContent(); name = (LocalElement) content.get(0); street = (LocalElement) content.get(1); assertEquals("name", name.getName()); assertEquals("street", street.getName()); Node nameNode2 = name.getPeer(); Node streetNode2 = street.getPeer(); assertTrue(name.referencesSameNode(nameNode)); assertTrue(street.referencesSameNode(streetNode)); listener.reset(); ur.redo(); content = seq.getContent(); assertEquals(2, content.size()); name = (LocalElement) content.get(1); street = (LocalElement) content.get(0); assertEquals("name", name.getName()); assertEquals("street", street.getName()); Node nameNode3 = name.getPeer(); Node streetNode3 = street.getPeer(); assertTrue(name.referencesSameNode(nameNode1)); assertTrue(street.referencesSameNode(streetNode1)); listener.assertEvent(ComponentEvent.EventType.CHILD_REMOVED, seq); listener.assertEvent(ComponentEvent.EventType.CHILD_ADDED, seq); }
Example 17
Source File: UndoRedoTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testIssue83963() throws Exception { SchemaModel model = Util.loadSchemaModel("resources/undoredo.xsd"); BaseDocument doc = (BaseDocument) model.getModelSource(). getLookup().lookup(BaseDocument.class); Schema s = model.getSchema(); TestComponentListener listener = new TestComponentListener(); model.addComponentListener(listener); UndoManager ur = new UndoManager(); model.addUndoableEditListener(ur); String original = doc.getText(0, doc.getLength()); //System.out.println("doc before add ComplexType"+doc.getText(0, doc.getLength())); GlobalComplexType gct = model.getFactory().createGlobalComplexType(); model.startTransaction(); s.addComplexType(gct); model.endTransaction(); model.removeUndoableEditListener(ur); doc.addUndoableEditListener(ur); //System.out.println("doc after add ComplexType"+doc.getText(0, doc.getLength())); String stStr = " <xsd:simpleType name=\"lend\">\n <xsd:list>\n <xsd:simpleType>\n <xsd:restriction base=\"xsd:string\"/>\n </xsd:simpleType>\n </xsd:list>\n </xsd:simpleType>"; String afterInsert = doc.getText(0, doc.getLength()); //System.out.println("doc after insert simpleType"+doc.getText(290, 10)); // position was changing which is weird but doesn't matter for undo-redo testing int schemaTagPosition = afterInsert.length() - 10; doc.insertString(schemaTagPosition, "\n", null); model.sync(); doc.insertString(schemaTagPosition + 1, stStr, null); model.sync(); //System.out.println("doc after insert simpleType"+doc.getText(0, doc.getLength())); ur.undo(); //System.out.println("doc after first undo"+doc.getText(0, doc.getLength())); ur.undo(); assertEquals(afterInsert,doc.getText(0, doc.getLength())); //System.out.println("doc after second undo"+doc.getText(0, doc.getLength())); ur.undo(); //System.out.println("doc after third undo"+doc.getText(0, doc.getLength())); assertEquals(original, doc.getText(0, doc.getLength())); ur.redo(); assertEquals(afterInsert,doc.getText(0, doc.getLength())); //System.out.println("doc after first redo"+doc.getText(0, doc.getLength())); ur.redo(); //System.out.println("doc after second redo"+doc.getText(0, doc.getLength())); ur.redo(); //System.out.println("doc after third redo"+doc.getText(0, doc.getLength())); }
Example 18
Source File: AbstractModelTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testCutPasteUndoRedo() throws Exception { defaultSetup(); UndoManager urListener = new UndoManager(); mModel.addUndoableEditListener(urListener); mModel.startTransaction(); B b2 = new B(mModel, 2); mModel.getRootComponent().addAfter(b2.getName(), b2, TestComponent3._A); mModel.endTransaction(); assertEquals("first edit setup", 2, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("first edit setup", 1, mModel.getRootComponent().getChildren(C.class).size()); B b2Copy = (B) b2.copy(mModel.getRootComponent()); mModel.startTransaction(); mModel.getRootComponent().removeChild(b2.getName(), b2); mModel.endTransaction(); assertEquals("cut", 1, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("cut", 1, mModel.getRootComponent().getChildren(C.class).size()); mModel.startTransaction(); mModel.getRootComponent().addAfter(b2Copy.getName(), b2Copy, TestComponent3._A); mModel.endTransaction(); assertEquals("paste", 2, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("paste", 1, mModel.getRootComponent().getChildren(C.class).size()); urListener.undo(); assertEquals("undo paste", 1, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("undo paste", 1, mModel.getRootComponent().getChildren(C.class).size()); urListener.undo(); assertEquals("undo cut", 2, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("undo cut", 1, mModel.getRootComponent().getChildren(C.class).size()); urListener.undo(); assertEquals("undo first sync", 1, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("undo first sync", 1, mModel.getRootComponent().getChildren(C.class).size()); urListener.redo(); assertEquals("redo first sync", 2, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("redo first sync", 1, mModel.getRootComponent().getChildren(C.class).size()); urListener.redo(); assertEquals("redo cut", 1, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("redo cut", 1, mModel.getRootComponent().getChildren(C.class).size()); urListener.redo(); assertEquals("redo paste", 2, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("redo paste", 1, mModel.getRootComponent().getChildren(C.class).size()); }
Example 19
Source File: AbstractModelTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testUndoRedo() throws Exception { defaultSetup(); UndoManager urListener = new UndoManager(); mModel.addUndoableEditListener(urListener); //setup mModel.startTransaction(); A a1 = mModel.getRootComponent().getChild(A.class); String v = "testComponentListener.a1"; a1.setValue(v); mModel.endTransaction(); assertEquals("edit #1: initial set a1 attribute 'value'", v, a1.getAttribute(TestAttribute3.VALUE)); urListener.undo(); String val = a1.getAttribute(TestAttribute3.VALUE); assertNull("undo edit #1, expect attribute 'value' is null, got "+val, val); urListener.redo(); assertEquals(v, a1.getAttribute(TestAttribute3.VALUE)); mModel.startTransaction(); B b2 = new B(mModel, 2); mModel.getRootComponent().addAfter(b2.getName(), b2, TestComponent3._A); b2.setValue(v); mModel.endTransaction(); assertEquals("edit #2: insert b2", 2, mModel.getRootComponent().getChildren(B.class).size()); mModel.startTransaction(); C c1 = mModel.getRootComponent().getChild(C.class); mModel.getRootComponent().removeChild("testComponentListener.remove.c1", c1); mModel.endTransaction(); assertNull("edit #3: remove c1", mModel.getRootComponent().getChild(C.class)); urListener.undo(); c1 = mModel.getRootComponent().getChild(C.class); assertEquals("undo edit #3", 1, c1.getIndex()); urListener.redo(); assertNull("redo edit #3", mModel.getRootComponent().getChild(C.class)); urListener.undo(); assertEquals("undo edit #3 after redo", 1, mModel.getRootComponent().getChildren(C.class).size()); assertNotNull("c should be intact", mModel.getRootComponent().getChild(C.class)); urListener.undo(); assertEquals("undo edit #2", 1, mModel.getRootComponent().getChildren(B.class).size()); assertNotNull("c should be intact", mModel.getRootComponent().getChild(C.class)); urListener.undo(); a1 = mModel.getRootComponent().getChild(A.class); val = a1.getAttribute(TestAttribute3.VALUE); assertNull("undo edit #1, expect attribute 'value' is null, got "+val, val); assertNotNull("c should be intact", mModel.getRootComponent().getChild(C.class)); urListener.redo(); assertNotNull("c should be intact", mModel.getRootComponent().getChild(C.class)); urListener.redo(); assertEquals("redo edit #1 and #2", 2, mModel.getRootComponent().getChildren(B.class).size()); assertEquals("testUndo.1", 1, mModel.getRootComponent().getChildren(C.class).size()); }
Example 20
Source File: NsPrefixCreationUndoTest.java From netbeans with Apache License 2.0 | 4 votes |
/** * Tests procesing of an interruption inside of ComponentUpdater with * a RuntimeException. According to TestComponentUpdater class, * a RuntimeException should be thrown when an Err element is added to the model. * * This test shows that regardless of the exception, the XAM model remains * valid due to AbstractDocumentModel.refresh() method is called. * * @throws Exception */ public void testInterruptedComponentUpdater() throws Exception { defaultSetup(); final UndoManager ur = new UndoManager(); model.addUndoableEditListener(ur); A a = model.getRootComponent().getChild(A.class); // String xdmModelTextInitial = Util.getXdmBasedModelText(model); String xamModelTextInitial = Util.getXamBasedModelText(model); // // Add child component to A element model.startTransaction(); try { TestComponent3.Err newChildErr = new TestComponent3.Err(model, 1); a.appendChild(TestComponent3.Err.LNAME, newChildErr); } finally { model.endTransaction(); } // TestComponent3.Err newErr = a.getChild(TestComponent3.Err.class); assertEquals(TestComponent3.NS_URI, newErr.getNamespaceURI()); // String xdmModelTextAfterAdd = Util.getXdmBasedModelText(model); String xamModelTextAfterAdd = Util.getXamBasedModelText(model); // ur.undo(); // // Check the XDM and XAM models' structure return back to initial state after undo. String xdmModelText = Util.getXdmBasedModelText(model); assertEquals(xdmModelText, xdmModelTextInitial); // String xamModelText = Util.getXamBasedModelText(model); assertEquals(xamModelText, xamModelTextInitial); // try { ur.redo(); } catch (Exception ex) { String exMsg = ex.getMessage(); assertEquals(exMsg, "Test synch crashed."); } // xdmModelText = Util.getXdmBasedModelText(model); assertEquals(xdmModelText, xdmModelTextAfterAdd); // xamModelText = Util.getXamBasedModelText(model); assertEquals(xamModelText, xamModelTextAfterAdd); // ur.undo(); // xdmModelText = Util.getXdmBasedModelText(model); assertEquals(xdmModelText, xdmModelTextInitial); // xamModelText = Util.getXamBasedModelText(model); assertEquals(xamModelText, xamModelTextInitial); // }