@Override
 public void onCacheUpdated(CacheUpdatedEvent event) {
   if (event.getConfig() != null) config = event.getConfig();
   if (event.getOriginalSource() != populateLocalCache) {
     DeferredCommand.addCommand(populateLocalCache);
   }
   if (event.getSession() != null && event.getSession().getUser() != null)
     DeferredCommand.addCommand(updateEvents);
 }
Example #2
0
  /** Parse and store the user credentials to the appropriate fields. */
  private void parseUserCredentials() {
    Configuration conf = (Configuration) GWT.create(Configuration.class);
    String cookie = conf.authCookie();
    String auth = Cookies.getCookie(cookie);
    if (auth == null) {
      authenticateUser();
      // Redundant, but silences warnings about possible auth NPE, below.
      return;
    }
    int sepIndex = auth.indexOf(conf.cookieSeparator());
    if (sepIndex == -1) authenticateUser();
    token = auth.substring(sepIndex + 1);
    final String username = auth.substring(0, sepIndex);
    if (username == null) authenticateUser();

    refreshWebDAVPassword();

    DeferredCommand.addCommand(
        new Command() {

          @Override
          public void execute() {
            fetchUser(username);
          }
        });
  }
 @Override
 public void saveSettings(final Command command) {
   if (loading) {
     // If we are in the process of loading, we must defer saving.
     DeferredCommand.addCommand(
         new Command() {
           @Override
           public void execute() {
             saveSettings(command);
           }
         });
   } else {
     String s = encodeSettings();
     OdeLog.log("Saving global settings: " + s);
     Ode.getInstance()
         .getUserInfoService()
         .storeUserSettings(
             s,
             new OdeAsyncCallback<Void>(
                 // failure message
                 MESSAGES.settingsSaveError()) {
               @Override
               public void onSuccess(Void result) {
                 if (command != null) {
                   command.execute();
                 }
               }
             });
   }
 }
Example #4
0
 public BackgroundMonitorEvent() {
   WebEventManager.getAppEvManager()
       .addListener(
           ServerSentEventNames.SVR_BACKGROUND_REPORT,
           new WebEventListener<String>() {
             public void eventNotify(WebEvent<String> ev) {
               BackgroundStatus bgStat = BackgroundStatus.parse(ev.getData());
               if (bgStat != null) setStatus(bgStat);
               else
                 GwtUtil.getClientLogger()
                     .log(Level.INFO, "failed to parse BackgroundStatus:" + ev.getData());
             }
           });
   DeferredCommand.addCommand(
       new Command() {
         public void execute() {
           if (BrowserCache.isPerm()) {
             BrowserCache.addHandlerForKey(
                 STATE_KEY,
                 new StorageEvent.Handler() {
                   public void onStorageChange(StorageEvent ev) {
                     //                            syncWithCache(ev);
                   }
                 });
           }
         }
       });
 }
Example #5
0
  /** Checks if <tt>User</tt> changed properties. */
  private void checkIfUserChangedProperties() {
    DeferredCommand.addCommand(
        new Command() {
          @Override
          public void execute() {
            if (Context.getAuthenticatedUser().isDefaultAdministrator()) {
              Context.getUserService()
                  .getUser(
                      "admin",
                      new OpenXDataAsyncCallback<User>() {

                        @Override
                        public void onOtherFailure(Throwable throwable) {
                          Utilities.displayMessage(throwable.getLocalizedMessage());
                        }

                        @Override
                        public void onSuccess(User user) {
                          checkIfAdministratorChangedPassword(user);
                        }
                      });
            }
          }
        });
  }
 @Override
 public void execute() {
   clearLocalCache();
   session = VeggieDinner.getSession();
   if (session == null || session.getUser() == null) return;
   me = VeggieDinner.getUser(session.getUser());
   if (me == null) {
     VeggieDinner.requestNewUser(session.getUser(), populateLocalCache);
     return;
   }
   boolean hasAll = true;
   myGroupDTOs.addAll(VeggieDinner.getGroups(me.getGroups()).values());
   myEventDTOs.addAll(VeggieDinner.getEvents(me.getSchedule()).values());
   myEventDTOs.addAll(VeggieDinner.getEvents(getEventsFromGroups(myGroupDTOs)).values());
   myCohosts.addAll(VeggieDinner.getUsers(getHostsFromGroups(myGroupDTOs)).values());
   if (!myGroupDTOs.containsAll(me.getGroups())) {
     VeggieDinner.requestNewGroup(me.getGroups(), populateLocalCache);
     return;
   }
   if (!myEventDTOs.containsAll(me.getSchedule())
       || !myEventDTOs.containsAll(getEventsFromGroups(myGroupDTOs))) {
     HashSet<Key<EventDTO>> events = getEventsFromGroups(myGroupDTOs);
     events.addAll(me.getSchedule());
     VeggieDinner.requestNewEvent(events, populateLocalCache);
     return;
   }
   if (!myCohosts.containsAll(getHostsFromGroups(myGroupDTOs))) {
     VeggieDinner.requestNewUser(getHostsFromGroups(myGroupDTOs), populateLocalCache);
     return;
   }
   DeferredCommand.addCommand(updateMyStuff);
 }
  public GoogleCalendarPanel(CalendarTaskManager calendarManager) {

    // style this element as absolute position
    DOM.setStyleAttribute(this.getElement(), "position", "absolute");

    calendarTaskManager = calendarManager;

    configureCalendar();
    createDatePickerDialog();

    setHeaderVisible(false);
    setBodyBorder(false);
    setBorders(false);
    setTopComponent(createCalendarToolbar());
    add(calendar);

    // window events to handle resizing
    Window.enableScrolling(false);
    Window.addResizeHandler(
        new ResizeHandler() {
          public void onResize(ResizeEvent event) {
            resizeTimer.schedule(500);
            int h = event.getHeight();
          }
        });
    DeferredCommand.addCommand(
        new Command() {
          public void execute() {
            LayoutContainer center = (LayoutContainer) Registry.get(AppView.CENTER_PANEL);
            calendar.setHeight(center.getHeight() - calendarHeightSize + "px");
          }
        });
  }
