Search in sources :

Example 1 with NoChangeEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent in project webtools.sourceediting by eclipse.

the class StructuredDocumentToTextAdapter method handlePendingEvents.

/**
 * assume only for "no change" events, for now
 */
protected void handlePendingEvents() {
    if (lastEventQueue == null)
        return;
    Iterator iterator = lastEventQueue.iterator();
    while (iterator.hasNext()) {
        NoChangeEvent noChangeEvent = (NoChangeEvent) iterator.next();
        redrawNoChange(noChangeEvent);
    }
    lastEventQueue = null;
    lastEvent = null;
}
Also used : Iterator(java.util.Iterator) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)

Example 2 with NoChangeEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent in project webtools.sourceediting by eclipse.

the class BasicStructuredDocument method internalReplaceText.

/**
 * @param requester
 * @param start
 * @param replacementLength
 * @param changes
 * @param modificationStamp
 * @param ignoreReadOnlySettings
 * @return
 */
private StructuredDocumentEvent internalReplaceText(Object requester, int start, int replacementLength, String changes, long modificationStamp, boolean ignoreReadOnlySettings) {
    StructuredDocumentEvent result = null;
    stopPostNotificationProcessing();
    if (changes == null)
        // $NON-NLS-1$
        changes = "";
    // 
    if (Debug.debugStructuredDocument)
        // $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
        System.out.println(getClass().getName() + "::replaceText(" + start + "," + replacementLength + "," + changes + ")");
    if (Debug.perfTestStructuredDocumentOnly || Debug.perfTest || Debug.perfTestRawStructuredDocumentOnly) {
        startStreamTime = System.currentTimeMillis();
    }
    try {
        // Note: event must be computed before 'fire' method called
        fDocumentEvent = new DocumentEvent(this, start, replacementLength, changes);
        fireDocumentAboutToChanged();
        try {
            acquireLock();
            if (!ignoreReadOnlySettings && (containsReadOnly(start, replacementLength))) {
                NoChangeEvent noChangeEvent = new NoChangeEvent(this, requester, changes, start, replacementLength);
                noChangeEvent.reason = NoChangeEvent.READ_ONLY_STATE_CHANGE;
                result = noChangeEvent;
            } else {
                result = updateModel(requester, start, replacementLength, changes);
            }
        } finally {
            releaseLock();
        }
        if (Debug.perfTestRawStructuredDocumentOnly || Debug.perfTest) {
            long stopStreamTime = System.currentTimeMillis();
            // $NON-NLS-1$
            System.out.println("\n\t\t\t\t Time for IStructuredDocument raw replaceText: " + (stopStreamTime - startStreamTime));
        }
        if (Debug.debugStructuredDocument) {
            // $NON-NLS-1$
            System.out.println("event type returned by replaceTextWithNoDebuggingThread: " + result);
        }
    } finally {
        // increment modification stamp if modifications were made
        if (result != null && !(result instanceof NoChangeEvent)) {
            fModificationStamp = modificationStamp;
            fNextModificationStamp = Math.max(fModificationStamp, fNextModificationStamp);
            fDocumentEvent.fModificationStamp = fModificationStamp;
        }
        if (result == null) {
            // result should not be null, but if an exception was thrown,
            // it will be
            // so send a noChangeEvent and log the problem
            NoChangeEvent noChangeEvent = new NoChangeEvent(this, requester, changes, start, replacementLength);
            noChangeEvent.reason = NoChangeEvent.NO_EVENT;
            fireStructuredDocumentEvent(noChangeEvent);
            // $NON-NLS-1$
            Logger.log(Logger.ERROR, "Program Error: invalid structured document event");
        } else {
            if (result instanceof RegionChangedEvent) {
                fireStructuredDocumentEvent((RegionChangedEvent) result);
            } else {
                if (result instanceof RegionsReplacedEvent) {
                    fireStructuredDocumentEvent((RegionsReplacedEvent) result);
                } else {
                    if (result instanceof StructuredDocumentRegionsReplacedEvent) {
                        // probably more efficient to mark old regions as
                        // 'deleted' at the time
                        // that are determined to be deleted, but I'll do
                        // here
                        // in then central spot
                        // for programming ease.
                        updateDeletedFields((StructuredDocumentRegionsReplacedEvent) result);
                        fireStructuredDocumentEvent((StructuredDocumentRegionsReplacedEvent) result);
                    } else {
                        if (result instanceof NoChangeEvent) {
                            fireStructuredDocumentEvent((NoChangeEvent) result);
                        } else {
                            // if here, this means a new event was created
                            // and not handled here
                            // just send a no event until this issue is
                            // resolved.
                            NoChangeEvent noChangeEvent = new NoChangeEvent(this, requester, changes, start, replacementLength);
                            noChangeEvent.reason = NoChangeEvent.NO_EVENT;
                            fireStructuredDocumentEvent(noChangeEvent);
                            // $NON-NLS-1$
                            Logger.log(Logger.INFO, "Program Error: unexpected structured document event: " + result);
                        }
                    }
                }
            }
        }
        if (Debug.perfTest || Debug.perfTestStructuredDocumentOnly) {
            long stopStreamTime = System.currentTimeMillis();
            // $NON-NLS-1$
            System.out.println("\n\t\t\t\t Total Time for IStructuredDocument event signaling/processing in replaceText: " + (stopStreamTime - startStreamTime));
        }
        resumePostNotificationProcessing();
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent) RegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) DocumentEvent(org.eclipse.jface.text.DocumentEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)

