use of org.eclipse.swt.custom.TreeEditor in project arduino-eclipse-plugin by Sloeber.
the class LibrarySelectionPage method createTree.
public void createTree(Composite parent) {
// filtering applied to all columns
PatternFilter filter = new PatternFilter() {
@Override
protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
int numberOfColumns = ((TreeViewer) viewer1).getTree().getColumnCount();
boolean isMatch = false;
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
String labelText = LibraryLabelProvider.getColumnText(element, columnIndex);
isMatch |= wordMatches(labelText);
}
return isMatch;
}
};
this.tree = new FilteredTree(parent, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true) {
@SuppressWarnings("synthetic-access")
@Override
protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
viewer1.setCheckStateProvider(new LibraryCheckProvider());
viewer1.setLabelProvider(new LibraryLabelProvider());
viewer1.setContentProvider(new LibraryContentProvider());
return viewer1;
}
};
this.viewer = this.tree.getViewer();
this.viewer.setInput(this.libs);
TreeColumn name = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
name.setWidth(400);
TreeColumn version = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
version.setWidth(100);
// create the editor and set its attributes
this.editor = new TreeEditor(this.viewer.getTree());
this.editor.horizontalAlignment = SWT.LEFT;
this.editor.grabHorizontal = true;
this.editor.setColumn(1);
// this ensures the tree labels are displayed correctly
this.viewer.refresh(true);
// enable tooltips
ColumnViewerToolTipSupport.enableFor(this.viewer);
// tree interactions listener
this.viewer.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (LibrarySelectionPage.this.editor.getEditor() != null) {
LibrarySelectionPage.this.editor.getEditor().dispose();
}
final TreeItem item = event.item instanceof TreeItem ? (TreeItem) event.item : null;
if (item != null && event.detail == SWT.CHECK) {
if (item.getData() instanceof LibraryTree.Category) {
item.setGrayed(false);
for (LibraryTree.Library child : ((LibraryTree.Category) item.getData()).getLibraries()) {
if (item.getChecked()) {
child.setVersion(child.getLatest());
} else {
child.setVersion(null);
}
}
for (TreeItem child : item.getItems()) {
child.setChecked(item.getChecked());
if (item.getChecked()) {
child.setText(1, ((LibraryTree.Library) child.getData()).getLatest());
} else {
child.setText(1, emptyString);
}
}
} else {
if (item.getChecked()) {
((LibraryTree.Library) item.getData()).setVersion(((LibraryTree.Library) item.getData()).getLatest());
item.setText(1, ((LibraryTree.Library) item.getData()).getLatest());
} else {
((LibraryTree.Library) item.getData()).setVersion(null);
item.setText(1, emptyString);
}
verifySubtreeCheckStatus(item.getParentItem());
}
}
if (item != null && item.getItemCount() == 0 && item.getChecked()) {
// Create the dropdown and add data to it
final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY);
for (VersionNumber version1 : ((LibraryTree.Library) item.getData()).getVersions()) {
combo.add(version1.toString());
}
// Select the previously selected item from the cell
combo.select(combo.indexOf(item.getText(1)));
// Compute the width for the editor
// Also, compute the column width, so that the dropdown fits
// Set the focus on the dropdown and set into the editor
combo.setFocus();
LibrarySelectionPage.this.editor.setEditor(combo, item, 1);
// Add a listener to set the selected item back into the
// cell
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event1) {
((LibraryTree.Library) item.getData()).setVersion(combo.getText());
item.setText(1, combo.getText());
// Item selected: end the editing session
combo.dispose();
}
});
}
}
});
}
use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.
the class AbstractColumnDropTree method removeItemBranch.
protected void removeItemBranch(TreeItem item) {
TreeEditor[] editors = (TreeEditor[]) item.getData(ITEM_EDITOR_KEY);
if (editors != null) {
for (TreeEditor editor : editors) {
editor.getEditor().dispose();
editor.dispose();
}
}
if (item.getItemCount() == 0) {
item.dispose();
this.setDirty(true);
return;
}
TreeItem[] items = item.getItems();
for (TreeItem item2 : items) {
removeItemBranch(item2);
}
item.dispose();
this.setDirty(true);
}
use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.
the class AnalysisTableTreeViewer method createOneUnit.
public void createOneUnit(final TreeItem treeItem, TableIndicatorUnit indicatorUnit) {
final TreeItem indicatorItem = new TreeItem(treeItem, SWT.NONE);
final TableIndicatorUnit unit = indicatorUnit;
IndicatorEnum type = indicatorUnit.getType();
final IndicatorEnum indicatorEnum = type;
indicatorItem.setData(TABLE_INDICATOR_KEY, treeItem.getData(TABLE_INDICATOR_KEY));
indicatorItem.setData(INDICATOR_UNIT_KEY, unit);
indicatorItem.setData(VIEWER_KEY, this);
String label = indicatorUnit.getIndicatorName();
// $NON-NLS-1$
label = label != null ? label : "Unknown indicator";
SysIndicatorDefinitionRepNode recursiveFindIndicatorDefinition = RepositoryNodeHelper.recursiveFindIndicatorDefinition(indicatorUnit.getIndicator().getIndicatorDefinition());
if (recursiveFindIndicatorDefinition != null && !recursiveFindIndicatorDefinition.getProject().isMainProject()) {
label = label + recursiveFindIndicatorDefinition.getDisplayProjectName();
}
if (IndicatorEnum.WhereRuleIndicatorEnum.compareTo(type) == 0) {
indicatorItem.setImage(0, ImageLib.getImage(ImageLib.DQ_RULE));
} else if (IndicatorEnum.RowCountIndicatorEnum.compareTo(type) == 0) {
indicatorItem.setImage(0, ImageLib.getImage(ImageLib.IND_DEFINITION));
}
indicatorItem.setText(0, label);
TreeEditor optionEditor = new TreeEditor(tree);
// $NON-NLS-1$
final Label optionLabel = createTreeItemLabel(tree, ImageLib.OPTION, "AnalysisTableTreeViewer.options");
optionLabel.setData(indicatorUnit);
optionLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
boolean hasIndicatorParameters = openIndicatorOptionDialog(Display.getCurrent().getActiveShell(), indicatorItem);
if (hasIndicatorParameters) {
optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
}
}
});
optionEditor.minimumWidth = optionLabel.getImage().getBounds().width;
optionEditor.horizontalAlignment = SWT.CENTER;
optionEditor.setEditor(optionLabel, indicatorItem, 1);
TreeEditor delEditor = null;
if (!(unit.getIndicator() instanceof RowCountIndicator)) {
delEditor = new TreeEditor(tree);
// $NON-NLS-1$
Label delLabel = createTreeItemLabel(tree, ImageLib.DELETE_ACTION, "AnalysisTableTreeViewer.delete");
delLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
deleteIndicatorItems((TableIndicator) treeItem.getData(TABLE_INDICATOR_KEY), unit);
if (indicatorItem.getParentItem() != null && indicatorItem.getParentItem().getData(INDICATOR_UNIT_KEY) != null) {
setElements(tableIndicators);
} else {
removeItemBranch(indicatorItem);
indicatorTreeItemMap.remove(unit);
}
}
});
delEditor.minimumWidth = delLabel.getImage().getBounds().width;
delEditor.horizontalAlignment = SWT.CENTER;
delEditor.setEditor(delLabel, indicatorItem, 2);
}
if (delEditor == null) {
indicatorItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { optionEditor });
} else {
indicatorItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { optionEditor, delEditor });
}
if (indicatorEnum != null && indicatorEnum.hasChildren()) {
indicatorItem.setData(treeItem.getData(TABLE_INDICATOR_KEY));
createIndicatorItems(indicatorItem, indicatorUnit.getChildren());
}
if (hasIndicatorParameters(indicatorUnit)) {
optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
}
// ADD xqliu 2009-04-30 bug 6808
this.indicatorTreeItemMap.put(unit, indicatorItem);
}
use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.
the class AnalysisTableTreeViewer method addItemElements.
private void addItemElements(final TableIndicator[] elements) {
for (final TableIndicator tableIndicator : elements) {
final TreeItem treeItem = new TreeItem(tree, SWT.NONE);
if (tableIndicator.isTable()) {
treeItem.setImage(ImageLib.getImage(ImageLib.TABLE));
} else if (tableIndicator.isView()) {
treeItem.setImage(ImageLib.getImage(ImageLib.VIEW));
}
ModelElement columnSet = tableIndicator.getColumnSet();
if (columnSet.eIsProxy()) {
// try to resolve the proxy
columnSet = (ModelElement) EObjectHelper.resolveObject(columnSet);
}
String columnSetName = columnSet.getName();
if (columnSetName == null) {
// $NON-NLS-1$
columnSetName = "Unknown name";
}
treeItem.setText(0, columnSetName);
treeItem.setData(TABLE_INDICATOR_KEY, tableIndicator);
TreeEditor addDQRuleEditor = new TreeEditor(tree);
// $NON-NLS-1$
Label addDQRuleLabl = createTreeItemLabel(tree, ImageLib.ADD_DQ, "AnalysisColumnTreeViewer.addDQRule");
addDQRuleLabl.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
showAddDQRuleDialog(treeItem, tableIndicator);
}
});
addDQRuleEditor.minimumWidth = addDQRuleLabl.getImage().getBounds().width;
addDQRuleEditor.setEditor(addDQRuleLabl, treeItem, 1);
TreeEditor delLabelEditor = new TreeEditor(tree);
// $NON-NLS-1$
Label delLabel = createTreeItemLabel(tree, ImageLib.DELETE_ACTION, "AnalysisColumnTreeViewer.delete");
delLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
deleteTableItems(tableIndicator);
if (treeItem.getParentItem() != null && treeItem.getParentItem().getData(INDICATOR_UNIT_KEY) != null) {
setElements(tableIndicators);
} else {
deleteIndicatorItems(tableIndicator);
removeItemBranch(treeItem);
indicatorTreeItemMap.remove(tableIndicator);
}
// MOD mzhao 2005-05-05 bug 6587.
// MOD mzhao 2009-06-8, bug 5887.
// updateBindConnection(masterPage, getTableIndicator(),
// tree);
}
});
delLabelEditor.minimumWidth = delLabel.getImage().getBounds().width;
delLabelEditor.horizontalAlignment = SWT.CENTER;
delLabelEditor.setEditor(delLabel, treeItem, 2);
treeItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { addDQRuleEditor, delLabelEditor });
if (tableIndicator.hasIndicators()) {
createIndicatorItems(treeItem, tableIndicator.getIndicatorUnits());
}
treeItem.setExpanded(true);
// ADD xqliu 2009-04-30 bug 6808
this.indicatorTreeItemMap.put(tableIndicator, treeItem);
}
this.setDirty(true);
}
use of org.eclipse.swt.custom.TreeEditor in project BiglyBT by BiglySoftware.
the class WebSeedsEditor method createWindow.
private void createWindow() {
this.display = Display.getCurrent();
this.shell = com.biglybt.ui.swt.components.shell.ShellFactory.createShell(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
Messages.setLanguageText(this.shell, "wizard.webseedseditor.edit.title");
Utils.setShellIcon(shell);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
shell.setLayout(layout);
GridData gridData;
if (!anonymous) {
Label labelName = new Label(shell, SWT.NULL);
Messages.setLanguageText(labelName, "wizard.multitracker.edit.name");
textName = new Text(shell, SWT.BORDER);
textName.setText(currentName);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Utils.setLayoutData(textName, gridData);
textName.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
currentName = textName.getText();
computeSaveEnable();
}
});
}
treeGroups = new Tree(shell, SWT.BORDER);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 3;
gridData.heightHint = 150;
Utils.setLayoutData(treeGroups, gridData);
treeGroups.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
if (treeGroups.getSelectionCount() == 1) {
TreeItem treeItem = treeGroups.getSelection()[0];
String type = (String) treeItem.getData("type");
if (type.equals("tracker")) {
editTreeItem(treeItem);
}
}
}
});
Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
Utils.setLayoutData(labelSeparator, gridData);
// button row
Label label = new Label(shell, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(label, gridData);
Composite cButtons = new Composite(shell, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
Utils.setLayoutData(cButtons, gridData);
GridLayout layoutButtons = new GridLayout();
layoutButtons.numColumns = 3;
cButtons.setLayout(layoutButtons);
label = new Label(cButtons, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(label, gridData);
btnSave = new Button(cButtons, SWT.PUSH);
gridData = new GridData();
gridData.widthHint = 70;
gridData.horizontalAlignment = GridData.END;
Utils.setLayoutData(btnSave, gridData);
Messages.setLanguageText(btnSave, "wizard.multitracker.edit.save");
btnSave.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
update();
shell.dispose();
}
});
btnCancel = new Button(cButtons, SWT.PUSH);
gridData = new GridData();
gridData.horizontalAlignment = GridData.END;
gridData.widthHint = 70;
Utils.setLayoutData(btnCancel, gridData);
Messages.setLanguageText(btnCancel, "Button.cancel");
btnCancel.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
shell.dispose();
}
});
shell.setDefaultButton(btnSave);
shell.addListener(SWT.Traverse, new Listener() {
@Override
public void handleEvent(Event e) {
if (e.character == SWT.ESC) {
shell.dispose();
}
}
});
computeSaveEnable();
refresh();
constructMenu();
editor = new TreeEditor(treeGroups);
treeGroups.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (itemEdited != null && !editor.getEditor().isDisposed())
itemEdited.setText(((Text) editor.getEditor()).getText());
removeEditor();
}
});
shell.pack();
Point size = shell.computeSize(400, SWT.DEFAULT);
shell.setSize(size);
Utils.centreWindow(shell);
shell.open();
}
Aggregations