Search in sources :

Example 1 with MetaAction

use of eu.ggnet.saft.core.cap.ActionFactory.MetaAction in project dwoss by gg-net.

the class SwingClient method init.

public void init() {
    try {
        UIManager.setLookAndFeel(Dl.local().lookup(UserPreferences.class).loadLaf());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
        L.warn("Cound not set LAF:" + ex.getMessage(), ex);
    }
    // Create the View
    view = new ClientView();
    // Collecting all MetaActions
    Collection<? extends ActionFactory> actionFactories = Lookup.getDefault().lookupAll(ActionFactory.class);
    if (actionFactories == null || actionFactories.isEmpty())
        throw new IllegalStateException("No ActionFactories found");
    // Registering DependentActionFactories in Saft
    actionFactories.stream().flatMap(a -> a.createDependentActionFactories().stream()).forEach(d -> Ops.registerActionFactory(d));
    // Registering DependentActions in Saft
    actionFactories.stream().flatMap(a -> a.createDependentActions().stream()).forEach(d -> Ops.registerAction(d));
    List<MetaAction> metaActions = new ArrayList<>();
    for (ActionFactory actionFactory : actionFactories) {
        metaActions.addAll(actionFactory.createMetaActions());
    }
    // Filling the Menus
    SortedMap<Integer, JMenu> finalMenus = buildMenus(metaActions);
    for (Map.Entry<Integer, JMenu> entry : finalMenus.entrySet()) {
        JMenu m = entry.getValue();
        view.menuBar.add(m);
        if (m.getText().equals("System"))
            m.add(buildLafMenu());
    }
    // Filling the Toolbar
    for (MetaAction metaAction : metaActions) {
        if (metaAction.isToolbar())
            view.toolBar.add(metaAction.getAction());
    }
    view.toolBar.addSeparator();
    Collection<? extends ToolbarComponent> tcs = Lookup.getDefault().lookupAll(ToolbarComponent.class);
    SortedMap<Integer, Component> tccs = new TreeMap<>();
    for (ToolbarComponent tc : tcs) {
        if (tc instanceof Component)
            tccs.put(tc.getOrder(), (Component) tc);
        if ((tc instanceof UserChangeListener) && Lookup.getDefault().lookup(Guardian.class) != null)
            Dl.local().lookup(Guardian.class).addUserChangeListener((UserChangeListener) tc);
    }
    for (Component tc : tccs.values()) {
        view.toolBar.add(tc);
    }
    // Filling the Main Panel
    Collection<? extends MainComponent> mcs = Lookup.getDefault().lookupAll(MainComponent.class);
    for (MainComponent mc : mcs) {
        if (mc instanceof Component)
            view.mainPanel.add((Component) mc, mc.getLayoutHint());
        if ((mc instanceof UserChangeListener) && Lookup.getDefault().lookup(Guardian.class) != null)
            Dl.local().lookup(Guardian.class).addUserChangeListener((UserChangeListener) mc);
    }
    enableAccessRestrictions(metaActions);
    es.scheduleAtFixedRate(new HiddenMonitorDisplayer(view), 2, 2, TimeUnit.SECONDS);
    view.setLocationByPlatform(true);
    Dl.local().lookup(UserPreferences.class).loadLocation(view.getClass(), view);
    UiCore.addOnShutdown(() -> {
        Dl.local().lookup(UserPreferences.class).storeLocation(view.getClass(), view);
        es.shutdownNow();
        try {
            boolean result = es.awaitTermination(10, TimeUnit.SECONDS);
            L.info("Shutdown Client,ExecutorService.isTerminated={}", result);
        } catch (InterruptedException ex) {
        }
        close();
    });
    if (System.getProperty("persistence.host") != null)
        view.setTitle(view.getTitle() + " Datenbank:" + System.getProperty("persistence.host"));
    // Autostart Saft. This will be different one day.
    UiCore.continueSwing(view);
    UiCore.backgroundActivityProperty().addListener((ov, o, n) -> {
        EventQueue.invokeLater(() -> view.extraProgressPanel.setVisible(n));
        Platform.runLater(() -> view.progressIndicator.setProgress(n ? -1 : 0));
    });
}
Also used : EventQueue(java.awt.EventQueue) Lookup(org.openide.util.Lookup) java.util(java.util) ActionListener(java.awt.event.ActionListener) Logger(org.slf4j.Logger) eu.ggnet.saft.core.cap(eu.ggnet.saft.core.cap) java.util.concurrent(java.util.concurrent) LoggerFactory(org.slf4j.LoggerFactory) MetaAction(eu.ggnet.saft.core.cap.ActionFactory.MetaAction) Accessable(eu.ggnet.saft.api.auth.Accessable) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) Application(javafx.application.Application) Platform(javafx.application.Platform) eu.ggnet.saft.core.auth(eu.ggnet.saft.core.auth) UserPreferences(eu.ggnet.saft.core.ui.UserPreferences) eu.ggnet.saft(eu.ggnet.saft) javax.swing(javax.swing) UserPreferences(eu.ggnet.saft.core.ui.UserPreferences) MetaAction(eu.ggnet.saft.core.cap.ActionFactory.MetaAction) Component(java.awt.Component)

