Search in sources :

Example 31 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class ExportWizard method setPreset.

/**
 * Set the given preset.
 *
 * @param preset the preset name
 * @return if the preset was successfully set
 */
public boolean setPreset(String preset) {
    IOConfiguration config = projectService.getExportConfiguration(preset);
    if (config != null) {
        IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(config.getProviderId());
        if (descriptor != null) {
            descriptor = new PresetDescriptor(descriptor, preset);
            setProviderFactory(descriptor);
            getProvider().loadConfiguration(config.getProviderConfiguration());
            setContentType(getProvider().getContentType());
            return true;
        }
    }
    setProviderFactory(null);
    return false;
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)

Example 32 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class ExportWizard method createConfigurationPages.

@Override
protected ListMultimap<String, AbstractConfigurationPage<? extends P, ? extends IOWizard<P>>> createConfigurationPages(Collection<IOProviderDescriptor> factories) {
    ListMultimap<String, AbstractConfigurationPage<? extends P, ? extends IOWizard<P>>> configPages = super.createConfigurationPages(factories);
    ListMultimap<String, AbstractConfigurationPage<? extends P, ? extends IOWizard<P>>> result = ArrayListMultimap.create();
    // append target selection page if applicable
    for (IOProviderDescriptor descr : factories) {
        if (!suppressTargetPage() && descr.getSupportedTypes() != null && !descr.getSupportedTypes().isEmpty()) {
            result.put(descr.getIdentifier(), getSelectTargetPage());
        }
    }
    // append all other configuration pages
    result.putAll(configPages);
    return result;
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) AbstractConfigurationPage(eu.esdihumboldt.hale.ui.io.config.AbstractConfigurationPage)

