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.escidoc.browser.elabsmodul.views.helpers.StartInvestigationViewHelper.java

License:Open Source License

public void createStartButton(Panel panel) {
    Button startBtn = new Button(ELabsViewContants.BTN_START);
    startBtn.setWidth("100%");

    startBtn.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -7563393988056484131L;

        @Override/*from   w  ww .  j  a v  a2s.c  o  m*/
        public void buttonClick(final ClickEvent event) {
            if (event.getButton().getCaption().equals(ELabsViewContants.BTN_START)) {
                labsPanel.getReference().getApplication().getMainWindow()
                        .addWindow(new YesNoDialog("Start investigation",
                                "Really want to start the investigation?", new YesNoDialog.Callback() {
                                    @Override
                                    public void onDialogResult(boolean resultIsYes) {
                                        if (resultIsYes) {
                                            try {
                                                investigationAction.getLabsService().start();
                                                event.getButton().setCaption(ELabsViewContants.BTN_STOP);
                                                labsPanel.getReference().getApplication().getMainWindow()
                                                        .getWindow().showNotification("Starting",
                                                                "Starting process...",
                                                                Notification.TYPE_TRAY_NOTIFICATION);
                                            } catch (EscidocBrowserException e) {
                                                event.getButton().setCaption(ELabsViewContants.BTN_START);
                                                labsPanel.getReference().getApplication().getMainWindow()
                                                        .getWindow().showNotification("Problem",
                                                                "Starting process... cancelled",
                                                                Notification.TYPE_TRAY_NOTIFICATION);
                                            }
                                        }
                                    }
                                }));
            } else if (event.getButton().getCaption().equals(ELabsViewContants.BTN_STOP)) {

                try {
                    investigationAction.getLabsService().stop();
                    event.getButton().setCaption(ELabsViewContants.BTN_START);
                    labsPanel.getReference().getApplication().getMainWindow().getWindow().showNotification(
                            "Stopping", "Halting process...", Notification.TYPE_TRAY_NOTIFICATION);
                } catch (EscidocBrowserException e) {
                    event.getButton().setCaption(ELabsViewContants.BTN_STOP);
                    labsPanel.getReference().getApplication().getMainWindow().getWindow().showNotification(
                            "Problem", "Halting process... cancelled", Notification.TYPE_TRAY_NOTIFICATION);
                }
            } else {
                LOG.error("There is no such button!");
            }
        }
    });

    HorizontalLayout layout = new HorizontalLayout();
    layout.addComponent(startBtn);
    layout.setWidth("100%");
    layout.setComponentAlignment(startBtn, Alignment.MIDDLE_CENTER);
    panel.addComponent(layout);
}

From source file:org.escidoc.browser.layout.NavigationSimpleLayout.java

License:Open Source License

private CssLayout newHeaderButton(final TreeDataSource ds) {
    CssLayout cssLayout = new CssLayout();
    cssLayout.setWidth("97%");
    cssLayout.setMargin(false);/* ww  w .  ja v a  2s.  co  m*/

    ThemeResource plusIcon = new ThemeResource("images/assets/plus.png");

    final Button createGroupButton = new Button();
    createGroupButton.setStyleName(BaseTheme.BUTTON_LINK);
    createGroupButton.addStyleName("floatright paddingtop3");
    createGroupButton.setWidth("20px");
    createGroupButton.setIcon(plusIcon);
    createGroupButton.addListener(new ClickListener() {

        @Override
        public void buttonClick(@SuppressWarnings("unused") final ClickEvent event) {
            showCreateGroupView();
        }

        private void showCreateGroupView() {
            router.getMainWindow().addWindow(
                    new CreateGroupView(repositories.group(), router.getMainWindow(), ds).modalWindow());
        }

    });
    cssLayout.addComponent(createGroupButton);
    return cssLayout;
}

From source file:org.escidoc.browser.ui.GroupRolesView.java

License:Open Source License