Example #8
0
  /**
   * Causes an element to "fade out" via opacity. When onFadeComplete is called, the element will be
   * entirely transparent.
   *
   * @param target the UIObject to be faded out
   * @param milliseconds how long the fade effect should take to process
   * @param callback the callback to be invoked on fade progress
   */
  public static void fadeOut(
      final UIObject target, final int milliseconds, final FadeCallback callback) {
    final Element e = target.getElement();
    final int interval = milliseconds / 50;
    DeferredCommand.addCommand(
        new Command() {

          public void execute() {
            callback.onFadeStart();

            final Timer t =
                new Timer() {
                  int pct = 100;

                  @Override
                  public void run() {
                    pct -= 2;
                    setOpacity(e, pct);
                    if (pct == 0) {
                      this.cancel();
                      callback.onFadeComplete();
                    }
                  }
                };
            t.scheduleRepeating(interval);
          }
        });
  }
Example #9
0
 private void runCommandQueue() {
   for (int i = 0; i < commandQueue.size(); i++) {
     Command x = (Command) commandQueue.get(i);
     DeferredCommand.addCommand(x);
   }
   commandQueue.clear();
 }
Example #10
0
 /** Executes the event using a deferred command. */
 private <H extends EventHandler> void scheduleEvent(final DomEvent<H> event) {
   DeferredCommand.addCommand(
       new Command() {
         public void execute() {
           onEvent(event);
         }
       });
 }
Example #11
0
 /**
  * Focus the window. If a focusWidget is set, it will receive focus, otherwise the window itself
  * will receive focus.
  */
 public void focus() {
   DeferredCommand.addCommand(
       new Command() {
         public void execute() {
           doFocus();
         }
       });
 }
 /**
  * Sets up the post composite. If the implementation of the minimizer can be built into the
  * constructor of the post composite, then this function should be removed.
  */
 private void setupPostComposite() {
   shadowPanel.add(postComposite);
   DeferredCommand.addCommand(
       new Command() {
         public void execute() {
           postComposite.setUpMinimizer();
         }
       });
 }
 @Override
 public void execute() {
   if (session == null || me == null || config == null) {
     myStuffItem.setVisible(false);
     login.setVisible(true);
     logout.setVisible(false);
     signup.setVisible(config.isAllowSignup());
     return;
   }
   login.setVisible(false);
   logout.setVisible(true);
   signup.setVisible(false);
   myStuffItem.setVisible(true);
   myStuff.clearItems();
   myStuff.addItem(
       "Edit My Profile",
       new Command() {
         @Override
         public void execute() {
           VeggieDinner.showUserForm(me.getKey());
         }
       });
   if (me.isGroupFinalized()) DeferredCommand.addCommand(populateMyEvents);
   else {
     if (me.numGroups() > 0) {
       DeferredCommand.addCommand(populateMyInvites);
     }
     if (config.isAllowGroupFormation()) {
       myStuff.addItem(
           "Create Group",
           new Command() {
             @Override
             public void execute() {
               VeggieDinner.showSelectGroupForm(session.getUser());
             }
           });
     }
   }
   if (me.getSchedule() != null && me.getSchedule().size() > 0)
     DeferredCommand.addCommand(populateMySchedule);
   // TODO anything else that falls under myStuff?
 }
Example #14
0
 public void onKeyPress(KeyPressEvent ev) {
   final char keyCode = ev.getCharCode();
   if (keyCode == KeyCodes.KEY_ENTER) {
     DeferredCommand.addCommand(
         new Command() {
           public void execute() {
             checkForChange();
           }
         });
   }
 }
Example #15
0
 @Override
 protected void onRightClick(ComponentEvent ce) {
   ce.stopEvent();
   final int x = ce.getClientX();
   final int y = ce.getClientY();
   DeferredCommand.addCommand(
       new Command() {
         public void execute() {
           tabPanel.onItemContextMenu(TabItem.this, x, y);
         }
       });
 }
Example #16
0
    @Override
    IElement add(final Widget widget, String name) {
      TabWidget tabWidget = new TabWidget(name);
      tabPanel.insert(widget, tabWidget, tabPanel.getWidgetCount() - 1);
      final int idx = tabPanel.getWidgetIndex(widget);
      tabWidgets.add(tabWidget);
      DeferredCommand.addCommand(
          new Command() {
            public void execute() {
              tabPanel.selectTab(idx);
            }
          });

      return tabWidget;
    }
