use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class InfoSchedule method fillResourceType.
// dynInit
/**
* Fill Resource Type (one time)
*/
private void fillResourceType() {
// Get ResourceType of selected Resource
int S_ResourceType_ID = 0;
if (m_mAssignment.getS_Resource_ID() != 0) {
String sql = "SELECT S_ResourceType_ID FROM S_Resource WHERE S_Resource_ID=?";
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_mAssignment.getS_Resource_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
S_ResourceType_ID = rs.getInt(1);
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
}
// Get Resource Types
String sql = MRole.getDefault().addAccessSQL("SELECT S_ResourceType_ID, Name FROM S_ResourceType WHERE IsActive='Y' ORDER BY 2", "S_ResourceType", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
KeyNamePair defaultValue = null;
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
if (S_ResourceType_ID == pp.getKey())
defaultValue = pp;
fieldResourceType.appendItem(pp.getName(), pp.getKey());
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
if (defaultValue != null) {
int cnt = fieldResourceType.getItemCount();
for (int i = 0; i < cnt; i++) {
ListItem li = fieldResourceType.getItemAtIndex(i);
Integer key = (Integer) li.getValue();
if (key.intValue() == defaultValue.getKey()) {
fieldResourceType.setSelectedItem(li);
break;
}
}
} else if (fieldResourceType.getItemCount() > 0) {
fieldResourceType.setSelectedIndex(0);
}
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class InfoSchedule method doAdd.
// adjustDate
//
private void doAdd() {
ListItem listItem = fieldResource.getSelectedItem();
if (listItem == null)
return;
// Get Resource Type
KeyNamePair pp = new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel());
int S_Resource_ID = pp.getKey();
ScheduleUtil schedule = new ScheduleUtil(Env.getCtx());
Timestamp start = m_dateFrom;
java.sql.Date startDate = new java.sql.Date(start.getTime());
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(startDate.getTime());
start = new Timestamp(startDate.getTime());
start = new Timestamp(cal.getTimeInMillis());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
start = new Timestamp(cal.getTimeInMillis());
cal.add(Calendar.DAY_OF_MONTH, 1);
Timestamp end = new Timestamp(cal.getTimeInMillis());
MAssignmentSlot[] mas = schedule.getAssignmentSlots(S_Resource_ID, start, end, null, true, null);
MAssignmentSlot[] mts = schedule.getDayTimeSlots();
MAssignmentSlot slot = null;
for (int i = 0; i < mts.length; i++) {
slot = mts[i];
for (int j = 0; j < mas.length; j++) {
if (mts[i].getStartTime().getTime() == mas[j].getStartTime().getTime()) {
slot = null;
break;
}
if (mas[j].getEndTime() != null) {
if (mts[i].getStartTime().getTime() > mas[j].getStartTime().getTime() && mts[i].getStartTime().getTime() < mas[j].getEndTime().getTime()) {
slot = null;
break;
} else if (mts[i].getEndTime().getTime() > mas[j].getStartTime().getTime() && mts[i].getEndTime().getTime() < mas[j].getEndTime().getTime()) {
slot = null;
break;
} else if (mts[i].getStartTime().getTime() < mas[j].getStartTime().getTime() && mts[i].getEndTime().getTime() >= mas[j].getEndTime().getTime()) {
slot = null;
break;
}
}
}
if (slot != null)
break;
}
if (slot != null) {
MResourceAssignment ma;
if (m_mAssignment == null)
ma = new MResourceAssignment(Env.getCtx(), 0, null);
else
ma = m_mAssignment;
ma.setS_Resource_ID(S_Resource_ID);
ma.setAssignDateFrom(TimeUtil.getDayTime(start, slot.getStartTime()));
ma.setQty(new BigDecimal(1));
WAssignmentDialog vad = new WAssignmentDialog(ma, false, m_createNew);
mAssignmentCallback(vad.getMResourceAssignment());
} else {
FDialog.error(0, this, "No available time slot for the selected day.");
}
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class WAttributeGrid method createGrid.
/**
* Create Grid
*/
private void createGrid() {
if (attributeCombo1 == null || m_setting)
// init
return;
Object attr1 = attributeCombo1.getSelectedItem().getValue();
Object attr2 = attributeCombo2.getSelectedItem().getValue();
if (attr1.equals(attr2)) {
FDialog.warn(m_WindowNo, "Same Attribute Selected", getTitle());
log.warning("Same Attribute Selected");
tabbox.setSelectedIndex(0);
return;
}
m_setting = true;
m_M_PriceList_Version_ID = 0;
ListItem pl = pickPriceList.getSelectedItem();
if (pl != null)
m_M_PriceList_Version_ID = Integer.valueOf(pl.getValue().toString());
m_M_Warehouse_ID = 0;
ListItem wh = pickWarehouse.getSelectedItem();
if (wh != null)
m_M_Warehouse_ID = Integer.valueOf(wh.getValue().toString());
// x dimension
int noOfCols = 2;
int indexAttr1 = 0;
MAttributeValue[] xValues = null;
if (attr1 != null) {
int value = Integer.parseInt(attr1.toString());
for (int i = 0; i < m_attributes.length; i++) {
if (m_attributes[i].getKeyNamePair().getKey() == value) {
xValues = m_attributes[i].getMAttributeValues();
indexAttr1 = i;
break;
}
}
}
if (xValues != null)
noOfCols = xValues.length;
// y dimension
int noOfRows = 2;
int indexAttr2 = 0;
MAttributeValue[] yValues = null;
if (attr2 != null) {
int value = Integer.parseInt(attr2.toString());
for (int i = 0; i < m_attributes.length; i++) {
if (m_attributes[i].getKeyNamePair().getKey() == value) {
yValues = m_attributes[i].getMAttributeValues();
indexAttr2 = i;
break;
}
}
}
if (yValues != null)
noOfRows = yValues.length;
gridView.getChildren().clear();
Rows rows = new Rows();
gridView.appendChild(rows);
log.info("Rows=" + noOfRows + " - Cols=" + noOfCols);
for (int rowIndex = 0; rowIndex < noOfRows; rowIndex++) {
Row row = new Row();
row.setWidth("100%");
rows.appendChild(row);
for (int colIndex = 0; colIndex < noOfCols; colIndex++) {
MAttributeValue xValue = null;
if (xValues != null)
xValue = xValues[colIndex];
MAttributeValue yValue = null;
if (yValues != null)
yValue = yValues[rowIndex];
if (rowIndex == 0 && colIndex == 0) {
Vbox descr = new Vbox();
descr.setWidth("100%");
if (xValues != null) {
Div div = new Div();
div.setAlign("right");
div.appendChild(new Label(m_attributes[indexAttr1].getName()));
descr.appendChild(div);
}
if (yValues != null)
descr.appendChild(new Label(m_attributes[indexAttr2].getName()));
row.appendChild(descr);
} else if (// column labels
rowIndex == 0) {
if (xValue != null) {
Div div = new Div();
div.setAlign("center");
div.appendChild(new Label(xValue.getName()));
row.appendChild(div);
} else
row.appendChild(new Label());
} else if (// row labels
colIndex == 0) {
if (yValue != null)
row.appendChild(new Label(yValue.getName()));
else
row.appendChild(new Label());
} else {
row.appendChild(getGridElement(xValue, yValue));
}
}
}
tabbox.setSelectedIndex(1);
m_setting = false;
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class WBOMDrop method onEvent.
// addDisplay
/**************************************************************************
* Action Listener
* @param e event
*/
public void onEvent(Event e) throws Exception {
log.config(e.getName());
Object source = e.getTarget();
// Toggle Qty Enabled
if (source instanceof Checkbox || source instanceof Radio) {
cmd_selection(source);
// need to de-select the others in group
if (source instanceof Radio) {
// find Button Group
Iterator<Radiogroup> it = m_buttonGroups.values().iterator();
while (it.hasNext()) {
Radiogroup group = it.next();
Enumeration en = (Enumeration) group.getChildren();
while (en.hasMoreElements()) {
// We found the group
if (source == en.nextElement()) {
Enumeration info = (Enumeration) group.getChildren();
while (info.hasMoreElements()) {
Object infoObj = info.nextElement();
if (source != infoObj)
cmd_selection(infoObj);
}
}
}
}
}
} else // Product / Qty
if (source == productField || source == productQty) {
m_qty = productQty.getValue();
ListItem listitem = productField.getSelectedItem();
KeyNamePair pp = null;
if (listitem != null)
pp = listitem.toKeyNamePair();
m_product = MProduct.get(Env.getCtx(), pp.getKey());
createMainPanel();
//sizeIt();
} else // Order
if (source == orderField) {
ListItem listitem = orderField.getSelectedItem();
KeyNamePair pp = null;
if (listitem != null)
pp = listitem.toKeyNamePair();
boolean valid = (pp != null && pp.getKey() > 0);
if (invoiceField != null)
invoiceField.setEnabled(!valid);
if (projectField != null)
projectField.setEnabled(!valid);
} else // Invoice
if (source == invoiceField) {
ListItem listitem = invoiceField.getSelectedItem();
KeyNamePair pp = null;
if (listitem != null)
pp = listitem.toKeyNamePair();
boolean valid = (pp != null && pp.getKey() > 0);
if (orderField != null)
orderField.setEnabled(!valid);
if (projectField != null)
projectField.setEnabled(!valid);
} else // Project
if (source == projectField) {
ListItem listitem = projectField.getSelectedItem();
KeyNamePair pp = null;
if (listitem != null)
pp = listitem.toKeyNamePair();
boolean valid = (pp != null && pp.getKey() > 0);
//
if (orderField != null)
orderField.setEnabled(!valid);
if (invoiceField != null)
invoiceField.setEnabled(!valid);
} else // OK
if (confirmPanel.getButton("Ok").equals(e.getTarget())) {
if (cmd_save())
SessionManager.getAppDesktop().closeActiveWindow();
} else if (confirmPanel.getButton("Cancel").equals(e.getTarget()))
SessionManager.getAppDesktop().closeActiveWindow();
// Enable OK
boolean OK = m_product != null;
if (OK) {
KeyNamePair pp = null;
if (orderField != null) {
ListItem listitem = orderField.getSelectedItem();
if (listitem != null)
pp = listitem.toKeyNamePair();
}
if ((pp == null || pp.getKey() <= 0) && invoiceField != null) {
ListItem listitem = invoiceField.getSelectedItem();
if (listitem != null)
pp = listitem.toKeyNamePair();
}
if ((pp == null || pp.getKey() <= 0) && projectField != null) {
ListItem listitem = projectField.getSelectedItem();
if (listitem != null)
pp = listitem.toKeyNamePair();
}
OK = (pp != null && pp.getKey() > 0);
}
confirmPanel.setEnabled("Ok", OK);
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class ADSortTab method migrateValueAcrossLists.
/**
* @param event
*/
void migrateValueAcrossLists(Event event) {
Object source = event.getTarget();
if (source instanceof ListItem) {
source = ((ListItem) source).getListbox();
}
Listbox listFrom = (source == bAdd || source == noList) ? noList : yesList;
Listbox listTo = (source == bAdd || source == noList) ? yesList : noList;
SimpleListModel lmFrom = (source == bAdd || source == noList) ? noModel : yesModel;
SimpleListModel lmTo = (lmFrom == yesModel) ? noModel : yesModel;
Set selectedItems = listFrom.getSelectedItems();
List<ListElement> selObjects = new ArrayList<ListElement>();
for (Object obj : selectedItems) {
ListItem listItem = (ListItem) obj;
int index = listFrom.getIndexOfItem(listItem);
ListElement selObject = (ListElement) lmFrom.getElementAt(index);
selObjects.add(selObject);
}
for (ListElement selObject : selObjects) {
if (selObject == null || !selObject.isUpdateable())
continue;
lmFrom.removeElement(selObject);
lmTo.addElement(selObject);
// Enable explicit Save
setIsChanged(true);
}
for (ListElement selObject : selObjects) {
int index = lmTo.indexOf(selObject);
listTo.setSelectedIndex(index);
}
if (listTo.getSelectedItem() != null) {
AuFocus focus = new AuFocus(listTo.getSelectedItem());
Clients.response(focus);
}
}
Aggregations