Example 3 with NoChangeEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent in project webtools.sourceediting by eclipse.

the class JobSafeStructuredDocument method replaceText.

/* (non-Javadoc)
	 * @see org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument#replaceText(java.lang.Object, int, int, java.lang.String, boolean)
	 */
public StructuredDocumentEvent replaceText(final Object requester, final int start, final int replacementLength, final String changes, final boolean ignoreReadOnlySettings) {
    StructuredDocumentEvent event = null;
    IExecutionDelegate delegate = getExecutionDelegate();
    if (delegate == null) {
        event = super.replaceText(requester, start, replacementLength, changes, ignoreReadOnlySettings);
    } else {
        final Object[] resultSlot = new Object[1];
        JobSafeRunnable runnable = new JobSafeRunnable() {

            public void run() throws Exception {
                resultSlot[0] = JobSafeStructuredDocument.super.replaceText(requester, start, replacementLength, changes, ignoreReadOnlySettings);
            }

            public void handleException(Throwable exception) {
                resultSlot[0] = new NoChangeEvent(JobSafeStructuredDocument.this, requester, changes, start, replacementLength);
                super.handleException(exception);
            }
        };
        delegate.execute(runnable);
        event = (StructuredDocumentEvent) resultSlot[0];
    }
    return event;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IExecutionDelegate(org.eclipse.wst.sse.core.internal.IExecutionDelegate) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)

Example 4 with NoChangeEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent in project webtools.sourceediting by eclipse.

the class JobSafeStructuredDocument method setText.

public StructuredDocumentEvent setText(final Object requester, final String theString) {
    StructuredDocumentEvent event = null;
    IExecutionDelegate executionDelegate = getExecutionDelegate();
    if (executionDelegate == null) {
        event = super.setText(requester, theString);
    } else {
        final Object[] resultSlot = new Object[1];
        JobSafeRunnable runnable = new JobSafeRunnable() {

            public void run() throws Exception {
                resultSlot[0] = JobSafeStructuredDocument.super.setText(requester, theString);
            }

            public void handleException(Throwable exception) {
                resultSlot[0] = new NoChangeEvent(JobSafeStructuredDocument.this, requester, theString, 0, 0);
                super.handleException(exception);
            }
        };
        executionDelegate.execute(runnable);
        event = (StructuredDocumentEvent) resultSlot[0];
    }
    return event;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IExecutionDelegate(org.eclipse.wst.sse.core.internal.IExecutionDelegate) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)

Example 5 with NoChangeEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent in project webtools.sourceediting by eclipse.

the class StructuredDocumentReParser method checkForNoChange.

/**
 * Checks to see if change request exactly matches the text it would be
 * replacing. (In future, this, or similar method is where to check for
 * "read only" attempted change.)
 */
private StructuredDocumentEvent checkForNoChange() {
    StructuredDocumentEvent result = null;
    // doesn't do this.)
    if ((fChanges != null) && (fDeletedText != null) && (fChanges.length() == fDeletedText.length()) && (fChanges.equals(fDeletedText))) {
        result = new NoChangeEvent(fStructuredDocument, fRequester, fChanges, fStart, fLengthToReplace);
        ((NoChangeEvent) result).reason = NoChangeEvent.NO_CONTENT_CHANGE;
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)

Aggregations

NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)12 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)6 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)3 RegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)3 StructuredDocumentRegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)3 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)2 Position (org.eclipse.jface.text.Position)2 IExecutionDelegate (org.eclipse.wst.sse.core.internal.IExecutionDelegate)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 Iterator (java.util.Iterator)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 NewDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1