Example #17
0
 @Override
 protected void resize() {
   final int oldCount = getVisibleRowCount();
   super.resize();
   if (mainBody != null) {
     resizeLiveScroller();
     scroller.setWidth(grid.getWidth() - getScrollAdjust(), true);
     DeferredCommand.addCommand(
         new Command() {
           public void execute() {
             if (oldCount != getVisibleRowCount()) {
               updateRows(LiveGridView.this.viewIndex, true);
             }
           }
         });
   }
 }
Example #18
0
 @Override
 void remove(final int idx) {
   tabWidgets.remove(idx);
   tabPanel.remove(idx);
   DeferredCommand.addCommand(
       new Command() {
         public void execute() {
           int idxSel = idx;
           // we can always select at the same position, but prefer
           // to select a normal element, if any, instead of the "+" tab:
           if (idxSel == tabPanel.getWidgetCount() - 1 && idxSel > 0) {
             idxSel--;
           }
           tabPanel.selectTab(idxSel);
         }
       });
 }
  @Override
  public void forceResize() {
    if (!widget.isAttached()) {
      return;
    }
    if (widget.getOffsetHeight() != getHeight()) {
      DeferredCommand.addCommand(
          new Command() {

            @Override
            public void execute() {

              widget.setHeight(getHeight() + "px");
            }
          });
    }
  }
Example #20
0
  /**
   * Display the dialog to allow the <code>Administrator User</code> to change the default password.
   *
   * @param passwordChanged Flag to indicate administrator <tt>User Password</tt> was changed or
   *     not.
   */
  protected void displayDialogToChangePassword(final Boolean passwordChanged) {
    DeferredCommand.addCommand(
        new Command() {
          @Override
          public void execute() {
            if (!passwordChanged) {

              // Prompt User to Change Administrator Password.
              new PasswordChangeDialog().initializeDialog();

              // Alert the User of the operation.
              Utilities.displayMessage(
                  "For security reasons, the administrator should change their password on initial login. "
                      + "Please change your password to avoid seeing this message and to protect your data.");
            }
          }
        });
  }
Example #21
0
  protected void setDayIncluded(int day, boolean included) {
    if (daysFilter[day] == included) {
      // No change.
      //
      return;
    }

    daysFilter[day] = included;
    if (pendingRefresh == null) {
      pendingRefresh =
          new Command() {
            public void execute() {
              pendingRefresh = null;
              dynaTable.refresh();
            }
          };
      DeferredCommand.addCommand(pendingRefresh);
    }
  }
  @Override
  public void saveSettings(final Command command) {
    if (Ode.getInstance().isReadOnly()) {
      return; // Don't save when in read-only mode
    }
    if (loading) {
      // If we are in the process of loading, we must defer saving.
      DeferredCommand.addCommand(
          new Command() {
            @Override
            public void execute() {
              saveSettings(command);
            }
          });
    } else if (!loaded) {
      // Do not save settings that have not been loaded. We should
      // only wind up in this state if we are in the early phases of
      // loading the App Inventor client code. If saveSettings is
      // called in this state, it is from the onWindowClosing
      // handler. We do *not* want to over-write a persons valid
      // settings with this empty version, so we just return.
      return;

    } else {
      String s = encodeSettings();
      OdeLog.log("Saving global settings: " + s);
      Ode.getInstance()
          .getUserInfoService()
          .storeUserSettings(
              s,
              new OdeAsyncCallback<Void>(
                  // failure message
                  MESSAGES.settingsSaveError()) {
                @Override
                public void onSuccess(Void result) {
                  if (command != null) {
                    command.execute();
                  }
                }
              });
    }
  }
Example #23
0
  private void addPackagesPanel() {
    DockLayoutPanel packageDockLayoutPanel = new DockLayoutPanel(Unit.EM);
    final PackagesTree packagesTreeItem = new PackagesTree();
    ScrollPanel packagesTreeItemPanel = new ScrollPanel(packagesTreeItem);

    if (CapabilitiesManager.getInstance().shouldShow(Capabilities.SHOW_CREATE_NEW_ASSET)) {
      packageDockLayoutPanel.addNorth(PackagesNewMenu.getMenu(packagesTreeItem), 2);
    }
    packageDockLayoutPanel.add(packagesTreeItemPanel);

    add(packageDockLayoutPanel, packagesTreeItem.getHeaderHTML(), 2);

    // lazy loaded to easy startup wait time.
    DeferredCommand.addCommand(
        new Command() {
          public void execute() {
            packagesTreeItem.loadPackageList();
          }
        });
  }
Example #24
0
  protected void endDrag(DragEvent de, boolean canceled) {
    dragging = false;
    unghost(de);
    if (!canceled) {
      restorePos = getPosition(true);
      positioned = true;
    }

    if (layer != null && getShadow()) {
      layer.enableShadow();
    }
    focus();
    DeferredCommand.addCommand(
        new Command() {
          public void execute() {
            if (Window.this.eventPreview != null && Window.this.ghost != null) {
              Window.this.eventPreview.getIgnoreList().remove(Window.this.ghost.dom);
            }
          }
        });
  }
