use of org.eclipse.jface.viewers.ViewerCell in project cubrid-manager by CUBRID.
the class TableFocusHighLighter method hookListener.
private void hookListener(final EditableTableViewer viewer) {
Listener listener = new Listener() {
public void handleEvent(Event event) {
if ((event.detail & SWT.SELECTED) > 0) {
ViewerCell focusCell = getFocusCell();
ViewerRow row = viewer.getViewerRowByItem(event.item);
ViewerCell cell = row.getCell(event.index);
if (focusCell == null || !cell.equals(focusCell)) {
removeSelectionInformation(event, cell);
} else {
markFocusedCell(event, cell);
}
}
}
};
viewer.getControl().addListener(SWT.EraseItem, listener);
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class BrowserColumnViewerTip method showToolTip.
/**
* Show tooltip for the cell at the given position
*
* @param x the widget relative x ordinate
* @param y the widget relative y ordinate
*/
protected void showToolTip(int x, int y) {
ViewerCell cell = viewer.getCell(new Point(x, y));
if (toolCell != null && toolCell.equals(cell) && BrowserTip.toolTipVisible(toolShell)) {
// tooltip already visible -> do nothing
return;
}
toolCell = cell;
BrowserTip.hideToolTip(toolShell);
if (cell != null) {
Object element = cell.getElement();
int col = cell.getColumnIndex();
/**
* It would be very nice if we could get the column from the viewer
* and the attached label provider, but the getViewerColumn method
* is only package visible
*/
String text = cell.getText();
String tipText = getToolTip(element, col, text);
if (tipText != null && !tipText.isEmpty() && tipText.length() >= tipCharThreshold) {
Rectangle cellBounds = cell.getBounds();
// toolShell = tip.showToolTip(viewer.getControl(), x, y, tipText);
toolShell = tip.showToolTip(viewer.getControl(), cellBounds.x, cellBounds.y + cellBounds.height, tipText, cellBounds, viewer.getControl());
}
}
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class DefinitionInstanceTreeViewer method createControls.
/**
* @see InstanceViewer#createControls(Composite, SchemaSpaceID)
*/
@Override
public void createControls(final Composite parent, SchemaSpaceID schemaSpace) {
main = new Composite(parent, SWT.NONE);
main.setLayout(new TreeColumnLayout());
treeViewer = new TreeViewer(main, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
treeViewer.setContentProvider(new TypeMetaPairContentProvider(treeViewer, schemaSpace));
treeViewer.setLabelProvider(new DefinitionMetaCompareLabelProvider(treeViewer));
// Add an editor for selecting specific paths.
editor = new TreeEditor(treeViewer.getTree());
editor.horizontalAlignment = SWT.RIGHT;
treeViewer.getTree().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
final ViewerCell cell = treeViewer.getCell(new Point(e.x, e.y));
// Selected cell changed?
if (cell == null || editor.getItem() != cell.getItem() || editor.getColumn() != cell.getColumnIndex()) {
// Clean up any previous editor control
Control oldEditor = editor.getEditor();
if (oldEditor != null) {
oldEditor.dispose();
editor.setEditor(null, null, 0);
}
}
// No valid selected cell
if (cell == null || cell.getColumnIndex() == 0) {
return;
}
// cell didn't change
if ((editor.getItem() == cell.getItem() && editor.getColumn() == cell.getColumnIndex())) {
return;
}
Composite editorControl = new Composite(treeViewer.getTree(), SWT.NONE);
GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).numColumns(2).applyTo(editorControl);
boolean hideCopy = false;
// multi value selector
// Quote the format first. Pattern.quote does the same, except,
// that it checks the input for \Es.
// Since we know that there will be no \Es in this case
// do it ourselves to be safe from changes to Pattern.quote.
String pattern = "\\Q" + DefinitionInstanceLabelProvider.MULTIPLE_VALUE_FORMAT + "\\E$";
pattern = pattern.replace("{0}", "\\E(\\d+)\\Q").replace("{1}", "\\E(\\d+)\\Q");
Matcher m = Pattern.compile(pattern).matcher(cell.getText());
if (m.find()) {
// multi value element
int current = Integer.parseInt(m.group(1));
int total = Integer.parseInt(m.group(2));
// Create the selection control.
ComboViewer combo = new ComboViewer(editorControl);
Integer[] values = new Integer[total];
for (int i = 1; i <= total; i++) values[i - 1] = i;
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setInput(values);
combo.setSelection(new StructuredSelection(current));
combo.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
// Update label provider and refresh viewer.
labelProviders.get(cell.getColumnIndex()).selectPath(cell.getViewerRow().getTreePath(), (Integer) (((IStructuredSelection) event.getSelection()).getFirstElement()));
treeViewer.refresh(cell.getElement(), true);
}
}
});
} else {
/*
* only one value - so we can safely determine if the copy
* button should be shown
*/
Object value = labelProviders.get(cell.getColumnIndex()).findInstanceEntry(cell.getViewerRow().getTreePath()).getValue();
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
hideCopy = value == null || value.toString().isEmpty();
}
// copy button
if (!hideCopy) {
Button button = new Button(editorControl, SWT.PUSH | SWT.FLAT);
button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
button.setToolTipText("Copy string value");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// determine text value
Object value = labelProviders.get(cell.getColumnIndex()).findInstanceEntry(cell.getViewerRow().getTreePath()).getValue();
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
if (value != null) {
final String textValue = value.toString();
if (!textValue.isEmpty()) {
// empty string is
// invalid
// copy content to clipboard
Clipboard clipBoard = new Clipboard(Display.getCurrent());
clipBoard.setContents(new Object[] { textValue }, new Transfer[] { TextTransfer.getInstance() });
clipBoard.dispose();
}
}
}
});
}
// calculate editor size
Point size = editorControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
editor.minimumHeight = size.y;
editor.minimumWidth = size.x;
editor.setEditor(editorControl, (TreeItem) cell.getItem(), cell.getColumnIndex());
}
});
maep = new MetadataCompareActionProvider(treeViewer);
maep.setup();
treeViewer.setComparator(new DefinitionComparator());
treeViewer.getTree().setHeaderVisible(true);
treeViewer.getTree().setLinesVisible(true);
ColumnViewerToolTipSupport.enableFor(treeViewer);
setInput(null, null);
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class WebTemplatesDialog method setupViewer.
@Override
protected void setupViewer(final TreeViewer viewer, WebTemplate initialSelection) {
// this label provider is used for filtering (I guess)
viewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof WebTemplate) {
return ((WebTemplate) element).getName();
}
return super.getText(element);
}
});
viewer.getTree().setHeaderVisible(true);
// viewer.getTree().setLinesVisible(true);
// main column
TreeViewerColumn mainColumn = new TreeViewerColumn(viewer, SWT.NONE);
mainColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
StyledString text = new StyledString();
if (element instanceof WebTemplate) {
WebTemplate template = (WebTemplate) element;
text.append(template.getName());
} else {
text.append(element.toString());
}
cell.setText(text.getString());
cell.setStyleRanges(text.getStyleRanges());
super.update(cell);
}
});
mainColumn.getColumn().setText("Template");
layout.setColumnData(mainColumn.getColumn(), new ColumnWeightData(7));
// link column
if (Desktop.isDesktopSupported()) {
TreeViewerColumn linkColumn = new TreeViewerColumn(viewer, SWT.CENTER);
linkColumn.setLabelProvider(new LinkLabels());
// listener that reacts on link cell clicks
viewer.getTree().addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
if (e.button == 1) {
ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
if (cell != null && cell.getColumnIndex() == 1 && cell.getTextBounds().contains(e.x, e.y)) {
Object element = cell.getElement();
if (element instanceof WebTemplate) {
try {
Desktop.getDesktop().browse(((WebTemplate) element).getSite());
} catch (IOException e1) {
log.error("Could not launch browser", e1);
}
}
}
}
}
});
layout.setColumnData(linkColumn.getColumn(), new ColumnWeightData(1));
}
viewer.setComparator(new ViewerComparator());
viewer.setContentProvider(new WebTemplatesContentProvider());
viewer.setInput(templates);
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class LookupTablePage method addPreview.
// add table for the preview to the given composite
private void addPreview(Composite page) {
tableContainer = new Composite(page, SWT.NONE);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TableColumnLayout layout = new TableColumnLayout();
tableContainer.setLayout(layout);
tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
tableViewer.getTable().setLinesVisible(true);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
sourceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
return entry.getKey().getStringRepresentation();
}
});
targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
targetColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
if (entry.getValue() == null) {
StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
cell.setText(styledString.getString());
cell.setStyleRanges(styledString.getStyleRanges());
} else {
cell.setText(entry.getValue().getStringRepresentation());
cell.setStyleRanges(null);
}
super.update(cell);
}
});
}
Aggregations