use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ValidatorSelectionDialog method createDialogArea.
/**
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
composite.setLayoutData(data);
Label label = new Label(composite, SWT.NONE);
label.setText("Please select a validator if you want to validate the exported file");
label.setLayoutData(GridDataFactory.swtDefaults().span(3, 1).align(SWT.BEGINNING, SWT.BEGINNING).create());
validators = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
validators.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
validators.setContentProvider(ArrayContentProvider.getInstance());
validators.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IOProviderDescriptor) {
return ((IOProviderDescriptor) element).getDisplayName();
}
return super.getText(element);
}
});
validators.setInput(input);
validators.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
selection = event.getSelection();
}
});
return composite;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class AbstractProviderSource method createProviders.
/**
* Create the provider selector combo viewer. Once created it can be
* retrieved using {@link #getProviders()}. This should be called in
* {@link #createControls(Composite)}.
*
* @param parent the parent composite
* @return the created combo viewer
*/
protected ComboViewer createProviders(Composite parent) {
// create provider combo
providers = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
providers.setContentProvider(ArrayContentProvider.getInstance());
providers.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IOProviderDescriptor) {
return ((IOProviderDescriptor) element).getDisplayName();
}
return super.getText(element);
}
});
// process selection changes
providers.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
onProviderSelectionChanged(event);
}
});
return providers;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class AbstractProviderSource method updateProvider.
/**
* Update the provider selector when the content type has changed. This is
* based on the content type stored in the source configuration.
*/
protected void updateProvider() {
IContentType contentType = getConfiguration().getContentType();
if (contentType != null) {
IOProviderDescriptor lastSelected = null;
ISelection provSel = providers.getSelection();
if (!provSel.isEmpty() && provSel instanceof IStructuredSelection) {
lastSelected = (IOProviderDescriptor) ((IStructuredSelection) provSel).getFirstElement();
}
List<IOProviderDescriptor> supported = HaleIO.filterFactories(getConfiguration().getFactories(), contentType);
providers.setInput(supported);
if (lastSelected != null && supported.contains(lastSelected)) {
// reuse old selection
providers.setSelection(new StructuredSelection(lastSelected), true);
} else if (!supported.isEmpty()) {
// select first provider
providers.setSelection(new StructuredSelection(supported.get(0)), true);
}
providers.getControl().setEnabled(supported.size() > 1);
} else {
providers.setInput(null);
providers.getControl().setEnabled(false);
}
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ProjectResourcesUtil method executeConfiguration.
/**
* Execute a single I/O configuration with a custom advisor.
*
* @param conf the I/O configuration
* @param customAdvisor the custom advisor to use or <code>null</code>
* @param publishReport if the report should be published
* @param cacheCallback call back that is notified on cache changes for the
* I/O configuration, may be <code>null</code>
*/
public static void executeConfiguration(IOConfiguration conf, IOAdvisor<?> customAdvisor, boolean publishReport, CacheCallback cacheCallback) {
// get provider ...
IOProvider provider = null;
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (descriptor != null) {
try {
provider = descriptor.createExtensionObject();
} catch (Exception e) {
log.error(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} could not be created.", conf.getProviderId()), e);
return;
}
// ... and advisor
final String actionId = conf.getActionId();
IOAdvisor<?> advisor = customAdvisor;
if (advisor == null) {
List<IOAdvisorFactory> advisors = IOAdvisorExtension.getInstance().getFactories(new FactoryFilter<IOAdvisor<?>, IOAdvisorFactory>() {
@Override
public boolean acceptFactory(IOAdvisorFactory factory) {
return factory.getActionID().equals(actionId);
}
@Override
public boolean acceptCollection(ExtensionObjectFactoryCollection<IOAdvisor<?>, IOAdvisorFactory> collection) {
return true;
}
});
if (advisors != null && !advisors.isEmpty()) {
try {
advisor = advisors.get(0).createAdvisor(actionId, HaleUI.getServiceProvider());
} catch (Exception e) {
log.error(MessageFormat.format("Could not execute I/O configuration, advisor with ID {0} could not be created.", advisors.get(0).getIdentifier()), e);
return;
}
}
}
if (advisor != null) {
// configure settings
provider.loadConfiguration(conf.getProviderConfiguration());
if (provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setCache(conf.getCache());
}
// execute provider
executeProvider(provider, advisor, publishReport, cacheCallback);
} else {
log.error(MessageFormat.format("Could not execute I/O configuration, no advisor for action {0} found.", actionId));
}
} else {
log.error(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} not found.", conf.getProviderId()));
}
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ProjectServiceImpl method getExportConfigurationNames.
@Override
public Collection<String> getExportConfigurationNames(Class<? extends IOProvider> providerClass) {
Set<String> result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
for (Entry<String, IOConfiguration> entry : main.getExportConfigurations().entrySet()) {
IOConfiguration conf = entry.getValue();
String providerId = conf.getProviderId();
IOProviderDescriptor descr = IOProviderExtension.getInstance().getFactory(providerId);
if (descr != null && providerClass.isAssignableFrom(descr.getProviderType())) {
result.add(entry.getKey());
}
}
return result;
}
Aggregations