private Button buildAddGrantButton(final NativeSelect resourceSelect, final NativeSelect roleNameSelect) {
    Button assignGrantButton = new Button();
    assignGrantButton.setIcon(new ThemeResource("images/assets/plus.png"));

    assignGrantButton.addListener(new Button.ClickListener() {

        @Override//from  w w  w . ja v  a 2s. co m
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            try {
                if (getSelectedRole() == null) {
                    router.getMainWindow().showNotification("Role can not be empty", "",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                    return;
                }
                Grant grant = assignGrantInServer();
                updateView();
                showSuccessMessage(grant);
            } catch (EscidocClientException e) {
                router.getMainWindow().showNotification("Error Message",
                        "Something wrong happens. Cause: " + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
            }
        }

        private void showSuccessMessage(Grant grant) {
            router.getMainWindow().showNotification("",
                    "Sucessfully assign" + grant.getXLinkTitle() + " to " + groupId,
                    Notification.TYPE_TRAY_NOTIFICATION);

        }

        private Grant assignGrantInServer() throws EscidocClientException {
            return repositories.group().assign(groupId).withRole(getSelectedRole())
                    .onResources(getSelectedResources()).execute();
        }

        private RoleModel getSelectedRole() {
            final Object value = roleNameSelect.getValue();
            if (value instanceof RoleModel) {
                return (RoleModel) value;
            }
            return null;
        }

        private Set<ResourceModel> getSelectedResources() {
            final Object value = resourceSelect.getValue();
            if (value instanceof ResourceModel) {
                return Collections.singleton((ResourceModel) value);
            }
            return Collections.emptySet();
        }

        private void updateView() throws EscidocClientException {
            listRolesForUser(rolesLayout);
        }
    });
    return assignGrantButton;
}

From source file:org.escidoc.browser.ui.GroupRolesView.java

License:Open Source License

private Button buildRemoveButton(int rowNumber, Grant grant) {
    Button removeButton = new Button();
    removeButton.setIcon(new ThemeResource("images/assets/minus.png"));
    removeButton.setData(Integer.valueOf(rowNumber));
    removeButton.addListener(new OnRemoveGrant(grant, groupId, repositories, router.getMainWindow()));
    return removeButton;
}

From source file:org.escidoc.browser.ui.listeners.OnContextAdminDescriptor.java

License:Open Source License

@SuppressWarnings("serial")
public void adminDescriptorForm() {
    final Window subwindow = new Window("A modal subwindow");
    subwindow.setModal(true);// w ww.  j  a va  2  s.  c o  m
    subwindow.setWidth("650px");
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);

    final TextField txtName = new TextField("Name");
    txtName.setImmediate(true);
    txtName.setValidationVisible(true);
    final TextArea txtContent = new TextArea("Content");
    txtContent.setColumns(30);
    txtContent.setRows(40);

    Button addAdmDescButton = new Button("Add Description");
    addAdmDescButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {

            if (txtName.getValue().toString() == null) {
                router.getMainWindow().showNotification(ViewConstants.PLEASE_ENTER_A_NAME,
                        Notification.TYPE_ERROR_MESSAGE);
            } else if (!XmlUtil.isWellFormed(txtContent.getValue().toString())) {
                router.getMainWindow().showNotification(ViewConstants.XML_IS_NOT_WELL_FORMED,
                        Notification.TYPE_ERROR_MESSAGE);
            } else {
                AdminDescriptor newAdmDesc = controller.addAdminDescriptor(txtName.getValue().toString(),
                        txtContent.getValue().toString());
                (subwindow.getParent()).removeWindow(subwindow);
                router.getMainWindow().showNotification("Addedd Successfully",
                        Notification.TYPE_HUMANIZED_MESSAGE);
            }
        }
    });

    subwindow.addComponent(txtName);
    subwindow.addComponent(txtContent);
    subwindow.addComponent(addAdmDescButton);

    Button close = new Button(ViewConstants.CLOSE, new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    layout.addComponent(close);
    layout.setComponentAlignment(close, Alignment.TOP_RIGHT);

    router.getMainWindow().addWindow(subwindow);

}

From source file:org.escidoc.browser.ui.listeners.OnContextAdminDescriptor.java

License:Open Source License

/**
 * Editing since it has a parameter//w  w  w . j ava  2  s .  c o m
 * 
 * @param adminDescriptor
 */
