Search in sources :

Example 1 with PropertyPathContentProvider

use of eu.esdihumboldt.hale.ui.common.definition.viewer.PropertyPathContentProvider 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());
    }
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyPathContentProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.PropertyPathContentProvider) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 DefinitionComparator (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator)1 PropertyPathContentProvider (eu.esdihumboldt.hale.ui.common.definition.viewer.PropertyPathContentProvider)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Label (org.eclipse.swt.widgets.Label)1