use of org.eclipse.swt.events.DisposeEvent in project eclipse.platform.text by eclipse.
the class TextViewer method createControl.
/**
* Creates the viewer's SWT control. The viewer's text widget either is
* the control or is a child of the control.
*
* @param parent the parent of the viewer's control
* @param styles the SWT style bits for the viewer's control
*/
protected void createControl(Composite parent, int styles) {
fTextWidget = createTextWidget(parent, styles);
// Support scroll page upon MOD1+MouseWheel
fTextWidget.addListener(SWT.MouseVerticalWheel, new Listener() {
@Override
public void handleEvent(Event event) {
if (((event.stateMask & SWT.MOD1) == 0))
return;
int topIndex = fTextWidget.getTopIndex();
int bottomIndex = JFaceTextUtil.getBottomIndex(fTextWidget);
if (event.count > 0)
fTextWidget.setTopIndex(2 * topIndex - bottomIndex);
else
fTextWidget.setTopIndex(bottomIndex);
updateViewportListeners(INTERNAL);
}
});
fTextWidget.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
fDisposedControl = getControl();
handleDispose();
}
});
fTextWidget.setFont(parent.getFont());
fTextWidget.setDoubleClickEnabled(true);
/*
* Disable SWT Shift+TAB traversal in this viewer
* 1GIYQ9K: ITPUI:WINNT - StyledText swallows Shift+TAB
*/
fTextWidget.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if ((SWT.SHIFT == e.stateMask) && ('\t' == e.character))
e.doit = !fTextWidget.getEditable();
}
});
// where does the first line start
fTopInset = -fTextWidget.computeTrim(0, 0, 0, 0).y;
fVerifyListener.forward(true);
fTextWidget.addVerifyListener(fVerifyListener);
fTextWidget.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent event) {
selectionChanged(event.x, event.y - event.x);
}
@Override
public void widgetSelected(SelectionEvent event) {
selectionChanged(event.x, event.y - event.x);
}
});
fCursorListener = new CursorListener();
fCursorListener.install();
initializeViewportUpdate();
}
use of org.eclipse.swt.events.DisposeEvent in project eclipse.platform.text by eclipse.
the class RevisionPainter method connectIfNeeded.
/**
* Ensures that the column is fully instantiated, i.e. has a control, and that the viewer is
* visible.
*/
private void connectIfNeeded() {
if (isConnected() || fParentRuler == null)
return;
fViewer = fParentRuler.getTextViewer();
if (fViewer == null)
return;
fWidget = fViewer.getTextWidget();
if (fWidget == null)
return;
fControl = fColumn.getControl();
if (fControl == null)
return;
fControl.addMouseTrackListener(fMouseHandler);
fControl.addMouseMoveListener(fMouseHandler);
fControl.addListener(SWT.MouseUp, fMouseHandler);
fControl.addListener(SWT.MouseDown, fMouseHandler);
fControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
}
});
fRevisionSelectionProvider.install(fViewer);
}
use of org.eclipse.swt.events.DisposeEvent in project eclipse.platform.text by eclipse.
the class DiffPainter method connectIfNeeded.
/**
* Ensures that the column is fully instantiated, i.e. has a control, and that the viewer is
* visible.
*/
private void connectIfNeeded() {
if (isConnected() || fParentRuler == null)
return;
fViewer = fParentRuler.getTextViewer();
if (fViewer == null)
return;
fWidget = fViewer.getTextWidget();
if (fWidget == null)
return;
fControl = fColumn.getControl();
if (fControl == null)
return;
fControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
}
});
}
use of org.eclipse.swt.events.DisposeEvent in project eclipse.platform.text by eclipse.
the class AbstractInformationControlManager method getInformationControl.
/**
* Returns the information control. If the information control has not been created yet,
* it is automatically created.
*
* @return the information control
*/
protected IInformationControl getInformationControl() {
if (fDisposed)
return fInformationControl;
IInformationControlCreator creator = null;
if (fCustomInformationControlCreator == null) {
creator = fInformationControlCreator;
if (fIsCustomInformationControl && fInformationControl != null) {
if (fInformationControl instanceof IInformationControlExtension5)
fSizeConstraints = null;
fInformationControl.dispose();
fInformationControl = null;
}
fIsCustomInformationControl = false;
} else {
creator = fCustomInformationControlCreator;
if (creator instanceof IInformationControlCreatorExtension) {
IInformationControlCreatorExtension extension = (IInformationControlCreatorExtension) creator;
if (fInformationControl != null && extension.canReuse(fInformationControl))
return fInformationControl;
}
if (fInformationControl != null) {
if (fInformationControl instanceof IInformationControlExtension5)
fSizeConstraints = null;
fInformationControl.dispose();
fInformationControl = null;
}
fIsCustomInformationControl = true;
}
if (fInformationControl == null) {
fInformationControl = creator.createInformationControl(fSubjectControl.getShell());
fInformationControl.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleInformationControlDisposed();
}
});
if (fInformationControlCloser != null)
fInformationControlCloser.setInformationControl(fInformationControl);
}
return fInformationControl;
}
use of org.eclipse.swt.events.DisposeEvent in project eclipse.platform.text by eclipse.
the class AnnotationRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
fHitDetectionCursor = parentControl.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
fCanvas = createCanvas(parentControl);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseListener = new MouseListener() {
@Override
public void mouseUp(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseClicked(lineNumber);
}
@Override
public void mouseDown(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
AnnotationRulerColumn.this.mouseDown(lineNumber);
}
@Override
public void mouseDoubleClick(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseDoubleClicked(lineNumber);
}
};
fCanvas.addMouseListener(fMouseListener);
fCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
handleMouseMove(e);
}
});
fCanvas.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
handleMouseScrolled(e);
}
});
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fLineListener);
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
redraw();
}
}
});
}
return fCanvas;
}
Aggregations