示例#1
0
  private void populateConfigurations() {
    IProject prj = getProject();
    // Do nothing in case of Preferences page.
    if (prj == null) return;

    // Do not re-read if list already created by another page
    if (cfgDescs == null) {
      ICProjectDescription pDesc = CDTPropertyManager.getProjectDescription(this, prj);
      cfgDescs = (pDesc == null) ? null : pDesc.getConfigurations();
      if (cfgDescs == null || cfgDescs.length == 0) return;
      Arrays.sort(cfgDescs, CDTListComparator.getInstance());

    } else {
      if (cfgDescs.length == 0) return;
      // just register in CDTPropertyManager;
      CDTPropertyManager.getProjectDescription(this, prj);
    }

    // Do nothing if widget not created yet.
    if (configSelector == null) {
      lastSelectedCfg = cfgDescs[getActiveCfgIndex()];
      cfgChanged(lastSelectedCfg);
      return;
    }

    // Clear and replace the contents of the selector widget
    configSelector.removeAll();
    for (int i = 0; i < cfgDescs.length; ++i) {
      String name = cfgDescs[i].getName();
      if (cfgDescs[i].isActive()) {
        name = name + "  " + Messages.AbstractPage_16; // $NON-NLS-1$
      }
      configSelector.add(name);
    }

    // Ensure that the last selected config is selected by default
    int cfgIndex = getCfgIndex(lastSelectedCfg);

    // "All cfgs" - shown if at least 2 cfgs available
    if (cfgDescs.length > 1) {
      configSelector.add(Messages.AbstractPage_4);
      if (multiCfgs == cfgDescs) {
        cfgIndex = cfgDescs.length;
      }
    }
    // "Multi cfgs" - shown if at least 3 cfgs available
    if (cfgDescs.length > 2) {
      configSelector.add(Messages.AbstractPage_5);
      if (multiCfgs != null && multiCfgs != cfgDescs) {
        cfgIndex = cfgDescs.length + 1;
      }
    }

    if (cfgIndex < 0) {
      cfgIndex = getActiveCfgIndex();
    }

    configSelector.select(cfgIndex);
    handleConfigSelection();
  }
示例#2
0
  /*
   * Event Handlers
   */
  private void handleConfigSelection() {
    // If there is nothing in config selection widget just bail
    if (configSelector.getItemCount() == 0) return;
    int selectionIndex = configSelector.getSelectionIndex();
    if (selectionIndex == -1) return;
    if (cfgDescs == null || cfgDescs.length == 0) return;

    // Check if the user has selected the "all / multiple" configuration
    if (selectionIndex >= cfgDescs.length) {
      if (selectionIndex == cfgDescs.length) { // all
        multiCfgs = cfgDescs;
      } else { // multiple
        // Check previous state of variables figuring out if need to pop up selection dialog
        // areCfgsStillThere() covers deletions by a user in Manage Configurations dialog
        boolean enterMultiCfgsDialog =
            (multiCfgs == null) || (multiCfgs == cfgDescs) || !areCfgsStillThere(multiCfgs);
        if (enterMultiCfgsDialog) {
          ICConfigurationDescription[] mcfgs =
              ConfigMultiSelectionDialog.select(cfgDescs, parentComposite.getShell());
          if (mcfgs == null || mcfgs.length == 0) {
            // return back to previous selection
            int cfgIndex = -1;
            if (multiCfgs == cfgDescs) { // return to choice "All"
              cfgIndex = cfgDescs.length;
            } else {
              cfgIndex = getCfgIndex(lastSelectedCfg);
            }
            configSelector.select(cfgIndex);
            return;
          }
          multiCfgs = mcfgs;
        }
      }
      lastSelectedCfg = null;

      cfgChanged(MultiItemsHolder.createCDescription(multiCfgs));
      return;
    }
    multiCfgs = null;

    String id1 = getResDesc() == null ? null : getResDesc().getId();
    lastSelectedCfg = cfgDescs[selectionIndex];
    String id2 = lastSelectedCfg.getId();
    if (id2 != null && !id2.equals(id1)) {
      cfgChanged(lastSelectedCfg);
    }
  }