Example #1
0
  protected void executeSelectedAlgorithm() {

    try {
      if (m_Alg != null) {
        final GeoAlgorithm alg = m_Alg.getNewInstance();
        final int iRet =
            SextanteGUI.getGUIFactory().showAlgorithmDialog(alg, m_ParentDialog.getDialog(), null);
        if (iRet == IGUIFactory.OK) {
          final String[] cmd = alg.getAlgorithmAsCommandLineSentences();
          if (cmd != null) {
            History.addToHistory(cmd);
          }
          GeoAlgorithmExecutors.execute(alg, m_ParentDialog.getDialog());
          updateListOfMostRecentAlgorithms();
        }
      } else if (m_Action != null) {
        m_Action.execute();
      }
    } catch (final Exception e) {
      Sextante.addErrorToLog(e);
    }
  }
Example #2
0
  /**
   * Fills the tree with the algorithms that match a search criteria
   *
   * @param sSearchString The search string to look for in the algorithms context help
   * @param bSearchInFiles true if it should search in help files. if false, it will only search in
   *     algorithm names
   * @return the number of algorithms that match the given criteria
   */
  public int fillTree(final String sSearchString, final boolean bSearchInHelpFiles) {

    m_sLastSearchString = sSearchString;
    m_bLastSearchIncludedHelpFiles = bSearchInHelpFiles;

    int iCount = 0;
    String sGroup, sSubgroup;
    final DefaultMutableTreeNode mainNode =
        new DefaultMutableTreeNode(Sextante.getText("Algorithms"));
    final HashMap<Object, HashMap<String, HashMap<String, DefaultMutableTreeNode>>> groups =
        new HashMap<Object, HashMap<String, HashMap<String, DefaultMutableTreeNode>>>();

    setCursor(new Cursor(Cursor.WAIT_CURSOR));

    // algorithms
    final HashMap<String, HashMap<String, GeoAlgorithm>> algs = Sextante.getAlgorithms();
    final Set<String> groupKeys = algs.keySet();
    final Iterator<String> groupIter = groupKeys.iterator();
    while (groupIter.hasNext()) {
      final String groupKey = groupIter.next();
      final HashMap<String, GeoAlgorithm> groupAlgs = algs.get(groupKey);
      final Set keys = groupAlgs.keySet();
      final Iterator iter = keys.iterator();
      while (iter.hasNext()) {
        final GeoAlgorithm alg = groupAlgs.get(iter.next());
        if (m_Filter.accept(alg)) {
          if (bSearchInHelpFiles) {
            if (!HelpIO.containsStringInHelpFile(alg, sSearchString)) {
              continue;
            }
          } else {
            if ((sSearchString != null) && !alg.getName().toLowerCase().contains(sSearchString)) {
              continue;
            }
          }
          iCount++;
          final AlgorithmGroupConfiguration conf =
              AlgorithmGroupsOrganizer.getGroupConfiguration(alg);
          if (conf != null) {
            if (!conf.isShow()) {
              continue;
            }
            sGroup = conf.getGroup();
            sSubgroup = conf.getSubgroup();
          } else {
            sGroup = groupKey;
            sSubgroup = alg.getGroup();
          }
          HashMap<String, HashMap<String, DefaultMutableTreeNode>> group = groups.get(sGroup);
          if (group == null) {
            group = new HashMap<String, HashMap<String, DefaultMutableTreeNode>>();
            groups.put(sGroup, group);
          }
          HashMap<String, DefaultMutableTreeNode> subgroup = group.get(sSubgroup);
          if (subgroup == null) {
            subgroup = new HashMap<String, DefaultMutableTreeNode>();
            group.put(sSubgroup, subgroup);
          }
          subgroup.put(alg.getName(), new DefaultMutableTreeNode(alg));
        }
      }
    }

    // toolbox actions
    final HashMap<NameAndIcon, ArrayList<ToolboxAction>> allActions =
        SextanteGUI.getToolboxActions();
    final Set<NameAndIcon> actionsKeys = allActions.keySet();
    final Iterator<NameAndIcon> actionsIter = actionsKeys.iterator();
    while (actionsIter.hasNext()) {
      final NameAndIcon nai = actionsIter.next();
      final ArrayList<ToolboxAction> actions = allActions.get(nai);
      for (int i = 0; i < actions.size(); i++) {
        final ToolboxAction ita = actions.get(i);
        if ((sSearchString != null) && !ita.getName().toLowerCase().contains(sSearchString)) {
          continue;
        }
        iCount++;
        sSubgroup = ita.getGroup();
        HashMap<String, HashMap<String, DefaultMutableTreeNode>> group = groups.get(nai.getName());
        if (group == null) {
          group = groups.get(nai);
        }
        if (group == null) {
          group = new HashMap<String, HashMap<String, DefaultMutableTreeNode>>();
          groups.put(nai, group);
        }
        HashMap<String, DefaultMutableTreeNode> subgroup = group.get(sSubgroup);
        if (subgroup == null) {
          subgroup = new HashMap<String, DefaultMutableTreeNode>();
          group.put(sSubgroup, subgroup);
        }
        subgroup.put(ita.getName(), new DefaultMutableTreeNode(ita));
      }
    }

    final Set<Object> set = groups.keySet();
    final Iterator<Object> iter = set.iterator();
    while (iter.hasNext()) {
      final Object key = iter.next();
      final DefaultMutableTreeNode node = new DefaultMutableTreeNode(key);
      addNodeInSortedOrder(mainNode, node);
      final HashMap<String, HashMap<String, DefaultMutableTreeNode>> g = groups.get(key);
      final Set<String> set2 = g.keySet();
      final Iterator<String> iter2 = set2.iterator();
      while (iter2.hasNext()) {
        final String sKey2 = iter2.next();
        final DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(sKey2);
        addNodeInSortedOrder(node, node2);
        final HashMap<String, DefaultMutableTreeNode> g2 = g.get(sKey2);
        final Set<String> set3 = g2.keySet();
        final Iterator<String> iter3 = set3.iterator();
        while (iter3.hasNext()) {
          final String sKey3 = iter3.next();
          final DefaultMutableTreeNode node3 = g2.get(sKey3);
          addNodeInSortedOrder(node2, node3);
        }
      }
    }

    final boolean bShowMostRecent =
        new Boolean(SextanteGUI.getSettingParameterValue(SextanteGeneralSettings.SHOW_MOST_RECENT))
            .booleanValue();
    if (bShowMostRecent) {
      final GeoAlgorithm[] recent = History.getRecentlyUsedAlgs();
      final DefaultMutableTreeNode recentNode =
          new DefaultMutableTreeNode(Sextante.getText("RecentAlgorithms"));
      for (int i = 0; i < recent.length; i++) {
        final DefaultMutableTreeNode node = new DefaultMutableTreeNode(recent[i]);
        recentNode.add(node);
      }
      mainNode.insert(recentNode, 0);
    }

    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

    jTree.setModel(new DefaultTreeModel(mainNode));

    if (sSearchString != null) {
      expandAll();
    }

    m_ParentDialog.setAlgorithmsCount(iCount);

    return iCount;
  }