use of org.eclipse.jface.viewers.CheckStateChangedEvent in project hale by halestudio.
the class EditMappableTypesPage method createControl.
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
parent.setLayout(new GridLayout());
// create filtered tree
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true) {
@Override
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
return new CheckboxTreeViewer(parent, style);
}
};
// configure viewer
viewer = (CheckboxTreeViewer) tree.getViewer();
contentProvider = new NSTypeTreeContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setComparator(new DefinitionComparator());
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object doubleClicked = selection.getFirstElement();
if (doubleClicked instanceof String)
viewer.setExpandedState(doubleClicked, !viewer.getExpandedState(doubleClicked));
else {
boolean newState = !checkStateProvider.isChecked(doubleClicked);
viewer.setChecked(doubleClicked, newState);
checkStateOfTypeChanged((TypeDefinition) doubleClicked, newState);
}
}
});
viewer.setLabelProvider(definitionLabels);
// because elements filtered by FilteredTree lose their checked state:
checkStateProvider = new ICheckStateProvider() {
@Override
public boolean isGrayed(Object element) {
if (element instanceof String) {
Object[] children = contentProvider.getChildren(element);
boolean containsChecked = false;
boolean containsUnchecked = false;
for (Object child : children) {
if (isChecked(child))
containsChecked = true;
else
containsUnchecked = true;
if (containsChecked && containsUnchecked)
return true;
}
}
return false;
}
@Override
public boolean isChecked(Object element) {
if (element instanceof String) {
for (Object child : contentProvider.getChildren(element)) if (isChecked(child))
return true;
return false;
}
return ((TypeDefinition) element).getConstraint(MappingRelevantFlag.class).isEnabled() != changedTypes.contains(element);
}
};
viewer.setCheckStateProvider(checkStateProvider);
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getElement() instanceof String) {
// update children
viewer.setGrayed(event.getElement(), false);
for (Object child : contentProvider.getChildren(event.getElement())) {
// if (mappedTypeFilter.select(viewer, event.getElement(), child)) {
if (checkStateProvider.isChecked(child) != event.getChecked()) {
viewer.setChecked(child, event.getChecked());
checkStateOfTypeChanged((TypeDefinition) child, event.getChecked());
}
// }
}
viewer.setGrayed(event.getElement(), checkStateProvider.isGrayed(event.getElement()));
// only two levels, no need to update any parents or
// children's children
} else {
// if (mappedTypeFilter.select(viewer, null, event.getElement()))
checkStateOfTypeChanged((TypeDefinition) event.getElement(), event.getChecked());
// else if (!event.getChecked())
// viewer.setChecked(event.getElement(), true);
}
}
});
// // filter types which are used in the current alignment
// viewer.addFilter(mappedTypeFilter);
// set input to all types in the given index
viewer.setInput(typeIndex.getTypes());
// expand all except XMLSchema
viewer.expandAll();
viewer.setExpandedState("http://www.w3.org/2001/XMLSchema", false);
// set control
setControl(viewer.getControl());
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project eclipse.platform.text by eclipse.
the class MatchFilterSelectionDialog method createMatchFilterControls.
private void createMatchFilterControls(Composite parent) {
// Create list viewer
Label l = new Label(parent, SWT.NONE);
l.setFont(parent.getFont());
l.setText(SearchMessages.MatchFilterSelectionDialog_filter_description);
Table table = new Table(parent, SWT.CHECK | SWT.BORDER);
table.setFont(parent.getFont());
fListViewer = new CheckboxTableViewer(table);
GridData data = new GridData(GridData.FILL_BOTH);
data.minimumHeight = convertHeightInCharsToPixels(8);
table.setLayoutData(data);
class ListenerAndLabelProvider extends LabelProvider implements ISelectionChangedListener, ICheckStateListener {
@Override
public void selectionChanged(SelectionChangedEvent event) {
performFilterListSelectionChanged();
}
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
performFilterListCheckStateChanged();
}
@Override
public String getText(Object element) {
return ((MatchFilter) element).getName();
}
}
ListenerAndLabelProvider listenerAndLP = new ListenerAndLabelProvider();
fListViewer.setLabelProvider(listenerAndLP);
fListViewer.setContentProvider(new ArrayContentProvider());
fListViewer.addSelectionChangedListener(listenerAndLP);
fListViewer.addCheckStateListener(listenerAndLP);
fListViewer.setInput(fAllFilters);
fListViewer.setCheckedElements(fEnabledFilters);
l = new Label(parent, SWT.NONE);
l.setFont(parent.getFont());
l.setText(SearchMessages.MatchFilterSelectionDialog_description_label);
fDescription = new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
fDescription.setFont(parent.getFont());
data = new GridData(GridData.FILL_HORIZONTAL);
data.heightHint = convertHeightInCharsToPixels(3);
fDescription.setLayoutData(data);
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project eclipse.platform.text by eclipse.
the class TemplatePreferencePage method createContents.
@Override
protected Control createContents(Composite ancestor) {
Composite parent = new Composite(ancestor, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
parent.setLayout(layout);
Composite innerParent = new Composite(parent, SWT.NONE);
GridLayout innerLayout = new GridLayout();
innerLayout.numColumns = 2;
innerLayout.marginHeight = 0;
innerLayout.marginWidth = 0;
innerParent.setLayout(innerLayout);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
innerParent.setLayoutData(gd);
Composite tableComposite = new Composite(innerParent, SWT.NONE);
GridData data = new GridData(GridData.FILL_BOTH);
data.widthHint = 360;
data.heightHint = convertHeightInCharsToPixels(10);
tableComposite.setLayoutData(data);
ColumnLayout columnLayout = new ColumnLayout();
tableComposite.setLayout(columnLayout);
Table table = new Table(tableComposite, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
table.setHeaderVisible(true);
table.setLinesVisible(true);
GC gc = new GC(getShell());
gc.setFont(JFaceResources.getDialogFont());
TemplateViewerComparator viewerComparator = new TemplateViewerComparator();
TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText(TemplatesMessages.TemplatePreferencePage_column_name);
int minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_name);
columnLayout.addColumnData(new ColumnWeightData(2, minWidth, true));
column1.addSelectionListener(new TemplateColumnSelectionAdapter(column1, 0, viewerComparator));
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText(TemplatesMessages.TemplatePreferencePage_column_context);
minWidth = computeMinimumContextColumnWidth(gc);
columnLayout.addColumnData(new ColumnWeightData(1, minWidth, true));
column2.addSelectionListener(new TemplateColumnSelectionAdapter(column2, 1, viewerComparator));
TableColumn column3 = new TableColumn(table, SWT.NONE);
column3.setText(TemplatesMessages.TemplatePreferencePage_column_description);
minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_description);
columnLayout.addColumnData(new ColumnWeightData(3, minWidth, true));
column3.addSelectionListener(new TemplateColumnSelectionAdapter(column3, 2, viewerComparator));
TableColumn column4 = new TableColumn(table, SWT.NONE);
column4.setAlignment(SWT.CENTER);
column4.setText(TemplatesMessages.TemplatePreferencePage_column_autoinsert);
minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_autoinsert);
minWidth = Math.max(minWidth, computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_on));
columnLayout.addColumnData(new ColumnPixelData(minWidth, false, false));
column4.addSelectionListener(new TemplateColumnSelectionAdapter(column4, 3, viewerComparator));
gc.dispose();
fTableViewer = new CheckboxTableViewer(table);
fTableViewer.setLabelProvider(new TemplateLabelProvider());
fTableViewer.setContentProvider(new TemplateContentProvider());
fTableViewer.setComparator(viewerComparator);
// Specify default sorting
table.setSortColumn(column1);
table.setSortDirection(viewerComparator.getDirection());
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent e) {
edit();
}
});
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent e) {
selectionChanged1();
}
});
fTableViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
TemplatePersistenceData d = (TemplatePersistenceData) event.getElement();
d.setEnabled(event.getChecked());
}
});
BidiUtils.applyTextDirection(fTableViewer.getControl(), BidiUtils.BTD_DEFAULT);
Composite buttons = new Composite(innerParent, SWT.NONE);
buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
buttons.setLayout(layout);
fAddButton = new Button(buttons, SWT.PUSH);
fAddButton.setText(TemplatesMessages.TemplatePreferencePage_new);
fAddButton.setLayoutData(getButtonGridData(fAddButton));
fAddButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
add();
}
});
fEditButton = new Button(buttons, SWT.PUSH);
fEditButton.setText(TemplatesMessages.TemplatePreferencePage_edit);
fEditButton.setLayoutData(getButtonGridData(fEditButton));
fEditButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
edit();
}
});
fRemoveButton = new Button(buttons, SWT.PUSH);
fRemoveButton.setText(TemplatesMessages.TemplatePreferencePage_remove);
fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton));
fRemoveButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
remove();
}
});
createSeparator(buttons);
fRestoreButton = new Button(buttons, SWT.PUSH);
fRestoreButton.setText(TemplatesMessages.TemplatePreferencePage_restore);
fRestoreButton.setLayoutData(getButtonGridData(fRestoreButton));
fRestoreButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
restoreDeleted();
}
});
fRevertButton = new Button(buttons, SWT.PUSH);
fRevertButton.setText(TemplatesMessages.TemplatePreferencePage_revert);
fRevertButton.setLayoutData(getButtonGridData(fRevertButton));
fRevertButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
revert();
}
});
createSeparator(buttons);
fImportButton = new Button(buttons, SWT.PUSH);
fImportButton.setText(TemplatesMessages.TemplatePreferencePage_import);
fImportButton.setLayoutData(getButtonGridData(fImportButton));
fImportButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
import_();
}
});
fExportButton = new Button(buttons, SWT.PUSH);
fExportButton.setText(TemplatesMessages.TemplatePreferencePage_export);
fExportButton.setLayoutData(getButtonGridData(fExportButton));
fExportButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
export();
}
});
fPatternViewer = doCreateViewer(parent);
if (isShowFormatterSetting()) {
fFormatButton = new Button(parent, SWT.CHECK);
fFormatButton.setText(TemplatesMessages.TemplatePreferencePage_use_code_formatter);
GridData gd1 = new GridData();
gd1.horizontalSpan = 2;
fFormatButton.setLayoutData(gd1);
fFormatButton.setSelection(getPreferenceStore().getBoolean(getFormatterPreferenceKey()));
}
fTableViewer.setInput(fTemplateStore);
fTableViewer.setAllChecked(false);
fTableViewer.setCheckedElements(getEnabledTemplates());
updateButtons();
Dialog.applyDialogFont(parent);
innerParent.layout();
return parent;
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project eclipse.platform.text by eclipse.
the class SelectResourcesDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
Label label = new Label(composite, SWT.LEFT);
label.setText(fInstruction);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fResourceGroup = new SelectResourcesBlock(composite, ResourcesPlugin.getWorkspace().getRoot(), getResourceProvider(IResource.FOLDER | IResource.PROJECT), WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), getResourceProvider(IResource.FILE), WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), SWT.NONE, useHeightHint(parent));
fResourceGroup.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
updateSelectionCount();
}
});
fCountIndication = new Label(composite, SWT.LEFT);
fCountIndication.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
createSelectionButtonGroup(composite);
setInitialSelection();
return composite;
}
use of org.eclipse.jface.viewers.CheckStateChangedEvent in project erlide_eclipse by erlang.
the class ErlangWizardResourceImportPage method createFileSelectionGroup.
/**
* Create the import source selection widget
*/
protected void createFileSelectionGroup(final Composite parent) {
// Just create with a dummy root.
selectionGroup = new ResourceTreeAndListGroup(parent, // $NON-NLS-1$
new FileSystemElement("Dummy", null, true), getFolderProvider(), new WorkbenchLabelProvider(), getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, DialogUtil.inRegularFontMode(parent));
final ICheckStateListener listener = new ICheckStateListener() {
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
updateWidgetEnablements();
}
};
final WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
selectionGroup.setTreeComparator(comparator);
selectionGroup.setListComparator(comparator);
selectionGroup.addCheckStateListener(listener);
}
Aggregations