Exemple #1
0
  @Override
  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (columnIndex == 0) {
      if (aValue instanceof Integer) {
        Pack pack = packs.get(rowIndex);
        boolean packadded = false;
        if ((Integer) aValue == 1) {
          packadded = true;
          String packid = pack.getLangPackId(); // TODO - see IZPACK-799
          if (packid != null) {
            if (this.rules.canInstallPack(packid, this.variables)
                || this.rules.canInstallPackOptional(packid, this.variables)) {
              if (pack.isRequired()) {
                checkValues[rowIndex] = -1;
              } else {
                checkValues[rowIndex] = 1;
              }
            }
          } else {
            if (pack.isRequired()) {
              checkValues[rowIndex] = -1;
            } else {
              checkValues[rowIndex] = 1;
            }
          }
        } else {
          packadded = false;
          checkValues[rowIndex] = 0;
        }
        updateExcludes(rowIndex);
        updateDeps();

        if (packadded) {
          if (panel.getDebugger() != null) {
            panel.getDebugger().packSelectionChanged("after adding pack " + pack.getLangPackId());
          }
          // temporarily add pack to packstoinstall
          this.packsToInstall.add(pack);
        } else {
          if (panel.getDebugger() != null) {
            panel.getDebugger().packSelectionChanged("after removing pack " + pack.getLangPackId());
          }
          // temporarily remove pack from packstoinstall
          this.packsToInstall.remove(pack);
        }
        updateConditions();
        if (packadded) {
          // redo
          this.packsToInstall.remove(pack);
        } else {
          // redo
          this.packsToInstall.add(pack);
        }
        refreshPacksToInstall();
        updateBytes();
        fireTableDataChanged();
        panel.showSpaceRequired();
      }
    }
  }
Exemple #2
0
 /**
  * This function updates the checkboxes after a change by disabling packs that cannot be installed
  * anymore and enabling those that can after the change. This is accomplished by running a search
  * that pinpoints the packs that must be disabled by a non-fullfiled dependency.
  */
 private void updateDeps() {
   int[] statusArray = new int[packs.size()];
   for (int i = 0; i < statusArray.length; i++) {
     statusArray[i] = 0;
   }
   dfs(statusArray);
   for (int i = 0; i < statusArray.length; i++) {
     if (statusArray[i] == 0 && checkValues[i] < 0) {
       checkValues[i] += 2;
     }
     if (statusArray[i] == 1 && checkValues[i] >= 0) {
       checkValues[i] = -2;
     }
   }
   // The required ones must propagate their required status to all the
   // ones
   // that they depend on
   for (Pack pack : packs) {
     if (pack.isRequired()) {
       String packid = pack.getLangPackId();
       if (packid != null) {
         if (!(!this.rules.canInstallPack(packid, this.variables)
             && this.rules.canInstallPackOptional(packid, this.variables))) {
           propRequirement(pack.getName());
         }
       } else {
         propRequirement(pack.getName());
       }
     }
   }
 }
Exemple #3
0
  private void removeAlreadyInstalledPacks(List<Pack> selectedpacks) {
    List<Pack> removepacks = new ArrayList<Pack>();

    for (Pack selectedpack : selectedpacks) {
      String key = "";
      if (selectedpack.getLangPackId() != null) {
        key = selectedpack.getLangPackId();
      } else {
        key = selectedpack.getName();
      }
      if (installedpacks.containsKey(key)) {
        // pack is already installed, remove it
        removepacks.add(selectedpack);
      }
    }
    for (Pack removepack : removepacks) {
      selectedpacks.remove(removepack);
    }
  }
Exemple #4
0
  private void updateConditions(boolean initial) {
    boolean changes = true;

    while (changes) {
      changes = false;
      // look for packages,
      for (Pack pack : packs) {
        int pos = getPos(pack.getName());
        logger.fine("Conditions fulfilled for: " + pack.getName() + "?");
        if (!this.rules.canInstallPack(
            pack.getLangPackId(), this.variables)) // TODO - see IZPACK-799
        {
          logger.fine("no");
          if (this.rules.canInstallPackOptional(pack.getLangPackId(), this.variables)) {
            logger.fine("optional");
            logger.fine(pack.getLangPackId() + " can be installed optionally.");
            if (initial) {
              if (checkValues[pos] != 0) {
                checkValues[pos] = 0;
                changes = true;
                // let the process start from the beginning
                break;
              }
            }
          } else {
            logger.fine("Pack" + pack.getLangPackId() + " cannot be installed");
            if (checkValues[pos] != -2) {
              checkValues[pos] = -2;
              changes = true;
              // let the process start from the beginning
              break;
            }
          }
        }
      }
      refreshPacksToInstall();
    }
  }
