Ejemplo n.º 1
0
  private void fetchCheckBoxState() {
    rpcService.fetchCheckBoxStateFor(
        display.getStrategicDTO().getStrategicId(),
        new AsyncCallback<ArrayList<JobAndAreaOfExpertise>>() {

          @Override
          public void onSuccess(ArrayList<JobAndAreaOfExpertise> result) {

            String title = "";

            for (int i = 0; i < result.size(); ++i) {
              if (result.get(i).getIsChecked() == 1)
                title += result.get(i).getAreaOfExpertise().getDepartmentName() + " ";
            }

            display.getAreaOfExpertise().setText(title);
          }

          @Override
          public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub

          }
        });
  }
Ejemplo n.º 2
0
  private void fetchSkillResources(
      final ArrayList<ResourceUse> resourceList, final boolean updateState) {
    rpcService.fetchSkills(
        new AsyncCallback<ArrayList<Skills>>() {

          @Override
          public void onFailure(Throwable caught) {
            Window.alert("failed to load skill list");
          }

          @Override
          public void onSuccess(ArrayList<Skills> skillsList) {

            display.getSkillsResourceContainer().clear();

            for (int i = 0; i < skillsList.size(); i++) {
              SkillsResources skillsResources = new SkillsResources();

              skillsResources
                  .getSkillsList()
                  .addItem(skillsList.get(i).getSkillName(), skillsList.get(i).getSkillId() + "");

              skillsResources.setAvailableHours(skillsList.get(i).getAvailableHours());

              skillsResources.getNoOfResources().setText("0");

              skillsResources
                  .getNoOfResources()
                  .addBlurHandler(
                      new BlurHandler() {

                        @Override
                        public void onBlur(BlurEvent event) {
                          calculateManHours();
                        }
                      });

              skillsResources.getSkillsList().setSelectedIndex(i);

              display.getSkillsResourceContainer().add(skillsResources);
              display.getSkillsResourceContainer().addStyleName("spacer");
              skillsResources.getSkillsList().addStyleName("lstSkillResources");
              skillsResources.getNoOfResources().addStyleName("spacer");
            }

            if (updateState && resourceList != null) {
              for (int i = 0; i < resourceList.size(); i++) {

                ((SkillsResources) display.getSkillsResourceContainer().getWidget(i))
                    .getSkillsList()
                    .addItem(
                        resourceList.get(i).getSkill().getSkillName(),
                        resourceList.get(i).getSkill().getSkillId() + "");

                ((SkillsResources) display.getSkillsResourceContainer().getWidget(i))
                    .getNoOfResources()
                    .setText(String.valueOf(resourceList.get(i).getNoOfResources()));

                ((SkillsResources) display.getSkillsResourceContainer().getWidget(i))
                    .getSkillsList()
                    .setSelectedIndex(i);
              }
            }
          }
        });
  }
