org.eclipse.jface.text.TextViewer Java Examples

The following examples show how to use org.eclipse.jface.text.TextViewer. 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: CommonProjectionViewer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void handleDispose()
{
	// HACK We force the widget command to be nulled out so it can be garbage collected. Might want to
	// report a bug with eclipse to clean this up.
	try
	{
		Field f = TextViewer.class.getDeclaredField("fWidgetCommand"); //$NON-NLS-1$
		if (f != null)
		{
			f.setAccessible(true);
			f.set(this, null);
		}
	}
	catch (Throwable t)
	{
		// ignore
	}
	finally
	{
		super.handleDispose();
	}
}
 
Example #2
Source File: PropertiesFileMergeViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer) {
	if (!(textViewer instanceof SourceViewer))
		return;

	if (fPreferenceStore == null) {
		fSourceViewerConfigurations= new ArrayList<SourceViewerConfiguration>(3);
		fPreferenceStore= JavaPlugin.getDefault().getCombinedPreferenceStore();
		fPreferenceChangeListener= new IPropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent event) {
				Iterator<SourceViewerConfiguration> iter= fSourceViewerConfigurations.iterator();
				while (iter.hasNext())
					((PropertiesFileSourceViewerConfiguration)iter.next()).handlePropertyChangeEvent(event);
				invalidateTextPresentation();
			}
		};
		fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
	}

	SourceViewerConfiguration sourceViewerConfiguration= new PropertiesFileSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), fPreferenceStore, null,
			getDocumentPartitioning());

	fSourceViewerConfigurations.add(sourceViewerConfiguration);
	((SourceViewer)textViewer).configure(sourceViewerConfiguration);
}
 
Example #3
Source File: TypeScriptMergeViewer.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer viewer) {
	if (viewer instanceof SourceViewer) {
		SourceViewer sourceViewer = (SourceViewer) viewer;
		if (fSourceViewer == null)
			fSourceViewer = new ArrayList<>();
		if (!fSourceViewer.contains(sourceViewer))
			fSourceViewer.add(sourceViewer);
		TypeScriptTextTools tools = JSDTTypeScriptUIPlugin.getDefault().getJavaTextTools();
		if (tools != null) {
			IEditorInput editorInput = getEditorInput(sourceViewer);
			sourceViewer.unconfigure();
			if (editorInput == null) {
				sourceViewer.configure(getSourceViewerConfiguration(sourceViewer, null));
				return;
			}
			getSourceViewerConfiguration(sourceViewer, editorInput);
		}
	}
}
 
Example #4
Source File: JavaMergeViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer viewer) {
	if (viewer instanceof SourceViewer) {
		SourceViewer sourceViewer= (SourceViewer)viewer;
		if (fSourceViewer == null)
			fSourceViewer= new ArrayList<SourceViewer>();
		if (!fSourceViewer.contains(sourceViewer))
			fSourceViewer.add(sourceViewer);
		JavaTextTools tools= JavaCompareUtilities.getJavaTextTools();
		if (tools != null) {
			IEditorInput editorInput= getEditorInput(sourceViewer);
			sourceViewer.unconfigure();
			if (editorInput == null) {
				sourceViewer.configure(getSourceViewerConfiguration(sourceViewer, null));
				return;
			}
			getSourceViewerConfiguration(sourceViewer, editorInput);
		}
	}
}
 