Example 33 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class ImportSelectSourcePage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    // set content types for file field
    List<IOProviderDescriptor> factories = getWizard().getFactories();
    final Set<IContentType> supportedTypes = new HashSet<IContentType>();
    for (IOProviderDescriptor factory : factories) {
        supportedTypes.addAll(factory.getSupportedTypes());
    }
    // get compatible sources
    List<ImportSourceFactory> availableSources = ImportSourceExtension.getInstance().getFactories(new FactoryFilter<ImportSource<?>, ImportSourceFactory>() {

        @Override
        public boolean acceptFactory(ImportSourceFactory factory) {
            // check provider factory compatibility
            boolean providerMatch = factory.getProviderType().isAssignableFrom(getWizard().getProviderType());
            if (!providerMatch) {
                return false;
            }
            // check content type compatibility
            IContentType ct = factory.getContentType();
            if (ct == null) {
                // any content type supported
                return true;
            } else {
                // stated type must be present
                return supportedTypes.contains(ct);
            }
        }

        @Override
        public boolean acceptCollection(ExtensionObjectFactoryCollection<ImportSource<?>, ImportSourceFactory> collection) {
            return false;
        }
    });
    if (availableSources == null || availableSources.isEmpty()) {
        Label label = new Label(page, SWT.NONE);
        label.setText("No import source available.");
    } else if (availableSources.size() == 1) {
        // add source directly
        createSource(availableSources.iterator().next(), page, supportedTypes);
        setActiveSource(0);
    } else {
        // add tab for each source
        page.setLayout(new FillLayout());
        final TabFolder tabs = new TabFolder(page, SWT.NONE);
        for (ImportSourceFactory sourceFactory : availableSources) {
            TabItem item = new TabItem(tabs, SWT.NONE);
            item.setText(MessageFormat.format("From {0}", sourceFactory.getDisplayName()));
            // image
            URL iconURL = sourceFactory.getIconURL();
            if (iconURL != null) {
                Image image = ImageDescriptor.createFromURL(iconURL).createImage();
                if (image != null) {
                    // remember for disposal
                    images.add(image);
                    item.setImage(image);
                }
            }
            // tooltip
            item.setToolTipText(sourceFactory.getDescription());
            // content
            Composite wrapper = new Composite(tabs, SWT.NONE);
            // for
            wrapper.setLayout(GridLayoutFactory.swtDefaults().create());
            // minimum
            // margin
            Composite content = new Composite(wrapper, SWT.NONE);
            content.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
            createSource(sourceFactory, content, supportedTypes);
            item.setControl(wrapper);
        }
        tabs.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                setActiveSource(tabs.getSelectionIndex());
            }
        });
        setActiveSource(0);
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) TabFolder(org.eclipse.swt.widgets.TabFolder) IContentType(org.eclipse.core.runtime.content.IContentType) FillLayout(org.eclipse.swt.layout.FillLayout) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) ImportSourceFactory(eu.esdihumboldt.hale.ui.io.source.internal.ImportSourceFactory) TabItem(org.eclipse.swt.widgets.TabItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HashSet(java.util.HashSet)

Example 34 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class FileValidateTarget method createControls.

@Override
public void createControls(Composite parent) {
    super.createControls(parent);
    // page has a 3-column grid layout
    Group validatorGroup = new Group(parent, SWT.NONE);
    validatorGroup.setText("Validation");
    validatorGroup.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).span(3, 1).indent(8, 10).create());
    validatorGroup.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).margins(10, 8).create());
    // Add project validator by default
    IOProviderDescriptor pvDescriptor = HaleIO.findIOProviderFactory(IOProvider.class, getWizard().getContentType(), ProjectValidator.PROVIDER_ID);
    if (pvDescriptor != null) {
        ProjectValidator projectValidator = new ProjectValidator();
        List<? extends Locatable> schemas = getWizard().getProvider().getValidationSchemas();
        projectValidator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
        ValidatorEntry entry = new ValidatorEntry(projectValidator, pvDescriptor);
        validators.add(entry);
        getWizard().addValidator(projectValidator);
    }
    // viewer with validator list
    Composite tableContainer = new Composite(validatorGroup, SWT.NONE);
    tableContainer.setLayoutData(GridDataFactory.swtDefaults().span(3, 1).minSize(100, 100).align(SWT.FILL, SWT.FILL).grab(true, true).create());
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    validatorsTableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    validatorsTableViewer.getTable().setLinesVisible(true);
    validatorsTableViewer.getTable().setHeaderVisible(true);
    validatorsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    validatorsTableViewer.setInput(validators);
    TableViewerColumn typeColumn = new TableViewerColumn(validatorsTableViewer, SWT.NONE);
    layout.setColumnData(typeColumn.getColumn(), new ColumnWeightData(4));
    typeColumn.getColumn().setText("Validator");
    typeColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            return validator.getDescriptor().getDisplayName();
        }

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
         */
        @Override
        public Image getImage(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            if (validator.getStatusMessage() != null && !validator.getStatusMessage().isEmpty()) {
                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR);
            }
            return null;
        }
    });
    TableViewerColumn errorColumn = new TableViewerColumn(validatorsTableViewer, SWT.NONE);
    layout.setColumnData(errorColumn.getColumn(), new ColumnWeightData(3));
    errorColumn.getColumn().setText("Status");
    errorColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            String message = validator.getStatusMessage();
            if (message == null || message.trim().isEmpty()) {
                message = "OK";
            }
            return message;
        }
    });
    validatorsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateWizard(getSelectedValidator(event.getSelection()));
        }
    });
    // Selection dialog for adding validators to the list
    final ValidatorSelectionDialog validatorSelectionDialog = new ValidatorSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
    addValidatorButton = new Button(validatorGroup, SWT.PUSH);
    addValidatorButton.setText("Add validator...");
    addValidatorButton.setEnabled(false);
    addValidatorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            validatorSelectionDialog.create();
            validatorSelectionDialog.setContentType(getWizard().getContentType());
            if (validatorSelectionDialog.open() == Dialog.OK) {
                IOProviderDescriptor selection = validatorSelectionDialog.getSelection();
                addValidator(selection);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    // Remove button
    removeValidatorButton = new Button(validatorGroup, SWT.PUSH);
    removeValidatorButton.setText("Remove validator...");
    removeValidatorButton.setEnabled(false);
    removeValidatorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ValidatorEntry selection = getSelectedValidator();
            getWizard().removeValidator(selection.getValidator());
            validators.remove(selection);
            updateWizard(getSelectedValidator());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    // Configure button
    configureValidatorButton = new Button(validatorGroup, SWT.PUSH);
    configureValidatorButton.setText("Configure validator...");
    configureValidatorButton.setEnabled(false);
    getWizard().addIOWizardListener(this);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ProjectValidator(eu.esdihumboldt.hale.io.validation.ProjectValidator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 35 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class InstanceExportWizard method getFactories.

/**
 * @see IOWizard#getFactories()
 */
@Override
public List<IOProviderDescriptor> getFactories() {
    if (cachedFactories != null) {
        return cachedFactories;
    }
    List<IOProviderDescriptor> providers = super.getFactories();
    IOAdvisor<InstanceWriter> advisor = getAdvisor();
    if (advisor == null) {
        return providers;
    }
    List<IOProviderDescriptor> result = new ArrayList<IOProviderDescriptor>();
    for (IOProviderDescriptor providerFactory : providers) {
        // create a dummy provider
        InstanceWriter provider;
        try {
            provider = (InstanceWriter) providerFactory.createExtensionObject();
        } catch (Exception e) {
            log.error("Error creating an instance writer: " + providerFactory.getIdentifier(), e);
            // ignore this provider as it cannot be created
            continue;
        }
        // assign the basic configuration
        advisor.prepareProvider(provider);
        advisor.updateConfiguration(provider);
        // and check the compatibility
        try {
            provider.checkCompatibility();
            result.add(providerFactory);
        } catch (IOProviderConfigurationException e) {
        // ignore this export provider, it is not compatible
        }
    }
    cachedFactories = result;
    return cachedFactories;
}
Also used : IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) InstanceWriter(eu.esdihumboldt.hale.common.instance.io.InstanceWriter) ArrayList(java.util.ArrayList) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)

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