Example usage for com.vaadin.ui Button setIcon

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

Introduction

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

Prototype

@Override
public void setIcon(Resource icon) 

Source Link

Document

Sets the component's icon.

Usage

From source file:jp.primecloud.auto.ui.MyCloudManage.java

License:Open Source License

MyCloudManage(Application ap) {

    apl = ap;/*from w  w  w  .j  a  va2s  . c o  m*/
    //
    setIcon(Icons.EDITMINI.resource());

    setCaption(ViewProperties.getCaption("window.myCloudManage"));
    setModal(true);
    setWidth("550px");

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

    // ?
    HorizontalLayout tbar = new HorizontalLayout();
    tbar.setWidth("100%");
    tbar.setSpacing(true);

    // ?
    Label tcaption = new Label(ViewProperties.getCaption("table.cloud"));
    tcaption.setWidth("300px");
    tbar.addComponent(tcaption);
    tbar.setComponentAlignment(tcaption, Alignment.MIDDLE_LEFT);

    // Edit
    Button editButton = new Button(ViewProperties.getCaption("button.editCloud"));
    editButton.setDescription(ViewProperties.getCaption("description.editCloud"));
    editButton.setIcon(Icons.EDITMINI.resource());
    editButton.setWidth("85px");
    editButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            MyCloudManage.this.editButtonClick(event);
        }
    });
    tbar.addComponent(editButton);
    tbar.setComponentAlignment(editButton, Alignment.BOTTOM_RIGHT);

    // Delete
    Button deleteButton = new Button(ViewProperties.getCaption("button.delete"));
    deleteButton.setDescription(ViewProperties.getCaption("description.delete"));
    deleteButton.setWidth("85px");
    deleteButton.setIcon(Icons.DELETEMINI.resource());
    deleteButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {

            MyCloudManage.this.deleteButtonClick(event);
        }
    });
    tbar.addComponent(deleteButton);
    tbar.setComponentAlignment(deleteButton, Alignment.BOTTOM_RIGHT);
    tbar.setExpandRatio(tcaption, 10);
    layout.addComponent(tbar);

    // ?
    Label spacer1 = new Label("");
    spacer1.setHeight("5px");
    layout.addComponent(spacer1);

    // 
    cloudTable = new CloudTable();
    layout.addComponent(cloudTable);

    // ?
    Label spacer2 = new Label("");
    spacer2.setHeight("7px");
    layout.addComponent(spacer2);

    // ??
    HorizontalLayout bbar = new HorizontalLayout();
    bbar.setWidth("100%");
    HorizontalLayout rlay = new HorizontalLayout();
    rlay.setSpacing(true);

    // New
    Button addButton = new Button(ViewProperties.getCaption("button.newCloud"));
    addButton.setDescription(ViewProperties.getCaption("description.newCloud"));
    addButton.setIcon(Icons.ADD.resource());
    addButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            MyCloudManage.this.addButtonClick(event);
        }
    });
    bbar.addComponent(addButton);
    bbar.setComponentAlignment(addButton, Alignment.MIDDLE_LEFT);

    // Switch
    Button switchButton = new Button(ViewProperties.getCaption("button.switch"));
    switchButton.setDescription(ViewProperties.getCaption("description.mycloud.switch"));
    switchButton.setWidth("85px");
    switchButton.setIcon(Icons.SELECTMINI.resource());
    switchButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            MyCloudManage.this.switchButtonClick(event);
        }
    });
    // [Enter]?switchButton
    switchButton.setClickShortcut(KeyCode.ENTER);
    switchButton.focus();
    rlay.addComponent(switchButton);

    // Cancel
    Button cancelButton = new Button(ViewProperties.getCaption("button.cancel"));
    cancelButton.setDescription(ViewProperties.getCaption("description.cancel"));
    cancelButton.setWidth("85px");
    cancelButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            MyCloudManage.this.close();
        }
    });
    rlay.addComponent(cancelButton);

    bbar.addComponent(rlay);
    bbar.setComponentAlignment(rlay, Alignment.MIDDLE_RIGHT);

    layout.addComponent(bbar);

    // ???
    initData();

    //???/?
    if (ViewContext.getPowerUser()) {
        addButton.setEnabled(true);
        deleteButton.setEnabled(true);
        editButton.setEnabled(true);
        //??????????????
        if (ViewContext.getPowerUser()
                && !ViewContext.getPowerDefaultMaster().equals(ViewContext.getLoginUser())) {
            addButton.setEnabled(false);
        }

    } else if (ViewContext.getUserNo().equals(ViewContext.getLoginUser())) {
        addButton.setEnabled(true);
        deleteButton.setEnabled(true);
        editButton.setEnabled(true);
    } else {
        addButton.setEnabled(false);
        deleteButton.setEnabled(false);
        editButton.setEnabled(false);
    }

    // 
    showClouds();
}

From source file:jp.primecloud.auto.ui.ServerTable.java

License:Open Source License

public void setButtonStatus(Instance instance) {
    for (Entry<Long, List<Button>> entry : map.entrySet()) {
        Long key = entry.getKey();
        if (key.equals(instance.getInstanceNo())) {
            for (Button button : entry.getValue()) {
                if ("".equals(instance.getStatus())
                        || InstanceStatus.STOPPED.toString().equals(instance.getStatus())) {
                    if (("STOP".equals(button.getCaption()))) {
                        button.setEnabled(false);
                    } else if (("START".equals(button.getCaption()))) {
                        button.setIcon(Icons.PLAY.resource());
                        button.setDescription(ViewProperties.getCaption("description.startServer"));
                        button.setEnabled(true);
                    } else {
                        button.setEnabled(true);
                    }// ww  w  .j ava2 s .com
                } else if (InstanceStatus.RUNNING.toString().equals(instance.getStatus())) {
                    if (("STOP".equals(button.getCaption()))) {
                        button.setEnabled(true);
                    } else if (("START".equals(button.getCaption()))) {
                        button.setIcon(Icons.RELOAD.resource());
                        button.setDescription(ViewProperties.getCaption("description.reloadServer"));
                        button.setEnabled(true);
                    } else {
                        button.setEnabled(false);
                    }
                } else if (InstanceStatus.WARNING.toString().equals(instance.getStatus())) {
                    if (("STOP".equals(button.getCaption()))) {
                        button.setEnabled(true);
                    } else {
                        button.setEnabled(false);
                    }
                } else {
                    button.setEnabled(false);
                }
            }
        } else {
            for (Button button : entry.getValue()) {
                button.setEnabled(false);
            }
        }
    }
}