Example #25
0
  /**
   * Fetches the User object for the specified username.
   *
   * @param username the username of the user
   */
  private void fetchUser(final String username) {
    String path = getApiPath() + username + "/";
    GetCommand<UserResource> getUserCommand =
        new GetCommand<UserResource>(UserResource.class, username, path, null) {

          @Override
          public void onComplete() {

            currentUserResource = getResult();
            Scheduler.get()
                .scheduleDeferred(
                    new ScheduledCommand() {
                      @Override
                      public void execute() {
                        treeView.fetchRootFolders();
                      }
                    });
            final String announcement = currentUserResource.getAnnouncement();
            if (announcement != null)
              DeferredCommand.addCommand(
                  new Command() {

                    @Override
                    public void execute() {
                      displayInformation(announcement);
                    }
                  });
          }

          @Override
          public void onError(Throwable t) {
            GWT.log("Fetching user error", t);
            if (t instanceof RestException)
              GSS.get().displayError("No user found:" + ((RestException) t).getHttpStatusText());
            else GSS.get().displayError("System error fetching user data:" + t.getMessage());
            authenticateUser();
          }
        };
    DeferredCommand.addCommand(getUserCommand);
  }
 protected void setUpEffect(final Command command) {
   if (thePanel != null) thePanel.getElement().getStyle().setProperty("overflow", "hidden");
   // Need to call set up first, so that the panel gets hidden before being displayed
   // Dimensions are set up in Deferred Command below, which might take longer to execute than
   // the control back in the NEffect which displays the widget.  BY setting the initial effect to
   // large values in the constructor, we can then immediately hide this panel by position, then
   // the
   // deferred command can do its work and place it where needed for sliding in.
   super.setUpEffect();
   DeferredCommand.addCommand(
       new Command() {
         public void execute() {
           height = effectElements.get(0).getOffsetHeight();
           width = effectElements.get(0).getOffsetWidth();
           command.execute();
           setNewStartStyle(new Rule(newEnd));
         }
       });
   // This change listener will allow the panel to be visible outside of bounding box (for example
   // we would like this on the elastic transition physics so that once the effect is greater than
   // 1.0
   // we display, and below 1.0 we hide overshots.
   // However, since this is only really applicable to the elastic transition physics and would
   // carry an overhead
   // for others, we allow a boolean to indicate if available or not.
   if ((displayOutsideBounds) && (thePanel != null)) {
     this.addEffectSteppingHandler(
         new EffectSteppingHandler() {
           public void onEffectStep(EffectSteppingEvent handler) {
             if (getProgressInterpolated() > 1)
               thePanel.getElement().getStyle().setProperty("overflow", "visible");
             else thePanel.getElement().getStyle().setProperty("overflow", "hidden");
           }
         });
   }
 }
Example #27
0
  @Override
  public void onModuleLoad() {
    // Initialize the singleton before calling the constructors of the
    // various widgets that might call GSS.get().
    singleton = this;
    parseUserCredentials();

    topPanel = new TopPanel(GSS.images);
    topPanel.setWidth("100%");

    messagePanel.setWidth("100%");
    messagePanel.setVisible(false);

    search = new Search(images);
    searchStatus.add(search, DockPanel.WEST);
    searchStatus.add(userDetailsPanel, DockPanel.EAST);
    searchStatus.setCellHorizontalAlignment(userDetailsPanel, HasHorizontalAlignment.ALIGN_RIGHT);
    searchStatus.setCellVerticalAlignment(search, HasVerticalAlignment.ALIGN_MIDDLE);
    searchStatus.setCellVerticalAlignment(userDetailsPanel, HasVerticalAlignment.ALIGN_MIDDLE);
    searchStatus.setWidth("100%");

    fileList = new FileList(images);

    searchResults = new SearchResults(images);

    // Inner contains the various lists.
    inner.sinkEvents(Event.ONCONTEXTMENU);
    inner.setAnimationEnabled(true);
    inner.getTabBar().addStyleName("gss-MainTabBar");
    inner.getDeckPanel().addStyleName("gss-MainTabPanelBottom");
    inner.add(
        fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true);

    inner.add(
        groups, createHeaderHTML(AbstractImagePrototype.create(images.groups()), "Groups"), true);
    inner.add(
        searchResults,
        createHeaderHTML(AbstractImagePrototype.create(images.search()), "Search Results"),
        true);
    // inner.add(new CellTreeView(images),
    // createHeaderHTML(AbstractImagePrototype.create(images.search()), "Cell tree sample"), true);
    inner.setWidth("100%");
    inner.selectTab(0);

    inner.addSelectionHandler(
        new SelectionHandler<Integer>() {

          @Override
          public void onSelection(SelectionEvent<Integer> event) {
            int tabIndex = event.getSelectedItem();
            //				TreeItem treeItem = GSS.get().getFolders().getCurrent();
            switch (tabIndex) {
              case 0:
                //						Files tab selected
                // fileList.clearSelectedRows();
                fileList.updateCurrentlyShowingStats();
                break;
              case 1:
                //						Groups tab selected
                groups.updateCurrentlyShowingStats();
                updateHistory("Groups");
                break;
              case 2:
                //						Search tab selected
                searchResults.clearSelectedRows();
                searchResults.updateCurrentlyShowingStats();
                updateHistory("Search");
                break;
            }
          }
        });
    //		If the application starts with no history token, redirect to a new "Files" state
    String initToken = History.getToken();
    if (initToken.length() == 0) History.newItem("Files");
    //		   Add history listener to handle any history events
    History.addValueChangeHandler(
        new ValueChangeHandler<String>() {
          @Override
          public void onValueChange(ValueChangeEvent<String> event) {
            String tokenInput = event.getValue();
            String historyToken = handleSpecialFolderNames(tokenInput);
            try {
              if (historyToken.equals("Search")) inner.selectTab(2);
              else if (historyToken.equals("Groups")) inner.selectTab(1);
              else if (historyToken.equals("Files") || historyToken.length() == 0)
                inner.selectTab(0);
              else {
                /*TODO: CELLTREE
                PopupTree popupTree = GSS.get().getFolders().getPopupTree();
                TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken);
                SelectionEvent.fire(popupTree, treeObj);
                */
              }
            } catch (IndexOutOfBoundsException e) {
              inner.selectTab(0);
            }
          }
        });

    // Add the left and right panels to the split panel.
    splitPanel.setLeftWidget(treeView);
    splitPanel.setRightWidget(inner);
    splitPanel.setSplitPosition("25%");
    splitPanel.setSize("100%", "100%");
    splitPanel.addStyleName("gss-splitPanel");

    // Create a dock panel that will contain the menu bar at the top,
    // the shortcuts to the left, the status bar at the bottom and the
    // right panel taking the rest.
    VerticalPanel outer = new VerticalPanel();
    outer.add(topPanel);
    outer.add(searchStatus);
    outer.add(messagePanel);
    outer.add(splitPanel);
    outer.add(statusPanel);
    outer.setWidth("100%");
    outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);

    outer.setSpacing(4);

    // Hook the window resize event, so that we can adjust the UI.
    Window.addResizeHandler(this);
    // Clear out the window's built-in margin, because we want to take
    // advantage of the entire client area.
    Window.setMargin("0px");
    // Finally, add the outer panel to the RootPanel, so that it will be
    // displayed.
    RootPanel.get().add(outer);
    // Call the window resized handler to get the initial sizes setup. Doing
    // this in a deferred command causes it to occur after all widgets'
    // sizes have been computed by the browser.
    DeferredCommand.addCommand(
        new Command() {

          @Override
          public void execute() {
            onWindowResized(Window.getClientHeight());
          }
        });
  }
