當前位置: 首頁>>代碼示例>>Java>>正文


Java TextSelection類代碼示例

本文整理匯總了Java中org.eclipse.jface.text.TextSelection的典型用法代碼示例。如果您正苦於以下問題:Java TextSelection類的具體用法?Java TextSelection怎麽用?Java TextSelection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TextSelection類屬於org.eclipse.jface.text包,在下文中一共展示了TextSelection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHoverRegion

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {

	IDocument document = textViewer.getDocument();

	/* Vérifie qu'on est dans une String de KSP */
	boolean isSqlString = DocumentUtils.isContentType(document, offset, KspRegionType.STRING);
	if (!isSqlString) {
		return null;
	}

	/* Extrait le mot courant. */
	ITextSelection selection = new TextSelection(document, offset, 0);
	ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE);
	if (currentWordSelection == null) {
		return null;
	}
	String currentWord = currentWordSelection.getText();
	if (currentWord == null) {
		return null;
	}

	/* Renvoie la région du mot. */
	return new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:26,代碼來源:KspTextHover.java

示例2: insertMultiLiner

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
private void insertMultiLiner(BracketInsertion data, ISelectionProvider selectionProvider, int offset,
		IDocument document) throws BadLocationException {
	IRegion region = document.getLineInformationOfOffset(offset);
	if (region == null) {
		return;
	}
	int length = region.getLength();

	String textBeforeColumn = document.get(offset - length, length-1); //-1 to get not he bracket itself
	String relevantColumnsBefore = TextUtil.trimRightWhitespaces(textBeforeColumn);
	InsertionData result = support.prepareInsertionString(
			data.createMultiLineTemplate(SourceCodeInsertionSupport.CURSOR_VARIABLE), relevantColumnsBefore);

	document.replace(offset - 1, 1, result.getSourceCode());
	selectionProvider.setSelection(new TextSelection(offset + result.getCursorOffset() - 1, 0));

}
 
開發者ID:de-jcup,項目名稱:egradle,代碼行數:18,代碼來源:GroovyBracketInsertionCompleter.java

示例3: run

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
public void run() {
    if (editor == null)
        return;
    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
    IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    TexCompletionProposal prop = new TexCompletionProposal(entry, selection.getOffset() + 1, 0, 
            editor.getViewer());
    try {
        // insert a backslash first
        doc.replace(selection.getOffset(), 0, "\\");
        prop.apply(doc);
        int newOffset = selection.getOffset() + entry.key.length() + 1;
        if (entry.arguments > 0) {
            newOffset += 1;
        }
        editor.getSelectionProvider().setSelection(new TextSelection(newOffset, 0));
    } catch (BadLocationException e) {
        TexlipsePlugin.log("Error while trying to insert command", e);
    }
}
 
開發者ID:eclipse,項目名稱:texlipse,代碼行數:21,代碼來源:TexInsertMathSymbolAction.java

