コード例 #1
0
      @Override
      public void step1() {
        txt = content.getValue().toString();
        txt = txt.trim();
        if (txt.length() < 5) {
          Notification.show(
              "Card not played.",
              "Your message is too short to be useful.",
              Notification.Type.ERROR_MESSAGE);
          doNotAdvanceSteps(); // come into step1 again next time
          return;
        }
        if (txt.length() > 140) {
          Notification.show(
              "Card not played.", "Only 140 characters please.", Notification.Type.ERROR_MESSAGE);
          doNotAdvanceSteps(); // come into step1 again next time
          return;
        }

        // Admins get to add cards under other names
        author = Mmowgli2UI.getGlobals().getUserTL();
        if (author.isAdministrator()) adminSwitchAuthorsTL(event.getButton(), this);
        else run(); // does not need to suspend, so "continues" and executes step2
        // in the same clicklistener thread
      }
コード例 #2
0
      @Override
      @HibernateUserRead
      public void step2() {
        CardType ct = CardType.getTL(ctId);
        Date dt = new Date();
        Card c = new Card(txt, ct, dt);
        c.setCreatedInMove(Move.getCurrentMoveTL());
        c.setAuthor(User.getTL(author.getId())); // fresh
        if (newCardListener != null) newCardListener.cardCreatedTL(c);

        content.setValue("");
        content.setInputPrompt("Enter text for another card.");
        closeDrawer();

        resetCoroutine(); // for another click
      }
コード例 #3
0
    @SuppressWarnings("serial")
    @HibernateRead
    private void adminSwitchAuthorsTL(Button butt, final CardPlayHandler coroutine) {
      ArrayList<User> meLis = new ArrayList<User>(1);
      meLis.add(coroutine.author);
      User me = User.getTL(Mmowgli2UI.getGlobals().getUserID());

      final AddAuthorDialog dial = new AddAuthorDialog(meLis, true);
      StringBuilder sb = new StringBuilder("As adminstrator, <b>");
      sb.append(me.getUserName());
      sb.append("</b>, you may choose another player to be card author.");
      dial.infoLabel.setValue(sb.toString());
      dial.setCaption("Select Proxy Author");
      dial.setMultiSelect(false);
      dial.cancelButt.setCaption("Use myself");
      dial.addButt.setCaption("Use selected");

      // Rearrange buttons, add real cancel butt.
      // -------------------
      HorizontalLayout buttonHL = dial.getButtonHorizontalLayout();
      Iterator<Component> itr = buttonHL.iterator();
      Vector<Component> v = new Vector<Component>();
      while (itr.hasNext()) {
        Component component = itr.next();
        if (component instanceof Button) v.add(component);
      }
      buttonHL.removeAllComponents();
      itr = v.iterator();
      while (itr.hasNext()) {
        buttonHL.addComponent(itr.next());
      }
      Label sp = null;
      buttonHL.addComponent(sp = new Label());
      sp.setWidth("1px");
      buttonHL.setExpandRatio(sp, 1.0f);

      Button cancelButt = null;
      buttonHL.addComponent(cancelButt = new Button("Cancel"));
      cancelButt.addClickListener(
          new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
              UI.getCurrent().removeWindow(dial); // dial.getParent().removeWindow(dial);
              coroutine.resetCoroutine();
            }
          });
      // -------------------

      dial.selectItemAt(0);
      dial.addListener(
          new CloseListener() {
            @Override
            @MmowgliCodeEntry
            @HibernateOpened
            @HibernateClosed
            @HibernateUserRead
            public void windowClose(CloseEvent e) {
              HSess.init();
              if (dial.addClicked) {
                Object o = dial.getSelected();

                if (o instanceof User) {
                  coroutine.author = (User) o;
                } else if (o instanceof QuickUser) {
                  QuickUser qu = (QuickUser) o;
                  coroutine.author = User.getTL(qu.id);
                }
              }
              coroutine.run(); // finish up
              HSess.close();
            }
          });

      UI.getCurrent().addWindow(dial);
      dial.center();
    }
コード例 #4
0
 private boolean checkNoCreateBecauseHiddenTL(Card c) {
   if (c == null) return false; // ok to create
   User me = Mmowgli2UI.getGlobals().getUserTL();
   return c.isHidden() && !me.isGameMaster();
 }