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:org.apache.ace.webui.vaadin.AddArtifactWindow.java

License:Apache License

/**
 * Create a new button that delete an OBREntry on-click.
 * /*from w  ww . j a  va 2 s  . c  om*/
 * @param entry
 *            The entry
 * @return The button
 */
private Button createDeleteOBREntryButton(final OBREntry entry) {
    Button button = new Button("x");
    button.setStyleName(Reindeer.BUTTON_SMALL);
    button.setDescription("Delete " + entry.getName());

    button.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            event.getButton().setEnabled(false);

            try {
                int code = OBRUtil.deleteOBREntry(getConnectionFactory(), entry, m_obrUrl);
                if (code == HttpServletResponse.SC_OK) {
                    m_artifactsTable.removeItem(entry.getUri());
                } else {
                    showErrorNotification("Failed to delete resource",
                            "The OBR returned an unexpected response code: " + code);
                }
            } catch (IOException e) {
                showErrorNotification("Failed to delete resource", "Reason: " + e.getMessage());
            }

        }
    });

    return button;
}

From source file:org.apache.ace.webui.vaadin.component.BaseObjectPanel.java

License:Apache License

/**
 * Creates a remove-item button for the given repository object.
 * /*from w  w  w  . java 2s .  c om*/
 * @param object
 *            the object to create a remove-item button, cannot be <code>null</code>;
 * @param displayName
 *            the display name for the description of the button, cannot be <code>null</code>.
 * @return a remove-item button, never <code>null</code>.
 */
protected final Button createRemoveItemButton(RepositoryObject object, String displayName) {
    Button result = new Button();
    result.setIcon(createIconResource("trash"));
    result.setData(object.getDefinition());
    result.setStyleName("small tiny");
    result.setDescription("Delete " + displayName);
    result.setDisableOnClick(true);

    result.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            try {
                handleItemRemoveObject(event.getButton().getData());
            } catch (Exception e) {
                // ACE-246: notify user when the removal failed!
                getWindow().showNotification("Failed to remove item!", "<br/>Reason: " + e.getMessage(),
                        Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });

    return result;
}

From source file:org.apache.ace.webui.vaadin.component.BaseObjectPanel.java

License:Apache License

/**
 * Creates a remove-link button for the given repository object.
 * //from  w ww .j  ava 2 s.  c  o m
 * @param object
 *            the object to create a remove-link button, cannot be <code>null</code>;
 * @param displayName
 *            the display name for the description of the button, cannot be <code>null</code>.
 * @return a remove-link button, never <code>null</code>.
 */
protected final Button createRemoveLinkButton(RepositoryObject object, String displayName) {
    Button result = new Button();
    result.setIcon(createIconResource("unlink"));
    result.setStyleName("small tiny");
    result.setData(object.getDefinition());
    result.setDescription("Unlink " + displayName);
    // Only enable this button when actually selected...
    result.setEnabled(false);
    result.setDisableOnClick(true);

    result.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            handleItemRemoveLink(event.getButton().getData());
        }

    });

    return result;
}

From source file:org.apache.ace.webui.vaadin.LoginWindow.java

License:Apache License

/**
 * Creates a new {@link LoginWindow} instance.
 * // w  ww  .j a  v  a 2  s.  c o m
 * @param log
 *            the log service to use;
 * @param loginFunction
 *            the login callback to use.
 */
public LoginWindow(LogService log, LoginFunction loginFunction) {
    super("Apache ACE Login");

    m_log = log;
    m_loginFunction = loginFunction;

    setResizable(false);
    setClosable(false);
    setModal(true);
    setWidth("20em");

    m_additionalInfo = new Label("");
    m_additionalInfo.setImmediate(true);
    m_additionalInfo.setStyleName("alert");
    m_additionalInfo.setHeight("1.2em");
    // Ensures the information message disappears when starting typing...
    FieldEvents.TextChangeListener changeListener = new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(TextChangeEvent event) {
            m_additionalInfo.setValue("");
        }
    };

    final TextField nameField = new TextField("Name", "");
    nameField.addListener(changeListener);
    nameField.setImmediate(true);
    nameField.setWidth("100%");

    final PasswordField passwordField = new PasswordField("Password", "");
    passwordField.addListener(changeListener);
    passwordField.setImmediate(true);
    passwordField.setWidth("100%");

    Button loginButton = new Button("Login");
    loginButton.setImmediate(true);
    // Allow enter to be used to login directly...
    loginButton.setClickShortcut(KeyCode.ENTER);
    // Highlight this button as the default one...
    loginButton.addStyleName(Reindeer.BUTTON_DEFAULT);

    loginButton.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Button button = event.getButton();
            button.setEnabled(false);

            try {
                String username = (String) nameField.getValue();
                String password = (String) passwordField.getValue();

                if (m_loginFunction.login(username, password)) {
                    m_log.log(LogService.LOG_INFO, "Apache Ace WebUI succesfull login by user: " + username);

                    closeWindow();
                } else {
                    m_log.log(LogService.LOG_WARNING, "Apache Ace WebUI invalid username or password entered.");

                    m_additionalInfo.setValue("Invalid username or password!");

                    nameField.focus();
                    nameField.selectAll();
                }
            } finally {
                button.setEnabled(true);
            }
        }
    });

    final VerticalLayout content = (VerticalLayout) getContent();
    content.setSpacing(true);
    content.setMargin(true);
    content.setSizeFull();

    content.addComponent(nameField);
    content.addComponent(passwordField);
    content.addComponent(m_additionalInfo);
    content.addComponent(loginButton);

    content.setComponentAlignment(loginButton, Alignment.BOTTOM_CENTER);

    nameField.focus();
}

