Search in sources :

Example 41 with TextSelection

use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.

the class AbstractIndentAction method doIndent.

/**
 * Do the actual indentation work.
 */
private void doIndent() {
    if (targetEditor == null) {
        return;
    }
    final IDocument document = getDocument();
    if (null == document) {
        return;
    }
    Interval rootInterval = GlobalIntervalHandler.getInterval(document);
    if (rootInterval == null) {
        rootInterval = (new HeuristicalIntervalDetector()).buildIntervals(document);
        GlobalIntervalHandler.putInterval(document, rootInterval);
    }
    if (rootInterval == null) {
        return;
    }
    int startLine = -1;
    int endLine = -1;
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            final TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                startLine = tSelection.getStartLine();
                endLine = tSelection.getEndLine();
            }
        }
    }
    if (startLine == -1 || endLine == -1) {
        startLine = 0;
        endLine = document.getNumberOfLines() - 1;
    }
    indentArray.clear();
    indentArray.add("");
    final int nofLines = endLine - startLine;
    int offset;
    int realOffset;
    int lineLength;
    Interval interval;
    try {
        final int regionStartOffset = document.getLineOffset(startLine);
        final int regionLength = document.getLineOffset(endLine) + document.getLineLength(endLine) - regionStartOffset;
        multiEdit = new MultiTextEdit(regionStartOffset, regionLength);
        final RewriteSessionEditProcessor processor = new RewriteSessionEditProcessor(document, multiEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
        for (int i = nofLines; i >= 0; i--) {
            lineLength = document.getLineLength(startLine + i);
            offset = document.getLineOffset(startLine + i);
            realOffset = getRealLineStart(document, offset, lineLength);
            interval = rootInterval.getSmallestEnclosingInterval(realOffset);
            final int indentLevel = lineIndentationLevel(document, realOffset, offset + lineLength, interval);
            setIndentLevel(document, document.getLineOffset(startLine + i), indentLevel);
        }
        performEdits(processor);
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    return;
}
Also used : RewriteSessionEditProcessor(org.eclipse.jface.text.RewriteSessionEditProcessor) TextSelection(org.eclipse.jface.text.TextSelection) HeuristicalIntervalDetector(org.eclipse.titan.designer.editors.HeuristicalIntervalDetector) IDocument(org.eclipse.jface.text.IDocument) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) BadLocationException(org.eclipse.jface.text.BadLocationException) Interval(org.eclipse.titan.common.parsers.Interval)

Example 42 with TextSelection

use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.

the class ASN1Editor method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    super.createPartControl(parent);
    projectionViewer = (ProjectionViewer) getSourceViewer();
    projectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
    projectionSupport.install();
    projectionViewer.doOperation(ProjectionViewer.TOGGLE);
    annotationModel = projectionViewer.getProjectionAnnotationModel();
    getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            ASN1Editor.this.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
        }
    });
    getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty() || !(selection instanceof TextSelection) || "".equals(((TextSelection) selection).getText())) {
                return;
            }
            final TextSelection textSelection = (TextSelection) selection;
            final int offset = textSelection.getOffset() + textSelection.getLength();
            occurrencesMarker.markOccurences(getDocument(), offset);
        }
    });
    IFile file = (IFile) getEditorInput().getAdapter(IFile.class);
    if (file != null) {
        EditorTracker.put(file, this);
    }
}
Also used : ProjectionSupport(org.eclipse.jface.text.source.projection.ProjectionSupport) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 43 with TextSelection

use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.

the class ReferenceSearch method runAction.

/**
 * Helper function used by FindReferences classes for TTCN-3, ASN.1 and
 * TTCNPP editors
 */
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
    }
    // find the module
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    if (ResourceExclusionHelper.isExcluded(file)) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
        return;
    }
    final ReferenceFinder rf = new ReferenceFinder();
    boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
    if (!isDetected) {
        return;
    }
    final ReferenceSearchQuery query = new ReferenceSearchQuery(rf, module, file.getProject());
    for (ISearchQuery runningQuery : NewSearchUI.getQueries()) {
        NewSearchUI.cancelQuery(runningQuery);
    }
    NewSearchUI.runQueryInBackground(query);
}
Also used : IFile(org.eclipse.core.resources.IFile) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder) TextSelection(org.eclipse.jface.text.TextSelection) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ISearchQuery(org.eclipse.search.ui.ISearchQuery)

Example 44 with TextSelection

use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.

the class GotoMatchingBracketAction method run.

@Override
public final void run(final IAction action) {
    if (targetEditor == null) {
        return;
    }
    if (targetEditor.getActiveEditor() != targetEditor.getEditor()) {
        return;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return;
            }
        }
    }
    ConfigTextEditor textEditor = targetEditor.getEditor();
    IDocument document = textEditor.getDocument();
    int carretOffset = textEditor.getCarretOffset();
    PairMatcher pairMatcher = new PairMatcher();
    IRegion region = pairMatcher.match(document, carretOffset);
    if (region == null) {
        return;
    }
    int targetOffset;
    if (region.getOffset() + 1 == carretOffset) {
        targetOffset = region.getOffset() + region.getLength();
    } else {
        targetOffset = region.getOffset() + 1;
    }
    textEditor.setCarretOffset(targetOffset);
    textEditor.selectAndReveal(targetOffset, 0);
}
Also used : PairMatcher(org.eclipse.titan.designer.editors.configeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 45 with TextSelection

use of org.eclipse.jface.text.TextSelection in project titan.EclipsePlug-ins by eclipse.

the class GotoMatchingBracketAction method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof ConfigEditor) {
        this.targetEditor = (ConfigEditor) activeEditor;
    } else {
        this.targetEditor = null;
    }
    if (activeEditor == null) {
        return null;
    }
    if (this.targetEditor.getActiveEditor() != this.targetEditor.getEditor()) {
        return null;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return null;
            }
        }
    }
    ConfigTextEditor textEditor = this.targetEditor.getEditor();
    IDocument document = textEditor.getDocument();
    int carretOffset = textEditor.getCarretOffset();
    PairMatcher pairMatcher = new PairMatcher();
    IRegion region = pairMatcher.match(document, carretOffset);
    if (region == null) {
        return null;
    }
    int targetOffset;
    if (region.getOffset() + 1 == carretOffset) {
        targetOffset = region.getOffset() + region.getLength();
    } else {
        targetOffset = region.getOffset() + 1;
    }
    textEditor.setCarretOffset(targetOffset);
    textEditor.selectAndReveal(targetOffset, 0);
    return null;
}
Also used : PairMatcher(org.eclipse.titan.designer.editors.configeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

TextSelection (org.eclipse.jface.text.TextSelection)109 IFile (org.eclipse.core.resources.IFile)35 ISelection (org.eclipse.jface.viewers.ISelection)26 ITextSelection (org.eclipse.jface.text.ITextSelection)24 Test (org.junit.Test)23 IDocument (org.eclipse.jface.text.IDocument)21 IEditorPart (org.eclipse.ui.IEditorPart)19 InputStream (java.io.InputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Path (org.eclipse.core.runtime.Path)13 BadLocationException (org.eclipse.jface.text.BadLocationException)11 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)11 IRegion (org.eclipse.jface.text.IRegion)10 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)8 Module (org.eclipse.titan.designer.AST.Module)8 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)8 XExpression (org.eclipse.xtext.xbase.XExpression)8 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)7 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)7 IResource (org.eclipse.core.resources.IResource)6