Example #28
0
  public EventEditor(final Admin admin, JSEventTemplate et) {
    this.admin = admin;
    this.et = et;

    vpanel.setWidth("100%");
    vpanel.setHeight("100%");

    final Label errmsg = new Label();
    errmsg.addStyleName(errmsg.getStylePrimaryName() + "-error");
    errmsg.addStyleName(errmsg.getStylePrimaryName() + "-bottom");

    FlexTable grid = new FlexTable();
    grid.setWidth("100%");

    CellFormatter cf = grid.getCellFormatter();
    // right align field labels
    cf.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    cf.setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    cf.setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    cf.setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    cf.setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    cf.setHorizontalAlignment(5, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    cf.setHorizontalAlignment(7, 0, HasHorizontalAlignment.ALIGN_RIGHT);

    grid.setText(0, 0, "Event Name:");
    grid.setText(1, 0, "Raid Size:");
    grid.setText(2, 0, "Minimum Level:");
    grid.setText(3, 0, "Instance:");
    grid.setText(4, 0, "Bosses:");
    grid.setText(5, 0, "Roles:");
    grid.setText(7, 0, "Badges:");

    size.setVisibleLength(2);
    minlevel.setVisibleLength(2);

    size.addChangeHandler(
        new ChangeHandler() {
          public void onChange(ChangeEvent event) {
            try {
              int sizen = Integer.parseInt(size.getText());
              if (sizen < 0) {
                size.setText("0");
              }
            } catch (NumberFormatException e) {
              size.setText("25");
            }

            updateRoleTotals();
          }
        });

    minlevel.addChangeHandler(
        new ChangeHandler() {
          public void onChange(ChangeEvent event) {
            try {
              int minleveln = Integer.parseInt(minlevel.getText());
              if (minleveln < 0) {
                size.setText("0");
              }
            } catch (NumberFormatException e) {
              size.setText(MAX_LEVEL);
            }
          }
        });

    instances.setWidth("100%");
    instances.setVisibleItemCount(1);

    roles.setWidth("100%");
    roles.setVisibleItemCount(1);

    badges.setWidth("100%");
    badges.setVisibleItemCount(1);

    grid.setWidget(0, 1, name);
    grid.setWidget(1, 1, size);
    grid.setWidget(2, 1, minlevel);

    grid.setWidget(3, 1, instances);

    GoteFarm.goteService.getInstances(
        admin.current_guild.key,
        new AsyncCallback<List<JSInstance>>() {
          public void onSuccess(List<JSInstance> results) {
            int sel = 0;

            for (JSInstance i : results) {
              instances.addItem(i.name, i.key);
              if (EventEditor.this.et != null && i.key.equals(EventEditor.this.et.instance_key)) {
                sel = instances.getItemCount() - 1;
              }
            }

            instances.setSelectedIndex(sel);

            updateBosses();
          }

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

    instances.addChangeHandler(this);
    roles.addChangeHandler(this);
    badges.addChangeHandler(this);

    grid.setWidget(3, 2, newinst);

    newinst.setText(NEW_INSTANCE);

    newinst.addKeyPressHandler(
        new KeyPressHandler() {
          public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
              final String inst = newinst.getText();

              boolean found = false;

              for (int i = 0; i < instances.getItemCount(); ++i) {
                if (instances.getItemText(i).equals(inst)) {
                  instances.setSelectedIndex(i);
                  focusBoss();
                  found = true;
                  break;
                }
              }

              if (!found) {
                GoteFarm.goteService.addInstance(
                    admin.current_guild.key,
                    inst,
                    new AsyncCallback<JSInstance>() {
                      public void onSuccess(JSInstance result) {
                        instances.addItem(result.name, result.key);
                        instances.setSelectedIndex(instances.getItemCount() - 1);
                        bosses.clear();

                        focusBoss();
                      }

                      public void onFailure(Throwable caught) {
                        errmsg.setText(caught.getMessage());
                      }
                    });
              }
            }
          }
        });

    grid.setWidget(4, 1, bosses);
    grid.setWidget(4, 2, newboss);

    bosses.setWidth("100%");
    bosses.setVisibleItemCount(10);

    newboss.setText(NEW_BOSS);

    newboss.addKeyPressHandler(
        new KeyPressHandler() {
          public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
              int selinst = instances.getSelectedIndex();
              if (selinst == -1) {
                errmsg.setText("You need to select and instance to " + "add a boss.");
                return;
              }

              final String boss = newboss.getText();

              boolean found = false;

              for (int i = 0; i < bosses.getItemCount(); ++i) {
                if (bosses.getItemText(i).equals(boss)) {
                  bosses.setItemSelected(i, true);
                  focusBoss();
                  found = true;
                  break;
                }
              }

              if (!found) {
                GoteFarm.goteService.addBoss(
                    instances.getValue(selinst),
                    boss,
                    new AsyncCallback<JSBoss>() {

                      public void onSuccess(JSBoss result) {
                        bosses.addItem(result.name, result.key);
                        bosses.setItemSelected(bosses.getItemCount() - 1, true);

                        focusBoss();
                      }

                      public void onFailure(Throwable caught) {
                        errmsg.setText(caught.getMessage());
                      }
                    });
              }
            }
          }
        });

    grid.setWidget(5, 1, roles);

    roles.addItem(SELECT_A_ROLE);

    GoteFarm.goteService.getRoles(
        admin.current_guild.key,
        new AsyncCallback<List<JSRole>>() {
          public void onSuccess(List<JSRole> results) {
            for (JSRole i : results) {
              roles.addItem(i.name, i.key);
            }
          }

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

    grid.setWidget(5, 2, newrole);

    newrole.setText(NEW_ROLE);

    newrole.addKeyPressHandler(
        new KeyPressHandler() {
          private void focusRole() {
            newrole.setFocus(true);
            newrole.setText(NEW_ROLE);
            newrole.setSelectionRange(0, NEW_ROLE.length());
          }

          public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
              final String role = newrole.getText();

              boolean found = false;

              for (int i = 0; i < roles.getItemCount(); ++i) {
                if (roles.getItemText(i).equals(role)) {
                  roles.setSelectedIndex(i);
                  addRole(role);
                  focusRole();
                  found = true;
                  break;
                }
              }

              if (!found) {
                GoteFarm.goteService.addRole(
                    admin.current_guild.key,
                    role,
                    true,
                    new AsyncCallback<JSRole>() {
                      public void onSuccess(JSRole result) {
                        roles.addItem(role, result.key);
                        roles.setSelectedIndex(roles.getItemCount() - 1);

                        addRole(role);
                        focusRole();
                      }

                      public void onFailure(Throwable caught) {
                        errmsg.setText(caught.getMessage());
                      }
                    });
              }
            }
          }
        });

    roleft.setWidth("100%");
    roleft.setCellSpacing(0);
    roleft.setCellPadding(5);
    roleft.setText(0, 0, "Role");
    roleft.setText(0, 1, "Min");
    roleft.setText(0, 2, "Max");
    roleft.setText(1, 0, "Totals");

    FlexTable.FlexCellFormatter rcf = roleft.getFlexCellFormatter();
    rcf.addStyleName(0, 0, "header");
    rcf.addStyleName(0, 1, "header");
    rcf.addStyleName(0, 2, "header");
    rcf.addStyleName(0, 3, "header");
    rcf.addStyleName(1, 0, "footer");
    rcf.addStyleName(1, 1, "footer");
    rcf.addStyleName(1, 2, "footer");
    rcf.addStyleName(1, 3, "footer");

    FlexTable.FlexCellFormatter gcf = grid.getFlexCellFormatter();

    grid.setWidget(6, 0, roleft);
    gcf.setColSpan(6, 0, 3);

    grid.setWidget(7, 1, badges);

    badges.addItem(SELECT_A_BADGE);

    GoteFarm.goteService.getBadges(
        admin.current_guild.key,
        new AsyncCallback<List<JSBadge>>() {
          public void onSuccess(List<JSBadge> results) {
            for (JSBadge badge : results) {
              badges.addItem(badge.name, badge.key);
            }
          }

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

    grid.setWidget(7, 2, newbadge);

    newbadge.setText(NEW_BADGE);

    newbadge.addKeyPressHandler(
        new KeyPressHandler() {
          private void focusBadge() {
            newbadge.setFocus(true);
            newbadge.setText(NEW_BADGE);
            newbadge.setSelectionRange(0, NEW_BADGE.length());
          }

          public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
              final String badge = newbadge.getText();

              boolean found = false;

              for (int i = 0; i < badges.getItemCount(); ++i) {
                if (badges.getItemText(i).equals(badge)) {
                  addBadge(badge);
                  focusBadge();
                  found = true;
                  break;
                }
              }

              if (!found) {
                GoteFarm.goteService.addBadge(
                    admin.current_guild.key,
                    badge,
                    0,
                    new AsyncCallback<JSBadge>() {
                      public void onSuccess(JSBadge result) {
                        badges.addItem(badge, result.key);
                        badges.setSelectedIndex(badges.getItemCount() - 1);

                        addBadge(badge);
                        focusBadge();
                      }

                      public void onFailure(Throwable caught) {
                        errmsg.setText(caught.getMessage());
                      }
                    });
              }
            }
          }
        });

    badgeft.setWidth("100%");
    badgeft.setCellSpacing(0);
    badgeft.setCellPadding(5);
    badgeft.setText(0, 0, "Badge");
    badgeft.setText(0, 1, "Require For Sign Up");
    badgeft.setText(0, 2, "Apply To Role");
    badgeft.setText(0, 3, "Num Role Slots");
    badgeft.setText(0, 4, "Early Signup (Hours)");

    FlexTable.FlexCellFormatter bcf = badgeft.getFlexCellFormatter();
    bcf.addStyleName(0, 0, "header");
    bcf.addStyleName(0, 1, "header");
    bcf.addStyleName(0, 2, "header");
    bcf.addStyleName(0, 3, "header");
    bcf.addStyleName(0, 4, "header");
    bcf.addStyleName(0, 5, "header");

    grid.setWidget(8, 0, badgeft);
    gcf.setColSpan(8, 0, 3);

    vpanel.add(grid);

    HorizontalPanel hpanel = new HorizontalPanel();
    hpanel.setWidth("100%");

    final CheckBox modify = new CheckBox("Modify published events (can change signups)");
    modify.setValue(true);
    modify.addStyleName(modify.getStylePrimaryName() + "-bottom");
    modify.addStyleName(modify.getStylePrimaryName() + "-left");

    Button save =
        new Button(
            "Save",
            new ClickHandler() {
              public void onClick(ClickEvent event) {
                // clear error message
                errmsg.setText("");

                final JSEventTemplate t = new JSEventTemplate();

                if (EventEditor.this.et != null) {
                  t.key = EventEditor.this.et.key;
                } else {
                  t.key = null;
                }

                t.name = name.getText();
                t.size = getRaidSize();
                t.minimumLevel = Integer.parseInt(minlevel.getText());
                int index = instances.getSelectedIndex();
                if (index < 0) {
                  errmsg.setText("Please select an instance for this event.");
                  return;
                }
                t.instance_key = instances.getValue(index);

                t.boss_keys = new ArrayList<String>();
                for (int i = 0; i < bosses.getItemCount(); ++i) {
                  if (bosses.isItemSelected(i)) {
                    t.boss_keys.add(bosses.getValue(i));
                  }
                }

                t.roles = new ArrayList<JSEventRole>();
                for (int i = 0; i < roleft.getRowCount() - 2; ++i) {
                  JSEventRole er = new JSEventRole();
                  er.name = roleft.getText(i + 1, 0);
                  er.role_key = getRoleKey(er.name);
                  TextBox minmax;
                  minmax = (TextBox) roleft.getWidget(i + 1, 1);
                  er.min = Integer.parseInt(minmax.getText());
                  minmax = (TextBox) roleft.getWidget(i + 1, 2);
                  er.max = Integer.parseInt(minmax.getText());
                  t.roles.add(er);
                }

                t.badges = new ArrayList<JSEventBadge>();
                for (int i = 0; i < badgeft.getRowCount() - 1; ++i) {
                  JSEventBadge eb = new JSEventBadge();
                  eb.name = badgeft.getText(i + 1, 0);
                  eb.badge_key = getBadgeKey(eb.name);
                  CheckBox cb = (CheckBox) badgeft.getWidget(i + 1, 1);
                  eb.requireForSignup = cb.getValue();
                  ListBox lb = (ListBox) badgeft.getWidget(i + 1, 2);
                  String role = lb.getItemText(lb.getSelectedIndex());
                  if (!role.equals(ALL_ROLES)) {
                    eb.applyToRole = role;
                  }
                  TextBox tb;
                  tb = (TextBox) badgeft.getWidget(i + 1, 3);
                  eb.numSlots = Integer.parseInt(tb.getText());
                  tb = (TextBox) badgeft.getWidget(i + 1, 4);
                  eb.earlySignup = Integer.parseInt(tb.getText());
                  t.badges.add(eb);
                }

                t.modifyEvents = modify.getValue();

                GoteFarm.goteService.saveEventTemplate(
                    admin.current_guild.key,
                    t,
                    new AsyncCallback<JSEventTemplate>() {
                      public void onSuccess(JSEventTemplate result) {
                        EventEditor.this.admin.eventAdded();
                        EventEditor.this.admin.setCenterWidget(null);
                        if (t.key != null && t.modifyEvents) {
                          admin.fireAdminChange(AdminChange.getEventsChanged());
                        }
                      }

                      public void onFailure(Throwable caught) {
                        errmsg.setText(caught.getMessage());
                      }
                    });
              }
            });

    save.addStyleName(save.getStylePrimaryName() + "-bottom");
    save.addStyleName(save.getStylePrimaryName() + "-left");

    Button cancel =
        new Button(
            "Cancel",
            new ClickHandler() {
              public void onClick(ClickEvent event) {
                EventEditor.this.admin.setCenterWidget(null);
              }
            });

    cancel.addStyleName(cancel.getStylePrimaryName() + "-bottom");
    cancel.addStyleName(cancel.getStylePrimaryName() + "-right");

    hpanel.add(save);
    // Editing an existing event?
    if (EventEditor.this.et != null) {
      hpanel.add(modify);
    }
    hpanel.add(errmsg);
    hpanel.add(cancel);

    vpanel.add(hpanel);

    if (et != null) {
      for (JSEventRole ev : et.roles) {
        addRole(ev.name, ev.min, ev.max);
      }

      for (JSEventBadge eb : et.badges) {
        addBadge(eb.name, eb.requireForSignup, eb.applyToRole, eb.numSlots, eb.earlySignup);
      }
    }

    if (et == null) {
      name.setText(NEW_EVENT);

      DeferredCommand.addCommand(
          new Command() {
            public void execute() {
              name.setFocus(true);
              name.setSelectionRange(0, NEW_EVENT.length());
            }
          });

      size.setText("25");
      minlevel.setText(MAX_LEVEL);
    } else {
      name.setText(et.name);
      size.setText("" + et.size);
      minlevel.setText("" + et.minimumLevel);
    }

    updateRoleTotals();

    initWidget(vpanel);

    setStyleName("Admin-EventEditor");
  }