From source file:jp.primecloud.auto.ui.ServiceTable.java

License:Open Source License

Button getLoadBalancerButton(LoadBalancerDto lbDto) {
    Button btn = new Button();
    btn.setCaption(lbDto.getLoadBalancer().getLoadBalancerName());
    btn.setIcon(Icons.LOADBALANCER_TAB.resource());
    btn.setData(lbDto);//from ww  w. ja v a  2s. com
    btn.addStyleName("borderless");
    btn.addStyleName("loadbalancer-button");
    btn.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            loadBalancerButtonClick(event);
        }
    });
    return btn;
}

From source file:jp.primecloud.auto.ui.ServiceTable.java

License:Open Source License

public void setButtonStatus(ComponentDto dto) {
    //????????//from  w  ww.  ja  va2 s  . co m
    //  START,EDIT,STOP 
    // ? START,EDIT,DELETE 
    // ???
    // WARNINGEDIT,STOP 

    jp.primecloud.auto.entity.crud.Component component = dto.getComponent();
    for (Entry<Long, List<Button>> entry : map.entrySet()) {
        Long key = entry.getKey();
        if (key.equals(component.getComponentNo())) {
            for (Button button : entry.getValue()) {
                if ("".equals(dto.getStatus()) || "STOPPED".equals(dto.getStatus())) {
                    if (("STOP".equals(button.getCaption()))) {
                        button.setEnabled(false);
                    } else if (("START".equals(button.getCaption()))) {
                        button.setIcon(Icons.PLAY.resource());
                        button.setDescription(ViewProperties.getCaption("description.startService"));
                        button.setEnabled(true);
                    } else {
                        button.setEnabled(true);
                    }
                } else if ("RUNNING".equals(dto.getStatus())) {
                    if (("STOP".equals(button.getCaption()))) {
                        button.setEnabled(true);
                    } else if (("START".equals(button.getCaption()))) {
                        button.setIcon(Icons.RELOAD.resource());
                        button.setDescription(ViewProperties.getCaption("description.reloadService"));
                        button.setEnabled(true);
                    } else if (("EDIT".equals(button.getCaption()))) {
                        button.setEnabled(true);
                    } else {
                        button.setEnabled(false);
                    }
                } else if ("WARNING".equals(dto.getStatus())) {
                    if (("STOP".equals(button.getCaption()))) {
                        button.setEnabled(true);
                    } else if ("START".equals(button.getCaption())) {
                        button.setIcon(Icons.RELOAD.resource());
                        button.setDescription(ViewProperties.getCaption("description.reloadService"));
                        button.setEnabled(true);
                    } else if ("EDIT".equals(button.getCaption())) {
                        // ????????????
                        boolean processing = false;
                        for (ComponentInstanceDto componentInstance : dto.getComponentInstances()) {
                            ComponentInstanceStatus status = ComponentInstanceStatus
                                    .fromStatus(componentInstance.getComponentInstance().getStatus());
                            if (status != ComponentInstanceStatus.RUNNING
                                    && status != ComponentInstanceStatus.WARNING
                                    && status != ComponentInstanceStatus.STOPPED) {
                                processing = true;
                                break;
                            }
                        }
                        button.setEnabled(!processing);
                    } else {
                        button.setEnabled(false);
                    }
                } else {
                    button.setEnabled(false);
                }
            }
        } else {
            for (Button button : entry.getValue()) {
                button.setEnabled(false);
            }
        }
    }
}

From source file:jp.primecloud.auto.ui.TopBar.java

License:Open Source License

