Java Code Examples for org.eclipse.xtext.ui.editor.XtextEditor#isDirty()

The following examples show how to use org.eclipse.xtext.ui.editor.XtextEditor#isDirty() . 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: N4JSMarkerResolutionGenerator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns true iff for at least one of the given markers the corresponding editor is open and is dirty. Does not
 * open any editors if they aren't open already.
 */
private boolean existsDirtyEditorFor(IMarker[] markers) {
	// look for an editor containing one of the given markers that is already open and dirty
	for (IMarker marker : markers) {
		final XtextEditor editorForMarker = findEditor(marker.getResource()); // returns null if not open already
		if (editorForMarker != null && editorForMarker.isDirty())
			return true;
	}
	return false;
}
 
Example 2
Source File: XtextGrammarQuickfixProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void assertAndApplyAllResolutions(XtextEditor xtextEditor, String issueCode, int issueDataCount, int issueCount,
		String resolutionLabel) throws CoreException {
	InternalBuilderTest.setAutoBuild(true);
	if (xtextEditor.isDirty()) {
		xtextEditor.doSave(new NullProgressMonitor());
	}
	InternalBuilderTest.fullBuild();
	IXtextDocument document = xtextEditor.getDocument();
	validateInEditor(document);
	List<Issue> issues = getIssues(document);
	assertFalse("Document has no issues, but should.", issues.isEmpty());

	issues.iterator().forEachRemaining((issue) -> {
		assertEquals(issueCode, issue.getCode());
		assertNotNull(issue.getData());
		assertEquals(issueDataCount, issue.getData().length);
	});
	IResource resource = xtextEditor.getResource();
	IMarker[] problems = resource.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_INFINITE);
	assertEquals("Resource should have " + issueCount + " error marker.", issueCount, problems.length);
	validateInEditor(document);
	MarkerResolutionGenerator instance = injector.getInstance(MarkerResolutionGenerator.class);
	List<IMarkerResolution> resolutions = Lists.newArrayList(instance.getResolutions(problems[0]));
	assertEquals(1, resolutions.size());
	IMarkerResolution resolution = resolutions.iterator().next();
	assertTrue(resolution instanceof WorkbenchMarkerResolution);
	WorkbenchMarkerResolution workbenchResolution = (WorkbenchMarkerResolution) resolution;
	IMarker primaryMarker = problems[0];
	List<IMarker> others = Lists.newArrayList(workbenchResolution.findOtherMarkers(problems));
	assertFalse(others.contains(primaryMarker));
	assertEquals(problems.length - 1, others.size());
	others.add(primaryMarker);
	workbenchResolution.run(others.toArray(new IMarker[others.size()]), new NullProgressMonitor());
	if (xtextEditor.isDirty()) {
		xtextEditor.doSave(null);
	}
	InternalBuilderTest.cleanBuild();
	problems = resource.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_INFINITE);
	assertEquals("Resource should have no error marker.", 0, problems.length);
}
 
Example 3
Source File: DerivedSourceView.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String computeDescription(IWorkbenchPartSelection workbenchPartSelection) {
	if (selectedSource == null) {
		return super.computeDescription(workbenchPartSelection);
	}
	XtextEditor xtextEditor = (XtextEditor) workbenchPartSelection.getWorkbenchPart();
	if (xtextEditor.isDirty()) {
		return Messages.DerivedSourceView_EditorDirty;
	} else {
		return selectedSource.getFullPath().toString();
	}
}
 
Example 4
Source File: SARLEditorErrorTickUpdater.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("checkstyle:nestedifdepth")
public void modelChanged(IAnnotationModel model) {
	super.modelChanged(model);
	//FIXME: for helping to resolve #661
	final XtextEditor editor = getEditor();
	if (editor != null && !editor.isDirty() && editor.getInternalSourceViewer() != null) {
		final IAnnotationModel currentModel = editor.getInternalSourceViewer().getAnnotationModel();
		if (currentModel != null && currentModel == model) {
			final Resource resource = getXtextResource();
			if (isReconciliable(resource)) {
				final Set<String> markers = extractErrorMarkerMessages(currentModel);
				final List<Diagnostic> resourceErrors = resource.getErrors();
				if (markers.size() != resourceErrors.size() || notSame(markers, resourceErrors)) {
					final Display display = PlatformUI.getWorkbench().getDisplay();
					display.asyncExec(new Runnable() {
						@Override
						public void run() {
							LangActivator.getInstance().getLog().log(
									new Status(IStatus.ERROR, LangActivator.PLUGIN_ID,
									MessageFormat.format(Messages.SARLEditorErrorTickUpdater_0, resource.getURI())));
						}
					});
				}
			}
		}
	}
}