Exemple #5
0
  @Override
  public Object getValueAt(int rowIndex, int columnIndex) {
    Pack pack = packs.get(rowIndex);
    switch (columnIndex) {
      case 0:
        return checkValues[rowIndex];

      case 1:
        Object name = null;
        if (messages != null && pack.getLangPackId() != null && !pack.getLangPackId().equals("")) {
          name = messages.get(pack.getLangPackId());
        }
        if (name == null || "".equals(name)) {
          name = pack.getName();
        }
        return name;

      case 2:
        return Pack.toByteUnitsString(pack.getSize());

      default:
        return null;
    }
  }
Exemple #6
0
  private void updateBytes() {
    long bytes = 0;
    for (int q = 0; q < packs.size(); q++) {
      if (Math.abs(checkValues[q]) == 1) {
        Pack pack = packs.get(q);
        bytes += pack.getSize();
      }
    }

    // add selected hidden bytes
    for (Pack hidden : this.hiddenPacks) {
      if (this.rules.canInstallPack(hidden.getLangPackId(), variables)) {
        bytes += hidden.getSize();
      }
    }
    panel.setBytes(bytes);
  }
Exemple #7
0
  private void refreshPacksToInstall() {

    packsToInstall.clear();
    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);
      String key = "";
      if ((pack.getLangPackId() != null) && (pack.getLangPackId().length() > 0)) {
        key = pack.getLangPackId();
      } else {
        key = pack.getName();
      }
      if ((Math.abs(checkValues[i]) == 1) && (!installedpacks.containsKey(key))) {
        packsToInstall.add(pack);
      }
    }

    for (int i = 0; i < packs.size(); i++) {
      Pack pack = packs.get(i);

      String key = "";
      if ((pack.getLangPackId() != null) && (pack.getLangPackId().length() > 0)) {
        key = pack.getLangPackId();
      } else {
        key = pack.getName();
      }
      if (installedpacks.containsKey(key)) {
        checkValues[i] = -3;
      }
    }
    // add hidden packs
    for (Pack hiddenpack : this.hiddenPacks) {
      if (this.rules.canInstallPack(hiddenpack.getLangPackId(), variables)) {
        packsToInstall.add(hiddenpack);
      }
    }
  }
Exemple #8
0
  public PacksModel(PacksPanelInterface panel, GUIInstallData idata, RulesEngine rules) {
    this.idata = idata;
    modifyinstallation = Boolean.valueOf(idata.getVariable(InstallData.MODIFY_INSTALLATION));
    this.installedpacks = new HashMap<String, Pack>();

    if (modifyinstallation) {
      // installation shall be modified
      // load installation information

      try {
        FileInputStream fin =
            new FileInputStream(
                new File(
                    idata.getInstallPath()
                        + File.separator
                        + InstallData.INSTALLATION_INFORMATION));
        ObjectInputStream oin = new ObjectInputStream(fin);
        List<Pack> packsinstalled = (List<Pack>) oin.readObject();
        for (Pack installedpack : packsinstalled) {
          if ((installedpack.getLangPackId() != null)
              && (installedpack.getLangPackId().length() > 0)) {
            this.installedpacks.put(installedpack.getLangPackId(), installedpack);
          } else {
            this.installedpacks.put(installedpack.getName(), installedpack);
          }
        }
        this.removeAlreadyInstalledPacks(idata.getSelectedPacks());
        logger.fine("Found " + packsinstalled.size() + " installed packs");

        Properties variables = (Properties) oin.readObject();

        for (Object key : variables.keySet()) {
          idata.setVariable((String) key, (String) variables.get(key));
        }
        fin.close();
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    this.rules = rules;

    this.packs = new ArrayList<Pack>();
    this.hiddenPacks = new ArrayList<Pack>();
    for (Pack availablePack : idata.getAvailablePacks()) {
      // only add a pack if not hidden
      if (!availablePack.isHidden()) {
        this.packs.add(availablePack);
      } else {
        this.hiddenPacks.add(availablePack);
      }
    }

    this.packsToInstall = idata.getSelectedPacks();
    this.panel = panel;
    variables = idata.getVariables();
    variables.set(INITAL_PACKSELECTION, Boolean.toString(true));
    messages = panel.getMessages();
    checkValues = new int[packs.size()];
    reverseDeps();
    initvalues();
    this.updateConditions(true);
    refreshPacksToInstall();
    variables.set(INITAL_PACKSELECTION, Boolean.toString(false));
  }