@Override
public void attach() {
    addStyleName("TopBar");
    setWidth("100%");
    setHeight("30px");
    setMargin(false, true, false, false);

    // PrimeCloud
    Label plbl = new Label(IconUtils.createImageTag(getApplication(), Icons.PCCLOGO), Label.CONTENT_XHTML);
    plbl.addStyleName("logo");
    addComponent(plbl);//from ww w.  ja  va2 s .co m

    // ??
    String versionProp = Config.getVersionProperty("version");
    if (StringUtils.isNotEmpty(versionProp)) {
        StringBuilder version = new StringBuilder();
        version.append("ver").append(versionProp);
        Label versionNo = new Label("<p>" + version.toString() + "</p>", Label.CONTENT_XHTML);
        versionNo.addStyleName("versionNo");
        addComponent(versionNo);
    } else {
        Label versionNo = new Label("<p></p>", Label.CONTENT_XHTML);
        versionNo.addStyleName("versionNoNone");
        addComponent(versionNo);
    }

    // myCloud?
    Button myCloudButton = new Button(ViewProperties.getCaption("button.myCloudManage"));
    myCloudButton.setDescription(ViewProperties.getCaption("description.myCloudManage"));
    myCloudButton.addStyleName("borderless");
    myCloudButton.addStyleName("mycloud");
    myCloudButton.setIcon(Icons.CLOUDBIG.resource());
    myCloudButton.setVisible(true);
    myCloudButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            showCloudEditWindow();
        }
    });
    addComponent(myCloudButton);

    // (Zabbix)
    String useZabbix = Config.getProperty("zabbix.useZabbix");
    if (useZabbix == null || BooleanUtils.toBoolean(useZabbix)) {
        String url = Config.getProperty("zabbix.display");
        Link zabbix = new Link(ViewProperties.getCaption("link.zabbix"), new ExternalResource(url));
        zabbix.setDescription(ViewProperties.getCaption("description.link.zabbix"));
        zabbix.setIcon(Icons.MNGSYSTEM.resource());
        zabbix.setTargetName("_blank");
        zabbix.addStyleName("zabbix");
        addComponent(zabbix);
    }

    // 
    Button eventLogButton = new Button(ViewProperties.getCaption("link.eventlog"));
    eventLogButton.setDescription(ViewProperties.getCaption("description.link.eventlog"));
    eventLogButton.addStyleName("borderless");
    eventLogButton.addStyleName("eventlog");
    eventLogButton.setIcon(Icons.CUSTOM.resource());
    eventLogButton.setVisible(true);
    eventLogButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            WinLogView window = new WinLogView();
            getApplication().addWindow(window);
            getApplication().getMainWindow().open(new ExternalResource(window.getURL()), "_blank");
        }
    });
    addComponent(eventLogButton);

    // 
    Boolean usePayment = BooleanUtils.toBooleanObject(Config.getProperty("payment.usePayment"));
    if (BooleanUtils.isTrue(usePayment)) {
        String url2 = Config.getProperty("payment.display");
        Link payment = new Link(ViewProperties.getCaption("link.payment"), new ExternalResource(url2));
        payment.setDescription(ViewProperties.getCaption("description.link.payment"));
        payment.setIcon(Icons.PAYSYSTEM.resource());
        payment.setTargetName("_payment");
        payment.addStyleName("payment");
        addComponent(payment);
    }

    // 
    Button logoutButton = new Button(ViewProperties.getCaption("button.logout"));
    logoutButton.setDescription(ViewProperties.getCaption("description.logout"));
    logoutButton.addStyleName("borderless");
    logoutButton.addStyleName("logout");
    logoutButton.setIcon(Icons.LOGOUT.resource());
    logoutButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.dialogConfirm"),
                    ViewMessages.getMessage("IUI-000001"), Buttons.OKCancel);
            Callback callback = new Callback() {
                @Override
                public void onDialogResult(Result result) {
                    if (result == Result.OK) {
                        // ?
                        LoggingUtils.removeContext();
                        ContextUtils.invalidateSession();
                        accountButton.setVisible(false);

                        // ????
                        getApplication().close();
                    }
                }
            };
            dialog.setCallback(callback);
            getApplication().getMainWindow().addWindow(dialog);
        }
    });
    addComponent(logoutButton);

    // ?
    accountButton = new Button(ViewProperties.getCaption("button.account"));
    accountButton.setDescription(ViewProperties.getCaption("description.account"));
    accountButton.addStyleName("borderless");
    accountButton.addStyleName("account");
    accountButton.setIcon(Icons.USER.resource());
    accountButton.setVisible(false);
    addComponent(accountButton);
}

From source file:life.qbic.components.OfferGeneratorTab.java

License:Open Source License

/**
 * creates the tab to generate the offers with the respective packages
 * @return vaadin component holding the offer generator
 *//*from w  w  w  .j a va  2 s.  c  om*/
static Component createOfferGeneratorTab() {

    Database db = qOfferManager.getDb();
    TabSheet managerTabs = qOfferManager.getManagerTabs();

    ComboBox selectedProjectComboBox = new ComboBox("Select Project");
    selectedProjectComboBox.setInputPrompt("No project selected!");
    selectedProjectComboBox.setDescription("Please select a project before its too late! :P");
    selectedProjectComboBox.addItems(db.getProjects());
    selectedProjectComboBox.setWidth("300px");

    Button completeButton = new Button("Complete");
    completeButton.setDescription("Click here to finalize the offer and save it into the DB!");
    completeButton.setIcon(FontAwesome.CHECK_CIRCLE);
    completeButton.setEnabled(false);

    // get the package ids and names as a bean container
    final BeanItemContainer<String> packageIdsAndNamesContainer = new BeanItemContainer<>(String.class);
    packageIdsAndNamesContainer.addAll(db.getPackageIdsAndNames());

    TwinColSelect selectPackagesTwinColSelect = new TwinColSelect();
    selectPackagesTwinColSelect.setContainerDataSource(packageIdsAndNamesContainer);
    selectPackagesTwinColSelect.setLeftColumnCaption("Available packages");
    selectPackagesTwinColSelect.setRightColumnCaption("Selected packages");
    selectPackagesTwinColSelect.setSizeFull();

    // text field which functions as a filter for the left side of the twin column select
    TextField twinColSelectFilter = new TextField();
    twinColSelectFilter.setCaption("Filter available packages");
    twinColSelectFilter.addTextChangeListener((FieldEvents.TextChangeListener) event -> {
        packageIdsAndNamesContainer.removeAllContainerFilters();
        packageIdsAndNamesContainer.addContainerFilter(new Container.Filter() {

            @Override
            public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
                return ((String) itemId).toLowerCase().contains(event.getText().toLowerCase())
                        || ((Collection) selectPackagesTwinColSelect.getValue()).contains(itemId);
            }

            @Override
            public boolean appliesToProperty(Object propertyId) {
                return true;
            }
        });
    });

    VerticalLayout right = new VerticalLayout();
    right.setSpacing(true);
    right.setMargin(true);

    VerticalLayout addPackLayout = new VerticalLayout();
    addPackLayout.setMargin(true);
    addPackLayout.setSpacing(true);

    Panel packageDescriptionPanel = new Panel("Package Details");
    packageDescriptionPanel.setContent(right);

    @SuppressWarnings("deprecation")
    Label packageDetailsLabel = new Label("Package details will appear here!", Label.CONTENT_XHTML);
    packageDetailsLabel.addStyleName(ValoTheme.LABEL_BOLD);
    right.addComponent(packageDetailsLabel);

    addListeners(db, managerTabs, selectedProjectComboBox, completeButton, addPackLayout,
            selectPackagesTwinColSelect, packageDescriptionPanel, packageDetailsLabel, twinColSelectFilter);

    addPackLayout.addComponent(selectedProjectComboBox);

    return addPackLayout;
}

