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;
}
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.");
}
}
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());
}
Aggregations