Example usage for com.vaadin.ui Label removeShortcutListener

List of usage examples for com.vaadin.ui Label removeShortcutListener

Introduction

In this page you can find the example usage for com.vaadin.ui Label removeShortcutListener.

Prototype

@Deprecated
    public void removeShortcutListener(ShortcutListener shortcut) 

Source Link

Usage

From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesEntry.java

License:Open Source License

private void construct(final AbstractJcrNodeAdapter favorite, final FavoritesView.Listener listener) {
    addStyleName("favorites-entry");
    setSizeUndefined();/* w w w .  java  2s  . c o  m*/
    root.setSizeUndefined();

    this.enterKeyShortcutListener = new EnterKeyShortcutListener(listener);
    this.escapeKeyShortcutListener = new EscapeKeyShortcutListener();

    this.nodename = favorite.getNodeName();
    this.location = favorite.getItemProperty(AdmincentralNodeTypes.Favorite.URL).getValue().toString();
    this.title = favorite.getItemProperty(AdmincentralNodeTypes.Favorite.TITLE).getValue().toString();

    String icon = "icon-app";
    if (favorite.getItemProperty(AdmincentralNodeTypes.Favorite.ICON).getValue() != null) {
        icon = favorite.getItemProperty(AdmincentralNodeTypes.Favorite.ICON).getValue().toString();
    }

    final Label iconLabel = new Label();
    iconLabel.setValue("<span class=\"" + icon + "\"></span>");
    iconLabel.setStyleName("icon");
    iconLabel.setContentMode(ContentMode.HTML);
    root.addComponent(iconLabel);

    titleField = new TextField();
    titleField.setValue(title);
    titleField.setReadOnly(true);

    titleField.addFocusListener(new FocusListener() {

        @Override
        public void focus(FocusEvent event) {
            iconLabel.removeShortcutListener(enterKeyShortcutListener);
            titleField.addShortcutListener(enterKeyShortcutListener);
            titleField.addShortcutListener(escapeKeyShortcutListener);
        }
    });

    titleField.addBlurListener(new BlurListener() {

        @Override
        public void blur(BlurEvent event) {
            titleField.removeShortcutListener(enterKeyShortcutListener);
            titleField.removeShortcutListener(escapeKeyShortcutListener);
        }
    });

    root.addComponent(titleField);

    editButton = new NativeButton();
    editButton.setHtmlContentAllowed(true);
    editButton.setCaption("<span class=\"icon-edit\"></span>");
    editButton.addStyleName("favorite-action");
    editButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            doEditTitle(listener);
        }
    });
    editButton.setVisible(false);
    root.addComponent(editButton);

    removeButton = new NativeButton();
    removeButton.setHtmlContentAllowed(true);
    removeButton.setCaption("<span class=\"icon-trash\"></span>");
    removeButton.addStyleName("favorite-action");
    removeButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            shell.openConfirmation(MessageStyleTypeEnum.WARNING,
                    i18n.translate("confirmation.delete.title.generic"),
                    i18n.translate("confirmation.cannot.undo"), i18n.translate("confirmation.delete.yes"),
                    i18n.translate("confirmation.no"), false, new ConfirmationCallback() {

                        @Override
                        public void onSuccess() {
                            listener.removeFavorite(getRelPath());
                        }

                        @Override
                        public void onCancel() {
                            // no op
                        }
                    });
        }
    });
    removeButton.setVisible(false);
    root.addComponent(removeButton);

    root.addLayoutClickListener(new LayoutClickListener() {
        @Override
        public void layoutClick(LayoutClickEvent event) {
            if (event.getClickedComponent() == titleField && !editable) {
                if (event.isDoubleClick()) {
                    // TODO fgrilli commented out as, besides making the text editable, it also goes to the saved location
                    // See MGNLUI-1317
                } else {
                    listener.goToLocation(location);
                }
            }
        }
    });

    setCompositionRoot(root);
    setIconsVisibility(false);
}