use of org.eclipse.jface.viewers.ICheckStateListener in project usbdm-eclipse-plugins by podonoghue.
the class UsbdmDevicePeripheralsView method createPartControl.
// /**
// * Provides the editor for the tree elements
// *
// * Does minor modifications to the default editor.
// */
// private class PeripheralsViewTextCellEditor extends TextCellEditor {
//
// private int minHeight;
//
// public PeripheralsViewTextCellEditor(Tree tree) {
// super(tree, SWT.BORDER);
// Text txt = (Text) getControl();
//
// Font fnt = txt.getFont();
// FontData[] fontData = fnt.getFontData();
// if (fontData != null && fontData.length > 0) {
// minHeight = fontData[0].getHeight() + 10;
// }
// }
//
// public LayoutData getLayoutData() {
// LayoutData data = super.getLayoutData();
// if (minHeight > 0)
// data.minimumHeight = minHeight;
// return data;
// }
// }
/**
* Callback that creates the viewer and initialises it.
*
* The View consists of a tree and a information panel
*/
public void createPartControl(Composite parent) {
// Create the manager and bind to main composite
resManager = new LocalResourceManager(JFaceResources.getResources(), parent);
parent.setLayoutData(new FillLayout());
SashForm form = new SashForm(parent, SWT.VERTICAL);
form.setLayout(new FillLayout());
// Make sash visible
form.setSashWidth(4);
form.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
// =============================
fPeripheralsTreeViewer = new CheckboxTreeViewer(form, SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION);
Tree tree = fPeripheralsTreeViewer.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
ColumnViewerToolTipSupport.enableFor(fPeripheralsTreeViewer);
// // Suppress tree expansion on double-click
// // see http://www.eclipse.org/forums/index.php/t/257325/
// peripheralsTreeViewer.getControl().addListener(SWT.MeasureItem, new Listener(){
// @Override
// public void handleEvent(Event event) {
// }});
fPeripheralsTreeViewer.setColumnProperties(fTreeProperties);
fPeripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new TextCellEditor(fPeripheralsTreeViewer.getTree()), null });
// peripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new PeripheralsViewTextCellEditor(peripheralsTreeViewer.getTree()), null });
fPeripheralsTreeViewer.setCellModifier(new PeripheralsViewCellModifier(this));
/*
* Name column
*/
TreeColumn column;
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultNameColumnWidth);
column.setText("Name");
// Add listener to column so peripherals are sorted by name when clicked
column.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
}
});
/*
* Value column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultValueColumnWidth);
column.setText("Value");
column.setResizable(fDefaultValueColumnWidth != 0);
/*
* Field column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultFieldColumnWidth);
column.setText("Field");
column.setResizable(fDefaultFieldColumnWidth != 0);
/*
* Mode column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultModeWidth);
column.setText("Mode");
column.setResizable(fDefaultModeWidth != 0);
/*
* Location column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultLocationColumnWidth);
column.setText("Location");
column.setResizable(fDefaultLocationColumnWidth != 0);
// Add listener to column so peripheral are sorted by address when clicked
column.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.AddressOrder));
}
});
/*
* Description column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultDescriptionColumnWidth);
column.setText("Description");
column.setResizable(fDefaultDescriptionColumnWidth != 0);
// Default to sorted by Peripheral name
fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
// Noting filtered
fPeripheralsTreeViewer.addFilter(new PeripheralsViewFilter(PeripheralsViewFilter.SelectionCriteria.SelectAll));
// Label provider
fPeripheralsTreeViewer.setLabelProvider(new PeripheralsViewCellLabelProvider(this));
// Content provider
fPeripheralsTreeViewer.setContentProvider(new PeripheralsViewContentProvider(this));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(fPeripheralsTreeViewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
// ||
return (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION);
// (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
}
};
TreeViewerEditor.create(fPeripheralsTreeViewer, actSupport, TreeViewerEditor.DEFAULT);
// Create the help context id for the viewer's control
// PlatformUI.getWorkbench().getHelpSystem().setHelp(treeViewer.getControl(),
// "usbdmMemory.viewer");
// =============================
fPeripheralsInformationPanel = new PeripheralsInformationPanel(form, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY, this.fPeripheralsTreeViewer);
form.setWeights(new int[] { 80, 20 });
// Tree expansion/collapse
fPeripheralsTreeViewer.addTreeListener(new ITreeViewerListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
Object element = event.getElement();
// System.err.println("treeExpanded() => event.getElement().getClass() = " + element.getClass());
if (element instanceof RegisterModel) {
((RegisterModel) element).update();
}
if (element instanceof PeripheralModel) {
((PeripheralModel) element).update();
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
});
// When user checks a checkbox in the tree, check all its children
fPeripheralsTreeViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
// peripheralsTreeViewer.expandToLevel(event.getElement(), 1);
fPeripheralsTreeViewer.setSubtreeChecked(event.getElement(), event.getChecked());
}
});
// Create the actions
makeActions();
// Add selected actions to context menu
hookContextMenu();
// Add selected actions to menu bar
contributeToActionBars();
}
use of org.eclipse.jface.viewers.ICheckStateListener in project nebula.widgets.nattable by eclipse.
the class FilterNatCombo method createDropdownControl.
@Override
protected void createDropdownControl(int style) {
super.createDropdownControl(style);
int dropdownListStyle = style | SWT.NO_SCROLL | HorizontalAlignmentEnum.getSWTStyle(this.cellStyle) | SWT.FULL_SELECTION;
this.selectAllItemViewer = CheckboxTableViewer.newCheckList(this.dropdownShell, dropdownListStyle);
// add a column to be able to resize the item width in the dropdown
new TableColumn(this.selectAllItemViewer.getTable(), SWT.NONE);
this.selectAllItemViewer.getTable().addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
calculateColumnWidth();
}
});
FormData data = new FormData();
if (this.showDropdownFilter) {
data.top = new FormAttachment(this.filterBox, 0, SWT.BOTTOM);
} else {
data.top = new FormAttachment(this.dropdownShell, 0, SWT.TOP);
}
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
this.selectAllItemViewer.getTable().setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(this.selectAllItemViewer.getControl(), 0, SWT.BOTTOM);
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
data.bottom = new FormAttachment(100);
this.dropdownTable.setLayoutData(data);
this.selectAllItemViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
return ((Collection<String>) inputElement).toArray();
}
});
this.selectAllItemViewer.setLabelProvider(new ILabelProvider() {
@Override
public void removeListener(ILabelProviderListener listener) {
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void dispose() {
}
@Override
public void addListener(ILabelProviderListener listener) {
}
@Override
public String getText(Object element) {
return element.toString();
}
@Override
public Image getImage(Object element) {
return null;
}
});
// $NON-NLS-1$
final String selectAllLabel = Messages.getString("FilterNatCombo.selectAll");
List<String> input = new ArrayList<String>();
input.add(selectAllLabel);
this.selectAllItemViewer.setInput(input);
this.selectAllItemViewer.getTable().setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
this.selectAllItemViewer.getTable().setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
this.selectAllItemViewer.getTable().setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
this.selectAllItemViewer.getTable().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
showDropdownControl();
}
});
this.selectAllItemViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getChecked()) {
// select all
FilterNatCombo.this.dropdownTable.selectAll();
} else {
// deselect all
FilterNatCombo.this.dropdownTable.deselectAll();
}
// selection and checkboxes are in sync
for (TableItem tableItem : FilterNatCombo.this.dropdownTable.getItems()) {
tableItem.setChecked(FilterNatCombo.this.dropdownTable.isSelected(FilterNatCombo.this.itemList.indexOf(tableItem.getText())));
}
// all checkbox
for (String item : FilterNatCombo.this.itemList) {
FilterNatCombo.this.selectionStateMap.put(item, event.getChecked());
}
updateTextControl(!FilterNatCombo.this.multiselect);
}
});
for (ICheckStateListener l : this.checkStateListener) {
this.selectAllItemViewer.addCheckStateListener(l);
}
// set an ICheckStateProvider that sets the checkbox state of the select
// all checkbox regarding the selection of the items in the dropdown
this.selectAllItemViewer.setCheckStateProvider(new ICheckStateProvider() {
@Override
public boolean isGrayed(Object element) {
return getSelectionCount() < FilterNatCombo.this.itemList.size();
}
@Override
public boolean isChecked(Object element) {
return getSelectionCount() > 0;
}
});
// add a selection listener to the items that simply refreshes the
// select all checkbox
this.dropdownTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FilterNatCombo.this.selectAllItemViewer.refresh();
}
});
}
use of org.eclipse.jface.viewers.ICheckStateListener in project nebula.widgets.nattable by eclipse.
the class FilterRowComboBoxCellEditor method createEditorControl.
@Override
public NatCombo createEditorControl(Composite parent) {
int style = SWT.READ_ONLY | SWT.MULTI | SWT.CHECK;
final FilterNatCombo combo = this.iconImage == null ? new FilterNatCombo(parent, this.cellStyle, this.maxVisibleItems, style, this.showDropdownFilter) : new FilterNatCombo(parent, this.cellStyle, this.maxVisibleItems, style, this.iconImage, this.showDropdownFilter);
combo.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_IBEAM));
combo.setMultiselectValueSeparator(this.multiselectValueSeparator);
combo.setMultiselectTextBracket(this.multiselectTextPrefix, this.multiselectTextSuffix);
addNatComboListener(combo);
// additionally add the ICheckStateListener so on changing the value of
// the select all item the change is also committed
combo.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getChecked()) {
setCanonicalValue(EditConstants.SELECT_ALL_ITEMS_VALUE);
}
commit(MoveDirectionEnum.NONE, (!FilterRowComboBoxCellEditor.this.multiselect && FilterRowComboBoxCellEditor.this.editMode == EditModeEnum.INLINE));
}
});
return combo;
}
use of org.eclipse.jface.viewers.ICheckStateListener in project n4js by eclipse.
the class ExportSelectionPage method createChoiceListGroup.
/**
* The List of projects
*
* @param composite
*/
private void createChoiceListGroup(Composite parent) {
Composite choiceListGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
choiceListGroup.setLayout(layout);
choiceListGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
choiceListGroup.setFont(parent.getFont());
choiceList = CheckboxTableViewer.newCheckList(choiceListGroup, SWT.BORDER);
choiceList.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
choiceList.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
// sort the projects before displaying, ignoring case like in the workspace projects view.
final List<IProject> sortedProjects = new ArrayList<>(projects.keySet());
sortedProjects.sort((a, b) -> a.getName().compareToIgnoreCase(b.getName()));
choiceList.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// n.t.d.
}
@Override
public void dispose() {
// n.t.d.
}
@Override
public Object[] getElements(Object inputElement) {
return sortedProjects.toArray();
}
});
choiceList.setCheckStateProvider(new ICheckStateProvider() {
@Override
public boolean isGrayed(Object element) {
return false;
}
@Override
public boolean isChecked(Object element) {
Boolean checkedState = projects.get(element);
return checkedState != null && checkedState.booleanValue();
}
});
choiceList.setInput(new StructuredSelection(projects));
choiceList.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
handleCheckStateChange(event);
}
});
}
use of org.eclipse.jface.viewers.ICheckStateListener in project hale by halestudio.
the class MergeParameterPage method createContent.
@Override
protected void createContent(Composite page) {
// set layout of page
page.setLayout(new GridLayout());
Label name = new Label(page, SWT.NONE);
name.setText(parameter.getDisplayName());
// create checkbox tree viewer
viewer = new CheckboxTreeViewer(page, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
viewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
// comparator
viewer.setComparator(new DefinitionComparator());
// label provider
viewer.setLabelProvider(labelProvider);
// content provider
viewer.setContentProvider(new PropertyPathContentProvider(SchemaSpaceID.SOURCE));
// check state listener
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
// add/remove it from/to set of selected properties
EntityDefinition eventSource = (EntityDefinition) event.getElement();
if (event.getChecked())
selection.add(eventSource);
else
selection.remove(eventSource);
}
});
// for now filter everything after first level
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return parentElement == sourceType;
}
});
if (parameter.getName().equals(PARAMETER_ADDITIONAL_PROPERTY))
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return !filtered.contains(element);
}
});
Cell unfinishedCell = getWizard().getUnfinishedCell();
if (unfinishedCell.getSource() != null) {
sourceType = (TypeDefinition) unfinishedCell.getSource().values().iterator().next().getDefinition().getDefinition();
}
viewer.setInput(sourceType);
// add initial selection
if (sourceType != null && initialSelection != null) {
for (String propertyPath : initialSelection) {
EntityDefinition entity = getEntityDefinition(propertyPath, sourceType);
if (entity != null) {
selection.add(entity);
} else {
log.warn("Could not find child for property path " + propertyPath);
}
}
viewer.setCheckedElements(selection.toArray());
}
}
Aggregations