Example usage for com.vaadin.ui Button addListener

List of usage examples for com.vaadin.ui Button addListener

Introduction

In this page you can find the example usage for com.vaadin.ui Button addListener.

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:ro.zg.netcell.vaadin.action.application.EntityListHandler.java

License:Apache License

@Override
public void handle(final ActionContext actionContext) throws Exception {

    final UserAction ua = actionContext.getUserAction();
    final OpenGroupsApplication app = actionContext.getApp();

    ComponentContainer targetContainer = actionContext.getTargetContainer();
    targetContainer.removeAllComponents();
    targetContainer.addStyleName(OpenGroupsStyles.LIST_ACTIONS_CONTAINER);

    final Entity entity = actionContext.getEntity();
    /* reset filters */
    entity.resetFilters();// ww w.ja v a2s .c o  m

    // Panel listContainer = new Panel();
    // ((VerticalLayout)listContainer.getContent()).setMargin(false);

    CssLayout refreshButtonContainer = new CssLayout();
    // refreshButtonContainer.setSizeFull();
    //   refreshButtonContainer.setWidth("100%");
    refreshButtonContainer.addStyleName(OpenGroupsStyles.LIST_REFRESH_BAR);

    // final VerticalLayout listContainer = new VerticalLayout();

    final CssLayout listAndPageControlsContainer = new CssLayout();
    //   final VerticalLayout listAndPageControlsContainer = new VerticalLayout();

    listAndPageControlsContainer.addStyleName("list-container");
    // listAndPageControlsContainer.setSizeFull();
    //   listAndPageControlsContainer.setWidth("100%");

    Button refreshButton = new Button();
    refreshButton.setDescription(getMessage("refresh.list"));
    refreshButton.setIcon(OpenGroupsResources.getIcon(OpenGroupsIconsSet.REFRESH, OpenGroupsIconsSet.MEDIUM));
    refreshButton.addStyleName(BaseTheme.BUTTON_LINK + " middle-right");
    refreshButton.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            refreshList(entity, ua, app, listAndPageControlsContainer, actionContext);
        }
    });

    targetContainer.addComponent(refreshButtonContainer);
    Component searchFilter = getSearchFilter(entity, ua, app, actionContext);
    searchFilter.addStyleName("middle-left");
    refreshButtonContainer.addComponent(searchFilter);
    refreshButtonContainer.addComponent(refreshButton);

    ComponentContainer filtersContainer = initFilters(entity, ua, app, actionContext);
    targetContainer.addComponent(filtersContainer);

    targetContainer.addComponent(listAndPageControlsContainer);
    int itemsCount = refreshList(entity, ua, app, listAndPageControlsContainer, actionContext);
}

From source file:ro.zg.netcell.vaadin.action.application.EntityListHandler.java

License:Apache License

