Search in sources :

Example 1 with SchemaPreset

use of eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset in project hale by halestudio.

the class SchemaPresetSelectionDialog method createViewer.

/**
 * @see AbstractViewerSelectionDialog#createViewer(Composite)
 */
@Override
protected TreeViewer createViewer(Composite parent) {
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    tree.getViewer().setComparator(new SchemaPresetComparator());
    // set filter to only accept schema selection (must be set after
    // pattern filter is created)
    setFilters(new ViewerFilter[] { new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof SchemaPreset;
        }
    } });
    return tree.getViewer();
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SchemaPreset(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset) Viewer(org.eclipse.jface.viewers.Viewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Example 2 with SchemaPreset

use of eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset in project hale by halestudio.

the class PresetsSource method createControls.

/**
 * @see ImportSource#createControls(Composite)
 */
@Override
public void createControls(Composite parent) {
    GridLayoutFactory parentLayout = GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false);
    parentLayout.applyTo(parent);
    GridDataFactory labelData = // 
    GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER);
    GridDataFactory controlData = // 
    GridDataFactory.swtDefaults().align(SWT.FILL, // 
    SWT.CENTER).grab(true, false);
    // preset label
    Label label = new Label(parent, SWT.NONE);
    label.setText("Select preset:");
    labelData.applyTo(label);
    // preset selector
    selector = new SchemaPresetSelector(parent);
    selector.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (description != null) {
                SchemaPreset schema = selector.getSelectedObject();
                if (schema != null && schema.getDescription() != null) {
                    description.setText(schema.getDescription());
                } else {
                    description.setText("");
                }
            }
            updateState(true);
        }
    });
    controlData.applyTo(selector.getControl());
    // skipper
    Composite empty = new Composite(parent, SWT.NONE);
    GridDataFactory.swtDefaults().hint(1, 1).applyTo(empty);
    // description label
    description = new Label(parent, SWT.WRAP);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(description);
    // preset label
    label = new Label(parent, SWT.NONE);
    label.setText("Import as");
    labelData.applyTo(label);
    // create provider combo
    ComboViewer providers = createProviders(parent);
    controlData.applyTo(providers.getControl());
    // prevent selector appearing very small
    parent.pack();
    // initial state update
    updateState(true);
}
Also used : GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Composite(org.eclipse.swt.widgets.Composite) SchemaPresetSelector(eu.esdihumboldt.hale.ui.schema.presets.internal.SchemaPresetSelector) SchemaPreset(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 3 with SchemaPreset

use of eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset in project hale by halestudio.

the class SchemaPresetLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    StyledString text = new StyledString();
    if (element instanceof SchemaPreset) {
        SchemaPreset schema = (SchemaPreset) element;
        text.append(schema.getName());
    }
    if (element instanceof SchemaCategory) {
        text.append(((SchemaCategory) element).getName());
    }
    if (element instanceof SchemaPreset) {
        SchemaPreset preset = (SchemaPreset) element;
        String version = preset.getVersion();
        if (version != null) {
            text.append(" " + version, StyledString.COUNTER_STYLER);
        }
        String tag = preset.getTag();
        if (tag != null) {
            text.append(" (" + tag + ")", StyledString.DECORATIONS_STYLER);
        }
    }
    // NoObject.NONE)
    if (element != null && (text.getString() == null || text.getString().isEmpty())) {
        text.append(getText(element));
    }
    cell.setImage(getImage(element));
    cell.setText(text.toString());
    cell.setStyleRanges(text.getStyleRanges());
    super.update(cell);
}
Also used : SchemaPreset(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset) SchemaCategory(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaCategory) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 4 with SchemaPreset

use of eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset in project hale by halestudio.

the class SchemaPresetLabelProvider method getImage.

@Override
public Image getImage(Object element) {
    if (element instanceof SchemaPreset) {
        SchemaPreset schema = (SchemaPreset) element;
        URL iconURL = schema.getIconURL();
        if (iconURL != null) {
            String key = iconURL.toString();
            Image image = urlImages.get(key);
            if (image == null) {
                image = ImageDescriptor.createFromURL(iconURL).createImage();
                urlImages.put(key, image);
            }
            return image;
        }
        return defImage;
    }
    if (element instanceof SchemaCategory) {
        return categoryImage;
    }
    return null;
}
Also used : SchemaPreset(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset) SchemaCategory(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaCategory) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL)

Aggregations

SchemaPreset (eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset)4 SchemaCategory (eu.esdihumboldt.hale.common.schema.presets.extension.SchemaCategory)2 StyledString (org.eclipse.jface.viewers.StyledString)2 SchemaPresetSelector (eu.esdihumboldt.hale.ui.schema.presets.internal.SchemaPresetSelector)1 URL (java.net.URL)1 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)1 GridLayoutFactory (org.eclipse.jface.layout.GridLayoutFactory)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Image (org.eclipse.swt.graphics.Image)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)1 PatternFilter (org.eclipse.ui.dialogs.PatternFilter)1