Search in sources :

Example 1 with IOWizard

use of eu.esdihumboldt.hale.ui.io.IOWizard in project hale by halestudio.

the class IOWizardAction method run.

/**
 * @see Action#run()
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void run() {
    try {
        // retrieve action ID
        final String actionId = getFactory().getActionID();
        // find associated advisor
        IOAdvisor<?> advisor = IOAdvisorExtension.getInstance().findAdvisor(actionId, HaleUI.getServiceProvider());
        checkState(advisor != null, "No advisor for action found");
        // create wizard
        IOWizard<?> wizard = getFactory().createExtensionObject();
        // set advisor and action ID
        ((IOWizard) wizard).setAdvisor(advisor, actionId);
        Shell shell = Display.getCurrent().getActiveShell();
        HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
        notifyResult(dialog.open() == Window.OK);
    } catch (Exception e) {
        log.error("Could not launch I/O wizard for advisor " + getFactory().getIdentifier(), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IOWizard(eu.esdihumboldt.hale.ui.io.IOWizard) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 2 with IOWizard

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

Aggregations

IOWizard (eu.esdihumboldt.hale.ui.io.IOWizard)2 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Shell (org.eclipse.swt.widgets.Shell)1