private void refreshPageControls(final Entity entity, final UserAction ua, final OpenGroupsApplication app,
        final ComponentContainer container, final ActionContext ac) {

    final int itemsPerPage = entity.getState().getItemsPerPage();

    Button prevButton = new Button();
    prevButton.setIcon(OpenGroupsResources.getIcon(OpenGroupsIconsSet.LEFT_ARROW, OpenGroupsIconsSet.SMALL));

    ComboBox currentPageSelect = new ComboBox();
    currentPageSelect.setImmediate(true);
    currentPageSelect.setNullSelectionAllowed(false);
    currentPageSelect.setNewItemsAllowed(false);

    double totalItemsCount = entity.getState().getCurrentListTotalItemsCount();

    if (totalItemsCount < 0) {
        /* the type of the listed entities */
        String targetEntityComplexType = ua.getTargetEntityComplexType().toLowerCase();
        /* let's find out if this list is recursive or not */
        boolean isRecursive = false;
        /* first check if the target type allows a recursive list in the first place */
        //       if (getAppConfigManager().getComplexEntityBooleanParam(ua.getTargetEntityComplexType(),
        //          ComplexEntityParam.ALLOW_RECURSIVE_LIST)) {
        if (app.getAppConfigManager().getTypeRelationBooleanConfigParam(ua.getTypeRelationId(),
                TypeRelationConfigParam.ALLOW_RECURSIVE_LIST)) {
            /*/*from w  ww  .  j a va2  s.  com*/
             * if it does, check if the filter is actually set to display all items, that means the recursion depth
             * is undefined or greater than 0
             */
            isRecursive = (entity.getFilterValue("depth") == null) ? true : false;
            if (!isRecursive) {
                long listDepth = (Long) entity.getFilter("depth").getValue();
                if (listDepth > 0) {
                    isRecursive = true;
                }
            }
        }

        /* if the list is recursive get the number of all entities of the specified type under selected entity */
        if (isRecursive) {
            totalItemsCount = entity.getRecursiveSubtypeEntitiesCount().get(targetEntityComplexType);
        }
        /* not recursive, get only the number of first level entities of the specified type */
        else {
            totalItemsCount = entity.getSubtypeEntitiesCount().get(targetEntityComplexType);
        }
    }

    /*
     * now that we know the total possible entities in this list, and the items per page, we can calculate, the
     * number of pages
     */
    int numberOfPages = (int) Math.ceil(totalItemsCount / itemsPerPage);
    final int currentPage = entity.getState().getCurrentPageForCurrentAction();

    /* populate the currentpage combobox with the number of pages */
    for (int i = 1; i <= numberOfPages; i++) {
        currentPageSelect.addItem(i + "/" + numberOfPages);
    }
    String currentPageString = currentPage + "/" + numberOfPages;
    currentPageSelect.setValue(currentPageString);
    int width = currentPageString.length() * 20;
    currentPageSelect.setWidth(width + "px");

    Button nextButton = new Button();
    nextButton.setIcon(OpenGroupsResources.getIcon(OpenGroupsIconsSet.RIGHT_ARROW, OpenGroupsIconsSet.SMALL));

    if (currentPage == 1) {
        prevButton.setEnabled(false);
    }
    if (currentPage == numberOfPages) {
        nextButton.setEnabled(false);
    }

    prevButton.addStyleName("middle-left right-margin-10");
    currentPageSelect.addStyleName("middle-left right-margin-10");
    nextButton.addStyleName("middle-left");

    container.addComponent(prevButton);
    container.addComponent(currentPageSelect);
    container.addComponent(nextButton);

    /* listeners */

    prevButton.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            entity.getState().setCurrentPageForCurrentAction(currentPage - 1);
            refreshList(entity, ua, app, entity.getState().getLastUsedContainer(), ac);
            // refreshList(entity, ua, app, entity.getState().getChildrenListContainer());
        }
    });

    nextButton.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            entity.getState().setCurrentPageForCurrentAction(currentPage + 1);
            refreshList(entity, ua, app, entity.getState().getLastUsedContainer(), ac);
            // refreshList(entity, ua, app, entity.getState().getChildrenListContainer());
        }
    });

    currentPageSelect.addListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            String value = (String) event.getProperty().getValue();
            String page = value.substring(0, value.indexOf("/"));
            entity.getState().setCurrentPageForCurrentAction(Integer.parseInt(page));
            refreshList(entity, ua, app, entity.getState().getLastUsedContainer(), ac);
            // refreshList(entity, ua, app, entity.getState().getChildrenListContainer());
        }
    });

}

From source file:ro.zg.netcell.vaadin.action.application.LoadMainWindowHandler.java

License:Apache License

private void addUserHeaderActions(final OpenGroupsApplication app, final ActionContext ac)
        throws ContextAwareException {
    UserActionList actionList = getGlobalActions(ActionLocations.HEADER);
    if (actionList == null) {
        return;// w  w w.  j  a  v  a2  s .  c  o  m
    }
    Collection<UserAction> userActions = actionList.getActions().values();
    OpenGroupsMainWindow window = ac.getWindow();
    User user = app.getCurrentUser();

    CssLayout header = window.getHeader();
    header.removeAllComponents();

    if (user != null) {

        Embedded usericon = new Embedded(null,
                OpenGroupsResources.getIcon(OpenGroupsIconsSet.USER, OpenGroupsIconsSet.MEDIUM));
        usericon.addStyleName("middle-left right-margin-10");
        header.addComponent(usericon);

        Label userInfo = new Label(/*app.getMessage("login.user.info") + ": " +*/ user.getUsername());
        userInfo.setSizeUndefined();
        header.addComponent(userInfo);
        userInfo.addStyleName("username-label");

    }

    /* get the current user types */
    //   List<String> userTypes = UsersManager.getInstance().getCurrentUserTypes(null, app);
    for (final UserAction ua : userActions) {
        /*
         * if the current user is not allowed to read/view the current action then skip it
         */
        //       if (!ua.allowRead(userTypes)) {
        if (!ua.isVisible(ac)) {
            continue;
        }
        Button actButton = new Button(ua.getDisplayName());

        actButton.addListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                // app.executeAction(ua, null);
                ua.executeHandler(null, app, null, ac);
            }
        });

        header.addComponent(actButton);
        actButton.addStyleName("middle-right left-margin-10");

    }

    Component rootLink = getRootEntityLink(app);
    Component metaLink = getMetaEntityLink(app);
    rootLink.setSizeUndefined();
    metaLink.setSizeUndefined();

    /* add quick links */
    header.addComponent(rootLink);
    header.addComponent(metaLink);
    rootLink.addStyleName("middle-right left-margin-10");
    metaLink.addStyleName("middle-right left-margin-10");
}

From source file:ro.zg.netcell.vaadin.action.application.OpenSelectedEntityHandler.java