From source file:life.qbic.components.OfferManagerTab.java

License:Open Source License

/**
 * creates the tab for displaying and modifying the offers in a vaadin grid
 * @return vaadin component//from ww w  .j a  va 2 s.com
 * @throws SQLException:
 */
static Component createOfferManagerTab() throws SQLException {

    Database db = qOfferManager.getDb();

    VerticalLayout offerManLayout = new VerticalLayout();
    HorizontalLayout editSettingsLayout = new HorizontalLayout();
    detailsLayout = new VerticalLayout();

    editSettingsLayout.setSpacing(true);
    detailsLayout.setSizeFull();

    ComboBox updateStatus = new ComboBox("Select Status");
    updateStatus.addItem("In Progress");
    updateStatus.addItem("Sent");
    updateStatus.addItem("Accepted");
    updateStatus.addItem("Rejected");

    Button updateButton = new Button("Update");
    updateButton.setIcon(FontAwesome.SPINNER);
    updateButton.setDescription("Click here to update the currently selected offer.");

    Button deleteOfferButton = new Button("Delete");
    deleteOfferButton.setIcon(FontAwesome.TRASH_O);
    deleteOfferButton.setDescription("Click here to delete the currently selected offer.");

    packageGroupComboBox = new ComboBox("Select package group");
    packageGroupComboBox.addItems("All", "Bioinformatics Analysis", "Mass spectrometry", "Project Management",
            "Sequencing", "Other");
    packageGroupComboBox.setValue("All");
    packageGroupComboBox.setNullSelectionAllowed(false);
    packageGroupComboBox
            .setDescription("Click here to select the package group for the packages displayed below.");

    Button exportTableButton = new Button("Export as .csv");
    exportTableButton.setIcon(FontAwesome.DOWNLOAD);
    exportTableButton.setDescription("Click here to export the table as .csv file.");

    editSettingsLayout.addComponent(updateStatus);
    editSettingsLayout.addComponent(updateButton);
    editSettingsLayout.addComponent(deleteOfferButton);
    editSettingsLayout.addComponent(packageGroupComboBox);
    editSettingsLayout.addComponent(exportTableButton);

    editSettingsLayout.setComponentAlignment(updateButton, Alignment.BOTTOM_CENTER);
    editSettingsLayout.setComponentAlignment(deleteOfferButton, Alignment.BOTTOM_CENTER);
    editSettingsLayout.setComponentAlignment(packageGroupComboBox, Alignment.BOTTOM_CENTER);
    editSettingsLayout.setComponentAlignment(exportTableButton, Alignment.BOTTOM_CENTER);

    Button generateOfferButton = new Button("Download offer");
    generateOfferButton.setIcon(FontAwesome.DOWNLOAD);
    generateOfferButton
            .setDescription("Select an offer from the grid then click here to download it as .docx!");
    generateOfferButton.setEnabled(false);

    offerManLayout.setMargin(true);
    offerManLayout.setSpacing(true);
    offerManLayout.setSizeFull();

    TableQuery tq = new TableQuery("offers", DBManager.getDatabaseInstanceAlternative());
    tq.setVersionColumn("OPTLOCK");
    SQLContainer container = new SQLContainer(tq);
    container.setAutoCommit(true);

    offerManagerGrid = new RefreshableGrid(container);

    // add the filters to the grid
    GridCellFilter filter = new GridCellFilter(offerManagerGrid);
    filter.setTextFilter("offer_id", true, true);
    filter.setTextFilter("offer_number", true, false);
    filter.setTextFilter("offer_project_reference", true, false);
    filter.setTextFilter("offer_facility", true, false);
    filter.setTextFilter("offer_name", true, false);
    filter.setTextFilter("offer_description", true, false);
    filter.setDateFilter("offer_date");
    filter.setDateFilter("last_edited");
    filter.setComboBoxFilter("offer_status", Arrays.asList("In Progress", "Sent", "Accepted", "Rejected"));

    offerManagerGrid.setSelectionMode(Grid.SelectionMode.SINGLE);

    addListeners(db, updateStatus, updateButton, deleteOfferButton, generateOfferButton, container,
            exportTableButton);

    offerManagerGrid.getColumn("offer_id").setHeaderCaption("Id").setWidth(100).setEditable(false);
    offerManagerGrid.getColumn("offer_number").setHeaderCaption("Quotation Number").setWidth(200)
            .setEditable(false);
    offerManagerGrid.getColumn("offer_project_reference").setHeaderCaption("Project Reference")
            .setEditable(false);
    offerManagerGrid.getColumn("offer_name").setHeaderCaption("Offer Name").setWidth(200);
    offerManagerGrid.getColumn("offer_facility").setHeaderCaption("Prospect");
    offerManagerGrid.getColumn("offer_description").setHeaderCaption("Description").setWidth(300);
    offerManagerGrid.getColumn("offer_total").setHeaderCaption("Price ()").setEditable(false);
    offerManagerGrid.getColumn("offer_status").setHeaderCaption("Status").setEditable(false);
    offerManagerGrid.getColumn("offer_date").setHeaderCaption("Date").setEditable(false);
    offerManagerGrid.getColumn("last_edited").setHeaderCaption("Last edited").setEditable(false);
    offerManagerGrid.getColumn("added_by").setHeaderCaption("Added by").setEditable(false);

    offerManagerGrid.setColumnOrder("offer_id", "offer_project_reference", "offer_number", "offer_name",
            "offer_description", "offer_total", "offer_facility", "offer_status", "offer_date", "last_edited",
            "added_by");

    offerManagerGrid.removeColumn("discount");
    offerManagerGrid.removeColumn("internal");
    offerManagerGrid.removeColumn("offer_group");
    offerManagerGrid.removeColumn("offer_extra_price");
    offerManagerGrid.removeColumn("offer_price");

    offerManagerGrid.sort("offer_date", SortDirection.DESCENDING);
    offerManagerGrid.setWidth("100%");
    offerManagerGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
    offerManagerGrid.setEditorEnabled(true);

    // add tooltips to the cells
    offerManagerGrid.setCellDescriptionGenerator((Grid.CellDescriptionGenerator) cell -> {
        if (cell.getValue() == null)
            return null;
        return cell.getValue().toString();
    });

    // add tooltips to the header row
    for (Grid.Column column : offerManagerGrid.getColumns()) {
        Grid.HeaderCell cell = offerManagerGrid.getDefaultHeaderRow().getCell(column.getPropertyId());
        String htmlWithTooltip = String.format("<span title=\"%s\">%s</span>", cell.getText(), cell.getText());
        cell.setHtml(htmlWithTooltip);
    }

    offerManLayout.addComponent(offerManagerGrid);
    offerManLayout.addComponent(editSettingsLayout);
    offerManLayout.addComponent(detailsLayout);
    offerManLayout.addComponent(generateOfferButton);

    return offerManLayout;
}

