use of eu.esdihumboldt.hale.ui.service.schema.util.NSTypeTreeContentProvider 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());
}
Aggregations