Example 2 with MetaAction

use of eu.ggnet.saft.core.cap.ActionFactory.MetaAction in project dwoss by gg-net.

the class SwingClient method enableAccessRestrictions.

private void enableAccessRestrictions(Collection<MetaAction> metaActions) {
    Guardian accessCos = Lookup.getDefault().lookup(Guardian.class);
    if (accessCos != null) {
        for (ActionFactory.MetaAction metaAction : metaActions) {
            if (metaAction.getAction() instanceof Accessable) {
                Accessable accessable = (Accessable) metaAction.getAction();
                accessCos.add(accessable);
            }
        }
    }
}
Also used : MetaAction(eu.ggnet.saft.core.cap.ActionFactory.MetaAction) Accessable(eu.ggnet.saft.api.auth.Accessable)

Example 3 with MetaAction

use of eu.ggnet.saft.core.cap.ActionFactory.MetaAction in project dwoss by gg-net.

the class SwingClient method buildMenus.

private SortedMap<Integer, JMenu> buildMenus(Collection<MetaAction> metaActions) {
    Map<String, JMenu> menus = new HashMap<>();
    SortedMap<Integer, JMenu> finalMenus = new TreeMap<>();
    for (MetaAction metaAction : metaActions) {
        JMenu parrentMenu = null;
        Action action = metaAction.getAction();
        for (int i = 0; i < metaAction.getMenuNames().size(); i++) {
            List<String> names = metaAction.getMenuNames().subList(0, i + 1);
            String indexName = names.toString();
            String leafName = names.get(i);
            if (!menus.containsKey(indexName)) {
                // Gibt es das Menu schon, wenn nicht, lege es an
                JMenu menu = new JMenu(leafName);
                menus.put(indexName, menu);
                if (parrentMenu == null)
                    finalMenus.put(index(leafName), menu);
                else
                    parrentMenu.add(menu);
            }
            JMenu menu = menus.get(indexName);
            parrentMenu = menu;
            // If we are at the final iteration, add the action or the separator
            if (i == metaAction.getMenuNames().size() - 1) {
                if (action == null)
                    menu.addSeparator();
                else
                    menu.add(action);
            }
        }
    }
    return finalMenus;
}
Also used : MetaAction(eu.ggnet.saft.core.cap.ActionFactory.MetaAction) MetaAction(eu.ggnet.saft.core.cap.ActionFactory.MetaAction)

Aggregations

MetaAction (eu.ggnet.saft.core.cap.ActionFactory.MetaAction)3 Accessable (eu.ggnet.saft.api.auth.Accessable)2 eu.ggnet.saft (eu.ggnet.saft)1 eu.ggnet.saft.core.auth (eu.ggnet.saft.core.auth)1 eu.ggnet.saft.core.cap (eu.ggnet.saft.core.cap)1 UserPreferences (eu.ggnet.saft.core.ui.UserPreferences)1 Component (java.awt.Component)1 EventQueue (java.awt.EventQueue)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 java.util (java.util)1 java.util.concurrent (java.util.concurrent)1 Application (javafx.application.Application)1 Platform (javafx.application.Platform)1 javax.swing (javax.swing)1 Lookup (org.openide.util.Lookup)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1