From source file:life.qbic.components.OfferManagerTabPackageComponent.java

License:Open Source License

/**
 * creates the component showing the packages of the respective package type of the currently selected offer in a
 * grid and enables the user to add and remove packages from the offer
 * @param offerGridContainer: sql container of all the offers
 * @param selectedOfferID: id of the currently selected offer
 * @param packagesType: type of the packages: "All", "Bioinformatics Analysis", "Project Management", "Sequencing",
 *                    "Mass spectrometry", "Other"; what type of packages the grid should display
 * @return vaadin component// w w  w  .  ja v a  2s .c  o  m
 * @throws SQLException :
 */
static Component createOfferManagerTabPackageComponent(SQLContainer offerGridContainer, String selectedOfferID,
        String packagesType) throws SQLException {

    Database db = qOfferManager.getDb();

    VerticalLayout packQuantityLayout = new VerticalLayout();
    packQuantityLayout.setMargin(true);
    packQuantityLayout.setSpacing(true);
    packQuantityLayout.setSizeFull();
    HorizontalLayout packSettingsLayout = new HorizontalLayout();

    ComboBox packageQuantityComboBox = new ComboBox("Select Quantity");

    for (int i = 1; i <= 1000; i++)
        packageQuantityComboBox.addItem(i);

    Button updateQuantityButton = new Button("Update quantity");
    updateQuantityButton.setIcon(FontAwesome.SPINNER);
    updateQuantityButton.setDescription("Updates the quantity of the current package.");

    Button removePackageButton = new Button("Remove");
    removePackageButton.setIcon(FontAwesome.TRASH_O);
    removePackageButton.setDescription("Removes the selected package from the current offer.");

    // we are only displaying the packages for the current package group
    ComboBox packagesAvailableForOfferComboBox = new ComboBox("Select package to add");
    packagesAvailableForOfferComboBox.setFilteringMode(FilteringMode.CONTAINS);

    String selectedPackageGroup = OfferManagerTab.getPackageGroupComboBoxValue();
    if (selectedPackageGroup.equals("All")) {
        packagesAvailableForOfferComboBox.addItems(db.getPackageIdsAndNames());
    } else {
        packagesAvailableForOfferComboBox.addItems(db.getPackageIdsAndNames(selectedPackageGroup));
    }

    Button addPackageButton = new Button("Add");
    addPackageButton.setIcon(FontAwesome.PLUS);
    addPackageButton.setDescription("Adds a package to the current offer.");

    ComboBox externalInternalPriceComboBox = new ComboBox("External/Internal Price");
    externalInternalPriceComboBox
            .setDescription("Select here whether the internal, the external academical or the "
                    + "external commercial price should be used for the current selected package.");
    externalInternalPriceComboBox.addItems("Internal", "External academic", "External commercial");

    Button externalInternalButton = new Button("Update price type");
    externalInternalButton.setIcon(FontAwesome.SPINNER);
    externalInternalButton.setDescription(
            "Updates the package price type (internal/external academic/external " + "commercial) to use.");

    packSettingsLayout.addComponent(packageQuantityComboBox);
    packSettingsLayout.addComponent(updateQuantityButton);
    packSettingsLayout.addComponent(removePackageButton);
    packSettingsLayout.addComponent(packagesAvailableForOfferComboBox);
    packSettingsLayout.addComponent(addPackageButton);
    packSettingsLayout.addComponent(externalInternalPriceComboBox);
    packSettingsLayout.addComponent(externalInternalButton);

    packSettingsLayout.setComponentAlignment(updateQuantityButton, Alignment.BOTTOM_CENTER);
    packSettingsLayout.setComponentAlignment(removePackageButton, Alignment.BOTTOM_CENTER);
    packSettingsLayout.setComponentAlignment(addPackageButton, Alignment.BOTTOM_CENTER);
    packSettingsLayout.setComponentAlignment(externalInternalPriceComboBox, Alignment.MIDDLE_CENTER);
    packSettingsLayout.setComponentAlignment(externalInternalButton, Alignment.BOTTOM_CENTER);

    packSettingsLayout.setSpacing(true);

    // we need different freeform queries if 'All' package groups are selected or e.g. only 'Bioinformatics' package groups
    String freeformQueryString = "SELECT * " + "FROM offers "
            + "INNER JOIN offers_packages ON offers.`offer_id` = offers_packages.`offer_id` "
            + "INNER JOIN packages ON packages.`package_id` = offers_packages.`package_id`"
            + "WHERE offers.offer_id = " + selectedOfferID + " AND packages.`package_group` = '" + packagesType
            + "'";
    if (Objects.equals(packagesType, "All")) {
        freeformQueryString = "SELECT * " + "FROM offers "
                + "INNER JOIN offers_packages ON offers.`offer_id` = offers_packages.`offer_id` "
                + "INNER JOIN packages ON packages.`package_id` = offers_packages.`package_id`"
                + "WHERE offers.offer_id = " + selectedOfferID;
    }

    FreeformQuery query = new FreeformQuery(freeformQueryString, DBManager.getDatabaseInstanceAlternative());

    SQLContainer packsContainer = new SQLContainer(query);
    packsContainer.setAutoCommit(true);

    selectedPacksInOfferGrid = new RefreshableGrid(packsContainer);

    // add tooltips to the cells
    selectedPacksInOfferGrid.setCellDescriptionGenerator((Grid.CellDescriptionGenerator) cell -> {
        if (cell.getValue() == null)
            return null;
        return cell.getValue().toString();
    });

    // update the array lists holding the information about the packages of the current offer
    updatePackageArrays(packsContainer);

    addListeners(offerGridContainer, selectedOfferID, db, packageQuantityComboBox, updateQuantityButton,
            removePackageButton, packagesAvailableForOfferComboBox, addPackageButton, packsContainer,
            externalInternalPriceComboBox, externalInternalButton);

    // remove unimportant columns from the grid
    selectedPacksInOfferGrid.removeColumn("offer_id");
    selectedPacksInOfferGrid.removeColumn("offer_number");
    selectedPacksInOfferGrid.removeColumn("offer_project_reference");
    selectedPacksInOfferGrid.removeColumn("offer_facility");
    selectedPacksInOfferGrid.removeColumn("offer_name");
    selectedPacksInOfferGrid.removeColumn("offer_description");
    selectedPacksInOfferGrid.removeColumn("offer_group");
    selectedPacksInOfferGrid.removeColumn("offer_price");
    selectedPacksInOfferGrid.removeColumn("offer_extra_price");
    selectedPacksInOfferGrid.removeColumn("offer_total");
    selectedPacksInOfferGrid.removeColumn("offer_date");
    selectedPacksInOfferGrid.removeColumn("offer_status");
    selectedPacksInOfferGrid.removeColumn("last_edited");
    selectedPacksInOfferGrid.removeColumn("added_by");
    selectedPacksInOfferGrid.removeColumn("package_date");
    selectedPacksInOfferGrid.removeColumn("discount");
    selectedPacksInOfferGrid.removeColumn("internal");
    selectedPacksInOfferGrid.removeColumn("package_grp");

    // rename the header caption
    selectedPacksInOfferGrid.getColumn("package_id").setHeaderCaption("Id");
    selectedPacksInOfferGrid.getColumn("package_addon_price").setHeaderCaption("Package total price ()");
    selectedPacksInOfferGrid.getColumn("package_count").setHeaderCaption("Quantity");
    selectedPacksInOfferGrid.getColumn("package_discount").setHeaderCaption("Discount");
    selectedPacksInOfferGrid.getColumn("package_name").setHeaderCaption("Package Name").setWidth(200);
    selectedPacksInOfferGrid.getColumn("package_facility").setHeaderCaption("Package Facility");
    selectedPacksInOfferGrid.getColumn("package_description").setHeaderCaption("Description").setWidth(300);
    selectedPacksInOfferGrid.getColumn("package_group").setHeaderCaption("Group");
    selectedPacksInOfferGrid.getColumn("package_price_internal").setHeaderCaption("Internal base price ()");
    selectedPacksInOfferGrid.getColumn("package_price_external_academic")
            .setHeaderCaption("External academic base price ()");
    selectedPacksInOfferGrid.getColumn("package_price_external_commercial")
            .setHeaderCaption("External commercial base price ()");
    selectedPacksInOfferGrid.getColumn("package_unit_type").setHeaderCaption("Unit Type");
    selectedPacksInOfferGrid.getColumn("package_price_type").setHeaderCaption("Package price type");

    selectedPacksInOfferGrid.setColumnOrder("package_id", "package_name", "package_description",
            "package_addon_price", "package_count", "package_discount", "package_group", "package_facility",
            "package_price_internal", "package_price_external_academic", "package_price_external_commercial",
            "package_price_type", "package_unit_type");

    // we don't want the packages to be be editable, because this would change the package in other offers as well
    selectedPacksInOfferGrid.setEditorEnabled(false);
    selectedPacksInOfferGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
    selectedPacksInOfferGrid.setWidth("100%");

    // label showing the packages group currently displayed (e.g. "All", "Project Management", etc.)
    Label packagesGroupLabel = new Label("<b><u>" + packagesType + ":</u></b>", ContentMode.HTML);
    packQuantityLayout.addComponent(packagesGroupLabel);
    packQuantityLayout.addComponent(selectedPacksInOfferGrid);
    packQuantityLayout.addComponent(packSettingsLayout);

    return packQuantityLayout;
}