License:Apache License

private Button getButtonForInactiveAction(final UserAction ha, final Entity entity,
        final OpenGroupsApplication app, final ActionContext ac) {
    String actionState = ha.getActionName() + ".off";
    String caption = OpenGroupsResources.getMessage(actionState);
    Button actButton = new Button();
    actButton.setDescription(caption);/*  w ww  . ja v a2s.c om*/
    actButton.setIcon(OpenGroupsResources.getIcon(actionState, OpenGroupsIconsSet.MEDIUM));
    actButton.addStyleName(BaseTheme.BUTTON_LINK);
    actButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // ha.executeHandler(entity,app,app.getTemporaryTab(entity).getContainer());
            CssLayout hac = (CssLayout) entity.getHeaderActionContainer(ha.getActionName());
            hac.setVisible(true);
            ha.executeHandler(entity, app, hac, ac);
            // app.refreshEntity(entity);
            refreshHeaderActionLinks(entity, app, ac);
        }
    });
    return actButton;
}

From source file:ro.zg.netcell.vaadin.action.application.OpenSelectedEntityHandler.java

License:Apache License

private Button getButtonForActiveAction(final UserAction ha, final Entity entity,
        final OpenGroupsApplication app, final ActionContext ac) {

    String actionState = ha.getActionName() + ".on";
    String caption = OpenGroupsResources.getMessage(actionState);
    Button actButton = new Button();
    actButton.setDescription(caption);/*  www . ja v  a 2  s .c  o  m*/
    actButton.setIcon(OpenGroupsResources.getIcon(actionState, OpenGroupsIconsSet.MEDIUM));
    actButton.addStyleName(BaseTheme.BUTTON_LINK);
    actButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            entity.getState().setActionInactive(ha.getActionName());
            // app.getTemporaryTab(entity).setRefreshOn(true);
            // getActionsManager().executeAction(ActionsManager.OPEN_ENTITY_IN_TAB,
            // entity,app,null, false);
            CssLayout hac = (CssLayout) entity.getHeaderActionContainer(ha.getActionName());
            hac.setVisible(false);
            // app.refreshEntity(entity);
            refreshHeaderActionLinks(entity, app, ac);
        }
    });
    return actButton;
}

From source file:ro.zg.netcell.vaadin.action.application.OpenSelectedEntityHandler.java

License:Apache License

private Button getRefreshButton(final Entity entity, final OpenGroupsApplication app, final ActionContext ac) {
    Button refreshButton = new Button();
    refreshButton.setDescription(getMessage("refresh.entity"));
    refreshButton.setIcon(OpenGroupsResources.getIcon(OpenGroupsIconsSet.REFRESH, OpenGroupsIconsSet.MEDIUM));
    refreshButton.addStyleName(BaseTheme.BUTTON_LINK);

    refreshButton.addListener(new ClickListener() {

        @Override/*from  w  w  w.ja v a2s  . co  m*/
        public void buttonClick(ClickEvent event) {
            // app.getTemporaryTab(entity).setRefreshOn(true);
            // getActionsManager().executeAction(ActionsManager.OPEN_ENTITY_IN_TAB,
            // entity, app, null, false);
            app.fullyRefreshEntity(entity, ac);
        }
    });
    return refreshButton;
}

From source file:ro.zg.netcell.vaadin.action.application.OpenSelectedEntityWithHeaderActions.java

License:Apache License

private Button getShowCauseButton(final ActionContext context, final ComboBox causesCombo) {
    final Entity entity = context.getEntity();
    final Button actButton = new Button();
    actButton.addStyleName(BaseTheme.BUTTON_LINK);
    actButton.addListener(new ClickListener() {
        @Override//w  ww  .  ja  v a  2s .c om
        public void buttonClick(ClickEvent event) {
            EntityState state = entity.getState();
            if (state.isActionActive(ActionConstants.SHOW_CAUSE)) {
                state.setActionInactive(ActionConstants.SHOW_CAUSE);
                hideCause(context);
                causesCombo.setVisible(true);
            } else {
                state.setActionActive(ActionConstants.SHOW_CAUSE);
                showCause(context);
                causesCombo.setVisible(false);
            }
            updateCausesFragment(context, actButton);
        }
    });
    return actButton;
}

From source file:ro.zg.netcell.vaadin.action.application.UpdateEntityHandler.java

License:Apache License

