Search in sources :

Example 6 with ITextListener

use of org.eclipse.jface.text.ITextListener in project eclipse-integration-commons by spring-projects.

the class EditorToolkit method createTextEditor.

public TextViewer createTextEditor(Composite composite, String text, boolean spellCheck, int style) {
    AnnotationModel annotationModel = new AnnotationModel();
    final SourceViewer textViewer = new SourceViewer(composite, null, null, true, style);
    textViewer.showAnnotations(false);
    textViewer.showAnnotationsOverview(false);
    IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(textViewer, null, annotationAccess, EditorsUI.getSharedTextColors());
    @SuppressWarnings("unchecked") Iterator e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator();
    while (e.hasNext()) {
        support.setAnnotationPreference((AnnotationPreference) e.next());
    }
    support.install(EditorsUI.getPreferenceStore());
    textViewer.getTextWidget().setIndent(2);
    textViewer.getTextWidget().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            support.uninstall();
        }
    });
    IThemeManager themeManager = editorSite.getWorkbenchWindow().getWorkbench().getThemeManager();
    textViewer.getTextWidget().setFont(themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT));
    final ActionContributorProxy actionContributor = getContributor();
    if (actionContributor.getSelectionChangedListener() != null) {
        textViewer.addSelectionChangedListener(actionContributor.getSelectionChangedListener());
    }
    textViewer.getTextWidget().addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            actionContributor.updateSelectableActions(textViewer.getSelection());
        }

        public void focusLost(FocusEvent e) {
            StyledText st = (StyledText) e.widget;
            st.setSelectionRange(st.getCaretOffset(), 0);
            actionContributor.forceActionsEnabled();
        }
    });
    textViewer.addTextListener(new ITextListener() {

        public void textChanged(TextEvent event) {
            actionContributor.updateSelectableActions(textViewer.getSelection());
        }
    });
    Document document = new Document(text);
    StsTextViewerConfiguration viewerConfig = new StsTextViewerConfiguration(spellCheck, false);
    textViewer.configure(viewerConfig);
    textViewer.setDocument(document, annotationModel);
    EditorUtil.setTextViewer(textViewer.getControl(), textViewer);
    configureContextMenuManager(textViewer.getControl());
    return textViewer;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TextEvent(org.eclipse.jface.text.TextEvent) ITextListener(org.eclipse.jface.text.ITextListener) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) IThemeManager(org.eclipse.ui.themes.IThemeManager) MarkerAnnotationPreferences(org.eclipse.ui.texteditor.MarkerAnnotationPreferences) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Document(org.eclipse.jface.text.Document) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) FocusEvent(org.eclipse.swt.events.FocusEvent) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) Iterator(java.util.Iterator) FocusListener(org.eclipse.swt.events.FocusListener)

Example 7 with ITextListener

use of org.eclipse.jface.text.ITextListener in project webtools.sourceediting by eclipse.

the class TestTextViewer method fireTextChanged.

protected void fireTextChanged(TextEvent event) {
    Iterator e = new ArrayList(fTextListeners).iterator();
    while (e.hasNext()) {
        ITextListener l = (ITextListener) e.next();
        l.textChanged(event);
    }
}
Also used : ITextListener(org.eclipse.jface.text.ITextListener) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList)

Example 8 with ITextListener

use of org.eclipse.jface.text.ITextListener in project egit by eclipse.

the class GitHistoryPage method createControl.

