예제 #1
0
  @Override
  public boolean isActive() {
    ICConfigurationDescription desc = resolveSelectedConfiguration();

    return (desc != null) && desc.isActive();
  }
  /**
   * Fills the menu with build configurations which are common for all selected projects
   *
   * @param menu The menu to fill
   */
  protected void fillMenu(Menu menu) {
    // This should not happen
    if (menu == null) return;

    MenuItem[] items = menu.getItems();
    for (MenuItem item2 : items) item2.dispose();

    SortedSet<String> configNames = new TreeSet<String>();
    String sCurrentConfig = null;
    boolean bCurrentConfig = true;
    for (IProject prj : fProjects) {
      ICConfigurationDescription[] cfgDescs = getCfgs(prj);

      String sActiveConfig = null;
      // Store names and detect active configuration
      for (ICConfigurationDescription cfgDesc : cfgDescs) {
        String s = cfgDesc.getName();
        if (!configNames.contains(s)) configNames.add(s);
        if (cfgDesc.isActive()) sActiveConfig = s;
      }

      // Check whether all projects have the same active configuration
      if (bCurrentConfig) {
        if (sCurrentConfig == null) sCurrentConfig = sActiveConfig;
        else {
          if (!sCurrentConfig.equals(sActiveConfig)) bCurrentConfig = false;
        }
      }
    }

    int accel = 0;
    for (String sName : configNames) {
      String sDesc = null;
      boolean commonName = true;
      boolean commonDesc = true;
      boolean firstProj = true;
      for (IProject prj : fProjects) {
        ICConfigurationDescription[] cfgDescs = getCfgs(prj);
        int i = 0;
        for (; i < cfgDescs.length; i++) {
          if (cfgDescs[i].getName().equals(sName)) {
            String sNewDesc = cfgDescs[i].getDescription();
            if (sNewDesc != null && sNewDesc.length() == 0) {
              sNewDesc = null;
            }
            if (commonDesc) {
              if (firstProj) {
                sDesc = sNewDesc;
                firstProj = false;
              } else if (sNewDesc == null && sDesc != null
                  || sNewDesc != null && !sNewDesc.equals(sDesc)) {
                commonDesc = false;
              }
            }
            break;
          }
        }
        if (i == cfgDescs.length) {
          commonName = false;
          break;
        }
      }
      if (commonName) {
        StringBuffer builder = new StringBuffer(sName);
        if (commonDesc) {
          if (sDesc != null) {
            builder.append(" ("); // $NON-NLS-1$
            builder.append(sDesc);
            builder.append(")"); // $NON-NLS-1$
          }
        } else {
          builder.append(" (...)"); // $NON-NLS-1$
        }

        IAction action = makeAction(sName, builder, accel);
        if (bCurrentConfig && sCurrentConfig != null && sCurrentConfig.equals(sName)) {
          action.setChecked(true);
        }
        ActionContributionItem item = new ActionContributionItem(action);
        item.fill(menu, -1);
        accel++;
      }
    }
  }