Java Code Examples for org.eclipse.jface.text.DocumentEvent#getDocument()

The following examples show how to use org.eclipse.jface.text.DocumentEvent#getDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentLineList.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void documentChanged(DocumentEvent event) {
	IDocument document = event.getDocument();
	try {
		int startLine = DocumentHelper.getStartLine(event);
		if (!DocumentHelper.isRemove(event)) {
			int endLine = DocumentHelper.getEndLine(event, false);
			// Insert new lines
			for (int i = startLine; i < endLine; i++) {
				DocumentLineList.this.addLine(i + 1);
			}
			if (startLine == endLine) {
				DocumentLineList.this.updateLine(startLine);
			}
		} else {
			// Update line
			DocumentLineList.this.updateLine(startLine);
		}
		invalidateLine(startLine);
	} catch (BadLocationException e) {
		TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e));
	}
}
 
Example 2
Source File: JsonEditor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void documentChanged(DocumentEvent event) {
    if (event.getDocument() instanceof JsonDocument) {
        final JsonDocument document = (JsonDocument) event.getDocument();

        document.onChange();
        Display.getCurrent().asyncExec(new Runnable() {
            @Override
            public void run() {
                if (contentOutline != null) {
                    // depends on the results of document.onChange()
                    contentOutline.setInput(getEditorInput());
                }
            }
        });
        // depends on the results of document.onChange()
        runValidate(false);
    }
}
 
Example 3
Source File: KillRing.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Determine if a selection is being replaced by non-emacs+ behavior (or YANK), and save the
 * replaced content in the kill ring. This captures the Eclipse (but not emacs) behavior where
 * typing/pasting into a selection replaces the old with the new, so it is appropriate to save
 * the old text to the kill ring.
 * 
 * @param event the DocumentEvent containing the IDocument, offset, and length
 * @return true if the non-zero length region matches the current selection in the editor
 */
private boolean isSelectionReplace(DocumentEvent event) {
	int len = event.getLength();
	// ignore plain insertion or any emacs+ (except YANK) command invocation
	if (selectionReplace &&  len > 0 && shouldSave()) {
		ITextEditor editor = EmacsPlusUtils.getCurrentEditor();
		// otherwise, if we can get the selection, see if it matches the replace region
		if (editor != null && editor.getDocumentProvider().getDocument(editor.getEditorInput()) == event.getDocument()) {
			ISelection isel = editor.getSelectionProvider().getSelection();
			if (isel instanceof ITextSelection) {
				ITextSelection selection = (ITextSelection)isel;
				boolean result = selection.getOffset() == event.getOffset() && selection.getLength() == len;
				return result;
			}
		}
	}
	return false;
}
 
Example 4
Source File: PatternExpressionModelBuilder.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void documentChanged(DocumentEvent event) {
    final IDocument document = event.getDocument();
    if (shouldBuild()) {
        doBuild(document, allGroovyPartitions(document));
    }
}
 
Example 5
Source File: LogViewer.java    From LogViewer with Eclipse Public License 2.0 4 votes vote down vote up
public void documentChanged(DocumentEvent event) {
    if(!isAvailable()) {
        return;
    }

    LogFileTab tab = getSelectedTab();

    // activate / show the view and tab
    if (viewer.isShowWhenUpdated()) {
        //LogViewer view = null;
        try {
            //view = (LogViewer)
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("de.anbos.eclipse.logviewer.plugin.LogViewer");
        } catch (PartInitException e) {
            e.printStackTrace();
        }

        // change selection
        if (event.getDocument() != tab.getDocument()) {
            // show active document
            Iterator<String> keyIterator = logTab.keySet().iterator();
            while(keyIterator.hasNext()) {
                Object key = keyIterator.next();
                LogFileTab newTab = logTab.get(key);
                if (event.getDocument() == newTab.getDocument()) {
                    showDocument(newTab.getDocument(),null,0,true);
                    tabfolder.setSelection(new TabItem[] {newTab.getItem()});
                    // send event to refresh encoding
                    Event newEvent = new Event();
                    newEvent.item = newTab.getItem();
                    tabfolder.notifyListeners(SWT.Selection, newEvent);
                    break;
                }
            }
        }
    }

    if(logTab != null && event.getDocument() == tab.getDocument() && viewer.getDocument() != null) {
        viewer.refresh();
        viewer.showBottomOfFile();
    }
    if (stopAfterChange) {
        stopAfterChange = false;
        stopTail();
    }
}