Java Code Examples for org.eclipse.swt.custom.StyledText#isDisposed()

The following examples show how to use org.eclipse.swt.custom.StyledText#isDisposed() . 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: SubWordActions.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
    final ISourceViewer viewer = getSourceViewer();

    final StyledText text = viewer.getTextWidget();
    if (text != null && !text.isDisposed()) {

        final Point selection = text.getSelection();
        final int caret = text.getCaretOffset();
        final int offset = modelOffset2WidgetOffset(viewer, position);

        if (caret == selection.x) {
            text.setSelectionRange(selection.y, offset - selection.y);
        } else {
            text.setSelectionRange(selection.x, offset - selection.x);
        }
    }
}
 
Example 2
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void selectText() {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}
	// viewer.setSelectedRange(selectionOffset, selectionLength)
	int textLength = text.getText().length();
	if (textLength > 0) {
		EditorSelectionEnum selectionMode = getSelectionMode();
		if (selectionMode == EditorSelectionEnum.ALL) {
			text.setSelection(0, textLength);
		} else if (selectionMode == EditorSelectionEnum.END) {
			text.setSelection(textLength, textLength);
		}
	}
	text.setCaretOffset(textLength);
}
 
Example 3
Source File: AnnotationExpansionControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void resetViewerBackground(StyleRange[] oldRanges) {

		if (oldRanges == null)
			return;

		if (fInput == null)
			return;

		StyledText text= fInput.fViewer.getTextWidget();
		if (text == null || text.isDisposed())
			return;

		// set the ranges one by one
		for (int i= 0; i < oldRanges.length; i++) {
			text.setStyleRange(oldRanges[i]);
		}
	}
 
Example 4
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
	final ISourceViewer viewer= getSourceViewer();

	final StyledText text= viewer.getTextWidget();
	if (text != null && !text.isDisposed()) {

		final Point selection= text.getSelection();
		final int caret= text.getCaretOffset();
		final int offset= modelOffset2WidgetOffset(viewer, position);

		if (caret == selection.x)
			text.setSelectionRange(selection.y, offset - selection.y);
		else
			text.setSelectionRange(selection.x, offset - selection.x);
	}
}
 
Example 5
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
	final ISourceViewer viewer = getSourceViewer();

	final StyledText text = viewer.getTextWidget();
	if (text != null && !text.isDisposed()) {

		final Point selection = text.getSelection();
		final int caret = text.getCaretOffset();
		final int offset = modelOffset2WidgetOffset(viewer, position);

		if (caret == selection.x)
			text.setSelectionRange(selection.y, offset - selection.y);
		else
			text.setSelectionRange(selection.x, offset - selection.x);
	}
}
 
Example 6
Source File: PythonSourceViewer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates the given viewer's colors to match the preferences.
 */
public void updateViewerColors() {
    IPreferenceStore store = getPreferenceStore();
    if (store != null) {
        StyledText styledText = getTextWidget();
        if (styledText == null || styledText.isDisposed()) {
            return;
        }
        Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null
                : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
        styledText.setForeground(color);
        if (getForegroundColor() != null) {
            getForegroundColor().dispose();
        }
        setForegroundColor(color);

        color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null
                : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
        styledText.setBackground(color);
        if (getBackgroundColor() != null) {
            getBackgroundColor().dispose();
        }
        setBackgroundColor(color);
    }
}
 
Example 7
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
	final ISourceViewer viewer = getSourceViewer();

	final StyledText text = viewer.getTextWidget();
	if (text != null && !text.isDisposed()) {

		final Point selection = text.getSelection();
		final int caret = text.getCaretOffset();
		final int offset = modelOffset2WidgetOffset(viewer, position);

		if (caret == selection.x)
			text.setSelectionRange(selection.y, offset - selection.y);
		else
			text.setSelectionRange(selection.x, offset - selection.x);
	}
}
 
Example 8
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void close() {
	if (close) {
		return;
	}

	for (Listener listener : closingListeners) {
		Event event = new Event();
		event.data = this;
		listener.handleEvent(event);
	}

	close = true; // 状态改为已经关闭
	xliffEditor.getTable().removeDisposeListener(this);

	StyledText text = viewer.getTextWidget();
	if (text != null && !text.isDisposed()) {
		actionHandler.removeTextViewer();
		text.setMenu(null); // dispose前应去掉右键menu,因为右键menu是和nattable共享的
		viewer.reset();
		text.dispose();
		text = null;
	}

	// 如果 XLIFF 编辑器仍处于激活状态,则把焦点交给编辑器
	try {
		IWorkbenchPart activepart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActivePart();
		if (xliffEditor.equals(activepart)) {
			xliffEditor.setFocus();
		}
	} catch (NullPointerException e) {
	}

	// NatTable table = xliffEditor.getTable();
	// int[] rowPositions = new int[] { hsCellEditor.getRowPosition() };
	// table.doCommand(new AutoResizeCurrentRowsCommand(table, rowPositions, table.getConfigRegistry()));
}
 
