Пример #1
0
  public ConfigView(final EventBus eventBus, UserBean userBean, int refreshPeriod, String id) {
    setLayout(new FlowLayout());
    setScrollMode(Scroll.AUTOY);
    setHeaderVisible(false);

    this.eventBus = eventBus;
    this.userBean = userBean;

    groupFieldBinding = new GroupFieldBinding(modelData());

    addListener(
        Events.Resize,
        new Listener<BaseEvent>() {

          @Override
          public void handleEvent(BaseEvent be) {
            Scheduler.get()
                .scheduleDeferred(
                    new ScheduledCommand() {

                      @Override
                      public void execute() {
                        ConfigView.this.layout(true);
                      }
                    });
          }
        });

    if (null == this.scheduler) {
      this.scheduler =
          new AbstractSubModuleScheduler(
              this.eventBus, this, this, refreshPeriod, id, EventType.OnServiceRefreshEnd);
    }

    setTopComponent(initToolBar());

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

          @Override
          public void onEvent(SubModuleEvent event) {
            EventType evt = event.getEventType();
            if (evt == EventType.OnClickRefresh) {
              load();
            }
          }
        });

    build();
    register();
    loadValues();
  }
  @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;
  }