diff options
Diffstat (limited to 'target_explorer/plugins')
3 files changed, 147 insertions, 1 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/tabs/PathMapTab.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/tabs/PathMapTab.java index 89bb4b446..7758da2bd 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/tabs/PathMapTab.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/tabs/PathMapTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2014 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2012, 2015 Wind River Systems, Inc. and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -35,6 +35,7 @@ import org.eclipse.tcf.te.tcf.launch.ui.activator.UIPlugin; import org.eclipse.tcf.te.tcf.launch.ui.editor.AbstractTcfLaunchTabContainerEditorPage; import org.eclipse.tcf.te.tcf.launch.ui.nls.Messages; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; +import org.eclipse.tcf.te.ui.jface.tooltips.ClippedCellToolTip; import org.eclipse.tcf.te.ui.swt.SWTControlUtil; /** @@ -188,6 +189,8 @@ public class PathMapTab extends TCFPathMapTab { Assert.isNotNull(viewer); super.configureTableViewer(viewer); + ClippedCellToolTip.enableFor(viewer); + // Add a filter filtering out the generated mappings if "Show all" is not checked viewer.addFilter(new ViewerFilter() { @Override diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/META-INF/MANIFEST.MF index c8c809481..fd72b66c8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/META-INF/MANIFEST.MF @@ -13,6 +13,7 @@ Bundle-Localization: plugin Export-Package: org.eclipse.tcf.te.ui.jface.dialogs, org.eclipse.tcf.te.ui.jface.images, org.eclipse.tcf.te.ui.jface.interfaces, + org.eclipse.tcf.te.ui.jface.tooltips, org.eclipse.tcf.te.ui.swt, org.eclipse.tcf.te.ui.swt.activator;x-internal:=true, org.eclipse.tcf.te.ui.swt.listener, diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/jface/tooltips/ClippedCellToolTip.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/jface/tooltips/ClippedCellToolTip.java new file mode 100644 index 000000000..e7a4b861e --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.swt/src/org/eclipse/tcf/te/ui/jface/tooltips/ClippedCellToolTip.java @@ -0,0 +1,142 @@ +/** + * ClippedCellToolTip.java + * Created on Jul 3, 2015 + * + * Copyright (c) 2015 Wind River Systems, Inc. + * + * The right to copy, distribute, modify, or otherwise make use + * of this software may be licensed only pursuant to the terms + * of an applicable Wind River license agreement. + */ +package org.eclipse.tcf.te.ui.jface.tooltips; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.jface.window.DefaultToolTip; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.ScrollBar; + +/** + * A tooltip which shows the full content of clipped viewer cell text. + */ +public class ClippedCellToolTip extends DefaultToolTip { + + @SuppressWarnings("unused") + public static void enableFor(ColumnViewer viewer) { + if (Platform.OS_WIN32.equals(Platform.getOS())) + return; + new ClippedCellToolTip(viewer, NO_RECREATE); + } + + private final ColumnViewer fViewer; + + /** + * Constructor. + * @param viewer + * @param style + */ + protected ClippedCellToolTip(ColumnViewer viewer, int style) { + super(viewer.getControl(), style, false); + fViewer = viewer; + } + + @Override + protected Object getToolTipArea(Event event) { + return fViewer.getCell(new Point(event.x, event.y)); + } + + @Override + protected boolean shouldCreateToolTip(Event event) { + if (!super.shouldCreateToolTip(event)) + return false; + + ColumnViewer viewer = fViewer; + + Point point = new Point(event.x, event.y); + ViewerCell cell = viewer.getCell(point); + if (cell == null) + return false; + + String text = cell.getText(); + Rectangle cellBounds = cell.getBounds(); + Rectangle textBounds = cell.getTextBounds(); + int maxWidth = textBounds != null ? textBounds.width : cellBounds.width; + + GC gc = new GC(viewer.getControl()); + gc.setFont(cell.getFont()); + int width = gc.textExtent(text).x; + gc.dispose(); + + if (width <= maxWidth) { + // test against viewer bounds + int cellMargin = cellBounds.x + width + 4; + Rectangle viewerBounds = viewer.getControl().getBounds(); + int viewerMargin = viewerBounds.x + viewerBounds.width - 4; + ScrollBar vsb = null; + if (viewer instanceof TableViewer) + vsb = ((TableViewer) viewer).getTable().getVerticalBar(); + else if (viewer instanceof TreeViewer) + vsb = ((TreeViewer) viewer).getTree().getVerticalBar(); + if (vsb != null && vsb.isVisible()) + viewerMargin -= vsb.getSize().x; + if (cellMargin <= viewerMargin) + return false; + } + setText(wrapText(text)); + return true; + } + + @Override + protected void afterHideToolTip(Event event) { + super.afterHideToolTip(event); + if (event != null && event.widget != fViewer.getControl()) { + fViewer.getControl().setFocus(); + } + } + + private String wrapText(String tooltipText) { + StringBuilder buf = new StringBuilder(); + final int maxCol = 80; + int col = 0; + int wordIdx = 0; + int breakIdx = 0; + int i; + for (i = 0; i<tooltipText.length(); ++i) { + char c = tooltipText.charAt(i); + if (col >= maxCol && c != '\n') { + if (breakIdx == wordIdx) { + if (wordIdx > 0) buf.append('\n'); + buf.append(tooltipText.substring(wordIdx, i)); + col = i - wordIdx; + wordIdx = i; + } else { + buf.append(tooltipText.substring(wordIdx, i)); + wordIdx = breakIdx = i; + } + } + switch (c) { + case ' ': + buf.append(tooltipText.substring(wordIdx, i)); + buf.append(c); + ++col; + wordIdx = breakIdx = i+1; + continue; + case '\n': + buf.append(tooltipText.substring(wordIdx, i)); + buf.append(c); + col = 0; + wordIdx = breakIdx = i+1; + continue; + } + ++col; + } + buf.append(tooltipText.substring(wordIdx, i)); + return buf.toString(); + } +} |