Example #5
Source File: AbapGitStagingView.java    From ADT_Frontend with MIT License 6 votes vote down vote up
private void createCommitMessageComposite(Composite parent) {
	Composite commitMessageComposite = this.toolkit.createComposite(parent);
	this.toolkit.paintBordersFor(commitMessageComposite);
	GridLayoutFactory.fillDefaults().numColumns(1).applyTo(commitMessageComposite);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(commitMessageComposite);

	this.commitMessageTextViewer = new TextViewer(commitMessageComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	this.commitMessageTextViewer.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(this.commitMessageTextViewer.getTextWidget());
	this.commitMessageTextViewer.getTextWidget().setAlwaysShowScrollBars(false);
	this.commitMessageTextViewer.getTextWidget().setFont(JFaceResources.getTextFont());
	SWTUtil.addTextEditMenu(this.commitMessageTextViewer.getTextWidget());
	//draw a line to hint the max commit line length
	createMarginPainter(this.commitMessageTextViewer);

	this.commitMessageTextViewer.getTextWidget().addModifyListener(e -> validateInputs());
}
 
Example #6
Source File: RepositionHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * A semi-hack... This uses stuff that may change at any time in Eclipse.  
 * In the java editor, the projection annotation model contains the collapsible regions which correspond to methods (and other areas
 * such as import groups).
 * 
 * This may work in other editor types as well... TBD
 */
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection,
		ExecutionEvent event) throws BadLocationException {

	ITextViewerExtension viewer = MarkUtils.getITextViewer(editor);
	if (viewer instanceof ProjectionViewer) {
		ProjectionAnnotationModel projection = ((ProjectionViewer)viewer).getProjectionAnnotationModel();
		Iterator<Annotation> pit = projection.getAnnotationIterator();
		while (pit.hasNext()) {
			Position p = projection.getPosition(pit.next());
			if (p.includes(currentSelection.getOffset())) {
				if (isUniversalPresent()) {
					// Do this here to prevent subsequent scrolling once range is revealed
					MarkUtils.setSelection(editor, new TextSelection(document, p.offset, 0));
				}
				// the viewer is pretty much guaranteed to be a TextViewer
				if (viewer instanceof TextViewer) {
					((TextViewer)viewer).revealRange(p.offset, p.length);
				}
				break;
			}
		}
	}
	return NO_OFFSET;		
}
 
Example #7
Source File: CommonMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void configureTextViewer(final TextViewer textViewer)
{
	ThemePlugin.getDefault().getControlThemerFactory().apply(textViewer);

	// Force line highlight color. We need to perform this after the line painter is attached, which happens after
	// the return of this method. Scheduling async seems to work.
	UIUtils.getDisplay().asyncExec(new Runnable()
	{

		public void run()
		{
			CursorLinePainter p = getCursorLinePainterInstalled(textViewer);
			if (p != null)
			{
				p.setHighlightColor(getColorManager().getColor(getCurrentTheme().getLineHighlightAgainstBG()));
			}
		}
	});
}
 
Example #8
Source File: TMEditor.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
public TMEditor(IGrammar grammar, ITokenProvider tokenProvider, String text) {
	shell = new Shell();
	viewer = new TextViewer(shell, SWT.NONE);
	document = new Document();
	viewer.setDocument(document);
	commands = new ArrayList<>();
	collector = new StyleRangesCollector();

	setAndExecute(text);

	reconciler = new TMPresentationReconciler();
	reconciler.addTMPresentationReconcilerListener(collector);
	reconciler.setGrammar(grammar);
	reconciler.setTheme(tokenProvider);
	reconciler.install(viewer);

}
 
Example #9
Source File: CommonMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private CursorLinePainter getCursorLinePainterInstalled(TextViewer viewer)
{
	Listener[] listeners = viewer.getTextWidget().getListeners(3001/* StyledText.LineGetBackground */);
	for (Listener listener : listeners)
	{
		if (listener instanceof TypedListener)
		{
			TypedListener typedListener = (TypedListener) listener;
			if (typedListener.getEventListener() instanceof CursorLinePainter)
			{
				return (CursorLinePainter) typedListener.getEventListener();
			}
		}
	}
	return null;
}
 
Example #10
Source File: FormatterModifyTabPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected Composite doCreatePreviewPane(Composite composite, int numColumns)
{
	createLabel(numColumns - 1, composite, FormatterMessages.FormatterModifyTabPage_preview_label_text);

	fShowInvisibleButton = new Button(composite, SWT.CHECK);
	fShowInvisibleButton.setText(FormatterMessages.FormatterModifyTabPage_showInvisible);
	fShowInvisibleButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false));
	fShowInvisibleButton.addSelectionListener(new SelectionAdapter()
	{
		public void widgetSelected(SelectionEvent e)
		{
			final boolean newValue = fShowInvisibleButton.getSelection();
			updateShowInvisible(newValue);
			getDialogSettings().put(SHOW_INVISIBLE_PREFERENCE_KEY, newValue);
		}
	});
	previewViewer = dialog.getOwner().createPreview(composite);
	final boolean savedValue = getDialogSettings().getBoolean(SHOW_INVISIBLE_PREFERENCE_KEY);
	fShowInvisibleButton.setSelection(savedValue);
	updateShowInvisible(savedValue);

	if (previewViewer instanceof TextViewer)
	{
		GridData gd = createGridData(numColumns, GridData.FILL_BOTH, 0);
		gd.widthHint = 100;
		gd.heightHint = 100;
		((TextViewer) previewViewer).getControl().setLayoutData(gd);
	}

	return composite;
}
 