From source file:org.apache.ace.webui.vaadin.ManageResourceProcessorWindow.java

License:Apache License

private Button createRemoveButton(final ArtifactObject rp) {
    Button button = new Button("x");
    button.setStyleName(Reindeer.BUTTON_SMALL);
    button.setDescription("Remove " + rp.getAttribute(Constants.BUNDLE_SYMBOLICNAME));
    button.addListener(new ClickListener() {
        @Override/*from   w  w w.jav  a2  s.c  o  m*/
        public void buttonClick(ClickEvent event) {
            event.getButton().setEnabled(false);

            try {
                getArtifactRepository().remove(rp);
                m_artifactsTable.removeItem(rp.getDefinition());
            } catch (Exception e) {
                getParent().showNotification("Failed to delete resource", "Reason: <br/>" + e.getMessage(),
                        Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
    return button;
}

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

/**
 * Create a button to show a pop window for adding new features.
 * // w w  w  .j a v  a2  s  .c om
 * @param user
 * 
 * @param main
 *            Main Window
 * @return Button
 */
private Button createAddArtifactButton() {
    Button button = new Button("+");
    addCrossPlatformAddShortcut(button, KeyCode.A, "Add a new artifact");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            showAddArtifactDialog();
        }
    });
    return button;
}

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

/**
 * Create a button to show a popup window for adding a new distribution. On success this calls the
 * createDistribution() method.//from   w  w w.j  av  a 2 s.  c o  m
 * 
 * @param user
 * 
 * @return the add-distribution button instance.
 */
private Button createAddDistributionButton() {
    Button button = new Button("+");
    addCrossPlatformAddShortcut(button, KeyCode.D, "Add a new distribution");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            GenericAddWindow window = new GenericAddWindow("Add Distribution") {
                public void handleError(Exception e) {
                    // ACE-241: notify user when the distribution-creation failed!
                    getWindow().showNotification("Failed to add new distribution!",
                            "<br/>Reason: " + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
                }

                public void onOk(String name, String description) {
                    createDistribution(name, description);
                }
            };
            window.show(getMainWindow());
        }
    });

    return button;
}

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

/***
 * Create a button to show popup window for adding a new feature. On success this calls the createFeature() method.
 * /*from   w w  w  .  j a v  a2 s  . co  m*/
 * @param user
 * 
 * @return the add-feature button instance.
 */
private Button createAddFeatureButton() {
    Button button = new Button("+");
    addCrossPlatformAddShortcut(button, KeyCode.F, "Add a new feature");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            GenericAddWindow window = new GenericAddWindow("Add Feature") {
                public void handleError(Exception e) {
                    // ACE-241: notify user when the feature-creation failed!
                    getWindow().showNotification("Failed to add new feature!", "<br/>Reason: " + e.getMessage(),
                            Notification.TYPE_ERROR_MESSAGE);
                }

                public void onOk(String name, String description) {
                    createFeature(name, description);
                }
            };
            window.show(getMainWindow());
        }
    });
    return button;
}

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

/**
 * Create a button to show a popup window for adding a new target. On success this calls the createTarget() method
 * /*ww w .ja  va  2  s  . co m*/
 * @param user
 * 
 * @return the add-target button instance.
 */
private Button createAddTargetButton() {
    Button button = new Button("+");
    addCrossPlatformAddShortcut(button, KeyCode.G, "Add a new target");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            GenericAddWindow window = new GenericAddWindow("Add Target") {
                protected void handleError(Exception e) {
                    // ACE-241: notify user when the target-creation failed!
                    getWindow().showNotification("Failed to add new target!", "<br/>Reason: " + e.getMessage(),
                            Notification.TYPE_ERROR_MESSAGE);
                }

                @Override
                protected void initDialog() {
                    m_name.setCaption("Identifier");
                    m_description.setVisible(false);

                    super.initDialog();
                }

                protected void onOk(String id, String description) {
                    createTarget(id);
                }
            };
            window.show(getMainWindow());
        }
    });
    return button;
}

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

/**
 * @return a button to approve one or more targets.
 *///from  ww w.j  a  v a2  s  .co m
private Button createApproveTargetsButton() {
    final Button button = new Button("A");
    button.setDisableOnClick(true);
    button.setImmediate(true);
    button.setEnabled(false);
    button.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            m_targetsPanel.approveSelectedTargets();
        }
    });
    m_targetsPanel.addListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            TargetsPanel targetsPanel = (TargetsPanel) event.getProperty();

            Collection<?> itemIDs = (Collection<?>) targetsPanel.getValue();

            boolean enabled = false;
            for (Object itemID : itemIDs) {
                if (targetsPanel.isItemApproveNeeded(itemID)) {
                    enabled = true;
                    break;
                }
            }

            button.setEnabled(enabled);
        }
    });
    return button;
}