Example 9
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void disposeEmbeddedEditor() {
	if (mouseListener != null && switchControl != null && !switchControl.isDisposed()) {
		switchControl.removeMouseListener(mouseListener);
		mouseListener = null;
		switchControl.dispose();
		switchControl = null;
	}
	if (inlineIcon != null && !inlineIcon.isDisposed())
		inlineIcon.dispose();

	if (collapsedBorder != null && !collapsedBorder.isDisposed())
		collapsedBorder.dispose();

	if (embeddedEditor != null) {
		embeddedEditor.getDocument().getValidationJob().cancel();
		StyledText embeddedEditorWidget = embeddedEditor.getViewer().getTextWidget();
		if (embeddedEditorWidget != null && !embeddedEditorWidget.isDisposed()) {
			if (resizeListener != null) {
				embeddedEditorWidget.removeControlListener(resizeListener);
				getSash().removeControlListener(resizeListener);
				resizeListener = null;
			}
			embeddedEditorWidget.dispose();
			embeddedEditorWidget = null;
			embeddedEditor = null;
		}
	}
	nameModificationListener = null;
}
 
Example 10
Source File: StyledTextCellEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将指定文本添加到光标所在位置。 robert 2011-12-21
 * @param canonicalValue
 *            ;
 */
public void insertCanonicalValue(Object canonicalValue) {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}

	int offset = text.getCaretOffset();
	text.insert(canonicalValue.toString());
	text.setCaretOffset(offset + canonicalValue.toString().length());
}
 
Example 11
Source File: RenameLinkedMode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static RenameLinkedMode getActiveLinkedMode() {
	if (fgActiveLinkedMode != null) {
		ISourceViewer viewer= fgActiveLinkedMode.fEditor.getViewer();
		if (viewer != null) {
			StyledText textWidget= viewer.getTextWidget();
			if (textWidget != null && ! textWidget.isDisposed()) {
				return fgActiveLinkedMode;
			}
		}
		// make sure we don't hold onto the active linked mode if anything went wrong with canceling:
		fgActiveLinkedMode= null;
	}
	return null;
}
 
Example 12
Source File: TypeScriptEditor.java    From typescript.java with MIT License 5 votes vote down vote up
public void install() {
	ISourceViewer sourceViewer = getSourceViewer();
	if (sourceViewer == null)
		return;

	StyledText text = sourceViewer.getTextWidget();
	if (text == null || text.isDisposed())
		return;

	sourceViewer.addTextInputListener(this);

	IDocument document = sourceViewer.getDocument();
	if (document != null)
		document.addDocumentListener(this);
}
 
Example 13
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将指定文本添加到光标所在位置。 robert 2011-12-21
 * @param canonicalValue
 *            ;
 */
public void insertCanonicalValue(Object canonicalValue) {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}

	int offset = text.getCaretOffset();
	text.insert(canonicalValue.toString());
	text.setCaretOffset(offset + canonicalValue.toString().length());
}
 
Example 14
Source File: ResultPage.java    From tlaplus with MIT License 5 votes vote down vote up
/**
    * {@inheritDoc}
    */
@Override
public void setFocus() {
	if ((expressionEvalInput != null) && !expressionEvalInput.getTextWidget().isDisposed()
									  && !expressionEvalInput.getTextWidget().isFocusControl()) {
		final StyledText st = expressionEvalInput.getTextWidget();
		final int caretOffset = st.getText().length();
		
		st.setFocus();
		
		/*
		 * We get a focus notification at least 3 times after TLC execution finishes, in which none of those times
		 * 	does the text widget believe itself focused. Further, the text widget gaining focus resets its caret
		 * 	offset to 0; so, nearly ubiquitously we end up with the caret offset position set invocation never
		 * 	sticking. We resort to this waiting-out-the-notification-storm ugly hack to get the caret set
		 *  to stick; were we getting more than 3 notifications, i would use a thread pool to gate proliferation
		 *  here.
		 */
		final Runnable ohSWT = () -> {
			try {
				Thread.sleep(75);
			} catch (Exception e) { }
			
			if (!st.isDisposed()) {
				st.getDisplay().asyncExec(() -> {
					if (!st.isDisposed()) {
						st.setCaretOffset(caretOffset);
					}
				});
			}
		};
		(new Thread(ohSWT)).start();
	}
}
 
Example 15
Source File: SearchMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
protected void leave() {
	StyledText text = getTextWidget();
	if (text != null && !text.isDisposed()) {
		leave(text.getCaretOffset());
	} else {
		super.leave(true);
	}
}
 
Example 16
Source File: PyCompletionPresentationUpdater.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private StyleRange createStyleRange(ITextViewer viewer, int initialOffset, int len) {
    StyledText text = viewer.getTextWidget();
    if (text == null || text.isDisposed()) {
        return null;
    }

    int widgetCaret = text.getCaretOffset();

    int modelCaret = 0;
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        modelCaret = extension.widgetOffset2ModelOffset(widgetCaret);
    } else {
        IRegion visibleRegion = viewer.getVisibleRegion();
        modelCaret = widgetCaret + visibleRegion.getOffset();
    }

    if (modelCaret >= initialOffset + len) {
        return null;
    }

    int length = initialOffset + len - modelCaret;

    Color foreground = getForegroundColor();
    Color background = getBackgroundColor();

    return new StyleRange(modelCaret, length, foreground, background);
}
 