@Override
public void createControl(final Composite parent) {
    trace = GitTraceLocation.HISTORYVIEW.isActive();
    if (trace)
        GitTraceLocation.getTrace().traceEntry(GitTraceLocation.HISTORYVIEW.getLocation());
    attachSelectionTracker();
    historyControl = createMainPanel(parent);
    warningComposite = new Composite(historyControl, SWT.NONE);
    warningComposite.setLayout(new GridLayout(2, false));
    warningComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    warningLabel = new CLabel(warningComposite, SWT.NONE);
    warningLabel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    warningLabel.setToolTipText(UIText.GitHistoryPage_IncompleteListTooltip);
    Link preferencesLink = new Link(warningComposite, SWT.NONE);
    preferencesLink.setText(UIText.GitHistoryPage_PreferencesLink);
    preferencesLink.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // $NON-NLS-1$
            String preferencePageId = "org.eclipse.egit.ui.internal.preferences.HistoryPreferencePage";
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), preferencePageId, new String[] { preferencePageId }, null);
            dialog.open();
        }
    });
    GridDataFactory.fillDefaults().grab(true, true).applyTo(historyControl);
    graphDetailSplit = new SashForm(historyControl, SWT.VERTICAL);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(graphDetailSplit);
    graph = new CommitGraphTable(graphDetailSplit, getSite(), popupMgr, this, resources);
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(listener);
    revInfoSplit = new SashForm(graphDetailSplit, SWT.HORIZONTAL);
    commentAndDiffScrolledComposite = new ScrolledComposite(revInfoSplit, SWT.H_SCROLL | SWT.V_SCROLL);
    commentAndDiffScrolledComposite.setExpandHorizontal(true);
    commentAndDiffScrolledComposite.setExpandVertical(true);
    commentAndDiffComposite = new Composite(commentAndDiffScrolledComposite, SWT.NONE);
    commentAndDiffScrolledComposite.setContent(commentAndDiffComposite);
    commentAndDiffComposite.setLayout(GridLayoutFactory.fillDefaults().create());
    commentViewer = new CommitMessageViewer(commentAndDiffComposite, getPartSite());
    commentViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    commentViewer.addTextListener(new ITextListener() {

        @Override
        public void textChanged(TextEvent event) {
            resizeCommentAndDiffScrolledComposite();
        }
    });
    commentAndDiffComposite.setBackground(commentViewer.getControl().getBackground());
    HyperlinkSourceViewer.Configuration configuration = new HyperlinkSourceViewer.Configuration(EditorsUI.getPreferenceStore()) {

        @Override
        public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
            return SWT.NONE;
        }

        @Override
        protected IHyperlinkDetector[] internalGetHyperlinkDetectors(ISourceViewer sourceViewer) {
            IHyperlinkDetector[] registered = super.internalGetHyperlinkDetectors(sourceViewer);
            // want those to show always.
            if (registered == null) {
                return new IHyperlinkDetector[] { new CommitMessageViewer.KnownHyperlinksDetector() };
            } else {
                IHyperlinkDetector[] result = new IHyperlinkDetector[registered.length + 1];
                System.arraycopy(registered, 0, result, 0, registered.length);
                result[registered.length] = new CommitMessageViewer.KnownHyperlinksDetector();
                return result;
            }
        }

        @Override
        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return new String[] { IDocument.DEFAULT_CONTENT_TYPE, CommitMessageViewer.HEADER_CONTENT_TYPE, CommitMessageViewer.FOOTER_CONTENT_TYPE };
        }

        @Override
        public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) {
            PresentationReconciler reconciler = new PresentationReconciler();
            reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(viewer));
            DefaultDamagerRepairer hyperlinkDamagerRepairer = new DefaultDamagerRepairer(new HyperlinkTokenScanner(this, viewer));
            reconciler.setDamager(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            reconciler.setRepairer(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            TextAttribute headerDefault = new TextAttribute(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
            DefaultDamagerRepairer headerDamagerRepairer = new DefaultDamagerRepairer(new HyperlinkTokenScanner(this, viewer, headerDefault));
            reconciler.setDamager(headerDamagerRepairer, CommitMessageViewer.HEADER_CONTENT_TYPE);
            reconciler.setRepairer(headerDamagerRepairer, CommitMessageViewer.HEADER_CONTENT_TYPE);
            DefaultDamagerRepairer footerDamagerRepairer = new DefaultDamagerRepairer(new FooterTokenScanner(this, viewer));
            reconciler.setDamager(footerDamagerRepairer, CommitMessageViewer.FOOTER_CONTENT_TYPE);
            reconciler.setRepairer(footerDamagerRepairer, CommitMessageViewer.FOOTER_CONTENT_TYPE);
            return reconciler;
        }
    };
    commentViewer.configure(configuration);
    diffViewer = new DiffViewer(commentAndDiffComposite, null, SWT.NONE);
    diffViewer.configure(new DiffViewer.Configuration(EditorsUI.getPreferenceStore()));
    diffViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    setWrap(store.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP));
    commentAndDiffScrolledComposite.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            if (!resizing && commentViewer.getTextWidget().getWordWrap()) {
                resizeCommentAndDiffScrolledComposite();
            }
        }
    });
    fileViewer = new CommitFileDiffViewer(revInfoSplit, getSite());
    fileViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            List<FileDiff> diffs = new ArrayList<>();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection sel = (IStructuredSelection) selection;
                for (Object obj : sel.toList()) if (obj instanceof FileDiff)
                    diffs.add((FileDiff) obj);
            }
            formatDiffs(diffs);
        }
    });
    layoutSashForm(graphDetailSplit, UIPreferences.RESOURCEHISTORY_GRAPH_SPLIT);
    layoutSashForm(revInfoSplit, UIPreferences.RESOURCEHISTORY_REV_SPLIT);
    attachCommitSelectionChanged();
    initActions();
    getSite().setSelectionProvider(new RepositorySelectionProvider(graph.getTableView(), () -> {
        HistoryPageInput myInput = getInputInternal();
        return myInput != null ? myInput.getRepository() : null;
    }));
    getSite().registerContextMenu(POPUP_ID, popupMgr, graph.getTableView());
    // Track which of our controls has the focus, so that we can focus the
    // last focused one in setFocus().
    focusTracker = new FocusTracker();
    trackFocus(graph.getControl());
    trackFocus(diffViewer.getControl());
    trackFocus(commentViewer.getControl());
    trackFocus(fileViewer.getControl());
    layout();
    myRefsChangedHandle = Repository.getGlobalListenerList().addRefsChangedListener(this);
    IToolBarManager manager = getSite().getActionBars().getToolBarManager();
    searchBar = new // $NON-NLS-1$
    SearchBar(// $NON-NLS-1$
    GitHistoryPage.class.getName() + ".searchBar", graph, actions.findAction, getSite().getActionBars());
    // $NON-NLS-1$
    manager.prependToGroup("org.eclipse.team.ui.historyView", searchBar);
    getSite().getActionBars().updateActionBars();
    if (trace)
        GitTraceLocation.getTrace().traceExit(GitTraceLocation.HISTORYVIEW.getLocation());
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ITextListener(org.eclipse.jface.text.ITextListener) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TextAttribute(org.eclipse.jface.text.TextAttribute) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) DefaultDamagerRepairer(org.eclipse.jface.text.rules.DefaultDamagerRepairer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusTracker(org.eclipse.egit.ui.internal.commit.FocusTracker) HyperlinkTokenScanner(org.eclipse.egit.ui.internal.dialogs.HyperlinkTokenScanner) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IShowInTargetList(org.eclipse.ui.part.IShowInTargetList) ArrayList(java.util.ArrayList) List(java.util.List) PresentationReconciler(org.eclipse.jface.text.presentation.PresentationReconciler) IPresentationReconciler(org.eclipse.jface.text.presentation.IPresentationReconciler) TextEvent(org.eclipse.jface.text.TextEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DiffViewer(org.eclipse.egit.ui.internal.commit.DiffViewer) SashForm(org.eclipse.swt.custom.SashForm) HyperlinkSourceViewer(org.eclipse.egit.ui.internal.dialogs.HyperlinkSourceViewer) IToolBarManager(org.eclipse.jface.action.IToolBarManager) GridData(org.eclipse.swt.layout.GridData) RevObject(org.eclipse.jgit.revwalk.RevObject) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ControlEvent(org.eclipse.swt.events.ControlEvent) Link(org.eclipse.swt.widgets.Link)

Example 9 with ITextListener

use of org.eclipse.jface.text.ITextListener in project jbosstools-hibernate by jbosstools.

the class HQLEditor method createPartControl.

/**
 * Creates the SWT controls for the editor.
 *
 * @see org.eclipse.ui.texteditor.AbstractTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
 */
public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    createToolbar(parent);
    super.createPartControl(parent);
    if (getSourceViewer() != null) {
        getSourceViewer().addTextListener(new ITextListener() {

            public void textChanged(TextEvent event) {
                updateExecButton();
            }
        });
    }
    // move to base class?
    Control control = parent.getChildren()[1];
    control.setLayoutData(new GridData(GridData.FILL_BOTH));
    setProjectionSupport(createProjectionSupport());
    /* Now that we have enabled source folding, make sure everything is
	     * expanded.
	     */
    ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
    viewer.doOperation(ProjectionViewer.TOGGLE);
    /* Set a help context ID to enable F1 help. */
    getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(parent, HELP_CONTEXT_ID);
    // the following is needed to make sure the editor area gets focus when editing after query execution
    // TODO: find a better way since this is triggered on every mouse click and key stroke in the editor area
    // one more remark: without this code -> JBIDE-4446
    StyledText textWidget = getSourceViewer().getTextWidget();
    textWidget.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            getSite().getPage().activate(HQLEditor.this);
        }
    });
    textWidget.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent e) {
            getSite().getPage().activate(HQLEditor.this);
        }
    });
    initTextAndToolTip(HibernateConsoleMessages.ExecuteQueryAction_run_hql);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) TextEvent(org.eclipse.jface.text.TextEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ITextListener(org.eclipse.jface.text.ITextListener) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyAdapter(org.eclipse.swt.events.KeyAdapter) GridData(org.eclipse.swt.layout.GridData) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer)

