1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
package com.galhauban.patrimoine.batiment;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
import org.richfaces.component.UITree;
import org.richfaces.event.TreeSelectionChangeEvent;
import com.galhauban.patrimoine.composants.CalendarBean;
import com.galhauban.patrimoine.interfaces.ColbertBtEntity;
import com.galhauban.patrimoine.interfaces.ColbertInterventionTotal;
import com.galhauban.patrimoine.interfaces.IColbertBt;
//@Named("refItemController")
@ManagedBean(name="refItemController")
@SessionScoped
public class RefItemController implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private RefItemLocal items;
private List<RefItemEntity> liste =new ArrayList<RefItemEntity>();
@EJB
private IBatiment batis;
private List<BatimentEntity> listeBatis =new ArrayList<BatimentEntity>();
private Noeud myTree = new Noeud();
private Noeud currentSelection = null;
private boolean remarquesBool = false;
private String remarques;
private List<BatimentStructureEntity> listeStructure = new ArrayList<BatimentStructureEntity>();
private List<BatimentCarnetEntity> listeCarnet = new ArrayList<BatimentCarnetEntity>();
@EJB
private IColbertBt bt;
private List<ColbertBtEntity> btList = new ArrayList<ColbertBtEntity>();
//Déclaration d'un tablo pour réceptionner les objets montants
private List<ColbertInterventionTotal> totaux = new ArrayList<ColbertInterventionTotal>();
@EJB
private CalendarBean calDebut;
@EJB
private CalendarBean calFin;
private boolean afficheNot = false;
public RefItemController(){};
//Affiche l'arborescence
public String doSearch() {
try {
liste = items.refItemList();
System.out.println("Liste taille : " + liste.size());
listeBatis = batis.listBatiment();
addNoeud(findRoot(liste),liste,listeBatis);
return "referentiel.found";
}
catch (Exception ex){
System.out.println("pb : " + ex.getMessage());
ex.printStackTrace();
return null;
}
}
//Ajoute un noeud
public void addNoeud (ArrayList<Noeud> tablo, List<RefItemEntity> listeRef, List<BatimentEntity> listeBat){
ArrayList<Noeud> tabli = new ArrayList<Noeud>();
for (Noeud noeud : tablo)
{
for (RefItemEntity objet : listeRef){
if(objet.getPere() == noeud.getId())
{
Noeud fils = new Noeud();
fils.setType("arbo");
fils.setId(objet.getId());
fils.setName(objet.getNom());
noeud.addChild(String.valueOf(fils.getId()), fils);
tabli.add(fils);
System.out.println("Fils : " + fils.getName());
//boucle permettant d'ajouter les éventuels batiments au fils
for(BatimentEntity bat : listeBat){
if (bat.getIdref() == fils.getId()){
Noeud filsBat = new Noeud();
filsBat.setType("bati");
filsBat.setId(bat.getId());
filsBat.setId_achatmode(bat.getIdacm());
filsBat.setId_batimenttype(bat.getIdbty());
filsBat.setId_ensemble(bat.getIdens());
filsBat.setId_quartier(bat.getIdqua());
filsBat.setName(bat.getNom());
filsBat.setRefexterne(bat.getRefexterne());
filsBat.setNumero(bat.getNumero());
filsBat.setBis(bat.getBis());
filsBat.setRue(bat.getRue());
filsBat.setCodepostal(bat.getCodepostal());
filsBat.setCommune(bat.getCommune());
filsBat.setRemarques(bat.getRemarques());
fils.addChild(String.valueOf(filsBat.getId()), filsBat);
System.out.println("----" + bat.getNom());
//listeBatis.remove(listeBatis.indexOf(bat));
}
}
}
}
if (tabli.size() != 0) {
//System.out.println("*** Taille du tablo : " + tabli.size());
addNoeud(tabli,listeRef,listeBat);
}
else System.out.println("*** Fin ****");
}
}
//Permet de recupérer l'élèment racine
//L'élèment racine possède une valeur null au niveau de la colonne pere
public ArrayList<Noeud> findRoot(List<RefItemEntity> liste ) {
ArrayList<Noeud> tablo = new ArrayList<Noeud>() ;
for (RefItemEntity objet : liste) {
if (objet.getPere() == null) {
Noeud root = new Noeud();
root.setName(objet.getNom());
root.setId(objet.getId());
root.setType("arbo");
myTree.addChild(String.valueOf(root.getId()), root);
tablo.add(root);
System.out.println("**************************** root : " + root.getId());
liste.remove(liste.indexOf(objet));
break;
}
}
return tablo;
}
public void selectionChanged(TreeSelectionChangeEvent selectionChangeEvent) {
// considering only single selection
System.out.println("*** selectionchanged");
List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection());
Object currentSelectionKey = selection.get(0);
UITree tree = (UITree) selectionChangeEvent.getSource();
System.out.println("*** selection : " + selection.get(0)+ " - taille : " +selection.size());
Object storedKey = tree.getRowKey();
tree.setRowKey(currentSelectionKey);
currentSelection = (Noeud) tree.getRowData();
tree.setRowKey(storedKey);
}
public boolean changeBool(boolean bool){
setRemarquesBool(!bool);
return(bool);
}
public boolean changeAffiche(boolean bool){
setAfficheNot(!bool);
return(bool);
}
public void majBatiment(){
String remini = currentSelection.getRemarques();
String rem = batis.BatimentMaj(currentSelection.getId(),remini +"<br/>"+ remarques).getRemarques();
setRemarques(null);
currentSelection.setRemarques(rem);
}
/*************************************************************************************
* GETTERS AND SETTERS
*************************************************************************************/
public List<RefItemEntity> getListe() {
return liste;
}
public void setListe(List<RefItemEntity> liste) {
this.liste = liste;
}
public RefItemLocal getItems() {
return items;
}
public void setItems(RefItemLocal items) {
this.items = items;
}
public Noeud getMyTree() {
return myTree;
}
public void setMyTree(Noeud myTree) {
this.myTree = myTree;
}
public Noeud getCurrentSelection() {
return currentSelection;
}
public void setCurrentSelection(Noeud currentSelection) {
this.currentSelection = currentSelection;
}
public IBatiment getBatis() {
return batis;
}
public void setBatis(IBatiment batis) {
this.batis = batis;
}
public List<BatimentEntity> getListeBatis() {
return listeBatis;
}
public void setListeBatis(List<BatimentEntity> listeBatis) {
this.listeBatis = listeBatis;
}
public boolean isRemarquesBool() {
return remarquesBool;
}
public void setRemarquesBool(boolean remarquesBool) {
this.remarquesBool = remarquesBool;
}
public String getRemarques() {
return remarques;
}
public void setRemarques(String remarques) {
this.remarques = remarques;
}
public List<BatimentStructureEntity> getListeStructure() {
listeStructure = batis.listStructure();
return listeStructure;
}
public void setListeStructure(List<BatimentStructureEntity> listeStructure) {
this.listeStructure = listeStructure;
}
public List<BatimentCarnetEntity> getListeCarnet() {
listeCarnet = batis.findCarnet(currentSelection.getId());
return listeCarnet;
}
public void setListeCarnet(List<BatimentCarnetEntity> listeCarnet) {
this.listeCarnet = listeCarnet;
}
public IColbertBt getBt() {
return bt;
}
public void setBt(IColbertBt bt) {
this.bt = bt;
}
public List<ColbertBtEntity> getBtList() throws ParseException {
System.out.println("DATE DEBUT : "+calDebut.getSelectedDate()+" - FIN : "+calFin.getSelectedDate());
btList=bt.coutBt(currentSelection.getRefexterne(), calDebut.getSelectedDate(), calFin.getSelectedDate());
System.out.println("NB BTS : "+btList.size());
return btList;
}
public void setBtList(List<ColbertBtEntity> btList) {
this.btList = btList;
}
public boolean isAfficheNot() {
return afficheNot;
}
public void setAfficheNot(boolean afficheNot) {
this.afficheNot = afficheNot;
}
public CalendarBean getCalDebut() {
System.out.println("calDebut : "+calDebut.getSelectedDate());
return calDebut;
}
public void setCalDebut(CalendarBean calDebut) {
this.calDebut = calDebut;
}
public CalendarBean getCalFin() {
System.out.println("calFin : "+calFin.getSelectedDate());
return calFin;
}
public void setCalFin(CalendarBean calFin) {
this.calFin = calFin;
}
} |
Partager