From source file:life.qbic.components.PackageManagerTab.java

License:Open Source License

/**
 * creates the tab for creating new packages
 * @return vaadin component// w w w.  j  a va 2s  .  c o m
 * @throws SQLException:
 */
static Component createPackageManagerTab() throws SQLException {

    Database db = qOfferManager.getDb();

    VerticalLayout packManVerticalLayout = new VerticalLayout();
    packManVerticalLayout.setMargin(true);
    packManVerticalLayout.setSpacing(true);
    packManVerticalLayout.setSizeFull();

    HorizontalLayout packManHorizontalLayout = new HorizontalLayout();
    packManHorizontalLayout.setSpacing(true);

    Button addPackageButton = new Button("New Package");
    addPackageButton.setIcon(FontAwesome.PLUS);
    addPackageButton.setDescription("Click here to add a new package but don't forget to update the details.");

    ComboBox updatePackageGroupComboBox = new ComboBox("Select package group");
    updatePackageGroupComboBox.addItems("Sequencing", "Project Management", "Bioinformatics Analysis",
            "Mass spectrometry", "Other");
    updatePackageGroupComboBox.setDescription(
            "Select a package group for the currently selected package and hit the " + "update button.");

    Button updateSelectedPackageButton = new Button("Update");
    updateSelectedPackageButton.setIcon(FontAwesome.SPINNER);
    updateSelectedPackageButton.setDescription("Click here to update the currently selected package.");

    Button deleteSelectedPackageButton = new Button("Delete");
    deleteSelectedPackageButton.setIcon(FontAwesome.TRASH_O);
    deleteSelectedPackageButton.setDescription("Click here to delete the currently selected package.");

    Button exportTableButton = new Button("Export as .csv");
    exportTableButton.setIcon(FontAwesome.DOWNLOAD);
    exportTableButton.setDescription("Click here to export the table as .csv file.");

    CheckBox calculatePricesAutomaticallyCheckBox = new CheckBox("Auto-calculate external prices");
    calculatePricesAutomaticallyCheckBox
            .setDescription("Click here to enable/disable the automatic calculation of the "
                    + "external prices based on the internal prices.");
    calculatePricesAutomaticallyCheckBox.setValue(true);

    TableQuery tq = new TableQuery("packages", DBManager.getDatabaseInstanceAlternative());
    tq.setVersionColumn("OPTLOCK");

    SQLContainer container = new SQLContainer(tq);
    container.setAutoCommit(true);

    GeneratedPropertyContainer gpcontainer = new GeneratedPropertyContainer(container);

    // create the column holding the offer_ids where the package is being used in
    // TODO: offer_ids currently not in use; since it's extremely slow..
    /*
        gpcontainer.addGeneratedProperty("offer_ids",
            new PropertyValueGenerator<String>() {
              @Override
              public String getValue(Item item, Object itemId,
                         Object propertyId) {
            
    int package_id = (Integer) item.getItemProperty("package_id").getValue();
            
    // query offers_packages for all offer_ids of the current package
    ArrayList<String> offerIds = db.getOfferIdsForPackage(package_id);
            
    return String.join(",", offerIds);
              }
            
              @Override
              public Class<String> getType() {
    return String.class;
              }
            });
    */

    RefreshableGrid packageGrid = new RefreshableGrid(gpcontainer);

    // add the filters to the grid
    GridCellFilter filter = new GridCellFilter(packageGrid);
    filter.setTextFilter("package_id", true, true);
    filter.setTextFilter("package_name", true, false);
    filter.setTextFilter("package_facility", true, false);
    filter.setTextFilter("package_description", true, false);
    filter.setTextFilter("package_group", true, false);
    filter.setTextFilter("package_unit_type", true, false);
    filter.setComboBoxFilter("package_group", Arrays.asList("Bioinformatics Analysis", "Mass spectrometry",
            "Project Management", "Sequencing", "Other"));

    packageGrid.getColumn("package_id").setHeaderCaption("Id").setWidth(100);
    packageGrid.getColumn("package_name").setHeaderCaption("Name");
    packageGrid.getColumn("package_facility").setHeaderCaption("Facility");
    packageGrid.getColumn("package_description").setHeaderCaption("Description").setWidth(300);
    packageGrid.getColumn("package_group").setHeaderCaption("Package Group").setEditable(false);
    packageGrid.getColumn("package_price_internal").setHeaderCaption("Internal Price ()");
    packageGrid.getColumn("package_price_external_academic").setHeaderCaption("Ext. Academical Price ()");
    packageGrid.getColumn("package_price_external_commercial").setHeaderCaption("Ext. Commercial Price ()");
    // TODO: offer_ids currently not in use; since it's extremely slow..
    //packageGrid.getColumn("offer_ids").setHeaderCaption("Offer Id's");
    packageGrid.getColumn("package_unit_type").setHeaderCaption("Unit Type");

    /*
    // TODO: offer_ids currently not in use; since it's extremely slow..
    packageGrid.setColumnOrder("package_id", "package_name", "package_description", "package_group", "package_facility",
        "package_price_internal", "package_price_external_academic", "package_price_external_commercial",
        "package_unit_type", "offer_ids");*/

    packageGrid.setColumnOrder("package_id", "package_name", "package_description", "package_group",
            "package_facility", "package_price_internal", "package_price_external_academic",
            "package_price_external_commercial", "package_unit_type");

    packageGrid.removeColumn("added_by");
    packageGrid.removeColumn("package_grp");
    packageGrid.removeColumn("package_date");
    packageGrid.removeColumn("last_edited");

    packageGrid.sort("package_name", SortDirection.ASCENDING);
    packageGrid.setWidth("100%");
    packageGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
    packageGrid.setEditorEnabled(true);

    addAutomaticPriceCalculation(calculatePricesAutomaticallyCheckBox, container, packageGrid);

    // add tooltips to the cells
    packageGrid.setCellDescriptionGenerator((Grid.CellDescriptionGenerator) cell -> {
        if (cell.getValue() == null)
            return null;
        return cell.getValue().toString();
    });

    // add tooltips to the header row
    for (Grid.Column column : packageGrid.getColumns()) {
        Grid.HeaderCell cell = packageGrid.getDefaultHeaderRow().getCell(column.getPropertyId());
        String htmlWithTooltip = String.format("<span title=\"%s\">%s</span>", cell.getText(), cell.getText());
        cell.setHtml(htmlWithTooltip);
    }

    addListeners(db, addPackageButton, updatePackageGroupComboBox, updateSelectedPackageButton,
            deleteSelectedPackageButton, container, packageGrid, exportTableButton);

    packManHorizontalLayout.addComponent(addPackageButton);
    packManHorizontalLayout.addComponent(updatePackageGroupComboBox);
    packManHorizontalLayout.addComponent(updateSelectedPackageButton);
    packManHorizontalLayout.addComponent(deleteSelectedPackageButton);
    packManHorizontalLayout.addComponent(exportTableButton);
    packManHorizontalLayout.addComponent(calculatePricesAutomaticallyCheckBox);

    packManHorizontalLayout.setComponentAlignment(addPackageButton, Alignment.BOTTOM_CENTER);
    packManHorizontalLayout.setComponentAlignment(updatePackageGroupComboBox, Alignment.MIDDLE_CENTER);
    packManHorizontalLayout.setComponentAlignment(updateSelectedPackageButton, Alignment.BOTTOM_CENTER);
    packManHorizontalLayout.setComponentAlignment(deleteSelectedPackageButton, Alignment.BOTTOM_CENTER);
    packManHorizontalLayout.setComponentAlignment(calculatePricesAutomaticallyCheckBox,
            Alignment.MIDDLE_CENTER);
    packManHorizontalLayout.setComponentAlignment(exportTableButton, Alignment.BOTTOM_CENTER);

    packManVerticalLayout.addComponent(packageGrid);
    packManVerticalLayout.addComponent(packManHorizontalLayout);

    return packManVerticalLayout;
}

