Search in sources :

Example 1 with DocumentBasedDirtyResource

use of org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource in project xtext-eclipse by eclipse.

the class DirtyStateEditorSupportTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    document = this;
    resourceSet = new ResourceSetImpl();
    resourceURI = URI.createURI("scheme://foo");
    resource = new XtextResource(resourceURI);
    resource.setLanguageName("FooLanguage");
    final DefaultResourceServiceProvider resourceServiceProvider = new DefaultResourceServiceProvider() {

        @Override
        public org.eclipse.xtext.resource.IResourceDescription.Manager getResourceDescriptionManager() {
            return DirtyStateEditorSupportTest.this;
        }

        @SuppressWarnings("unchecked")
        @Override
        public <T> T get(Class<T> t) {
            if (DirtyStateResourceDescription.Manager.class.isAssignableFrom(t))
                return (T) new DirtyStateResourceDescription.Manager(DirtyStateEditorSupportTest.this);
            if (LanguageInfo.class.isAssignableFrom(t))
                return (T) new LanguageInfo("FooLanguage");
            return super.get(t);
        }
    };
    ResourceServiceProviderRegistryImpl registry = new ResourceServiceProviderRegistryImpl() {

        @Override
        public IResourceServiceProvider getResourceServiceProvider(URI uri) {
            return resourceServiceProvider;
        }
    };
    resource.setResourceServiceProvider(resourceServiceProvider);
    resourceSet.getResources().add(resource);
    dirtyStateSupport = new DirtyStateEditorSupport();
    dirtyStateSupport.setConcurrentEditingWarningDialog(this);
    dirtyStateSupport.setResourceDescriptions(this);
    dirtyStateManager = new DirtyStateManager();
    stateChangeEventBroker = new StateChangeEventBroker();
    dirtyStateManager.addListener(stateChangeEventBroker);
    dirtyStateSupport.setDirtyStateManager(dirtyStateManager);
    dirtyStateSupport.setStateChangeEventBroker(stateChangeEventBroker);
    dirtyResource = new DocumentBasedDirtyResource();
    dirtyStateSupport.setDirtyResource(dirtyResource);
    dirtyStateSupport.setResourceServiceProviderRegistry(registry);
    ignoreConcurrentEditing = Lists.newLinkedList();
    exportedObjects = Collections.emptyList();
}
Also used : DefaultResourceServiceProvider(org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) DirtyStateResourceDescription(org.eclipse.xtext.ui.editor.DirtyStateResourceDescription) XtextResource(org.eclipse.xtext.resource.XtextResource) Manager(org.eclipse.xtext.resource.IContainer.Manager) DirtyStateManager(org.eclipse.xtext.ui.editor.DirtyStateManager) URI(org.eclipse.emf.common.util.URI) LanguageInfo(org.eclipse.xtext.LanguageInfo) DirtyStateManager(org.eclipse.xtext.ui.editor.DirtyStateManager) StateChangeEventBroker(org.eclipse.xtext.ui.notification.StateChangeEventBroker) EClass(org.eclipse.emf.ecore.EClass) ResourceServiceProviderRegistryImpl(org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl) DocumentBasedDirtyResource(org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource) DirtyStateEditorSupport(org.eclipse.xtext.ui.editor.DirtyStateEditorSupport)

Example 2 with DocumentBasedDirtyResource

use of org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource in project xtext-eclipse by eclipse.

the class DocumentBasedDirtyResourceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    with(XtextStandaloneSetup.class);
    uri = URI.createURI("scheme:/foobar.xtext");
    documentContent = "grammar foo with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: name=ID;";
    resource = getResource(documentContent, uri.toString());
    DefaultResourceServiceProvider provider = new DefaultResourceServiceProvider() {

        @Override
        public org.eclipse.xtext.resource.IResourceDescription.Manager getResourceDescriptionManager() {
            return DocumentBasedDirtyResourceTest.this;
        }
    };
    resource.setResourceServiceProvider(provider);
    dirtyResource = new DocumentBasedDirtyResource();
    description = this;
}
Also used : DefaultResourceServiceProvider(org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) DocumentBasedDirtyResource(org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource)

Example 3 with DocumentBasedDirtyResource

use of org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource in project n4js by eclipse.

the class PrevStateAwareDirtyStateManager method reflectiveGetInnerResource.

private DocumentBasedDirtyResource reflectiveGetInnerResource(final IDirtyResource dirtyResource) {
    Field[] declaredFields = dirtyResource.getClass().getDeclaredFields();
    DocumentBasedDirtyResource myDirtyResource = null;
    try {
        Field field = declaredFields[0];
        field.setAccessible(true);
        Object fieldValue = field.get(dirtyResource);
        if (fieldValue instanceof DirtyStateEditorSupport) {
            myDirtyResource = ((DirtyStateEditorSupport) fieldValue).getDirtyResource();
        }
    } catch (IllegalArgumentException | IllegalAccessException e) {
    // ignore
    }
    return myDirtyResource;
}
Also used : Field(java.lang.reflect.Field) DocumentBasedDirtyResource(org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource) DirtyStateEditorSupport(org.eclipse.xtext.ui.editor.DirtyStateEditorSupport)

Aggregations

DocumentBasedDirtyResource (org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource)3 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 DefaultResourceServiceProvider (org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider)2 DirtyStateEditorSupport (org.eclipse.xtext.ui.editor.DirtyStateEditorSupport)2 Field (java.lang.reflect.Field)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 LanguageInfo (org.eclipse.xtext.LanguageInfo)1 Manager (org.eclipse.xtext.resource.IContainer.Manager)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 ResourceServiceProviderRegistryImpl (org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl)1 DirtyStateManager (org.eclipse.xtext.ui.editor.DirtyStateManager)1 DirtyStateResourceDescription (org.eclipse.xtext.ui.editor.DirtyStateResourceDescription)1 StateChangeEventBroker (org.eclipse.xtext.ui.notification.StateChangeEventBroker)1