Search in sources :

Example 1 with ImportSourceFactory

use of eu.esdihumboldt.hale.ui.io.source.internal.ImportSourceFactory 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)

Aggregations

IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 ImportSourceFactory (eu.esdihumboldt.hale.ui.io.source.internal.ImportSourceFactory)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 IContentType (org.eclipse.core.runtime.content.IContentType)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 TabFolder (org.eclipse.swt.widgets.TabFolder)1 TabItem (org.eclipse.swt.widgets.TabItem)1