diff options
author | Jonathan Bauer | 2015-09-07 09:44:05 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-09-07 09:44:05 +0200 |
commit | e4811fd3b312229a5a7497275e66a808b14d6015 (patch) | |
tree | 529f428570ab23d0fa01bd87df9b2a135234e7c9 | |
parent | [client] Add hints to config dialog (diff) | |
download | tutor-module-e4811fd3b312229a5a7497275e66a808b14d6015.tar.gz tutor-module-e4811fd3b312229a5a7497275e66a808b14d6015.tar.xz tutor-module-e4811fd3b312229a5a7497275e66a808b14d6015.zip |
[client] Working on Client update checks [WIP]
TODO real URL for getting newest version
TODO continue update check window popup
5 files changed, 312 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index c852b891..4e0e18c0 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -35,6 +35,7 @@ import org.openslx.dozmod.filetransfer.DownloadTask; import org.openslx.dozmod.gui.Gui.GuiCallable; import org.openslx.dozmod.gui.activity.ActivityPanel; import org.openslx.dozmod.gui.activity.DownloadPanel; +import org.openslx.dozmod.gui.activity.UpdatePanel; import org.openslx.dozmod.gui.activity.UploadPanel; import org.openslx.dozmod.gui.control.QLabel; import org.openslx.dozmod.gui.helper.CompositePage; @@ -42,6 +43,7 @@ import org.openslx.dozmod.gui.helper.DebugWindow; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.UiFeedback; +import org.openslx.dozmod.gui.window.CheckUpdateWindow; import org.openslx.dozmod.gui.window.ConfigWindow; import org.openslx.dozmod.gui.window.DisclaimerWindow; import org.openslx.dozmod.gui.window.ImageListWindow; @@ -53,6 +55,7 @@ import org.openslx.dozmod.state.UploadWizardState; import org.openslx.dozmod.thrift.GuiErrorCallback; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.ThriftActions; +import org.openslx.dozmod.util.ClientVersion; import org.openslx.dozmod.util.FormatHelper; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; @@ -260,6 +263,11 @@ public abstract class MainWindow { // a session, just bail out completely if (Session.getSatelliteToken() == null) System.exit(42); + // at this point we are sure to be logged in with a proper token + // thus we directly check for new version + if (!ClientVersion.isNewest()) { + addPanel(new UpdatePanel(ClientVersion.getNewVersion())); + } // Show main menu by default showPage(MainMenuWindow.class); createMenu(); @@ -367,8 +375,10 @@ public abstract class MainWindow { JMenuItem disclaimerItem = new JMenuItem("Nutzungsvereinbarung"); JMenuItem virtualizerNoticeItem = new JMenuItem("Virtualisierer"); + JMenuItem updateCheckItem = new JMenuItem("Software-Aktualisierung"); cascadeAboutMenu.add(disclaimerItem); cascadeAboutMenu.add(virtualizerNoticeItem); + cascadeAboutMenu.add(updateCheckItem); menuBar.add(Box.createHorizontalGlue()); final QLabel memStats = new QLabel(); @@ -432,6 +442,13 @@ public abstract class MainWindow { } }); + updateCheckItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + CheckUpdateWindow.open(mainWindow); + } + }); + // Debug label QuickTimer.scheduleAtFixedDelay(new Task() { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java new file mode 100644 index 00000000..c4cf3071 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java @@ -0,0 +1,57 @@ +package org.openslx.dozmod.gui.activity; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.openslx.dozmod.gui.control.QLabel; +import org.openslx.dozmod.util.OpenLinks; +import org.openslx.dozmod.util.OpenLinks.Link; + +public class UpdatePanel extends ActivityPanel implements ActionListener { + + protected JPanel header; + protected JLabel lblInfo; + protected final JButton btnLink; + protected final JButton btnClose; + @Override + public boolean wantConfirmQuit() { + return false; + } + + public UpdatePanel(final String newVersion) { + super(); + + setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + // Header: Neue Version verfügbar: <newVersion> [Button] + header = new JPanel(); + header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS)); + lblInfo = new QLabel("Neue Version verfügbar: " + newVersion); + header.add(lblInfo); + header.add(Box.createHorizontalGlue()); + btnLink = new JButton("Im Browser öffnen"); + btnClose = new JButton("Schließen"); + btnLink.addActionListener(this); + btnClose.addActionListener(this); + header.add(btnLink); + header.add(btnClose); + add(header); + } + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == btnLink) { + OpenLinks.openWebpage(Link.VMWARE); + close(); + } + if (e.getSource() == btnClose) { + close(); + } + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java new file mode 100644 index 00000000..8e128322 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java @@ -0,0 +1,47 @@ +package org.openslx.dozmod.gui.window; + +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.JFrame; + +import org.apache.log4j.Logger; +import org.openslx.dozmod.Config; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.helper.UiFeedback; +import org.openslx.dozmod.gui.window.layout.CheckUpdateWindowLayout; +import org.openslx.dozmod.gui.window.layout.DisclaimerWindowLayout; + +/** + * Window for showing the disclaimer. + */ +@SuppressWarnings("serial") +public class CheckUpdateWindow extends CheckUpdateWindowLayout implements UiFeedback { + + private final static Logger LOGGER = Logger.getLogger(CheckUpdateWindow.class); + + public CheckUpdateWindow(Frame modalParent) { + super(modalParent); + + btnLink.setEnabled(false); + + } + + public static void open(Frame modalParent) { + new CheckUpdateWindow(modalParent).setVisible(true); + } + + @Override + public boolean wantConfirmQuit() { + return false; + } + + @Override + public void escapePressed() { + dispose(); + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java new file mode 100644 index 00000000..d12bbd6e --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java @@ -0,0 +1,94 @@ +package org.openslx.dozmod.gui.window.layout; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Frame; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.control.QLabel; +import org.openslx.dozmod.gui.helper.GridManager; +import org.openslx.sat.thrift.version.Version; + + +@SuppressWarnings("serial") +public abstract class CheckUpdateWindowLayout extends JDialog { + + private final static String title = "Update"; + private final static String noticeLabel = "Update"; + private final static String noticeText = "Hier können Sie nach Software-Update suchen und den Changelog ansehen."; + private final static String closeButtonLabel = "Schließen"; + + protected static String changelogText = "-"; + protected static QLabel vmwareLink; + protected static JButton btnLink; + protected static JButton btnClose; + protected JScrollPane disclaimerPanel; + protected static JLabel newVersion; + + public CheckUpdateWindowLayout(Frame modalParent) { + super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); + setLayout(new BorderLayout()); + setPreferredSize(new Dimension(500, 300)); + + // Panel used for creating border. We'll add everything into this. + JPanel borderPanel = new JPanel(); + borderPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + add(borderPanel); + + // information before the disclaimer + JPanel infoPanel = new JPanel(); + GridManager infoGrid = new GridManager(infoPanel, 4); + infoPanel.setBorder(BorderFactory.createTitledBorder(noticeLabel)); + infoGrid.add(new JLabel("Ihre Version")); + infoGrid.add(Box.createHorizontalStrut(10)); + infoGrid.add(new JLabel(String.valueOf(Version.VERSION))); + infoGrid.add(Box.createHorizontalGlue()).fill(true, false).expand(true, false); + infoGrid.nextRow(); + infoGrid.add(new JLabel("Neueste Version")); + infoGrid.add(Box.createHorizontalStrut(10)); + infoGrid.add(new JLabel(String.valueOf(Version.VERSION))); + infoGrid.add(Box.createHorizontalGlue()).fill(true, false).expand(true, false); + infoGrid.finish(false); + + + // the disclaimer text box with scrolling functionality + JTextArea disclaimerText = new JTextArea(changelogText, 30, 20); + disclaimerText.setLineWrap(true); + disclaimerText.setWrapStyleWord(true); + disclaimerPanel = new JScrollPane(disclaimerText, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + disclaimerPanel.setBorder(BorderFactory.createTitledBorder("Changelog")); + + + // checkbox for acknowledging the disclaimer + btnLink = new JButton("Neueste Version herunterladen"); + btnClose = new JButton(closeButtonLabel); + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); + buttonPanel.add(Box.createHorizontalGlue()); + buttonPanel.add(btnLink); + buttonPanel.add(btnClose); + + + // put everything together + GridManager grid = new GridManager(borderPanel, 1); + grid.add(infoPanel).fill(true, false).expand(true, false); + grid.nextRow(); + grid.add(disclaimerPanel).fill(true, true).expand(true, true); + grid.finish(false); + + add(buttonPanel, BorderLayout.PAGE_END); + pack(); + Gui.centerShellOverShell(modalParent, this); + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java new file mode 100644 index 00000000..a1a86692 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java @@ -0,0 +1,97 @@ +package org.openslx.dozmod.util; + +import java.net.URL; +import java.util.Scanner; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +import org.apache.log4j.Logger; + +// ClientVersion is a bad name, TODO find better suited one :) +public class ClientVersion { + + private static final Logger LOGGER = Logger.getLogger(ClientVersion.class); + + private static String remoteVersion = null; + private static Long localRevisionTime = null; + private static Long remoteRevisionTime = null; + private static String revision = null; + + private static void init() { + // load local version information from the jar's MANIFEST.MF + String manifestRev = null; + String manifestRevTime = null; + try { + Attributes attributes = getAttr(); + if (attributes == null) + return; + manifestRev = attributes.getValue("Build-Revision"); + manifestRevTime = attributes.getValue("Build-Revision-Timestamp"); + if (manifestRev != null) + revision = manifestRev; + if (manifestRevTime != null) + localRevisionTime = Long.valueOf(manifestRevTime); + } catch ( NumberFormatException e) { + LOGGER.warn("Error while reading version: ", e); + } + LOGGER.info("Local version timestamp: " + localRevisionTime); + // load the remote version information + URL remoteVersionUrl = null; + Scanner scanner = null; + try { + remoteVersionUrl = new URL("http://132.230.4.25/dozmod.version"); + scanner = new Scanner(remoteVersionUrl.openStream()); + } catch (Exception e) { + // TODO shouldn't happen anyways + LOGGER.error("Could not download remote version from: " + remoteVersionUrl.getPath(), e); + } + // process only one line for now + Long remoteTime = null; + if (scanner.hasNextLong()) { + remoteTime = scanner.nextLong(); + } + scanner.close(); + if (remoteTime != null) { + remoteRevisionTime = remoteTime; + } + LOGGER.info("Remote version timestamp: " + remoteRevisionTime); + + } + + private static Attributes getAttr() { + Class clazz = ClientVersion.class; + String className = clazz.getSimpleName() + ".class"; + String classPath = clazz.getResource(className).toString(); + if (!classPath.startsWith("jar")) { + // Class not from JAR + return null; + } + String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + + "/META-INF/MANIFEST.MF"; + Manifest manifest = null; + try { + manifest = new Manifest(new URL(manifestPath).openStream()); + } catch (Exception e) { + LOGGER.error("Could not open MANIFEST", e); + return null; + } + Attributes attr = manifest.getMainAttributes(); + return attr; + } + public static String getNewVersion() { + return getRevision(); + } + public static String getRevision() { + if (revision == null) + init(); + return revision; + } + + public static boolean isNewest() { + if (localRevisionTime == null || remoteRevisionTime == null) + init(); + if (localRevisionTime == null || remoteRevisionTime == null) + return true; // hax + return localRevisionTime >= remoteRevisionTime; + } +} |