public void testDirtyFlagOnLocalResourceTypedElementAndEmptyRight() throws CoreException, InvocationTargetException, InterruptedException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, IOException { // Create left element by SaveableCompareEditorInput to be properly // saved, see javadoc to SaveableCompareEditorInput LocalResourceTypedElement el1 = (LocalResourceTypedElement) SaveableCompareEditorInput.createFileElement(file1); ITypedElement el2 = null; CompareConfiguration conf = new CompareConfiguration(); conf.setLeftEditable(true); TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(el1, el2, conf); compareEditorInput.prepareCompareInput(null); verifyDirtyStateChanges(compareEditorInput); // check whether file was saved assertTrue( compareContent( new ByteArrayInputStream((fileContents1 + appendFileContents).getBytes()), file1.getContents())); }
public void testDirtyFlagOnCustomTypedElementAndEmptyRight() throws CoreException, InvocationTargetException, InterruptedException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, IOException { ITypedElement el1 = new TestFileElement(file1); ITypedElement el2 = null; CompareConfiguration conf = new CompareConfiguration(); conf.setLeftEditable(true); TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(el1, el2, conf); compareEditorInput.prepareCompareInput(null); verifyDirtyStateChanges(compareEditorInput); /* * not checking if changes were saved because in this case saving is not * handled, see javadoc to SaveableCompareEditorInput. */ }
private void verifyDirtyStateChanges(TestSaveableEditorInput compareEditorInput) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); TextMergeViewer viewer = (TextMergeViewer) compareEditorInput.findContentViewer(null, compareEditorInput.input, shell); viewer.setInput(compareEditorInput.getCompareResult()); MergeSourceViewer left = (MergeSourceViewer) ReflectionUtils.getField(viewer, "fLeft"); StyledText leftText = left.getSourceViewer().getTextWidget(); // modify the left side of editor leftText.append(appendFileContents); assertTrue(compareEditorInput.isDirty()); // save editor viewer.flush(null); assertFalse(compareEditorInput.isDirty()); }