Search in sources :

Example 1 with ResourceDescriptionChangeEvent

use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project xtext-eclipse by eclipse.

the class DirtyStateAwareResourceDescriptions method globalDescriptionsChanged.

public void globalDescriptionsChanged(IResourceDescription.Event event) {
    ResourceDescriptionChangeEvent changeEvent = new ResourceDescriptionChangeEvent(Iterables.filter(event.getDeltas(), new Predicate<IResourceDescription.Delta>() {

        @Override
        public boolean apply(Delta input) {
            URI uri = input.getUri();
            return !dirtyStateManager.hasContent(uri);
        }
    }));
    notifyListeners(changeEvent);
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) ChangedResourceDescriptionDelta(org.eclipse.xtext.resource.impl.ChangedResourceDescriptionDelta) URI(org.eclipse.emf.common.util.URI) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent) Predicate(com.google.common.base.Predicate)

Example 2 with ResourceDescriptionChangeEvent

use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project xtext-eclipse by eclipse.

the class AbstractBuilderState method update.

@Override
public synchronized ImmutableList<IResourceDescription.Delta> update(BuildData buildData, IProgressMonitor monitor) {
    ensureLoaded();
    final SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.AbstractBuilderState_0, 1);
    subMonitor.subTask(Messages.AbstractBuilderState_0);
    if (buildData.isEmpty())
        return ImmutableList.of();
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
    final Collection<IResourceDescription.Delta> result = doUpdate(buildData, newData, subMonitor.split(1));
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    final ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(result);
    // update the reference
    setResourceDescriptionsData(newData);
    notifyListeners(event);
    return event.getDeltas();
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 3 with ResourceDescriptionChangeEvent

use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project xtext-eclipse by eclipse.

the class AbstractBuilderState method clean.

@Override
public synchronized ImmutableList<IResourceDescription.Delta> clean(Set<URI> toBeRemoved, IProgressMonitor monitor) throws OperationCanceledException {
    ensureLoaded();
    toBeRemoved = ensureNotNull(toBeRemoved);
    SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.AbstractBuilderState_0, 2);
    subMonitor.subTask(Messages.AbstractBuilderState_0);
    if (toBeRemoved.isEmpty())
        return ImmutableList.of();
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    Collection<IResourceDescription.Delta> deltas = doClean(toBeRemoved, subMonitor.split(1));
    final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    for (IResourceDescription.Delta delta : deltas) {
        newData.removeDescription(delta.getOld().getURI());
    }
    ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(deltas);
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    int i = 0;
    subMonitor.setWorkRemaining(toBeRemoved.size() / MONITOR_CHUNK_SIZE_CLEAN + 1);
    for (IResourceDescription.Delta delta : event.getDeltas()) {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        updateMarkers(delta, null, subMonitor);
        i++;
        if (i % MONITOR_CHUNK_SIZE_CLEAN == 0)
            subMonitor.worked(1);
    }
    // update the reference
    setResourceDescriptionsData(newData);
    notifyListeners(event);
    return event.getDeltas();
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 4 with ResourceDescriptionChangeEvent

use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project xtext-eclipse by eclipse.

the class DirtyStateManager method notifyListeners.

/**
 * @since 2.22
 */
protected void notifyListeners(IResourceDescription prevDirtyDescription, IDirtyResource dirtyResource) {
    IResourceDescription.Delta delta = new IResourceDescription.Delta() {

        @Override
        public boolean haveEObjectDescriptionsChanged() {
            return true;
        }

        @Override
        public IResourceDescription getOld() {
            return prevDirtyDescription;
        }

        @Override
        public IResourceDescription getNew() {
            return dirtyResource.getDescription();
        }

        @Override
        public URI getUri() {
            return dirtyResource.getURI();
        }
    };
    notifyListeners(new ResourceDescriptionChangeEvent(Collections.singletonList(delta)));
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 5 with ResourceDescriptionChangeEvent

use of org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent in project xtext-core by eclipse.

the class StateBasedContainerTest method testBug352214.

@Override
@Test
public void testBug352214() {
    // initialize uri map
    container.getResourceDescriptions();
    ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(Collections.<IResourceDescription.Delta>singletonList(new ChangedResourceDescriptionDelta(resourceDescription, null)));
    simulateEmpty = true;
    container.descriptionsChanged(event);
    assertEquals(0, container.getResourceDescriptionCount());
    assertTrue(Iterables.all(container.getResourceDescriptions(), Predicates.notNull()));
    assertFalse(container.hasResourceDescription(uri));
    assertNull(container.getResourceDescription(uri));
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ChangedResourceDescriptionDelta(org.eclipse.xtext.resource.impl.ChangedResourceDescriptionDelta) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent) ResourceDescriptionsBasedContainerTest(org.eclipse.xtext.resource.impl.ResourceDescriptionsBasedContainerTest) Test(org.junit.Test)

Aggregations

ResourceDescriptionChangeEvent (org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)10 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)4 DefaultResourceDescriptionDelta (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta)4 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)4 NullResourceDescriptionsData (com.avaloq.tools.ddk.xtext.builder.layered.NullResourceDescriptionsData)3 AbstractResourceDescriptionsData (com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData)3 ChangedResourceDescriptionDelta (org.eclipse.xtext.resource.impl.ChangedResourceDescriptionDelta)3 IResourceDescriptionsData (com.avaloq.tools.ddk.xtext.extensions.IResourceDescriptionsData)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 URI (org.eclipse.emf.common.util.URI)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 CoarseGrainedChangeEvent (org.eclipse.xtext.resource.impl.CoarseGrainedChangeEvent)1 ResourceDescriptionsBasedContainerTest (org.eclipse.xtext.resource.impl.ResourceDescriptionsBasedContainerTest)1 Test (org.junit.Test)1