Example #11
Source File: CSSMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer)
{
	super.configureTextViewer(textViewer);

	if (textViewer instanceof SourceViewer)
	{
		SourceViewer sourceViewer = (SourceViewer) textViewer;
		sourceViewer.unconfigure();
		IPreferenceStore preferences = CSSSourceEditor.getChainedPreferenceStore();
		CSSSourceViewerConfiguration config = new CSSSourceViewerConfiguration(preferences, null);
		sourceViewer.configure(config);
	}
}
 
Example #12
Source File: DTDMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer)
{
	super.configureTextViewer(textViewer);

	if (textViewer instanceof SourceViewer)
	{
		SourceViewer sourceViewer = (SourceViewer) textViewer;
		sourceViewer.unconfigure();
		IPreferenceStore preferences = DTDEditor.getChainedPreferenceStore();
		DTDSourceViewerConfiguration config = new DTDSourceViewerConfiguration(preferences, null);
		sourceViewer.configure(config);
	}
}
 
Example #13
Source File: HTMLMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer)
{
	super.configureTextViewer(textViewer);

	if (textViewer instanceof SourceViewer)
	{
		SourceViewer sourceViewer = (SourceViewer) textViewer;
		sourceViewer.unconfigure();
		IPreferenceStore preferences = HTMLEditor.getChainedPreferenceStore();
		HTMLSourceViewerConfiguration config = new HTMLSourceViewerConfiguration(preferences, null);
		sourceViewer.configure(config);
	}
}
 
Example #14
Source File: JSMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer)
{
	super.configureTextViewer(textViewer);

	if (textViewer instanceof SourceViewer)
	{
		SourceViewer sourceViewer = (SourceViewer) textViewer;
		sourceViewer.unconfigure();
		IPreferenceStore preferences = JSSourceEditor.getChainedPreferenceStore();
		JSSourceViewerConfiguration config = new JSSourceViewerConfiguration(preferences, null);
		sourceViewer.configure(config);
	}
}
 
Example #15
Source File: SmartBackspaceManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void beginChange() {
	ITextViewer viewer= fViewer;
	if (viewer instanceof TextViewer) {
		TextViewer v= (TextViewer) viewer;
		v.getRewriteTarget().beginCompoundChange();
	}
}
 
Example #16
Source File: XMLMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer)
{
	super.configureTextViewer(textViewer);

	if (textViewer instanceof SourceViewer)
	{
		SourceViewer sourceViewer = (SourceViewer) textViewer;
		sourceViewer.unconfigure();
		IPreferenceStore preferences = XMLEditor.getChainedPreferenceStore();
		XMLSourceViewerConfiguration config = new XMLSourceViewerConfiguration(preferences, null);
		sourceViewer.configure(config);
	}
}
 
Example #17
Source File: SourceView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the action.
 *
 * @param textViewer the text viewer
 */
public SelectAllAction(TextViewer textViewer) {
	super("selectAll"); //$NON-NLS-1$

	Assert.isNotNull(textViewer);
	fTextViewer= textViewer;

	setText(InfoViewMessages.SelectAllAction_label);
	setToolTipText(InfoViewMessages.SelectAllAction_tooltip);
	setDescription(InfoViewMessages.SelectAllAction_description);

	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IAbstractTextEditorHelpContextIds.SELECT_ALL_ACTION);
}
 
Example #18
Source File: SVGMergeViewer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer)
{
	super.configureTextViewer(textViewer);

	if (textViewer instanceof SourceViewer)
	{
		SourceViewer sourceViewer = (SourceViewer) textViewer;
		sourceViewer.unconfigure();
		IPreferenceStore preferences = SVGEditor.getChainedPreferenceStore();
		SVGSourceViewerConfiguration config = new SVGSourceViewerConfiguration(preferences, null);
		sourceViewer.configure(config);
	}
}
 
Example #19
Source File: SmartBackspaceManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void endChange() {
	ITextViewer viewer= fViewer;
	if (viewer instanceof TextViewer) {
		TextViewer v= (TextViewer) viewer;
		v.getRewriteTarget().endCompoundChange();
	}
}
 
Example #20
Source File: TextMenuManager.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @param id
 * @param viewer
 * @param name
 * @param operation
 * @return
 */
private final SQLEditorAction getAction( String id, TextViewer viewer,
		String name, int operation )
{
	SQLEditorAction action = (SQLEditorAction) htActions.get( id );
	if ( action == null )
	{
		action = new SQLEditorAction( viewer, name, operation );
		htActions.put( id, action );
	}
	return action;
}
 
