Search in sources :

Example 11 with NamePair

use of org.compiere.util.NamePair in project adempiere by adempiere.

the class Viewer method mouse_clicked.

//	cmd_drill
/**
	 * 	Mouse clicked
	 * 	@param e event
	 * 	@param rightClick true if right click
	 */
private void mouse_clicked(MouseEvent e, boolean rightClick) {
    Point point = e.getPoint();
    log.info("Right=" + rightClick + " - " + point.toString());
    if (rightClick) {
        m_ddQ = m_viewPanel.getDrillDown(point);
        m_daQ = m_viewPanel.getDrillAcross(point);
        m_ddM = null;
        m_daM = null;
        if (m_ddQ == null && m_daQ == null)
            return;
        //	Create Menu
        JPopupMenu pop = new JPopupMenu();
        Icon wi = Env.getImageIcon("mWindow.gif");
        if (m_ddQ != null) {
            m_ddM = new CMenuItem(m_ddQ.getDisplayName(Env.getCtx()), wi);
            m_ddM.setToolTipText(m_ddQ.toString());
            m_ddM.addActionListener(this);
            pop.add(m_ddM);
        }
        if (m_daQ != null) {
            m_daM = new CMenuItem(m_daQ.getDisplayName(Env.getCtx()), wi);
            m_daM.setToolTipText(m_daQ.toString());
            m_daM.addActionListener(this);
            pop.add(m_daM);
        }
        Point pp = e.getPoint();
        pop.show((Component) e.getSource(), pp.x, pp.y);
        return;
    }
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    if (m_drillDown) {
        MQuery query = m_viewPanel.getDrillDown(point);
        if (query != null) {
            log.info("Drill Down: " + query.getWhereClause(true));
            executeDrill(query);
        }
    } else if (comboDrill.getSelectedItem() != null && comboDrill.getSelectedIndex() > 0) {
        MQuery query = m_viewPanel.getDrillAcross(point);
        if (query != null) {
            NamePair pp = (NamePair) comboDrill.getSelectedItem();
            query.setTableName(pp.getID());
            log.info("Drill Accross: " + query.getWhereClause(true));
            executeDrill(query);
        }
    }
    //	setCursor
    cmd_drill();
}
Also used : CMenuItem(org.compiere.swing.CMenuItem) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) MQuery(org.compiere.model.MQuery) Point(java.awt.Point) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) JPopupMenu(javax.swing.JPopupMenu)

Example 12 with NamePair

use of org.compiere.util.NamePair in project adempiere by adempiere.

the class WButtonEditor method setValue.

@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 (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 : "");
}
Also used : NamePair(org.compiere.util.NamePair)

Example 13 with NamePair

use of org.compiere.util.NamePair in project adempiere by adempiere.

the class RecordInfoController method addLine.

/**
	 * 	Add Line
	 *	@param AD_Column_ID column
	 *	@param Updated updated
	 *	@param UpdatedBy user
	 *	@param OldValue old
	 *	@param NewValue new
	 */
