/** * Clears the console. * <p> * Since a console may or may not support direct manipulation * of its document's contents, this method should be called to clear a text console's * document. The default implementation sets this console's document content * to the empty string directly. Subclasses should override as required. * </p> */ public void clearConsole() { IDocument document = getDocument(); if (document != null) { document.set(""); //$NON-NLS-1$ } }
/** * Clears the console. * <p> * Since a console may or may not support direct manipulation * of its document's contents, this method should be called to clear a text console's * document. The default implementation sets this console's document content * to the empty string directly. Subclasses should override as required. * </p> */ public void clearConsole() { IDocument document = getDocument(); if (document != null) { document.set(""); //$NON-NLS-1$ } }
/** * Returns all hyperlinks in this console. * * @return all hyperlinks in this console */ public IHyperlink[] getHyperlinks() { try { Position[] positions = getDocument().getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); IHyperlink[] hyperlinks = new IHyperlink[positions.length]; for (int i = 0; i < positions.length; i++) { ConsoleHyperlinkPosition position = (ConsoleHyperlinkPosition) positions[i]; hyperlinks[i] = position.getHyperLink(); } return hyperlinks; } catch (BadPositionCategoryException e) { return new IHyperlink[0]; } }
/** * Returns all hyperlinks in this console. * * @return all hyperlinks in this console */ public IHyperlink[] getHyperlinks() { try { Position[] positions = getDocument().getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); IHyperlink[] hyperlinks = new IHyperlink[positions.length]; for (int i = 0; i < positions.length; i++) { ConsoleHyperlinkPosition position = (ConsoleHyperlinkPosition) positions[i]; hyperlinks[i] = position.getHyperLink(); } return hyperlinks; } catch (BadPositionCategoryException e) { return new IHyperlink[0]; } }
private IDocument getConsoleDocument() throws FileNotFoundException { if (con != null) { if(con instanceof TextConsole) { return ((TextConsole)con).getDocument(); } else {
/** * Returns the hyperlink at the given offset of <code>null</code> if none. * * @param offset offset for which a hyperlink is requested * @return the hyperlink at the given offset of <code>null</code> if none */ public IHyperlink getHyperlink(int offset) { try { IDocument document = getDocument(); if (document != null) { Position[] positions = document.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); Position position = findPosition(offset, positions); if (position instanceof ConsoleHyperlinkPosition) { return ((ConsoleHyperlinkPosition) position).getHyperLink(); } } } catch (BadPositionCategoryException e) { } return null; }
/** * Returns the hyperlink at the given offset of <code>null</code> if none. * * @param offset offset for which a hyperlink is requested * @return the hyperlink at the given offset of <code>null</code> if none */ public IHyperlink getHyperlink(int offset) { try { IDocument document = getDocument(); if (document != null) { Position[] positions = document.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); Position position = findPosition(offset, positions); if (position instanceof ConsoleHyperlinkPosition) { return ((ConsoleHyperlinkPosition) position).getHyperLink(); } } } catch (BadPositionCategoryException e) { } return null; }
protected String getMatchedText(PatternMatchEvent event) { int eventOffset = event.getOffset(); int eventLength = event.getLength(); IDocument document = fConsole.getDocument(); String matchedText = null; try { matchedText = document.get(eventOffset, eventLength); } catch (BadLocationException e) { AntUIPlugin.log(e); } return matchedText; }
/** * Adds a hyperlink to this console. * * @param hyperlink the hyperlink to add * @param offset the offset in the console document at which the hyperlink should be added * @param length the length of the text which should be hyperlinked * @throws BadLocationException if the specified location is not valid. */ public void addHyperlink(IHyperlink hyperlink, int offset, int length) throws BadLocationException { IDocument document = getDocument(); ConsoleHyperlinkPosition hyperlinkPosition = new ConsoleHyperlinkPosition(hyperlink, offset, length); try { document.addPosition(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY, hyperlinkPosition); fConsoleManager.refresh(this); } catch (BadPositionCategoryException e) { ConsolePlugin.log(e); } }
/** * Returns the region associated with the given hyperlink. * * @param link hyperlink * @return the region associated with the hyperlink or null if the hyperlink is not found. */ public IRegion getRegion(IHyperlink link) { try { IDocument doc = getDocument(); if (doc != null) { Position[] positions = doc.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); for (int i = 0; i < positions.length; i++) { ConsoleHyperlinkPosition position = (ConsoleHyperlinkPosition)positions[i]; if (position.getHyperLink().equals(link)) { return new Region(position.getOffset(), position.getLength()); } } } } catch (BadPositionCategoryException e) { } return null; }
/** * Adds a hyperlink to this console. * * @param hyperlink the hyperlink to add * @param offset the offset in the console document at which the hyperlink should be added * @param length the length of the text which should be hyperlinked * @throws BadLocationException if the specified location is not valid. */ public void addHyperlink(IHyperlink hyperlink, int offset, int length) throws BadLocationException { IDocument document = getDocument(); ConsoleHyperlinkPosition hyperlinkPosition = new ConsoleHyperlinkPosition(hyperlink, offset, length); try { document.addPosition(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY, hyperlinkPosition); fConsoleManager.refresh(this); } catch (BadPositionCategoryException e) { ConsolePlugin.log(e); } }
/** * Returns this link's text * * @exception CoreException if unable to retrieve the text */ protected String getLinkText() throws CoreException { try { IDocument document = getConsole().getDocument(); IRegion region = getConsole().getRegion(this); int regionOffset = region.getOffset(); int lineNumber = document.getLineOfOffset(regionOffset); IRegion lineInformation = document.getLineInformation(lineNumber); int lineOffset = lineInformation.getOffset(); String line = document.get(lineOffset, lineInformation.getLength()); int regionOffsetInLine = regionOffset - lineOffset; int linkEnd = line.indexOf(')', regionOffsetInLine); int linkStart = line.lastIndexOf(' ', regionOffsetInLine); return line.substring(linkStart==-1?0:linkStart+1,linkEnd+1); } catch (BadLocationException e) { IStatus status = new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), 0, ConsoleMessages.JavaStackTraceHyperlink_Unable_to_retrieve_hyperlink_text__8, e); throw new CoreException(status); } }
public void matchFound(PatternMatchEvent event) { try { int offset = event.getOffset(); int length = event.getLength(); String url = console.getDocument().get(offset, length); IHyperlink link = new UrlHyperLink(url); console.addHyperlink(link, offset, length); } catch (BadLocationException e) { } }
/** * Returns the region associated with the given hyperlink. * * @param link hyperlink * @return the region associated with the hyperlink or null if the hyperlink is not found. */ public IRegion getRegion(IHyperlink link) { try { IDocument doc = getDocument(); if (doc != null) { Position[] positions = doc.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); for (int i = 0; i < positions.length; i++) { ConsoleHyperlinkPosition position = (ConsoleHyperlinkPosition)positions[i]; if (position.getHyperLink().equals(link)) { return new Region(position.getOffset(), position.getLength()); } } } } catch (BadPositionCategoryException e) { } return null; }
protected int getLineNumber(int eventOffset, boolean sameLine) { IDocument document = fConsole.getDocument(); try { int fileLine = document.getLineOfOffset(eventOffset); if (!sameLine) { fileLine += 1; } IRegion region = document.getLineInformation(fileLine); int regionLength = region.getLength(); if (region.getOffset() != eventOffset) { regionLength = regionLength - (eventOffset - region.getOffset()); } String lineLine = document.get(eventOffset, regionLength); Matcher matcher = null; synchronized (fgLineNumberPattern) { matcher = fgLineNumberPattern.matcher(lineLine); } if (matcher.find()) { String lineString = matcher.group(); return Integer.parseInt(lineString); } } catch (BadLocationException e) { AntUIPlugin.log(e); } catch (NumberFormatException e) { AntUIPlugin.log(e); } return -1; }
/** * Returns this link's text * * @exception CoreException * if unable to retrieve the text */ protected String getLinkText() throws CoreException { try { IDocument document = getConsole().getDocument(); IRegion region = getConsole().getRegion(this); int regionOffset = region.getOffset(); int lineNumber = document.getLineOfOffset(regionOffset); IRegion lineInformation = document.getLineInformation(lineNumber); int lineOffset = lineInformation.getOffset(); String line = document.get(lineOffset, lineInformation.getLength()); int regionOffsetInLine = regionOffset - lineOffset; int linkEnd = line.indexOf(')', regionOffsetInLine); int linkStart = line.lastIndexOf(' ', regionOffsetInLine); return line.substring(linkStart == -1 ? 0 : linkStart + 1, linkEnd + 1); } catch (BadLocationException e) { IStatus status = new Status(IStatus.ERROR, DLTKDebugUIPlugin.getUniqueIdentifier(), 0, ConsoleMessages.RutaFileHyperlink_Unable_to_retrieve_hyperlink_text__8, e); throw new CoreException(status); } }
public void matchFound(PatternMatchEvent event) { try { int offset = event.getOffset(); int length = event.getLength(); TextConsole console = getConsole(); String exceptionName; exceptionName = console.getDocument().get(offset, length - 1); IHyperlink link = new JavaExceptionHyperLink(console, exceptionName); getConsole().addHyperlink(link, offset, length - 1); } catch (BadLocationException e) { } } }
protected String getMessage(MarkerInfo info) { IDocument doc = fConsole.getDocument(); String message = ConsoleMessages.JavacMarkerCreator_0; if (fUseCustomMessage) { FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(doc); try { IRegion match = adapter.find(info.fOffset, "[javac] ----------", true, false, false, false); //$NON-NLS-1$ if (match != null) { match = adapter.find(match.getOffset(), "[javac]", false, false, false, false); //$NON-NLS-1$ if (match != null) { int start = match.getOffset() + match.getLength() + 1; IRegion lineInfo = doc.getLineInformationOfOffset(start); message = doc.get(start, lineInfo.getOffset() - start + lineInfo.getLength()); } } } catch (BadLocationException e) { AntUIPlugin.log(e); } } return message; }
/** * Constructs a new viewer in the given parent for the specified console. * * @param parent * containing widget * @param console * text console */ public TextConsoleViewer(Composite parent, TextConsole console) { super(parent, null, SWT.V_SCROLL | SWT.H_SCROLL); this.console = console; IDocument document = console.getDocument(); setDocument(document); StyledText styledText = getTextWidget(); styledText.setDoubleClickEnabled(true); styledText.addLineStyleListener(this); styledText.addLineBackgroundListener(this); styledText.setEditable(true); setFont(console.getFont()); styledText.addMouseTrackListener(this); styledText.addListener(SWT.MouseUp, mouseUpListener); ColorRegistry colorRegistry = JFaceResources.getColorRegistry(); propertyChangeListener = new HyperlinkColorChangeListener(); colorRegistry.addListener(propertyChangeListener); revealJob.setSystem(true); document.addDocumentListener(documentListener); document.addPositionUpdater(positionUpdater); }
this.console = console; IDocument document = console.getDocument(); setDocument(document);