use of org.eclipse.swt.custom.TreeEditor in project dbeaver by serge-rider.
the class PropertyTreeViewer method registerEditor.
private void registerEditor() {
// Make an editor
final Tree treeControl = super.getTree();
treeEditor = new TreeEditor(treeControl);
treeEditor.horizontalAlignment = SWT.CENTER;
treeEditor.verticalAlignment = SWT.CENTER;
treeEditor.minimumWidth = 50;
treeControl.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// showEditor((TreeItem) e.item, true);
}
@Override
public void widgetSelected(final SelectionEvent e) {
TreeItem item = (TreeItem) e.item;
if (GeneralUtils.isMacOS()) {
// [#10279] [#10366] [#10361]
showEditor(item, isMouseEventOnMacos);
isMouseEventOnMacos = false;
return;
}
showEditor(item, (e.stateMask & SWT.BUTTON_MASK) != 0);
}
});
treeControl.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
TreeItem item = treeControl.getItem(new Point(e.x, e.y));
if (GeneralUtils.isMacOS()) {
// [#10279] [#10366] [#10361]
isMouseEventOnMacos = true;
}
if (item != null) {
selectedColumn = UIUtils.getColumnAtPos(item, e.x, e.y);
} else {
selectedColumn = -1;
if (newPropertiesAllowed) {
TreeItem[] allItems = treeControl.getItems();
TreeItem lastItem = allItems[allItems.length - 1];
if (lastItem.getData() instanceof TreeNode) {
TreeNode lastNode = (TreeNode) lastItem.getData();
if (!CommonUtils.isEmpty(lastNode.children)) {
lastNode = lastNode.children.get(lastNode.children.size() - 1);
}
if (lastNode.property != null && CommonUtils.isEmpty(lastNode.property.getDisplayName())) {
return;
}
if (lastNode.parent != null)
lastNode = lastNode.parent;
addProperty(lastNode, new PropertyDescriptor(lastNode.category, "prop" + lastNode.children.size(), "", "", false, String.class, "", null), true);
allItems = treeControl.getItems();
TreeItem newItem = allItems[allItems.length - 1];
treeControl.setSelection(newItem);
selectedColumn = UIUtils.getColumnAtPos(newItem, e.x, e.y);
}
}
}
}
});
treeControl.addTraverseListener(e -> {
if (e.detail == SWT.TRAVERSE_RETURN) {
// Set focus on editor
if (curCellEditor != null) {
curCellEditor.setFocus();
} else {
final TreeItem[] selection = treeControl.getSelection();
if (selection.length == 0) {
return;
}
showEditor(selection[0], true);
}
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
}
});
}
use of org.eclipse.swt.custom.TreeEditor in project dbeaver by serge-rider.
the class DatabaseNavigatorTree method initEditor.
private void initEditor() {
if (inlineRenameEnabled) {
Tree treeControl = this.treeViewer.getTree();
treeEditor = new TreeEditor(treeControl);
treeEditor.horizontalAlignment = SWT.LEFT;
treeEditor.verticalAlignment = SWT.TOP;
treeEditor.grabHorizontal = false;
treeEditor.minimumWidth = 50;
if (!checkEnabled) {
// Add rename listener only for non CHECK trees
treeControl.addMouseListener(new TreeSelectionAdapter());
}
}
}
use of org.eclipse.swt.custom.TreeEditor in project yyl_example by Relucent.
the class DispelTreeEditorBug method setVisibilityTreeEditor.
private void setVisibilityTreeEditor(TreeItem treeItem, boolean visible) {
for (String sEditorName : sEditorNames) {
Object obj = treeItem.getData(sEditorName);
if (obj instanceof TreeEditor) {
TreeEditor oTreeEditor = (TreeEditor) obj;
oTreeEditor.minimumWidth = visible ? 12 : 0;
oTreeEditor.layout();
}
}
}
use of org.eclipse.swt.custom.TreeEditor 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.swt.custom.TreeEditor in project pentaho-kettle by pentaho.
the class ScriptDialog method addRenameTowTreeScriptItems.
private void addRenameTowTreeScriptItems() {
lastItem = new TreeItem[1];
editor = new TreeEditor(wTree);
wTree.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
final TreeItem item = (TreeItem) event.item;
renameFunction(item);
}
});
}
Aggregations