### Eclipse Workspace Patch 1.0 #P org.eclipse.jface.text Index: src/org/eclipse/jface/text/TextViewer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java,v retrieving revision 1.222 diff -u -r1.222 TextViewer.java --- src/org/eclipse/jface/text/TextViewer.java 16 Dec 2009 14:40:02 -0000 1.222 +++ src/org/eclipse/jface/text/TextViewer.java 3 Feb 2010 11:14:09 -0000 @@ -22,6 +22,7 @@ import java.util.regex.PatternSyntaxException; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.Field3270; import org.eclipse.swt.custom.LineBackgroundEvent; import org.eclipse.swt.custom.LineBackgroundListener; import org.eclipse.swt.custom.MovementEvent; @@ -135,6 +136,8 @@ */ private static final int TEXT_HOVER_HEIGHT_CHARS= 12; //used to be 10 (text font) + private boolean is3270SupportRequired; //ira + /** * Represents a replace command that brings the text viewer's text widget * back in synchronization with text viewer's document after the document @@ -309,8 +312,8 @@ * @see MouseListener#mouseUp */ public void mouseUp(MouseEvent e) { - if (fTextWidget != null) - fTextWidget.removeSelectionListener(this); + if (getTextWidget() != null) + getTextWidget().removeSelectionListener(this); updateViewportListeners(MOUSE_END); } @@ -318,8 +321,8 @@ * @see MouseListener#mouseDown */ public void mouseDown(MouseEvent e) { - if (fTextWidget != null) - fTextWidget.addSelectionListener(this); + if (getTextWidget() != null) + getTextWidget().addSelectionListener(this); } /* @@ -672,7 +675,7 @@ public void lineGetBackground(LineBackgroundEvent event) { /* Don't use cached line information because of patched redrawing events. */ - if (fTextWidget != null) { + if (getTextWidget() != null) { int offset= widgetOffset2ModelOffset(event.lineOffset); if (fPosition.includes(offset)) event.lineBackground= fHighlightColor; @@ -686,7 +689,7 @@ */ public void install() { TextViewer.this.addTextListener(this); - fTextWidget.addLineBackgroundListener(this); + getTextWidget().addLineBackgroundListener(this); IDocument document= TextViewer.this.getDocument(); try { @@ -716,8 +719,8 @@ document.removePosition(fPosition); } - if (fTextWidget != null && !fTextWidget.isDisposed()) - fTextWidget.removeLineBackgroundListener(this); + if (getTextWidget() != null && !getTextWidget().isDisposed()) + getTextWidget().removeLineBackgroundListener(this); TextViewer.this.removeTextListener(this); @@ -728,8 +731,8 @@ * Clears the highlighting of this range. */ private void clear() { - if (fTextWidget != null && !fTextWidget.isDisposed()) - fTextWidget.redraw(); + if (getTextWidget() != null && !getTextWidget().isDisposed()) + getTextWidget().redraw(); } /** @@ -741,18 +744,18 @@ int offset= widgetRegion.getOffset(); int length= widgetRegion.getLength(); - int count= fTextWidget.getCharCount(); + int count= getTextWidget().getCharCount(); if (offset + length >= count) { length= count - offset; // clip - Point upperLeft= fTextWidget.getLocationAtOffset(offset); - Point lowerRight= fTextWidget.getLocationAtOffset(offset + length); - int width= fTextWidget.getClientArea().width; - int height= fTextWidget.getLineHeight(offset + length) + lowerRight.y - upperLeft.y; - fTextWidget.redraw(upperLeft.x, upperLeft.y, width, height, false); + Point upperLeft= getTextWidget().getLocationAtOffset(offset); + Point lowerRight= getTextWidget().getLocationAtOffset(offset + length); + int width= getTextWidget().getClientArea().width; + int height= getTextWidget().getLineHeight(offset + length) + lowerRight.y - upperLeft.y; + getTextWidget().redraw(upperLeft.x, upperLeft.y, width, height, false); } - fTextWidget.redrawRange(offset, length, true); + getTextWidget().redrawRange(offset, length, true); } /* @@ -1390,9 +1393,9 @@ * Installs this cursor listener. */ private void install() { - if (fTextWidget != null && !fTextWidget.isDisposed()) { - fTextWidget.addKeyListener(this); - fTextWidget.addMouseListener(this); + if (getTextWidget() != null && !getTextWidget().isDisposed()) { + getTextWidget().addKeyListener(this); + getTextWidget().addMouseListener(this); } } @@ -1400,9 +1403,9 @@ * Uninstalls this cursor listener. */ private void uninstall() { - if (fTextWidget != null && !fTextWidget.isDisposed()) { - fTextWidget.removeKeyListener(this); - fTextWidget.removeMouseListener(this); + if (getTextWidget() != null && !getTextWidget().isDisposed()) { + getTextWidget().removeKeyListener(this); + getTextWidget().removeMouseListener(this); } } @@ -1416,7 +1419,7 @@ * @see KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent) */ public void keyReleased(KeyEvent e) { - if (fTextWidget.getSelectionCount() == 0) { + if (getTextWidget().getSelectionCount() == 0) { fLastSentSelectionChange= null; queuePostSelectionChanged(e.character == SWT.DEL); } @@ -1438,7 +1441,7 @@ * @see MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent) */ public void mouseUp(MouseEvent event) { - if (fTextWidget.getSelectionCount() == 0) + if (getTextWidget().getSelectionCount() == 0) queuePostSelectionChanged(false); } } @@ -1522,6 +1525,7 @@ /** The viewer's text widget */ private StyledText fTextWidget; + private Field3270 fField3270Widget; //ira /** The viewer's input document */ private IDocument fDocument; /** The viewer's visible document */ @@ -1752,6 +1756,11 @@ styledText.setLeftMargin(Math.max(styledText.getLeftMargin(), 2)); return styledText; } + protected Field3270 createField3270Widget(Composite parent, int styles) { + Field3270 field3270 = new Field3270(parent, styles); + field3270.getStyledText().setLeftMargin(Math.max(field3270.getStyledText().getLeftMargin(), 2)); + return field3270; + } /** * Factory method to create the document adapter to be used by this viewer. @@ -1770,29 +1779,31 @@ * @param styles the SWT style bits for the viewer's control */ protected void createControl(Composite parent, int styles) { - - fTextWidget= createTextWidget(parent, styles); + if (!is3270SupportRequired) + fTextWidget= createTextWidget(parent, styles); + else + fField3270Widget = createField3270Widget(parent, styles); // Support scroll page upon MOD1+MouseWheel - fTextWidget.addListener(SWT.MouseVerticalWheel, new Listener() { + getTextWidget().addListener(SWT.MouseWheel, new Listener() { public void handleEvent(Event event) { if (((event.stateMask & SWT.MOD1) == 0)) return; - int topIndex= fTextWidget.getTopIndex(); - int bottomIndex= JFaceTextUtil.getBottomIndex(fTextWidget); + int topIndex= getTextWidget().getTopIndex(); + int bottomIndex = JFaceTextUtil.getBottomIndex(getTextWidget()); if (event.count > 0) - fTextWidget.setTopIndex(2 * topIndex - bottomIndex); + getTextWidget().setTopIndex(2 * topIndex - bottomIndex); else - fTextWidget.setTopIndex(bottomIndex); + getTextWidget().setTopIndex(bottomIndex); updateViewportListeners(INTERNAL); } }); - fTextWidget.addDisposeListener( + getTextWidget().addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { handleDispose(); @@ -1800,14 +1811,14 @@ } ); - fTextWidget.setFont(parent.getFont()); - fTextWidget.setDoubleClickEnabled(true); + getTextWidget().setFont(parent.getFont()); + getTextWidget().setDoubleClickEnabled(true); /* * Disable SWT Shift+TAB traversal in this viewer * 1GIYQ9K: ITPUI:WINNT - StyledText swallows Shift+TAB */ - fTextWidget.addTraverseListener(new TraverseListener() { + getTextWidget().addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if ((SWT.SHIFT == e.stateMask) && ('\t' == e.character)) e.doit= false; @@ -1815,12 +1826,12 @@ }); // where does the first line start - fTopInset= -fTextWidget.computeTrim(0, 0, 0, 0).y; + fTopInset= -getTextWidget().computeTrim(0, 0, 0, 0).y; fVerifyListener.forward(true); - fTextWidget.addVerifyListener(fVerifyListener); + getTextWidget().addVerifyListener(fVerifyListener); - fTextWidget.addSelectionListener(new SelectionListener() { + getTextWidget().addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) { selectionChanged(event.x, event.y - event.x); } @@ -1839,7 +1850,9 @@ * @see Viewer#getControl() */ public Control getControl() { - return fTextWidget; + if (!is3270SupportRequired) + return fTextWidget; + return fField3270Widget; } /* @@ -1849,8 +1862,8 @@ if (fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty() && fDoubleClickStrategyConnector == null) { fDoubleClickStrategyConnector= new TextDoubleClickStrategyConnector(); - fTextWidget.addWordMovementListener(fDoubleClickStrategyConnector); - fTextWidget.addMouseListener(fDoubleClickStrategyConnector); + getTextWidget().addWordMovementListener(fDoubleClickStrategyConnector); + getTextWidget().addMouseListener(fDoubleClickStrategyConnector); } ensureHoverControlManagerInstalled(); @@ -1977,7 +1990,8 @@ fDocument= null; fScroller= null; - fTextWidget= null; + fTextWidget = null; + fField3270Widget = null; } @@ -1987,7 +2001,9 @@ * @see org.eclipse.jface.text.ITextViewer#getTextWidget() */ public StyledText getTextWidget() { - return fTextWidget; + if (!is3270SupportRequired) + return fTextWidget; + return fField3270Widget.getStyledText(); } /** @@ -2130,17 +2146,17 @@ * @see ITextViewer#isEditable() */ public boolean isEditable() { - if (fTextWidget == null) + if (getTextWidget() == null) return false; - return fTextWidget.getEditable(); + return getTextWidget().getEditable(); } /* * @see ITextViewer#setEditable(boolean) */ public void setEditable(boolean editable) { - if (fTextWidget != null) - fTextWidget.setEditable(editable); + if (getTextWidget() != null) + getTextWidget().setEditable(editable); } /* @@ -2290,7 +2306,7 @@ * @since 2.0 */ public boolean requestWidgetToken(IWidgetTokenKeeper requester) { - if (fTextWidget != null) { + if (getTextWidget() != null) { if (fWidgetTokenKeeper != null) { if (fWidgetTokenKeeper == requester) return true; @@ -2311,7 +2327,7 @@ * @since 3.0 */ public boolean requestWidgetToken(IWidgetTokenKeeper requester, int priority) { - if (fTextWidget != null) { + if (getTextWidget() != null) { if (fWidgetTokenKeeper != null) { if (fWidgetTokenKeeper == requester) @@ -2358,8 +2374,8 @@ if (!redraws() && fViewerState != null) return fViewerState.getSelection(); - if (fTextWidget != null) { - Point p= fTextWidget.getSelectionRange(); + if (getTextWidget() != null) { + Point p= getTextWidget().getSelectionRange(); p= widgetSelection2ModelSelection(p); if (p != null) return p; @@ -2379,7 +2395,7 @@ return; } - if (fTextWidget == null) + if (getTextWidget() == null) return; IRegion widgetSelection= modelRange2ClosestWidgetRange(new Region(selectionOffset, selectionLength)); @@ -2388,7 +2404,7 @@ int[] selectionRange= new int[] { widgetSelection.getOffset(), widgetSelection.getLength() }; validateSelectionRange(selectionRange); if (selectionRange[0] >= 0) { - fTextWidget.setSelectionRange(selectionRange[0], selectionRange[1]); + getTextWidget().setSelectionRange(selectionRange[0], selectionRange[1]); selectionChanged(selectionRange[0], selectionRange[1]); } } @@ -2497,19 +2513,19 @@ int startOffset= modelRange2ClosestWidgetRange(startRegion).getOffset(); IRegion endRegion= new Region(endLineInfo.getOffset() + s.getEndColumn() - endVirtuals, 0); int endOffset= modelRange2ClosestWidgetRange(endRegion).getOffset(); - Point clientAreaOrigin= new Point(fTextWidget.getHorizontalPixel(), fTextWidget.getTopPixel()); - Point startLocation= Geometry.add(clientAreaOrigin, fTextWidget.getLocationAtOffset(startOffset)); + Point clientAreaOrigin= new Point(getTextWidget().getHorizontalPixel(), getTextWidget().getTopPixel()); + Point startLocation= Geometry.add(clientAreaOrigin, getTextWidget().getLocationAtOffset(startOffset)); int averageCharWidth= getAverageCharWidth(); startLocation.x += startVirtuals * averageCharWidth; - Point endLocation= Geometry.add(clientAreaOrigin, fTextWidget.getLocationAtOffset(endOffset)); + Point endLocation= Geometry.add(clientAreaOrigin, getTextWidget().getLocationAtOffset(endOffset)); endLocation.x += endVirtuals * averageCharWidth; - endLocation.y += fTextWidget.getLineHeight(endOffset); + endLocation.y += getTextWidget().getLineHeight(endOffset); int widgetLength= endOffset - startOffset; int[] widgetSelection= { startOffset, widgetLength}; validateSelectionRange(widgetSelection); if (widgetSelection[0] >= 0) { - fTextWidget.setBlockSelectionBounds(Geometry.createRectangle(startLocation, Geometry.subtract(endLocation, startLocation))); + getTextWidget().setBlockSelectionBounds(Geometry.createRectangle(startLocation, Geometry.subtract(endLocation, startLocation))); selectionChanged(startOffset, widgetLength); } } catch (BadLocationException e) { @@ -2530,14 +2546,14 @@ * @see Viewer#getSelection() */ public ISelection getSelection() { - if (fTextWidget != null && fTextWidget.getBlockSelection()) { - int[] ranges= fTextWidget.getSelectionRanges(); + if (getTextWidget() != null && getTextWidget().getBlockSelection()) { + int[] ranges= getTextWidget().getSelectionRanges(); int startOffset= ranges[0]; int endOffset= ranges[ranges.length - 2] + ranges[ranges.length - 1]; // getBlockSelectionBounds returns pixel coordinates relative to document - Rectangle bounds= fTextWidget.getBlockSelectionBounds(); - int clientAreaX= fTextWidget.getHorizontalPixel(); + Rectangle bounds= getTextWidget().getBlockSelectionBounds(); + int clientAreaX= getTextWidget().getHorizontalPixel(); int startX= bounds.x - clientAreaX; int endX= bounds.x + bounds.width - clientAreaX; int avgCharWidth= getAverageCharWidth(); @@ -2559,7 +2575,7 @@ int endColumn= endOffset - document.getLineOffset(endLine) + endVirtuals; if (startLine == -1 || endLine == -1) return TextSelection.emptySelection(); - return new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, fTextWidget.getTabs()); + return new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, getTextWidget().getTabs()); } catch (BadLocationException e) { return TextSelection.emptySelection(); } @@ -2584,7 +2600,7 @@ * @since 3.5 */ private int computeVirtualChars(int offset, int x, int avgCharWidth) { - int diff= x - fTextWidget.getLocationAtOffset(offset).x; + int diff= x - getTextWidget().getLocationAtOffset(offset).x; return diff > 0 ? diff / avgCharWidth : 0; } @@ -2632,10 +2648,10 @@ * @since 3.0 */ private Display getDisplay() { - if (fTextWidget == null || fTextWidget.isDisposed()) + if (getTextWidget() == null || getTextWidget().isDisposed()) return null; - Display display= fTextWidget.getDisplay(); + Display display= getTextWidget().getDisplay(); if (display != null && display.isDisposed()) return null; @@ -2660,7 +2676,7 @@ if (id == fNumberOfPostSelectionChangedEvents[0]) { // Check again because this is executed after the delay if (getDisplay() != null) { - Point selection= fTextWidget.getSelectionRange(); + Point selection= getTextWidget().getSelectionRange(); if (selection != null) { IRegion r= widgetRange2ModelRange(new Region(selection.x, selection.y)); if (fireEqualSelection || (r != null && !r.equals(fLastSentPostSelectionChange)) || r == null) { @@ -3033,15 +3049,15 @@ if (fViewportGuard != null) return; - if (fTextWidget != null) { + if (getTextWidget() != null) { fViewportGuard= new ViewportGuard(); fLastTopPixel= -1; - fTextWidget.addKeyListener(fViewportGuard); - fTextWidget.addMouseListener(fViewportGuard); + getTextWidget().addKeyListener(fViewportGuard); + getTextWidget().addMouseListener(fViewportGuard); - fScroller= fTextWidget.getVerticalBar(); + fScroller= getTextWidget().getVerticalBar(); if (fScroller != null) fScroller.addSelectionListener(fViewportGuard); } @@ -3052,10 +3068,10 @@ */ private void removeViewPortUpdate() { - if (fTextWidget != null) { + if (getTextWidget() != null) { - fTextWidget.removeKeyListener(fViewportGuard); - fTextWidget.removeMouseListener(fViewportGuard); + getTextWidget().removeKeyListener(fViewportGuard); + getTextWidget().removeMouseListener(fViewportGuard); if (fScroller != null && !fScroller.isDisposed()) { fScroller.removeSelectionListener(fViewportGuard); @@ -3099,7 +3115,7 @@ protected void updateViewportListeners(int origin) { if (redraws()) { - int topPixel= fTextWidget.getTopPixel(); + int topPixel= getTextWidget().getTopPixel(); if (topPixel >= 0 && topPixel != fLastTopPixel) { if (fViewportListeners != null) { for (int i= 0; i < fViewportListeners.size(); i++) { @@ -3119,8 +3135,8 @@ */ public int getTopIndex() { - if (fTextWidget != null) { - int top= fTextWidget.getTopIndex(); + if (getTextWidget() != null) { + int top= getTextWidget().getTopIndex(); return widgetLine2ModelLine(top); } @@ -3132,14 +3148,14 @@ */ public void setTopIndex(int index) { - if (fTextWidget != null) { + if (getTextWidget() != null) { int widgetLine= modelLine2WidgetLine(index); if (widgetLine == -1) widgetLine= getClosestWidgetLineForModelLine(index); if (widgetLine > -1) { - fTextWidget.setTopIndex(widgetLine); + getTextWidget().setTopIndex(widgetLine); updateViewportListeners(INTERNAL); } } @@ -3156,10 +3172,10 @@ * @deprecated as of 3.2 */ protected int getVisibleLinesInViewport() { - if (fTextWidget != null) { - Rectangle clArea= fTextWidget.getClientArea(); + if (getTextWidget() != null) { + Rectangle clArea= getTextWidget().getClientArea(); if (!clArea.isEmpty()) - return clArea.height / fTextWidget.getLineHeight(); + return clArea.height / getTextWidget().getLineHeight(); } return -1; } @@ -3169,10 +3185,10 @@ */ public int getBottomIndex() { - if (fTextWidget == null) + if (getTextWidget() == null) return -1; - int widgetBottom= JFaceTextUtil.getBottomIndex(fTextWidget); + int widgetBottom= JFaceTextUtil.getBottomIndex(getTextWidget()); return widgetLine2ModelLine(widgetBottom); } @@ -3181,8 +3197,8 @@ */ public int getTopIndexStartOffset() { - if (fTextWidget != null) { - int top= fTextWidget.getTopIndex(); + if (getTextWidget() != null) { + int top= getTextWidget().getTopIndex(); try { top= getVisibleDocument().getLineOffset(top); return widgetOffset2ModelOffset(top); @@ -3223,7 +3239,7 @@ */ public void revealRange(int start, int length) { - if (fTextWidget == null || !redraws()) + if (getTextWidget() == null || !redraws()) return; IRegion modelRange= new Region(start, length); @@ -3258,11 +3274,11 @@ int startLine= doc.getLineOfOffset(start); int endLine= doc.getLineOfOffset(end); - int top= fTextWidget.getTopIndex(); + int top= getTextWidget().getTopIndex(); if (top > -1) { // scroll vertically - int bottom= JFaceTextUtil.getBottomIndex(fTextWidget); + int bottom= JFaceTextUtil.getBottomIndex(getTextWidget()); int lines= bottom - top; // if the widget is not scrollable as it is displaying the entire content @@ -3275,7 +3291,7 @@ } else { int delta= Math.max(0, lines - (endLine - startLine)); - fTextWidget.setTopIndex(startLine - delta/3); + getTextWidget().setTopIndex(startLine - delta/3); updateViewportListeners(INTERNAL); } @@ -3293,17 +3309,17 @@ if (endLine > startLine) { // reveal the beginning of the range in the start line IRegion extent= getExtent(start, start); - startPixel= extent.getOffset() + fTextWidget.getHorizontalPixel(); + startPixel= extent.getOffset() + getTextWidget().getHorizontalPixel(); endPixel= startPixel; } else { IRegion extent= getExtent(start, end); - startPixel= extent.getOffset() + fTextWidget.getHorizontalPixel(); + startPixel= extent.getOffset() + getTextWidget().getHorizontalPixel(); endPixel= startPixel + extent.getLength(); } - int visibleStart= fTextWidget.getHorizontalPixel(); - int visibleEnd= visibleStart + fTextWidget.getClientArea().width; + int visibleStart= getTextWidget().getHorizontalPixel(); + int visibleEnd= visibleStart + getTextWidget().getClientArea().width; // scroll only if not yet visible if (startPixel < visibleStart || visibleEnd < endPixel) { @@ -3325,7 +3341,7 @@ float index= ((float)newOffset) / ((float)getAverageCharWidth()); - fTextWidget.setHorizontalIndex(Math.round(index)); + getTextWidget().setHorizontalIndex(Math.round(index)); } } @@ -3342,8 +3358,8 @@ * @deprecated use getWidthInPixels(int, int) instead */ final protected int getWidthInPixels(String text) { - GC gc= new GC(fTextWidget); - gc.setFont(fTextWidget.getFont()); + GC gc= new GC(getTextWidget()); + gc.setFont(getTextWidget().getFont()); Point extent= gc.textExtent(text); gc.dispose(); return extent.x; @@ -3362,11 +3378,11 @@ */ final protected IRegion getExtent(int start, int end) { if (end > 0 && start < end) { - Rectangle bounds= fTextWidget.getTextBounds(start, end - 1); + Rectangle bounds= getTextWidget().getTextBounds(start, end - 1); return new Region(bounds.x, bounds.width); } - return new Region(fTextWidget.getLocationAtOffset(start).x, 0); + return new Region(getTextWidget().getLocationAtOffset(start).x, 0); } /** @@ -3470,14 +3486,14 @@ */ private void initializeWidgetContents() { - if (fTextWidget != null && fVisibleDocument != null) { + if (getTextWidget() != null && fVisibleDocument != null) { // set widget content if (fDocumentAdapter == null) fDocumentAdapter= createDocumentAdapter(); fDocumentAdapter.setDocument(fVisibleDocument); - fTextWidget.setContent(fDocumentAdapter); + getTextWidget().setContent(fDocumentAdapter); // invalidate presentation invalidateTextPresentation(); @@ -3761,9 +3777,9 @@ return; } - if (fTextWidget.getBlockSelection() && (e.text == null || e.text.length() < 2)) { - Point sel = fTextWidget.getSelection(); - if (fTextWidget.getLineAtOffset(sel.x) != fTextWidget.getLineAtOffset(sel.y)) { + if (getTextWidget().getBlockSelection() && (e.text == null || e.text.length() < 2)) { + Point sel = getTextWidget().getSelection(); + if (getTextWidget().getLineAtOffset(sel.x) != getTextWidget().getLineAtOffset(sel.y)) { verifyEventInBlockSelection(e); return; } @@ -3784,7 +3800,7 @@ fDocumentCommand.execute(getDocument()); - if (fTextWidget != null) { + if (getTextWidget() != null) { int documentCaret= fDocumentCommand.caretOffset; if (documentCaret == -1) { // old behavior of document command @@ -3805,10 +3821,10 @@ if (widgetCaret != -1) { // there is a valid widget caret - fTextWidget.setCaretOffset(widgetCaret); + getTextWidget().setCaretOffset(widgetCaret); } - fTextWidget.showSelection(); + getTextWidget().showSelection(); } } catch (BadLocationException x) { @@ -3889,7 +3905,7 @@ */ private boolean isMarkedRegionEmpty() { return - fTextWidget == null || + getTextWidget() == null || fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null; @@ -3900,14 +3916,14 @@ */ public boolean canDoOperation(int operation) { - if (fTextWidget == null || !redraws()) + if (getTextWidget() == null || !redraws()) return false; switch (operation) { case CUT: - return isEditable() &&(fTextWidget.getSelectionCount() > 0 || !isMarkedRegionEmpty()); + return isEditable() &&(getTextWidget().getSelectionCount() > 0 || !isMarkedRegionEmpty()); case COPY: - return fTextWidget.getSelectionCount() > 0 || !isMarkedRegionEmpty(); + return getTextWidget().getSelectionCount() > 0 || !isMarkedRegionEmpty(); case DELETE: case PASTE: return isEditable(); @@ -3935,7 +3951,7 @@ */ public void doOperation(int operation) { - if (fTextWidget == null || !redraws()) + if (getTextWidget() == null || !redraws()) return; Point selection= null; @@ -3957,24 +3973,24 @@ } break; case CUT: - if (fTextWidget.getSelectionCount() == 0) + if (getTextWidget().getSelectionCount() == 0) copyMarkedRegion(true); else wrapCompoundChange(new Runnable() { public void run() { - fTextWidget.cut(); + getTextWidget().cut(); } }); - selection= fTextWidget.getSelectionRange(); + selection= getTextWidget().getSelectionRange(); fireSelectionChanged(selection.x, selection.y); break; case COPY: - if (fTextWidget.getSelectionCount() == 0) + if (getTextWidget().getSelectionCount() == 0) copyMarkedRegion(false); else - fTextWidget.copy(); + getTextWidget().copy(); break; case PASTE: paste(); @@ -3985,9 +4001,9 @@ case SELECT_ALL: { IDocument doc= getDocument(); if (doc != null) { - if (fTextWidget.getBlockSelection()) + if (getTextWidget().getBlockSelection()) // XXX: performance hack: use 1000 for the endColumn - StyledText will not select more than what's possible in the viewport. - setSelection(new BlockTextSelection(doc, 0, 0, doc.getNumberOfLines() - 1, 1000, fTextWidget.getTabs())); + setSelection(new BlockTextSelection(doc, 0, 0, doc.getNumberOfLines() - 1, 1000, getTextWidget().getTabs())); else setSelectedRange(0, doc.getLength()); } @@ -4012,8 +4028,8 @@ } private void delete() { - if (!fTextWidget.getBlockSelection()) { - fTextWidget.invokeAction(ST.DELETE_NEXT); + if (!getTextWidget().getBlockSelection()) { + getTextWidget().invokeAction(ST.DELETE_NEXT); } else { wrapCompoundChange(new Runnable(){ public void run() { @@ -4026,14 +4042,14 @@ } }); } - Point selection= fTextWidget.getSelectionRange(); + Point selection= getTextWidget().getSelectionRange(); fireSelectionChanged(selection.x, selection.y); } private void paste() { // ignoreAutoEditStrategies(true); - if (!fTextWidget.getBlockSelection()) { - fTextWidget.paste(); + if (!getTextWidget().getBlockSelection()) { + getTextWidget().paste(); } else { wrapCompoundChange(new Runnable(){ public void run() { @@ -4082,7 +4098,7 @@ } }); } - Point selection= fTextWidget.getSelectionRange(); + Point selection= getTextWidget().getSelectionRange(); fireSelectionChanged(selection.x, selection.y); // ignoreAutoEditStrategies(false); } @@ -4097,7 +4113,7 @@ * @since 3.5 */ private void wrapCompoundChange(Runnable runnable) { - if (!fTextWidget.getBlockSelection()) { + if (!getTextWidget().getBlockSelection()) { runnable.run(); return; } @@ -4162,28 +4178,28 @@ */ protected void copyMarkedRegion(boolean delete) { - if (fTextWidget == null) + if (getTextWidget() == null) return; if (fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null) return; int widgetMarkOffset= modelOffset2WidgetOffset(fMarkPosition.offset); - Point selection= fTextWidget.getSelection(); + Point selection= getTextWidget().getSelection(); if (selection.x <= widgetMarkOffset) - fTextWidget.setSelection(selection.x, widgetMarkOffset); + getTextWidget().setSelection(selection.x, widgetMarkOffset); else - fTextWidget.setSelection(widgetMarkOffset, selection.x); + getTextWidget().setSelection(widgetMarkOffset, selection.x); if (delete) { wrapCompoundChange(new Runnable() { public void run() { - fTextWidget.cut(); + getTextWidget().cut(); } }); } else { - fTextWidget.copy(); - fTextWidget.setSelection(selection.x); // restore old cursor position + getTextWidget().copy(); + getTextWidget().setSelection(selection.x); // restore old cursor position } } @@ -4195,7 +4211,7 @@ * @deprecated use StyledText.invokeAction instead */ protected void deleteText() { - fTextWidget.invokeAction(ST.DELETE_NEXT); + getTextWidget().invokeAction(ST.DELETE_NEXT); } /** @@ -4502,7 +4518,7 @@ * @since 3.4 */ public void print(StyledTextPrintOptions options) { - final Shell shell= fTextWidget.getShell(); + final Shell shell= getTextWidget().getShell(); if (Printer.getPrinterList().length == 0) { String title= JFaceTextMessages.getString("TextViewer.warning.noPrinter.title"); //$NON-NLS-1$ @@ -4517,7 +4533,7 @@ if (data != null) { final Printer printer= new Printer(data); - final Runnable styledTextPrinter= fTextWidget.print(printer, options); + final Runnable styledTextPrinter= getTextWidget().print(printer, options); Thread printingThread= new Thread("Printing") { //$NON-NLS-1$ public void run() { @@ -4561,7 +4577,7 @@ */ protected boolean canPerformFind() { IDocument d= getVisibleDocument(); - return (fTextWidget != null && d != null && d.getLength() > 0); + return (getTextWidget() != null && d != null && d.getLength() > 0); } /** @@ -4599,7 +4615,7 @@ * */ protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) { - if (fTextWidget == null) + if (getTextWidget() == null) return -1; try { @@ -4620,7 +4636,7 @@ setRedraw(false); if (redraws()) { - fTextWidget.setSelectionRange(widgetPos, length); + getTextWidget().setSelectionRange(widgetPos, length); internalRevealRange(widgetPos, widgetPos + length); selectionChanged(widgetPos, length); } else { @@ -4655,7 +4671,7 @@ * @since 3.0 */ protected int findAndSelectInRange(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, int rangeOffset, int rangeLength, boolean regExSearch) { - if (fTextWidget == null) + if (getTextWidget() == null) return -1; try { @@ -4697,7 +4713,7 @@ setRedraw(false); if (redraws()) { - fTextWidget.setSelectionRange(widgetPos, length); + getTextWidget().setSelectionRange(widgetPos, length); internalRevealRange(widgetPos, widgetPos + length); selectionChanged(widgetPos, length); } else { @@ -4732,7 +4748,7 @@ * @see ITextViewer#setTextColor(Color, start, length, boolean) */ public void setTextColor(Color color, int start, int length, boolean controlRedraw) { - if (fTextWidget != null) { + if (getTextWidget() != null) { StyleRange s= new StyleRange(); s.foreground= color; @@ -4742,12 +4758,12 @@ s= modelStyleRange2WidgetStyleRange(s); if (s != null) { if (controlRedraw) - fTextWidget.setRedraw(false); + getTextWidget().setRedraw(false); try { - fTextWidget.setStyleRange(s); + getTextWidget().setStyleRange(s); } finally { if (controlRedraw) - fTextWidget.setRedraw(true); + getTextWidget().setRedraw(true); } } } @@ -4765,7 +4781,7 @@ range= modelStyleRange2WidgetStyleRange(range); if (range != null) - fTextWidget.setStyleRange(range); + getTextWidget().setStyleRange(range); ArrayList ranges= new ArrayList(presentation.getDenumerableRanges()); Iterator e= presentation.getNonDefaultStyleRangeIterator(); @@ -4777,7 +4793,7 @@ } if (!ranges.isEmpty()) - fTextWidget.replaceStyleRanges(0, 0, (StyleRange[])ranges.toArray(new StyleRange[ranges.size()])); + getTextWidget().replaceStyleRanges(0, 0, (StyleRange[])ranges.toArray(new StyleRange[ranges.size()])); } else { IRegion region= modelRange2WidgetRange(presentation.getCoverage()); @@ -4796,7 +4812,7 @@ if (!list.isEmpty()) { StyleRange[] ranges= new StyleRange[list.size()]; list.toArray(ranges); - fTextWidget.replaceStyleRanges(region.getOffset(), region.getLength(), ranges); + getTextWidget().replaceStyleRanges(region.getOffset(), region.getLength(), ranges); } } } @@ -4821,7 +4837,7 @@ if (!list.isEmpty()) { StyleRange[] ranges= new StyleRange[list.size()]; list.toArray(ranges); - fTextWidget.setStyleRanges(ranges); + getTextWidget().setStyleRanges(ranges); } } @@ -4850,7 +4866,7 @@ if (presentation == null || !redraws()) return; - if (fTextWidget == null) + if (getTextWidget() == null) return; @@ -4870,7 +4886,7 @@ return; if (controlRedraw) - fTextWidget.setRedraw(false); + getTextWidget().setRedraw(false); if (fReplaceTextPresentation) applyTextPresentation(presentation); @@ -4878,7 +4894,7 @@ addPresentation(presentation); if (controlRedraw) - fTextWidget.setRedraw(true); + getTextWidget().setRedraw(true); } /* @@ -5079,8 +5095,8 @@ fViewerState= null; } - if (fTextWidget != null && !fTextWidget.isDisposed()) - fTextWidget.setRedraw(true); + if (getTextWidget() != null && !getTextWidget().isDisposed()) + getTextWidget().setRedraw(true); fireRedrawChanged(); } @@ -5098,8 +5114,8 @@ extension.stopForwardingDocumentChanges(); } - if (fTextWidget != null && !fTextWidget.isDisposed()) - fTextWidget.setRedraw(false); + if (getTextWidget() != null && !getTextWidget().isDisposed()) + getTextWidget().setRedraw(false); fireRedrawChanged(); } @@ -5724,5 +5740,10 @@ public void setTabsToSpacesConverter(IAutoEditStrategy converter) { fTabsToSpacesConverter= converter; } + + public void setIs3270SupportRequired(boolean b){ + this.is3270SupportRequired = b; + } + }