Example #29
0
  protected void afterRender() {
    final Store store = ScreenManager.getStore();

    XTemplate template =
        new XTemplate(
            new String[] {
              "<tpl for='.'>",
              "<tpl if='thumbnail'>",
              "<div id={id}-dv class='thumb-wrap'>",
              "<div class='thumb'><img src='{thumbnail}' ext:qtip='{title}'></div>",
              "<span class='x-editable' ext:qtip='{title}'>{shortTitle}</span></div>",
              "</tpl>",
              "</tpl>",
              "<div class='x-clear'></div>"
            });

    Panel panel = new Panel();
    panel.setId("showcase-view");
    panel.setAutoWidth(true);
    panel.setAutoScroll(true);
    panel.setCollapsible(true);
    panel.setLayout(new FitLayout());
    panel.setTitle("Welcome to GWT-Ext 2.0.6");

    final DataView dataView =
        new DataView("div.thumb-wrap") {
          public void prepareData(Data data) {
            data.setProperty("shortTitle", Format.ellipsis(data.getProperty("title"), 15));
          }
        };

    dataView.addListener(
        new DataViewListenerAdapter() {

          public void onClick(DataView source, int index, Element node, EventObject e) {
            String id = DOMUtil.getID(node);
            String screenName = id.substring(0, id.length() - 3);
            Record record = store.getById(screenName);

            final ShowcasePanel panel = (ShowcasePanel) record.getAsObject("screen");
            if (panel != null) {
              String title = record.getAsString("title");
              String icon = record.getAsString("icon");
              screenManager.showScreen(panel, title, icon, screenName);
            }
          }
        });

    dataView.setTpl(template);
    dataView.setAutoWidth(true);
    dataView.setAutoHeight(true);
    dataView.setMultiSelect(false);
    dataView.setOverCls("x-view-over");
    dataView.setEmptyText("No Images to display");
    panel.add(dataView);

    DeferredCommand.addCommand(
        new Command() {
          public void execute() {
            dataView.setStore(store);
            dataView.refresh();
          }
        });
    add(panel);
  }
