public ListBoxItem(String name, String title) {
    super(name, title);

    listBox = new ListBox();
    listBox.setName(name);
    listBox.setTitle(title);
    listBox.setVisibleItemCount(5);
    listBox.setTabIndex(0);
    listBox.setHeight("50px");

    valueChangeHandler =
        new ChangeHandler() {
          @Override
          public void onChange(ChangeEvent event) {}
        };
    listBox.addChangeHandler(valueChangeHandler);

    wrapper = new HorizontalPanel();
    wrapper.add(listBox);
  }
Example #2
0
 @Test
 public void checkName() {
   ListBox listBox = new ListBox(false);
   listBox.setName("name");
   Assert.assertEquals("name", listBox.getName());
 }
  private void createComponent() {
    hlBack = new Anchor("<<back");
    hlBack.addClickHandler(this);
    vPanel.add(hlBack);
    ProjectItems projectItems = currentUser.getProjectItems();
    if (projectItems.getProjectItemCount() == 0) {
      vPanel.add(new HTML("You are not subscribed to any projects."));
    } else {
      vPanel.add(form);
      lbProjects = new ListBox(false);
      lbProjects.addChangeHandler(this);
      vPanel.setSize("1000px", "500px");
      table.setCellSpacing(5);
      table.setCellPadding(0);
      table.setWidth("100%");
      tbName.setWidth("300px");
      // tbDescription.setWidth("300px");
      txtFileNotes.setHeight("75px");
      upload.setName("uploadFormElement");
      // fileUpload.setName("fileuploadFormElement");
      tbName.setName("name");
      tbDescription.setName("description");
      txtFileNotes.setName("notes");
      lbProjects.setName("projectDetails");
      btnSubmit.addClickHandler(this);
      txtWarnings.setStylePrimaryName("warnings");
      txtWarningDesc.setStylePrimaryName("warnings");
      txtFileNotes.setCharacterWidth(50);
      tbName.setMaxLength(50);
      // tbDescription.setMaxLength(255);
      // tbDescription.setText("");
      txtLogin = new TextBox();
      txtLogin.setName("user");
      txtLogin.setVisible(false);

      txtProject = new TextBox();
      txtProject.setName("projectName");
      txtProject.setVisible(false);

      int projectId = currentUser.getPreferredProjectId();

      for (int i = 0; i < projectItems.getProjectItemCount(); i++) {
        ProjectItem item = projectItems.getProjectItem(i);
        lbProjects.addItem(item.getProjectName(), String.valueOf(item.getProjectId()));
        if (projectId > 0) {
          if (projectId == item.getProjectId()) {
            lbProjects.setItemSelected(i, true);
          }
        } else {
          lbProjects.setItemSelected(0, true);
        }
      }

      table.setText(0, 0, "");
      table.setWidget(0, 1, txtWarnings);
      table.setText(1, 0, "");
      table.setWidget(1, 1, txtWarningDesc);
      table.setWidget(2, 0, new HTML("<b>Name:</b>&nbsp;&nbsp;&nbsp;"));
      table.setWidget(2, 1, tbName);
      table.setWidget(3, 0, new HTML("<b>File:</b>&nbsp;&nbsp;&nbsp;"));
      table.setWidget(3, 1, upload);
      // table.setWidget(4, 0, new HTML("<b>Description:</b>&nbsp;&nbsp;&nbsp;"));
      // table.setWidget(4, 1, fileUpload);
      table.setWidget(5, 0, new HTML("<b>Project:</b>&nbsp;&nbsp;&nbsp;"));
      table.setWidget(5, 1, lbProjects);
      table.setWidget(6, 0, new HTML("<b>Notes:</b>&nbsp;&nbsp;&nbsp;"));
      table.setWidget(6, 1, txtFileNotes);
      table.setWidget(7, 1, btnSubmit);
      table.setWidget(7, 2, txtLogin);
      table.setWidget(7, 3, txtProject);

      table.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(4, 0, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(5, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(5, 0, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(6, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(6, 0, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(7, 0, HasHorizontalAlignment.ALIGN_RIGHT);
      table.getCellFormatter().setVerticalAlignment(7, 0, HasVerticalAlignment.ALIGN_TOP);

      table.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(1, 1, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(2, 1, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(3, 1, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(4, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(4, 1, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(5, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(5, 1, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(6, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(6, 1, HasVerticalAlignment.ALIGN_TOP);
      table.getCellFormatter().setHorizontalAlignment(7, 1, HasHorizontalAlignment.ALIGN_LEFT);
      table.getCellFormatter().setVerticalAlignment(7, 1, HasVerticalAlignment.ALIGN_TOP);

      form.add(table);

      form.setAction(UPLOAD_ACTION_URL);
      form.setEncoding(FormPanel.ENCODING_MULTIPART);
      form.setMethod(FormPanel.METHOD_POST);

      form.addSubmitHandler(
          new FormPanel.SubmitHandler() {
            public void onSubmit(SubmitEvent event) {
              // This event is fired just before the form is submitted. We can
              // take this opportunity to perform validation.
              String fileName1 = upload.getFilename().trim();
              // String fileName2 = fileUpload.getFilename().trim();
              // System.out.println("File1: " + fileName1);
              if (fileName1.length() == 0 && tbName.getText().length() == 0) {
                txtWarnings.setHTML("*Please upload a file.");
                txtWarningDesc.setHTML("*Please enter the Job name.");
                event.cancel();
              }
              if ((fileName1.length() == 0) && tbName.getText().length() != 0) {
                txtWarnings.setText("");
                txtWarningDesc.setText("");
                txtWarnings.setHTML("*Please upload a file.");
                event.cancel();
              }
              if ((!(fileName1.length() == 0)) && tbName.getText().length() == 0) {
                txtWarnings.setText("");
                txtWarningDesc.setText("");
                txtWarnings.setHTML("*Please enter the Job name.");
                event.cancel();
              }
            }
          });

      form.addSubmitCompleteHandler(
          new FormPanel.SubmitCompleteHandler() {
            public void onSubmitComplete(SubmitCompleteEvent event) {
              txtFileNotes.setText("");
              txtWarningDesc.setText("");
              String sessionID = Cookies.getCookie("sid");
              if (sessionID != null) {
                String result = event.getResults();
                System.out.println("UploadJob Result: " + result);
                // Log.info("Result: " + result);
                String[] results = result.split("~");
                /*for(int i = 0; i < results.length; i++)
                {
                	 System.out.println(results[i]);
                	 try
                	 {
                		 jobId = Integer.parseInt(results[0]);
                	 }
                	 catch(NumberFormatException e)
                	 {
                		 e.printStackTrace();
                	 }
                }*/
                int jobId = -1;
                try {
                  jobId = Integer.parseInt(results[0]);
                } catch (NumberFormatException e) {
                  e.printStackTrace();
                }
                // Code modified
                if (jobId == 0) {
                  txtWarnings.setHTML(results[1]);
                }
                // Code modified
                // txtWarnings.setHTML(results[1]);

                else {
                  if (currentUser.getUsertype().equalsIgnoreCase("user")) {
                    History.newItem("userJobList");
                  } else {
                    if (tab == 0) {

                      History.newItem("adminJobList");
                    } else {
                      History.newItem("jobList");
                    }
                    // AdminPage adminPage = new AdminPage(tab);
                    // RootPanel.get("content").add(adminPage);
                  }
                }
              } else {
                Login login = new Login();
                login.displayLoginBox();
              }
            }
          });
    }
  }