From c3f7a5961084635939762089e2c351deccf9f125 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Aug 2011 10:14:53 +0000 Subject: Autostart extension: Disable menu item when not possible git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@952 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java | 6 ++++++ .../main/java/at/gv/egiz/bku/webstart/autostart/Autostart.java | 8 +++++++- .../at/gv/egiz/bku/webstart/autostart/AutostartInterface.java | 1 + .../java/at/gv/egiz/bku/webstart/autostart/AutostartLinux.java | 7 +++++++ .../java/at/gv/egiz/bku/webstart/autostart/AutostartWindows.java | 7 +++++++ .../java/at/gv/egiz/bku/webstart/gui/BKUControllerInterface.java | 6 ++++++ .../src/main/java/at/gv/egiz/bku/webstart/gui/MOCCAIcon.java | 7 +++++-- 7 files changed, 39 insertions(+), 3 deletions(-) (limited to 'BKUWebStart/src/main/java/at/gv') diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java index 3fa7f805..95d76a4a 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java @@ -293,10 +293,16 @@ public class Launcher implements BKUControllerInterface { return version; } + @Override + public boolean isAutostartPossible() { + return autostart.isPossible(); + } + @Override public boolean isAutostartEnabled() { return autostart.isEnabled(); } + @Override public boolean setAutostart(boolean doAutostart) { return autostart.set(doAutostart); diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/Autostart.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/Autostart.java index a3291d05..db27f0d4 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/Autostart.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/Autostart.java @@ -37,13 +37,19 @@ public class Autostart { _autostart = new AutostartLinux(); else if (os.toLowerCase().contains("windows")) _autostart = new AutostartWindows(); - if (_webstartName != null) + if (_autostart != null && _webstartName != null) _autostart.setWebstartName(_webstartName); } return _autostart; } + public boolean isPossible() { + if (getAutostart() == null) + return false; + return getAutostart().isPossible(); + } + public boolean isEnabled() { if (getAutostart() == null) return false; diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartInterface.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartInterface.java index f085fc94..bcd87ac8 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartInterface.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartInterface.java @@ -24,6 +24,7 @@ package at.gv.egiz.bku.webstart.autostart; public interface AutostartInterface { + public boolean isPossible(); public boolean isEnabled(); public boolean set(boolean enable); public void setWebstartName(String webstartName); diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartLinux.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartLinux.java index 4fc91a30..59e06d95 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartLinux.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartLinux.java @@ -67,6 +67,13 @@ public class AutostartLinux extends AbstractAutostart { return autostartFiles; } + @Override + public boolean isPossible() { + Map autostartFiles = getAutostartFiles(); + + return !autostartFiles.isEmpty(); + } + @Override public boolean isEnabled() { Map autostartFiles = getAutostartFiles(); diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartWindows.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartWindows.java index 50c38d97..6200c02b 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartWindows.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/autostart/AutostartWindows.java @@ -153,6 +153,13 @@ public class AutostartWindows extends AbstractAutostart { return autostartFileName; } + @Override + public boolean isPossible() { + String autostartFileName = getAutostartFileName(); + + return autostartFileName != null; + } + @Override public boolean isEnabled() { String autostartFileName = getAutostartFileName(); diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/BKUControllerInterface.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/BKUControllerInterface.java index 91ce0e77..a340c980 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/BKUControllerInterface.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/BKUControllerInterface.java @@ -37,6 +37,12 @@ public interface BKUControllerInterface { public void pinManagement(Locale locale); + /** + * Check if MOCCA Autostart is possible + * @return autostart possibility + */ + boolean isAutostartPossible(); + /** * Check if MOCCA Autostart is enabled * @return autostart state diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/MOCCAIcon.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/MOCCAIcon.java index d6dc6d5b..64b94424 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/MOCCAIcon.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/gui/MOCCAIcon.java @@ -126,6 +126,7 @@ public class MOCCAIcon implements StatusNotifier, ActionListener, ItemListener { autostartItem.addItemListener(this); autostartItem.setActionCommand(COMMANDS.AUTOSTART_COMMAND.name()); autostartItem.setState(controller.isAutostartEnabled()); + autostartItem.setEnabled(controller.isAutostartPossible()); settingsMenu.add(autostartItem); menu.addSeparator(); @@ -238,11 +239,13 @@ public class MOCCAIcon implements StatusNotifier, ActionListener, ItemListener { @Override public void itemStateChanged(ItemEvent e) { - log.debug("autostart toggle requested via tray menu"); CheckboxMenuItem item = (CheckboxMenuItem) e.getItemSelectable(); switch (COMMANDS.valueOf(item.getActionCommand())) { case AUTOSTART_COMMAND: - item.setState((controller.setAutostart(item.getState()))); + boolean reqState = item.getState(); + boolean newState = controller.setAutostart(reqState); + log.debug("autostart toggle requested via tray menu (" + reqState + " -> " + newState + ")"); + item.setState(newState); break; default: -- cgit v1.2.3