private void addLine(int AD_Column_ID, Timestamp Updated, int UpdatedBy, String OldValue, String NewValue) {
    Vector<String> line = new Vector<String>();
    //	Column
    MColumn column = MColumn.get(Env.getCtx(), AD_Column_ID);
    //	No for specific column
    if (m_Field == null) {
        line.add(Msg.translate(Env.getCtx(), column.getColumnName()));
    }
    //
    if (OldValue != null && OldValue.equals(MChangeLog.NULL))
        OldValue = null;
    String showOldValue = OldValue;
    if (NewValue != null && NewValue.equals(MChangeLog.NULL))
        NewValue = null;
    String showNewValue = NewValue;
    //
    try {
        if (DisplayType.isText(column.getAD_Reference_ID()))
            ;
        else if (column.getAD_Reference_ID() == DisplayType.YesNo) {
            if (OldValue != null) {
                boolean yes = OldValue.equals("true") || OldValue.equals("Y");
                showOldValue = Msg.getMsg(Env.getCtx(), yes ? "Y" : "N");
            }
            if (NewValue != null) {
                boolean yes = NewValue.equals("true") || NewValue.equals("Y");
                showNewValue = Msg.getMsg(Env.getCtx(), yes ? "Y" : "N");
            }
        } else if (column.getAD_Reference_ID() == DisplayType.Amount) {
            if (OldValue != null)
                showOldValue = m_amtFormat.format(new BigDecimal(OldValue));
            if (NewValue != null)
                showNewValue = m_amtFormat.format(new BigDecimal(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.Integer) {
            if (OldValue != null)
                showOldValue = m_intFormat.format(new Integer(OldValue));
            if (NewValue != null)
                showNewValue = m_intFormat.format(new Integer(NewValue));
        } else if (DisplayType.isNumeric(column.getAD_Reference_ID())) {
            if (OldValue != null)
                showOldValue = m_numberFormat.format(new BigDecimal(OldValue));
            if (NewValue != null)
                showNewValue = m_numberFormat.format(new BigDecimal(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.Date) {
            if (OldValue != null)
                showOldValue = m_dateFormat.format(Timestamp.valueOf(OldValue));
            if (NewValue != null)
                showNewValue = m_dateFormat.format(Timestamp.valueOf(NewValue));
        } else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
            if (OldValue != null)
                showOldValue = m_dateTimeFormat.format(Timestamp.valueOf(OldValue));
            if (NewValue != null)
                showNewValue = m_dateTimeFormat.format(Timestamp.valueOf(NewValue));
        } else if (DisplayType.isLookup(column.getAD_Reference_ID())) {
            MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, AD_Column_ID, column.getAD_Reference_ID(), Env.getLanguage(Env.getCtx()), column.getColumnName(), column.getAD_Reference_Value_ID(), column.isParent(), null);
            if (OldValue != null) {
                Object key = OldValue;
                NamePair pp = lookup.get(key);
                if (pp != null)
                    showOldValue = pp.getName();
            }
            if (NewValue != null) {
                Object key = NewValue;
                NamePair pp = lookup.get(key);
                if (pp != null)
                    showNewValue = pp.getName();
            }
        } else if (DisplayType.isLOB(column.getAD_Reference_ID()))
            ;
    } catch (Exception e) {
        log.log(Level.WARNING, OldValue + "->" + NewValue, e);
    }
    //
    line.add(showNewValue);
    line.add(showOldValue);
    //	UpdatedBy
    MUser user = MUser.get(Env.getCtx(), UpdatedBy);
    line.add(user.getName());
    //	Updated
    line.add(m_dateFormat.format(Updated));
    //	No for specific column
    if (m_Field == null) {
        line.add(column.getColumnName());
    }
    m_data.add(line);
}
Also used : MColumn(org.compiere.model.MColumn) MLookup(org.compiere.model.MLookup) NamePair(org.compiere.util.NamePair) Vector(java.util.Vector) MUser(org.compiere.model.MUser) BigDecimal(java.math.BigDecimal)

Example 14 with NamePair

use of org.compiere.util.NamePair in project adempiere by adempiere.

the class Lookup method put.

//	put
/**
	 *	Put Value
	 *  @param key key
	 *  @param value value
	 */
public void put(int key, String value) {
    NamePair pp = new KeyNamePair(key, value);
    addElement(pp);
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair)

Example 15 with NamePair

use of org.compiere.util.NamePair in project adempiere by adempiere.

the class VComboBox method setValue.

/**
	 *  Common Setup
	 *
	private void common_init()
	{
		LookAndFeel.installColorsAndFont(this, "TextField.background", "TextField.foreground", "TextField.font");
		setForeground(AdempierePLAF.getTextColor_Normal());
		setBackground(AdempierePLAF.getFieldBackground_Normal());
		setPreferredSize(s_text.getPreferredSize());
	//	this.setKeySelectionManager(new ComboSelectionManager());
	}   //  common_init

	/** Reference Field         *
	private static  JTextField  s_text = new JTextField(VTextField.DISPLAY_SIZE);

	/**
	 *	Set Selected Item to key.
	 *		Find key value in list
	 *  @param key
	 */
public void setValue(Object key) {
    if (key == null) {
        this.setSelectedIndex(-1);
        return;
    }
    ComboBoxModel model = getModel();
    int size = model.getSize();
    for (int i = 0; i < size; i++) {
        Object element = model.getElementAt(i);
        String ID = null;
        if (element instanceof NamePair)
            ID = ((NamePair) element).getID();
        else if (element instanceof MLocator)
            ID = String.valueOf(((MLocator) element).getM_Locator_ID());
        else
            log.log(Level.SEVERE, "Element not NamePair - " + element.getClass().toString());
        if (key == null || ID == null) {
            if (key == null && ID == null) {
                setSelectedIndex(i);
                return;
            }
        } else if (ID.equals(key.toString())) {
            setSelectedIndex(i);
            return;
        }
    }
    setSelectedIndex(-1);
    setSelectedItem(null);
}
Also used : MLocator(org.compiere.model.MLocator) KeyNamePair(org.compiere.util.KeyNamePair) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) ComboBoxModel(javax.swing.ComboBoxModel)

Aggregations

NamePair (org.compiere.util.NamePair)21 KeyNamePair (org.compiere.util.KeyNamePair)14 ValueNamePair (org.compiere.util.ValueNamePair)12 BigDecimal (java.math.BigDecimal)5 Point (java.awt.Point)4 AttributedString (java.text.AttributedString)3 Vector (java.util.Vector)3 MColumn (org.compiere.model.MColumn)3 MLookup (org.compiere.model.MLookup)3 MUser (org.compiere.model.MUser)3 Color (java.awt.Color)2 Font (java.awt.Font)2 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)2 TextLayout (java.awt.font.TextLayout)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 AttributedCharacterIterator (java.text.AttributedCharacterIterator)2 HashMap (java.util.HashMap)2 MQuery (org.compiere.model.MQuery)2 Dimension (java.awt.Dimension)1