use of org.eclipse.jface.viewers.CheckStateChangedEvent in project tracecompass by tracecompass.
the class AbstractTracePackageWizardPage method createElementViewer.
/**
* Create the element viewer
*
* @param compositeParent
* the parent composite
*/
protected void createElementViewer(Composite compositeParent) {
fElementViewer = new CheckboxTreeViewer(compositeParent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.CHECK);
fElementViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
TracePackageElement element = (TracePackageElement) event.getElement();
if (!element.isEnabled()) {
fElementViewer.setChecked(element, element.isChecked());
} else {
setSubtreeChecked(fElementViewer, element, true, event.getChecked());
}
maintainCheckIntegrity(element);
if (element.getParent() != null) {
// Uncheck everything in this trace if Trace files are unchecked
if (element instanceof TracePackageFilesElement) {
if (!element.isChecked()) {
setSubtreeChecked(fElementViewer, element.getParent(), false, false);
}
// Check Trace files if anything else is selected
} else if (element.isChecked()) {
TracePackageElement parent = element.getParent();
while (parent != null) {
for (TracePackageElement e : parent.getChildren()) {
if (e instanceof TracePackageFilesElement) {
setSubtreeChecked(fElementViewer, e, false, true);
break;
}
}
parent = parent.getParent();
}
}
}
maintainExperimentIntegrity(element);
updateApproximateSelectedSize();
updatePageCompletion();
}
private void maintainCheckIntegrity(final TracePackageElement element) {
TracePackageElement parentElement = element.getParent();
boolean allChecked = true;
boolean oneChecked = false;
if (parentElement != null) {
if (parentElement.getChildren() != null) {
for (TracePackageElement child : parentElement.getChildren()) {
if (fElementViewer.getGrayed(child)) {
oneChecked = true;
allChecked = false;
break;
}
boolean checked = fElementViewer.getChecked(child);
oneChecked |= checked;
allChecked &= checked;
}
}
if (oneChecked && !allChecked) {
fElementViewer.setGrayChecked(parentElement, true);
} else {
fElementViewer.setGrayed(parentElement, false);
fElementViewer.setChecked(parentElement, allChecked);
}
maintainCheckIntegrity(parentElement);
}
}
private void maintainExperimentIntegrity(final TracePackageElement element) {
TracePackageElement parent = element;
while (parent.getParent() != null) {
parent = parent.getParent();
}
if (parent instanceof TracePackageExperimentElement && fElementViewer.getChecked(parent)) {
TracePackageExperimentElement experiment = (TracePackageExperimentElement) parent;
// Check all traces of the checked experiment
for (String expTrace : experiment.getExpTraces()) {
for (TracePackageElement root : (TracePackageElement[]) fElementViewer.getInput()) {
if (!(root instanceof TracePackageExperimentElement) && root.getText().equals(expTrace)) {
fElementViewer.setSubtreeChecked(root, true);
break;
}
}
}
} else if (!(parent instanceof TracePackageExperimentElement) && !fElementViewer.getChecked(parent)) {
// Uncheck all experiments that contain unchecked trace
for (TracePackageElement root : (TracePackageElement[]) fElementViewer.getInput()) {
if (root instanceof TracePackageExperimentElement) {
TracePackageExperimentElement experiment = (TracePackageExperimentElement) root;
if (experiment.getExpTraces().contains(parent.getText())) {
fElementViewer.setSubtreeChecked(experiment, false);
}
}
}
}
}
});
GridData layoutData = new GridData(GridData.FILL_BOTH);
fElementViewer.getTree().setLayoutData(layoutData);
fElementViewer.setContentProvider(new TracePackageContentProvider());
fElementViewer.setLabelProvider(new TracePackageLabelProvider());
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project grails-ide by spring-attic.
the class InstalledGrailsInstallBlock method createControl.
public void createControl(Composite ancestor) {
Font font = ancestor.getFont();
Composite parent = SWTFactory.createComposite(ancestor, font, 2, 1, GridData.FILL_BOTH);
GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
fControl = parent;
SWTFactory.createLabel(parent, "Grails Installations:", 2);
fTable = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
fTable.setFont(font);
fTable.setHeaderVisible(true);
fTable.setLinesVisible(true);
// GridData gd = new GridData(GridData.FILL_BOTH);
// gd.heightHint = 250;
// gd.widthHint = 350;
GridDataFactory.fillDefaults().hint(350, 250).grab(true, true).applyTo(fTable);
TableColumn column = new TableColumn(fTable, SWT.LEFT);
column.setText("Name");
column.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
sortByName();
}
});
column = new TableColumn(fTable, SWT.LEFT);
column.setText("Location");
column.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
sortByLocation();
}
});
fVMList = new CheckboxTableViewer(fTable);
fVMList.setLabelProvider(new VMLabelProvider());
fVMList.setContentProvider(new JREsContentProvider());
// by default, sort by name
sortByName();
fVMList.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent evt) {
enableButtons();
}
});
fVMList.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getChecked()) {
setCheckedJRE((IGrailsInstall) event.getElement());
} else {
setCheckedJRE(null);
}
}
});
fVMList.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent e) {
if (!fVMList.getSelection().isEmpty()) {
editVM();
}
}
});
fTable.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if (event.character == SWT.DEL && event.stateMask == 0) {
if (fRemoveButton.isEnabled()) {
removeVMs();
}
}
}
});
Composite buttons = SWTFactory.createComposite(parent, font, 1, 1, GridData.VERTICAL_ALIGN_BEGINNING, 0, 0);
fAddButton = SWTFactory.createPushButton(buttons, "Add...", null);
fAddButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event evt) {
addVM();
}
});
fEditButton = SWTFactory.createPushButton(buttons, "Edit...", null);
fEditButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event evt) {
editVM();
}
});
fRemoveButton = SWTFactory.createPushButton(buttons, "Remove...", null);
fRemoveButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event evt) {
removeVMs();
}
});
SWTFactory.createVerticalSpacer(parent, 1);
fillWithWorkspaceJREs();
enableButtons();
fAddButton.setEnabled(JavaRuntime.getVMInstallTypes().length > 0);
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project org.eclipse.rap by eclipse-rap.
the class TestCheckboxTree method createViewer.
public Viewer createViewer(Composite parent) {
CheckboxTreeViewer viewer = new CheckboxTreeViewer(parent);
viewer.setContentProvider(new TestModelContentProvider());
viewer.setLabelProvider(new TestLabelProvider());
viewer.addTreeListener(new ITreeViewerListener() {
public void treeExpanded(TreeExpansionEvent e) {
handleTreeExpanded((TestElement) e.getElement());
}
public void treeCollapsed(TreeExpansionEvent e) {
}
});
viewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent e) {
checkChildren((TestElement) e.getElement(), e.getChecked());
}
});
fCheckboxViewer = viewer;
fViewer = viewer;
return viewer;
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project org.eclipse.rap by eclipse-rap.
the class CustomizePerspectiveDialog method createActionSetAvailabilityPage.
private Composite createActionSetAvailabilityPage(Composite parent) {
GridData data;
Composite actionSetsComposite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
actionSetsComposite.setLayout(layout);
// Select... label
Label label = new Label(actionSetsComposite, SWT.WRAP);
label.setText(NLS.bind(WorkbenchMessages.get().ActionSetSelection_selectActionSetsLabel, perspective.getDesc().getLabel()));
data = new GridData(SWT.FILL, SWT.CENTER, true, false);
label.setLayoutData(data);
Label sep = new Label(actionSetsComposite, SWT.HORIZONTAL | SWT.SEPARATOR);
sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
SashForm sashComposite = new SashForm(actionSetsComposite, SWT.HORIZONTAL);
data = new GridData(SWT.FILL, SWT.FILL, true, true);
sashComposite.setLayoutData(data);
// Action Set List Composite
Composite actionSetGroup = new Composite(sashComposite, SWT.NONE);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
actionSetGroup.setLayout(layout);
actionSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
label = new Label(actionSetGroup, SWT.WRAP);
label.setText(WorkbenchMessages.get().ActionSetSelection_availableActionSets);
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
final CheckboxTableViewer actionSetsViewer = CheckboxTableViewer.newCheckList(actionSetGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
actionSetAvailabilityTable = actionSetsViewer;
actionSetsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
actionSetsViewer.setLabelProvider(new LabelProvider());
actionSetsViewer.setContentProvider(new ArrayContentProvider());
actionSetsViewer.setComparator(new WorkbenchViewerComparator());
actionSetsViewer.setCheckStateProvider(new ICheckStateProvider() {
public boolean isChecked(Object element) {
return ((ActionSet) element).isActive();
}
public boolean isGrayed(Object element) {
return false;
}
});
actionSetsViewer.setInput(actionSets.toArray());
Table table = actionSetsViewer.getTable();
// RAP [bm] ToolTip
// new TableToolTip(table);
final ActionSet[] selectedActionSet = { null };
// Filter to show only branches necessary for the selected action set.
final ViewerFilter setFilter = new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (selectedActionSet[0] == null)
return false;
return includeInSetStructure((DisplayItem) element, selectedActionSet[0]);
}
};
// Updates the check state of action sets
actionSetsViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
final ActionSet actionSet = (ActionSet) event.getElement();
if (event.getChecked()) {
actionSet.setActive(true);
for (Iterator i = actionSet.contributionItems.iterator(); i.hasNext(); ) {
DisplayItem item = (DisplayItem) i.next();
item.setCheckState(true);
}
} else {
actionSet.setActive(false);
}
}
});
// Menu and toolbar composite
Composite actionGroup = new Composite(sashComposite, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = true;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.horizontalSpacing = 0;
actionGroup.setLayout(layout);
actionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Composite menubarGroup = new Composite(actionGroup, SWT.NONE);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
menubarGroup.setLayout(layout);
menubarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
label = new Label(menubarGroup, SWT.WRAP);
label.setText(WorkbenchMessages.get().ActionSetSelection_menubarActions);
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
final TreeViewer actionSetMenuViewer = new TreeViewer(menubarGroup);
actionSetMenuViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
actionSetMenuViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
actionSetMenuViewer.setUseHashlookup(true);
actionSetMenuViewer.setContentProvider(TreeManager.getTreeContentProvider());
actionSetMenuViewer.setLabelProvider(TreeManager.getLabelProvider());
actionSetMenuViewer.addFilter(setFilter);
actionSetMenuViewer.setInput(menuItems);
Tree tree = actionSetMenuViewer.getTree();
// RAP [bm] ToolTip
// new ItemDetailToolTip(actionSetMenuViewer, tree, false, true, setFilter);
Composite toolbarGroup = new Composite(actionGroup, SWT.NONE);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
toolbarGroup.setLayout(layout);
toolbarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
label = new Label(toolbarGroup, SWT.WRAP);
label.setText(WorkbenchMessages.get().ActionSetSelection_toolbarActions);
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
final TreeViewer actionSetToolbarViewer = new TreeViewer(toolbarGroup);
actionSetToolbarViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
actionSetToolbarViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
actionSetToolbarViewer.setContentProvider(TreeManager.getTreeContentProvider());
actionSetToolbarViewer.setLabelProvider(TreeManager.getLabelProvider());
actionSetToolbarViewer.addFilter(setFilter);
actionSetToolbarViewer.setInput(toolBarItems);
tree = actionSetToolbarViewer.getTree();
// RAP [bm] ToolTip
// new ItemDetailToolTip(actionSetToolbarViewer, tree, false, true, setFilter);
// Updates the menu item and toolbar items tree viewers when the
// selection changes
actionSetsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
selectedActionSet[0] = (ActionSet) ((IStructuredSelection) event.getSelection()).getFirstElement();
actionSetMenuViewer.setInput(menuItems);
actionSetToolbarViewer.setInput(toolBarItems);
}
});
sashComposite.setWeights(new int[] { 30, 70 });
return actionSetsComposite;
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project org.eclipse.rap by eclipse-rap.
the class DecoratorsPreferencePage method createDecoratorsArea.
/**
* Creates the widgets for the list of decorators.
*/
private void createDecoratorsArea(Composite mainComposite) {
Font mainFont = mainComposite.getFont();
Composite decoratorsComposite = new Composite(mainComposite, SWT.NONE);
decoratorsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout decoratorsLayout = new GridLayout();
decoratorsLayout.marginWidth = 0;
decoratorsLayout.marginHeight = 0;
decoratorsComposite.setLayout(decoratorsLayout);
decoratorsComposite.setFont(mainFont);
Label decoratorsLabel = new Label(decoratorsComposite, SWT.NONE);
decoratorsLabel.setText(WorkbenchMessages.get().DecoratorsPreferencePage_decoratorsLabel);
decoratorsLabel.setFont(mainFont);
// Checkbox table viewer of decorators
checkboxViewer = CheckboxTableViewer.newCheckList(decoratorsComposite, SWT.SINGLE | SWT.TOP | SWT.BORDER);
checkboxViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
checkboxViewer.getTable().setFont(decoratorsComposite.getFont());
checkboxViewer.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
return ((DecoratorDefinition) element).getName();
}
});
checkboxViewer.getTable().setFont(mainFont);
checkboxViewer.setContentProvider(new IStructuredContentProvider() {
private final Comparator comparer = new Comparator() {
private Collator collator = Collator.getInstance();
public int compare(Object arg0, Object arg1) {
String s1 = ((DecoratorDefinition) arg0).getName();
String s2 = ((DecoratorDefinition) arg1).getName();
return collator.compare(s1, s2);
}
};
public void dispose() {
// Nothing to do on dispose
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getElements(Object inputElement) {
// Make an entry for each decorator definition
Object[] elements = (Object[]) inputElement;
Object[] results = new Object[elements.length];
System.arraycopy(elements, 0, results, 0, elements.length);
Collections.sort(Arrays.asList(results), comparer);
return results;
}
});
checkboxViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
DecoratorDefinition definition = (DecoratorDefinition) sel.getFirstElement();
if (definition == null) {
clearDescription();
} else {
showDescription(definition);
}
}
}
});
checkboxViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
checkboxViewer.setSelection(new StructuredSelection(event.getElement()));
}
});
}
Aggregations