当前位置: 首页>>代码示例>>Java>>正文


Java ITextSelection类代码示例

本文整理汇总了Java中org.eclipse.jface.text.ITextSelection的典型用法代码示例。如果您正苦于以下问题:Java ITextSelection类的具体用法?Java ITextSelection怎么用?Java ITextSelection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ITextSelection类属于org.eclipse.jface.text包,在下文中一共展示了ITextSelection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLaunchConfigFromEditor

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
protected LaunchConfig getLaunchConfigFromEditor(ExecutionEvent event) {
    XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event);
    if (activeXtextEditor == null) {
        return null;
    }
    final ITextSelection selection = (ITextSelection) activeXtextEditor.getSelectionProvider().getSelection();
    return activeXtextEditor.getDocument().priorityReadOnly(new IUnitOfWork<LaunchConfig, XtextResource>() {

        @Override
        public LaunchConfig exec(XtextResource xTextResource) throws Exception {
            EObject lc = eObjectAtOffsetHelper.resolveContainedElementAt(xTextResource, selection.getOffset());
            return findParentLaunchConfig(lc);
        }

    });
}
 
开发者ID:mduft,项目名称:lcdsl,代码行数:17,代码来源:AbstractLaunchConfigGeneratorHandler.java

示例2: getCurrentEditorCurrentWord

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
public static String getCurrentEditorCurrentWord(WordSelectionType wordSelectionType) {
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

	/* Extrait l'éditeur courant. */
	ITextEditor editor = (ITextEditor) activePage.getActiveEditor();
	if (editor == null) {
		return null;
	}

	/* Extrait la sélection courante. */
	ITextSelection selection = (ITextSelection) activePage.getSelection();
	if (selection == null) {
		return null;
	}

	/* Extrait le document courant. */
	IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

	/* Extrait le mot sélectionné. */
	ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, wordSelectionType);
	if (currentWordSelection == null) {
		return null;
	}

	return currentWordSelection.getText();
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:27,代码来源:UiUtils.java

示例3: getHoverRegion

import org.eclipse.jface.text.ITextSelection; //导入依赖的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

示例4: buildProposals

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
/**
 * Constuit les propositions d'aucomplétion.
 * 
 * @param suggestions Suggestionsà proposer.
 * @param currentWordSelection Mot courant à remplacer dans le document.
 * @return Propositions d'autocomplétion.
 */
private ICompletionProposal[] buildProposals(List<CompletionCandidate> suggestions, ITextSelection currentWordSelection) {
	/* Calcul l'offset et la longueur du mot à remplacer dans le document. */
	int replacementLength = currentWordSelection.getLength();
	int replacementOffset = currentWordSelection.getOffset();

	/* Construit les propositions en parcourant les suggestions. */
	List<ICompletionProposal> proposals = new ArrayList<>();
	for (CompletionCandidate suggestion : suggestions) {
		/* String qui remplacera le mot courant. */
		String replacementString = suggestion.getDisplayString();

		/* String affiché comme libellé de la proposition. */
		String displayString = replacementString;

		/* String affiché comme description de la proposition (dans la boîte jaune). */
		String additionalProposalInfo = suggestion.getAdditionalProposalInfo();
		CompletionProposal proposal = new CompletionProposal(replacementString, replacementOffset, replacementLength, replacementString.length(), null,
				displayString, null, additionalProposalInfo);
		proposals.add(proposal);
	}
	return proposals.toArray(new ICompletionProposal[0]);
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:30,代码来源:BaseContentAssistProcessor.java

示例5: getCandidates

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
@Override
protected List<CompletionCandidate> getCandidates(ITextSelection currentWordSelection) {
	List<CompletionCandidate> list = new ArrayList<>();

	/* Trouve la déclaration contenant le nom de paramètre. */
	IFile file = UiUtils.getCurrentEditorFile();
	FileRegion fileRegion = new FileRegion(file, currentWordSelection.getOffset(), currentWordSelection.getLength());
	KspDeclaration declaration = KspManager.getInstance().findDeclarationAt(fileRegion);
	if (declaration == null) {
		return list;
	}

	/* Construit les candidats */
	for (KspAttribute attribute : declaration.getAttributes()) {
		handleAttribute(attribute, list);
	}

	/* Tri par libellé. */
	list.sort((o1, o2) -> o1.getDisplayString().compareTo(o2.getDisplayString()));

	return list;
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:23,代码来源:KspStringContentAssistProcessor.java

示例6: toggleLineBreakpoints

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
	ITextEditor textEditor = getEditor(part);
	if (textEditor != null) {
		IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
		ITextSelection textSelection = (ITextSelection) selection;
		int lineNumber = textSelection.getStartLine();
		IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager()
				.getBreakpoints(DSPPlugin.ID_DSP_DEBUG_MODEL);
		for (int i = 0; i < breakpoints.length; i++) {
			IBreakpoint breakpoint = breakpoints[i];
			if (breakpoint instanceof ILineBreakpoint && resource.equals(breakpoint.getMarker().getResource())) {
				if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
					// remove
					breakpoint.delete();
					return;
				}
			}
		}
		// create line breakpoint (doc line numbers start at 0)
		DSPLineBreakpoint lineBreakpoint = new DSPLineBreakpoint(resource, lineNumber + 1);
		DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
	}
}
 