public void adminDescriptorForm(AdminDescriptor adminDescriptor) {

    // Editing
    final Window subwindow = new Window("A modal subwindow");
    subwindow.setModal(true);
    subwindow.setWidth("650px");

    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);

    final TextField txtName = new TextField("Name");
    txtName.setValue(adminDescriptor.getName());
    txtName.setImmediate(true);
    txtName.setValidationVisible(true);
    final TextArea txtContent = new TextArea("Content");
    txtContent.setColumns(30);
    txtContent.setRows(40);
    try {
        txtContent.setValue(adminDescriptor.getContentAsString());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    txtContent.setColumns(30);

    Button addAdmDescButton = new Button("Add Description");
    addAdmDescButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {

            if (txtName.getValue().toString() == null) {
                router.getMainWindow().showNotification(ViewConstants.PLEASE_ENTER_A_NAME,
                        Notification.TYPE_ERROR_MESSAGE);

            } else if (!XmlUtil.isWellFormed(txtContent.getValue().toString())) {
                router.getMainWindow().showNotification(ViewConstants.XML_IS_NOT_WELL_FORMED,
                        Notification.TYPE_ERROR_MESSAGE);
            } else {
                controller.addAdminDescriptor(txtName.getValue().toString(), txtContent.getValue().toString());
                (subwindow.getParent()).removeWindow(subwindow);
                router.getMainWindow().showNotification("Addedd Successfully",
                        Notification.TYPE_HUMANIZED_MESSAGE);
            }
        }
    });

    subwindow.addComponent(txtName);
    subwindow.addComponent(txtContent);
    subwindow.addComponent(addAdmDescButton);

    Button close = new Button(ViewConstants.CLOSE, new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    layout.addComponent(close);
    layout.setComponentAlignment(close, Alignment.TOP_RIGHT);

    router.getMainWindow().addWindow(subwindow);

}

From source file:org.escidoc.browser.ui.listeners.RelationsClickListener.java

License:Open Source License

public Layout getRelations(final Repository cr, final String id, final Window subwindow)
        throws EscidocClientException {

    final Relations relations = cr.getRelations(id);
    final HorizontalLayout hl = new HorizontalLayout();

    for (final Relation relation : relations) {
        String predicate;//from  w w  w. ja v  a2s. c  o  m
        if (relation.getPredicate().indexOf("#") != -1) {
            predicate = relation.getPredicate().substring(relation.getPredicate().lastIndexOf('#'),
                    relation.getPredicate().length());
        } else {
            predicate = relation.getPredicate();
        }

        final String prefixPath = relation.getXLinkHref().substring(0,
                relation.getXLinkHref().lastIndexOf('/'));
        type = ResourceType.getValue(prefixPath);

        final Button btnRelation = new Button(
                itemProxy.getName() + " relation as " + predicate + " of " + relation.getXLinkTitle());
        btnRelation.setStyleName(BaseTheme.BUTTON_LINK);
        btnRelation.addListener(new ClickListener() {

            @Override
            public void buttonClick(final ClickEvent event) {
                if (type.name().equals("CONTAINER")) {
                    try {
                        new ContainerController(repositories, router,
                                repositories.container().findById(relation.getObjid()));
                    } catch (final EscidocClientException e) {
                        mainWindow.showNotification(e.getLocalizedMessage());
                        e.printStackTrace();
                    }
                } else if (type.name().equals("ITEM")) {
                    try {
                        new ItemController(repositories, router,
                                repositories.item().findById(relation.getObjid()));
                    } catch (final EscidocClientException e) {
                        mainWindow.showNotification(e.getLocalizedMessage());
                    }
                }

            }
        });
        hl.addComponent(btnRelation);
        LOG.debug("relation title: " + relation.getXLinkTitle());
    }

    return hl;

}

From source file:org.escidoc.browser.ui.maincontent.ContainerMetadataRecordsView.java

License:Open Source License