Example #30
0
  /**
   * Finalizes the <tt>User</tt> login.
   *
   * @param user Authenticated <tt>User.</tt>
   */
  private void onSuccessfulLogin(User user) {

    FormUtil.dlg.setText(OpenXdataText.get(TextConstants.LOADING));
    FormUtil.dlg.center();

    final LogoutListener logoutListener = this;
    final User loggedInUser = user;

    DeferredCommand.addCommand(
        new Command() {
          @Override
          public void execute() {
            try {

              // Set the authenticated User
              // in the Context for global access.
              Context.setAuthenticatedUser(loggedInUser);

              while (RootPanel.get().getWidgetCount() > 0) RootPanel.get().remove(0);

              if (mainView == null) {

                // Configure the Widget Factory for this session.
                OpenXDataWidgetFactory widgetFactory = new OpenXDataViewFactory();

                // Inject Widget Factory into other classes.
                injectWidgetFactory(widgetFactory);

                // Construct the MainView.
                mainView = (MainView) widgetFactory.getMainView(logoutListener);

                // Load Preliminary data.
                MainViewControllerFacade.loadPreliminaryViewData();

                RootPanel.get().add(mainView);

                FormUtil.dlg.hide();

                // Call the window resized handler to get the initial sizes setup.
                // Doing this in a deferred command causes it to occur after all widgets' sizes have
                // been computed by the browser.
                DeferredCommand.addCommand(
                    new Command() {
                      @Override
                      public void execute() {
                        resizeMainView(Window.getClientWidth(), Window.getClientHeight());

                        // We check User properties after all operations have been completed.
                        DeferredCommand.addCommand(
                            new Command() {
                              @Override
                              public void execute() {
                                checkIfUserChangedProperties();
                              }
                            });
                      }
                    });
              }
            } catch (Exception ex) {
              FormUtil.dlg.hide();
              FormUtil.displayException(ex);
            }
          }
        });
  }