Search in sources :

Example 6 with IOProviderDescriptor

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOWizard(eu.esdihumboldt.hale.ui.io.IOWizard) HashSet(java.util.HashSet)

Example 7 with IOProviderDescriptor

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();
}
Also used : InstanceValidator(eu.esdihumboldt.hale.common.instance.io.InstanceValidator) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) ArrayList(java.util.ArrayList) IContentType(org.eclipse.core.runtime.content.IContentType)

Example 8 with IOProviderDescriptor

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;
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with IOProviderDescriptor

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();
}
Also used : StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) GridLayout(org.eclipse.swt.layout.GridLayout) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IContentType(org.eclipse.core.runtime.content.IContentType)

Example 10 with IOProviderDescriptor

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;
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) ArrayList(java.util.ArrayList)

Aggregations

IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)40 IContentType (org.eclipse.core.runtime.content.IContentType)17 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)8 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)8 Label (org.eclipse.swt.widgets.Label)7 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 ComboViewer (org.eclipse.jface.viewers.ComboViewer)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)5 ArrayList (java.util.ArrayList)5 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)5 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)4 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)4 InstanceWriter (eu.esdihumboldt.hale.common.instance.io.InstanceWriter)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4