Ejemplo n.º 3
0
  private void bind() {
    // if a record is foung in db- then I create widgets acc to db record
    // set the values of form fields accordingly

    rpcService.fetchJobTime(
        display.getStrategicDTO().getStrategicId(),
        new AsyncCallback<JobTimeEstimationDTO>() {

          @Override
          public void onSuccess(JobTimeEstimationDTO result) {

            //
            //	display.getEstimatedWeeks().setText(String.valueOf(result.getJobTimeEstimation().getEstimatedWeeks()));

            if (result != null) {
              // Window.alert("not null");

              display.setJobEstimationId(result.getJobTimeEstimation().getJobTimeEstimationId());

              for (int i = 0; i < display.getEstWeeksListBox().getItemCount(); i++) {
                if (display
                    .getEstWeeksListBox()
                    .getItemText(i)
                    .equals(String.valueOf(result.getJobTimeEstimation().getEstimatedWeeks()))) {
                  display.getEstWeeksListBox().setSelectedIndex(i);
                  break;
                }
              }

              display
                  .getJobTimeEstId()
                  .setText(String.valueOf(result.getJobTimeEstimation().getJobTimeEstimationId()));

              display
                  .getEstWeeksListBox()
                  .addItem(String.valueOf(result.getJobTimeEstimation().getEstimatedWeeks()));

              // display.getFieldWorkManHours().setText(
              // String.valueOf(result.getJobTimeEstimation().getManagementHours() ));

              display
                  .getTotalWorkingManHours()
                  .setText(String.valueOf(result.getJobTimeEstimation().getHoursInclTravel()));

              display
                  .getFieldWorkManHours()
                  .setText(String.valueOf(result.getJobTimeEstimation().getFieldWorkManHours()));

              display
                  .getMgmtHours()
                  .setText(String.valueOf(result.getJobTimeEstimation().getManagementHours()));

              display
                  .getHoursInclusiveOfTravel()
                  .setText(String.valueOf(result.getJobTimeEstimation().getHoursInclTravel()));

              for (int i = 0; i < display.getPlaceofWorkListBox().getItemCount(); i++) {
                if (display
                    .getPlaceofWorkListBox()
                    .getItemText(i)
                    .equals(String.valueOf(result.getJobTimeEstimation().getTravelDays()))) {
                  display.getPlaceofWorkListBox().setSelectedIndex(i);
                  break;
                }
              }

              // display.getPlaceofWorkListBox().addItem(
              // result.getJobTimeEstimation().getPlaceOfWork());

              display
                  .getHighLevelScopeOfWork()
                  .setText(result.getJobTimeEstimation().getScopeOfWork());

              for (int i = 0; i < display.getTravelingDaysListBox().getItemCount(); i++) {
                if (display
                    .getTravelingDaysListBox()
                    .getItemText(i)
                    .equals(String.valueOf(result.getJobTimeEstimation().getTravelDays())))
                  display.getTravelingDaysListBox().setSelectedIndex(i);
              }

              display
                  .getTotalWorkingManHoursTextBox()
                  .setText(String.valueOf(result.getJobTimeEstimation().getTotalWorkingManHours()));
              display.getSkillsResourceContainer().clear();

              fetchSkillResources(result.getResourceUse(), true);
            }
          }

          @Override
          public void onFailure(Throwable caught) {
            System.out.println("fail");
          }
        });

    display
        .getBackButton()
        .addClickHandler(
            new ClickHandler() {

              @Override
              public void onClick(ClickEvent event) {
                // TODO Auto-generated method stub
                History.newItem("auditScheduling");
              }
            });
    display.getHeading().setText(display.getStrategicDTO().getStrategicObjective());

    display.getFieldWorkManHours().setText("0");

    display
        .getSaveJobTimeEst()
        .addClickHandler(
            new ClickHandler() {

              @Override
              public void onClick(ClickEvent event) {

                // store the current state of form in DTO

                JobTimeEstimation jobTimeEstEntity = new JobTimeEstimation();
                ArrayList<ResourceUse> resourceAndNo = new ArrayList<ResourceUse>();
                ArrayList<SkillUpdateData> updateForSkills = new ArrayList<SkillUpdateData>();

                try {

                  jobTimeEstEntity.setJobTimeEstimationId(
                      Integer.parseInt(display.getJobTimeEstId().getText()));

                  jobTimeEstEntity.setJobId(display.getStrategicDTO().getStrategicId());

                  jobTimeEstEntity.setEstimatedWeeks(
                      Integer.parseInt(
                          display
                              .getEstWeeksListBox()
                              .getItemText(display.getEstWeeksListBox().getSelectedIndex())));

                  jobTimeEstEntity.setFieldWorkManHours(
                      Integer.parseInt(display.getFieldWorkManHours().getText().toString()));

                  jobTimeEstEntity.setTotalWorkingManHours(
                      Integer.parseInt(display.getTotalWorkingManHours().getText().toString()));

                  jobTimeEstEntity.setManagementHours(
                      Integer.parseInt(display.getMgmtHours().getText().toString()));

                  jobTimeEstEntity.setHoursInclTravel(
                      Integer.parseInt(display.getHoursInclusiveOfTravel().getText().toString()));

                  jobTimeEstEntity.setPlaceOfWork(
                      display
                          .getPlaceofWorkListBox()
                          .getItemText(display.getPlaceofWorkListBox().getSelectedIndex()));

                  jobTimeEstEntity.setScopeOfWork(
                      display.getHighLevelScopeOfWork().getText().toString());

                  jobTimeEstEntity.setTravelDays(
                      Integer.parseInt(
                          display
                              .getTravelingDaysListBox()
                              .getItemText(display.getTravelingDaysListBox().getSelectedIndex())));

                  jobTimeEstEntity.setHoursInclTravel(
                      jobTimeEstEntity.getTotalWorkingManHours()
                          + jobTimeEstEntity.getTravelDays() * 8);

                  // since the size of listbox is dynamic, we need to get it at the runtime
                  // 0th widget of the VerticalPanel is always a 'SkillResource'
                  // we cast it to the Type and get skilllist size
                  int listSize = /*((SkillsResources)*/
                      display
                          .getSkillsResourceContainer()
                          .getWidgetCount(); // (0)).getSkillsList().getItemCount();

                  boolean maxHoursReached = false;

                  // loop through all the list boxes and get the selected index and value / text
                  for (int i = 0; i < listSize; i++) {
                    // ith widget of Vpanel is always a 'SkillResource'
                    SkillsResources res =
                        ((SkillsResources) display.getSkillsResourceContainer().getWidget(i));

                    ResourceUse r = new ResourceUse();

                    int hoursReqd =
                        Integer.parseInt(res.getNoOfResources().getText().toString())
                            * 40
                            * jobTimeEstEntity.getEstimatedWeeks();

                    if (hoursReqd > res.getAvailableHours()) {
                      maxHoursReached = false;

                      System.out.println(
                          "You have selected more hours than available hours for "
                              + res.getSkillsList()
                                  .getItemText(res.getSkillsList().getSelectedIndex()));

                      // return;

                    }
                    // get id of skill

                    SkillUpdateData updatedInfoForSkill = new SkillUpdateData();

                    updatedInfoForSkill.setSkillId(
                        Integer.parseInt(res.getSkillsList().getValue(0)));
                    updatedInfoForSkill.setHoursToSubt(hoursReqd);

                    updateForSkills.add(updatedInfoForSkill);

                    // get spent hour

                    // update db

                    r.setNoOfResources(
                        Integer.parseInt(res.getNoOfResources().getText().toString()));

                    int index = res.getSkillsList().getSelectedIndex();

                    // how to set this ? ..
                    Skills skills = new Skills();
                    skills.setSkillId(Integer.parseInt(res.getSkillsList().getValue(index)));
                    r.setSkillId(skills);

                    resourceAndNo.add(r);
                  }

                } catch (NumberFormatException e) {

                  Window.alert("Please enter a number, characters are not allowed");
                  return;
                }

                JobTimeEstimationDTO dto = new JobTimeEstimationDTO();

                dto.setJobTimeEstimation(jobTimeEstEntity);
                dto.setResourceUse(resourceAndNo);

                rpcService.saveJobTimeEstimation(
                    dto,
                    updateForSkills,
                    new AsyncCallback<Boolean>() {

                      @Override
                      public void onSuccess(Boolean savedSuccess) {

                        if (savedSuccess) {
                          new DisplayAlert("Job Estimation Saved");
                          History.newItem("auditScheduling");
                        } else Window.alert("There are not enough number of Resources available");
                      }

                      @Override
                      public void onFailure(Throwable caught) {}
                    });

                // History.newItem("jobCreation");

              }
            });

    display
        .getEstWeeksListBox()
        .addChangeHandler(
            new ChangeHandler() {

              @Override
              public void onChange(ChangeEvent event) {
                calculateManHours();
              }
            });

    display
        .getPlaceofWorkListBox()
        .addChangeHandler(
            new ChangeHandler() {

              @Override
              public void onChange(ChangeEvent event) {

                int index = display.getPlaceofWorkListBox().getSelectedIndex();

                String place = display.getPlaceofWorkListBox().getItemText(index);

                if (place.equals("Outstation")) {
                  display.getTravelingDaysListBox().setEnabled(true);
                  display.getTravelingDaysListBox().setSelectedIndex(0);
                }

                if (place.equals("Inhouse")) {
                  // as we have inhouse work, we dont need to go wandering
                  display.getTravelingDaysListBox().setEnabled(false);

                  // if the user previously selected outstation, this will recalculate the traveling
                  // hours and
                  // hours incl travel

                  int hoursToSubt =
                      Integer.parseInt(
                          display
                              .getTravelingDaysListBox()
                              .getItemText(display.getTravelingDaysListBox().getSelectedIndex()));

                  int currentHoursForTravel =
                      Integer.parseInt(display.getHoursInclusiveOfTravel().getText());

                  display
                      .getHoursInclusiveOfTravel()
                      .setText(String.valueOf(currentHoursForTravel - hoursToSubt * 8));

                  display.getTravelingDaysListBox().setSelectedIndex(0);
                }
              }
            });

    display
        .getMgmtHours()
        .addKeyUpHandler(
            new KeyUpHandler() { // for later

              @Override
              public void onKeyUp(KeyUpEvent event) {
                try {
                  calculateHoursInclTravel();

                } catch (Exception e) {
                  display.getMgmtHours().setText("");
                  display.getTotalWorkingManHours().setText("");
                  display.getTotalWorkingManHours().setText("Please enter a correct value");
                  event.preventDefault();
                }
              }
            });

    display
        .getTravelingDaysListBox()
        .addChangeHandler(
            new ChangeHandler() {

              @Override
              public void onChange(ChangeEvent event) {
                calculateHoursInclTravel();
              }
            });

    // this.

    // if ( ! display.isListCreated() )
    // {

    fetchSkillResources(null, false);
  }