Search in sources :

Example 1 with IErlElementDelta

use of org.erlide.engine.model.root.IErlElementDelta in project erlide_eclipse by erlang.

the class ErlElementDelta method addAffectedChild.

/**
 * Adds the child delta to the collection of affected children. If the child is
 * already in the collection, walk down the hierarchy.
 *
 * JC: this sucks a little bit, too much code, as always... (from C model, not my
 * fault)
 */
protected void addAffectedChild(final ErlElementDelta child) {
    switch(fKind) {
        case IErlElementDelta.ADDED:
        case IErlElementDelta.REMOVED:
            // no need to add a child if this parent is added or removed
            return;
        case IErlElementDelta.CHANGED:
            fFlags |= IErlElementDelta.F_CHILDREN;
            break;
        default:
            fKind = IErlElementDelta.CHANGED;
            fFlags |= IErlElementDelta.F_CHILDREN;
            break;
    }
    // Check if we already have the delta.
    IErlElementDelta existingChild = null;
    int existingChildIndex = -1;
    for (int i = 0; i < fChildren.size(); i++) {
        // project
        if (equalsAndSameParent(fChildren.get(i).getElement(), child.getElement())) {
            existingChild = fChildren.get(i);
            existingChildIndex = i;
            break;
        }
    }
    if (existingChild == null) {
        // new affected child
        fChildren.add(child);
    } else {
        switch(existingChild.getKind()) {
            case IErlElementDelta.ADDED:
                switch(child.getKind()) {
                    // child was added then added -> it is added
                    case IErlElementDelta.ADDED:
                    // child was added then changed -> it is added
                    case IErlElementDelta.CHANGED:
                        return;
                    // child was added then removed -> noop
                    case IErlElementDelta.REMOVED:
                        fChildren.remove(existingChildIndex);
                        return;
                    default:
                        break;
                }
                break;
            case IErlElementDelta.REMOVED:
                switch(child.getKind()) {
                    // child was removed then added -> it is changed
                    case IErlElementDelta.ADDED:
                        child.fKind = IErlElementDelta.CHANGED;
                        fChildren.set(existingChildIndex, child);
                        return;
                    // child was removed then changed -> it is removed
                    case IErlElementDelta.CHANGED:
                    // child was removed then removed -> it is removed
                    case IErlElementDelta.REMOVED:
                        return;
                    default:
                        break;
                }
                break;
            case IErlElementDelta.CHANGED:
                switch(child.getKind()) {
                    // child was changed then added -> it is added
                    case IErlElementDelta.ADDED:
                    // child was changed then removed -> it is removed
                    case IErlElementDelta.REMOVED:
                        fChildren.set(existingChildIndex, child);
                        return;
                    // child was changed then changed -> it is changed
                    case IErlElementDelta.CHANGED:
                        final IErlElementDelta[] children = child.getChildren(IErlElementDelta.ALL);
                        for (final IErlElementDelta element : children) {
                            final ErlElementDelta childsChild = (ErlElementDelta) element;
                            ((ErlElementDelta) existingChild).addAffectedChild(childsChild);
                        }
                        // add the non-erlang resource deltas if needed
                        // note that the child delta always takes
                        // precedence over this existing child delta
                        // as non-erlang resource deltas are always
                        // created last (by the DeltaProcessor)
                        ((ErlElementDelta) existingChild).fResourceDeltas = child.fResourceDeltas;
                        return;
                    default:
                        break;
                }
                break;
            default:
                // unknown -> existing child becomes the child with the existing
                // child's
                // flags
                final int flags = existingChild.getFlags();
                fChildren.set(existingChildIndex, child);
                child.fFlags |= flags;
        }
    }
}
Also used : IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta) IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta)

Example 2 with IErlElementDelta

use of org.erlide.engine.model.root.IErlElementDelta in project erlide_eclipse by erlang.

the class ErlModelDeltaManager method fireReconcileDelta.

private void fireReconcileDelta(final IElementChangedListener[] listeners, final int[] listenerMask, final int listenerCount) {
    final IErlElementDelta deltaToNotify = mergeDeltas(reconcileDeltas.values());
    if (ErlModelDeltaManager.verbose) {
        System.out.println(// $NON-NLS-1$//$NON-NLS-2$
        "FIRING POST_RECONCILE Delta [" + Thread.currentThread() + "]:");
        System.out.println(// $NON-NLS-1$
        deltaToNotify == null ? "<NONE>" : deltaToNotify.toString());
    }
    if (deltaToNotify != null) {
        // flush now so as to keep listener reactions to post their own
        // deltas for
        // subsequent iteration
        reconcileDeltas.clear();
        model.notifyListeners(deltaToNotify, ElementChangedEvent.POST_RECONCILE, listeners, listenerMask, listenerCount);
    }
}
Also used : IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta)

Example 3 with IErlElementDelta

use of org.erlide.engine.model.root.IErlElementDelta in project erlide_eclipse by erlang.

the class ErlModelDeltaManager method fire.

/**
 * Fire Model deltas, flushing them after the fact. If the firing mode has
 * been turned off, this has no effect.
 */
