Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/ReferenceTable.java @ 1:2e911857a759
(none)
| author | jurzua |
|---|---|
| date | Wed, 29 Oct 2014 14:00:28 +0000 |
| parents | |
| children | 4aa8c425685d |
comparison
equal
deleted
inserted
replaced
| 0:74df02964906 | 1:2e911857a759 |
|---|---|
| 1 package de.mpiwg.itgroup.ismi.util.guiComponents; | |
| 2 | |
| 3 import java.util.ArrayList; | |
| 4 import java.util.List; | |
| 5 | |
| 6 import javax.faces.event.ActionEvent; | |
| 7 | |
| 8 import org.mpi.openmind.repository.bo.Entity; | |
| 9 | |
| 10 import de.mpiwg.itgroup.ismi.entry.beans.AbstractBean; | |
| 11 import de.mpiwg.itgroup.ismi.utils.ISMIUtils; | |
| 12 import de.mpiwg.itgroup.ismi.utils.SelectableObject; | |
| 13 | |
| 14 | |
| 15 public class ReferenceTable extends AbstractBean{ | |
| 16 | |
| 17 private Reference ref; | |
| 18 private Reference originalRef; | |
| 19 | |
| 20 | |
| 21 public List<SelectableObject<Reference>> list = new ArrayList<SelectableObject<Reference>>(); | |
| 22 | |
| 23 public ReferenceTable(){} | |
| 24 | |
| 25 public void loadRefs(List<Entity> refs){ | |
| 26 for(Entity ent : refs){ | |
| 27 this.list.add(new SelectableObject<Reference>(new Reference(ent))); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 public void listenerEditRef(ActionEvent event){ | |
| 32 SelectableObject<Reference> so = (SelectableObject<Reference>)getRequestBean("item"); | |
| 33 if(so != null && so.getObj() != null){ | |
| 34 this.originalRef = (Reference)so.getObj(); | |
| 35 try { | |
| 36 this.ref = (Reference)this.originalRef.clone(); | |
| 37 } catch (Exception e) { | |
| 38 e.printStackTrace(); | |
| 39 } | |
| 40 | |
| 41 }else{ | |
| 42 addErrorMsg("Problems loading references"); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 public String actionEditRef(){ | |
| 47 SelectableObject<Reference> so = (SelectableObject<Reference>)getRequestBean("item"); | |
| 48 if(so != null && so.getObj() != null){ | |
| 49 this.originalRef = (Reference)so.getObj(); | |
| 50 try { | |
| 51 this.ref = (Reference)this.originalRef.clone(); | |
| 52 } catch (Exception e) { | |
| 53 e.printStackTrace(); | |
| 54 } | |
| 55 | |
| 56 }else{ | |
| 57 addErrorMsg("Problems loading references"); | |
| 58 } | |
| 59 return new String(); | |
| 60 } | |
| 61 | |
| 62 public void actionListenerSave(ActionEvent event){ | |
| 63 this.save(); | |
| 64 } | |
| 65 | |
| 66 private void save(){ | |
| 67 System.out.println("actionRefSave actionRefSave actionRefSave"); | |
| 68 if(!ref.isEmpty()){ | |
| 69 ref.getEnt(); | |
| 70 if(originalRef != null){ | |
| 71 ISMIUtils.replaceRef(list, originalRef, ref); | |
| 72 }else{ | |
| 73 list.add(new SelectableObject<Reference>(ref)); | |
| 74 } | |
| 75 } | |
| 76 this.ref = null; | |
| 77 this.originalRef = null; | |
| 78 } | |
| 79 | |
| 80 public void listenerRefSave(ActionEvent event){ | |
| 81 if(!ref.isEmpty()){ | |
| 82 ref.getEnt(); | |
| 83 if(originalRef != null){ | |
| 84 ISMIUtils.replaceRef(list, originalRef, ref); | |
| 85 }else{ | |
| 86 list.add(new SelectableObject<Reference>(ref)); | |
| 87 } | |
| 88 } | |
| 89 this.ref = null; | |
| 90 this.originalRef = null; | |
| 91 } | |
| 92 | |
| 93 public void listenerCreateRef(ActionEvent event){ | |
| 94 this.ref = new Reference(null); | |
| 95 this.originalRef = null; | |
| 96 } | |
| 97 | |
| 98 public String actionCreateRef(){ | |
| 99 System.out.println("actionCreateRef"); | |
| 100 this.ref = new Reference(null); | |
| 101 this.originalRef = null; | |
| 102 return new String(""); | |
| 103 } | |
| 104 | |
| 105 public String actionCancel(){ | |
| 106 this.ref = null; | |
| 107 this.originalRef = null; | |
| 108 return new String(); | |
| 109 } | |
| 110 | |
| 111 | |
| 112 public void listenerCancel(ActionEvent event){ | |
| 113 this.ref = null; | |
| 114 this.originalRef = null; | |
| 115 } | |
| 116 | |
| 117 public String actionRemoveRef(){ | |
| 118 System.out.println("actionRemoveRef"); | |
| 119 List<SelectableObject<Reference>> toDelete = new ArrayList<SelectableObject<Reference>>(); | |
| 120 for(SelectableObject<Reference> so : this.list){ | |
| 121 if(so.isSelected()){ | |
| 122 toDelete.add(so); | |
| 123 } | |
| 124 } | |
| 125 for(SelectableObject<Reference> so : toDelete){ | |
| 126 this.list.remove(so); | |
| 127 } | |
| 128 return new String(""); | |
| 129 } | |
| 130 | |
| 131 public void listenerRemoveRef(ActionEvent event){ | |
| 132 List<SelectableObject<Reference>> toDelete = new ArrayList<SelectableObject<Reference>>(); | |
| 133 for(SelectableObject<Reference> so : this.list){ | |
| 134 if(so.isSelected()){ | |
| 135 toDelete.add(so); | |
| 136 } | |
| 137 } | |
| 138 for(SelectableObject<Reference> so : toDelete){ | |
| 139 this.list.remove(so); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 public Reference getRef() { | |
| 144 return ref; | |
| 145 } | |
| 146 | |
| 147 public void setRef(Reference ref) { | |
| 148 this.ref = ref; | |
| 149 } | |
| 150 | |
| 151 public Reference getOriginalRef() { | |
| 152 return originalRef; | |
| 153 } | |
| 154 | |
| 155 public void setOriginalRef(Reference originalRef) { | |
| 156 this.originalRef = originalRef; | |
| 157 } | |
| 158 | |
| 159 public List<SelectableObject<Reference>> getList() { | |
| 160 return list; | |
| 161 } | |
| 162 | |
| 163 public void setList(List<SelectableObject<Reference>> list) { | |
| 164 this.list = list; | |
| 165 } | |
| 166 | |
| 167 public boolean getHasReferences(){ | |
| 168 if(this.list.isEmpty()) | |
| 169 return false; | |
| 170 return true; | |
| 171 } | |
| 172 } |
