List of usage examples for com.vaadin.ui Button setEnabled
@Override public void setEnabled(boolean enabled)
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 *//* w w w. j a v a 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.OfferGeneratorTab.java
License:Open Source License
/** * adds all the listeners to the offer generator tab * @param db: database instance to query * @param managerTabs: TabSheet holding the three tabs (Offer Generator, Offer Manager and Package Manager) * @param selectedProjectComboBox: ComboBox for selecting the project for the offer to generate * @param completeButton: button to complete the offer * @param addPackLayout: vertical layout which holds the twin select for selecting the packages, the package * description panel and the button to complete the offer * @param selectPackagesTwinColSelect: TwinSelect to select the packages for the current offer * @param packageDescriptionPanel: panel holding the descriptions labels for the selected packages * @param packageDescriptionLabel: label holding the description for the packages * @param twinColSelectFilter: text field for filtering the left side of the TwinColSelect *//* w w w . j av a 2s. c o m*/ private static void addListeners(Database db, TabSheet managerTabs, ComboBox selectedProjectComboBox, Button completeButton, VerticalLayout addPackLayout, TwinColSelect selectPackagesTwinColSelect, Panel packageDescriptionPanel, Label packageDescriptionLabel, TextField twinColSelectFilter) { final float[] totalPrice = new float[1]; final String[] descriptionText = new String[1]; final String[][] offerGeneratorPackageNames = new String[1][1]; final String[][] offerGeneratorPackageIds = new String[1][1]; selectedProjectComboBox.addValueChangeListener(new Property.ValueChangeListener() { /** * */ private static final long serialVersionUID = 6871999698387032993L; @Override public void valueChange(Property.ValueChangeEvent event) { if (selectedProjectComboBox.getValue() == null) { displayNotification("oO! No project selected!", "Please select a project to proceed, otherwise we are going to have a situation here! ;)", "error"); } else { addPackLayout.addComponent(twinColSelectFilter); addPackLayout.addComponent(selectPackagesTwinColSelect); addPackLayout.addComponent(packageDescriptionPanel); addPackLayout.addComponent(completeButton); } } }); selectPackagesTwinColSelect.addValueChangeListener(new Property.ValueChangeListener() { /** * */ private static final long serialVersionUID = -5813954665588509117L; @Override public void valueChange(Property.ValueChangeEvent event) { // get the packages (package_id: package_name) as comma separated string and remove the leading and trailing bracket String selectedPackages = selectPackagesTwinColSelect.getValue().toString().substring(1); selectedPackages = selectedPackages.substring(0, selectedPackages.length() - 1); // in case there is no package selected, we do nothing if (selectedPackages.length() == 0) { return; } // init the arrays holding the package names and package ids offerGeneratorPackageNames[0] = selectedPackages.split(","); offerGeneratorPackageIds[0] = selectedPackages.split(","); // split the package id and the package name for (int i = 0; i < offerGeneratorPackageNames[0].length; i++) { offerGeneratorPackageIds[0][i] = offerGeneratorPackageIds[0][i].split(": ", 2)[0]; offerGeneratorPackageNames[0][i] = offerGeneratorPackageNames[0][i].split(": ", 2)[1]; } // TODO: value change listener does not trigger if the last element from the twin col select gets deselected System.out.println("packages in twin col select:"); System.out.println(selectPackagesTwinColSelect.getValue()); // there is a package for the current project, so we enable the complete offer button if (selectPackagesTwinColSelect.getValue() != null) { completeButton.setEnabled(true); } else { completeButton.setEnabled(false); } assert offerGeneratorPackageNames[0].length == offerGeneratorPackageIds[0].length; // iterate over all of the packages for the current offer and add their price and description to the view descriptionText[0] = ""; totalPrice[0] = 0; for (int i = 0; i < offerGeneratorPackageNames[0].length; i++) { int currentPackageId = Integer.valueOf(offerGeneratorPackageIds[0][i].trim()); // calculate the total offer price try { totalPrice[0] += Float.parseFloat(db.getPriceFromPackageId(currentPackageId, "internal")); } catch (NullPointerException e) { displayNotification("Package price is null!", "The package price of the package " + offerGeneratorPackageIds[0][i] + ": " + offerGeneratorPackageNames[0][i] + " is null. Please remove the " + "package from the offer or update the " + "package price on the package manager tab. Otherwise " + "bad stuff is expected to happen..", "error"); } // get the description for the current package descriptionText[0] = descriptionText[0] + "<tr><td><p><b>" + offerGeneratorPackageIds[0][i] + ": " + offerGeneratorPackageNames[0][i] + "</b><br>" + db.getPackageDescriptionFromPackageId(currentPackageId) + "</td><td align='right' valign='top'>" + db.getPriceFromPackageId(currentPackageId, "internal") + "</td>" + "</p></tr>"; // add the description and the total price to the view if (offerGeneratorPackageNames[0][i].length() != 0) packageDescriptionLabel.setValue( "<table width='100%'><tr><td><p style='color:red;'><b>Package Name and Description</b></p>" + "</td><td align='right'><p style='color:red;'><b>Price</b></p></td></tr><tr> </tr>" + descriptionText[0] + "<tr><td><p style='color:red;'><b>Grand Total</b> (excl. Taxes)</p></td><td align='right'>" + "<p style='color:red;'><b>" + totalPrice[0] + "</b></p></td></tr></table>"); else packageDescriptionLabel.setValue("No description available!"); } } }); completeButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 8181926819540586585L; @Override public void buttonClick(Button.ClickEvent event) { // get some fields for the current offer String offerProjectReference = selectedProjectComboBox.getValue().toString(); String dateToday = new SimpleDateFormat("yyyyMMdd").format(new Date()); String offerNumber = dateToday + "_" + offerProjectReference; String offerFacility = db.getPIFromProjectRef(offerProjectReference); String offerName = db.getShortTitleFromProjectRef(offerProjectReference); String offerDescription = db.getLongDescFromProjectRef(offerProjectReference); // register the new offer in the database; NOTE: internal has no functionality anymore, so we simply set it to // true int offerId = db.registerNewOffer(offerNumber, offerProjectReference, offerFacility, offerName, offerDescription, totalPrice[0], new Date(), "temp", true); // TODO: if a liferay instance is running uncomment this and remove the call to db.registerNewOffer above /* offerId = db.registerNewOffer(offerNumber, offerProjectReference, offerFacility, offerName, offerDescription, totalPrice, dNow, LiferayAndVaadinUtils.getUser().getScreenName(), externalPriceSelectedCheckBox.getValue()); */ // iterate over the packages from the current offer and insert them also in the database for (String packageId : offerGeneratorPackageIds[0]) { int currentPackageId = Integer.valueOf(packageId); float packageUnitPrice = Float.valueOf(db.getPriceFromPackageId(currentPackageId, "internal")); db.insertOrUpdateOffersPackages(offerId, currentPackageId, packageUnitPrice); } displayNotification("Perfect! Offer successfully saved in the Database!", "Next step is to modify, finalize and send it to the customer. Keep in mind that the " + "description of the offer is still missing. Please go ahead and complete it. Fingers crossed!", "success"); // change view to offer manager managerTabs.setSelectedTab(1); } }); }
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 w w w.ja v a2 s.c om * @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.OfferManagerTab.java
License:Open Source License
/** * adds the listeners to the offer manager tab * @param db: database instance to query * @param updateStatusComboBox: combo box for selecting the status of the offer * @param updateButton: button for updating the status of the offer * @param deleteOfferButton: button for deleting an offer * @param generateOfferButton: button for printing an offer * @param container: sql container holding the data from the database * @param exportTableButton: button for exporting the grid as csv *//*w ww . j av a 2 s . c o m*/ private static void addListeners(Database db, ComboBox updateStatusComboBox, Button updateButton, Button deleteOfferButton, Button generateOfferButton, SQLContainer container, Button exportTableButton) { // several lists holding the package names, descriptions, prices, etc. for the current offer // TODO: change to one list of packageBeans List<String> packageNames = qOfferManager.getPackageNames(); List<String> packageDescriptions = qOfferManager.getPackageDescriptions(); List<String> packageCounts = qOfferManager.getPackageCounts(); List<String> packageUnitPrices = qOfferManager.getPackageUnitPrices(); List<String> packageTotalPrices = qOfferManager.getPackageTotalPrices(); offerManagerGrid.addSelectionListener(selectionEvent -> { // Get selection from the selection model Object selected = ((Grid.SingleSelectionModel) offerManagerGrid.getSelectionModel()).getSelectedRow(); if (selected != null) { // check if any of the packages in the current offer has no package_grp (e.g. "Bioinformatics Analysis", // "Project Management", etc.) associated with it and display a warning for the user ArrayList<String> packageIdsWithoutPackageGroup = db.getPackageIdsWithoutPackageGroup( container.getItem(selected).getItemProperty("offer_id").getValue().toString()); if (packageIdsWithoutPackageGroup.size() > 0) { String firstPackageName = db.getPackageNameFromPackageId(packageIdsWithoutPackageGroup.get(0)); displayNotification("Package not associated to package group", "The package " + firstPackageName + " with id " + packageIdsWithoutPackageGroup.get(0) + " has no package group associated with it. Please consider assigning the package to a " + "package group.", "warning"); } updateStatusComboBox.select(db.getOfferStatus( container.getItem(selected).getItemProperty("offer_id").getValue().toString())); // enable the print offer button generateOfferButton.setEnabled(true); Notification.show("Selected " + db.getOfferStatus( container.getItem(selected).getItemProperty("offer_id").getValue().toString())); detailsLayout.removeAllComponents(); try { detailsLayout.addComponent(createOfferManagerTabPackageComponent(container, container.getItem(selected).getItemProperty("offer_id").getValue().toString(), "All")); } catch (Exception e) { e.printStackTrace(); } } }); updateButton.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 8910018717791341602L; @Override public void buttonClick(Button.ClickEvent event) { if (offerManagerGrid.getSelectedRow() == null) { displayNotification("oOps! Forgot something?!", "Please make sure that you select an offer to update.", "error"); } else if (updateStatusComboBox.getValue() == null) { displayNotification("oOps! Forgot something?!", "Please make sure that you select an option for status update.", "error"); } else { // update the status of the offer (sent, accepted, declined, etc.) db.updateStatus(updateStatusComboBox.getValue().toString(), offerManagerGrid.getSelectedRow().toString()); container.refresh(); } } }); deleteOfferButton.addClickListener((Button.ClickListener) event -> { Object selectedRow = offerManagerGrid.getSelectedRow(); if (selectedRow == null) { displayNotification("No offer selected!", "Please select an offer to delete.", "error"); return; } int selectedOfferId = (int) offerManagerGrid.getContainerDataSource().getItem(selectedRow) .getItemProperty("offer_id").getValue(); db.deleteOffer(selectedOfferId); // since refreshing the rows doesn't work properly; we force an update of the grid by setting the sort direction // of the package name column offerManagerGrid.sort("offer_id", SortDirection.ASCENDING); displayNotification("Offer deleted", "Offer " + selectedOfferId + " " + "successfully deleted.", "success"); }); packageGroupComboBox.addValueChangeListener((Property.ValueChangeListener) event -> { Object selected = ((Grid.SingleSelectionModel) offerManagerGrid.getSelectionModel()).getSelectedRow(); if (selected == null) { displayNotification("No offer selected.", "Please select an offer to display", "error"); return; } // e.g. "All", "Sequencing", or "Project Management" String selectedPackageGroup = packageGroupComboBox.getValue().toString(); // change the view to display only the packages for the selected package group detailsLayout.removeAllComponents(); try { detailsLayout.addComponent(createOfferManagerTabPackageComponent(container, container.getItem(selected).getItemProperty("offer_id").getValue().toString(), selectedPackageGroup)); } catch (SQLException e) { e.printStackTrace(); } }); // adds the file creation and the export functionality to the print offer button try { setupOfferFileExportFunctionality(db, generateOfferButton, container, packageNames, packageDescriptions, packageCounts, packageUnitPrices, packageTotalPrices); } catch (IOException e) { displayNotification("Whoops, something went wrong.", "A file could not be found, please try" + "again.", "error"); e.printStackTrace(); } try { setupTableExportFunctionality(container, exportTableButton); } catch (IOException e) { displayNotification("Whoops, something went wrong.", "A file could not be found, please try" + "again.", "error"); e.printStackTrace(); } }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
private Layout getButtonPreviews() { Layout grid = getPreviewLayout("Buttons"); Button button = new Button("Button"); grid.addComponent(button);/*from w w w . j a v a 2s . c o m*/ button = new Button("Default"); button.setStyleName("default"); grid.addComponent(button); button = new Button("Small"); button.setStyleName("small"); grid.addComponent(button); button = new Button("Small Default"); button.setStyleName("small default"); grid.addComponent(button); button = new Button("Big"); button.setStyleName("big"); grid.addComponent(button); button = new Button("Big Default"); button.setStyleName("big default"); grid.addComponent(button); button = new Button("Disabled"); button.setEnabled(false); grid.addComponent(button); button = new Button("Disabled default"); button.setEnabled(false); button.setStyleName("default"); grid.addComponent(button); button = new Button("Link style"); button.setStyleName(BaseTheme.BUTTON_LINK); grid.addComponent(button); button = new Button("Disabled link"); button.setStyleName(BaseTheme.BUTTON_LINK); button.setEnabled(false); grid.addComponent(button); button = new Button("120px overflows out of the button"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); button.setWidth("120px"); grid.addComponent(button); button = new Button("Small"); button.setStyleName("small"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Big"); button.setStyleName("big"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Big Default"); button.setStyleName("big default"); button.setIcon(new ThemeResource("../runo/icons/32/document-txt.png")); grid.addComponent(button); button = new Button("Big link"); button.setStyleName(BaseTheme.BUTTON_LINK + " big"); button.setIcon(new ThemeResource("../runo/icons/32/document.png")); grid.addComponent(button); button = new Button("Borderless"); button.setStyleName("borderless"); button.setIcon(new ThemeResource("../runo/icons/32/note.png")); grid.addComponent(button); button = new Button("Borderless icon on top"); button.setStyleName("borderless icon-on-top"); button.setIcon(new ThemeResource("../runo/icons/32/note.png")); grid.addComponent(button); button = new Button("Icon on top"); button.setStyleName("icon-on-top"); button.setIcon(new ThemeResource("../runo/icons/32/users.png")); grid.addComponent(button); button = new Button("Wide Default"); button.setStyleName("wide default"); grid.addComponent(button); button = new Button("Wide"); button.setStyleName("wide"); grid.addComponent(button); button = new Button("Tall"); button.setStyleName("tall"); grid.addComponent(button); button = new Button("Wide, Tall & Big"); button.setStyleName("wide tall big"); grid.addComponent(button); button = new Button("Icon on right"); button.setStyleName("icon-on-right"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Big icon"); button.setStyleName("icon-on-right big"); button.setIcon(new ThemeResource("../runo/icons/16/document.png")); grid.addComponent(button); button = new Button("Toggle (down)"); button.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (event.getButton().getStyleName().endsWith("down")) { event.getButton().removeStyleName("down"); } else { event.getButton().addStyleName("down"); } } }); button.addStyleName("down"); grid.addComponent(button); button.setDescription( button.getDescription() + "<br><strong>Stylename switching logic must be done separately</strong>"); button = new Button(); button.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (event.getButton().getStyleName().endsWith("down")) { event.getButton().removeStyleName("down"); } else { event.getButton().addStyleName("down"); } } }); button.addStyleName("icon-only"); button.addStyleName("down"); button.setIcon(new ThemeResource("../runo/icons/16/user.png")); grid.addComponent(button); button.setDescription( button.getDescription() + "<br><strong>Stylename switching logic must be done separately</strong>"); Link l = new Link("Link: vaadin.com", new ExternalResource("http://vaadin.com")); grid.addComponent(l); l = new Link("Link: vaadin.com", new ExternalResource("http://vaadin.com")); l.setIcon(new ThemeResource("../runo/icons/32/globe.png")); grid.addComponent(l); return grid; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java
License:Apache License
private Component displayIssueTypes() { VerticalLayout vl = new VerticalLayout(); Grid grid = new Grid(TRANSLATOR.translate(ISSUE_TYPE)); BeanItemContainer<IssueType> types = new BeanItemContainer<>(IssueType.class); types.addAll(new IssueTypeJpaController(DataBaseManager.getEntityManagerFactory()).findIssueTypeEntities()); grid.setContainerDataSource(types);//from ww w.j a v a 2 s . c om grid.setSelectionMode(SelectionMode.SINGLE); grid.setColumns("typeName", DESC); Grid.Column name = grid.getColumn("typeName"); name.setHeaderCaption(TRANSLATOR.translate("general.name")); name.setConverter(new TranslationConverter()); Grid.Column desc = grid.getColumn(DESC); desc.setHeaderCaption(TRANSLATOR.translate("general.description")); desc.setConverter(new TranslationConverter()); grid.setSizeFull(); vl.addComponent(grid); grid.setHeightMode(HeightMode.ROW); grid.setHeightByRows(types.size() > 5 ? 5 : types.size()); //Menu HorizontalLayout hl = new HorizontalLayout(); Button add = new Button(TRANSLATOR.translate("general.create")); add.addClickListener(listener -> { VMWindow w = new VMWindow(); w.setContent(new IssueTypeComponent(new IssueType(), true)); ((VMUI) UI.getCurrent()).addWindow(w); w.addCloseListener(l -> { ((VMUI) UI.getCurrent()).updateScreen(); }); }); hl.addComponent(add); Button delete = new Button(TRANSLATOR.translate("general.delete")); delete.setEnabled(false); delete.addClickListener(listener -> { IssueType selected = (IssueType) ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); if (selected != null && selected.getId() >= 1000) { try { new IssueTypeJpaController(DataBaseManager.getEntityManagerFactory()).destroy(selected.getId()); ((VMUI) UI.getCurrent()).updateScreen(); } catch (IllegalOrphanException | NonexistentEntityException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate(DELETE_ERROR), TRANSLATOR.translate(DELETE_ERROR), Notification.Type.ERROR_MESSAGE); } } }); hl.addComponent(delete); vl.addComponent(hl); grid.addSelectionListener(event -> { // Java 8 // Get selection from the selection model IssueType selected = (IssueType) ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow(); //Only delete custom ones. delete.setEnabled(selected != null && selected.getId() >= 1000); }); return vl; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java
License:Apache License
private Component displayIssueResolutions() { VerticalLayout vl = new VerticalLayout(); Grid grid = new Grid(TRANSLATOR.translate(ISSUE_RESOLUTION)); BeanItemContainer<IssueResolution> types = new BeanItemContainer<>(IssueResolution.class); types.addAll(new IssueResolutionJpaController(DataBaseManager.getEntityManagerFactory()) .findIssueResolutionEntities()); grid.setContainerDataSource(types);// w ww .j a v a 2s . co m grid.setSelectionMode(SelectionMode.SINGLE); grid.setColumns(NAME); Grid.Column name = grid.getColumn(NAME); name.setHeaderCaption(TRANSLATOR.translate("general.name")); name.setConverter(new TranslationConverter()); grid.setSizeFull(); vl.addComponent(grid); grid.setHeightMode(HeightMode.ROW); grid.setHeightByRows(types.size() > 5 ? 5 : types.size()); //Menu HorizontalLayout hl = new HorizontalLayout(); Button add = new Button(TRANSLATOR.translate("general.create")); add.addClickListener(listener -> { VMWindow w = new VMWindow(); w.setContent(new IssueResolutionComponent(new IssueResolution(), true)); ((VMUI) UI.getCurrent()).addWindow(w); w.addCloseListener(l -> { ((VMUI) UI.getCurrent()).updateScreen(); }); }); hl.addComponent(add); Button delete = new Button(TRANSLATOR.translate("general.delete")); delete.setEnabled(false); delete.addClickListener(listener -> { IssueResolution selected = (IssueResolution) ((SingleSelectionModel) grid.getSelectionModel()) .getSelectedRow(); if (selected != null && selected.getId() >= 1000) { try { new IssueResolutionJpaController(DataBaseManager.getEntityManagerFactory()) .destroy(selected.getId()); ((VMUI) UI.getCurrent()).updateScreen(); } catch (IllegalOrphanException | NonexistentEntityException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate(DELETE_ERROR), TRANSLATOR.translate(DELETE_ERROR), Notification.Type.ERROR_MESSAGE); } } }); hl.addComponent(delete); vl.addComponent(hl); grid.addSelectionListener(event -> { // Java 8 // Get selection from the selection model IssueResolution selected = (IssueResolution) ((SingleSelectionModel) grid.getSelectionModel()) .getSelectedRow(); //Only delete custom ones. delete.setEnabled(selected != null && selected.getId() >= 1000); }); return vl; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java
License:Apache License
private Component displayRequirementTypes() { VerticalLayout vl = new VerticalLayout(); Grid grid = new Grid(TRANSLATOR.translate(REQUIREMENT_TYPE)); BeanItemContainer<RequirementType> types = new BeanItemContainer<>(RequirementType.class); types.addAll(new RequirementTypeJpaController(DataBaseManager.getEntityManagerFactory()) .findRequirementTypeEntities()); grid.setContainerDataSource(types);//w w w .j a v a2 s . c om grid.setSelectionMode(SelectionMode.SINGLE); grid.setColumns(NAME, DESC); Grid.Column name = grid.getColumn(NAME); name.setHeaderCaption(TRANSLATOR.translate("general.name")); name.setConverter(new TranslationConverter()); Grid.Column desc = grid.getColumn(DESC); desc.setHeaderCaption(TRANSLATOR.translate("general.description")); desc.setConverter(new TranslationConverter()); grid.setSizeFull(); vl.addComponent(grid); grid.setHeightMode(HeightMode.ROW); grid.setHeightByRows(types.size() > 5 ? 5 : types.size()); //Menu HorizontalLayout hl = new HorizontalLayout(); Button add = new Button(TRANSLATOR.translate("general.create")); add.addClickListener(listener -> { VMWindow w = new VMWindow(); w.setContent(new RequirementTypeComponent(new RequirementType(), true)); ((VMUI) UI.getCurrent()).addWindow(w); w.addCloseListener(l -> { ((VMUI) UI.getCurrent()).updateScreen(); }); }); hl.addComponent(add); Button delete = new Button(TRANSLATOR.translate("general.delete")); delete.setEnabled(false); delete.addClickListener(listener -> { RequirementType selected = (RequirementType) ((SingleSelectionModel) grid.getSelectionModel()) .getSelectedRow(); if (selected != null && selected.getId() >= 1000) { try { new RequirementTypeJpaController(DataBaseManager.getEntityManagerFactory()) .destroy(selected.getId()); ((VMUI) UI.getCurrent()).updateScreen(); } catch (IllegalOrphanException | NonexistentEntityException ex) { LOG.log(Level.SEVERE, null, ex); Notification.show(TRANSLATOR.translate(DELETE_ERROR), TRANSLATOR.translate(DELETE_ERROR), Notification.Type.ERROR_MESSAGE); } } }); hl.addComponent(delete); vl.addComponent(hl); grid.addSelectionListener(event -> { // Java 8 // Get selection from the selection model RequirementType selected = (RequirementType) ((SingleSelectionModel) grid.getSelectionModel()) .getSelectedRow(); //Only delete custom ones. delete.setEnabled(selected != null && selected.getId() >= 1000); }); return vl; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.execution.ExecutionWizardStep.java
License:Apache License
@Override public Component getContent() { Panel form = new Panel(TRANSLATOR.translate("step.detail")); if (getExecutionStep().getExecutionStart() == null) { //Set the start date. getExecutionStep().setExecutionStart(new Date()); }//from w w w .j av a 2 s . c o m FormLayout layout = new FormLayout(); form.setContent(layout); form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); BeanFieldGroup binder = new BeanFieldGroup(getExecutionStep().getStep().getClass()); binder.setItemDataSource(getExecutionStep().getStep()); TextArea text = new TextArea(TRANSLATOR.translate("general.text")); text.setConverter(new ByteToStringConverter()); binder.bind(text, "text"); text.setSizeFull(); layout.addComponent(text); Field notes = binder.buildAndBind(TRANSLATOR.translate("general.notes"), "notes", TextArea.class); notes.setSizeFull(); layout.addComponent(notes); if (getExecutionStep().getExecutionStart() != null) { start = new DateField(TRANSLATOR.translate("start.date")); start.setResolution(Resolution.SECOND); start.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal()); start.setValue(getExecutionStep().getExecutionStart()); start.setReadOnly(true); layout.addComponent(start); } if (getExecutionStep().getExecutionEnd() != null) { end = new DateField(TRANSLATOR.translate("end.date")); end.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal()); end.setResolution(Resolution.SECOND); end.setValue(getExecutionStep().getExecutionEnd()); end.setReadOnly(true); layout.addComponent(end); } binder.setReadOnly(true); //Space to record result if (getExecutionStep().getResultId() != null) { result.setValue(getExecutionStep().getResultId().getResultName()); } layout.addComponent(result); if (reviewer) {//Space to record review if (getExecutionStep().getReviewResultId() != null) { review.setValue(getExecutionStep().getReviewResultId().getReviewName()); } layout.addComponent(review); } //Add Reviewer name if (getExecutionStep().getReviewer() != null) { TextField reviewerField = new TextField(TRANSLATOR.translate("general.reviewer")); reviewerField.setValue(getExecutionStep().getReviewer().getFirstName() + " " + getExecutionStep().getReviewer().getLastName()); reviewerField.setReadOnly(true); layout.addComponent(reviewerField); } if (getExecutionStep().getReviewDate() != null) { reviewDate = new DateField(TRANSLATOR.translate("review.date")); reviewDate.setDateFormat(VMSettingServer.getSetting("date.format").getStringVal()); reviewDate.setResolution(Resolution.SECOND); reviewDate.setValue(getExecutionStep().getReviewDate()); reviewDate.setReadOnly(true); layout.addComponent(reviewDate); } if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { TextArea expectedResult = new TextArea(TRANSLATOR.translate("expected.result")); expectedResult.setConverter(new ByteToStringConverter()); binder.bind(expectedResult, "expectedResult"); expectedResult.setSizeFull(); layout.addComponent(expectedResult); } //Add the fields fields.clear(); getExecutionStep().getStep().getDataEntryList().forEach(de -> { switch (de.getDataEntryType().getId()) { case 1://String TextField tf = new TextField(TRANSLATOR.translate(de.getEntryName())); tf.setRequired(true); tf.setData(de.getEntryName()); if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { //Add expected result DataEntryProperty stringCase = DataEntryServer.getProperty(de, "property.match.case"); DataEntryProperty r = DataEntryServer.getProperty(de, "property.expected.result"); if (r != null && !r.getPropertyValue().equals("null")) { String error = TRANSLATOR.translate("expected.result") + ": " + r.getPropertyValue(); tf.setRequiredError(error); tf.setRequired(DataEntryServer.getProperty(de, "property.required").getPropertyValue() .equals("true")); tf.addValidator((Object val) -> { //We have an expected result and a match case requirement if (stringCase != null && stringCase.getPropertyValue().equals("true") ? !((String) val).equals(r.getPropertyValue()) : !((String) val).equalsIgnoreCase(r.getPropertyValue())) { throw new InvalidValueException(error); } }); } } fields.add(tf); //Set value if already recorded updateValue(tf); layout.addComponent(tf); break; case 2://Numeric NumberField field = new NumberField(TRANSLATOR.translate(de.getEntryName())); field.setSigned(true); field.setUseGrouping(true); field.setGroupingSeparator(','); field.setDecimalSeparator('.'); field.setConverter(new StringToDoubleConverter()); field.setRequired( DataEntryServer.getProperty(de, "property.required").getPropertyValue().equals("true")); field.setData(de.getEntryName()); Double min = null, max = null; for (DataEntryProperty prop : de.getDataEntryPropertyList()) { String value = prop.getPropertyValue(); if (prop.getPropertyName().equals("property.max")) { try { max = Double.parseDouble(value); } catch (NumberFormatException ex) { //Leave as null } } else if (prop.getPropertyName().equals("property.min")) { try { min = Double.parseDouble(value); } catch (NumberFormatException ex) { //Leave as null } } } //Add expected result if (VMSettingServer.getSetting("show.expected.result").getBoolVal() && (min != null || max != null)) { String error = TRANSLATOR.translate("error.out.of.range") + " " + (min == null ? " " : (TRANSLATOR.translate("property.min") + ": " + min)) + " " + (max == null ? "" : (TRANSLATOR.translate("property.max") + ": " + max)); field.setRequiredError(error); field.addValidator(new DoubleRangeValidator(error, min, max)); } fields.add(field); //Set value if already recorded updateValue(field); layout.addComponent(field); break; case 3://Boolean CheckBox cb = new CheckBox(TRANSLATOR.translate(de.getEntryName())); cb.setData(de.getEntryName()); cb.setRequired( DataEntryServer.getProperty(de, "property.required").getPropertyValue().equals("true")); if (VMSettingServer.getSetting("show.expected.result").getBoolVal()) { DataEntryProperty r = DataEntryServer.getProperty(de, "property.expected.result"); if (r != null) { //Add expected result String error = TRANSLATOR.translate("expected.result") + ": " + r.getPropertyValue(); cb.addValidator((Object val) -> { if (!val.toString().equals(r.getPropertyValue())) { throw new InvalidValueException(error); } }); } } fields.add(cb); //Set value if already recorded updateValue(cb); layout.addComponent(cb); break; case 4://Attachment Label l = new Label(TRANSLATOR.translate(de.getEntryName())); layout.addComponent(l); break; default: LOG.log(Level.SEVERE, "Unexpected field type: {0}", de.getDataEntryType().getId()); } }); //Add the Attachments HorizontalLayout attachments = new HorizontalLayout(); attachments.setCaption(TRANSLATOR.translate("general.attachment")); HorizontalLayout comments = new HorizontalLayout(); comments.setCaption(TRANSLATOR.translate("general.comments")); HorizontalLayout issues = new HorizontalLayout(); issues.setCaption(TRANSLATOR.translate("general.issue")); int commentCounter = 0; int issueCounter = 0; for (ExecutionStepHasIssue ei : getExecutionStep().getExecutionStepHasIssueList()) { issueCounter++; Button a = new Button("Issue #" + issueCounter); a.setIcon(VaadinIcons.BUG); a.addClickListener((Button.ClickEvent event) -> { displayIssue(new IssueServer(ei.getIssue())); }); a.setEnabled(!step.getLocked()); issues.addComponent(a); } for (ExecutionStepHasAttachment attachment : getExecutionStep().getExecutionStepHasAttachmentList()) { switch (attachment.getAttachment().getAttachmentType().getType()) { case "comment": { //Comments go in a different section commentCounter++; Button a = new Button("Comment #" + commentCounter); a.setIcon(VaadinIcons.CLIPBOARD_TEXT); a.addClickListener((Button.ClickEvent event) -> { if (!step.getLocked()) { //Prompt if user wants this removed MessageBox mb = getDeletionPrompt(attachment); mb.open(); } else { displayComment(new AttachmentServer(attachment.getAttachment().getAttachmentPK())); } }); a.setEnabled(!step.getLocked()); comments.addComponent(a); break; } default: { Button a = new Button(attachment.getAttachment().getFileName()); a.setEnabled(!step.getLocked()); a.setIcon(VaadinIcons.PAPERCLIP); a.addClickListener((Button.ClickEvent event) -> { if (!step.getLocked()) { //Prompt if user wants this removed MessageBox mb = getDeletionPrompt(attachment); mb.open(); } else { displayAttachment(new AttachmentServer(attachment.getAttachment().getAttachmentPK())); } }); attachments.addComponent(a); break; } } } if (attachments.getComponentCount() > 0) { layout.addComponent(attachments); } if (comments.getComponentCount() > 0) { layout.addComponent(comments); } if (issues.getComponentCount() > 0) { layout.addComponent(issues); } //Add the menu HorizontalLayout hl = new HorizontalLayout(); attach = new Button(TRANSLATOR.translate("add.attachment")); attach.setIcon(VaadinIcons.PAPERCLIP); attach.addClickListener((Button.ClickEvent event) -> { //Show dialog to upload file. Window dialog = new VMWindow(TRANSLATOR.translate("attach.file")); VerticalLayout vl = new VerticalLayout(); MultiFileUpload multiFileUpload = new MultiFileUpload() { @Override protected void handleFile(File file, String fileName, String mimeType, long length) { try { LOG.log(Level.FINE, "Received file {1} at: {0}", new Object[] { file.getAbsolutePath(), fileName }); //Process the file //Create the attachment AttachmentServer a = new AttachmentServer(); a.addFile(file, fileName); //Overwrite the default file name set in addFile. It'll be a temporary file name a.setFileName(fileName); a.write2DB(); //Now add it to this Execution Step if (getExecutionStep().getExecutionStepHasAttachmentList() == null) { getExecutionStep().setExecutionStepHasAttachmentList(new ArrayList<>()); } getExecutionStep().addAttachment(a); getExecutionStep().write2DB(); w.updateCurrentStep(); } catch (Exception ex) { LOG.log(Level.SEVERE, "Error creating attachment!", ex); } } }; multiFileUpload.setCaption(TRANSLATOR.translate("select.files.attach")); vl.addComponent(multiFileUpload); dialog.setContent(vl); dialog.setHeight(25, Sizeable.Unit.PERCENTAGE); dialog.setWidth(25, Sizeable.Unit.PERCENTAGE); ValidationManagerUI.getInstance().addWindow(dialog); }); hl.addComponent(attach); bug = new Button(TRANSLATOR.translate("create.issue")); bug.setIcon(VaadinIcons.BUG); bug.addClickListener((Button.ClickEvent event) -> { displayIssue(new IssueServer()); }); hl.addComponent(bug); comment = new Button(TRANSLATOR.translate("add.comment")); comment.setIcon(VaadinIcons.CLIPBOARD_TEXT); comment.addClickListener((Button.ClickEvent event) -> { AttachmentServer as = new AttachmentServer(); //Get comment type AttachmentType type = AttachmentTypeServer.getTypeForExtension("comment"); as.setAttachmentType(type); displayComment(as); }); hl.addComponent(comment); step.update(); attach.setEnabled(!step.getLocked()); bug.setEnabled(!step.getLocked()); comment.setEnabled(!step.getLocked()); result.setEnabled(!step.getLocked()); layout.addComponent(hl); return layout; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.template.TemplateScreenProvider.java
License:Apache License
private Component getLeftComponent() { Panel p = new Panel(); VerticalLayout layout = new VerticalLayout(); templates.setNullSelectionAllowed(true); templates.setWidth(100, Sizeable.Unit.PERCENTAGE); BeanItemContainer<Template> container = new BeanItemContainer<>(Template.class, new TemplateJpaController(DataBaseManager.getEntityManagerFactory()).findTemplateEntities()); templates.setContainerDataSource(container); templates.getItemIds().forEach(id -> { Template temp = ((Template) id); templates.setItemCaption(id, TRANSLATOR.translate(temp.getTemplateName())); });//from w w w. j a va 2 s . c o m templates.addValueChangeListener(event -> { hs.setSecondComponent(getRightComponent()); }); templates.setNullSelectionAllowed(false); templates.setWidth(100, Sizeable.Unit.PERCENTAGE); layout.addComponent(templates); HorizontalLayout hl = new HorizontalLayout(); Button create = new Button(TRANSLATOR.translate("general.add")); create.addClickListener(listener -> { displayTemplateCreateWizard(); }); hl.addComponent(create); Button copy = new Button(TRANSLATOR.translate("general.copy")); copy.addClickListener(listener -> { displayTemplateCopyWizard(); }); hl.addComponent(copy); Button delete = new Button(TRANSLATOR.translate("general.delete")); delete.addClickListener(listener -> { displayTemplateDeleteWizard(); }); hl.addComponent(delete); templates.addValueChangeListener(listener -> { if (templates.getValue() != null) { Template t = (Template) templates.getValue(); delete.setEnabled(t.getId() >= 1_000); copy.setEnabled(t.getTemplateNodeList().size() > 0); } }); layout.addComponent(hl); layout.setSizeFull(); p.setContent(layout); p.setSizeFull(); return p; }