protected void fire(final IErlElementDelta customDeltas, final int eventType) {
    if (fFire) {
        IErlElementDelta deltaToNotify;
        if (customDeltas == null) {
            deltaToNotify = mergeDeltas(erlModelDeltas);
        } else {
            deltaToNotify = customDeltas;
        }
        final IElementChangedListener[] listeners;
        final int listenerCount;
        final int[] listenerMask;
        // Notification
        synchronized (model.elementChangedListeners) {
            listeners = new IElementChangedListener[model.elementChangedListeners.size()];
            model.elementChangedListeners.toArray(listeners);
            listenerCount = listeners.length;
            listenerMask = null;
        }
        switch(eventType) {
            case ErlModelDeltaManager.DEFAULT_CHANGE_EVENT:
                // firePreAutoBuildDelta(deltaToNotify, listeners, listenerMask,
                // listenerCount);
                firePostChangeDelta(deltaToNotify, listeners, listenerMask, listenerCount);
                fireReconcileDelta(listeners, listenerMask, listenerCount);
                break;
            // break;
            case ElementChangedEvent.POST_CHANGE:
                firePostChangeDelta(deltaToNotify, listeners, listenerMask, listenerCount);
                fireReconcileDelta(listeners, listenerMask, listenerCount);
                break;
            case ElementChangedEvent.POST_RECONCILE:
                fireReconcileDelta(listeners, listenerMask, listenerCount);
                break;
            case ElementChangedEvent.POST_SHIFT:
                fireShiftEvent(deltaToNotify, listeners, listenerMask, listenerCount);
                return;
            default:
                break;
        }
    }
}
Also used : IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta) IElementChangedListener(org.erlide.engine.model.root.IElementChangedListener)

Example 4 with IErlElementDelta

use of org.erlide.engine.model.root.IErlElementDelta in project erlide_eclipse by erlang.

the class ErlModelDeltaManager method mergeDeltas.

IErlElementDelta mergeDeltas(final Collection<IErlElementDelta> deltas) {
    synchronized (deltas) {
        if (deltas.isEmpty()) {
            return null;
        }
        if (deltas.size() == 1) {
            return deltas.iterator().next();
        }
        final Iterator<IErlElementDelta> iterator = deltas.iterator();
        final IErlElement cRoot = ErlangEngine.getInstance().getModel();
        final ErlElementDelta rootDelta = new ErlElementDelta(0, 0, cRoot);
        boolean insertedTree = false;
        while (iterator.hasNext()) {
            final ErlElementDelta delta = (ErlElementDelta) iterator.next();
            final IErlElement element = delta.getElement();
            if (cRoot.equals(element)) {
                final IErlElementDelta[] children = delta.getChildren(IErlElementDelta.ALL);
                for (final IErlElementDelta element0 : children) {
                    final ErlElementDelta projectDelta = (ErlElementDelta) element0;
                    rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta);
                    insertedTree = true;
                }
                final IResourceDelta[] resourceDeltas = delta.getResourceDeltas();
                if (resourceDeltas != null) {
                    for (final IResourceDelta element0 : resourceDeltas) {
                        rootDelta.addResourceDelta(element0);
                        insertedTree = true;
                    }
                }
            } else {
                rootDelta.insertDeltaTree(element, delta);
                insertedTree = true;
            }
        }
        if (insertedTree) {
            return rootDelta;
        }
        return null;
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta) IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta) ErlElementDelta(org.erlide.engine.internal.model.root.ErlElementDelta) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 5 with IErlElementDelta

use of org.erlide.engine.model.root.IErlElementDelta in project erlide_eclipse by erlang.

the class DefaultErlangFoldingStructureProvider method projectionEnabled.

/*
     * @seeorg.eclipse.jface.text.source.projection.IProjectionListener#
     * projectionEnabled()
     */
@Override
public void projectionEnabled() {
    // http://home.ott.oti.com/teams/wswb/anon/out/vms/index.html
    // projectionEnabled messages are not always paired with
    // projectionDisabled
    // i.e. multiple enabled messages may be sent out.
    // we have to make sure that we disable first when getting an enable
    // message.
    projectionDisabled();
    initialize();
    if (fEditor instanceof ErlangEditor && fModule != null) {
        boolean structureKnown = false;
        try {
            structureKnown = fModule.isStructureKnown();
        } catch (final ErlModelException e1) {
        }
        if (structureKnown) {
            final IErlElementDelta d = ErlangEngine.getInstance().getModel().createElementDelta(IErlElementDelta.CHANGED, IErlElementDelta.F_CONTENT, fModule);
            processDelta(d);
        } else {
            try {
                fModule.open(null);
            } catch (final ErlModelException e) {
                ErlLogger.error(e);
            }
        }
    }
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Aggregations

IErlElementDelta (org.erlide.engine.model.root.IErlElementDelta)6 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 ProjectionAnnotationModel (org.eclipse.jface.text.source.projection.ProjectionAnnotationModel)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 ErlElementDelta (org.erlide.engine.internal.model.root.ErlElementDelta)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 IErlElement (org.erlide.engine.model.IErlElement)1 IElementChangedListener (org.erlide.engine.model.root.IElementChangedListener)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)1