use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ConfigurationPageExtension method getConfigurationPages.
/**
* Get the configuration pages registered for the given I/O provider
* descriptors
*
* @param
* <P>
* the {@link IOProvider} type used in the wizard
*
* @param descriptors the provider descriptors
* @return the configuration pages in a multimap where the corresponding
* provider identifier is mapped to the configuration page, one page
* (the same instance) might be mapped for multiple identifiers
*/
@SuppressWarnings("unchecked")
public <P extends IOProvider> ListMultimap<String, AbstractConfigurationPage<? extends P, ? extends IOWizard<P>>> getConfigurationPages(Iterable<IOProviderDescriptor> descriptors) {
// collect provider IDs
final Set<String> providerIds = new HashSet<String>();
for (IOProviderDescriptor descriptor : descriptors) {
providerIds.add(descriptor.getIdentifier());
}
// get all factories that support at least one of the providers
List<ConfigurationPageFactory> factories = getFactories(new FactoryFilter<AbstractConfigurationPage<?, ?>, ConfigurationPageFactory>() {
@Override
public boolean acceptFactory(ConfigurationPageFactory factory) {
Set<String> supported = new HashSet<String>(factory.getSupportedProviderIDs());
supported.retainAll(providerIds);
return !supported.isEmpty();
}
@Override
public boolean acceptCollection(ExtensionObjectFactoryCollection<AbstractConfigurationPage<?, ?>, ConfigurationPageFactory> collection) {
return false;
}
});
ListMultimap<String, AbstractConfigurationPage<? extends P, ? extends IOWizard<P>>> result = ArrayListMultimap.create();
// add pages to result map
for (ConfigurationPageFactory factory : factories) {
AbstractConfigurationPage<? extends P, ? extends IOWizard<P>> page = null;
try {
page = (AbstractConfigurationPage<? extends P, ? extends IOWizard<P>>) factory.createExtensionObject();
} catch (Exception e) {
log.error("Error creating configuration page " + factory.getTypeName(), e);
break;
}
if (page != null) {
for (String providerId : factory.getSupportedProviderIDs()) {
if (providerIds.contains(providerId)) {
result.put(providerId, page);
}
}
}
}
return result;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class FileValidateTarget method updateState.
/**
* @see eu.esdihumboldt.hale.ui.io.target.FileTarget#updateState()
*/
@Override
protected void updateState() {
if (addValidatorButton != null) {
IContentType contentType = getWizard().getContentType();
Collection<IOProviderDescriptor> factories = new ArrayList<>();
if (contentType != null) {
factories.addAll(HaleIO.getProviderFactories(InstanceValidator.class));
factories = HaleIO.filterFactories(factories, contentType);
}
if (factories.isEmpty()) {
addValidatorButton.setEnabled(false);
} else {
addValidatorButton.setEnabled(true);
}
}
if (validatorsTableViewer != null) {
validatorsTableViewer.setInput(validators);
}
checkValidatorConfigurations();
super.updateState();
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ValidatorSelectionDialog method getSelection.
/**
* @return the current selection
*/
public IOProviderDescriptor getSelection() {
if (selection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) selection;
Object element = sel.getFirstElement();
if (element instanceof IOProviderDescriptor) {
return (IOProviderDescriptor) element;
}
}
return null;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class AbstractProjectDetailsPage method createContent.
/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(Composite page) {
page.setLayout(new GridLayout(2, false));
// name
name = new StringFieldEditor("name", "Project name:", page);
name.setEmptyStringAllowed(false);
name.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
name.setErrorMessage("The project name must be specified.");
name.setPage(this);
// author
author = new StringFieldEditor("author", "Project author:", page);
author.setEmptyStringAllowed(false);
author.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
author.setPage(this);
// description
Label descLabel = new Label(page, SWT.NONE);
descLabel.setText("Description:");
descLabel.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).create());
description = new Text(page, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
description.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(500, SWT.DEFAULT).create());
// listen for state changes on field editors
IPropertyChangeListener stateListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(StringFieldEditor.IS_VALID)) {
updateState();
}
}
};
name.setPropertyChangeListener(stateListener);
author.setPropertyChangeListener(stateListener);
// listen for provider changes
getWizard().addIOWizardListener(new IOWizardListener<P, E>() {
@Override
public void providerDescriptorChanged(IOProviderDescriptor providerFactory) {
// update fields as the provider will have changed
updateFields();
}
@Override
public void contentTypeChanged(IContentType contentType) {
// ignore
}
});
updateState();
updateFields();
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class SaveProjectWizard method getFactories.
@Override
public List<IOProviderDescriptor> getFactories() {
// constructors before restrictToContentTypes is initalized
if (restrictToContentTypes == null || restrictToContentTypes.isEmpty()) {
return super.getFactories();
}
/*
* Remove all providers that do not support the content type the export
* is restricted to.
*/
List<IOProviderDescriptor> factories = new ArrayList<>(super.getFactories());
Iterator<IOProviderDescriptor> it = factories.iterator();
while (it.hasNext()) {
IOProviderDescriptor pd = it.next();
if (pd.getSupportedTypes() == null || !restrictToContentTypes.stream().anyMatch(ct -> pd.getSupportedTypes().contains(ct))) {
it.remove();
}
}
return factories;
}
Aggregations