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);
}
}
Aggregations