| 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 java.util.List; | 
  | 19 |  |   | 
  | 20 |  |  import org.kuali.student.common.assembly.data.Metadata; | 
  | 21 |  |  import org.kuali.student.common.assembly.data.QueryPath; | 
  | 22 |  |  import org.kuali.student.common.ui.client.application.Application; | 
  | 23 |  |  import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; | 
  | 24 |  |  import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; | 
  | 25 |  |  import org.kuali.student.common.ui.client.configurable.mvc.layouts.ConfigurableLayout; | 
  | 26 |  |  import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem; | 
  | 27 |  |  import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.UpdatableMultiplicityComposite; | 
  | 28 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.GroupSection; | 
  | 29 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.RemovableItemWithHeader; | 
  | 30 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; | 
  | 31 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; | 
  | 32 |  |  import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; | 
  | 33 |  |  import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; | 
  | 34 |  |  import org.kuali.student.common.ui.client.mvc.DataModelDefinition; | 
  | 35 |  |  import org.kuali.student.common.ui.client.widgets.KSButton; | 
  | 36 |  |  import org.kuali.student.common.ui.client.widgets.KSLabel; | 
  | 37 |  |  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; | 
  | 38 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; | 
  | 39 |  |  import org.kuali.student.core.organization.ui.client.mvc.model.FieldInfo; | 
  | 40 |  |  import org.kuali.student.core.organization.ui.client.mvc.model.MultipleFieldInfoImpl; | 
  | 41 |  |  import org.kuali.student.core.organization.ui.client.mvc.model.SectionConfigInfo; | 
  | 42 |  |  import org.kuali.student.core.organization.ui.client.mvc.model.SectionViewInfo; | 
  | 43 |  |   | 
  | 44 |  |  import com.google.gwt.core.client.GWT; | 
  | 45 |  |  import com.google.gwt.event.dom.client.ClickEvent; | 
  | 46 |  |  import com.google.gwt.event.dom.client.ClickHandler; | 
  | 47 |  |  import com.google.gwt.user.client.DOM; | 
  | 48 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 49 |  |   | 
  | 50 | 0 |  public class CommonConfigurer { | 
  | 51 |  |   | 
  | 52 |  |   | 
  | 53 |  |      private DataModelDefinition modelDefinition; | 
  | 54 |  |      private SectionConfigInfo sectionConfigInfo; | 
  | 55 | 0 |      private static String groupName = "org"; | 
  | 56 | 0 |      private boolean WITH_DIVIDER = true; | 
  | 57 |  |      public static final String ORG_PROPOSAL_MODEL = "orgProposalModel"; | 
  | 58 |  |      public static final String ORG_SEARCH = "searchOrgs"; | 
  | 59 |  |      public PositionTable positionTable; | 
  | 60 |  |      public OrgPersonRelationTypePicker personRelationPicker; | 
  | 61 |  |      private String orgId; | 
  | 62 |  |      public static final String ORG_INFO_PATH                  = "orgInfo"; | 
  | 63 |  |      public static final String POSITION_PATH                  = "OrgPositionRestrictionInfo"; | 
  | 64 |  |      public static final String PERSON_PATH                  = "orgPersonRelationInfo"; | 
  | 65 |  |      public static final String ORGORG_PATH                  = "orgOrgRelationInfo"; | 
  | 66 |  |   | 
  | 67 | 0 |      public enum SectionsEnum { | 
  | 68 | 0 |          ORG_INFO, ORG_RELATIONS, POSITIONS, PERSON_RELATIONS,BROWSE_TREE,BROWSE_LIST,BROWSE_CHART,BROWSE_NAME,SEARCH | 
  | 69 |  |      } | 
  | 70 |  |   | 
  | 71 |  |      public void setModelDefinition(DataModelDefinition modelDefinition){ | 
  | 72 | 0 |          this.modelDefinition = modelDefinition; | 
  | 73 | 0 |      } | 
  | 74 |  |   | 
  | 75 |  |      public void setSectionConfigInfo(SectionConfigInfo sectionConfigInfo){ | 
  | 76 | 0 |          this.sectionConfigInfo=sectionConfigInfo; | 
  | 77 | 0 |      } | 
  | 78 |  |   | 
  | 79 |  |      public void setOrgId(String orgId){ | 
  | 80 | 0 |          this.orgId=orgId; | 
  | 81 |  |   | 
  | 82 | 0 |      } | 
  | 83 |  |   | 
  | 84 |  |      public String getOrgId(){ | 
  | 85 | 0 |          return orgId; | 
  | 86 |  |      } | 
  | 87 |  |   | 
  | 88 |  |       | 
  | 89 |  |   | 
  | 90 |  |   | 
  | 91 |  |   | 
  | 92 |  |      public void configureOrgProposal(ConfigurableLayout layout){ | 
  | 93 |  |          List<SectionViewInfo> sectionViewInfoList; | 
  | 94 | 0 |          sectionViewInfoList = sectionConfigInfo.getSectionViewInfoList(); | 
  | 95 | 0 |          for(SectionViewInfo sectionViewInfo:sectionViewInfoList){ | 
  | 96 | 0 |            layout.addSection(new String[] {sectionViewInfo.getTab(),sectionViewInfo.getMenu()}, generateSection(sectionViewInfo)); | 
  | 97 |  |   | 
  | 98 |  |          } | 
  | 99 |  |   | 
  | 100 |  |   | 
  | 101 | 0 |      } | 
  | 102 |  |   | 
  | 103 |  |       | 
  | 104 |  |   | 
  | 105 |  |   | 
  | 106 |  |   | 
  | 107 |  |   | 
  | 108 |  |      private SectionView generateSection(SectionViewInfo sectionViewInfo){ | 
  | 109 |  |          try { | 
  | 110 | 0 |          VerticalSectionView section = initSectionView(SectionsEnum.valueOf(sectionViewInfo.getSectionEnum()), sectionViewInfo.getSectionName()); | 
  | 111 |  |   | 
  | 112 |  |   | 
  | 113 | 0 |          VerticalSection orgInfo = new VerticalSection(); | 
  | 114 |  |           | 
  | 115 | 0 |          groupName="org"; | 
  | 116 | 0 |          List<FieldInfo> fieldList = sectionViewInfo.getfields(); | 
  | 117 | 0 |          if (fieldList != null) { | 
  | 118 | 0 |                  for (FieldInfo field : fieldList) { | 
  | 119 |  |                       | 
  | 120 | 0 |                      if (field instanceof MultipleFieldInfoImpl) { | 
  | 121 | 0 |                          List<FieldInfo> fieldMultiList = ((MultipleFieldInfoImpl) field).getFields(); | 
  | 122 |  |   | 
  | 123 |  |                           | 
  | 124 | 0 |                          addField(orgInfo, field.getKey(), generateMessageInfo(field.getLabel()), new CommonMultiplicityList("Add", " ", fieldMultiList, field.getKey())); | 
  | 125 |  |   | 
  | 126 | 0 |                      } else { | 
  | 127 |  |                           | 
  | 128 | 0 |                          Widget widget = null; | 
  | 129 | 0 |                          if (field.getWidget() != null) { | 
  | 130 | 0 |                              if (field.getWidget().equals("OrgLocateTree")) { | 
  | 131 | 0 |                                  widget = new OrgTree(section); | 
  | 132 |  |                              } | 
  | 133 | 0 |                              if (field.getWidget().equals("PositionTable")) { | 
  | 134 | 0 |                                  positionTable = new PositionTable(); | 
  | 135 | 0 |                                  DOM.setElementAttribute(positionTable.getElement(), "id", "orgPositionsTable"); | 
  | 136 | 0 |                                  widget = positionTable; | 
  | 137 |  |                              } | 
  | 138 |  |   | 
  | 139 |  |                          } | 
  | 140 | 0 |                          addField(orgInfo, field.getKey(), generateMessageInfo(field.getLabel()), widget); | 
  | 141 | 0 |                      } | 
  | 142 |  |                  } | 
  | 143 |  |              } | 
  | 144 |  |   | 
  | 145 |  |   | 
  | 146 |  |   | 
  | 147 | 0 |          orgInfo.addStyleName("KS-CORE-Section-Divider"); | 
  | 148 |  |           | 
  | 149 | 0 |          section.addSection(orgInfo); | 
  | 150 |  |           | 
  | 151 | 0 |          return section; | 
  | 152 |  |          } | 
  | 153 | 0 |          catch(Exception e){ | 
  | 154 | 0 |              GWT.log("Error in config", e); | 
  | 155 |  |          } | 
  | 156 | 0 |          return null; | 
  | 157 |  |      } | 
  | 158 |  |       | 
  | 159 |  |      protected static MessageKeyInfo generateMessageInfo(String labelKey) { | 
  | 160 | 0 |          return new MessageKeyInfo(groupName, "org", "draft", labelKey); | 
  | 161 |  |      } | 
  | 162 |  |       | 
  | 163 |  |      private static VerticalSection initSection(SectionTitle title, boolean withDivider) { | 
  | 164 | 0 |          VerticalSection section = new VerticalSection(); | 
  | 165 | 0 |          if (title !=  null) { | 
  | 166 | 0 |            section.getLayout().setLayoutTitle(title); | 
  | 167 |  |          } | 
  | 168 | 0 |          section.addStyleName("KS-CORE-Section"); | 
  | 169 | 0 |          if (withDivider) | 
  | 170 | 0 |              section.addStyleName("KS-CORE-Section-Divider"); | 
  | 171 | 0 |          return section; | 
  | 172 |  |      } | 
  | 173 |  |   | 
  | 174 |  |      private static VerticalSectionView initSectionView (Enum<?> viewEnum, String labelKey) { | 
  | 175 | 0 |          VerticalSectionView section = new VerticalSectionView(viewEnum, labelKey, ORG_PROPOSAL_MODEL); | 
  | 176 | 0 |          section.addStyleName("KS-CORE-Section"); | 
  | 177 | 0 |          section.getLayout().setLayoutTitle(getH1Title(labelKey)); | 
  | 178 | 0 |          return section; | 
  | 179 |  |      } | 
  | 180 |  |      private static SectionTitle getH1Title(String labelKey) { | 
  | 181 | 0 |          return SectionTitle.generateH1Title(getLabel(labelKey)); | 
  | 182 |  |      } | 
  | 183 |  |      private static SectionTitle getH3Title(String labelKey) { | 
  | 184 | 0 |          return SectionTitle.generateH3Title(getLabel(labelKey)); | 
  | 185 |  |      } | 
  | 186 |  |      public static String getLabel(String labelKey) { | 
  | 187 | 0 |          return Application.getApplicationContext().getUILabel(groupName, "org", "draft", labelKey); | 
  | 188 |  |      } | 
  | 189 |  |       | 
  | 190 |  |       | 
  | 191 |  |       | 
  | 192 |  |       | 
  | 193 |  |      protected FieldDescriptor addField(Section section, String fieldKey) { | 
  | 194 | 0 |              return addField(section, fieldKey, null, null, null); | 
  | 195 |  |      }     | 
  | 196 |  |      protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey) { | 
  | 197 | 0 |              return addField(section, fieldKey, messageKey, null, null); | 
  | 198 |  |      } | 
  | 199 |  |      protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget) { | 
  | 200 | 0 |              return addField(section, fieldKey, messageKey, widget, null); | 
  | 201 |  |      } | 
  | 202 |  |      protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, String parentPath) { | 
  | 203 | 0 |          return addField(section, fieldKey, messageKey, null, parentPath); | 
  | 204 |  |      } | 
  | 205 |  |      protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) { | 
  | 206 | 0 |          QueryPath path = QueryPath.concat(parentPath, fieldKey); | 
  | 207 | 0 |              Metadata meta = modelDefinition.getMetadata(path); | 
  | 208 |  |   | 
  | 209 | 0 |              FieldDescriptor fd = new FieldDescriptor(path.toString(), messageKey, meta); | 
  | 210 | 0 |              if (widget != null) { | 
  | 211 | 0 |                      fd.setFieldWidget(widget); | 
  | 212 |  |              } | 
  | 213 | 0 |              section.addField(fd); | 
  | 214 | 0 |              return fd; | 
  | 215 |  |      } | 
  | 216 |  |   | 
  | 217 |  |       | 
  | 218 |  |   | 
  | 219 |  |   | 
  | 220 |  |   | 
  | 221 |  |   | 
  | 222 |  |   | 
  | 223 |  |   | 
  | 224 |  |   | 
  | 225 | 0 |      public class CommonMultiplicityList extends UpdatableMultiplicityComposite { | 
  | 226 |  |          private  List<FieldInfo> fieldList; | 
  | 227 |  |          private String parentPath; | 
  | 228 |  |   | 
  | 229 |  |          public CommonMultiplicityList(String addItemLabel, String itemLabel,List<FieldInfo> fieldList,String parentPath) | 
  | 230 | 0 |          { | 
  | 231 | 0 |                  super(StyleType.TOP_LEVEL); | 
  | 232 | 0 |              setAddItemLabel(getLabel(addItemLabel)); | 
  | 233 | 0 |              setItemLabel(getLabel(itemLabel)); | 
  | 234 | 0 |              this.fieldList=fieldList; | 
  | 235 | 0 |              this.parentPath=parentPath; | 
  | 236 | 0 |          } | 
  | 237 |  |   | 
  | 238 |  |          @Override | 
  | 239 |  |          public MultiplicityItem getItemDecorator(StyleType style) { | 
  | 240 | 0 |              RemovableItemWithHeader item = new RemovableItemWithHeader(style); | 
  | 241 | 0 |              item.setItemLabel(itemLabel); | 
  | 242 |  |   | 
  | 243 | 0 |              if(parentPath.equals(POSITION_PATH)){ | 
  | 244 | 0 |                  QueryPath qPath = QueryPath.concat(null, POSITION_PATH); | 
  | 245 | 0 |                  Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 246 | 0 |                  if(!meta.isCanEdit()){ | 
  | 247 | 0 |                      item.isReadOnly(true); | 
  | 248 |  |                  } | 
  | 249 |  |                  else{ | 
  | 250 | 0 |                      item.isReadOnly(false); | 
  | 251 |  |                  } | 
  | 252 |  |              } | 
  | 253 | 0 |              if(parentPath.equals(ORGORG_PATH)){ | 
  | 254 | 0 |                  QueryPath qPath = QueryPath.concat(null, ORGORG_PATH); | 
  | 255 | 0 |                  Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 256 | 0 |                  if(!meta.isCanEdit()){ | 
  | 257 | 0 |                      item.isReadOnly(true); | 
  | 258 |  |                  } | 
  | 259 |  |                  else{ | 
  | 260 | 0 |                      item.isReadOnly(false); | 
  | 261 |  |                  } | 
  | 262 |  |              } | 
  | 263 | 0 |              if(parentPath.equals(PERSON_PATH)){ | 
  | 264 | 0 |                  QueryPath qPath = QueryPath.concat(null, PERSON_PATH); | 
  | 265 | 0 |                  Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 266 | 0 |                  if(!meta.isCanEdit()){ | 
  | 267 | 0 |                      item.isReadOnly(true); | 
  | 268 |  |                  } | 
  | 269 |  |                  else{ | 
  | 270 | 0 |                      item.isReadOnly(false); | 
  | 271 |  |                  } | 
  | 272 |  |              } | 
  | 273 | 0 |              return item; | 
  | 274 |  |          } | 
  | 275 |  |   | 
  | 276 |  |          public Widget generateAddWidget() { | 
  | 277 |  |               | 
  | 278 |  |               | 
  | 279 |  |              KSButton addWidget; | 
  | 280 | 0 |              if(style == StyleType.TOP_LEVEL){ | 
  | 281 | 0 |                  addWidget = new KSButton(addItemLabel, ButtonStyle.FORM_LARGE); | 
  | 282 |  |              } | 
  | 283 |  |              else{ | 
  | 284 | 0 |                  addWidget = new KSButton(addItemLabel, ButtonStyle.FORM_SMALL); | 
  | 285 |  |              } | 
  | 286 | 0 |              addWidget.addClickHandler(new ClickHandler(){ | 
  | 287 |  |                  public void onClick(ClickEvent event) { | 
  | 288 | 0 |                      addItem(); | 
  | 289 | 0 |                  } | 
  | 290 |  |              }); | 
  | 291 |  |   | 
  | 292 | 0 |              if(parentPath.equals(POSITION_PATH)){ | 
  | 293 | 0 |                  QueryPath qPath = QueryPath.concat(null, POSITION_PATH); | 
  | 294 | 0 |                  Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 295 | 0 |                  if(!meta.isCanEdit()){ | 
  | 296 | 0 |                      addWidget.setEnabled(false); | 
  | 297 |  |                  } | 
  | 298 |  |                  else{ | 
  | 299 | 0 |                      addWidget.setEnabled(true); | 
  | 300 |  |                  } | 
  | 301 |  |              } | 
  | 302 | 0 |              if(parentPath.equals(ORGORG_PATH)){ | 
  | 303 | 0 |                  QueryPath qPath = QueryPath.concat(null, ORGORG_PATH); | 
  | 304 | 0 |                  Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 305 | 0 |                  if(!meta.isCanEdit()){ | 
  | 306 | 0 |                      addWidget.setEnabled(false); | 
  | 307 |  |                  } | 
  | 308 |  |                  else{ | 
  | 309 | 0 |                      addWidget.setEnabled(true); | 
  | 310 |  |                  } | 
  | 311 |  |              } | 
  | 312 | 0 |              if(parentPath.equals(PERSON_PATH)){ | 
  | 313 | 0 |                  QueryPath qPath = QueryPath.concat(null, PERSON_PATH); | 
  | 314 | 0 |                  Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 315 | 0 |                  if(!meta.isCanEdit()){ | 
  | 316 | 0 |                      addWidget.setEnabled(false); | 
  | 317 |  |                  } | 
  | 318 |  |                  else{ | 
  | 319 | 0 |                      addWidget.setEnabled(true); | 
  | 320 |  |                  } | 
  | 321 |  |              } | 
  | 322 | 0 |              return addWidget; | 
  | 323 |  |          } | 
  | 324 |  |   | 
  | 325 |  |          private boolean readPermission(String path){ | 
  | 326 | 0 |              QueryPath qPath = QueryPath.concat(null, path); | 
  | 327 | 0 |              Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 328 | 0 |              return meta.isCanEdit(); | 
  | 329 |  |          } | 
  | 330 |  |          @Override | 
  | 331 |  |          public Widget createItem() { | 
  | 332 | 0 |              String path = QueryPath.concat(parentPath, String.valueOf(itemCount-1)).toString(); | 
  | 333 | 0 |              GroupSection ns = new GroupSection(); | 
  | 334 |  |               | 
  | 335 | 0 |              for (FieldInfo field : fieldList) { | 
  | 336 |  |   | 
  | 337 |  |   | 
  | 338 |  |   | 
  | 339 |  |   | 
  | 340 |  |   | 
  | 341 |  |   | 
  | 342 |  |   | 
  | 343 |  |   | 
  | 344 |  |   | 
  | 345 |  |   | 
  | 346 | 0 |                  Widget widget = null; | 
  | 347 |  |                   | 
  | 348 | 0 |                  if (field.getWidget() != null) { | 
  | 349 | 0 |                      QueryPath qPath = QueryPath.concat(path, field.getKey()); | 
  | 350 | 0 |                      Metadata meta = modelDefinition.getMetadata(qPath); | 
  | 351 | 0 |                      if (field.getWidget().equals("OrgRelationTypePicker")) { | 
  | 352 |  |   | 
  | 353 | 0 |                          if(meta.isCanEdit()){ | 
  | 354 | 0 |                              widget = new OrgRelationTypePicker(); | 
  | 355 |  |   | 
  | 356 |  |                          } | 
  | 357 |  |                          else{ | 
  | 358 |  |   | 
  | 359 |  |   | 
  | 360 |  |   | 
  | 361 |  |   | 
  | 362 |  |   | 
  | 363 |  |   | 
  | 364 |  |   | 
  | 365 |  |   | 
  | 366 |  |   | 
  | 367 |  |   | 
  | 368 |  |   | 
  | 369 |  |   | 
  | 370 |  |   | 
  | 371 |  |   | 
  | 372 | 0 |                              widget = new KSLabel(); | 
  | 373 |  |                          } | 
  | 374 |  |   | 
  | 375 |  |                      } | 
  | 376 |  |   | 
  | 377 | 0 |                      if (field.getWidget().equals("OrgPositionTypePicker")) { | 
  | 378 |  |   | 
  | 379 | 0 |                          widget = new OrgPositionTypePicker(); | 
  | 380 |  |                      } | 
  | 381 | 0 |                      if (field.getWidget().equals("OrgPersonRelationTypePicker")) { | 
  | 382 | 0 |                          if(meta.isCanEdit()){ | 
  | 383 | 0 |                          personRelationPicker = new OrgPersonRelationTypePicker(); | 
  | 384 | 0 |                          personRelationPicker.setOrgId(orgId); | 
  | 385 | 0 |                          widget = personRelationPicker; | 
  | 386 |  |                          } | 
  | 387 |  |                          else{ | 
  | 388 | 0 |                              widget = new KSLabel(); | 
  | 389 |  |                          } | 
  | 390 |  |   | 
  | 391 |  |                      } | 
  | 392 |  |   | 
  | 393 |  |   | 
  | 394 |  |                  } | 
  | 395 | 0 |                  addField(ns, field.getKey(), generateMessageInfo(field.getLabel()),widget,path);     | 
  | 396 | 0 |              } | 
  | 397 | 0 |              return ns; | 
  | 398 |  |          } | 
  | 399 |  |      } | 
  | 400 |  |   | 
  | 401 |  |   | 
  | 402 |  |  } |