當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。