@SuppressWarnings("serial")
private Panel lblAddtionalResources() {
    final Panel pnl = new Panel();
    pnl.setSizeFull();//from w w  w.j  a  v a2  s.c om
    VerticalLayout hl = new VerticalLayout();
    hl.setSizeFull();
    final Button btnVersionHistoryContainer = new Button("Container Version History",
            new VersionHistoryClickListener(resourceProxy, mainWindow, repositories));
    btnVersionHistoryContainer.setStyleName(BaseTheme.BUTTON_LINK);
    btnVersionHistoryContainer.setDescription("Show Version history in a Pop-up");

    final CssLayout cssLayout = new CssLayout();
    buildPanelHeader(cssLayout, "Additional Resources");
    ThemeResource ICON = new ThemeResource("images/assets/plus.png");

    final Button addResourceButton = new Button();
    addResourceButton.setStyleName(BaseTheme.BUTTON_LINK);
    addResourceButton.addStyleName("floatright paddingtop3");
    addResourceButton.setWidth("20px");
    addResourceButton.setIcon(ICON);
    addResourceButton.addListener(new ClickListener() {

        @Override
        public void buttonClick(final ClickEvent event) {
            final Window subwindow = new Window("A modal subwindow");
            subwindow.setModal(true);
            subwindow.setWidth("650px");
            VerticalLayout layout = (VerticalLayout) subwindow.getContent();
            layout.setMargin(true);
            layout.setSpacing(true);

            subwindow.addComponent(new Label("Not yet implemented"));
            Button close = new Button("Close", new Button.ClickListener() {
                @Override
                public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
                    (subwindow.getParent()).removeWindow(subwindow);
                }
            });
            layout.addComponent(close);
            layout.setComponentAlignment(close, Alignment.TOP_RIGHT);

            router.getMainWindow().addWindow(subwindow);

        }

    });
    cssLayout.addComponent(addResourceButton);
    hl.addComponent(cssLayout);

    hl.addComponent(btnVersionHistoryContainer);
    pnl.setContent(hl);
    return pnl;
}

From source file:org.escidoc.browser.ui.maincontent.ContainerMetadataRecordsView.java

License:Open Source License

private Panel lblMetadaRecs() {
    panel.setSizeFull();/* w w  w  .j  av a2s.  c o  m*/
    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();
    final CssLayout cssLayout = new CssLayout();
    cssLayout.setHeight("20px");
    buildPanelHeader(cssLayout, ViewConstants.METADATA);
    ThemeResource ICON = new ThemeResource("images/assets/plus.png");

    if (containerController.hasAccess()) {
        final Button btnAddNew = new Button();
        btnAddNew.addListener(new OnAddContainerMetadata(mainWindow, repositories, resourceProxy));
        btnAddNew.setStyleName(BaseTheme.BUTTON_LINK);
        btnAddNew.addStyleName("floatright paddingtop3");
        btnAddNew.setWidth("20px");
        btnAddNew.setIcon(ICON);
        cssLayout.addComponent(btnAddNew);
    }
    vl.addComponent(cssLayout);
    ContainerMetadataTable metadataTable = new ContainerMetadataTable(resourceProxy.getMetadataRecords(),
            containerController, router, resourceProxy, repositories);
    metadataTable.buildTable();
    vl.addComponent(metadataTable);
    vl.setComponentAlignment(metadataTable, Alignment.TOP_LEFT);
    vl.setExpandRatio(metadataTable, 0.9f);
    panel.setContent(vl);

    return panel;
}

From source file:org.escidoc.browser.ui.maincontent.ContextRightPanel.java

License:Open Source License

@SuppressWarnings("serial")
private Panel buildAdminDescription() {
    final Panel admDescriptors = new Panel();
    admDescriptors.setWidth("100%");
    admDescriptors.setHeight("100%");
    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();// w w w.  ja v a2  s .c  o m
    final CssLayout cssLayout = new CssLayout();
    buildPanelHeader(cssLayout, ViewConstants.ADMIN_DESCRIPTION);
    ThemeResource ICON = new ThemeResource("images/assets/plus.png");
    if (contextController.canUpdateContext()) {
        final Button addResourceButton = new Button();
        addResourceButton.setStyleName(BaseTheme.BUTTON_LINK);
        addResourceButton.addStyleName("floatright paddingtop3");
        addResourceButton.setWidth("20px");
        addResourceButton.setIcon(ICON);
        addResourceButton.addListener(new ClickListener() {
            @Override
            public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
                new OnContextAdminDescriptor(router, contextController).adminDescriptorForm();
            }
        });
        cssLayout.addComponent(addResourceButton);
    }
    vl.addComponent(cssLayout);

    VerticalLayout vl2 = new VerticalLayout();
    final AdminDescriptors admDesc = resourceProxy.getAdminDescription();
    final AdminDescriptorsTable adminDescriptorTable = new AdminDescriptorsTable(contextController, admDesc,
            router);
    adminDescriptorTable.buildTable();
    vl2.addComponent(adminDescriptorTable);
    vl.addComponent(vl2);
    vl.setExpandRatio(vl2, 9);
    admDescriptors.setContent(vl);
    return admDescriptors;
}