use of org.eclipse.xtext.ui.editor.IDirtyResource in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method getDocument.
protected IXtextDocument getDocument(final String currentModelToParse) {
final XtextResource xtextResource = loadHelper.getResourceFor(new StringInputStream(Strings.emptyIfNull(currentModelToParse)));
if (announceDirtyState) {
dirtyResource = new IDirtyResource() {
@Override
public String getContents() {
return currentModelToParse;
}
@Override
public String getActualContents() {
return currentModelToParse;
}
@Override
public IResourceDescription getDescription() {
return xtextResource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(xtextResource);
}
@Override
public URI getURI() {
return xtextResource.getURI();
}
};
dirtyStateManager.manageDirtyState(dirtyResource);
}
return getDocument(xtextResource, currentModelToParse);
}
use of org.eclipse.xtext.ui.editor.IDirtyResource in project statecharts by Yakindu.
the class DirtyStateListener method resourceSetChanged.
public void resourceSetChanged(ResourceSetChangeEvent event) {
List<URI> remainingURIs = Lists.newArrayList(uri2dirtyResource.keySet());
for (Resource currentResource : event.getEditingDomain().getResourceSet().getResources()) {
if (currentResource instanceof XMIResource) {
XMIResource resource = (XMIResource) currentResource;
remainingURIs.remove(resource.getURI());
IDirtyResource dirtyResource = uri2dirtyResource.get(resource.getURI());
if (resource.isModified()) {
if (dirtyResource == null) {
createAndRegisterDirtyState(resource);
}
} else {
if (dirtyResource != null) {
uri2dirtyResource.remove(resource.getURI());
dirtyStateManager.discardDirtyState(dirtyResource);
}
}
}
}
for (URI remainingURI : remainingURIs) {
IDirtyResource dirtyResource = uri2dirtyResource.get(remainingURI);
dirtyStateManager.discardDirtyState(dirtyResource);
uri2dirtyResource.remove(remainingURI);
}
}
use of org.eclipse.xtext.ui.editor.IDirtyResource in project statecharts by Yakindu.
the class DirtyStateAwareDiagramDocumentEditor method removeDirtyResource.
private void removeDirtyResource(Resource resource) {
IDirtyResource dirtyResource = uri2dirtyResource.get(resource.getURI());
dirtyStateManager.discardDirtyState(dirtyResource);
uri2dirtyResource.remove(resource.getURI());
// TODO: remove adapter EcoreUtil.getExistingAdapter(resource, DirtyResourceUpdater.class) == null
}
use of org.eclipse.xtext.ui.editor.IDirtyResource in project xtext-eclipse by eclipse.
the class AbstractScopeResourceDescriptionsTest method assertDirtyState.
protected void assertDirtyState(boolean enabled) throws IOException {
String dirtyResourceName = "test/test." + fileExt.getPrimaryFileExtension();
final URI dirtyResourceURI = URI.createPlatformResourceURI(dirtyResourceName, true);
final String testModel = "stuff foo stuff bar refs foo";
IDirtyResource mockDirtyResource = new IDirtyResource() {
@Override
public String getActualContents() {
return testModel;
}
@Override
public String getContents() {
return testModel;
}
@Override
public IResourceDescription getDescription() {
return new URIBasedTestResourceDescription(dirtyResourceURI);
}
@Override
public URI getURI() {
return dirtyResourceURI;
}
};
try {
assertTrue(dirtyStateManager.manageDirtyState(mockDirtyResource));
Resource dirtyResource = resourceSet.getResource(dirtyResourceURI, true);
assertTrue(dirtyResource instanceof XtextResource);
assertTrue(dirtyResource.isLoaded());
assertFalse(dirtyResource.getContents().isEmpty());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
dirtyResource.save(byteArrayOutputStream, null);
assertEquals(testModel, new String(byteArrayOutputStream.toByteArray()));
assertTrue(enabled);
} catch (Throwable t) {
assertFalse(enabled);
boolean isResourceException = false;
for (Throwable tx : Throwables.getCausalChain(t)) {
if (tx instanceof org.eclipse.core.internal.resources.ResourceException) {
isResourceException = true;
break;
}
}
if (!isResourceException)
Exceptions.throwUncheckedException(t);
} finally {
dirtyStateManager.discardDirtyState(mockDirtyResource);
}
}
use of org.eclipse.xtext.ui.editor.IDirtyResource in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method getDocument.
protected IXtextDocument getDocument(final String currentModelToParse) {
StringInputStream in;
try {
in = new StringInputStream(Strings.emptyIfNull(currentModelToParse), getEncoding());
} catch (UnsupportedEncodingException e) {
in = new StringInputStream(Strings.emptyIfNull(currentModelToParse));
}
final XtextResource xtextResource = loadHelper.getResourceFor(in);
if (announceDirtyState) {
dirtyResource = new IDirtyResource() {
@Override
public String getContents() {
return currentModelToParse;
}
@Override
public String getActualContents() {
return currentModelToParse;
}
@Override
public IResourceDescription getDescription() {
return xtextResource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(xtextResource);
}
@Override
public URI getURI() {
return xtextResource.getURI();
}
};
dirtyStateManager.manageDirtyState(dirtyResource);
}
return getDocument(xtextResource, currentModelToParse);
}
Aggregations