Ejemplo n.º 1
0
  /**
   * add the section tabs for different segment structures. For example in Genesis these can be:
   * Chapters | Parshas | Commentary
   *
   * @param nodeList
   */
  private void addTabsection(List<BilingualNode> nodeList) {
    tabRoot = new LinearLayout(context);
    tabRoot.setOrientation(LinearLayout.HORIZONTAL);
    tabRoot.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    tabRoot.setGravity(Gravity.CENTER);
    this.addView(tabRoot, 0); // make sure it's on top

    for (int count = 0; count < nodeList.size(); count++) {
      MenuNode menuNode = (MenuNode) nodeList.get(count);
      // although generally this isn't necessary b/c the nodes come from menuState.getSections
      // this is used when rebuilding after memory dump and nodes come from setHasTabs()
      if (menuNode.getTitle(Util.Lang.EN).equals("Commentary")
          || (menuNode.getTitle(Util.Lang.EN).equals("Rif"))) {

        continue;
      }
      if (count > 0 && count < nodeList.size()) {
        LayoutInflater inflater =
            (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        inflater.inflate(R.layout.tab_divider_menu, tabRoot);
      }

      MenuButtonTab mbt = new MenuButtonTab(context, menuNode, menuState.getLang());
      mbt.setOnClickListener(tabButtonClick);
      tabRoot.addView(mbt);
      menuElementList.add(mbt);
      menuButtonTabList.add(mbt);
    }
  }
Ejemplo n.º 2
0
  public MenuNode getActiveNode() {
    MenuNode result = null;

    if (getActivePath() != null) {
      Iterator<String> iter = getActivePath().getSegmentIterator();
      result = menus.get(iter.next());

      while (result != null && iter.hasNext()) {
        result = result.getChild(iter.next());
      }
    }

    return result;
  }
Ejemplo n.º 3
0
  /**
   * Get the node whose id matches this node's idref attribute value.
   *
   * @return the MenuNode whose id matches this node's idref attribute value.
   */
  @Override
  public MenuNode getRefNode() {
    MenuNode refNode = null;

    // create one if it does not exist
    // should not happen, but can't hurt
    if (_idrefList == null) {
      String idref = getIdRef();
      _makeIdRefList(idref);
    }

    // Get idrefList
    String[] idrefList = _getIdRefList();

    // get group node's children
    List<MenuNode> children = getChildren();

    // Traverse the list. Do the following:
    //    o get Node from Model's hashMap of nodes and ids
    //    o check attributes (rendered, disabled, readOnly)
    //    o if they are ok, return the node
    for (int i = 0; i < Array.getLength(idrefList); i++) {
      Iterator<MenuNode> childIter = children.iterator();

      // All node "id" attribute values had the node's
      // system hashcode id appended to the id when
      // placed in the model's idNodeMap.
      //
      // Each id in the idreflist of a group node does
      // NOT have this node sys id appended it to it
      // and needs to or we won't find the group's
      // ref node.
      //
      // Since group nodes can only point to one of
      // its children, we iterate through them, get
      // their sys id and append it to idref until
      // we find a match (or not).
      while (childIter.hasNext()) {
        MenuNode childNode = childIter.next();
        String nodeSysId = childNode.getNodeSysId();

        // Need to append mode's sys id here to create a
        // unique id.
        String refNodeId = idrefList[i] + nodeSysId;

        refNode = (MenuNode) getRootModel().getNode(refNodeId);

        // if nothing found, move on to the next child
        if (refNode != null) break;
      }

      if (refNode == null) continue;

      // Check the attributes of the found node
      if (!refNode.getRendered()
          || refNode.getDisabled()
          || refNode.getReadOnly()
          || !refNode.getVisible()) {
        refNode = null;
        continue;
      }

      // Ok, we have a valid RefNode
      break;
    }

    // If no valid node is found,
    // log an error
    if (refNode == null) {
      _LOG.severe("GroupNode " + getLabel() + " refers to no valid node.\n");
      return null;
    }

    return refNode;
  }
Ejemplo n.º 4
0
  /** 加载菜单 */
  private static synchronized void loadMenus() {

    // 初始化
    if (contextPath == null) {
      log.error("请先设置应用程序上下文!");
      return;
    }
    htMenus = new Hashtable();
    htIndexById = new Hashtable();
    StringBuffer sbQuerySql =
        new StringBuffer("SELECT * FROM MENUALL WHERE (APPSYS = '99' OR APPSYS = '");
    sbQuerySql.append(PropertyManager.getProperty("appsys")).append("')");
    String strTempSqlwhere = PropertyManager.getProperty("menu.add.sqlwhere");
    if (sqlWhere == null || !sqlWhere.trim().equals("")) {
      if (strTempSqlwhere != null && !strTempSqlwhere.trim().equals("")) sqlWhere = strTempSqlwhere;
    } else {
      if (strTempSqlwhere != null && !strTempSqlwhere.trim().equals(""))
        sqlWhere = "(" + sqlWhere + ") AND (" + strTempSqlwhere + ")";
    }
    if (sqlWhere != null && sqlWhere.length() > 3) {
      log.debug("添加的Where条件:" + sqlWhere);
      sbQuerySql.append(" AND (").append(sqlWhere).append(") ");
    }
    sbQuerySql.append(" ORDER BY MENUID");
    DataBean db = new DataBean();
    DynaSqlBean dsb = new DynaSqlBean();
    dsb.setSql(sbQuerySql.toString());
    try {
      db.setCrs(dsb.executeQuery());
    } catch (SQLException e) {
      log.error(e.getMessage(), e);
      return;
    }
    log.debug("从数据库中取得菜单数:" + String.valueOf(db.getRowCount()));

    String strMenuNameEn;
    String strMenuNameCn;
    String strMenuId;
    String strUrl;
    String strPurview;

    // 所有菜单不用经过权限的检验,统一放到哈希表中,其中判断节点和
    // 菜单项的条件也改为仅与前一项的前两位字符相比较,如果不一样则
    // 为新的节点
    for (int i = 0; i < db.getRowCount(); i++) {
      strMenuId = db.getElementValue(i, "MENUID").trim();
      log.debug(strMenuId);
      strPurview = db.getElementValue(i, "MPURVIEW").trim();
      strMenuNameCn = db.getElementValue(i, "MNAMEC").trim();
      if (strMenuNameCn.indexOf("(&") > 0)
        strMenuNameCn = strMenuNameCn.substring(0, strMenuNameCn.indexOf("(&"));
      MenuNode mn = new MenuNode(strMenuId, strMenuNameCn);

      strMenuNameEn = db.getElementValue(i, "MNAMEE").trim();
      strUrl = db.getElementValue(i, "MFILEE").trim();
      if (strUrl.length() > 0) {
        if (strUrl.startsWith("/")) strUrl = getContextPath() + strUrl;
        strUrl = CommonTools.encodeUrl(strUrl);
      }
      mn.setUrl(strUrl);
      mn.setEnglishName(strMenuNameEn);
      mn.setPurview(strPurview);

      htIndexById.put(strMenuId, mn.getNodeId());

      // 填充主菜单
      while (i < db.getRowCount() - 1) {
        strMenuId = db.getElementValue(i + 1, "MENUID").trim();
        if (strMenuId.startsWith(mn.getNodeId().substring(0, 2))) {
          // 子菜单
          i++;
          log.debug(strMenuId);
          strPurview = db.getElementValue(i, "MPURVIEW").trim();
          //						if (!CommonTools.isMenuShow(strPurview, purview))
          //							continue;
          strMenuNameCn = db.getElementValue(i, "MNAMEC").trim();
          if (strMenuNameCn.indexOf("(&") > 0)
            strMenuNameCn = strMenuNameCn.substring(0, strMenuNameCn.indexOf("(&"));
          strMenuNameEn = db.getElementValue(i, "MNAMEE").trim();
          strUrl = db.getElementValue(i, "MFILEE").trim();
          if (strUrl.length() > 0) {
            if (strUrl.startsWith("/")) strUrl = getContextPath() + strUrl;
            strUrl = CommonTools.encodeUrl(strUrl);
          }
          MenuItem mi = new MenuItem();
          mi.setMenuId(strMenuId);
          mi.setChineseName(strMenuNameCn);
          mi.setEnglishName(strMenuNameEn);
          mi.setUrl(strUrl);
          mi.setPurview(strPurview);
          mn.addMenuItem(mi);
          htIndexById.put(strMenuId, mn.getNodeId());
        } else {
          break;
        }
      }
      htMenus.put(mn.getNodeId(), mn);
    }

    // 释放DATABEAN资源
    db.release();
    reload = false;
    loadMenuTime = System.currentTimeMillis();
    log.info(loadMenuTime);
  }