/**
  * Perform process.
  *
  * @return Message (clear text)
  * @throws Exception if not successful
  */
 protected String doIt() throws Exception {
   if (m_C_ProjectLine_ID == 0) throw new IllegalArgumentException("No Project Line");
   MProjectLine projectLine = new MProjectLine(getCtx(), m_C_ProjectLine_ID, get_TrxName());
   log.info("doIt - " + projectLine);
   if (projectLine.getM_Product_ID() == 0) throw new IllegalArgumentException("No Product");
   //
   MProject project = new MProject(getCtx(), projectLine.getC_Project_ID(), get_TrxName());
   if (project.getM_PriceList_ID() == 0) throw new IllegalArgumentException("No PriceList");
   //
   boolean isSOTrx = true;
   MProductPricing pp =
       new MProductPricing(
           projectLine.getM_Product_ID(),
           project.getC_BPartner_ID(),
           projectLine.getPlannedQty(),
           isSOTrx);
   pp.setM_PriceList_ID(project.getM_PriceList_ID());
   pp.setPriceDate(project.getDateContract());
   //
   projectLine.setPlannedPrice(pp.getPriceStd());
   projectLine.setPlannedMarginAmt(pp.getPriceStd().subtract(pp.getPriceLimit()));
   projectLine.saveEx();
   //
   String retValue =
       Msg.getElement(getCtx(), "PriceList")
           + pp.getPriceList()
           + " - "
           + Msg.getElement(getCtx(), "PriceStd")
           + pp.getPriceStd()
           + " - "
           + Msg.getElement(getCtx(), "PriceLimit")
           + pp.getPriceLimit();
   return retValue;
 } //	doIt
Example #2
0
 /**
  * Get Measure Display Text
  *
  * @return Measure Display Text
  */
 public String getXAxisText() {
   MMeasure measure = getMeasure();
   if (measure != null
       && X_PA_Measure.MEASUREDATATYPE_StatusQtyAmount.equals(measure.getMeasureDataType())) {
     if (X_PA_Measure.MEASURETYPE_Request.equals(measure.getMeasureType()))
       return Msg.getElement(getCtx(), "R_Status_ID");
     if (X_PA_Measure.MEASURETYPE_Project.equals(measure.getMeasureType()))
       return Msg.getElement(getCtx(), "C_Phase_ID");
   }
   String value = getMeasureDisplay();
   String display = MRefList.getListName(getCtx(), X_Ref_PA_Goal_Scope.AD_Reference_ID, value);
   return display == null ? value : display;
 } //	getMeasureDisplayText
Example #3
0
 /**
  * Get individual Change HTML
  *
  * @param sb string to append to
  * @param columnName column name
  */
 private void getChangeHTML(StringBuffer sb, String columnName) {
   if (get_Value(columnName) != null) {
     if (sb.length() > 0) sb.append("<br>");
     sb.append(Msg.getElement(getCtx(), columnName))
         .append(": ")
         .append(get_DisplayValue(columnName, true));
   } else {
     String nc = getNullColumns();
     if (nc != null && nc.indexOf(columnName) != -1) {
       if (sb.length() > 0) sb.append("<br>");
       sb.append("(").append(Msg.getElement(getCtx(), columnName)).append(")");
     }
   }
 } //	getChangeHTML
Example #4
0
  public static ElementBean getMsg(Properties ctx, String text) {
    String language = Env.getContext(ctx, UdiConstants.LANGUAGE_CTX_PARAM);

    if (language == null || language.trim().length() == 0) {
      language = Language.AD_Language_en_US;
    }

    String msg = Msg.getElement(language, text, true);

    if (msg == null || msg == "") {
      msg = Msg.translate(language, text);
    }

    if (msg == null || msg == "") {
      msg = text;
    }

    int ind = msg.indexOf(Env.NL);
    if (ind != -1) msg = msg.substring(0, ind);

    ElementBean elementBean = new ElementBean();
    elementBean.setColumnName(text);
    elementBean.setDescription(msg);
    elementBean.setHelp(msg);
    elementBean.setName(msg);
    elementBean.setPrintName(msg);

    return elementBean;
  }
Example #5
0
 @Override
 protected boolean beforeSave(boolean newRecord) {
   if (isUsingDictionary()) {
     StringBuilder msg = new StringBuilder();
     if (Util.isEmpty(getPathDictionary())) {
       msg.append(Msg.getElement(getCtx(), COLUMNNAME_PathDictionary));
     }
     if (getDictWordLength() <= 0) {
       if (msg.length() > 0) msg.append(", ");
       msg.append(Msg.getElement(getCtx(), COLUMNNAME_DictWordLength));
     }
     if (msg.length() > 0) {
       log.saveError("FillMandatory", msg.toString());
       return false;
     }
   }
   return true;
 }
Example #6
0
  @Override
  public void setValue(Object value) {
    m_value = value;
    String text = m_text;

    //  Nothing to show or Record_ID
    if (value == null || super.getColumnName().equals("Record_ID")) {;
    } else if (super.getColumnName().equals("DocAction")
        && !MSysConfig.getBooleanValue(
            MSysConfig.DOCACTIONBUTTON_SHOWACTIONNAME, false, Env.getAD_Client_ID(Env.getCtx()))) {
      text = Msg.getElement(Env.getCtx(), "DocAction");
    } else if (m_values != null) {
      text = (String) m_values.get(value);
    } else if (m_lookup != null) {
      NamePair pp = m_lookup.get(value);
      if (pp != null) text = pp.getName();
    }
    getComponent().setLabel(text != null ? text : "");
  }
