diff options
author | Steffen Ritter | 2018-07-09 15:31:48 +0200 |
---|---|---|
committer | Steffen Ritter | 2018-07-09 15:31:48 +0200 |
commit | 09079cdadf9e311665eabe80eae5b0bca1d5ebb3 (patch) | |
tree | fc8aaa4b8350c9102dc687dda99c28f4c8364abc /dozentenmodul/src/main/java/org/openslx | |
parent | [server] Fix issues FindBugs uncovered (diff) | |
download | tutor-module-09079cdadf9e311665eabe80eae5b0bca1d5ebb3.tar.gz tutor-module-09079cdadf9e311665eabe80eae5b0bca1d5ebb3.tar.xz tutor-module-09079cdadf9e311665eabe80eae5b0bca1d5ebb3.zip |
[client] Introduce visibility flag for runscript
Requires at least MiniLinux 21. Else it will break runscript
functionality if a visibility flag is set in the lecture db but the
minilinux doesn't know how to handle it.
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx')
-rwxr-xr-x[-rw-r--r--] | dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java | 98 |
1 files changed, 77 insertions, 21 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java index ead06c0c..5323a215 100644..100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/RunscriptConfigurator.java @@ -20,6 +20,7 @@ import javax.swing.JTextArea; import org.openslx.dozmod.gui.changemonitor.DialogChangeMonitor; import org.openslx.dozmod.gui.configurator.RunscriptConfigurator.RunscriptType; +import org.openslx.dozmod.gui.configurator.RunscriptConfigurator.RunscriptVisibility; import org.openslx.dozmod.gui.control.ComboBox; import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer; import org.openslx.dozmod.gui.control.QLabel; @@ -52,6 +53,23 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { } } + public static enum RunscriptVisibility { + NORMAL("Normal", 1), MINIMIZED("Minimiert", 2), HIDDEN("Versteckt", 0); + + private final String displayName; + private final int flag; + + private RunscriptVisibility(String name, int flag) { + this.displayName = name; + this.flag = flag; + } + + @Override + public String toString() { + return displayName; + } + } + public RunscriptConfigurator() { super(); @@ -83,8 +101,8 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { lblError.setText(msg); } /** - * Gets the runscript as String. The chosen interpreter will get encoded as - * the first line of the script. + * Gets the runscript as String. The chosen interpreter and visibility flag + * will get encoded in the first line of the script. * * @return runscript as String. If no text was entered, returns a empty * string. @@ -109,8 +127,16 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { setError("Fehlende Dateinamenerweiterung!"); return null; } + + RunscriptVisibility visibility = (RunscriptVisibility) cboRunscriptVisibility.getSelectedItem(); + if (visibility == null) { + // this should never happen, so return null to report this invalid state + setError("Fehlendes Sichtbarkeits-Flag!"); + return null; + } + setError(""); - return "ext=" + extension + "\n" + taInputText; + return "ext=" + extension + ";" + "visibility=" + visibility.flag + "\n" + taInputText; } /** @@ -127,34 +153,49 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { taRunScript.setText(""); return; } - String extensionHeader = null; + String header = null; try { BufferedReader reader = new BufferedReader(new StringReader(config)); - extensionHeader = reader.readLine(); + header = reader.readLine(); reader.close(); } catch (IOException e) { // swallow ... } - if (extensionHeader != null) { - // we should have following format: ext=<interpreter> - // e.g. ext=sh - extensionHeader = extensionHeader.replace("ext=", ""); - for (RunscriptType type : RunscriptType.values()) { - if (type.extension.equals(extensionHeader)) { - cboRunscriptType.setSelectedItem(type); - // mark that we found it by nulling the shebang... - extensionHeader = null; - continue; + if (header != null) { + // we should have following format: ext=<interpreter>;visibility=<flag> + // e.g. ext=sh;scriptVisibility=0 + String[] options = header.split(";"); + String extension = null; + for (String option : options) { + if(option.startsWith("ext=")) { + extension = option.replace("ext=", ""); + for (RunscriptType type : RunscriptType.values()) { + if (type.extension.equals(extension)) { + cboRunscriptType.setSelectedItem(type); + // mark that we found it by nulling the shebang... + extension = null; + break; + } + } + } else if (option.startsWith("visibility=")) { + option = option.replace("visibility=", ""); + for (RunscriptVisibility windowFlag : RunscriptVisibility.values()) { + if (windowFlag.flag == Integer.parseInt(option)) { + cboRunscriptVisibility.setSelectedItem(windowFlag); + break; + } + } } } - if (extensionHeader != null) { + + if (extension != null) { // user specific shebang, so just write the text to the cbo - cboRunscriptType.getEditor().setItem(extensionHeader); + cboRunscriptType.getEditor().setItem(extension); } } // finished with the interpreter, remove that line from the given config // before setting that text - taRunScript.setText(config.replaceFirst("^ext=.*\n", "")); + taRunScript.setText(config.replaceFirst(header + "\n", "")); } /** @@ -197,12 +238,13 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { } } } - + public void addToChangeMonitor(DialogChangeMonitor changeMonitor) { changeMonitor.add(taRunScript); changeMonitor.addEditableCombo(cboRunscriptType, null); + changeMonitor.addFixedCombo(cboRunscriptVisibility, null); } - + } /** @@ -217,6 +259,7 @@ class RunscriptConfiguratorLayout extends JPanel { protected final QLabel lblError; protected final JTextArea taRunScript; protected final ComboBox<RunscriptType> cboRunscriptType; + protected final ComboBox<RunscriptVisibility> cboRunscriptVisibility; public RunscriptConfiguratorLayout() { @@ -241,13 +284,26 @@ class RunscriptConfiguratorLayout extends JPanel { }); cboRunscriptType.setModel(new DefaultComboBoxModel<RunscriptType>( RunscriptType.values())); - ; cboRunscriptType.setEditable(true); grid.add(new QLabel("Dateinamenserweiterung: ")).fill(false, false) .expand(false, false); grid.add(cboRunscriptType).fill(true, false) .expand(true, false); grid.nextRow(); + cboRunscriptVisibility = new ComboBox<RunscriptVisibility>(new ComboBoxRenderer<RunscriptVisibility>() { + @Override + public String renderItem(RunscriptVisibility item) { + if (item == null) + return null; + return item.toString(); + } + }); + cboRunscriptVisibility.setModel(new DefaultComboBoxModel<RunscriptVisibility>(RunscriptVisibility.values())); + grid.add(new QLabel("Sichtbarkeit: ")).fill(false, false) + .expand(false, false); + grid.add(cboRunscriptVisibility).fill(true, false) + .expand(true, false); + grid.nextRow(); grid.add(scpRunScript, 2).fill(true, true).expand(true, true); grid.nextRow(); lblError = new QLabel(""); |