package view.backingbeans; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import view.objekti.utils.JSFUtils; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.faces.event.ValueChangeEvent; import javax.faces.model.SelectItem; import oracle.adf.model.BindingContext; import oracle.adf.model.binding.DCBindingContainer; import oracle.adf.model.binding.DCIteratorBinding; import oracle.adf.view.rich.component.rich.nav.RichCommandToolbarButton; import oracle.binding.AttributeBinding; import oracle.binding.BindingContainer; import oracle.binding.OperationBinding; import oracle.jbo.Row; import oracle.jbo.domain.Number; public class FormShuttle { private RichCommandToolbarButton Next1; public FormShuttle() { super(); } List selectedFruits; List allFruits; List selectedTerminali; List allTerminali; Boolean refreshSelectedList = false; public void setSelectedFruits(List selectedItems) { this.selectedFruits = selectedItems; } public List getSelectedFruits() { if (selectedFruits == null || refreshSelectedList) { selectedFruits = attributeListForIterator("KonekcijeView1Iterator", "AdslId"); // attributeListForIterator("TerminaliUObjektuView1Iterator", "TipTerminalaId"); } return selectedFruits; } public void setAllFruits(List allItems) { this.allFruits = allItems; } public static List attributeListForIterator(String iteratorName, String valueAttrName) { BindingContext bc = BindingContext.getCurrent(); DCBindingContainer binding = (DCBindingContainer)bc.getCurrentBindingsEntry(); DCIteratorBinding iter = binding.findIteratorBinding(iteratorName); List attributeList = new ArrayList(); for (Row r : iter.getAllRowsInRange()) { attributeList.add(r.getAttribute(valueAttrName)); } return attributeList; } public List getAllFruits() { if (allFruits == null) { allFruits = selectItemsForIterator("AdslView1Iterator", "AdslId", "TipKonekcije"); } return allFruits; } public static List<SelectItem> selectItemsForIterator(String iteratorName, String valueAttrName, String displayAttrName) { BindingContext bc = BindingContext.getCurrent(); DCBindingContainer binding = (DCBindingContainer)bc.getCurrentBindingsEntry(); DCIteratorBinding iter = binding.findIteratorBinding(iteratorName); List<SelectItem> selectItems = new ArrayList<SelectItem>(); for (Row r : iter.getAllRowsInRange()) { selectItems.add(new SelectItem(r.getAttribute(valueAttrName), (String)r.getAttribute(displayAttrName))); } return selectItems; } public void refreshSelectedList() { refreshSelectedList = true; } public Number getCurrentPersonId() { BindingContext bctx = BindingContext.getCurrent(); DCBindingContainer bindings = (DCBindingContainer)bctx.getCurrentBindingsEntry(); AttributeBinding attr = (AttributeBinding)bindings.get("ObjekatId2"); Number personId = (Number)attr.getInputValue(); return personId; } public String processShuttle() { BindingContext bctx = BindingContext.getCurrent(); DCBindingContainer binding = (DCBindingContainer)bctx.getCurrentBindingsEntry(); DCIteratorBinding iter = (DCIteratorBinding)binding.get("KonekcijeView1Iterator"); //Removing all rows for (Row r : iter.getAllRowsInRange()) { r.remove(); } if (this.getSelectedFruits().size() > 0) { for (int i = 0; i < selectedFruits.size(); i++) { Row row = iter.getRowSetIterator().createRow(); row.setNewRowState(Row.STATUS_INITIALIZED); row.setAttribute("ObjekatId", getCurrentPersonId()); row.setAttribute("AdslId", getSelectedFruits().get(i)); iter.getRowSetIterator().insertRow(row); iter.setCurrentRowWithKey(row.getKey().toStringFormat(true)); System.out.println("inside "); } } String ok = doCommit(); System.out.println("Commit value" + ok); return null; } public String doCommit() { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Commit"); Object result = operationBinding.execute(); if (operationBinding.getErrors().isEmpty()) { /* List errors = operationBinding.getErrors(); Iterator<oracle.jbo.JboException> iterator = errors.iterator(); while (iterator.hasNext()) { FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, iterator.next().getMessage(), null); FacesContext fctx = FacesContext.getCurrentInstance(); fctx.addMessage(null, fm); } */ return "problem"; } return "ok ki flight"; } public void setSelectedTerminali(List selectedItems) { this.selectedTerminali = selectedItems; } public List getSelectedTerminali() { if (selectedTerminali == null || refreshSelectedList) { selectedTerminali = attributeListForIterator2("TerminaliUObjektuView1Iterator", "TipTerminalaId"); } return selectedTerminali; } public void setAllTerminali(List allItems) { this.allTerminali = allItems; } public static List attributeListForIterator2(String iteratorName, String valueAttrName) { BindingContext bc = BindingContext.getCurrent(); DCBindingContainer binding = (DCBindingContainer)bc.getCurrentBindingsEntry(); DCIteratorBinding iter = binding.findIteratorBinding(iteratorName); List attributeList = new ArrayList(); for (Row r : iter.getAllRowsInRange()) { attributeList.add(r.getAttribute(valueAttrName)); } return attributeList; } public List getAllTerminali() { if (allTerminali == null) { allTerminali = selectItemsForIterator2("TipTerminalaView1Iterator", "TipTerminalaId", "Naziv"); } return allTerminali; } public static List<SelectItem> selectItemsForIterator2(String iteratorName, String valueAttrName, String displayAttrName) { BindingContext bc = BindingContext.getCurrent(); DCBindingContainer binding = (DCBindingContainer)bc.getCurrentBindingsEntry(); DCIteratorBinding iter = binding.findIteratorBinding(iteratorName); List<SelectItem> selectItems = new ArrayList<SelectItem>(); for (Row r : iter.getAllRowsInRange()) { selectItems.add(new SelectItem(r.getAttribute(valueAttrName), (String)r.getAttribute(displayAttrName))); } return selectItems; } { refreshSelectedList = true; } public Number getCurrentObjekatId() { BindingContext bctx = BindingContext.getCurrent(); DCBindingContainer bindings = (DCBindingContainer)bctx.getCurrentBindingsEntry(); AttributeBinding attr = (AttributeBinding)bindings.get("ObjekatId2"); Number objekatId = (Number)attr.getInputValue(); return objekatId; } public String processShuttle2() { BindingContext bctx = BindingContext.getCurrent(); DCBindingContainer binding = (DCBindingContainer)bctx.getCurrentBindingsEntry(); DCIteratorBinding iter = (DCIteratorBinding)binding.get("TerminaliUObjektuView1Iterator"); //Removing all rows for (Row r : iter.getAllRowsInRange()) { r.remove(); } if (this.getSelectedTerminali().size() > 0) { for (int i = 0; i < selectedTerminali.size(); i++) { Row row = iter.getRowSetIterator().createRow(); row.setNewRowState(Row.STATUS_INITIALIZED); row.setAttribute("ObjekatId", getCurrentObjekatId()); row.setAttribute("TipTerminalaId", getSelectedTerminali().get(i)); iter.getRowSetIterator().insertRow(row); iter.setCurrentRowWithKey(row.getKey().toStringFormat(true)); System.out.println("inside "); } } String ok = doCommit(); System.out.println("Commit value" + ok); return null; } public BindingContainer getBindings() { return BindingContext.getCurrent().getCurrentBindingsEntry(); } public String previous_action() { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Previous"); Object result = operationBinding.execute(); if (!operationBinding.getErrors().isEmpty()) { return null; } refreshSelectedList(); return null; } public String adslSljedeciButton_action() { if(((Boolean)JSFUtils.getManagedBeanValue("bindings.Commit.enabled")) == false) { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Next1"); Object result = operationBinding.execute(); if (!operationBinding.getErrors().isEmpty()) { return null; } } else { FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Napravili ste neke izmjene morate ih prvo pohraniti ili povratiti" + " prije nego mozete nastaviti!", null)); } refreshSelectedList(); return null; } public void setNext1(RichCommandToolbarButton Next1) { this.Next1 = Next1; } public RichCommandToolbarButton getNext1() { return Next1; } }