Example #21
Source File: TLACoverageEditor.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
protected SourceViewerDecorationSupport getSourceViewerDecorationSupport(ISourceViewer viewer) {
	//TODO Initialize painter after editor input has been set.
	painter = new TLACoveragePainter(this);
	((TextViewer) viewer).addTextPresentationListener(painter);
	
	return super.getSourceViewerDecorationSupport(viewer);
}
 
Example #22
Source File: TextMenuManager.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public SQLEditorAction( TextViewer viewer, String text,
		int operationCode )
{
	super( text );
	this.operationCode = operationCode;
	this.viewer = viewer;
}
 
Example #23
Source File: MarkUtils.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param editor
 * @param start
 *            - in model coords
 * @param length
 *            - in model coords
 */
public static ITextSelection setSelection(ITextEditor editor, int start, int length) {

	TextViewer tv = findTextViewer(editor);
	ITextSelection selection = new TextSelection(null, start, length);
	if (tv != null) {
		tv.setSelection(selection, false);
	} else {
		setSelection(editor, selection);
	}
	return selection;
}
 
Example #24
Source File: ToggleCommentHandler.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ITextSelection selection = WorkbenchUtils.getActiveTextSelection();
    IDocument      document  = WorkbenchUtils.getActiveDocument();
    IEditorInput   input     = WorkbenchUtils.getActiveInput();
    IEditorPart    editor    = WorkbenchUtils.getActiveEditor(false);

    boolean isTextOperationAllowed = (selection != null) && (document != null) 
                                  && (input != null)     && (editor != null) 
                                  && (editor instanceof SourceCodeTextEditor);

    if (isTextOperationAllowed) {
        final ITextOperationTarget operationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
        String commentPrefix = ((SourceCodeTextEditor)editor).getEOLCommentPrefix();
        isTextOperationAllowed = (operationTarget != null)
                              && (operationTarget instanceof TextViewer)
                              && (validateEditorInputState((ITextEditor)editor))
                              && (commentPrefix != null);
        
        if ((isTextOperationAllowed)) {
            final int operation = isSelectionCommented(document, selection, commentPrefix) 
                                ? ITextOperationTarget.STRIP_PREFIX 
                                : ITextOperationTarget.PREFIX;

            if (operationTarget.canDoOperation(operation)) {
                BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
                    public void run() {
                        // Really processed in TextViewer.doOperation:
                        operationTarget.doOperation(operation);
                    }
                });
            }
        }
    }

    return null;
}
 
Example #25
Source File: TextUtils.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
public static TabSpacesInfo getTabSpaces(ITextViewer viewer) {
	TabsToSpacesConverter converter = ClassHelper.getFieldValue(viewer, "fTabsToSpacesConverter", TextViewer.class); //$NON-NLS-1$
	if (converter != null) {
		int tabSize = ClassHelper.getFieldValue(converter, "fTabRatio", TabsToSpacesConverter.class); //$NON-NLS-1$
		return new TabSpacesInfo(tabSize, true);
	}
	return new TabSpacesInfo(-1, false);
}
 
Example #26
Source File: LangTextMergeViewer.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configureTextViewer(TextViewer textViewer) {
	if(textViewer instanceof SourceViewer) {
		SourceViewer sourceViewer = (SourceViewer) textViewer;
		sourceViewer.configure(getSourceViewerConfiguration(sourceViewer));
	} else {
		super.configureTextViewer(textViewer);
	}
	sourceViewerNumber = (sourceViewerNumber + 1) % 3;
}
 
Example #27
Source File: TMPresentationReconciler.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initialize foreground, background color, current line highlight from the
 * current theme if needed.
 *
 */
private void applyThemeEditorIfNeeded() {
	if (!initializeViewerColors) {
		StyledText styledText = viewer.getTextWidget();
		((ITheme) tokenProvider).initializeViewerColors(styledText);
		initializeViewerColors = true;
	}
	if (updateTextDecorations) {
		return;
	}
	try {
		// Ugly code to update "current line highlight" :
		// - get the PaintManager from the ITextViewer with reflection.
		// - get the list of IPainter of PaintManager with reflection
		// - loop for IPainter to retrieve CursorLinePainter which manages "current line
		// highlight".
		PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class);
		if (paintManager == null) {
			return;
		}
		List<IPainter> painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class);
		if (painters == null) {
			return;
		}
		for (IPainter painter : painters) {
			if (painter instanceof CursorLinePainter) {
				// Update current line highlight
				Color background = tokenProvider.getEditorCurrentLineHighlight();
				if (background != null) {
					((CursorLinePainter) painter).setHighlightColor(background);
				}
				updateTextDecorations = true;
			}
		}
	} catch (Exception e) {
		TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e));
	}
}
 
