Search in sources :

Example 1 with TypeIndexContentProvider

use of eu.esdihumboldt.hale.ui.common.definition.viewer.TypeIndexContentProvider in project hale by halestudio.

the class DataSetTypeSelectionDialog method setupViewer.

@Override
protected void setupViewer(TreeViewer viewer, Pair<TypeDefinition, DataSet> initialSelection) {
    viewer.setLabelProvider(new DefinitionLabelProvider(viewer) {

        @Override
        public String getText(Object element) {
            if (element instanceof DataSet) {
                switch((DataSet) element) {
                    case TRANSFORMED:
                        return "Transformed";
                    case SOURCE:
                    default:
                        return "Source";
                }
            }
            if (element instanceof Pair) {
                element = ((Pair<?, ?>) element).getFirst();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof DataSet) {
                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
            }
            if (element instanceof Pair) {
                element = ((Pair<?, ?>) element).getFirst();
            }
            return super.getImage(element);
        }
    });
    viewer.setContentProvider(new TypeIndexContentProvider(viewer) {

        @Override
        public Object[] getElements(Object inputElement) {
            return types.keySet().toArray();
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof DataSet) {
                DataSet dataSet = (DataSet) parentElement;
                List<Pair<TypeDefinition, DataSet>> typeList = new ArrayList<Pair<TypeDefinition, DataSet>>();
                for (TypeDefinition type : types.get(dataSet)) {
                    typeList.add(new Pair<TypeDefinition, DataSet>(type, dataSet));
                }
                return typeList.toArray();
            }
            return new Object[] {};
        }

        @Override
        public boolean hasChildren(Object parentElement) {
            return parentElement instanceof DataSet && !types.get((DataSet) parentElement).isEmpty();
        }
    });
    viewer.setAutoExpandLevel(2);
    viewer.setInput(types);
    if (initialSelection != null) {
        viewer.setSelection(new StructuredSelection(initialSelection));
    }
}
Also used : DefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionLabelProvider) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeIndexContentProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.TypeIndexContentProvider) ArrayList(java.util.ArrayList) List(java.util.List) Image(org.eclipse.swt.graphics.Image) Pair(eu.esdihumboldt.util.Pair) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 DefinitionLabelProvider (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionLabelProvider)1 TypeIndexContentProvider (eu.esdihumboldt.hale.ui.common.definition.viewer.TypeIndexContentProvider)1 Pair (eu.esdihumboldt.util.Pair)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Image (org.eclipse.swt.graphics.Image)1