开发者ID:tracymiranda,项目名称:dsp4e,代码行数:25,代码来源:DSPBreakpointAdapter.java

示例7: findMarkersInSelection

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
/**
 * @param resource
 * @param selection
 * @returns list of markers which are found by selection
 */
public static ArrayList<IMarker> findMarkersInSelection(final IResource resource,
    final ITextSelection selection) {
  final ArrayList<IMarker> markerListInArea = new ArrayList<>();
  final ArrayList<IMarker> markerList = MarkerFactory.findMarkersAsArrayList(resource);

  if (markerList.isEmpty()) {
    return null;
  }
  final int textStart = selection.getOffset();
  final int textEnd = textStart + selection.getLength();

  for (final IMarker iMarker : markerList) {
    final int markerStart = MarkUtilities.getStart(iMarker);
    final int markerEnd = MarkUtilities.getEnd(iMarker);
    if (textStart >= markerStart && textStart <= markerEnd
        || textEnd >= markerStart && textEnd <= markerEnd
        || markerStart >= textStart && markerStart <= textEnd
        || markerEnd >= textStart && markerEnd <= textEnd) {

      markerListInArea.add(iMarker);
    }
  }
  return markerListInArea;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:30,代码来源:MarkerFactory.java

示例8: selectionChanged

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
public void selectionChanged(IAction action, ISelection sel) {
	if (sel instanceof IStructuredSelection) {
		this.selection = (IStructuredSelection) sel;
		if (action != null) {
			setActionEnablement(action);
		}
	}
	if (sel instanceof ITextSelection){
			IEditorPart part = getTargetPage().getActiveEditor();
			if (part != null) {
				IEditorInput input = part.getEditorInput();
				IResource r = (IResource) input.getAdapter(IResource.class);
				if (r != null) {
					switch(r.getType()){
						case IResource.FILE:
							this.selection = new StructuredSelection(r);
							if (action != null) {
								setActionEnablement(action);
							}
						break;
					}
				}	//	set selection to current editor file;
			}
	}
}
 
开发者ID:subclipse,项目名称:subclipse,代码行数:26,代码来源:TeamAction.java

示例9: textSelectionChanged

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
/**
 * A selection event in the Annotate Source Editor
 * @param event
 */
private void textSelectionChanged(ITextSelection selection) {
	
	// Track where the last selection event came from to avoid
	// a selection event loop.
	lastSelectionWasText = true;
		
	// Locate the annotate block containing the selected line number.
	AnnotateBlock match = null;
	for (Iterator iterator = svnAnnotateBlocks.iterator(); iterator.hasNext();) {
		AnnotateBlock block = (AnnotateBlock) iterator.next();
		if (block.contains(selection.getStartLine())) {
			match = block;
			break;
		}
	}

	// Select the annotate block in the List View.
	if (match == null) {
		return;
	}
	
	StructuredSelection listSelection = new StructuredSelection(match); 
	viewer.setSelection(listSelection, true);
}
 
开发者ID:subclipse,项目名称:subclipse,代码行数:29,代码来源:AnnotateView.java

示例10: selectionChanged

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
public void selectionChanged(SelectionChangedEvent event) {
	ISelection selection = event.getSelection();
	if (selection instanceof ITextSelection) {
		ITextSelection textsel = (ITextSelection) selection;
		if (event.getSelectionProvider() instanceof ITextViewer) {
			IDocument doc = ((ITextViewer) event.getSelectionProvider()).getDocument();
			if (doc != null) {
				int offset = textsel.getOffset();
				int length = textsel.getLength();
				if (offset >= 0 && length >= 0) {
					LinkedPosition find = new LinkedPosition(doc, offset, length, LinkedPositionGroup.NO_STOP);
					LinkedPosition pos = fModel.findPosition(find);
					if (pos == null && fExitPosition != null && fExitPosition.includes(find))
						pos = fExitPosition;

					if (pos != null)
						switchPosition(pos, false, false);
				}
			}
		}
	}
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:23,代码来源:TweakedLinkedModeUI.java

示例11: TexSelections

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
/**
 * Takes a text editor as a parameter and sets variables 
 * to correspond selection features.
 * 
 * @param textEditor The currenct text editor
 */
public TexSelections(ITextEditor textEditor) {
     
    // Get the document
    this.document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
    this.editor = textEditor;
    
    // Get the selection
    this.textSelection = (ITextSelection) this.editor.getSelectionProvider().getSelection();
  
    this.startLineIndex = this.textSelection.getStartLine();
    this.endLineIndex = this.textSelection.getEndLine();
    this.selLength = this.textSelection.getLength();

    // Store selection information
    select();
}
 
开发者ID:eclipse,项目名称:texlipse,代码行数:23,代码来源:TexSelections.java

示例12: run

import org.eclipse.jface.text.ITextSelection; //导入依赖的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

示例13: documentChanged

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
public void documentChanged(DocumentEvent event) {
    // if this is enabled
    if ("\"".equals(event.getText())) {
        ITextSelection textSelection = (ITextSelection) this.editor.getSelectionProvider().getSelection();            
        try {
            char prev = document.getChar(textSelection.getOffset() - 1);
            String replacement = "\"";
            // TODO null checks?
            IProject project = ((FileEditorInput)editor.getEditorInput()).getFile().getProject();
            String lang = TexlipseProperties.getProjectProperty(project, TexlipseProperties.LANGUAGE_PROPERTY);
            if (Character.isWhitespace(prev)) {
                replacement = (String) quotes.get(lang + "o");
            } else if (Character.isLetterOrDigit(prev)) {
                replacement = (String) quotes.get(lang + "c");
            } else {
                return;
            }
            document.removeDocumentListener(this);
            document.replace(textSelection.getOffset(), 1, replacement);
            document.addDocumentListener(this);
            //editor.resetHighlightRange();
            //editor.setHighlightRange(textSelection.getOffset() + 1, 1, true);
            //editor.getSelectionProvider().setSelection(new TextSelection(textSelection.getOffset() + 3, 5));
        } catch (BadLocationException e) {}
    }
}
 
开发者ID:eclipse,项目名称:texlipse,代码行数:27,代码来源:TexQuoteListener.java

示例14: addBookmarkProperties

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
private void addBookmarkProperties(Map<String, String> properties, ITextEditor textEditor,
		ITextSelection textSelection) {
	int lineNumber = textSelection.getStartLine();
	addLineNumber(properties, lineNumber);
	addLineContent(properties, textEditor, lineNumber);
	addWorkspacePath(properties, textEditor);
	putIfAbsent(properties, PROPERTY_NAME, () -> {
		String lineContent = properties.get(PROP_LINE_CONTENT);
		if (lineContent != null) {
			return textEditor.getEditorInput().getName() + " : " + lineContent;
		} else {
			return textEditor.getEditorInput().getName();
		}
	});
	IPath filePath = getFilePath(textEditor);
	if (filePath != null) {
		addFilePath(properties, filePath);
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:20,代码来源:TextEditorBookmarkPropertiesProvider.java

示例15: testGotoBookmarkOnDoubleClick

import org.eclipse.jface.text.ITextSelection; //导入依赖的package包/类
@Test
public void testGotoBookmarkOnDoubleClick() throws Exception {
	// Given
	Bookmark bookmark = new Bookmark(new BookmarkId(), ImmutableMap.of(Bookmark.PROPERTY_NAME, "bookmark",
			PROP_WORKSPACE_PATH, "/BookmarksViewTest/src/main/java/org/apache/commons/cli/DefaultParser.java",
			PROP_LINE_CONTENT,
			"for (Enumeration<?> enumeration = properties.propertyNames(); enumeration.hasMoreElements();)"));
	addBookmark(getBookmarksRootFolderId(), bookmark);
	SWTBotTreeItem bookmarkTreeItem = waitUntil("Cannot find new bookmark",
			() -> bookmarksViewDriver.tree().getTreeItem("bookmark"));

	// When
	bookmarkTreeItem.doubleClick();

	// Then
	waitUntil("cannot go to bookmark", () -> "DefaultParser.java".equals(getActivePart().getTitle()));
	IWorkbenchPart workbenchPart = getActivePart();
	ITextSelection selection = (ITextSelection) getSelection(workbenchPart);
	assertEquals("DefaultParser.java", workbenchPart.getTitle());
	assertEquals(146, selection.getStartLine());
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:22,代码来源:BookmarksViewTest.java


注:本文中的org.eclipse.jface.text.ITextSelection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。