Example #28
Source File: PyPeerLinker.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a handler that will properly treat backspaces considering python code.
 */
public static VerifyKeyListener createVerifyKeyListener(final TextViewer viewer) {
    return new VerifyKeyListener() {

        private final PyPeerLinker pyPeerLinker = new PyPeerLinker();

        @Override
        public void verifyKey(VerifyEvent event) {
            if (!event.doit) {
                return;
            }
            switch (event.character) {
                case '\'':
                case '\"':
                case '[':
                case '{':
                case '(':
                case ']':
                case '}':
                case ')':
                    break;
                default:
                    return;
            }
            if (viewer != null && viewer.isEditable()) {
                boolean blockSelection = false;
                try {
                    blockSelection = viewer.getTextWidget().getBlockSelection();
                } catch (Throwable e) {
                    //that's OK (only available in eclipse 3.5)
                }
                if (!blockSelection) {
                    if (viewer instanceof ITextViewerExtensionAutoEditions) {
                        ITextViewerExtensionAutoEditions autoEditions = (ITextViewerExtensionAutoEditions) viewer;
                        if (!autoEditions.getAutoEditionsEnabled()) {
                            return;
                        }
                    }

                    ISelection selection = viewer.getSelection();
                    if (selection instanceof ITextSelection) {
                        IAdaptable adaptable;
                        if (viewer instanceof IAdaptable) {
                            adaptable = (IAdaptable) viewer;
                        } else {
                            adaptable = new IAdaptable() {

                                @Override
                                public <T> T getAdapter(Class<T> adapter) {
                                    return null;
                                }
                            };
                        }

                        //Don't bother in getting the indent prefs from the editor: the default indent prefs are
                        //always global for the settings we want.
                        pyPeerLinker.setIndentPrefs(new DefaultIndentPrefs(adaptable));
                        ITextSelection textSelection = (ITextSelection) selection;
                        PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(viewer, textSelection);

                        if (pyPeerLinker.perform(ps, event.character, viewer)) {
                            event.doit = false;
                        }
                    }
                }
            }
        }
    };
}
 
Example #29
Source File: PyBackspace.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a handler that will properly treat backspaces considering python code.
 */
public static VerifyKeyListener createVerifyKeyListener(final TextViewer viewer, final PyEdit edit) {
    return new VerifyKeyListener() {

        @Override
        public void verifyKey(VerifyEvent event) {
            if ((event.doit && event.character == SWT.BS && event.stateMask == 0 && viewer != null && viewer
                    .isEditable())) { //isBackspace
                boolean blockSelection = false;
                try {
                    blockSelection = viewer.getTextWidget().getBlockSelection();
                } catch (Throwable e) {
                    //that's OK (only available in eclipse 3.5)
                }
                if (!blockSelection) {
                    if (viewer instanceof ITextViewerExtensionAutoEditions) {
                        ITextViewerExtensionAutoEditions autoEditions = (ITextViewerExtensionAutoEditions) viewer;
                        if (!autoEditions.getAutoEditionsEnabled()) {
                            return;
                        }
                    }

                    ISelection selection = viewer.getSelection();
                    if (selection instanceof ITextSelection) {
                        //Only do our custom backspace if we're not in block selection mode.
                        PyBackspace pyBackspace = new PyBackspace();
                        if (edit != null) {
                            pyBackspace.setEditor(edit);
                        } else {
                            IAdaptable adaptable;
                            if (viewer instanceof IAdaptable) {
                                adaptable = (IAdaptable) viewer;
                            } else {
                                adaptable = new IAdaptable() {

                                    @Override
                                    public <T> T getAdapter(Class<T> adapter) {
                                        return null;
                                    }
                                };
                            }
                            pyBackspace.setIndentPrefs(new DefaultIndentPrefs(adaptable));
                        }
                        PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(viewer,
                                (ITextSelection) selection);
                        pyBackspace.perform(ps);
                        event.doit = false;
                    }
                }
            }
        }
    };
}
 
Example #30
Source File: PatternExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected TextViewer createViewer(final Composite parent) {
	return new SourceViewer(parent,null,SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
}