Search in sources :

Example 1 with AddonProperties

use of org.openecard.addon.AddonProperties in project open-ecard by ecsec.

the class ManagementDialog method createAddonPaneFromAddonSpec.

private void createAddonPaneFromAddonSpec(AddonSpecification desc, AddonSelectionModel model, boolean coreAddon) {
    String description = desc.getLocalizedDescription(LANGUAGE_CODE);
    String name = desc.getLocalizedName(LANGUAGE_CODE);
    Image logo;
    if (coreAddon) {
        logo = loadLogo(null, desc.getLogo());
    } else {
        try {
            ClassLoader loader = manager.getRegistry().downloadAddon(desc);
            logo = loadLogo(loader, "META-INF/" + desc.getLogo());
        } catch (AddonException ex) {
            logger.error("Failed to load logo from Add-on bundle.");
            logo = null;
        }
    }
    // setup about panel but just if we don't have a core addon
    String about = desc.getAbout(LANGUAGE_CODE);
    String licenseText = desc.getLicenseText(LANGUAGE_CODE);
    AboutPanel aboutPanel = null;
    if ((!about.equals("") || !licenseText.equals("")) && !coreAddon) {
        aboutPanel = new AboutPanel(desc, coreAddon, manager, this);
    }
    // inital setup of settings panel if the addon has general settings in the non protocol/action specific
    // declaration
    DefaultSettingsPanel settingsPanel = null;
    ArrayList<DefaultSettingsGroup> settingsGroups = new ArrayList<>();
    AddonProperties addonProps = new AddonProperties(desc);
    Settings settings = SettingsFactory.getInstance(addonProps);
    if (desc.getConfigDescription() != null && !desc.getConfigDescription().getEntries().isEmpty()) {
        DefaultSettingsGroup group = new DefaultSettingsGroup(lang.translationForKey("addon.settings.general"), settings, desc.getConfigDescription().getEntries());
        settingsGroups.add(group);
    }
    // AppExtensionActions
    if (!desc.getApplicationActions().isEmpty()) {
        for (AppExtensionSpecification appExtSpec : desc.getApplicationActions()) {
            if (appExtSpec.getConfigDescription() != null && !appExtSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(appExtSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, appExtSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // Binding actions
    if (!desc.getBindingActions().isEmpty()) {
        for (AppPluginSpecification appPluginSpec : desc.getBindingActions()) {
            if (appPluginSpec.getConfigDescription() != null && !appPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(appPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, appPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // IFD Actions
    if (!desc.getIfdActions().isEmpty()) {
        for (ProtocolPluginSpecification protPluginSpec : desc.getIfdActions()) {
            if (protPluginSpec.getConfigDescription() != null && !protPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(protPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, protPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // SAL Actions
    if (!desc.getSalActions().isEmpty()) {
        for (ProtocolPluginSpecification protPluginSpec : desc.getSalActions()) {
            if (protPluginSpec.getConfigDescription() != null && !protPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(protPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, protPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    if (!settingsGroups.isEmpty()) {
        settingsPanel = new DefaultSettingsPanel(settingsGroups.toArray(new DefaultSettingsGroup[settingsGroups.size()]));
    }
    // create the actions panel
    ActionPanel actionPanel = null;
    if (!desc.getApplicationActions().isEmpty()) {
        actionPanel = new ActionPanel();
        for (AppExtensionSpecification appExtSpec : desc.getApplicationActions()) {
            ActionEntryPanel entry = new ActionEntryPanel(desc, appExtSpec, manager);
            actionPanel.addActionEntry(entry);
        }
    }
    AddonPanel nextPanel = null;
    // check whether to use a tabbed pane or not
    if (actionPanel != null && settingsPanel == null && aboutPanel == null) {
        nextPanel = new AddonPanel(actionPanel, name, description, logo);
    } else if (actionPanel == null && settingsPanel != null && aboutPanel == null) {
        nextPanel = new AddonPanel(settingsPanel, name, description, logo);
    } else if (actionPanel == null && settingsPanel == null && aboutPanel != null) {
        nextPanel = new AddonPanel(aboutPanel, name, description, logo);
    } else if (actionPanel != null || settingsPanel != null || aboutPanel != null) {
        nextPanel = new AddonPanel(actionPanel, settingsPanel, aboutPanel, name, description, logo);
    }
    if (nextPanel != null) {
        model.addElement(name, nextPanel);
    }
}
Also used : AddonProperties(org.openecard.addon.AddonProperties) ArrayList(java.util.ArrayList) Image(java.awt.Image) DefaultSettingsPanel(org.openecard.richclient.gui.manage.addon.DefaultSettingsPanel) DefaultSettingsGroup(org.openecard.richclient.gui.manage.addon.DefaultSettingsGroup) AppPluginSpecification(org.openecard.addon.manifest.AppPluginSpecification) AddonException(org.openecard.addon.AddonException) AppExtensionSpecification(org.openecard.addon.manifest.AppExtensionSpecification) ProtocolPluginSpecification(org.openecard.addon.manifest.ProtocolPluginSpecification)

Aggregations

Image (java.awt.Image)1 ArrayList (java.util.ArrayList)1 AddonException (org.openecard.addon.AddonException)1 AddonProperties (org.openecard.addon.AddonProperties)1 AppExtensionSpecification (org.openecard.addon.manifest.AppExtensionSpecification)1 AppPluginSpecification (org.openecard.addon.manifest.AppPluginSpecification)1 ProtocolPluginSpecification (org.openecard.addon.manifest.ProtocolPluginSpecification)1 DefaultSettingsGroup (org.openecard.richclient.gui.manage.addon.DefaultSettingsGroup)1 DefaultSettingsPanel (org.openecard.richclient.gui.manage.addon.DefaultSettingsPanel)1