Search in sources :

Example 36 with IOProviderDescriptor

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 37 with IOProviderDescriptor

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

Example 38 with IOProviderDescriptor

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

Example 39 with IOProviderDescriptor

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()));
    }
}
Also used : IOAdvisorFactory(eu.esdihumboldt.hale.common.core.io.extension.IOAdvisorFactory) IOAdvisor(eu.esdihumboldt.hale.common.core.io.IOAdvisor) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 40 with IOProviderDescriptor

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

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