Java Code Examples for org.eclipse.swt.widgets.ScrollBar#addListener()

The following examples show how to use org.eclipse.swt.widgets.ScrollBar#addListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Gallery.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Add internal scrollbars listeners to this gallery.
 */
private void _addScrollBarsListeners() {
	// Vertical bar
	ScrollBar verticalBar = getVerticalBar();
	if (verticalBar != null) {
		verticalBar.addListener(SWT.Selection, event -> {
			if (vertical)
				scrollVertical();
		});
	}

	// Horizontal bar

	ScrollBar horizontalBar = getHorizontalBar();
	if (horizontalBar != null) {
		horizontalBar.addListener(SWT.Selection, event -> {
			if (!vertical)
				scrollHorizontal();
		});
	}

}
 
Example 2
Source File: BonitaContentProposalAdapter.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
void installListeners() {
    // Listeners on this popup's table and scroll bar
    proposalTable.addListener(SWT.FocusOut, this);
    final ScrollBar scrollbar = proposalTable.getVerticalBar();
    if (scrollbar != null) {
        scrollbar.addListener(SWT.Selection, this);
    }

    // Listeners on this popup's shell
    getShell().addListener(SWT.Deactivate, this);
    getShell().addListener(SWT.Close, this);

    // Listeners on the target control
    control.addListener(SWT.MouseDoubleClick, this);
    control.addListener(SWT.MouseDown, this);
    control.addListener(SWT.Dispose, this);
    control.addListener(SWT.FocusOut, this);
    // Listeners on the target control's shell
    final Shell controlShell = control.getShell();
    controlShell.addListener(SWT.Move, this);
    controlShell.addListener(SWT.Resize, this);

}
 
Example 3
Source File: HorizontalViewportLayer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
	public boolean doCommand(ILayerCommand command) {
		boolean b = super.doCommand(command);
		if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
			ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
			final ScrollBar vBar = clientAreaResizeCommand.getScrollable().getVerticalBar(); // 垂直滚动条
			Listener[] listeners = vBar.getListeners(SWT.Selection);
			for (Listener listener : listeners) { // 清除默认的 Selection 监听(在类 ScrollBarHandlerTemplate 中添加的)
				vBar.removeListener(SWT.Selection, listener);
			}
			vBar.addListener(SWT.Selection, new Listener() {
				
				private ViewportLayer viewportLayer = HorizontalViewportLayer.this;
				private IUniqueIndexLayer scrollableLayer = viewportLayer.getScrollableLayer();
				
				public void handleEvent(Event event) {
					// 滚动滚动条前提交当前处于编辑状态的文本段
					HsMultiActiveCellEditor.commit(true);
					ScrollBar scrollBar = (ScrollBar) event.widget;
					
					int position = scrollableLayer.getRowPositionByY(scrollBar.getSelection());
					
					viewportLayer.invalidateVerticalStructure();
					viewportLayer.setOriginRowPosition(position);
					vBar.setIncrement(viewportLayer.getRowHeightByPosition(0));
					
//					HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
				}
			});
		}

		return b;
	}
 
Example 4
Source File: HorizontalViewportLayer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean doCommand(ILayerCommand command) {
	boolean b = super.doCommand(command);
	if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
		ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
		final ScrollBar vBar = clientAreaResizeCommand.getScrollable().getVerticalBar(); // 垂直滚动条
		Listener[] listeners = vBar.getListeners(SWT.Selection);
		for (Listener listener : listeners) { // 清除默认的 Selection 监听(在类 ScrollBarHandlerTemplate 中添加的)
			vBar.removeListener(SWT.Selection, listener);
		}
		vBar.addListener(SWT.Selection, new Listener() {

			private ViewportLayer viewportLayer = HorizontalViewportLayer.this;
			private IUniqueIndexLayer scrollableLayer = viewportLayer.getScrollableLayer();

			public void handleEvent(Event event) {
				// 滚动滚动条前提交当前处于编辑状态的文本段
				if (TeActiveCellEditor.isValid())
					TeActiveCellEditor.commit();
				ScrollBar scrollBar = (ScrollBar) event.widget;

				int position = scrollableLayer.getRowPositionByY(scrollBar.getSelection());

				viewportLayer.invalidateVerticalStructure();
				viewportLayer.setOriginRowPosition(position);
				vBar.setIncrement(viewportLayer.getRowHeightByPosition(0));

			}
		});
	}

	return b;
}
 
Example 5
Source File: HorizontalViewportLayer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean doCommand(ILayerCommand command) {
	boolean b = super.doCommand(command);
	if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
		ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
		final ScrollBar vBar = clientAreaResizeCommand.getScrollable().getVerticalBar(); // 垂直滚动条
		Listener[] listeners = vBar.getListeners(SWT.Selection);
		for (Listener listener : listeners) { // 清除默认的 Selection 监听(在类 ScrollBarHandlerTemplate 中添加的)
			vBar.removeListener(SWT.Selection, listener);
		}
		vBar.addListener(SWT.Selection, new Listener() {
			
			private ViewportLayer viewportLayer = HorizontalViewportLayer.this;
			private IUniqueIndexLayer scrollableLayer = viewportLayer.getScrollableLayer();
			
			public void handleEvent(Event event) {
				// 滚动滚动条前提交当前处于编辑状态的文本段
				HsMultiActiveCellEditor.commit(true);
				ScrollBar scrollBar = (ScrollBar) event.widget;
				
				int position = scrollableLayer.getRowPositionByY(scrollBar.getSelection());
				
				viewportLayer.invalidateVerticalStructure();
				viewportLayer.setOriginRowPosition(position);
				vBar.setIncrement(viewportLayer.getRowHeightByPosition(0));
				
				HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
			}
		});
	}

	return b;
}
 
Example 6
Source File: ConsoleAutoScrollPageParticipant.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void init(IPageBookViewPage page, IConsole console)
{
	if (console.getType() != IDebugUIConstants.ID_PROCESS_CONSOLE_TYPE || !(page instanceof TextConsolePage))
	{
		return;
	}
	TextConsolePage consolePage = (TextConsolePage) page;
	TextConsoleViewer textViewer = consolePage.getViewer();
	if (!(textViewer instanceof IOConsoleViewer))
	{
		return;
	}
	final IOConsoleViewer viewer = (IOConsoleViewer) textViewer;
	scrollActionEnabled = viewer.isAutoScroll();
	final IToolBarManager toolBarManager = consolePage.getSite().getActionBars().getToolBarManager();
	IAction slAction = null;
	// Look for the ScrollLockAction
	for (IContributionItem item : toolBarManager.getItems())
	{
		if (item instanceof ActionContributionItem)
		{
			IAction action = ((ActionContributionItem) item).getAction();
			if (action instanceof ScrollLockAction)
			{
				slAction = action;
				break;
			}
		}
	}
	textWidget = viewer.getTextWidget();
	listener = new ConsoleListener(viewer, toolBarManager, slAction);

	// Based on Eclipse Snippet191 - Detects scrolling that were initiated by the user.
	textWidget.addListener(SWT.MouseDown, listener);
	textWidget.addListener(SWT.MouseMove, listener);
	textWidget.addListener(SWT.MouseUp, listener);
	textWidget.addListener(SWT.KeyDown, listener);
	textWidget.addListener(SWT.KeyUp, listener);
	ScrollBar vBar = textWidget.getVerticalBar();
	if (vBar != null)
	{
		vBar.addListener(SWT.Selection, listener);
	}
}