Add update notification window

This commit is contained in:
Zlatin Balevsky
2019-10-31 20:51:09 +00:00
parent f7e28e04f6
commit 2429bbf59e
8 changed files with 125 additions and 13 deletions

View File

@@ -76,4 +76,9 @@ mvcGroups {
view = 'com.muwire.gui.CloseWarningView'
controller = 'com.muwire.gui.CloseWarningController'
}
'update' {
model = 'com.muwire.gui.UpdateModel'
view = 'com.muwire.gui.UpdateView'
controller = 'com.muwire.gui.UpdateController'
}
}

View File

@@ -0,0 +1,27 @@
package com.muwire.gui
import griffon.core.artifact.GriffonController
import griffon.core.controller.ControllerAction
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.annotation.Nonnull
@ArtifactProviderFor(GriffonController)
class UpdateController {
@MVCMember @Nonnull
UpdateView view
@MVCMember @Nonnull
UpdateModel model
@ControllerAction
void close() {
view.dialog.setVisible(false)
mvcGroup.destroy()
}
@ControllerAction
void search() {
mvcGroup.parentGroup.controller.search(model.available.infoHash, "MuWire update")
close()
}
}

View File

@@ -1,3 +1,4 @@
package com.muwire.gui
import java.util.concurrent.ConcurrentHashMap
@@ -264,8 +265,10 @@ class MainFrameModel {
void onUpdateDownloadedEvent(UpdateDownloadedEvent e) {
runInsideUIAsync {
JOptionPane.showMessageDialog(null, "MuWire $e.version has been downloaded. You can update now",
"Update Downloaded", JOptionPane.INFORMATION_MESSAGE)
Map<String, Object> args = new HashMap<>()
args['available'] = null
args['downloaded'] = e
mvcGroup.createMVCGroup("update", "update", args)
}
}
@@ -529,13 +532,10 @@ class MainFrameModel {
void onUpdateAvailableEvent(UpdateAvailableEvent e) {
runInsideUIAsync {
int option = JOptionPane.showConfirmDialog(null,
"MuWire $e.version is available from $e.signer. You have "+ metadata["application.version"]+" Update?",
"New MuWire version availble", JOptionPane.OK_CANCEL_OPTION)
if (option == JOptionPane.CANCEL_OPTION)
return
controller.search(e.infoHash,"MuWire update")
Map<String, Object> args = new HashMap<>()
args['available'] = e
args['downloaded'] = null
mvcGroup.createMVCGroup("update", "update", args)
}
}

View File

@@ -0,0 +1,14 @@
package com.muwire.gui
import com.muwire.core.update.UpdateAvailableEvent
import com.muwire.core.update.UpdateDownloadedEvent
import griffon.core.artifact.GriffonModel
import griffon.transform.Observable
import griffon.metadata.ArtifactProviderFor
@ArtifactProviderFor(GriffonModel)
class UpdateModel {
UpdateAvailableEvent available
UpdateDownloadedEvent downloaded
}

View File

@@ -0,0 +1,61 @@
package com.muwire.gui
import griffon.core.artifact.GriffonView
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.swing.JDialog
import javax.swing.SwingConstants
import java.awt.BorderLayout
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.annotation.Nonnull
@ArtifactProviderFor(GriffonView)
class UpdateView {
@MVCMember @Nonnull
FactoryBuilderSupport builder
@MVCMember @Nonnull
UpdateModel model
def mainFrame
def dialog
def p
void initUI() {
mainFrame = application.windowManager.findWindow("main-frame")
String title = model.downloaded != null ? "Update Downloaded" : "Update Available"
dialog = new JDialog(mainFrame, title, true)
dialog.setResizable(true)
p = builder.panel {
borderLayout()
panel (constraints : BorderLayout.CENTER) {
scrollPane {
def text = model.downloaded != null ? model.downloaded.text : model.available.text
textArea(text : text, rows : 20, columns : 50, editable : false, lineWrap : true, wrapStyleWord : true)
}
}
panel (constraints : BorderLayout.SOUTH) {
if (model.available != null)
button(text : "Find", searchAction)
button(text : "Close", closeAction)
}
}
}
void mvcGroupInit(Map<String,String> args) {
dialog.getContentPane().add(p)
dialog.pack()
dialog.setLocationRelativeTo(mainFrame)
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
dialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
mvcGroup.destroy()
}
})
dialog.show()
}
}