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