Search in sources :

Example 1 with LookupService

use of eu.esdihumboldt.hale.common.lookup.LookupService in project hale by halestudio.

the class ClassificationMappingParameterPage method createFromFileTabControl.

private Control createFromFileTabControl(Composite tabParent) {
    // Parent composite for fromFileTab
    Composite item2Content = new Composite(tabParent, SWT.NONE);
    item2Content.setLayout(new GridLayout());
    // Label to descripe what the user should do
    Label l = new Label(item2Content, SWT.NONE);
    l.setText("Select the project lookup table resource you want to use for the classification:");
    // Get the Lookuptable Service
    final LookupService lookupService = HaleUI.getServiceProvider().getService(LookupService.class);
    // Composite for comboViewerComposite and Button
    Composite parent = new Composite(item2Content, SWT.NONE);
    parent.setLayout(new GridLayout(2, false));
    parent.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    // Description Label
    description = new Label(item2Content, SWT.WRAP);
    description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    description.setText("");
    description.setVisible(false);
    // label with warning message
    Composite warnComp = new Composite(item2Content, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(warnComp);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warnComp);
    Label warnImage = new Label(warnComp, SWT.NONE);
    warnImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(warnImage);
    Label warn = new Label(warnComp, SWT.WRAP);
    warn.setText("Classifications from a file resource will not function in another project where the alignment with the classification is imported or used as a base alignment.\n" + "If unsure, use the 'Explicit' mode instead and use the option to load the classification from a file.");
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(300, SWT.DEFAULT).applyTo(warn);
    // Composite for ComboViewer
    Composite viewerComposite = new Composite(parent, SWT.NONE);
    viewerComposite.setLayout(new FillLayout());
    GridData layoutData = new GridData(SWT.FILL, SWT.NONE, true, false);
    viewerComposite.setLayoutData(GridDataFactory.copyData(layoutData));
    // ComboViewer
    lookupTableComboViewer = new ComboViewer(viewerComposite, SWT.READ_ONLY);
    lookupTableComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    lookupTableComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                return lookupService.getTable((String) element).getName();
            }
            return null;
        }
    });
    lookupTableComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // Show the description for the selected lookupTable
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            String desc = lookupService.getTable(selection.getFirstElement().toString()).getDescription();
            if (desc != null) {
                description.setText("Description: " + desc);
            } else {
                description.setText("");
            }
            if (!description.isVisible()) {
                description.setVisible(true);
            }
        }
    });
    lookupTableComboViewer.setInput(lookupService.getTableIDs());
    if (selectedLookupTableID != null) {
        lookupTableComboViewer.setSelection(new StructuredSelection(selectedLookupTableID), true);
    }
    // Button to load a lookupTable if no one is loaded
    final Button browseButton = new Button(parent, SWT.PUSH);
    browseButton.setText("Add...");
    browseButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IOWizardAction action = new IOWizardAction("eu.esdihumboldt.hale.lookup.import");
            action.run();
            action.dispose();
            // Refresh the viewer
            lookupTableComboViewer.setInput(lookupService.getTableIDs());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing to do here
        }
    });
    return item2Content;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) LookupService(eu.esdihumboldt.hale.common.lookup.LookupService) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) IOWizardAction(eu.esdihumboldt.hale.ui.io.action.IOWizardAction) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with LookupService

use of eu.esdihumboldt.hale.common.lookup.LookupService in project hale by halestudio.

the class ClassificationMappingUtil method getClassificationLookup.

/**
 * Get the classification lookup table from the transformation parameters.
 *
 * @param parameters the transformation parameters
 * @param serviceProvider service provider in case a lookup table has to be
 *            retrieved through a service
 * @return the classification lookup table
 */
public static LookupTable getClassificationLookup(Multimap<String, ? extends Value> parameters, ServiceProvider serviceProvider) {
    try {
        if (!(parameters.get(PARAMETER_LOOKUPTABLE).isEmpty())) {
            Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE);
            return tmpMap.iterator().next().as(LookupTable.class);
        }
        if (!(parameters.get(PARAMETER_LOOKUPTABLE_ID).isEmpty())) {
            LookupService lookupServiceImpl = serviceProvider.getService(LookupService.class);
            Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE_ID);
            LookupTableInfo lookupTableInfo = lookupServiceImpl.getTable(tmpMap.iterator().next().as(String.class));
            return lookupTableInfo.getTable();
        }
    } catch (NullPointerException e) {
        log.error("Service provider not accessible for retrieving lookup table", e);
    }
    // For reason of compatibility we need the following code
    // lookup table in strangely encoded string parameter
    Collection<? extends Value> mappings = parameters.get(PARAMETER_CLASSIFICATIONS);
    try {
        Map<Value, Value> lookupMap = new HashMap<Value, Value>();
        for (Value mapping : mappings) {
            String[] parts = mapping.as(String.class).split(" ");
            if (parts.length > 0) {
                Value target = Value.of(URLDecoder.decode(parts[0], "UTF-8"));
                for (int i = 1; i < parts.length; i++) {
                    lookupMap.put(Value.of(URLDecoder.decode(parts[i], "UTF-8")), target);
                }
            }
        }
        return new LookupTableImpl(lookupMap);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("Failed to decode classification mapping.");
    }
}
Also used : HashMap(java.util.HashMap) LookupTableInfo(eu.esdihumboldt.hale.common.lookup.LookupTableInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LookupService(eu.esdihumboldt.hale.common.lookup.LookupService) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)

Example 3 with LookupService

use of eu.esdihumboldt.hale.common.lookup.LookupService in project hale by halestudio.

the class LookupImportAdvisor method handleResults.

@Override
public void handleResults(LookupTableImport provider) {
    super.handleResults(provider);
    LookupService ls = getService(LookupService.class);
    ls.registerTable(provider.getResourceIdentifier(), provider.getLookupTable());
}
Also used : LookupService(eu.esdihumboldt.hale.common.lookup.LookupService)

Aggregations

LookupService (eu.esdihumboldt.hale.common.lookup.LookupService)3 Value (eu.esdihumboldt.hale.common.core.io.Value)1 LookupTableInfo (eu.esdihumboldt.hale.common.lookup.LookupTableInfo)1 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)1 IOWizardAction (eu.esdihumboldt.hale.ui.io.action.IOWizardAction)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)1 StyledString (org.eclipse.jface.viewers.StyledString)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1