protected boolean isValidEmail(final String email) {
   boolean isValid = true;
   if (StringUtils.isEmpty(email)) {
     isValid = false;
   } else {
     isValid = email.matches(EMAIL_PATTERN);
   }
   return isValid;
 }
 public void onChange(ChangeEvent evt) {
   if (hasMultiselection(rolesListBox)) {
     availableMembersListBox.clear();
     selectedMembersListBox.clear();
   } else {
     String role = rolesListBox.getValue(rolesListBox.getSelectedIndex());
     if (!StringUtils.isEmpty(role)) {
       getUsersInRole(role);
     }
   }
   rolesPermissionsPanel.setSelectedPermissions();
 }
 public void onChange(ChangeEvent evt) {
   if (hasMultiselection(usersListBox)) {
     userPasswordTextBox.setText("");
     editPasswordButton.setEnabled(false);
     availableRolesListBox.clear();
     selectedRolesListBox.clear();
   } else {
     String user = usersListBox.getValue(usersListBox.getSelectedIndex());
     if (!StringUtils.isEmpty(user)) {
       getRolesForUser(user);
       userPasswordTextBox.setText("fakepassword");
       editPasswordButton.setEnabled(true);
     }
   }
 }
  private void handleWizardPanels(final JSONObject schedule, final JsJobTrigger trigger) {
    if (hasParams) {
      showScheduleParamsDialog(trigger, schedule);
    } else if (isEmailConfValid) {
      showScheduleEmailDialog(schedule);
    } else {
      // submit
      JSONObject scheduleRequest = (JSONObject) JSONParser.parseStrict(schedule.toString());

      if (editJob != null) {
        JSONArray scheduleParams = new JSONArray();

        for (int i = 0; i < editJob.getJobParams().length(); i++) {
          JsJobParam param = editJob.getJobParams().get(i);
          JsArrayString paramValue = (JsArrayString) JavaScriptObject.createArray().cast();
          paramValue.push(param.getValue());
          JsSchedulingParameter p = (JsSchedulingParameter) JavaScriptObject.createObject().cast();
          p.setName(param.getName());
          p.setType("string"); // $NON-NLS-1$
          p.setStringValue(paramValue);
          scheduleParams.set(i, new JSONObject(p));
        }

        scheduleRequest.put("jobParameters", scheduleParams); // $NON-NLS-1$

        String actionClass =
            editJob.getJobParamValue("ActionAdapterQuartzJob-ActionClass"); // $NON-NLS-1$
        if (!StringUtils.isEmpty(actionClass)) {
          scheduleRequest.put("actionClass", new JSONString(actionClass)); // $NON-NLS-1$
        }
      }

      RequestBuilder scheduleFileRequestBuilder =
          new RequestBuilder(RequestBuilder.POST, contextURL + "api/scheduler/job"); // $NON-NLS-1$
      scheduleFileRequestBuilder.setHeader(
          "Content-Type", "application/json"); // $NON-NLS-1$//$NON-NLS-2$
      scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

      try {
        scheduleFileRequestBuilder.sendRequest(
            scheduleRequest.toString(),
            new RequestCallback() {
              public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox =
                    new MessageDialogBox(
                        Messages.getString("error"),
                        exception.toString(),
                        false,
                        false,
                        true); //$NON-NLS-1$
                dialogBox.center();
                setDone(false);
              }

              public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                  setDone(true);
                  ScheduleRecurrenceDialog.this.hide();
                  if (callback != null) {
                    callback.okPressed();
                  }
                  if (showSuccessDialog) {
                    if (!PerspectiveManager.getInstance()
                        .getActivePerspective()
                        .getId()
                        .equals(PerspectiveManager.SCHEDULES_PERSPECTIVE)) {
                      ScheduleCreateStatusDialog successDialog = new ScheduleCreateStatusDialog();
                      successDialog.center();
                    } else {
                      MessageDialogBox dialogBox =
                          new MessageDialogBox(
                              Messages.getString("scheduleUpdatedTitle"),
                              Messages.getString(
                                  "scheduleUpdatedMessage"), //$NON-NLS-1$ //$NON-NLS-2$
                              false,
                              false,
                              true);
                      dialogBox.center();
                    }
                  }
                } else {
                  MessageDialogBox dialogBox =
                      new MessageDialogBox(
                          Messages.getString("error"), // $NON-NLS-1$
                          response.getText(),
                          false,
                          false,
                          true);
                  dialogBox.center();
                  setDone(false);
                }
              }
            });
      } catch (RequestException e) {
        MessageDialogBox dialogBox =
            new MessageDialogBox(
                Messages.getString("error"),
                e.toString(), // $NON-NLS-1$
                false,
                false,
                true);
        dialogBox.center();
        setDone(false);
      }

      setDone(true);
    }
  }
  public void loadBundle(
      String path,
      final String bundleName,
      boolean attemptLocalizedFetches,
      IResourceBundleLoadCallback bundleLoadCallback) {
    this.bundleName = bundleName;
    this.bundleLoadCallback = bundleLoadCallback;
    this.attemptLocalizedFetches = attemptLocalizedFetches;

    if (!StringUtils.isEmpty(path) && !path.endsWith("/")) { // $NON-NLS-1$
      path = path + "/"; // $NON-NLS-1$
    }
    this.path = path;

    // get the locale meta property if the url parameter is missing
    initCallbacks();
    // decompose locale
    // _en_US
    // 1. bundleName.properties
    // 2. bundleName_en.properties
    // 3. bundleName_en_US.properties

    final ResourceBundle supportedLanguagesBundle = new ResourceBundle();
    // callback for when supported_locales has been fetched (if desired)
    IResourceBundleLoadCallback supportedLangCallback =
        new IResourceBundleLoadCallback() {
          public void bundleLoaded(String ignore) {
            // supportedLanguages will be null if the user did not set them prior to loadBundle
            // if the user already set them, keep 'em, it's an override
            if (ResourceBundle.this.supportedLanguages == null) {
              ResourceBundle.this.supportedLanguages = supportedLanguagesBundle.getMap();
            }
            // always fetch the base first
            currentAttemptUrl =
                ResourceBundle.this.path + bundleName + PROPERTIES_EXTENSION + getUrlExtras();
            if (bundleCache.containsKey(currentAttemptUrl)) {
              // call in a separate timeout, to simulate the request builder call as closely as
              // possible
              Timer t =
                  new Timer() {
                    @Override
                    public void run() {
                      baseCallback.onResponseReceived(
                          null, new FakeResponse(bundleCache.get(currentAttemptUrl)));
                    }
                  };
              t.schedule(1);
            } else {
              RequestBuilder requestBuilder =
                  new RequestBuilder(RequestBuilder.GET, currentAttemptUrl);
              try {
                requestBuilder.sendRequest(null, baseCallback);
              } catch (RequestException e) {
                Window.alert("base load: " + e.getMessage()); // $NON-NLS-1$
                fireBundleLoadCallback();
              }
            }
          }
        };

    // supportedLanguages will not be null if they've already been set by the user, and in that
    // case,
    // we do not want attempt to load that bundle..
    if (attemptLocalizedFetches && supportedLanguages == null) {
      // load supported_languages bundle
      supportedLanguagesBundle.loadBundle(
          path, "supported_languages", false, supportedLangCallback); // $NON-NLS-1$
    } else {
      // simulate callback
      supportedLangCallback.bundleLoaded("supported_languages"); // $NON-NLS-1$
    }
  }
  public void onMantleSettingsLoaded(MantleSettingsLoadedEvent event) {
    final HashMap<String, String> settings = event.getSettings();
    final String startupPerspective = Window.Location.getParameter("startupPerspective");

    mantleRevisionOverride = settings.get("user-console-revision");
    RootPanel.get("pucMenuBar").add(MantleXul.getInstance().getMenubar());
    if (!StringUtils.isEmpty(startupPerspective)) {
      RootPanel.get("pucMenuBar").setVisible(false);
    }

    RootPanel.get("pucPerspectives").add(PerspectiveManager.getInstance());
    if (!StringUtils.isEmpty(startupPerspective)) {
      RootPanel.get("pucPerspectives").setVisible(false);
    }

    RootPanel.get("pucToolBar").add(MantleXul.getInstance().getToolbar());
    if (!StringUtils.isEmpty(startupPerspective)) {
      RootPanel.get("pucToolBar").setVisible(false);
    }

    // update supported file types
    PluginOptionsHelper.buildEnabledOptionsList(settings);

    // show stuff we've created/configured
    contentDeck.add(new Label());
    contentDeck.showWidget(0);
    contentDeck.add(SolutionBrowserPanel.getInstance());
    if (!StringUtils.isEmpty(startupPerspective)) {
      SolutionBrowserPanel.getInstance().setVisible(false);
    }

    contentDeck.getElement().setId("applicationShell");
    contentDeck.setStyleName("applicationShell");

    // menubar=no,location=no,resizable=yes,scrollbars=no,status=no,width=1200,height=800
    try {
      RootPanel.get("pucContent").add(contentDeck);
    } catch (Throwable t) {
      // onLoad of something is causing problems
    }

    RootPanel.get().add(WaitPopup.getInstance());

    // Add in the overlay panel
    overlayPanel.setVisible(false);
    overlayPanel.setHeight("100%");
    overlayPanel.setWidth("100%");
    overlayPanel.getElement().getStyle().setProperty("zIndex", "1000");
    overlayPanel.getElement().getStyle().setProperty("position", "absolute");
    RootPanel.get().add(overlayPanel, 0, 0);

    String showAdvancedFeaturesSetting = settings.get("show-advanced-features"); // $NON-NLS-1$
    showAdvancedFeatures =
        showAdvancedFeaturesSetting == null
            ? showAdvancedFeatures
            : Boolean.parseBoolean(showAdvancedFeaturesSetting);

    String submitOnEnterSetting = settings.get("submit-on-enter-key");
    submitOnEnter =
        submitOnEnterSetting == null ? submitOnEnter : Boolean.parseBoolean(submitOnEnterSetting);

    try {
      String restUrl = GWT.getHostPageBaseURL() + "api/repo/files/canAdminister"; // $NON-NLS-1$
      RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, restUrl);
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {

            @Override
            public void onError(Request arg0, Throwable arg1) {
              MessageDialogBox dialogBox =
                  new MessageDialogBox(
                      Messages.getString("error"),
                      arg1.getLocalizedMessage(),
                      false,
                      false,
                      true); //$NON-NLS-1$
              dialogBox.center();
            }

            @SuppressWarnings("deprecation")
            @Override
            public void onResponseReceived(Request arg0, Response response) {
              Boolean isAdministrator = Boolean.parseBoolean(response.getText());
              SolutionBrowserPanel.getInstance().setAdministrator(isAdministrator);

              try {
                String restUrl2 =
                    GWT.getHostPageBaseURL() + "api/scheduler/canSchedule"; // $NON-NLS-1$
                RequestBuilder requestBuilder2 = new RequestBuilder(RequestBuilder.GET, restUrl2);
                requestBuilder2.sendRequest(
                    null,
                    new RequestCallback() {
                      @Override
                      public void onError(Request arg0, Throwable arg1) {
                        MessageDialogBox dialogBox =
                            new MessageDialogBox(
                                Messages.getString("error"),
                                arg1.getLocalizedMessage(),
                                false,
                                false,
                                true); //$NON-NLS-1$
                        dialogBox.center();
                      }

                      public void onResponseReceived(Request arg0, Response response) {
                        Boolean isScheduler = Boolean.parseBoolean(response.getText());
                        SolutionBrowserPanel.getInstance().setScheduler(isScheduler);

                        String numStartupURLsSetting = settings.get("num-startup-urls");
                        if (numStartupURLsSetting != null) {
                          int numStartupURLs =
                              Integer.parseInt(numStartupURLsSetting); // $NON-NLS-1$
                          for (int i = 0; i < numStartupURLs; i++) {
                            String url = settings.get("startup-url-" + (i + 1)); // $NON-NLS-1$
                            String name = settings.get("startup-name-" + (i + 1)); // $NON-NLS-1$
                            if (url != null && !"".equals(url)) { // $NON-NLS-1$
                              SolutionBrowserPanel.getInstance()
                                  .getContentTabPanel()
                                  .showNewURLTab(name != null ? name : url, url, url, false);
                            }
                          }
                        }
                        if (SolutionBrowserPanel.getInstance().getContentTabPanel().getWidgetCount()
                            > 0) {
                          SolutionBrowserPanel.getInstance().getContentTabPanel().selectTab(0);
                        }

                        // startup-url on the URL for the app, wins over settings
                        String startupURL =
                            Window.Location.getParameter("startup-url"); // $NON-NLS-1$
                        if (startupURL != null && !"".equals(startupURL)) { // $NON-NLS-1$
                          String title = Window.Location.getParameter("name"); // $NON-NLS-1$
                          startupURL = URL.decodeComponent(startupURL);
                          SolutionBrowserPanel.getInstance()
                              .getContentTabPanel()
                              .showNewURLTab(title, title, startupURL, false);
                        }
                      }
                    });
              } catch (RequestException e) {
                MessageDialogBox dialogBox =
                    new MessageDialogBox(
                        Messages.getString("error"),
                        e.getLocalizedMessage(),
                        false,
                        false,
                        true); //$NON-NLS-1$
                dialogBox.center();
              }
            }
          });
    } catch (RequestException e) {
      MessageDialogBox dialogBox =
          new MessageDialogBox(
              Messages.getString("error"),
              e.getLocalizedMessage(),
              false,
              false,
              true); //$NON-NLS-1$
      dialogBox.center();
    }

    if (!StringUtils.isEmpty(startupPerspective)) {
      ICallback<Void> callback =
          new ICallback<Void>() {
            public void onHandle(Void nothing) {
              PerspectiveManager.getInstance().setPerspective(startupPerspective);
            }
          };
      PerspectiveManager.getInstance().addPerspectivesLoadedCallback(callback);
    }
  }