From source file:lv.polarisit.demosidemenu.ValoThemeUI.java

License:Apache License

CssLayout buildMenu() {
    // Add items/*from   w  w  w. java2  s  .  c o m*/
    menuItems.put("MessageView", "First Message");
    menuItems.put("MessageView1", "Second Message");
    /*
    menuItems.put("labels", "Labels");
    menuItems.put("buttons-and-links", "Buttons & Links");
    menuItems.put("textfields", "Text Fields");
    menuItems.put("datefields", "Date Fields");
    menuItems.put("comboboxes", "Combo Boxes");
    menuItems.put("selects", "Selects");
    menuItems.put("checkboxes", "Check Boxes & Option Groups");
    menuItems.put("sliders", "Sliders & Progress Bars");
    menuItems.put("colorpickers", "Color Pickers");
    menuItems.put("menubars", "Menu Bars");
    menuItems.put("trees", "Trees");
    menuItems.put("tables", "Tables");
    menuItems.put("dragging", "Drag and Drop");
    menuItems.put("panels", "Panels");
    menuItems.put("splitpanels", "Split Panels");
    menuItems.put("tabs", "Tabs");
    menuItems.put("accordions", "Accordions");
    menuItems.put("popupviews", "Popup Views");
    // menuItems.put("calendar", "Calendar");
    menuItems.put("forms", "Forms");
    */
    final HorizontalLayout top = new HorizontalLayout();
    top.setWidth("100%");
    top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    top.addStyleName("valo-menu-title");
    menu.addComponent(top);
    menu.addComponent(createThemeSelect());

    final Button showMenu = new Button("Menu", new ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            if (menu.getStyleName().contains("valo-menu-visible")) {
                menu.removeStyleName("valo-menu-visible");
            } else {
                menu.addStyleName("valo-menu-visible");
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(ValoTheme.BUTTON_SMALL);
    showMenu.addStyleName("valo-menu-toggle");
    showMenu.setIcon(FontAwesome.LIST);
    menu.addComponent(showMenu);

    final Label title = new Label("<h3>Vaadin <strong>Valo Theme</strong></h3>", ContentMode.HTML);
    title.setSizeUndefined();
    top.addComponent(title);
    top.setExpandRatio(title, 1);

    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");
    /*
    final StringGenerator sg = new StringGenerator();
    final MenuItem settingsItem = settings.addItem(sg.nextString(true)
        + " " + sg.nextString(true) + sg.nextString(false),
        new ThemeResource("../tests-valo/img/profile-pic-300px.jpg"),
        null);
            
    settingsItem.addItem("Edit Profile", null);
    settingsItem.addItem("Preferences", null);
    settingsItem.addSeparator();
    settingsItem.addItem("Sign Out", null);
                */
    menu.addComponent(settings);

    menuItemsLayout.setPrimaryStyleName("valo-menuitems");
    menu.addComponent(menuItemsLayout);

    Label label = null;
    int count = -1;
    for (final Entry<String, String> item : menuItems.entrySet()) {
        if (item.getKey().equals("labels")) {
            label = new Label("Components", ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);
        }
        if (item.getKey().equals("panels")) {
            label.setValue(label.getValue() + " <span class=\"valo-menu-badge\">" + count + "</span>");
            count = 0;
            label = new Label("Containers", ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);
        }
        if (item.getKey().equals("forms")) {
            label.setValue(label.getValue() + " <span class=\"valo-menu-badge\">" + count + "</span>");
            count = 0;
            label = new Label("Other", ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);
        }
        final Button b = new Button(item.getValue(), new ClickListener() {
            @Override
            public void buttonClick(final ClickEvent event) {
                navigator.navigateTo(item.getKey());
            }
        });
        if (count == 2) {
            b.setCaption(b.getCaption() + " <span class=\"valo-menu-badge\">123</span>");
        }
        b.setHtmlContentAllowed(true);
        b.setPrimaryStyleName("valo-menu-item");
        //            b.setIcon(testIcon.get());
        menuItemsLayout.addComponent(b);
        count++;
    }
    if (label != null)
        label.setValue(label.getValue() + " <span class=\"valo-menu-badge\">" + count + "</span>");

    return menu;
}