Example 10 with ITextListener

use of org.eclipse.jface.text.ITextListener in project jbosstools-hibernate by jbosstools.

the class CriteriaEditor method createPartControl.

public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    createToolbar(parent);
    super.createPartControl(parent);
    if (getSourceViewer() != null) {
        getSourceViewer().addTextListener(new ITextListener() {

            public void textChanged(TextEvent event) {
                updateExecButton();
            }
        });
    }
    Control control = parent.getChildren()[1];
    control.setLayoutData(new GridData(GridData.FILL_BOTH));
    // the following is needed to make sure the editor area gets focus when editing after query execution
    // TODO: find a better way since this is triggered on every mouse click and key stroke in the editor area
    // one more remark: without this code -> JBIDE-4446
    StyledText textWidget = getSourceViewer().getTextWidget();
    textWidget.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            getSite().getPage().activate(CriteriaEditor.this);
        }
    });
    textWidget.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent e) {
            getSite().getPage().activate(CriteriaEditor.this);
        }
    });
    initTextAndToolTip(HibernateConsoleMessages.ExecuteQueryAction_run_criteria);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) TextEvent(org.eclipse.jface.text.TextEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ITextListener(org.eclipse.jface.text.ITextListener) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyAdapter(org.eclipse.swt.events.KeyAdapter) GridData(org.eclipse.swt.layout.GridData) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Aggregations

ITextListener (org.eclipse.jface.text.ITextListener)10 TextEvent (org.eclipse.jface.text.TextEvent)8 StyledText (org.eclipse.swt.custom.StyledText)5 ArrayList (java.util.ArrayList)3 KeyEvent (org.eclipse.swt.events.KeyEvent)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Iterator (java.util.Iterator)2 DocumentEvent (org.eclipse.jface.text.DocumentEvent)2 SlaveDocumentEvent (org.eclipse.jface.text.SlaveDocumentEvent)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 FocusEvent (org.eclipse.swt.events.FocusEvent)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Control (org.eclipse.swt.widgets.Control)2 List (java.util.List)1