You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InstallUninstallAction.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This code is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * version 2 for more details (a copy is included in the LICENSE file that
  13. * accompanied this code).
  14. *
  15. * You should have received a copy of the GNU General Public License version
  16. * 2 along with this work; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20. * or visit www.oracle.com if you need additional information or have any
  21. * questions.
  22. *
  23. */
  24. package com.github.dcevm.installer;
  25. import javax.swing.*;
  26. import javax.swing.event.ListSelectionEvent;
  27. import javax.swing.event.ListSelectionListener;
  28. import java.awt.event.ActionEvent;
  29. import java.io.IOException;
  30. import java.util.Observable;
  31. import java.util.Observer;
  32. /**
  33. * @author Kerstin Breiteneder
  34. * @author Christoph Wimberger
  35. * @author Ivan Dubrov
  36. * @author Jiri Bubnik
  37. */
  38. class InstallUninstallAction extends AbstractAction implements ListSelectionListener, Observer {
  39. /**
  40. * Buttons to add/remove DCEVM.
  41. */
  42. public enum Type {
  43. UNINSTALL("Uninstall"),
  44. INSTALL("Replace by DCEVM"),
  45. INSTALL_ALTJVM("Install DCEVM as altjvm");
  46. String label;
  47. Type(String label) {
  48. this.label = label;
  49. }
  50. public String getLabel() {
  51. return label;
  52. }
  53. }
  54. private final JTable table;
  55. private final Type type;
  56. private Installation installation;
  57. public InstallUninstallAction(Type type, JTable t) {
  58. super(type.getLabel());
  59. this.type = type;
  60. setEnabled(false);
  61. table = t;
  62. t.getSelectionModel().addListSelectionListener(this);
  63. }
  64. private Installation getSelectedInstallation() {
  65. InstallationsTableModel itm = (InstallationsTableModel) table.getModel();
  66. int sel = table.getSelectedRow();
  67. if (sel < 0) {
  68. return null;
  69. } else {
  70. return itm.getInstallationAt(sel);
  71. }
  72. }
  73. public void actionPerformed(ActionEvent e) {
  74. try {
  75. if (type.equals(Type.INSTALL)) {
  76. getSelectedInstallation().installDCE(false);
  77. }
  78. else if (type.equals(Type.INSTALL_ALTJVM)) {
  79. getSelectedInstallation().installDCE(true);
  80. } else {
  81. getSelectedInstallation().uninstallDCE();
  82. }
  83. } catch (IOException ex) {
  84. MainWindow.showInstallerException(ex, table);
  85. }
  86. }
  87. private void setCurrentInstallation(Installation i) {
  88. if (installation != null) {
  89. installation.deleteObserver(this);
  90. }
  91. installation = i;
  92. if (installation != null) {
  93. installation.addObserver(this);
  94. }
  95. update();
  96. }
  97. public void valueChanged(ListSelectionEvent e) {
  98. Installation i = getSelectedInstallation();
  99. setCurrentInstallation(i);
  100. }
  101. private void update() {
  102. if (type.equals(Type.INSTALL)) {
  103. setEnabled(installation != null && !installation.isDCEInstalled());
  104. } else if (type.equals(Type.INSTALL_ALTJVM)) {
  105. setEnabled(installation != null && !installation.isDCEInstalledAltjvm());
  106. } else {
  107. setEnabled(installation != null && (installation.isDCEInstalled() || installation.isDCEInstalledAltjvm()));
  108. }
  109. }
  110. public void update(Observable o, Object arg) {
  111. update();
  112. }
  113. }