From 415b6e5287091a03a5bfb477368c45a69e99de5c Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 29 May 2019 19:05:19 +0100 Subject: [PATCH] disable button until core initialized --- .../src/main/groovy/com/muwire/core/Core.groovy | 6 +++--- gui/griffon-app/lifecycle/Ready.groovy | 5 +++++ .../models/com/muwire/gui/EventListModel.groovy | 17 +++++++++++++++++ .../views/com/muwire/gui/EventListView.groovy | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 87bb198e..3118f945 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -137,12 +137,12 @@ public class Core { log.info("initializing host cache") File hostStorage = new File(home, "hosts.json") - HostCache hostCache = new HostCache(trustService,hostStorage, 30000, props, i2pSession.getMyDestination()) + hostCache = new HostCache(trustService,hostStorage, 30000, props, i2pSession.getMyDestination()) eventBus.register(HostDiscoveredEvent.class, hostCache) eventBus.register(ConnectionEvent.class, hostCache) log.info("initializing connection manager") - ConnectionManager connectionManager = props.isLeaf() ? + connectionManager = props.isLeaf() ? new LeafConnectionManager(eventBus, me, 3, hostCache) : new UltrapeerConnectionManager(eventBus, me, 512, 512, hostCache, trustService) eventBus.register(TrustEvent.class, connectionManager) eventBus.register(ConnectionEvent.class, connectionManager) @@ -186,8 +186,8 @@ public class Core { public void startServices() { hasherService.start() - trustService.waitForLoad() trustService.start() + trustService.waitForLoad() persisterService.start() hostCache.start() connectionManager.start() diff --git a/gui/griffon-app/lifecycle/Ready.groovy b/gui/griffon-app/lifecycle/Ready.groovy index 70180c00..c7df44f7 100644 --- a/gui/griffon-app/lifecycle/Ready.groovy +++ b/gui/griffon-app/lifecycle/Ready.groovy @@ -12,6 +12,8 @@ import javax.inject.Inject import static griffon.util.GriffonApplicationUtils.isMacOSX import static groovy.swing.SwingBuilder.lookAndFeel +import java.beans.PropertyChangeEvent + @Log class Ready extends AbstractLifecycleHandler { @Inject @@ -48,6 +50,9 @@ class Ready extends AbstractLifecycleHandler { Core core = new Core(props, home) core.startServices() application.context.put("core",core) + application.getPropertyChangeListeners("core").each { + it.propertyChange(new PropertyChangeEvent(this, "core", null, core)) + } } } diff --git a/gui/griffon-app/models/com/muwire/gui/EventListModel.groovy b/gui/griffon-app/models/com/muwire/gui/EventListModel.groovy index fd02fe8b..ceab1f8c 100644 --- a/gui/griffon-app/models/com/muwire/gui/EventListModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/EventListModel.groovy @@ -1,10 +1,27 @@ package com.muwire.gui +import javax.annotation.Nonnull +import javax.inject.Inject +import javax.inject.Named + +import com.muwire.core.Core + import griffon.core.artifact.GriffonModel +import griffon.core.GriffonApplication +import griffon.inject.Contextual +import griffon.inject.MVCMember import griffon.transform.Observable import griffon.metadata.ArtifactProviderFor @ArtifactProviderFor(GriffonModel) class EventListModel { + @Inject @Nonnull GriffonApplication application @Observable int clickCount = 0 + @Observable boolean coreInitialized = false + + void mvcGroupInit(Map args) { + application.addPropertyChangeListener("core", {e -> + coreInitialized = (e.getNewValue() != null) + }) + } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/EventListView.groovy b/gui/griffon-app/views/com/muwire/gui/EventListView.groovy index 98b66752..7a36b083 100644 --- a/gui/griffon-app/views/com/muwire/gui/EventListView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/EventListView.groovy @@ -24,7 +24,7 @@ class EventListView { gridLayout(rows: 2, cols: 1) label(id: 'clickLabel', text: bind { model.clickCount }, horizontalAlignment: SwingConstants.CENTER) - button(id: 'clickButton', clickAction) + button(id: 'clickButton', clickAction, enabled: bind {model.coreInitialized}) } } }