Search in sources :

Example 6 with NoChangeEvent

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

the class TestNoChangeEvent method testNoChangeEvent.

public void testNoChangeEvent() {
    NoChangeEvent event = getBasicEvent();
    assertNotNull(event);
    assertEquals(NoChangeEvent.NO_CONTENT_CHANGE, event.reason);
}
Also used : NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)

Example 7 with NoChangeEvent

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

the class TestNoChangeEvent method getBasicEvent.

private NoChangeEvent getBasicEvent() {
    IStructuredDocument document = StructuredDocumentFactory.getNewStructuredDocumentInstance(new NullParser());
    document.setText(this, testString);
    NoChangeEvent event = new NoChangeEvent(document, this, "", 0, 0);
    event.reason = NoChangeEvent.NO_CONTENT_CHANGE;
    return event;
}
Also used : NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 8 with NoChangeEvent

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

the class UnitTests method handleEvent.

protected void handleEvent(StructuredDocumentEvent structuredDocumentEvent) {
    eventResult = false;
    switch(eventCase) {
        case 1:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 2:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 3:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 4:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 5:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 6:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(0).getText()))
                                if ("</B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(1).getText())) {
                                    // ok
                                    eventResult = true;
                                }
                }
                break;
            }
        case 7:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (1 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 8:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // if ("<B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(0).getText()))
                            // if ("</B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(1).getText())) {
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 9:
        case 10:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(0).getText()))
                                if ("</TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(1).getText()))
                                    // ok
                                    eventResult = true;
                }
                break;
            }
        case 11:
        case 12:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(0).getText()))
                                if ("</TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(1).getText()))
                                    // ok
                                    eventResult = true;
                }
                break;
            }
        case 13:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size())
                        if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 14:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (1 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 15:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    RegionChangedEvent regionChangedEvent = (RegionChangedEvent) structuredDocumentEvent;
                    IStructuredDocumentRegion documentRegion = ((RegionChangedEvent) structuredDocumentEvent).getStructuredDocumentRegion();
                    if ("b ".equals(documentRegion.getFullText(regionChangedEvent.getRegion()))) {
                        // ok
                        eventResult = true;
                    }
                }
                break;
            }
        case 16:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (0 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (1 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 17:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (1 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 18:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (2 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (2 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 19:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 20:
        case 21:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 22:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 23:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 24:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 25:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 26:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        // JSP5
        case 27:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 28:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 29:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 30:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        // JSP6
        case 31:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 32:
            {
                // changed 2002, 9/12 to fit -- this is definitely a change
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    RegionsReplacedEvent regionsReplacedEvent = (RegionsReplacedEvent) structuredDocumentEvent;
                    if (1 == regionsReplacedEvent.getOldRegions().size()) {
                        ITextRegion region = regionsReplacedEvent.getOldRegions().get(0);
                        IStructuredDocumentRegion documentRegion = regionsReplacedEvent.getStructuredDocumentRegion();
                        String text = documentRegion.getText(region);
                        if ("<% aaa %>".equals(text)) {
                            // ok
                            eventResult = true;
                        }
                    }
                } else if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    StructuredDocumentRegionsReplacedEvent nodesReplacedEvent = (StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent;
                    IStructuredDocumentRegionList regions = nodesReplacedEvent.getNewStructuredDocumentRegions();
                    if (1 == regions.getLength()) {
                        IStructuredDocumentRegion region = regions.item(0);
                        String text = region.getText();
                        // System.out.println(text);
                        if ("<c<% aaa ".equals(text)) {
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 33:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 34:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 35:
            {
                // if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 36:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 37:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 38:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 39:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 40:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NODES_REPLACED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_REGIONS_REPLACED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_REGION_CHANGED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NEW_MODEL_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof NewDocumentEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NO_CHANGE_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        default:
            {
                if (structuredDocumentEvent instanceof NewDocumentEvent) {
                    // ok
                    eventResult = true;
                }
            }
    }
}
Also used : NewDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent) RegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)

Example 9 with NoChangeEvent

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

the class BasicStructuredDocument method clearReadOnly.

public void clearReadOnly(int startOffset, int length) {
    // remove any that overlap.
    try {
        Position[] positions = getPositions(READ_ONLY_REGIONS_CATEGORY);
        for (int i = 0; i < positions.length; i++) {
            Position position = positions[i];
            if (position.overlapsWith(startOffset, length)) {
                String effectedText = this.get(startOffset, length);
                // fDocumentEvent = new DocumentEvent(this, startOffset,
                // length, effectedText);
                fireReadOnlyAboutToBeChanged();
                position.delete();
                NoChangeEvent noChangeEvent = new NoChangeEvent(this, null, effectedText, startOffset, length);
                noChangeEvent.reason = NoChangeEvent.READ_ONLY_STATE_CHANGE;
                fireReadOnlyStructuredDocumentEvent(noChangeEvent);
            }
        }
    } catch (BadPositionCategoryException e) {
    // just means no readonly regions been defined yet
    // so nothing to do.
    }
}
Also used : Position(org.eclipse.jface.text.Position) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException)

Example 10 with NoChangeEvent

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

the class BasicStructuredDocument method makeReadOnly.

public void makeReadOnly(int startOffset, int length, boolean canInsertBefore, boolean canInsertAfter) {
    // so we'll ignore those requests
    if (length <= 0)
        return;
    String affectedText = this.get(startOffset, length);
    // a document event for "read only" change ... must
    // be followed by "no change" structuredDocument event
    // fDocumentEvent = new DocumentEvent(this, startOffset, length,
    // affectedText);
    fireReadOnlyAboutToBeChanged();
    // if (containsReadOnly(startOffset, length)) {
    // adjustReadOnlyRegions(startOffset, length);
    // } else {
    // we can blindly add category, since no harm done if already
    // exists.
    addPositionCategory(READ_ONLY_REGIONS_CATEGORY);
    Position newPosition = new ReadOnlyPosition(startOffset, length, canInsertBefore);
    try {
        addPosition(READ_ONLY_REGIONS_CATEGORY, newPosition);
        // FIXME: need to change API to pass in requester, so this event
        // can be
        // created correctly, instead of using null.
        NoChangeEvent noChangeEvent = new NoChangeEvent(this, null, affectedText, startOffset, length);
        noChangeEvent.reason = NoChangeEvent.READ_ONLY_STATE_CHANGE;
        fireReadOnlyStructuredDocumentEvent(noChangeEvent);
    } catch (BadLocationException e) {
        // for now, log and ignore. Perhaps later we
        // could adjust to handle some cases?
        // $NON-NLS-1$ //$NON-NLS-2$
        Logger.logException(("could not create readonly region at " + startOffset + " to " + length), e);
    } catch (BadPositionCategoryException e) {
        // should never occur, since we add category
        Logger.logException(e);
    }
}
Also used : Position(org.eclipse.jface.text.Position) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) BadLocationException(org.eclipse.jface.text.BadLocationException)

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