/** Tests undo/redo of moving of a root element in a resource. */ public void test_undoRootElementMove_RATLC00537680() { final Library secondRoot = EXTLibraryFactory.eINSTANCE.createLibrary(); secondRoot.setName("secondRoot"); // $NON-NLS-1$ // first, add a second root that we can move domain.runInUndoInterval( new Runnable() { public void run() { try { domain.runAsWrite( new MRunnable() { public Object run() { testResource.getContents().add(secondRoot); return null; } }); } catch (MSLActionAbandonedException e) { fail(e); } } }); // now, move it MUndoInterval undo = domain.runInUndoInterval( new Runnable() { public void run() { try { domain.runAsWrite( new MRunnable() { public Object run() { testResource.getContents().move(0, secondRoot); return null; } }); } catch (MSLActionAbandonedException e) { fail(e); } } }); assertEquals(0, testResource.getContents().indexOf(secondRoot)); // try undoing undo.undo(); // should be at position 1 again assertEquals(1, testResource.getContents().indexOf(secondRoot)); // try redoing undo.redo(); // should be back to position 0 assertEquals(0, testResource.getContents().indexOf(secondRoot)); }
/** * Tests consistency of the <code>isTrackingModification()</code> method with the actual tracking * of modification provided by the <code>MSLObjectListener</code>. */ public void test_modificationTracking_112531() { class TestAdapter extends AdapterImpl { boolean modified; public void notifyChanged(Notification msg) { if (msg.getFeatureID(null) == Resource.RESOURCE__IS_MODIFIED) { modified = msg.getNewBooleanValue(); } } void reset() { modified = false; } } if (writing()) { // MSL resources initially track modification assertTrue(testResource.isTrackingModification()); TestAdapter adapter = new TestAdapter(); testResource.eAdapters().add(adapter); assertFalse(adapter.modified); // make a change Library lib = EXTLibraryFactory.eINSTANCE.createLibrary(); lib.setName("NewlyAdded"); // $NON-NLS-1$ root.getBranches().add(lib); assertTrue(adapter.modified); adapter.reset(); // disable modification tracking testResource.setModified(false); testResource.setTrackingModification(false); // make a change root.getBranches().remove(lib); assertFalse(adapter.modified); // re-enable tracking testResource.setTrackingModification(true); // make a change root.getBranches().add(lib); assertTrue(adapter.modified); } }
/** Tests undo/redo of addition of a root element to a resource. */ public void test_undoRootElementAdd_RATLC00537680() { if (writing()) { Library lib = EXTLibraryFactory.eINSTANCE.createLibrary(); lib.setName("NewlyAdded"); // $NON-NLS-1$ testResource.getContents().add(lib); } else { MUndoInterval undo = getLastUndo(); // try undoing undo.undo(); // should have removed the root that we added assertNotFound("NewlyAdded"); // $NON-NLS-1$ // try redoing undo.redo(); // should be able to find it again assertFound("NewlyAdded"); // $NON-NLS-1$ } }
/** {@inheritDoc} */ @Override protected void doExecute() { Writer newWriter = EXTLibraryFactory.eINSTANCE.createWriter(); newWriter.setFirstName("John Ronald Reuel"); newWriter.setLastName("Tolkien"); library.getWriters().add(newWriter); Book newBook1 = EXTLibraryFactory.eINSTANCE.createBook(); newBook1.setTitle("The Fellowship of the Ring"); newBook1.setAuthor(newWriter); library.getBooks().add(newBook1); Book newBook2 = EXTLibraryFactory.eINSTANCE.createBook(); newBook2.setTitle("The Two Towers"); newBook2.setAuthor(newWriter); library.getBooks().add(newBook2); Book newBook3 = EXTLibraryFactory.eINSTANCE.createBook(); newBook3.setTitle("The Return of the King"); newBook3.setAuthor(newWriter); library.getBooks().add(newBook3); }