private void displaySuccessfulMessage(final Entity entity, final UserAction ua, final OpenGroupsApplication app,
        final ComponentContainer targetComponent, final ActionContext ac) {
    /* store current target component */
    // final ComponentContainer targetComponent = app.getTargetComponent();
    targetComponent.removeAllComponents();
    String entityTypeLowerCase = ua.getTargetEntityType().toLowerCase();
    String createdSuccessfullyMessage = app.getMessage(entityTypeLowerCase + ".updated.successfully");
    String newUpdateMessage = app.getMessage("new.update");

    HorizontalLayout container = new HorizontalLayout();
    container.setSizeFull();//from   www  .j av  a2  s.  c  om
    container.setSpacing(true);
    targetComponent.addComponent(container);

    Label success = new Label(createdSuccessfullyMessage);
    container.addComponent(success);

    Button newUpdate = new Button(newUpdateMessage);
    container.addComponent(newUpdate);
    newUpdate.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            // Entity entity = new Entity(entityId);
            // app.pushSelectedEntity(entity);
            // app.executeAction(ActionsManager.OPEN_ENTITY_IN_WINDOW);
            ua.executeHandler(entity, app, targetComponent, ac);
        }
    });

}

From source file:ro.zg.netcell.vaadin.action.application.VoteEntityHandler.java

License:Apache License

private void showAlreadyVotedFragment(final ComponentContainer container, final Entity selectedEntity,
        final OpenGroupsApplication app, final UserAction ua, final ActionContext ac) {
    String entityType = selectedEntity.getSimpleType().toLowerCase();
    String currentUserVote = selectedEntity.getUserData().getVote();
    String messageKey = entityType + ".already.voted." + currentUserVote;
    HorizontalLayout hl = new HorizontalLayout();
    hl.addStyleName(OpenGroupsStyles.TOP_RIGHT);
    hl.setSpacing(true);/*from w ww .  ja  va 2 s . c  o  m*/
    hl.addComponent(new Label(OpenGroupsResources.getMessage(messageKey)));

    final VoteType opposedVote = VoteType.opposteVoteForValue(currentUserVote, entityType);

    Button changeVoteButton = new Button(/*OpenGroupsResources.getMessage("change.vote")*/);
    changeVoteButton.setCaption(opposedVote.getCaption());
    changeVoteButton.setIcon(opposedVote.getIcon());
    changeVoteButton.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            //      container.removeAllComponents();
            //      showVotesFragment(container, selectedEntity, app, ua, ac);
            Map<String, Object> params = ua.getActionParams();
            //      params.put("entityId", selectedEntity.getId());
            params.put("entityLinkId", selectedEntity.getSelectedCause().getLinkId());
            params.put("userId", app.getCurrentUserId());
            params.put("isRecordCreated", selectedEntity.getUserData().isEntityLinkUserRecordCreated());
            params.put("vote", opposedVote.getValue());
            CommandResponse response = executeAction(new ActionContext(ua, app, selectedEntity), params);
            /* refresh the entity only if the user was actually able to vote */
            if (response != null) {
                app.refreshEntity(selectedEntity, ac);
            }
        }
    });
    hl.addComponent(changeVoteButton);

    Button recallVoteButton = new Button(OpenGroupsResources.getMessage("recall.vote"));
    recallVoteButton.setIcon(OpenGroupsResources.getIcon(OpenGroupsIconsSet.CANCEL, OpenGroupsIconsSet.SMALL));
    recallVoteButton.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            EntityLink selectedCause = selectedEntity.getSelectedCause();

            Map<String, Object> params = ua.getActionParams();

            params.put("entityLinkId", selectedCause.getLinkId());
            params.put("userId", app.getCurrentUserId());
            params.put("isRecordCreated", true);

            CommandResponse response = executeAction(new ActionContext(ua, app, selectedEntity), params);
            /* refresh the entity only if the user was actually able to vote */
            if (response != null) {
                app.refreshEntity(selectedEntity, ac);
            }
        }
    });
    hl.addComponent(recallVoteButton);
    container.addComponent(hl);
}

From source file:ro.zg.netcell.vaadin.action.application.VoteEntityHandler.java

License:Apache License

private Button getButtonForVoteType(final VoteType voteType, final ComponentContainer container,
        final Entity selectedEntity, final OpenGroupsApplication app, final UserAction ua,
        final ActionContext ac) {
    Button button = new Button();
    button.setCaption(voteType.getCaption());
    button.setIcon(voteType.getIcon());//from w  ww .  ja va 2 s  .  c o  m
    //   button.setDescription(voteType.getCaption());
    button.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {

            Map<String, Object> params = ua.getActionParams();
            //      params.put("entityId", selectedEntity.getId());
            params.put("entityLinkId", selectedEntity.getSelectedCause().getLinkId());
            params.put("userId", app.getCurrentUserId());
            params.put("isRecordCreated", selectedEntity.getUserData().isEntityLinkUserRecordCreated());
            params.put("vote", voteType.getValue());
            CommandResponse response = executeAction(new ActionContext(ua, app, selectedEntity), params);
            /* refresh the entity only if the user was actually able to vote */
            if (response != null) {
                app.refreshEntity(selectedEntity, ac);
            }
        }
    });
    return button;
}