示例4: run

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
public void run() {
    try {
        handler.editor = EditorUtil.getTLAEditorWithFocus();
        handler.doc = editor.getDocumentProvider().getDocument(
                editor.getEditorInput());
        handler.selectionProvider = editor.getSelectionProvider();
        handler.selection = (TextSelection) selectionProvider
                .getSelection();
        handler.offset = selection.getOffset();

        // Get the module.
        String moduleName = editor.getModuleName();
        handler.moduleNode = ResourceHelper.getModuleNode(moduleName);

        handler.realExecute();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:21,代碼來源:DecomposeProofHandler.java

示例5: run

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
public void run() {
 		try {
 			handler.editor = EditorUtil.getTLAEditorWithFocus();
 			handler.doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
 	        handler.selectionProvider = editor.getSelectionProvider();
 	        handler.selection = (TextSelection) selectionProvider.getSelection();
 	        handler.offset = selection.getOffset();

 	        // Get the module.
 	        String moduleName = editor.getModuleName();
 	        handler.moduleNode = ResourceHelper.getModuleNode(moduleName);

	handler.realExecute() ;
} catch (ExecutionException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
 	}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:19,代碼來源:OldDecomposeProofHandler.java

示例6: startBoxedComment

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
private void startBoxedComment()
		throws org.eclipse.jface.text.BadLocationException {
	int indent = offset - lineInfo.getOffset() + 1;

	// set dontAddNewLine to true iff the rest of the line, starting from offset
	// consists entirely of // space characters.
	int restOfLineLength = lineInfo.getOffset() -  offset + lineInfo.getLength();
	String restOfLine = doc.get(offset, restOfLineLength);
	boolean dontAddNewLine = StringHelper.onlySpaces(restOfLine);

	String asterisks = StringHelper.copyString("*", Math.max(3, RightMargin
			- indent - 1));
	String newText = "(" + asterisks + StringHelper.newline
			+ StringHelper.newline + StringHelper.copyString(" ", indent)
			+ asterisks + ")" + (dontAddNewLine ? "" : StringHelper.newline);
	doc.replace(selection.getOffset(), selection.getLength(), newText);
	selectionProvider.setSelection(new TextSelection(offset + 1
			+ asterisks.length() + StringHelper.newline.length(), 0));
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:20,代碼來源:BoxedCommentHandler.java

示例7: commentSelection

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
public void commentSelection(TextSelection selection, IDocument doc){
	if (selection.getLength() > 0) {
		try {
			int offset;
			offset = selection.getOffset();
			doc.replace(offset, 0, commentBegin);
			offset += selection.getLength() + commentBegin.length();
			doc.replace(offset, 0, commentEnd);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
	} else {
		// TODO: Comment the range!
		System.out.println("Comment the range!");
	}
}
 
開發者ID:ncleclipse,項目名稱:ncl30-eclipse,代碼行數:17,代碼來源:CommentSelectionAction.java

示例8: execute

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	markSpec = getMark();
	IEditorPart edPart = HandlerUtil.getActiveEditor(event);
	if (edPart instanceof FluentMkEditor) {
		editor = (FluentMkEditor) edPart;
		doc = editor.getDocument();
		if (doc != null) {
			ISelection sel = HandlerUtil.getCurrentSelection(event);
			if (sel instanceof TextSelection) {
				TextSelection tsel = (TextSelection) sel;
				int beg = tsel.getOffset();
				int len = tsel.getLength();
				cpos = editor.getCursorOffset();
				if (len == 0) beg = cpos;
				try {
					if (samePartition(beg, len)) {
						toggle(beg, len);
					}
				} catch (BadLocationException e) {}
			}
		}
	}
	return null;
}
 
開發者ID:grosenberg,項目名稱:fluentmark,代碼行數:26,代碼來源:AbstractMarksHandler.java

示例9: execute

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart edPart = HandlerUtil.getActiveEditor(event);
	if (edPart instanceof FluentMkEditor) {
		FluentMkEditor editor = (FluentMkEditor) edPart;
		IDocument doc = editor.getDocument();
		if (doc != null) {
			ISelection sel = HandlerUtil.getCurrentSelection(event);
			if (sel instanceof TextSelection) {
				TextSelection tsel = (TextSelection) sel;
				int beg = tsel.getOffset();
				int len = tsel.getLength();

				switch (checkPartition(doc, beg, len)) {
					case NONE:
						addComment(doc, beg, len);
						break;
					case SAME:
						removeComment(doc, beg);
						break;
				}
			}
		}
	}
	return null;
}
 
開發者ID:grosenberg,項目名稱:fluentmark,代碼行數:27,代碼來源:ToggleHiddenCommentHandler.java

示例10: open

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
@Override
public void open() {
	// Open Implementation dialog
	Display.getDefault().asyncExec(() -> {
		try {
			Shell parent = Display.getDefault().getActiveShell();
			TypeScriptImplementationDialog dialog = new TypeScriptImplementationDialog(parent, SWT.RESIZE, tsFile);
			int offset = tsFile.getPosition(getRange().startLineNumber, getRange().startColumn);
			ITextSelection selection = new TextSelection(offset, 1);
			dialog.setSize(450, 500);
			dialog.setInput(selection);
			dialog.open();
		} catch (TypeScriptException e) {
			e.printStackTrace();
		}
	});
}
 
開發者ID:angelozerr,項目名稱:typescript.java,代碼行數:18,代碼來源:ImplementationsCodeLens.java

示例11: getMovingSelection

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
/**
 * Given a selection on a document, computes the lines fully or partially covered by
 * <code>selection</code>. A line in the document is considered covered if
 * <code>selection</code> comprises any characters on it, including the terminating delimiter.
 * <p>Note that the last line in a selection is not considered covered if the selection only
 * comprises the line delimiter at its beginning (that is considered part of the second last
 * line).
 * As a special case, if the selection is empty, a line is considered covered if the caret is
 * at any position in the line, including between the delimiter and the start of the line. The
 * line containing the delimiter is not considered covered in that case.
 * </p>
 *
 * @param document the document <code>selection</code> refers to
 * @param selection a selection on <code>document</code>
 * @param viewer the <code>ISourceViewer</code> displaying <code>document</code>
 * @return a selection describing the range of lines (partially) covered by
 * <code>selection</code>, without any terminating line delimiters
 * @throws BadLocationException if the selection is out of bounds (when the underlying document has changed during the call)
 */
private ITextSelection getMovingSelection(IDocument document, ITextSelection selection, ITextViewer viewer) throws BadLocationException {
	int low= document.getLineOffset(selection.getStartLine());
	int endLine= selection.getEndLine();
	int high= document.getLineOffset(endLine) + document.getLineLength(endLine);

	// get everything up to last line without its delimiter
	String delim= document.getLineDelimiter(endLine);
	if (delim != null)
		high -= delim.length();

	// the new selection will cover the entire lines being moved, except for the last line's
	// delimiter. The exception to this rule is an empty last line, which will stay covered
	// including its delimiter
	if (delim != null && document.getLineLength(endLine) == delim.length())
		fAddDelimiter= true;
	else
		fAddDelimiter= false;

	return new TextSelection(document, low, high - low);
}
 
開發者ID:cplutte,項目名稱:bts,代碼行數:40,代碼來源:TextViewerMoveLinesAction.java

示例12: run

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
@Override
public void run() {
	IXtextDocument document = editor.getDocument();
	ISelection selection = editor.getSelectionProvider().getSelection();
	if (selection instanceof TextSelection) {
		TextSelection textSelection = (TextSelection) selection;
		if (textSelection.getLength()==0) {
			IRegion region = matcher.match(document, textSelection.getOffset());
			if (region != null) {
				if (region.getOffset()+1==textSelection.getOffset()) {
					editor.selectAndReveal(region.getOffset()+region.getLength(),0);
				} else {
					editor.selectAndReveal(region.getOffset()+1,0);
				}
			}
		}
	}
}
 
開發者ID:cplutte,項目名稱:bts,代碼行數:19,代碼來源:GoToMatchingBracketAction.java

示例13: getFirstSelectedElement

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
/**
    * @param selection
    * @return first element of the selection
    */
   public static Object getFirstSelectedElement(ISelection selection) {
if (selection instanceof TreeSelection) {
    TreeSelection treeSelection = (TreeSelection) selection;
    return treeSelection.getFirstElement();
} else if (selection instanceof StructuredSelection) {
    StructuredSelection structuredSelection = (StructuredSelection) selection;
    return structuredSelection.getFirstElement();
} else if (selection instanceof IFileEditorInput) {
    IFileEditorInput editorInput = (FileEditorInput) selection;
    return editorInput.getFile();
} else if (selection instanceof TextSelection) {
    return null;
} else {
    throw new RuntimeException(
	    Messages.GeneratorUtils_SelectionNotSupported);
}
   }
 
開發者ID:junit-tools-team,項目名稱:junit-tools,代碼行數:22,代碼來源:EclipseUIUtils.java

示例14: modifyText

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
@Override
public void modifyText(final ModifyEvent e) {

	boolean wrap = true;
	final String text = find.getText();
	if (lastText.startsWith(text)) {
		wrap = false;
	}
	lastText = text;
	if (EMPTY.equals(text) || "".equals(text)) {
		adjustEnablement(false, null);
		final ISelectionProvider selectionProvider = editor.getSelectionProvider();
		if (selectionProvider != null) {
			final ISelection selection = selectionProvider.getSelection();
			if (selection instanceof TextSelection) {
				final ITextSelection textSelection = (ITextSelection) selection;
				selectionProvider.setSelection(new TextSelection(textSelection.getOffset(), 0));
			}
		}
	} else {
		find(true, true, wrap);
	}
}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:24,代碼來源:EditorSearchControls.java

示例15: search

import org.eclipse.jface.text.TextSelection; //導入依賴的package包/類
public void search() {
	final IWorkbenchPart part = WorkbenchHelper.getActivePart();
	if (part instanceof IEditorPart) {
		final IEditorPart editor = (IEditorPart) part;
		final IWorkbenchPartSite site = editor.getSite();
		if (site != null) {
			final ISelectionProvider provider = site.getSelectionProvider();
			if (provider != null) {
				final ISelection viewSiteSelection = provider.getSelection();
				if (viewSiteSelection instanceof TextSelection) {
					final TextSelection textSelection = (TextSelection) viewSiteSelection;
					text.setText(textSelection.getText());
				}
			}
		}

	}
	activate(null);
	text.setFocus();

}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:22,代碼來源:GamlSearchField.java


注:本文中的org.eclipse.jface.text.TextSelection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。