Search in sources :

Example 1 with DirtyStateManager

use of org.eclipse.xtext.ui.editor.DirtyStateManager 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 DirtyStateManager

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

the class ValidationJobSchedulerTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    referenceDescriptions = Lists.newArrayList();
    dirtyStateManager = new DirtyStateManager();
    testMe = new ValidationJobScheduler();
    testMe.setDirtyStateManager(dirtyStateManager);
    testMe.setDescriptionUtils(new DescriptionUtils());
    testMe.setResourceDescriptions(this);
    testMe.setResourceDescriptionManager(new DefaultResourceDescriptionManager());
    DocumentTokenSource nullSource = new DocumentTokenSource() {

        @Override
        protected IRegion computeDamageRegion(DocumentEvent e) {
            return new Region(0, 0);
        }
    };
    document = new XtextDocument(nullSource, null, outdatedStateManager, operationCanceledManager) {

        @Override
        public URI getResourceURI() {
            return documentURI;
        }

        @Override
        public void checkAndUpdateAnnotations() {
            validationScheduled = true;
        }
    };
    documentResource = new TestableDocumentResource();
    targetResource = new AbstractResourceDescription() {

        @Override
        public URI getURI() {
            return targetURI;
        }

        @Override
        public Iterable<IReferenceDescription> getReferenceDescriptions() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Iterable<QualifiedName> getImportedNames() {
            throw new UnsupportedOperationException();
        }

        @Override
        protected List<IEObjectDescription> computeExportedObjects() {
            if (documentResource.importedName == null)
                throw new UnsupportedOperationException();
            return Collections.emptyList();
        }
    };
}
Also used : DescriptionUtils(org.eclipse.xtext.resource.DescriptionUtils) AbstractResourceDescription(org.eclipse.xtext.resource.impl.AbstractResourceDescription) ValidationJobScheduler(org.eclipse.xtext.ui.editor.ValidationJobScheduler) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) DocumentEvent(org.eclipse.jface.text.DocumentEvent) URI(org.eclipse.emf.common.util.URI) DirtyStateManager(org.eclipse.xtext.ui.editor.DirtyStateManager) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) List(java.util.List)

Aggregations

URI (org.eclipse.emf.common.util.URI)2 DirtyStateManager (org.eclipse.xtext.ui.editor.DirtyStateManager)2 List (java.util.List)1 EClass (org.eclipse.emf.ecore.EClass)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 LanguageInfo (org.eclipse.xtext.LanguageInfo)1 DescriptionUtils (org.eclipse.xtext.resource.DescriptionUtils)1 Manager (org.eclipse.xtext.resource.IContainer.Manager)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 AbstractResourceDescription (org.eclipse.xtext.resource.impl.AbstractResourceDescription)1 DefaultResourceDescriptionManager (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager)1 DefaultResourceServiceProvider (org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider)1 ResourceServiceProviderRegistryImpl (org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl)1 DirtyStateEditorSupport (org.eclipse.xtext.ui.editor.DirtyStateEditorSupport)1 DirtyStateResourceDescription (org.eclipse.xtext.ui.editor.DirtyStateResourceDescription)1 DocumentBasedDirtyResource (org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource)1