| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.core.organization.ui.client.mvc.view; | 
  | 17 |  |   | 
  | 18 |  |  import static org.kuali.student.core.organization.ui.client.mvc.view.CommonConfigurer.getLabel; | 
  | 19 |  |   | 
  | 20 |  |  import java.util.ArrayList; | 
  | 21 |  |  import java.util.List; | 
  | 22 |  |  import java.util.Set; | 
  | 23 |  |   | 
  | 24 |  |  import org.kuali.student.common.ui.client.application.KSAsyncCallback; | 
  | 25 |  |  import org.kuali.student.common.ui.client.widgets.pagetable.GenericTableModel; | 
  | 26 |  |  import org.kuali.student.common.ui.client.widgets.pagetable.PagingScrollTableBuilder; | 
  | 27 |  |  import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow; | 
  | 28 |  |  import org.kuali.student.common.ui.client.widgets.searchtable.SearchColumnDefinition; | 
  | 29 |  |  import org.kuali.student.core.organization.ui.client.mvc.model.OrgPositionPersonRelationInfo; | 
  | 30 |  |  import org.kuali.student.core.organization.ui.client.service.OrgRpcService; | 
  | 31 |  |  import org.kuali.student.core.organization.ui.client.service.OrgRpcServiceAsync; | 
  | 32 |  |   | 
  | 33 |  |  import com.google.gwt.core.client.GWT; | 
  | 34 |  |  import com.google.gwt.gen2.table.client.AbstractColumnDefinition; | 
  | 35 |  |  import com.google.gwt.gen2.table.client.PagingScrollTable; | 
  | 36 |  |  import com.google.gwt.gen2.table.client.AbstractScrollTable.ResizePolicy; | 
  | 37 |  |  import com.google.gwt.gen2.table.event.client.RowSelectionHandler; | 
  | 38 |  |  import com.google.gwt.user.client.ui.Composite; | 
  | 39 |  |  import com.google.gwt.user.client.ui.VerticalPanel; | 
  | 40 |  |   | 
  | 41 | 0 |  public class PositionTable extends Composite{ | 
  | 42 |  |      private static final String DESC = "desc"; | 
  | 43 |  |      private static final String POSITION = "position"; | 
  | 44 |  |      private static final String PERSON = "person"; | 
  | 45 |  |   | 
  | 46 | 0 |      private List<ResultRow> resultRows = new ArrayList<ResultRow>(); | 
  | 47 | 0 |      private List<AbstractColumnDefinition<ResultRow, ?>> columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>(); | 
  | 48 | 0 |      private GenericTableModel<ResultRow> tableModel = new GenericTableModel<ResultRow>(resultRows); | 
  | 49 | 0 |      private PagingScrollTableBuilder<ResultRow> builder = new PagingScrollTableBuilder<ResultRow>(); | 
  | 50 |  |      protected PagingScrollTable<ResultRow> pagingScrollTable; | 
  | 51 | 0 |      private VerticalPanel layout = new VerticalPanel(); | 
  | 52 |  |      private String orgId; | 
  | 53 |  |   | 
  | 54 | 0 |      private OrgRpcServiceAsync orgProposalRpcServiceAsync = GWT.create(OrgRpcService.class); | 
  | 55 |  |   | 
  | 56 |  |      public PositionTable(){ | 
  | 57 | 0 |          super(); | 
  | 58 | 0 |          redraw(); | 
  | 59 | 0 |          layout.setWidth("100%"); | 
  | 60 | 0 |          initWidget(layout); | 
  | 61 | 0 |          initializeTable(); | 
  | 62 | 0 |          fetchPosition(); | 
  | 63 | 0 |      } | 
  | 64 |  |   | 
  | 65 |  |      public void clearTable(){ | 
  | 66 | 0 |          resultRows.clear(); | 
  | 67 | 0 |          this.redraw(); | 
  | 68 | 0 |      } | 
  | 69 |  |   | 
  | 70 |  |      public void removeSelected(){ | 
  | 71 | 0 |          for(ResultRow r: getSelectedRows()){ | 
  | 72 | 0 |              resultRows.remove(r); | 
  | 73 |  |          } | 
  | 74 | 0 |          this.redraw(); | 
  | 75 | 0 |      } | 
  | 76 |  |   | 
  | 77 |  |      public void initializeTable() { | 
  | 78 | 0 |          clearTable(); | 
  | 79 |  |   | 
  | 80 | 0 |          builder = new PagingScrollTableBuilder<ResultRow>(); | 
  | 81 | 0 |          builder.tablePixelSize(1100, 100); | 
  | 82 |  |   | 
  | 83 | 0 |          columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>(); | 
  | 84 | 0 |          columnDefs.add(new SearchColumnDefinition(getLabel("orgPositionTablePersonId"), PERSON)); | 
  | 85 | 0 |          columnDefs.add(new SearchColumnDefinition(getLabel("orgPositionTablePositionName"), POSITION)); | 
  | 86 | 0 |          columnDefs.add(new SearchColumnDefinition(getLabel("orgPositionTablePositionDesc"), DESC)); | 
  | 87 |  |   | 
  | 88 | 0 |          builder.columnDefinitions(columnDefs); | 
  | 89 | 0 |          tableModel.setColumnDefs(columnDefs); | 
  | 90 | 0 |          redraw(); | 
  | 91 | 0 |      } | 
  | 92 |  |   | 
  | 93 |  |      public void fetchPosition(){ | 
  | 94 | 0 |          if (orgId != null) { | 
  | 95 | 0 |              orgProposalRpcServiceAsync.getOrgPositionPersonRelation(orgId, new KSAsyncCallback<List<OrgPositionPersonRelationInfo>>() { | 
  | 96 |  |   | 
  | 97 |  |                  @Override | 
  | 98 |  |                  public void handleFailure(Throwable caught) { | 
  | 99 | 0 |                      GWT.log("fetch failed", caught); | 
  | 100 | 0 |                  } | 
  | 101 |  |   | 
  | 102 |  |                  @Override | 
  | 103 |  |                  public void onSuccess(List<OrgPositionPersonRelationInfo> result) { | 
  | 104 | 0 |                      resultRows.clear(); | 
  | 105 | 0 |                      if (result != null) { | 
  | 106 | 0 |                          for (OrgPositionPersonRelationInfo positionRelation : result) { | 
  | 107 | 0 |                              if (positionRelation.getPersonId().size() > 0) { | 
  | 108 | 0 |                                  for (Object personId : positionRelation.getPersonId()) { | 
  | 109 | 0 |                                      ResultRow theRow = new ResultRow(); | 
  | 110 | 0 |                                      theRow.setValue(POSITION, positionRelation.getTitle()); | 
  | 111 | 0 |                                      theRow.setValue(DESC, positionRelation.getDesc()); | 
  | 112 | 0 |                                      theRow.setValue(PERSON, (String) personId); | 
  | 113 | 0 |                                      resultRows.add(theRow); | 
  | 114 | 0 |                                  } | 
  | 115 |  |                              } else { | 
  | 116 | 0 |                                  ResultRow theRow = new ResultRow(); | 
  | 117 | 0 |                                  theRow.setValue(POSITION, positionRelation.getTitle()); | 
  | 118 | 0 |                                  theRow.setValue(DESC, positionRelation.getDesc()); | 
  | 119 | 0 |                                  theRow.setValue(PERSON, " "); | 
  | 120 | 0 |                                  resultRows.add(theRow); | 
  | 121 | 0 |                              } | 
  | 122 |  |   | 
  | 123 |  |                          } | 
  | 124 |  |                      } | 
  | 125 | 0 |                      redraw(); | 
  | 126 | 0 |                  } | 
  | 127 |  |   | 
  | 128 |  |              }); | 
  | 129 |  |   | 
  | 130 |  |          } | 
  | 131 | 0 |      } | 
  | 132 |  |   | 
  | 133 |  |      public void addSelectionHandler(RowSelectionHandler selectionHandler){ | 
  | 134 | 0 |          pagingScrollTable.getDataTable().addRowSelectionHandler(selectionHandler); | 
  | 135 | 0 |      } | 
  | 136 |  |      public void redraw(){ | 
  | 137 | 0 |          tableModel.setRows(resultRows); | 
  | 138 | 0 |          pagingScrollTable = builder.build(tableModel); | 
  | 139 | 0 |          pagingScrollTable.setResizePolicy(ResizePolicy.FILL_WIDTH); | 
  | 140 | 0 |          layout.clear(); | 
  | 141 | 0 |          layout.add(pagingScrollTable); | 
  | 142 | 0 |          pagingScrollTable.reloadPage(); | 
  | 143 | 0 |          pagingScrollTable.fillWidth(); | 
  | 144 | 0 |      } | 
  | 145 |  |   | 
  | 146 |  |      public List<ResultRow> getSelectedRows(){ | 
  | 147 | 0 |          List<ResultRow> rows = new ArrayList<ResultRow>(); | 
  | 148 | 0 |          Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows(); | 
  | 149 | 0 |          for(Integer i: selectedRows){ | 
  | 150 | 0 |              rows.add(pagingScrollTable.getRowValue(i)); | 
  | 151 |  |          } | 
  | 152 | 0 |          return rows; | 
  | 153 |  |      } | 
  | 154 |  |   | 
  | 155 |  |      public List<String> getSelectedIds(){ | 
  | 156 | 0 |          List<String> ids = new ArrayList<String>(); | 
  | 157 | 0 |          Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows(); | 
  | 158 | 0 |          for(Integer i: selectedRows){ | 
  | 159 | 0 |              ids.add(pagingScrollTable.getRowValue(i).getId()); | 
  | 160 |  |          } | 
  | 161 | 0 |          return ids; | 
  | 162 |  |      } | 
  | 163 |  |   | 
  | 164 |  |      public List<String> getAllIds(){ | 
  | 165 | 0 |          List<String> ids = new ArrayList<String>(); | 
  | 166 | 0 |          for(ResultRow r: resultRows){ | 
  | 167 | 0 |              ids.add(r.getId()); | 
  | 168 |  |          } | 
  | 169 | 0 |          return ids; | 
  | 170 |  |      } | 
  | 171 |  |   | 
  | 172 |  |      public List<ResultRow> getAllRows(){ | 
  | 173 | 0 |          List<ResultRow> rows = new ArrayList<ResultRow>(); | 
  | 174 | 0 |          for(ResultRow r: resultRows){ | 
  | 175 | 0 |              rows.add(r); | 
  | 176 |  |          } | 
  | 177 | 0 |          return rows; | 
  | 178 |  |      } | 
  | 179 |  |   | 
  | 180 |  |      public String getOrgId(){ | 
  | 181 | 0 |          return this.orgId; | 
  | 182 |  |      } | 
  | 183 |  |   | 
  | 184 |  |      public void setOrgId(String orgId){ | 
  | 185 | 0 |          this.orgId=orgId; | 
  | 186 | 0 |      } | 
  | 187 |  |   | 
  | 188 |  |  } |