| 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.HashMap; |
| 22 | |
import java.util.List; |
| 23 | |
import java.util.Map; |
| 24 | |
import java.util.Set; |
| 25 | |
|
| 26 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
| 27 | |
import org.kuali.student.common.ui.client.widgets.pagetable.GenericTableModel; |
| 28 | |
import org.kuali.student.common.ui.client.widgets.pagetable.PagingScrollTableBuilder; |
| 29 | |
import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow; |
| 30 | |
import org.kuali.student.common.ui.client.widgets.searchtable.SearchColumnDefinition; |
| 31 | |
import org.kuali.student.core.organization.dto.OrgPersonRelationInfo; |
| 32 | |
import org.kuali.student.core.organization.dto.OrgPersonRelationTypeInfo; |
| 33 | |
import org.kuali.student.core.organization.ui.client.mvc.model.MembershipInfo; |
| 34 | |
import org.kuali.student.core.organization.ui.client.service.OrgRpcService; |
| 35 | |
import org.kuali.student.core.organization.ui.client.service.OrgRpcServiceAsync; |
| 36 | |
|
| 37 | |
import com.google.gwt.core.client.GWT; |
| 38 | |
import com.google.gwt.gen2.table.client.AbstractColumnDefinition; |
| 39 | |
import com.google.gwt.gen2.table.client.PagingScrollTable; |
| 40 | |
import com.google.gwt.gen2.table.client.AbstractScrollTable.ResizePolicy; |
| 41 | |
import com.google.gwt.gen2.table.event.client.RowSelectionHandler; |
| 42 | |
import com.google.gwt.user.client.ui.Composite; |
| 43 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
| 44 | |
|
| 45 | 0 | public class MembersTable extends Composite{ |
| 46 | |
private static final String POSITION = "position"; |
| 47 | |
private static final String LNAME = "lname"; |
| 48 | |
private static final String FNAME = "fname"; |
| 49 | |
|
| 50 | 0 | private List<ResultRow> resultRows = new ArrayList<ResultRow>(); |
| 51 | 0 | private List<AbstractColumnDefinition<ResultRow, ?>> columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>(); |
| 52 | 0 | private GenericTableModel<ResultRow> tableModel = new GenericTableModel<ResultRow>(resultRows); |
| 53 | 0 | private PagingScrollTableBuilder<ResultRow> builder = new PagingScrollTableBuilder<ResultRow>(); |
| 54 | |
protected PagingScrollTable<ResultRow> pagingScrollTable; |
| 55 | 0 | private VerticalPanel layout = new VerticalPanel(); |
| 56 | |
private String orgId; |
| 57 | |
private HashMap<String,String> positionTypes; |
| 58 | |
private List<String> personIds; |
| 59 | |
private List<MembershipInfo> members; |
| 60 | |
|
| 61 | 0 | private OrgRpcServiceAsync orgProposalRpcServiceAsync = GWT.create(OrgRpcService.class); |
| 62 | |
|
| 63 | |
public MembersTable(){ |
| 64 | 0 | super(); |
| 65 | 0 | redraw(); |
| 66 | 0 | layout.setWidth("100%"); |
| 67 | 0 | layout.addStyleName("KS-Org-MemberTable"); |
| 68 | 0 | initWidget(layout); |
| 69 | 0 | initializeTable(); |
| 70 | |
|
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public void clearTable(){ |
| 74 | 0 | resultRows.clear(); |
| 75 | 0 | this.redraw(); |
| 76 | 0 | } |
| 77 | |
|
| 78 | |
public void removeSelected(){ |
| 79 | 0 | for(ResultRow r: getSelectedRows()){ |
| 80 | 0 | resultRows.remove(r); |
| 81 | |
} |
| 82 | 0 | this.redraw(); |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
public void initializeTable() { |
| 86 | 0 | clearTable(); |
| 87 | |
|
| 88 | 0 | builder = new PagingScrollTableBuilder<ResultRow>(); |
| 89 | 0 | builder.tablePixelSize(1100, 100); |
| 90 | |
|
| 91 | 0 | columnDefs = new ArrayList<AbstractColumnDefinition<ResultRow, ?>>(); |
| 92 | 0 | columnDefs.add(new SearchColumnDefinition(getLabel("orgMembersTableFirstName"), FNAME)); |
| 93 | 0 | columnDefs.add(new SearchColumnDefinition(getLabel("orgMembersTableLastName"), LNAME)); |
| 94 | 0 | columnDefs.add(new SearchColumnDefinition(getLabel("orgMembersTablePoistionName"), POSITION)); |
| 95 | |
|
| 96 | 0 | builder.columnDefinitions(columnDefs); |
| 97 | 0 | tableModel.setColumnDefs(columnDefs); |
| 98 | 0 | redraw(); |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public void addSelectionHandler(RowSelectionHandler selectionHandler){ |
| 104 | 0 | pagingScrollTable.getDataTable().addRowSelectionHandler(selectionHandler); |
| 105 | 0 | } |
| 106 | |
public void redraw(){ |
| 107 | 0 | tableModel.setRows(resultRows); |
| 108 | 0 | pagingScrollTable = builder.build(tableModel); |
| 109 | 0 | pagingScrollTable.setResizePolicy(ResizePolicy.FILL_WIDTH); |
| 110 | 0 | layout.clear(); |
| 111 | 0 | layout.add(pagingScrollTable); |
| 112 | 0 | pagingScrollTable.reloadPage(); |
| 113 | 0 | pagingScrollTable.fillWidth(); |
| 114 | 0 | } |
| 115 | |
|
| 116 | |
public List<ResultRow> getSelectedRows(){ |
| 117 | 0 | List<ResultRow> rows = new ArrayList<ResultRow>(); |
| 118 | 0 | Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows(); |
| 119 | 0 | for(Integer i: selectedRows){ |
| 120 | 0 | rows.add(pagingScrollTable.getRowValue(i)); |
| 121 | |
} |
| 122 | 0 | return rows; |
| 123 | |
} |
| 124 | |
|
| 125 | |
public List<String> getSelectedIds(){ |
| 126 | 0 | List<String> ids = new ArrayList<String>(); |
| 127 | 0 | Set<Integer> selectedRows = pagingScrollTable.getDataTable().getSelectedRows(); |
| 128 | 0 | for(Integer i: selectedRows){ |
| 129 | 0 | ids.add(pagingScrollTable.getRowValue(i).getId()); |
| 130 | |
} |
| 131 | 0 | return ids; |
| 132 | |
} |
| 133 | |
|
| 134 | |
public List<String> getAllIds(){ |
| 135 | 0 | List<String> ids = new ArrayList<String>(); |
| 136 | 0 | for(ResultRow r: resultRows){ |
| 137 | 0 | ids.add(r.getId()); |
| 138 | |
} |
| 139 | 0 | return ids; |
| 140 | |
} |
| 141 | |
|
| 142 | |
public List<ResultRow> getAllRows(){ |
| 143 | 0 | List<ResultRow> rows = new ArrayList<ResultRow>(); |
| 144 | 0 | for(ResultRow r: resultRows){ |
| 145 | 0 | rows.add(r); |
| 146 | |
} |
| 147 | 0 | return rows; |
| 148 | |
} |
| 149 | |
|
| 150 | |
public String getOrgId(){ |
| 151 | 0 | return this.orgId; |
| 152 | |
} |
| 153 | |
|
| 154 | |
public void setOrgId(String orgId){ |
| 155 | 0 | this.orgId=orgId; |
| 156 | 0 | } |
| 157 | |
|
| 158 | |
|
| 159 | |
public void fetchMemberTable(){ |
| 160 | 0 | if(orgId!=null){ |
| 161 | 0 | orgProposalRpcServiceAsync.getOrgPersonRelationTypes(new KSAsyncCallback<List<OrgPersonRelationTypeInfo>>(){ |
| 162 | |
|
| 163 | |
@Override |
| 164 | |
public void onSuccess(List<OrgPersonRelationTypeInfo> result) { |
| 165 | 0 | positionTypes = new HashMap<String, String>(); |
| 166 | 0 | for(OrgPersonRelationTypeInfo positionType:result){ |
| 167 | 0 | positionTypes.put(positionType.getId(), positionType.getName()); |
| 168 | |
} |
| 169 | 0 | fetchOrgPersonRelations(); |
| 170 | |
|
| 171 | 0 | } |
| 172 | |
|
| 173 | |
}); |
| 174 | |
|
| 175 | |
} |
| 176 | |
|
| 177 | 0 | } |
| 178 | |
|
| 179 | |
public void fetchOrgPersonRelations(){ |
| 180 | 0 | if(orgId!=null){ |
| 181 | 0 | orgProposalRpcServiceAsync.getOrgPersonRelationsByOrg(orgId, new KSAsyncCallback<List<OrgPersonRelationInfo>>(){ |
| 182 | |
|
| 183 | |
@Override |
| 184 | |
public void onSuccess(List<OrgPersonRelationInfo> result) { |
| 185 | 0 | members = new ArrayList<MembershipInfo>(); |
| 186 | 0 | personIds = new ArrayList<String>(); |
| 187 | 0 | for(OrgPersonRelationInfo relation: result){ |
| 188 | 0 | MembershipInfo member = new MembershipInfo(); |
| 189 | 0 | member.setPositionTypeKey(relation.getType()); |
| 190 | 0 | member.setPositionName(positionTypes.get(relation.getType())); |
| 191 | 0 | member.setEntityNameId(relation.getPersonId()); |
| 192 | 0 | personIds.add(relation.getPersonId()); |
| 193 | 0 | members.add(member); |
| 194 | 0 | } |
| 195 | |
|
| 196 | 0 | fetchPersonInfo(); |
| 197 | 0 | } |
| 198 | |
|
| 199 | |
}); |
| 200 | |
} |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
private void fetchPersonInfo(){ |
| 204 | 0 | if (personIds.size() > 0) { |
| 205 | 0 | orgProposalRpcServiceAsync.getNamesForPersonIds(personIds, new KSAsyncCallback<Map<String, MembershipInfo>>() { |
| 206 | |
|
| 207 | |
@Override |
| 208 | |
public void handleFailure(Throwable caught) { |
| 209 | 0 | GWT.log("fetch failed", caught); |
| 210 | 0 | } |
| 211 | |
|
| 212 | |
@Override |
| 213 | |
public void onSuccess(Map<String, MembershipInfo> result) { |
| 214 | 0 | resultRows.clear(); |
| 215 | 0 | for (MembershipInfo member : members) { |
| 216 | 0 | ResultRow theRow = new ResultRow(); |
| 217 | 0 | MembershipInfo retrievedMember = result.get(member.getEntityNameId()); |
| 218 | 0 | member.setFirstName(retrievedMember.getFirstName()); |
| 219 | 0 | member.setLastName(retrievedMember.getLastName()); |
| 220 | |
|
| 221 | 0 | theRow.setValue(FNAME, member.getFirstName()); |
| 222 | 0 | theRow.setValue(LNAME, member.getLastName()); |
| 223 | 0 | theRow.setValue(POSITION, member.getPositionName()); |
| 224 | 0 | resultRows.add(theRow); |
| 225 | 0 | } |
| 226 | 0 | redraw(); |
| 227 | 0 | } |
| 228 | |
|
| 229 | |
}); |
| 230 | |
} |
| 231 | 0 | } |
| 232 | |
|
| 233 | |
} |