Example 17
Source File: AbstractThemeableEditor.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void dispose()
{
	try
	{
		SourceViewerConfiguration svc = getSourceViewerConfiguration();
		if (svc instanceof CommonSourceViewerConfiguration)
		{
			((CommonSourceViewerConfiguration) svc).dispose();
		}
		if (fWordWrapControlListener != null)
		{
			ISourceViewer sourceViewer = getSourceViewer();
			if (sourceViewer != null)
			{
				StyledText textWidget = sourceViewer.getTextWidget();
				if (textWidget != null && !textWidget.isDisposed())
				{
					textWidget.removeControlListener(fWordWrapControlListener);
				}
			}
			fWordWrapControlListener = null;
		}

		if (occurrencesUpdater != null)
		{
			occurrencesUpdater.dispose();
			occurrencesUpdater = null;
		}

		if (fSelectionChangedListener != null)
		{
			fSelectionChangedListener.uninstall(getSelectionProvider());
			fSelectionChangedListener = null;
		}

		if (fThemeListener != null)
		{
			ThemePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fThemeListener);
			fThemeListener = null;
		}

		if (fThemeableEditorColorsExtension != null)
		{
			fThemeableEditorColorsExtension.dispose();
			fThemeableEditorColorsExtension = null;
		}

		if (fThemeableEditorFindBarExtension != null)
		{
			fThemeableEditorFindBarExtension.dispose();
			fThemeableEditorFindBarExtension = null;
		}
		if (foldingActionsGroup != null)
		{
			foldingActionsGroup.dispose();
			foldingActionsGroup = null;
		}

		if (fOutlinePage != null)
		{
			fOutlinePage.dispose();
			fOutlinePage = null;
		}

		fCommandElementsProvider = null;
		fPeerCharacterCloser = null;

		IDragAndDropService dndService = (IDragAndDropService) getSite().getService(IDragAndDropService.class);
		if (dndService != null)
		{
			ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
			if (viewer != null)
			{
				StyledText st = viewer.getTextWidget();
				if (st != null)
				{
					dndService.removeMergedDropTarget(st);
				}
			}
		}
	}
	finally
	{
		super.dispose();
	}
}
 
Example 18
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public void checkWidget() {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		SWT.error(SWT.ERROR_FAILED_EVALUATE);
	}
}
 
Example 19
Source File: JavaSourceViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void configure(SourceViewerConfiguration configuration) {

	/*
	 * Prevent access to colors disposed in unconfigure(), see:
	 *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641
	 *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177
	 */
	StyledText textWidget= getTextWidget();
	if (textWidget != null && !textWidget.isDisposed()) {
		Color foregroundColor= textWidget.getForeground();
		if (foregroundColor != null && foregroundColor.isDisposed())
			textWidget.setForeground(null);
		Color backgroundColor= textWidget.getBackground();
		if (backgroundColor != null && backgroundColor.isDisposed())
			textWidget.setBackground(null);
	}

	super.configure(configuration);
	if (configuration instanceof JavaSourceViewerConfiguration) {
		JavaSourceViewerConfiguration javaSVCconfiguration= (JavaSourceViewerConfiguration)configuration;
		fOutlinePresenter= javaSVCconfiguration.getOutlinePresenter(this, false);
		if (fOutlinePresenter != null)
			fOutlinePresenter.install(this);

		fStructurePresenter= javaSVCconfiguration.getOutlinePresenter(this, true);
		if (fStructurePresenter != null)
			fStructurePresenter.install(this);

		fHierarchyPresenter= javaSVCconfiguration.getHierarchyPresenter(this, true);
		if (fHierarchyPresenter != null)
			fHierarchyPresenter.install(this);

	}

	if (fPreferenceStore != null) {
		fPreferenceStore.addPropertyChangeListener(this);
		initializeViewerColors();
	}

	fIsConfigured= true;
}
 
Example 20
Source File: AbstractCompletionProposalExtension.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Called when Ctrl is selected during the completions
 * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean)
 */
@Override
public void selected(ITextViewer viewer, boolean smartToggle) {
    if (smartToggle) {
        StyledText text = viewer.getTextWidget();
        if (text == null || text.isDisposed()) {
            return;
        }

        int widgetCaret = text.getCaretOffset();
        IDocument document = viewer.getDocument();
        int finalOffset = widgetCaret;

        try {
            if (finalOffset >= document.getLength()) {
                unselected(viewer);
                return;
            }
            char c;
            do {
                c = document.getChar(finalOffset);
                finalOffset++;
            } while (isValidChar(c) && finalOffset < document.getLength());

            if (c == '(') {
                fLastIsPar = true;
            } else {
                fLastIsPar = false;
            }

            if (!isValidChar(c)) {
                finalOffset--;
            }

            this.fLen = finalOffset - widgetCaret;
            this.getPresentationUpdater().selected(viewer, widgetCaret, this.fLen);
        } catch (BadLocationException e) {
            Log.log(e);
        }

    } else {
        unselected(viewer);
    }
}