/*
   * (non-Javadoc)
   *
   * @see org.displaytag.decorator.ColumnDecorator#decorate(java.lang.Object)
   */
  public Widget decorate(Object columnValue) throws ClientDecoratorException {
    HorizontalPanel panel = new HorizontalPanel();
    panel.setSpacing(2);

    Double value = JobServerBean.REFRESHING_DATA;
    String tooltip = "";
    if (columnValue != null) {
      value = Double.parseDouble(String.valueOf(columnValue));
    }
    if (!active && value < 0) {
      tooltip = I18nUtils.getMessages().executionServer_disabled_desc();
      ClientImage image = new ClientImage(AdmIcons.INSTANCE.server_inactive(), null, null, tooltip);
      panel.add(super.decorate(image));
    } else if (refreshing) {
      tooltip = I18nUtils.getMessages().executionServer_refreshing();
      ClientImage image = new ClientImage(AdmIcons.INSTANCE.arrow_refresh(), null, null, tooltip);
      panel.add(super.decorate(image));
    } else {

      // System.out.println(columnValue);

      if (value >= 0) {

        double normalizedRate = value;

        double offset = 20d;

        double i = (double) normalizedRate / (double) offset;

        for (double j = 0.25d; j < 5; j += 1d) {

          ImageResource status = null;
          if (j <= i - 0.5d) {
            status = AdmIcons.INSTANCE.jobConductor_star_on();
          } else if (j <= i) {
            status = AdmIcons.INSTANCE.jobConductor_star_half();
          } else {
            status = AdmIcons.INSTANCE.jobConductor_star_off();
          }

          String strValue = String.valueOf(value);
          int indexOf = strValue.indexOf('.');
          if (indexOf > -1) {
            tooltip = strValue.substring(0, indexOf) + " %";
          }

          ClientImage image = new ClientImage(status, null, null, tooltip);
          panel.add(super.decorate(image));
        }
      } else {
        tooltip = I18nUtils.getMessages().executionServer_unavailable();
        ClientImage image = new ClientImage(AdmIcons.INSTANCE.error(), null, null, tooltip);
        panel.add(super.decorate(image));
      }
    }
    return panel;
  }
 TaskExecutionHistoryBeanDesc(
     String labelName, Map<String, String> converter, ColumnFilterType columnFilterType) {
   this.defaultValue = null;
   this.columnFilterType = columnFilterType;
   this.labelName = I18nUtils.getField(labelName);
   this.setConverter(converter);
 }
  private ContentPanel buildConfigBloc(ConfigGroup configGroup, ImageResource icon) {
    final ContentPanel cPanel = new ContentPanel(new ColumnLayout());
    cPanel.setHeading(
        "<div class='config-title'>" + I18nUtils.getString(configGroup.key) + "</div>");
    cPanel.getHeader().addStyleName("config-header");
    cPanel.setCollapsible(true);
    cPanel.setAnimCollapse(false);
    cPanel.collapse();
    cPanel.setIcon(AbstractImagePrototype.create(icon));
    cPanel.addListener(
        Events.Expand,
        new Listener<ComponentEvent>() {

          @Override
          public void handleEvent(ComponentEvent be) {
            cPanel.layout(true);
          }
        });

    cPanel.getHeader().addDomHandler(this, ClickEvent.getType());
    mapConfigGroupPanel.put(configGroup, cPanel);
    mapHeaderGroup.put(cPanel.getHeader(), cPanel);

    return cPanel;
  }
 private Field<?> buildTextField(
     final LayoutContainer fieldPart, final LayoutContainer messagePart, Config config) {
   String key = config.labelKey;
   if (config.editable
       && userBean.getRole().getRights().contains(RightsConstants.CONFIG_MANAGMENT)) {
     TextField<String> field = new TextField<String>();
     field.setName(config.name());
     buildField(config, I18nUtils.getString(key), field, fieldPart, messagePart);
     bindings.add(new FieldBinding<String>(field, config.name(), null));
     return field;
   } else {
     LabelField field = new LabelField();
     field.setName(config.name());
     buildField(config, I18nUtils.getString(key), field, fieldPart, messagePart);
     bindings.add(new FieldBinding<Object>(field, config.name(), null));
     return field;
   }
 }
 public void updateStatus(
     ConfigGroup configGroup, ConfigStatus status, String message, boolean bling) {
   ContentPanel contentPanel = mapConfigGroupPanel.get(configGroup);
   if (null != contentPanel) {
     String headling = I18nUtils.getString(configGroup.key);
     if (null != message) {
       headling += message;
     }
     String s = decorateStatus(headling, status, null, bling);
     contentPanel.setHeading(s);
   }
 }
  @Override
  public ToolBar initToolBar() {
    SubModuleToolbar toolbar = new SubModuleToolbar(getEventBus());

    final Button importUser = new Button();

    importUser.setText(I18nUtils.getMessages().user_button_importUsers());
    importUser.setTitle(I18nUtils.getMessages().user_button_importUsers_tip());
    importUser.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.user()));
    importUser.enable();
    importUser.addListener(
        Events.OnClick,
        new Listener<BaseEvent>() {

          public void handleEvent(BaseEvent be) {
            initUserImportView();
          }
        });
    toolbar.add(importUser);

    return toolbar;
  }
  /**
   * DOC bessaies Comment method "buildField".
   *
   * @param fieldPart
   * @param messagePart
   * @param configBean
   */
  private Field<?> buildPasswordField(
      final LayoutContainer fieldPart, final LayoutContainer messagePart, Config config) {
    String key = config.labelKey;
    TextField<String> field = new TextField<String>();
    field.setName(config.name());
    field.setReadOnly(
        !(config.editable
            && userBean.getRole().getRights().contains(RightsConstants.CONFIG_MANAGMENT)));
    field.setPassword(true);

    buildField(config, I18nUtils.getString(key), field, fieldPart, messagePart);
    bindings.add(new FieldBinding<String>(field, config.name()));
    return field;
  }
  private Button getExportButton() {
    Button exportButton = new Button(I18nUtils.getMessages().config_button_export());
    exportButton.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.page_save()));
    exportButton.addListener(
        Events.OnClick,
        new Listener<BaseEvent>() {

          @Override
          public void handleEvent(BaseEvent be) {
            String url = GWT.getModuleBaseURL() + "exportconfig";
            Window.open(url, "_self", "");
          }
        });
    return exportButton;
  }
  private Button getDownloadLogButton() {
    Button downloadButton = new Button(I18nUtils.getMessages().config_button_downloadLog());
    downloadButton.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.download()));
    downloadButton.addListener(
        Events.OnClick,
        new Listener<BaseEvent>() {

          @Override
          public void handleEvent(BaseEvent be) {
            String url = GWT.getModuleBaseURL() + "downloadlog";
            Window.open(url, "_self", "");
          }
        });

    return downloadButton;
  }
 TaskExecutionHistoryBeanDesc(Object defaultValue) {
   this.defaultValue = defaultValue;
   this.columnFilterType = null;
   this.labelName = I18nUtils.getField(name());
 }
 TaskExecutionHistoryBeanDesc(String labelName, ColumnFilterType columnFilterType) {
   this.defaultValue = null;
   this.columnFilterType = columnFilterType;
   this.labelName = I18nUtils.getField(labelName);
 }
 AdminUserBeanDesc(Object defaultValue) {
   this.defaultValue = defaultValue;
   this.labelName = I18nUtils.getField(name());
 }
 AdminUserBeanDesc() {
   this.defaultValue = null;
   this.labelName = I18nUtils.getField(name());
 }
  public void initUserImportView() {
    final Window window = new Window();
    window.setBodyBorder(false);
    FormPanel reportPanel = new FormPanel();
    Label dLabel = new Label(I18nUtils.getMessages().user_userImportReports());

    reportPanel.add(dLabel);
    reportPanel.setHeight(120);
    reportPanel.setBodyBorder(false);
    reportPanel.setHeaderVisible(false);
    reportPanel.setHideLabels(true);
    Button close = new Button(I18nUtils.getMessages().user_userImportReports_close());
    close.addListener(
        Events.OnClick,
        new Listener<BaseEvent>() {

          public void handleEvent(BaseEvent be) {
            window.hide();
          }
        });

    window.setTitle(I18nUtils.getMessages().user_userImportReports_window());
    window.setWidth(560);
    window.setHeading(I18nUtils.getMessages().user_importUsersPanel_title());
    window.setClosable(true);
    MyFileUpload importUserTool =
        new MyFileUpload("importusers") {

          @SuppressWarnings("unchecked")
          @Override
          public void fireActionComplete(String responseText) {
            JSONObject json = (JSONObject) JSONParser.parseLenient(responseText);
            JSONValue number = json.get("reportId");
            JSONNumber sJsonNumber = number.isNumber();

            UserService.Util.getInstance()
                .importUsers(
                    (int) sJsonNumber.doubleValue(),
                    new AsyncCallback() {

                      public void onFailure(Throwable caught) {
                        MessageBox.alert(
                            I18nUtils.getMessages().user_importUsersPanel_title(),
                            caught.getMessage(),
                            null);
                        GWT.log("importing users failed");
                      }

                      public void onSuccess(final Object result) {
                        ImportUserReport[] reports = (ImportUserReport[]) result;
                        String msg = "";
                        for (ImportUserReport r : reports) {
                          msg += r + "<br/>";
                        }
                        Dialog report = new Dialog();
                        report.setHeight(300);
                        report.setWidth(480);
                        report.addText(msg);
                        report.setHideOnButtonClick(true);
                        report.show();

                        load();
                      }
                    });
          }

          @Override
          public void actionEnd() {
            GWT.log("importing users  end up");
          }
        };

    reportPanel.add(importUserTool);
    reportPanel.addButton(close);
    reportPanel.setButtonAlign(HorizontalAlignment.RIGHT);
    window.add(reportPanel);

    window.show();
  }
 @Override
 public String getItemTitle() {
   return I18nUtils.getMessages().user_form_title();
 }
  @Override
  public ToolBar initToolBar() {
    SubModuleToolbar toolbar = new SubModuleToolbar(getEventBus(), getSubModule().hasEditRight());
    final Button bmToolbarButton =
        new Button(
            I18nUtils.getMessages().project_button_BranchManagment(),
            AbstractImagePrototype.create(Icons.INSTANCE.branches()));
    AdaptId.adapt(bmToolbarButton, IdElementsAdmResource.INSTANCE.idBranchManagementButton());
    bmToolbarButton.disable();
    bmToolbarButton.setTitle(I18nUtils.getMessages().project_button_BranchManagment());
    bmToolbarButton.addListener(
        Events.OnClick,
        new Listener<BaseEvent>() {

          public void handleEvent(BaseEvent be) {
            ModelData selected = getSelectedItem();
            if (selected != null && bmToolbarButton.isEnabled()) {
              Object obj = selected.get(ProjectBeanDesc.id.getName());
              int projectId = 0;
              if (obj != null) {
                projectId = (Integer) obj;
              }
              String name = selected.get(ProjectBeanDesc.label.getName());
              String warning = selected.get(ProjectBeanDesc.warning.getName());
              if (warning == null) {
                Window window = new BranchManagmentWindow(projectId, name);
                window.show();
              } else {
                String messageTitle = "<font size='3'>" + "Can't manage branches:" + "<font/><br>";
                String messageDetail =
                    "<I><font size='2' style='color:red'>" + warning + "<font/><I/>";
                String message = messageTitle + messageDetail;
                MessageBox.alert("Warning", message, null);
              }
            }
          }
        });

    if (!getSubModule().hasEditRight()) {
      GXTUtils.hideComponents(bmToolbarButton);
    }

    getEventBus()
        .addHandler(
            SubModuleEvent.getType(),
            new SubModuleHandler() {

              public void onEvent(SubModuleEvent event) {
                if (event.getEventType() == EventType.OnGridSelect
                    && getSubModule().hasEditRight()) {
                  bmToolbarButton.enable();
                } else if (event.getEventType() == EventType.OnGridUnselect
                    || event.getEventType() == EventType.OnClickCancel) {
                  bmToolbarButton.disable();
                }
              }
            });

    toolbar.add(bmToolbarButton);
    return toolbar;
  }