use of org.eclipse.jface.window.ToolTip in project mylyn.docs by eclipse.
the class DefaultWikiTextSourceEditorOutline method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
TreeViewer viewer = getTreeViewer();
viewer.setUseHashlookup(true);
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
viewer.setContentProvider(new BaseWorkbenchContentProvider());
viewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
viewer.setInput(getEditor().getAdapter(OutlineItem.class));
viewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
revealInEditor(event.getSelection());
}
});
viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
revealInEditor(event.getSelection());
}
});
viewer.expandAll();
updateSelectionToMatchEditor();
new ToolTip(viewer.getControl(), ToolTip.RECREATE, false) {
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
GridLayout gl = new GridLayout(1, false);
gl.marginBottom = 2;
gl.marginTop = 2;
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.marginLeft = 2;
gl.marginRight = 2;
gl.verticalSpacing = 1;
comp.setLayout(gl);
Object tipItem = getToolTipItem(new Point(event.x, event.y));
if (tipItem instanceof OutlineItem) {
OutlineItem outlineItem = (OutlineItem) tipItem;
Label label = new Label(comp, SWT.WRAP);
label.setBackground(comp.getBackground());
label.setText(outlineItem.getTooltip());
}
return comp;
}
@Override
protected boolean shouldCreateToolTip(Event event) {
final Object eventItem = getToolTipItem(new Point(event.x, event.y));
boolean shouldCreate = eventItem != null && eventItem instanceof OutlineItem && super.shouldCreateToolTip(event);
if (!shouldCreate) {
hide();
}
return shouldCreate;
}
protected Object getToolTipItem(Point point) {
TreeItem item = ((Tree) getTreeViewer().getControl()).getItem(point);
if (item != null) {
return item.getData();
}
return null;
}
};
// $NON-NLS-1$
MenuManager manager = new MenuManager("#PopUp");
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager menuManager) {
contextMenuAboutToShow(menuManager);
}
});
viewer.getTree().setMenu(manager.createContextMenu(viewer.getTree()));
}
use of org.eclipse.jface.window.ToolTip in project epp.mpc by eclipse.
the class AbstractMarketplaceDiscoveryItem method createTagsTooltip.
private void createTagsTooltip(final StyledText tagsLink, final List<? extends ITag> tags) {
final ToolTip tooltip = new ToolTip(tagsLink, ToolTip.NO_RECREATE, false) {
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite result = new Composite(parent, SWT.NONE);
result.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
result.setLayout(new GridLayout());
StyledText fullTagLinks = StyledTextHelper.createStyledTextLabel(result);
fullTagLinks.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
fullTagLinks.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
for (int i = 0; i < MAX_TOTAL_TAGS && i < tags.size(); i++) {
ITag tag = tags.get(i);
String tagName = tag.getName();
StyledTextHelper.appendLink(fullTagLinks, tagName, tagName, SWT.NORMAL);
// $NON-NLS-1$
fullTagLinks.append(" ");
}
if (tags.size() > MAX_TOTAL_TAGS) {
// Limit shown tags to a hard maximum, because too many links
// can crash the StyledText widget (at least on Windows...)
fullTagLinks.append(ELLIPSIS);
}
new LinkListener() {
@Override
protected void selected(Object href, TypedEvent e) {
hide();
if (href != null) {
searchForTag(href.toString());
}
}
}.register(fullTagLinks);
GridData gridData = new GridData();
gridData.widthHint = tagsLink.getSize().x;
fullTagLinks.setLayoutData(gridData);
Dialog.applyDialogFont(result);
return result;
}
@Override
public Point getLocation(Point tipSize, Event event) {
Point size = tagsLink.getSize();
return tagsLink.toDisplay(0, size.y);
}
};
tagsLink.setData(tooltip);
tooltip.setHideOnMouseDown(false);
tooltip.setPopupDelay(0);
tooltip.activate();
}
use of org.eclipse.jface.window.ToolTip in project epp.mpc by eclipse.
the class AbstractMarketplaceDiscoveryItem method createTagsLabel.
protected void createTagsLabel(Composite parent) {
tagsLink = StyledTextHelper.createStyledTextLabel(parent);
setWidgetId(tagsLink, WIDGET_ID_TAGS);
tagsLink.setEditable(false);
GridDataFactory.fillDefaults().indent(DESCRIPTION_MARGIN_LEFT, TAGS_MARGIN_TOP).span(3, 1).align(SWT.BEGINNING, SWT.BEGINNING).grab(true, false).applyTo(tagsLink);
ITags tagsObject = getCatalogItemNode().getTags();
if (tagsObject == null) {
return;
}
List<? extends ITag> tags = tagsObject.getTags();
if (tags.isEmpty()) {
return;
}
tags = new ArrayList<ITag>(tags);
// sort list so that technical tags are at the end
Collections.sort(tags, new Comparator<ITag>() {
public int compare(ITag o1, ITag o2) {
if (o1 == o2) {
return 0;
}
if (o1.getName().startsWith(FILE_EXTENSION_TAG_PREFIX)) {
if (o2.getName().startsWith(FILE_EXTENSION_TAG_PREFIX)) {
return 0;
}
return 1;
}
if (o2.getName().startsWith(FILE_EXTENSION_TAG_PREFIX)) {
return -1;
}
return 0;
}
});
boolean needsEllipsis = tags.size() > MAX_SHOWN_TAGS;
for (int i = 0; i < MAX_SHOWN_TAGS && i < tags.size(); i++) {
if (i > 0) {
// $NON-NLS-1$
tagsLink.append(" ");
}
ITag tag = tags.get(i);
String tagName = tag.getName();
StyledTextHelper.appendLink(tagsLink, tagName, tagName, SWT.NORMAL);
}
if (needsEllipsis) {
// $NON-NLS-1$
tagsLink.append(" ");
StyledTextHelper.appendLink(tagsLink, ELLIPSIS, ELLIPSIS, SWT.NORMAL);
createTagsTooltip(tagsLink, tags);
}
new LinkListener() {
@Override
protected void selected(Object href, TypedEvent e) {
if (href == ELLIPSIS) {
Object data = e.widget.getData();
if (data instanceof ToolTip) {
ToolTip tooltip = (ToolTip) data;
tooltip.show(new Point(0, 0));
}
} else if (href != null) {
searchForTag(href.toString());
}
}
}.register(tagsLink);
}
use of org.eclipse.jface.window.ToolTip in project translationstudio8 by heartsome.
the class TSTitleAreaDialog method layoutForNewMessage.
/**
* Re-layout the labels for the new message.
*
* @param forceLayout
* <code>true</code> to force a layout of the shell
*/
private void layoutForNewMessage(boolean forceLayout) {
int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
// If there are no images then layout as normal
if (errorMessage == null && messageImage == null) {
setImageLabelVisible(false);
setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
} else {
messageImageLabel.setVisible(true);
bottomFillerLabel.setVisible(true);
leftFillerLabel.setVisible(true);
/**
* Note that we do not use horizontalSpacing here as when the
* background of the messages changes there will be gaps between the
* icon label and the message that are the background color of the
* shell. We add a leading space elsewhere to compendate for this.
*/
FormData data = new FormData();
data.left = new FormAttachment(0, H_GAP_IMAGE);
data.top = new FormAttachment(titleLabel, verticalSpacing);
messageImageLabel.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(messageImageLabel, 0);
data.left = new FormAttachment(0, 0);
data.bottom = new FormAttachment(messageLabel, 0, SWT.BOTTOM);
data.right = new FormAttachment(messageImageLabel, 0, SWT.RIGHT);
bottomFillerLabel.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(messageImageLabel, 0, SWT.TOP);
data.left = new FormAttachment(0, 0);
data.bottom = new FormAttachment(messageImageLabel, 0, SWT.BOTTOM);
data.right = new FormAttachment(messageImageLabel, 0);
leftFillerLabel.setLayoutData(data);
FormData messageLabelData = new FormData();
messageLabelData.top = new FormAttachment(titleLabel, verticalSpacing);
messageLabelData.right = new FormAttachment(titleImageLabel);
messageLabelData.left = new FormAttachment(messageImageLabel, 0);
messageLabelData.height = messageLabelHeight;
if (titleImageLargest)
messageLabelData.bottom = new FormAttachment(titleImageLabel, 0, SWT.BOTTOM);
messageLabel.setLayoutData(messageLabelData);
}
if (forceLayout) {
getShell().layout();
} else {
// to avoid incomplete calculations.
if (dialogArea != null)
workArea.getParent().layout(true);
}
int messageLabelUnclippedHeight = messageLabel.computeSize(messageLabel.getSize().x - xTrim, SWT.DEFAULT, true).y;
boolean messageLabelClipped = messageLabelUnclippedHeight > messageLabel.getSize().y - yTrim;
if (messageLabel.getData() instanceof ToolTip) {
ToolTip toolTip = (ToolTip) messageLabel.getData();
toolTip.hide();
toolTip.deactivate();
messageLabel.setData(null);
}
if (messageLabelClipped) {
ToolTip tooltip = new ToolTip(messageLabel, ToolTip.NO_RECREATE, false) {
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite result = new Composite(parent, SWT.NONE);
result.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
result.setLayout(new GridLayout());
Text text = new Text(result, SWT.WRAP);
text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
text.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
text.setText(messageLabel.getText());
GridData gridData = new GridData();
gridData.widthHint = messageLabel.getSize().x;
text.setLayoutData(gridData);
Dialog.applyDialogFont(result);
return result;
}
public Point getLocation(Point tipSize, Event event) {
return messageLabel.getShell().toDisplay(messageLabel.getLocation());
}
};
messageLabel.setData(tooltip);
tooltip.setPopupDelay(0);
tooltip.activate();
}
}
use of org.eclipse.jface.window.ToolTip in project mylyn.docs by eclipse.
the class MarkupEditorOutline method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
TreeViewer viewer = getTreeViewer();
viewer.setUseHashlookup(true);
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
viewer.setContentProvider(new BaseWorkbenchContentProvider());
viewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
viewer.setInput(editor.getOutlineModel());
viewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
revealInEditor(event.getSelection(), true);
}
});
viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
revealInEditor(event.getSelection(), false);
}
});
viewer.expandAll();
new ToolTip(viewer.getControl(), ToolTip.RECREATE, false) {
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
GridLayout gl = new GridLayout(1, false);
gl.marginBottom = 2;
gl.marginTop = 2;
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.marginLeft = 2;
gl.marginRight = 2;
gl.verticalSpacing = 1;
comp.setLayout(gl);
Object tipItem = getToolTipItem(new Point(event.x, event.y));
if (tipItem instanceof OutlineItem) {
OutlineItem outlineItem = (OutlineItem) tipItem;
Label label = new Label(comp, SWT.WRAP);
label.setBackground(comp.getBackground());
label.setText(outlineItem.getTooltip());
}
return comp;
}
@Override
protected boolean shouldCreateToolTip(Event event) {
final Object eventItem = getToolTipItem(new Point(event.x, event.y));
boolean shouldCreate = eventItem != null && eventItem instanceof OutlineItem && super.shouldCreateToolTip(event);
if (!shouldCreate) {
hide();
}
return shouldCreate;
}
protected Object getToolTipItem(Point point) {
TreeItem item = ((Tree) getTreeViewer().getControl()).getItem(point);
if (item != null) {
return item.getData();
}
return null;
}
};
IPageSite site = getSite();
site.setSelectionProvider(viewer);
configureActionBars(site);
// $NON-NLS-1$
MenuManager manager = new MenuManager("#PopUp");
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager menuManager) {
contextMenuAboutToShow(menuManager);
}
});
viewer.getTree().setMenu(manager.createContextMenu(viewer.getTree()));
// $NON-NLS-1$
site.registerContextMenu(MarkupEditor.ID + ".outlineContextMenu", manager, viewer);
configureDnd();
configureActions();
}
Aggregations