Example #7
0
  /**
   * Before Save
   *
   * @param newRecord new
   * @return true
   */
  @Override
  protected boolean beforeSave(boolean newRecord) {
    //	if (getMultiplier(this) == null)	//	error
    //		setMeasureDisplay(getMeasureScope());

    //	Measure required if nor Summary
    if (!isSummary() && getPA_Measure_ID() == 0) {
      log.saveError("FillMandatory", Msg.getElement(getCtx(), "PA_Measure_ID"));
      return false;
    }
    if (isSummary() && getPA_Measure_ID() != 0) setPA_Measure_ID(0);

    //	User/Role Check
    if ((newRecord || is_ValueChanged("AD_User_ID") || is_ValueChanged("AD_Role_ID"))
        && getAD_User_ID() != 0) {
      MUser user = MUser.get(getCtx(), getAD_User_ID());
      MRole[] roles = user.getRoles(getAD_Org_ID());
      if (roles.length == 0) // 	No Role
      setAD_Role_ID(0);
      else if (roles.length == 1) // 	One
      setAD_Role_ID(roles[0].getAD_Role_ID());
      else {
        int AD_Role_ID = getAD_Role_ID();
        if (AD_Role_ID != 0) // 	validate
        {
          boolean found = false;
          for (MRole element : roles) {
            if (AD_Role_ID == element.getAD_Role_ID()) {
              found = true;
              break;
            }
          }
          if (!found) AD_Role_ID = 0;
        }
        if (AD_Role_ID == 0) // 	set to first one
        setAD_Role_ID(roles[0].getAD_Role_ID());
      } //	multiple roles
    } //	user check

    return true;
  } //	beforeSave