Exemplo n.º 7
0
  @SuppressWarnings("unchecked")
  public void populateFilesList(
      SolutionBrowserPerspective perspective, SolutionTree solutionTree, TreeItem item) {
    filesList.clear();
    ArrayList<Element> files = (ArrayList<Element>) item.getUserObject();
    // let's sort this list based on localized name
    Collections.sort(
        files,
        new Comparator<Element>() {
          public int compare(Element o1, Element o2) {
            String name1 = o1.getAttribute("localized-name"); // $NON-NLS-1$
            String name2 = o2.getAttribute("localized-name"); // $NON-NLS-1$
            return name1.compareTo(name2);
          }
        });
    if (files != null) {
      int rowCounter = 0;
      for (int i = 0; i < files.size(); i++) {
        Element fileElement = files.get(i);
        if ("false".equals(fileElement.getAttribute("isDirectory"))) { // $NON-NLS-1$ //$NON-NLS-2$
          String name = fileElement.getAttribute("name"); // $NON-NLS-1$
          String solution = solutionTree.getSolution();
          String path = solutionTree.getPath();
          String lastModifiedDateStr = fileElement.getAttribute("lastModifiedDate"); // $NON-NLS-1$
          String url = fileElement.getAttribute("url"); // $NON-NLS-1$
          ContentTypePlugin plugin = PluginOptionsHelper.getContentTypePlugin(name);
          String icon = null;
          if (plugin != null) {
            icon = plugin.getFileIcon();
          }
          String localizedName = fileElement.getAttribute("localized-name");
          String description = fileElement.getAttribute("description");
          String tooltip = localizedName;
          if (solutionTree.isUseDescriptionsForTooltip() && !StringUtils.isEmpty(description)) {
            tooltip = description;
          }
          final FileItem fileLabel =
              new FileItem(
                  name,
                  localizedName,
                  tooltip,
                  solution,
                  path, //$NON-NLS-1$
                  lastModifiedDateStr,
                  url,
                  this,
                  PluginOptionsHelper.getEnabledOptions(name),
                  toolbar.getSupportsACLs(),
                  icon);
          // BISERVER-2317: Request for more IDs for Mantle UI elements
          // set element id as the filename
          fileLabel.getElement().setId("file-" + name); // $NON-NLS-1$
          fileLabel.addFileSelectionChangedListener(toolbar);
          fileLabel.setWidth("100%"); // $NON-NLS-1$
          try {
            perspective.getDragController().makeDraggable(fileLabel);
          } catch (Exception e) {
            Throwable throwable = e;
            String text = "Uncaught exception: ";
            while (throwable != null) {
              StackTraceElement[] stackTraceElements = throwable.getStackTrace();
              text += throwable.toString() + "\n";
              for (int ii = 0; ii < stackTraceElements.length; ii++) {
                text += "    at " + stackTraceElements[ii] + "\n";
              }
              throwable = throwable.getCause();
              if (throwable != null) {
                text += "Caused by: ";
              }
            }
            DialogBox dialogBox = new DialogBox(true);
            DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF");
            System.err.print(text);
            text = text.replaceAll(" ", "&nbsp;");
            dialogBox.setHTML("<pre>" + text + "</pre>");
            dialogBox.center();
          }
          filesList.setWidget(rowCounter++, 0, fileLabel);

          if (selectedFileItem != null
              && selectedFileItem.getFullPath().equals(fileLabel.getFullPath())) {
            fileLabel.setStyleName("fileLabelSelected"); // $NON-NLS-1$
            selectedFileItem = fileLabel;
          } else {
            fileLabel.setStyleName("fileLabel"); // $NON-NLS-1$
          }
        }
      }
    }
  }