Example #8
0
  /** Create/Save Account */
  private void action_Save() {
    log.info("");
    /** Check completeness (mandatory fields) ... and for duplicates */
    StringBuffer sb = new StringBuffer();
    StringBuffer sql =
        new StringBuffer("SELECT C_ValidCombination_ID, Alias FROM C_ValidCombination WHERE ");
    Object value = null;
    if (s_AcctSchema.isHasAlias()) {
      value = f_Alias.getValue().toString();
      if (value == null) sb.append(Msg.translate(Env.getCtx(), "Alias")).append(", ");
    }
    MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
    for (int i = 0; i < elements.length; i++) {
      MAcctSchemaElement ase = elements[i];
      String type = ase.getElementType();
      //
      if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) {
        value = f_AD_Org_ID.getValue();
        sql.append("AD_Org_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account)) {
        value = f_Account_ID.getValue();
        sql.append("Account_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
        value = f_SubAcct_ID.getValue();
        sql.append("C_SubAcct_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Product)) {
        value = f_M_Product_ID.getValue();
        sql.append("M_Product_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) {
        value = f_C_BPartner_ID.getValue();
        sql.append("C_BPartner_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) {
        value = f_C_Campaign_ID.getValue();
        sql.append("C_Campaign_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) {
        value = f_C_LocFrom_ID.getValue();
        sql.append("C_LocFrom_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) {
        value = f_C_LocTo_ID.getValue();
        sql.append("C_LocTo_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Project)) {
        value = f_C_Project_ID.getValue();
        sql.append("C_Project_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) {
        value = f_C_SalesRegion_ID.getValue();
        sql.append("C_SalesRegion_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) {
        value = f_AD_OrgTrx_ID.getValue();
        sql.append("AD_OrgTrx_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) {
        value = f_C_Activity_ID.getValue();
        sql.append("C_Activity_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) {
        value = f_User1_ID.getValue();
        sql.append("User1_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
        value = f_User2_ID.getValue();
        sql.append("User2_ID");
        if (value == null) sql.append(" IS NULL AND ");
        else sql.append("=").append(value).append(" AND ");
      }
      //
      if (ase.isMandatory() && value == null) sb.append(ase.getName()).append(", ");
    } //	Fields in Element Order

    if (sb.length() != 0) {
      ADialog.error(m_WindowNo, this, "FillMandatory", sb.substring(0, sb.length() - 2));
      return;
    }
    if (f_AD_Org_ID == null || f_AD_Org_ID.getValue() == null) {
      ADialog.error(m_WindowNo, this, "FillMandatory", Msg.getElement(Env.getCtx(), "AD_Org_ID"));
      return;
    }
    if (f_Account_ID == null || f_Account_ID.getValue() == null) {
      ADialog.error(m_WindowNo, this, "FillMandatory", Msg.getElement(Env.getCtx(), "Account_ID"));
      return;
    }

    /** Check if already exists */
    sql.append("AD_Client_ID=? AND C_AcctSchema_ID=?");
    log.fine("Check = " + sql.toString());
    int IDvalue = 0;
    String Alias = null;
    try {
      PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
      pstmt.setInt(1, m_AD_Client_ID);
      pstmt.setInt(2, s_AcctSchema.getC_AcctSchema_ID());
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        IDvalue = rs.getInt(1);
        Alias = rs.getString(2);
      }
      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql.toString(), e);
      IDvalue = 0;
    }
    log.fine("ID=" + IDvalue + ", Alias=" + Alias);

    if (Alias == null) Alias = "";

    //	We have an account like this already - check alias
    if (IDvalue != 0 && s_AcctSchema.isHasAlias() && !f_Alias.getValue().toString().equals(Alias)) {
      sql = new StringBuffer("UPDATE C_ValidCombination SET Alias=");
      if (f_Alias.getValue().toString().length() == 0) sql.append("NULL");
      else sql.append("'").append(f_Alias.getValue()).append("'");
      sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue);
      int i = 0;
      try {
        java.sql.PreparedStatement stmt =
            DB.prepareStatement(
                sql.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
        i = stmt.executeUpdate();
        stmt.close();
      } catch (SQLException e) {
        log.log(Level.SEVERE, sql.toString(), e);
      }
      if (i == 0) ADialog.error(m_WindowNo, this, "AccountNotUpdated");
    }

    //	load and display
    if (IDvalue != 0) {
      loadInfo(IDvalue, s_AcctSchema.getC_AcctSchema_ID());
      action_Find(false);
      return;
    }

    log.config("New");
    Alias = null;
    if (f_Alias != null) Alias = f_Alias.getValue().toString();
    int C_SubAcct_ID = 0;
    if (f_SubAcct_ID != null && f_SubAcct_ID.getValue() != null)
      C_SubAcct_ID = ((Integer) f_SubAcct_ID.getValue()).intValue();
    int M_Product_ID = 0;
    if (f_M_Product_ID != null && f_M_Product_ID.getValue() != null)
      M_Product_ID = ((Integer) f_M_Product_ID.getValue()).intValue();
    int C_BPartner_ID = 0;
    if (f_C_BPartner_ID != null && f_C_BPartner_ID.getValue() != null)
      C_BPartner_ID = ((Integer) f_C_BPartner_ID.getValue()).intValue();
    int AD_OrgTrx_ID = 0;
    if (f_AD_OrgTrx_ID != null && f_AD_OrgTrx_ID.getValue() != null)
      AD_OrgTrx_ID = ((Integer) f_AD_OrgTrx_ID.getValue()).intValue();
    int C_LocFrom_ID = 0;
    if (f_C_LocFrom_ID != null && f_C_LocFrom_ID.getValue() != null)
      C_LocFrom_ID = ((Integer) f_C_LocFrom_ID.getValue()).intValue();
    int C_LocTo_ID = 0;
    if (f_C_LocTo_ID != null && f_C_LocTo_ID.getValue() != null)
      C_LocTo_ID = ((Integer) f_C_LocTo_ID.getValue()).intValue();
    int C_SRegion_ID = 0;
    if (f_C_SalesRegion_ID != null && f_C_SalesRegion_ID.getValue() != null)
      C_SRegion_ID = ((Integer) f_C_SalesRegion_ID.getValue()).intValue();
    int C_Project_ID = 0;
    if (f_C_Project_ID != null && f_C_Project_ID.getValue() != null)
      C_Project_ID = ((Integer) f_C_Project_ID.getValue()).intValue();
    int C_Campaign_ID = 0;
    if (f_C_Campaign_ID != null && f_C_Campaign_ID.getValue() != null)
      C_Campaign_ID = ((Integer) f_C_Campaign_ID.getValue()).intValue();
    int C_Activity_ID = 0;
    if (f_C_Activity_ID != null && f_C_Activity_ID.getValue() != null)
      C_Activity_ID = ((Integer) f_C_Activity_ID.getValue()).intValue();
    int User1_ID = 0;
    if (f_User1_ID != null && f_User1_ID.getValue() != null)
      User1_ID = ((Integer) f_User1_ID.getValue()).intValue();
    int User2_ID = 0;
    if (f_User2_ID != null && f_User2_ID.getValue() != null)
      User2_ID = ((Integer) f_User2_ID.getValue()).intValue();

    MAccount acct =
        MAccount.get(
            Env.getCtx(),
            m_AD_Client_ID,
            ((Integer) f_AD_Org_ID.getValue()).intValue(),
            s_AcctSchema.getC_AcctSchema_ID(),
            ((Integer) f_Account_ID.getValue()).intValue(),
            C_SubAcct_ID,
            M_Product_ID,
            C_BPartner_ID,
            AD_OrgTrx_ID,
            C_LocFrom_ID,
            C_LocTo_ID,
            C_SRegion_ID,
            C_Project_ID,
            C_Campaign_ID,
            C_Activity_ID,
            User1_ID,
            User2_ID,
            0,
            0);
    if (acct != null && acct.get_ID() == 0) acct.save();

    //  Show Info
    if (acct == null || acct.get_ID() == 0) loadInfo(0, 0);
    else {
      //	Update Account with optional Alias
      if (Alias != null && Alias.length() > 0) {
        acct.setAlias(Alias);
        acct.save();
      }
      loadInfo(acct.get_ID(), s_AcctSchema.getC_AcctSchema_ID());
    }
    action_Find(false);
  } //	action_Save
 /**
  * Create Balancing Entry
  *
  * @param asDefaultAccts acct schema default accounts
  * @param journal journal
  * @param drTotal dr
  * @param crTotal cr
  * @param AD_Org_ID org
  * @param lineNo base line no
  */
 private void createBalancing(
     MAcctSchemaDefault asDefaultAccts,
     MJournal journal,
     BigDecimal drTotal,
     BigDecimal crTotal,
     int AD_Org_ID,
     int lineNo) {
   if (journal == null) throw new IllegalArgumentException("Jornal is null");
   //		CR Entry = Gain
   if (drTotal.signum() != 0) {
     MJournalLine line = new MJournalLine(journal);
     line.setLine(lineNo + 1);
     MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedGain_Acct());
     MAccount acct =
         MAccount.get(
             getCtx(),
             asDefaultAccts.getAD_Client_ID(),
             AD_Org_ID,
             asDefaultAccts.getC_AcctSchema_ID(),
             base.getAccount_ID(),
             base.getC_SubAcct_ID(),
             base.getM_Product_ID(),
             base.getC_BPartner_ID(),
             base.getAD_OrgTrx_ID(),
             base.getC_LocFrom_ID(),
             base.getC_LocTo_ID(),
             base.getC_SalesRegion_ID(),
             base.getC_Project_ID(),
             base.getC_Campaign_ID(),
             base.getC_Activity_ID(),
             base.getUser1_ID(),
             base.getUser2_ID(),
             base.getUserElement1_ID(),
             base.getUserElement2_ID());
     line.setDescription(Msg.getElement(getCtx(), "UnrealizedGain_Acct"));
     // TODO: C_ValidCombination_ID is no longer a column because we have DR/CR accounts
     // line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
     line.setAmtSourceCr(drTotal);
     line.setAmtAcctCr(drTotal);
     line.save();
   }
   //	DR Entry = Loss
   if (crTotal.signum() != 0) {
     MJournalLine line = new MJournalLine(journal);
     line.setLine(lineNo + 2);
     MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedLoss_Acct());
     MAccount acct =
         MAccount.get(
             getCtx(),
             asDefaultAccts.getAD_Client_ID(),
             AD_Org_ID,
             asDefaultAccts.getC_AcctSchema_ID(),
             base.getAccount_ID(),
             base.getC_SubAcct_ID(),
             base.getM_Product_ID(),
             base.getC_BPartner_ID(),
             base.getAD_OrgTrx_ID(),
             base.getC_LocFrom_ID(),
             base.getC_LocTo_ID(),
             base.getC_SalesRegion_ID(),
             base.getC_Project_ID(),
             base.getC_Campaign_ID(),
             base.getC_Activity_ID(),
             base.getUser1_ID(),
             base.getUser2_ID(),
             base.getUserElement1_ID(),
             base.getUserElement2_ID());
     line.setDescription(Msg.getElement(getCtx(), "UnrealizedLoss_Acct"));
     // TODO: C_ValidCombination_ID is no longer a column because we have DR/CR accounts
     // line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
     line.setAmtSourceDr(crTotal);
     line.setAmtAcctDr(crTotal);
     line.save();
   }
 } //	createBalancing
Example #10
0
  @SuppressWarnings("serial")
  protected Component doCreatePart(Component parent) {
    PageDefinition pagedef =
        Executions.getCurrent()
            .getPageDefinition(ThemeManager.getThemeResource("zul/desktop/desktop.zul"));
    Component page = Executions.createComponents(pagedef, parent, null);
    layout = (Borderlayout) page.getFellow("layout");
    headerContainer = page.getFellow("northBody");
    pnlHead = (HeaderPanel) headerContainer.getFellow("header");

    layout.addEventListener("onZoom", this);
    layout.addEventListener(DrillEvent.ON_DRILL_DOWN, this);

    West w = layout.getWest();
    w.addEventListener(
        Events.ON_OPEN,
        new EventListener<Event>() {
          @Override
          public void onEvent(Event event) throws Exception {
            OpenEvent oe = (OpenEvent) event;
            updateMenuCollapsedPreference(!oe.isOpen());
          }
        });
    w.addEventListener(
        Events.ON_SWIPE,
        new EventListener<SwipeEvent>() {

          @Override
          public void onEvent(SwipeEvent event) throws Exception {
            if ("left".equals(event.getSwipeDirection())) {
              West w = (West) event.getTarget();
              if (w.isOpen()) {
                w.setOpen(false);
                updateMenuCollapsedPreference(true);
              }
            }
          }
        });

    w.addEventListener(
        Events.ON_SIZE,
        new EventListener<Event>() {

          @Override
          public void onEvent(Event event) throws Exception {
            West west = (West) event.getTarget();
            updateSideControllerWidthPreference(west.getWidth());
          }
        });

    UserPreference pref = SessionManager.getSessionApplication().getUserPreference();
    boolean menuCollapsed = pref.isPropertyBool(UserPreference.P_MENU_COLLAPSED);
    w.setOpen(!menuCollapsed);

    East e = layout.getEast();
    e.addEventListener(
        Events.ON_OPEN,
        new EventListener<Event>() {
          @Override
          public void onEvent(Event event) throws Exception {
            OpenEvent oe = (OpenEvent) event;
            updateHelpCollapsedPreference(!oe.isOpen());
            HtmlBasedComponent comp = windowContainer.getComponent();
            if (comp != null) {
              contextHelp.setVisible(!oe.isOpen());
              if (!oe.isOpen()) layout.getEast().setVisible(false);
            }
          }
        });

    e.addEventListener(
        Events.ON_SWIPE,
        new EventListener<SwipeEvent>() {

          @Override
          public void onEvent(SwipeEvent event) throws Exception {
            if ("right".equals(event.getSwipeDirection())) {
              East e = (East) event.getTarget();
              if (e.isOpen()) {
                e.setOpen(false);
                updateHelpCollapsedPreference(true);
              }
            }
          }
        });

    e.addEventListener(
        Events.ON_SIZE,
        new EventListener<Event>() {

          @Override
          public void onEvent(Event event) throws Exception {
            East east = (East) event.getTarget();
            updateHelpWidthPreference(east.getWidth());
          }
        });

    String westWidth = getWestWidthPreference();
    String eastWidth = getEastWidthPreference();

    // Set preference width
    if (westWidth != null || eastWidth != null) {

      // If both panels have prefered size check that the sum is not bigger than the browser
      if (westWidth != null && eastWidth != null) {
        ClientInfo browserInfo = getClientInfo();
        int browserWidth = browserInfo.desktopWidth;
        int wWidth = Integer.valueOf(westWidth.replace("px", ""));
        int eWidth = Integer.valueOf(eastWidth.replace("px", ""));

        if (eWidth + wWidth <= browserWidth) {
          w.setWidth(westWidth);
          e.setWidth(eastWidth);
        }

      } else if (westWidth != null) w.setWidth(westWidth);
      else if (eastWidth != null) e.setWidth(eastWidth);
    }

    boolean helpCollapsed = pref.isPropertyBool(UserPreference.P_HELP_COLLAPSED);
    e.setVisible(!helpCollapsed);

    helpController.render(e, this);

    Center windowArea = layout.getCenter();

    windowContainer.createPart(windowArea);

    homeTab = new Tabpanel();
    windowContainer.addWindow(
        homeTab, Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Home")), false, null);
    homeTab.getLinkedTab().setSclass("desktop-hometab");
    homeTab.setSclass("desktop-home-tabpanel");
    BusyDialog busyDialog = new BusyDialog();
    busyDialog.setShadow(false);
    homeTab.appendChild(busyDialog);

    // register as 0
    registerWindow(homeTab);

    BroadcastMessageWindow messageWindow = new BroadcastMessageWindow(pnlHead);
    BroadcastMsgUtil.showPendingMessage(Env.getAD_User_ID(Env.getCtx()), messageWindow);

    if (!layout.getDesktop().isServerPushEnabled()) {
      layout.getDesktop().enableServerPush(true);
    }

    Runnable runnable =
        new Runnable() {
          public void run() {
            try {
              Thread.sleep(100);
            } catch (InterruptedException e) {
            }

            IServerPushCallback callback =
                new IServerPushCallback() {
                  public void updateUI() {
                    Properties ctx =
                        (Properties)
                            layout
                                .getDesktop()
                                .getSession()
                                .getAttribute(SessionContextListener.SESSION_CTX);
                    try {
                      ServerContext.setCurrentInstance(ctx);
                      renderHomeTab();
                    } finally {
                      ServerContext.dispose();
                    }
                  }
                };
            ServerPushTemplate template = new ServerPushTemplate(layout.getDesktop());
            template.executeAsync(callback);
          }
        };

    Adempiere.getThreadPoolExecutor().submit(new DesktopRunnable(runnable, layout.getDesktop()));

    ToolBar toolbar = new ToolBar();
    windowContainer.getComponent().appendChild(toolbar);

    showHeader =
        new ToolBarButton() {
          @Override
          public void onPageDetached(Page page) {
            super.onPageDetached(page);
            if (DefaultDesktop.this.headerPopup != null) {
              DefaultDesktop.this.headerPopup.setPage(null);
            }
          }
        };
    toolbar.appendChild(showHeader);
    showHeader.setImage(ThemeManager.getThemeResource(IMAGES_THREELINE_MENU_PNG));
    showHeader.addEventListener(Events.ON_CLICK, this);
    showHeader.setSclass("window-container-toolbar-btn");
    showHeader.setStyle("cursor: pointer; border: 1px solid transparent; padding: 2px;");
    showHeader.setVisible(false);

    max = new ToolBarButton();
    toolbar.appendChild(max);
    max.setImage(ThemeManager.getThemeResource(IMAGES_UPARROW_PNG));
    max.addEventListener(Events.ON_CLICK, this);
    max.setSclass("window-container-toolbar-btn");
    max.setStyle("cursor: pointer; border: 1px solid transparent; padding: 2px;");

    contextHelp = new ToolBarButton();
    toolbar.appendChild(contextHelp);
    contextHelp.setImage(ThemeManager.getThemeResource(IMAGES_CONTEXT_HELP_PNG));
    contextHelp.addEventListener(Events.ON_CLICK, this);
    contextHelp.setSclass("window-container-toolbar-btn context-help-btn");
    contextHelp.setStyle("cursor: pointer; border: 1px solid transparent; padding: 2px;");
    contextHelp.setTooltiptext(Util.cleanAmp(Msg.getElement(Env.getCtx(), "AD_CtxHelp_ID")));
    contextHelp.setVisible(!e.isVisible());

    boolean headerCollapsed = pref.isPropertyBool(UserPreference.P_HEADER_COLLAPSED);
    if (headerCollapsed) {
      collapseHeader();
    }

    return layout;
  }
Example #11
0
 /**
  * Static Init
  *
  * @throws Exception
  */
 private void jbInit() throws Exception {
   CompiereColor.setBackground(panel);
   newBorder = new TitledBorder("");
   accountBorder = new TitledBorder("");
   mainPanel.setLayout(mainLayout);
   newPanel.setBorder(newBorder);
   newPanel.setLayout(newLayout);
   newBorder.setTitle(Msg.getMsg(Env.getCtx(), "ChargeNewAccount"));
   valueLabel.setText(Msg.translate(Env.getCtx(), "Value"));
   isExpense.setSelected(true);
   isExpense.setText(Msg.getMsg(Env.getCtx(), "Expense"));
   nameLabel.setText(Msg.translate(Env.getCtx(), "Name"));
   nameField.setColumns(20);
   valueField.setColumns(10);
   newButton.setText(
       Msg.getMsg(Env.getCtx(), "Create") + " " + Util.cleanAmp(Msg.getMsg(Env.getCtx(), "New")));
   newButton.addActionListener(this);
   accountPanel.setBorder(accountBorder);
   accountPanel.setLayout(accountLayout);
   accountBorder.setTitle(Msg.getMsg(Env.getCtx(), "ChargeFromAccount"));
   accountButton.setText(
       Msg.getMsg(Env.getCtx(), "Create")
           + " "
           + Msg.getMsg(Env.getCtx(), "From")
           + " "
           + Msg.getElement(Env.getCtx(), "Account_ID"));
   accountButton.addActionListener(this);
   accountOKPanel.setLayout(accountOKLayout);
   accountOKLayout.setAlignment(FlowLayout.RIGHT);
   confirmPanel.setActionListener(this);
   //
   mainPanel.add(newPanel, BorderLayout.NORTH);
   newPanel.add(
       valueLabel,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(5, 5, 5, 5),
           0,
           0));
   newPanel.add(
       valueField,
       new GridBagConstraints(
           1,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(5, 0, 5, 5),
           0,
           0));
   newPanel.add(
       nameLabel,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(5, 5, 5, 5),
           0,
           0));
   newPanel.add(
       nameField,
       new GridBagConstraints(
           1,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(5, 0, 5, 5),
           0,
           0));
   newPanel.add(
       isExpense,
       new GridBagConstraints(
           2,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(5, 5, 5, 5),
           0,
           0));
   newPanel.add(
       newButton,
       new GridBagConstraints(
           2,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(5, 5, 5, 5),
           0,
           0));
   mainPanel.add(accountPanel, BorderLayout.CENTER);
   accountPanel.add(accountOKPanel, BorderLayout.SOUTH);
   accountOKPanel.add(accountButton, null);
   accountPanel.add(dataPane, BorderLayout.CENTER);
   dataPane.getViewport().add(dataTable, null);
 } //  jbInit
Example #12
0
/**
 * Product Attribute Table. Select one or two attributes for view/etc.
 *
 * @author Jorg Janke
 * @version $Id: VAttributeGrid.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
 */
public class VAttributeGrid extends CPanel implements FormPanel, ChangeListener, ActionListener {
  /** */
  private static final long serialVersionUID = 3207678550566202041L;

  /**
   * Init
   *
   * @param WindowNo
   * @param frame
   */
  public void init(int WindowNo, FormFrame frame) {
    m_WindowNo = WindowNo;
    m_frame = frame;
    //	Layout
    frame.getContentPane().add(this, BorderLayout.CENTER);
    this.setLayout(new BorderLayout());
    this.add(tabbedPane, BorderLayout.CENTER);
    this.add(confirmPanel, BorderLayout.SOUTH);
    tabbedPane.addChangeListener(this);
    confirmPanel.addActionListener(this);
    //
    tabbedPane.add(selectPanel, Msg.getMsg(Env.getCtx(), "Selection"));
    selectPanel.add(attributeLabel1, new ALayoutConstraint(0, 0));
    m_attributes = MAttribute.getOfClient(Env.getCtx(), true, true);
    Vector<KeyNamePair> vector = new Vector<KeyNamePair>();
    vector.add(new KeyNamePair(0, ""));
    for (int i = 0; i < m_attributes.length; i++) vector.add(m_attributes[i].getKeyNamePair());
    attributeCombo1 = new CComboBox(vector);
    selectPanel.add(attributeCombo1, null);
    selectPanel.add(attributeLabel2, new ALayoutConstraint(1, 0));
    attributeCombo2 = new CComboBox(vector);
    selectPanel.add(attributeCombo2, null);
    //
    fillPicks();
    selectPanel.add(labelPriceList, new ALayoutConstraint(2, 0));
    selectPanel.add(pickPriceList);
    selectPanel.add(labelWarehouse, new ALayoutConstraint(3, 0));
    selectPanel.add(pickWarehouse);
    //
    selectPanel.setPreferredSize(new Dimension(300, 200));
    //
    //	Grid
    tabbedPane.add(gridPanel, "AttributeGrid");
    modePanel.add(modeLabel);
    modePanel.add(modeCombo);
    modeCombo.addActionListener(this);
  } //	init

  /** Window No */
  private int m_WindowNo = 0;
  /** FormFrame */
  private FormFrame m_frame;
  /** Product Attributes */
  private MAttribute[] m_attributes = null;
  /** Setting Grid */
  private boolean m_setting = false;
  /** Logger */
  private static CLogger log = CLogger.getCLogger(VAttributeGrid.class);

  /** Modes */
  private static String[] MODES = new String[] {Msg.getMsg(Env.getCtx(), "ModeView")
        //	,Msg.getMsg(Env.getCtx(), "ModePO")
        //	,Msg.getMsg(Env.getCtx(), "ModePrice")
      };

  private static final int MODE_VIEW = 0;
  private static final int MODE_PO = 0;
  private static final int MODE_PRICE = 0;

  /** Price List Version */
  private int m_M_PriceList_Version_ID = 0;

  private DecimalFormat m_price = DisplayType.getNumberFormat(DisplayType.CostPrice);
  /** Warehouse */
  private int m_M_Warehouse_ID = 0;

  private DecimalFormat m_qty = DisplayType.getNumberFormat(DisplayType.Quantity);

  /** UI * */
  private CTabbedPane tabbedPane = new CTabbedPane();

  private CPanel selectPanel = new CPanel(new ALayout());
  private CLabel attributeLabel1 =
      new CLabel(Msg.getElement(Env.getCtx(), "M_Attribute_ID") + " 1");
  private CComboBox attributeCombo1 = null;
  private CLabel attributeLabel2 =
      new CLabel(Msg.getElement(Env.getCtx(), "M_Attribute_ID") + " 2");
  private CComboBox attributeCombo2 = null;
  private CLabel labelPriceList = new CLabel(Msg.getElement(Env.getCtx(), "M_PriceList_ID"));
  private VComboBox pickPriceList = new VComboBox();
  private CLabel labelWarehouse = new CLabel(Msg.getElement(Env.getCtx(), "M_Warehouse_ID"));
  private VComboBox pickWarehouse = new VComboBox();
  private ConfirmPanel confirmPanel = new ConfirmPanel(true);
  //
  private CPanel gridPanel = new CPanel(new BorderLayout());
  private CPanel modePanel = new CPanel();
  private CLabel modeLabel = new CLabel(Msg.getMsg(Env.getCtx(), "Mode"));
  private CComboBox modeCombo = new CComboBox(MODES);

  /** Dispose */
  public void dispose() {
    if (m_frame != null) m_frame.dispose();
    m_frame = null;
  } //	dispose

  /** Fill Picks with values */
  private void fillPicks() {
    //	Price List
    String sql =
        "SELECT M_PriceList_Version.M_PriceList_Version_ID,"
            + " M_PriceList_Version.Name || ' (' || c.Iso_Code || ')' AS ValueName "
            + "FROM M_PriceList_Version, M_PriceList pl, C_Currency c "
            + "WHERE M_PriceList_Version.M_PriceList_ID=pl.M_PriceList_ID"
            + " AND pl.C_Currency_ID=c.C_Currency_ID"
            + " AND M_PriceList_Version.IsActive='Y' AND pl.IsActive='Y'";
    //	Add Access & Order
    sql =
        MRole.getDefault()
                .addAccessSQL(sql, "M_PriceList_Version", true, false) // fully qualidfied - RO
            + " ORDER BY M_PriceList_Version.Name";
    try {
      pickPriceList.addItem(new KeyNamePair(0, ""));
      PreparedStatement pstmt = DB.prepareStatement(sql, null);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        KeyNamePair kn = new KeyNamePair(rs.getInt(1), rs.getString(2));
        pickPriceList.addItem(kn);
      }
      rs.close();
      pstmt.close();

      //	Warehouse
      sql =
          "SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName "
              + "FROM M_Warehouse "
              + "WHERE IsActive='Y'";
      sql =
          MRole.getDefault().addAccessSQL(sql, "M_Warehouse", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO)
              + " ORDER BY Value";
      pickWarehouse.addItem(new KeyNamePair(0, ""));
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        KeyNamePair kn = new KeyNamePair(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
        pickWarehouse.addItem(kn);
      }
      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }
  } //	fillPicks

  /**
   * Change Listener
   *
   * @param e event
   */
  public void stateChanged(ChangeEvent e) {
    if (e.getSource() != tabbedPane) return;
    if (tabbedPane.getSelectedIndex() == 1) createGrid();
  } //	stateChanged

  /**
   * Action Performed
   *
   * @param e event
   */
  public void actionPerformed(ActionEvent e) {
    //	log.fine(e.toString());
    if (e.getSource() == modeCombo) createGrid();
    else if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
      if (tabbedPane.getSelectedIndex() == 0) createGrid();
      else gridOK();
    } else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) m_frame.dispose();
  } //	actionPerformed

  private void gridOK() {
    int mode = modeCombo.getSelectedIndex();
    //	Create PO
    if (mode == MODE_PO) {
      createPO();
      modeCombo.setSelectedIndex(MODE_VIEW);
      return;
    }
    //	Update Prices
    else if (mode == MODE_PRICE) {
      updatePrices();
      modeCombo.setSelectedIndex(MODE_VIEW);
      return;
    } else if (mode == MODE_VIEW) ;
    m_frame.dispose();
  } //	gridOK

  private void createPO() {}

  private void updatePrices() {}

  /** Create Grid */
  private void createGrid() {
    if (attributeCombo1 == null || m_setting) return; // 	init
    int indexAttr1 = attributeCombo1.getSelectedIndex();
    int indexAttr2 = attributeCombo2.getSelectedIndex();
    if (indexAttr1 == indexAttr2) {
      log.warning("Same Attribute Selected");
      tabbedPane.setSelectedIndex(0);
      return;
    }
    m_setting = true;
    m_M_PriceList_Version_ID = 0;
    KeyNamePair pl = (KeyNamePair) pickPriceList.getSelectedItem();
    if (pl != null) m_M_PriceList_Version_ID = pl.getKey();
    m_M_Warehouse_ID = 0;
    KeyNamePair wh = (KeyNamePair) pickWarehouse.getSelectedItem();
    if (wh != null) m_M_Warehouse_ID = wh.getKey();

    //	x dimension
    int cols = 2;
    MAttributeValue[] xValues = null;
    if (indexAttr1 > 0) xValues = m_attributes[indexAttr1 - 1].getMAttributeValues();
    if (xValues != null) {
      cols = xValues.length;
      log.info("X - " + m_attributes[indexAttr1 - 1].getName() + " #" + xValues.length);
    }

    //	y dimension
    int rows = 2;
    MAttributeValue[] yValues = null;
    if (indexAttr2 > 0) yValues = m_attributes[indexAttr2 - 1].getMAttributeValues();
    if (yValues != null) {
      rows = yValues.length;
      log.info("Y - " + m_attributes[indexAttr2 - 1].getName() + " #" + yValues.length);
    }

    //
    gridPanel.removeAll();
    CPanel grid = new CPanel(new GridLayout(rows, cols, 5, 5));
    gridPanel.add(modePanel, BorderLayout.NORTH);
    gridPanel.add(new CScrollPane(grid), BorderLayout.CENTER);
    //
    log.info("Rows=" + rows + " - Cols=" + cols);
    for (int row = 0; row < rows; row++) {
      for (int col = 0; col < cols; col++) {
        MAttributeValue xValue = null;
        if (xValues != null) xValue = xValues[col];
        MAttributeValue yValue = null;
        if (yValues != null) yValue = yValues[row];
        //	log.fine("Row=" + row + " - Col=" + col);
        //
        if (row == 0 && col == 0) {
          CPanel descr = new CPanel(new GridLayout(2, 1, 0, 0));
          if (xValues != null)
            descr.add(new JLabel(m_attributes[indexAttr1 - 1].getName(), JLabel.TRAILING));
          if (yValues != null) descr.add(new JLabel(m_attributes[indexAttr2 - 1].getName()));
          grid.add(descr);
        } else if (row == 0) // 	column labels
        {
          if (xValue != null) {
            grid.add(new JLabel(xValue.getName(), JLabel.TRAILING));
          } else grid.add(new JLabel());
        } else if (col == 0) // 	row labels
        {
          if (yValue != null) grid.add(new JLabel(yValue.getName()));
          else grid.add(new JLabel());
        } else {
          grid.add(getGridElement(xValue, yValue));
        }
      }
    }
    //
    tabbedPane.setSelectedIndex(1);
    m_setting = false;
    m_frame.pack();
  } //	createGrid

  /**
   * Get Grid Element
   *
   * @param xValue X value
   * @param yValue Y value
   * @return Panel with Info
   */
  private CPanel getGridElement(MAttributeValue xValue, MAttributeValue yValue) {
    CPanel element = new CPanel();
    element.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
    element.setLayout(new BoxLayout(element, BoxLayout.Y_AXIS));

    String sql = "SELECT * FROM M_Product WHERE IsActive='Y'";
    //	Product Attributes
    if (xValue != null)
      sql +=
          " AND M_AttributeSetInstance_ID IN "
              + "(SELECT M_AttributeSetInstance_ID "
              + "FROM M_AttributeInstance "
              + "WHERE M_Attribute_ID="
              + xValue.getM_Attribute_ID()
              + " AND M_AttributeValue_ID="
              + xValue.getM_AttributeValue_ID()
              + ")";
    if (yValue != null)
      sql +=
          " AND M_AttributeSetInstance_ID IN "
              + "(SELECT M_AttributeSetInstance_ID "
              + "FROM M_AttributeInstance "
              + "WHERE M_Attribute_ID="
              + yValue.getM_Attribute_ID()
              + " AND M_AttributeValue_ID="
              + yValue.getM_AttributeValue_ID()
              + ")";
    sql = MRole.getDefault().addAccessSQL(sql, "M_Product", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    int noProducts = 0;
    try {
      pstmt = DB.prepareStatement(sql, null);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        MProduct product = new MProduct(Env.getCtx(), rs, null);
        addProduct(element, product);
        noProducts++;
      }
      rs.close();
      pstmt.close();
      pstmt = null;
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    }
    try {
      if (pstmt != null) pstmt.close();
      pstmt = null;
    } catch (Exception e) {
      pstmt = null;
    }

    int mode = modeCombo.getSelectedIndex();
    //	No Products
    if (noProducts == 0 && mode == MODE_VIEW) {
      //	CButton button = ConfirmPanel.createNewButton(true);
      //	button.addActionListener(this);
      //	element.add(button);
    } else //	Additional Elements
    {
      if (mode == MODE_PRICE) {
        //	Price Field
      } else if (mode == MODE_PO) {
        //	Qty Field
      }
    }
    return element;
  } //	getGridElement

  /**
   * Add Product
   *
   * @param element panel
   * @param product product
   */
  private void addProduct(CPanel element, MProduct product) {
    Insets ii = new Insets(2, 4, 2, 4);
    int M_Product_ID = product.getM_Product_ID();
    CPanel pe = new CPanel();
    pe.setBorder(BorderFactory.createLineBorder(Color.BLUE, 1));
    pe.setLayout(new GridBagLayout());

    //	Product Value - Price
    pe.add(
        new JLabel(product.getValue()),
        new GridBagConstraints(
            0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    String formatted = "";
    if (m_M_PriceList_Version_ID != 0) {
      MProductPrice pp =
          MProductPrice.get(Env.getCtx(), m_M_PriceList_Version_ID, M_Product_ID, null);
      if (pp != null) {
        BigDecimal price = pp.getPriceStd();
        formatted = m_price.format(price);
      } else formatted = "-";
    }
    pe.add(
        new JLabel(formatted, JLabel.RIGHT),
        new GridBagConstraints(
            1, 0, 1, 1, .5, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, ii, 0, 0));

    //	Product Name - Qty
    pe.add(
        new JLabel(product.getName()),
        new GridBagConstraints(
            0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    formatted = "";
    if (m_M_Warehouse_ID != 0) {
      BigDecimal qty = MStorage.getQtyAvailable(m_M_Warehouse_ID, M_Product_ID, 0, null);
      if (qty == null) formatted = "-";
      else formatted = m_qty.format(qty);
    }
    pe.add(
        new JLabel(formatted, JLabel.RIGHT),
        new GridBagConstraints(
            1, 1, 1, 1, .5, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, ii, 0, 0));
    //
    element.add(pe);
  } //	addProduct

  /**
   * *********************************************************************** Test
   *
   * @param args ignored
   */
  public static void main(String[] args) {
    Adempiere.startup(true);
    Env.setContext(Env.getCtx(), "#AD_Client_ID", 11);
    FormFrame ff = new FormFrame();
    ff.openForm(1111, "org.compiere.apps.form.VAttributeGrid", "Attribute Table");
    ff.pack();
    AEnv.showCenterScreen(ff);
  } //	main
} //	VAttributeTable
 /**
  * Get Document Info
  *
  * @return document info (untranslated)
  */
 @Override
 public String getDocumentInfo() {
   return Msg.getElement(getCtx(), "C_AllocationHdr_ID") + " " + getDocumentNo();
 } //	getDocumentInfo