List of usage examples for com.vaadin.ui Button setSizeFull
@Override public void setSizeFull()
From source file:facs.components.Booking.java
License:Open Source License
public Booking(final BookingModel bookingModel, Date referenceDate) { String[] sayHello = { "Kon'nichiwa", "Hello", "Halo", "Hiya", "Hej", "Hallo", "Hola", "Grezi", "Servus", "Merhaba", "Bonjour", "Ahoj", "Moi", "Ciao", "Buongiorno" }; this.bookingModel = bookingModel; this.referenceDate = referenceDate; Label infoLabel = new Label(); infoLabel.addStyleName("h4"); Label selectDeviceLabel = new Label(); selectDeviceLabel.addStyleName("h4"); selectDeviceLabel.setValue("Please Select a Device"); final Label versionLabel = new Label(); versionLabel.addStyleName("h4"); versionLabel.setValue("Version 0.1.160727"); // showSuccessfulNotification(sayHello[(int) (Math.random() * sayHello.length)] + ", " // + bookingModel.userName() + "!", ""); Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); System.out.println(ft.format(dNow) + " INFO Calendar initiated! - User: " + bookingModel.getLDAP() + " " + versionLabel);//from w w w . j a v a 2s .c om // only users who are allowed to book devices will be able to do so if (bookingModel.isNotAllowed()) { VerticalLayout errorLayout = new VerticalLayout(); infoLabel.setValue("ACCESS DENIED"); errorLayout.addComponent(infoLabel); showErrorNotification("Access Denied!", "Sorry, you're not allowed to see anything here, at least your username told us so. Do you need assistance? Please contact 'info@qbic.uni-tuebingen.de'."); setCompositionRoot(errorLayout); return; } Panel book = new Panel(); book.addStyleName(ValoTheme.PANEL_BORDERLESS); DBManager.getDatabaseInstance(); db = Database.Instance; db.userLogin(bookingModel.getLDAP()); selectedDevice = initCalendars(bookingModel.getDevicesNames()); selectedService = new NativeSelect("Please select a service:"); selectedService.setDescription("Please select the service you would like to receive!"); selectedKostenstelle = new NativeSelect("Please select konstenstelle:"); selectedKostenstelle.setDescription("Please select the Kostenstelle you would like to use!"); selectedDevice.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 8153818693511960689L; @Override public void valueChange(ValueChangeEvent event) { versionLabel.setValue(db.getUserRoleDescByLDAPId(bookingModel.getLDAP(), getCurrentDevice())); selectedKostenstelle.setVisible(true); if (bookMap.containsKey(getCurrentDevice())) { cal.removeAllComponents(); setCalendar(); if (selectedDevice.getValue().equals("Aria")) { selectedService.removeAllItems(); selectedService.addItems("Full Service", "Partial Service", "Self Service"); selectedService.setValue("Full Service"); selectedService.setVisible(true); } else if (selectedDevice.getValue().equals("Mac")) { selectedService.removeAllItems(); selectedService.addItems("Self", "Service"); selectedService.setValue("Service"); selectedService.setVisible(true); } else { selectedService.setValue(null); selectedService.setVisible(false); } } else { bookMap.put(getCurrentDevice(), initCal(bookingModel, getCurrentDevice())); cal.removeAllComponents(); setCalendar(); if (selectedDevice.getValue().equals("Aria")) { selectedService.removeAllItems(); selectedService.addItems("Full Service", "Partial Service", "Self Service"); selectedService.setValue("Full Service"); selectedService.setVisible(true); } else if (selectedDevice.getValue().equals("Mac")) { selectedService.removeAllItems(); selectedService.addItems("Self", "Service"); selectedService.setValue("Service"); selectedService.setVisible(true); } else { selectedService.setValue(null); selectedService.setVisible(false); } } } }); if (bookingModel.getProject().isEmpty()) { infoLabel.setValue(bookingModel.userName() + " Kostenstelle: " + bookingModel.getKostenstelle() + " Institute: " + bookingModel.getInstitute()); } else { infoLabel.setValue(bookingModel.userName() + " Kostenstelle: " + bookingModel.getKostenstelle() + " Project: " + bookingModel.getProject() + " Institute: " + bookingModel.getInstitute()); } // bookDeviceLayout.addComponent(infoLabel); cal.setLocale(Locale.getDefault()); cal.setImmediate(true); selectedService.setImmediate(true); cal.setSizeFull(); String submitTitle = "Book"; Button submit = new Button(submitTitle); submit.setIcon(FontAwesome.CALENDAR); submit.setDescription("Please select a device and a time frame at first then click 'BOOK'!"); submit.setSizeFull(); // submit.setVisible(false); submit.addClickListener(new ClickListener() { private static final long serialVersionUID = -3610721151565496269L; @Override public void buttonClick(ClickEvent event) { submit(bookingModel.getLDAP(), getCurrentDevice()); newEvents.clear(); refreshDataSources(); } }); String buttonTitle = "Refresh"; Button refresh = new Button(buttonTitle); refresh.setIcon(FontAwesome.REFRESH); refresh.setSizeFull(); refresh.setDescription("Click here to reload the data from the database!"); refresh.addStyleName(ValoTheme.BUTTON_FRIENDLY); refresh.addClickListener(new ClickListener() { private static final long serialVersionUID = -3610721151565496269L; @Override public void buttonClick(ClickEvent event) { refreshDataSources(); } }); gridLayout.setWidth("100%"); // add components to the grid layout gridLayout.addComponent(infoLabel, 0, 4, 3, 4); gridLayout.addComponent(versionLabel, 4, 4, 5, 4); // gridLayout.addComponent(selectDeviceLabel,0,1); gridLayout.addComponent(selectedDevice, 0, 0); gridLayout.addComponent(selectedService, 1, 0); gridLayout.addComponent(selectedKostenstelle, 2, 0); selectedService.setVisible(false); gridLayout.addComponent(cal, 0, 2, 5, 2); gridLayout.addComponent(refresh, 0, 3); gridLayout.addComponent(submit, 1, 3, 5, 3); // gridLayout.addComponent(myBookings(), 0, 5, 5, 5); gridLayout.setMargin(true); gridLayout.setSpacing(true); gridLayout.setSizeFull(); book.setContent(gridLayout); booking = new TabSheet(); booking.addStyleName(ValoTheme.TABSHEET_FRAMED); booking.addTab(book).setCaption("Calendar"); booking.addTab(myNext24HoursBookings()).setCaption("Next 24 Hours"); booking.addTab(myUpcomingBookings()).setCaption("Upcoming"); booking.addTab(myPastBookings()).setCaption("Past Bookings"); // booking.addTab(myUpcomingBookingsSQLContainer()).setCaption("Test"); setCompositionRoot(booking); }
From source file:facs.components.UserAdmin.java
License:Open Source License
public UserAdmin(User user) { Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); System.out.println(ft.format(dNow) + " INFO Calendar User Manager accessed! - User: " + LiferayAndVaadinUtils.getUser().getScreenName()); Label infoLabel = new Label( DBManager.getDatabaseInstance().getUserNameByUserID(LiferayAndVaadinUtils.getUser().getScreenName()) + " " + LiferayAndVaadinUtils.getUser().getScreenName()); infoLabel.addStyleName("h4"); CheckBox isAdmin = new CheckBox("user has admin panel access"); isAdmin.setEnabled(false);// w ww. j a va 2s .c o m String buttonGroupUpdateTitle = "Edit Group"; Button updateUserGroup = new Button(buttonGroupUpdateTitle); updateUserGroup.setIcon(FontAwesome.EDIT); updateUserGroup.setSizeFull(); updateUserGroup.setDescription("Click here to update the group of the user!"); String buttonWorkgroupUpdateTitle = "Edit Workgroup"; Button updateUserWorkgroup = new Button(buttonWorkgroupUpdateTitle); updateUserWorkgroup.setIcon(FontAwesome.EDIT); updateUserWorkgroup.setSizeFull(); updateUserWorkgroup.setDescription("Click here to update the workgroup of the user!"); String buttonUpdateTitle = "Update (user role & group for device)"; Button updateUserRightsAndRoles = new Button(buttonUpdateTitle); updateUserRightsAndRoles.setIcon(FontAwesome.WRENCH); updateUserRightsAndRoles.setSizeFull(); updateUserRightsAndRoles.setDescription("Click here to update the user's role and group for a device!"); String buttonTitle = "Refresh"; Button refresh = new Button(buttonTitle); refresh.setIcon(FontAwesome.REFRESH); refresh.setSizeFull(); refresh.setDescription("Click here to reload the data from the database!"); refresh.addStyleName(ValoTheme.BUTTON_FRIENDLY); // String buttonTitleSave = "Save"; // Button save = new Button(buttonTitleSave); // save.setIcon(FontAwesome.SAVE); // save.setSizeFull(); // save.setDescription("Click here to save all changes!"); // save.addStyleName(ValoTheme.BUTTON_BORDERLESS); userDevice = new ListSelect("Devices"); userDevice.addItems(DBManager.getDatabaseInstance().getDeviceNames()); userDevice.setRows(6); userDevice.setNullSelectionAllowed(false); userDevice.setSizeFull(); userDevice.setImmediate(true); /* * userDevice.addValueChangeListener(e -> Notification.show("Device:", * String.valueOf(e.getProperty().getValue()), Type.TRAY_NOTIFICATION)); */ userGroup = new ListSelect("User Groups"); userGroup.addItems(DBManager.getDatabaseInstance().getUserGroups()); userGroup.addItem("N/A"); userGroup.setRows(6); userGroup.setNullSelectionAllowed(false); userGroup.setSizeFull(); userGroup.setImmediate(true); /* * userGroup.addValueChangeListener(e -> Notification.show("User Group:", * String.valueOf(e.getProperty().getValue()), Type.TRAY_NOTIFICATION)); */ userRole = new ListSelect("User Roles"); userRole.addItems(DBManager.getDatabaseInstance().getUserRoles()); userRole.addItem("N/A"); userRole.setRows(6); userRole.setNullSelectionAllowed(false); userRole.setSizeFull(); userRole.setImmediate(true); /* * userRole.addValueChangeListener(e -> Notification.show("User Role:", * String.valueOf(e.getProperty().getValue()), Type.TRAY_NOTIFICATION)); */ userWorkgroup = new ListSelect("Workgroups"); userWorkgroup.addItems(DBManager.getDatabaseInstance().getUserWorkgroups()); userWorkgroup.setRows(6); userWorkgroup.setNullSelectionAllowed(false); userWorkgroup.setSizeFull(); userWorkgroup.setImmediate(true); /* * userRole.addValueChangeListener(e -> Notification.show("User Role:", * String.valueOf(e.getProperty().getValue()), Type.TRAY_NOTIFICATION)); */ Button updateUser = new Button(buttonTitle); updateUser.setIcon(FontAwesome.WRENCH); updateUser.setDescription("Click here to update your user role and group!"); refresh.addClickListener(new ClickListener() { private static final long serialVersionUID = -3610721151565496269L; @Override public void buttonClick(ClickEvent event) { refreshDataSources(); } }); updateUser.addClickListener(new ClickListener() { private static final long serialVersionUID = -3610721151565496909L; @Override public void buttonClick(ClickEvent event) { refreshDataSources(); } }); updateUserWorkgroup.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = -295434651623561492L; @Override public void buttonClick(ClickEvent event) { try { Object selectedRow = ((SingleSelectionModel) usersGrid.getSelectionModel()).getSelectedRow(); if (selectedRow == null || userWorkgroup.getValue().equals(null)) { Notification("Something's missing!", "Please make sure that you selected the user and workgroup! Make sure they are highligthed.", "error"); } else { DBManager.getDatabaseInstance().adminUpdatesUserWorkgroup( DBManager.getDatabaseInstance() .getUserGroupIDByName(userWorkgroup.getValue().toString()), DBManager.getDatabaseInstance().getUserLDAPIDbyID(selectedRow.toString())); // log changes in 'user_log' table DBManager.getDatabaseInstance().logEverything( LiferayAndVaadinUtils.getUser().getScreenName(), "Admin edited Workgroup"); Notification("Successfully Updated", "Selected values are updated in the database. If it was a mistake, please remind that there is no 'undo' functionality yet.", "success"); } } catch (Exception e) { Notification("Something's missing!", "Please make sure that you selected the user and workgroup! Make sure they are highligthed.", "error"); } refreshDataSources(); } }); updateUserGroup.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = -5539382755814626288L; @Override public void buttonClick(ClickEvent event) { try { Object selectedRow = ((SingleSelectionModel) usersGrid.getSelectionModel()).getSelectedRow(); if (selectedRow == null || userWorkgroup.getValue().equals(null)) { Notification("Something's missing!", "Please make sure that you selected the user and group! Make sure they are highligthed.", "error"); } else { DBManager.getDatabaseInstance().adminUpdatesUserGroup( DBManager.getDatabaseInstance() .getUserGroupIDByName(userGroup.getValue().toString()), DBManager.getDatabaseInstance().getUserIDbyLDAPID(selectedRow.toString())); // log changes in 'user_log' table DBManager.getDatabaseInstance().logEverything( LiferayAndVaadinUtils.getUser().getScreenName(), "Admin edited User Group"); Notification("Successfully Updated", "Selected values are updated in the database. If it was a mistake, please remind that there is no 'undo' functionality yet.", "success"); } } catch (Exception e) { Notification("Something's missing!", "Please make sure that you selected the user and group! Make sure they are highligthed.", "error"); } refreshDataSources(); } }); updateUserRightsAndRoles.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = -295434651623561492L; @Override public void buttonClick(ClickEvent event) { try { Object selectedRow = ((SingleSelectionModel) usersGrid.getSelectionModel()).getSelectedRow(); if (selectedRow == null || userDevice.getValue().equals(null) || userRole.getValue().equals(null)) { Notification("Something's missing!", "Please make sure that you selected the user, device and role! Each list has to have one highligthed option.", "error"); } else { DBManager.getDatabaseInstance().adminUpdatesUserRoleForDevice( DBManager.getDatabaseInstance().getUserRoleIDbyDesc(userRole.getValue().toString()), DBManager.getDatabaseInstance().getUserIDbyLDAPID( DBManager.getDatabaseInstance().getUserLDAPIDbyID(selectedRow.toString())), DBManager.getDatabaseInstance() .getDeviceIDByName(userDevice.getValue().toString())); // log changes in 'user_log' table DBManager.getDatabaseInstance().logEverything( LiferayAndVaadinUtils.getUser().getScreenName(), "Admin edited Device, Role, Group"); Notification("Successfully Updated", "Selected values are updated in the database. If it was a mistake, please remind that there is no 'undo' functionality yet.", "success"); } } catch (Exception e) { Notification("Something's missing!", "Please make sure that you selected the user, device and role! Each list has to have one highligthed option.", "error"); } refreshDataSources(); } }); try { TableQuery tq = new TableQuery("user", DBManager.getDatabaseInstanceAlternative()); tq.setVersionColumn("OPTLOCK"); SQLContainer container = new SQLContainer(tq); // System.out.println("Print Container: " + container.size()); container.setAutoCommit(isEnabled()); usersGrid = new Grid(container); FieldGroup fieldGroup = usersGrid.getEditorFieldGroup(); fieldGroup.addCommitHandler(new FieldGroup.CommitHandler() { /** * */ private static final long serialVersionUID = 3799806709907688919L; @Override public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException { } @Override public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException { Notification("Successfully Updated", "Selected values are updated in the database. If it was a mistake, please remind that there is no 'undo' functionality yet.", "success"); refreshGrid(); } private void refreshGrid() { container.refresh(); } }); usersGrid.addSelectionListener(selectionEvent -> { // Java 8 // Get selection from the selection model Object selected = ((SingleSelectionModel) usersGrid.getSelectionModel()).getSelectedRow(); if (selected != null) { // userDevice.select(bookAdmin.getSelectedTab().getCaption()); userWorkgroup.select(DBManager.getDatabaseInstance().getUserWorkgroupByUserId(usersGrid .getContainerDataSource().getItem(selected).getItemProperty("user_id").toString())); userGroup.select(DBManager.getDatabaseInstance().getUserRoleByUserId(usersGrid .getContainerDataSource().getItem(selected).getItemProperty("user_id").toString())); userDevice.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = -8696555155016720475L; @Override public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { userRole.select( DBManager.getDatabaseInstance().getUserGroupDescriptionByUserID( usersGrid.getContainerDataSource().getItem(selected) .getItemProperty("user_id").toString(), userDevice.getValue().toString())); } }); isAdmin.setValue(DBManager.getDatabaseInstance().hasAdminPanelAccess(usersGrid .getContainerDataSource().getItem(selected).getItemProperty("user_id").toString())); Notification.show("Selected " + usersGrid.getContainerDataSource().getItem(selected).getItemProperty("user_id")); } else Notification.show("Nothing selected"); }); } catch (Exception e) { // TODO Auto-generated catch block Notification("Something went wrong!", "Unable to update/connect the database. There may be a connection problem, please check your internet connection settings then try it again.", "error"); e.printStackTrace(); } /* * // only admins are allowed to see the admin panel ;) if (!DBManager.getDatabaseInstance() * .getUserAdminPanelAccessByLDAPId(LiferayAndVaadinUtils.getUser().getScreenName()) * .equals("1")) { VerticalLayout errorLayout = new VerticalLayout(); * infoLabel.setValue("ACCESS DENIED"); errorLayout.addComponent(infoLabel); * showErrorNotification( "Access Denied!", * "Sorry, you're not allowed to see anything here, at least your username told us so. Do you need assistance? Please contact 'info@qbic.uni-tuebingen.de'." * ); setCompositionRoot(errorLayout); return; } */ this.setCaption("User Manager"); final TabSheet userAdmin = new TabSheet(); userAdmin.addStyleName(ValoTheme.TABSHEET_FRAMED); userAdmin.addTab(usersGrid()); /* * userAdmin.addSelectedTabChangeListener(new SelectedTabChangeListener() { * * @Override public void selectedTabChange(SelectedTabChangeEvent event) { * * } }); */ gridLayout.setWidth("100%"); // add components to the grid layout // gridLayout.addComponent(infoLabel, 0, 0, 3, 0); gridLayout.addComponent(userAdmin, 0, 1, 5, 1); gridLayout.addComponent(refresh, 0, 2); gridLayout.addComponent(isAdmin, 5, 2); // gridLayout.addComponent(save); gridLayout.addComponent(userWorkgroup, 0, 4); gridLayout.addComponent(userDevice, 1, 4); gridLayout.addComponent(userRole, 2, 4, 4, 4); gridLayout.addComponent(userGroup, 5, 4); gridLayout.addComponent(updateUserWorkgroup, 0, 5); gridLayout.addComponent(updateUserRightsAndRoles, 1, 5, 4, 5); gridLayout.addComponent(updateUserGroup, 5, 5); // gridLayout.addComponent(newContainerGrid, 1, 4); gridLayout.setSpacing(true); gridLayout.setSizeFull(); setCompositionRoot(gridLayout); }
From source file:fi.jasoft.dragdroplayouts.demo.views.DragdropDragCaptionDemo.java
License:Apache License
@Override public Component getLayout() { // start-source HorizontalLayout layout = new HorizontalLayout(); layout.setSizeFull();/*from w ww.j a va2s .com*/ layout.setMargin(true); layout.setSpacing(true); DDPanel panel1 = new DDPanel("Source"); panel1.setWidth("200px"); panel1.setHeight("200px"); panel1.setDragMode(LayoutDragMode.CLONE); panel1.setDropHandler(new DefaultPanelDropHandler()); panel1.setDragCaptionProvider(component -> new DragCaption( "<u>Custom drag caption:</u><br/>" + component.getClass().getSimpleName(), VaadinIcons.AIRPLANE, ContentMode.HTML)); layout.addComponent(panel1); Button content = new Button("Drag me!"); content.setSizeFull(); panel1.setContent(content); DDPanel panel2 = new DDPanel("Destination"); panel2.setWidth("200px"); panel2.setHeight("200px"); panel2.setDragMode(LayoutDragMode.CLONE); panel2.setDropHandler(new DefaultPanelDropHandler()); panel2.setDragCaptionProvider(component -> new DragCaption( "Drag caption goes back! " + component.getClass().getSimpleName(), VaadinIcons.AIRPLANE)); layout.addComponent(panel2); // end-source Label label = new Label("In this demo you can drag the button." + "\nYou will see custom drag caption(with icon) provided by DragCaptionProvider"); label.setContentMode(ContentMode.PREFORMATTED); return new VerticalLayout(label, layout); }
From source file:fi.jasoft.dragdroplayouts.demo.views.DragdropPanelDemo.java
License:Apache License
@Override public Component getLayout() { // start-source HorizontalLayout layout = new HorizontalLayout(); layout.setSizeFull();//from w w w. j a v a 2s .c om layout.setMargin(true); layout.setSpacing(true); DDPanel panel1 = new DDPanel("Source"); panel1.setWidth("200px"); panel1.setHeight("200px"); panel1.setDragMode(LayoutDragMode.CLONE); panel1.setDropHandler(new DefaultPanelDropHandler()); layout.addComponent(panel1); Button content = new Button("Drag me!"); content.setSizeFull(); panel1.setContent(content); DDPanel panel2 = new DDPanel("Destination"); panel2.setWidth("200px"); panel2.setHeight("200px"); panel2.setDragMode(LayoutDragMode.CLONE); panel2.setDropHandler(new DefaultPanelDropHandler()); layout.addComponent(panel2); // end-source return new VerticalLayout(new Label("In this demo you can drag the button from one Panel to the other one"), layout); }
From source file:fr.univlorraine.mondossierweb.views.ListeInscritsView.java
License:Apache License
private void displayTrombinoscope() { List<Inscrit> linscrits = MainUI.getCurrent().getListeInscrits(); if (trombiLayout != null) { trombiLayout.removeAllComponents(); } else {//from www .j av a 2s . c o m trombiLayout = new GridLayout(); trombiLayout.setColumns(5); trombiLayout.setWidth("100%"); trombiLayout.setHeight(null); trombiLayout.setSpacing(true); } for (Inscrit inscrit : linscrits) { if (listecodind.contains(inscrit.getCod_ind())) { VerticalLayout photoLayout = new VerticalLayout(); photoLayout.setId(inscrit.getCod_ind()); photoLayout.setHeight("100%"); if (inscrit.getUrlphoto() != null) { //Button fotoEtu=new Button(); Image fotoEtudiant = new Image(null, new ExternalResource(inscrit.getUrlphoto())); fotoEtudiant.setWidth("120px"); fotoEtudiant.setStyleName(ValoTheme.BUTTON_LINK); fotoEtudiant.addClickListener(e -> { rechercheController.accessToDetail(inscrit.getCod_etu().toString(), Utils.TYPE_ETU, null); }); photoLayout.addComponent(fotoEtudiant); //photoLayout.addComponent(fotoEtu); photoLayout.setComponentAlignment(fotoEtudiant, Alignment.MIDDLE_CENTER); photoLayout.setExpandRatio(fotoEtudiant, 1); } VerticalLayout nomCodeLayout = new VerticalLayout(); nomCodeLayout.setSizeFull(); nomCodeLayout.setSpacing(false); Button btnNomEtudiant = new Button(inscrit.getPrenom() + " " + inscrit.getNom()); btnNomEtudiant.setSizeFull(); btnNomEtudiant.setStyleName(ValoTheme.BUTTON_BORDERLESS); btnNomEtudiant.addStyleName("link"); btnNomEtudiant.addStyleName("v-link"); nomCodeLayout.addComponent(btnNomEtudiant); btnNomEtudiant.addClickListener(e -> { rechercheController.accessToDetail(inscrit.getCod_etu().toString(), Utils.TYPE_ETU, null); }); nomCodeLayout.setComponentAlignment(btnNomEtudiant, Alignment.MIDDLE_CENTER); //nomCodeLayout.setExpandRatio(btnNomEtudiant, 1); Label codetuLabel = new Label(inscrit.getCod_etu()); codetuLabel.setSizeFull(); codetuLabel.setStyleName(ValoTheme.LABEL_TINY); codetuLabel.addStyleName("label-centre"); nomCodeLayout.addComponent(codetuLabel); nomCodeLayout.setComponentAlignment(codetuLabel, Alignment.TOP_CENTER); photoLayout.addComponent(nomCodeLayout); trombiLayout.addComponent(photoLayout); trombiLayout.setComponentAlignment(photoLayout, Alignment.MIDDLE_CENTER); } } }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
private Button createImage() { final Button button = new Button("zen"); button.setSizeFull(); return button; }
From source file:org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorderWithIcon.java
License:Open Source License
@Override public Button decorate(final Button button, final String style, final boolean setStyle, final Resource icon) { this.button = button; button.setSizeFull(); button.addStyleName(ValoTheme.LABEL_SMALL); button.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED); setOrAddButtonStyle(style, setStyle); setButtonIcon(icon);/*from ww w.j a v a 2 s . com*/ return button; }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewConfigurationWindow.java
License:Open Source License
/** * The constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used * @param view the view to edit * @param saveActionListener the save action listener *///from ww w . j a v a2 s . c o m public SurveillanceViewConfigurationWindow(final SurveillanceViewService surveillanceViewService, final View view, final SaveActionListener saveActionListener) { /** * Setting the title */ super("Surveillance view configuration"); /** * Setting the modal and size properties */ setModal(true); setClosable(false); setResizable(false); setWidth(80, Sizeable.Unit.PERCENTAGE); setHeight(75, Sizeable.Unit.PERCENTAGE); /** * Title field */ final TextField titleField = new TextField(); titleField.setValue(view.getName()); titleField.setImmediate(true); titleField.setCaption("Title"); titleField.setDescription("Title of this surveillance view"); titleField.setWidth(25, Unit.PERCENTAGE); /** * Adding simple validator */ titleField.addValidator(new AbstractStringValidator("Please use an unique name for the surveillance view") { @Override protected boolean isValidValue(String string) { if ("".equals(string.trim())) { return false; } if (SurveillanceViewProvider.getInstance().containsView(string) && !view.getName().equals(string)) { return false; } return true; } }); /** * Refresh seconds field setup and validator */ final TextField refreshSecondsField = new TextField(); refreshSecondsField.setValue(String.valueOf(view.getRefreshSeconds())); refreshSecondsField.setImmediate(true); refreshSecondsField.setCaption("Refresh seconds"); refreshSecondsField.setDescription("Refresh duration in seconds"); refreshSecondsField.addValidator(new AbstractStringValidator("Only numbers allowed here") { @Override protected boolean isValidValue(String s) { int number; try { number = Integer.parseInt(s); } catch (NumberFormatException numberFormatException) { return false; } return (number >= 0); } }); /** * Columns table */ final Table columnsTable = new Table(); columnsTable.setSortEnabled(false); columnsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<ColumnDef> columns = new BeanItemContainer<ColumnDef>(ColumnDef.class, view.getColumns()); final Map<ColumnDef, Integer> columnOrder = new HashMap<>(); int c = 0; for (ColumnDef columnDef : view.getColumns()) { columnOrder.put(columnDef, c++); } columnsTable.setContainerDataSource(columns); columnsTable.setVisibleColumns("label"); columnsTable.setColumnHeader("label", "Columns"); columnsTable.setColumnExpandRatio("label", 1.0f); columnsTable.setSelectable(true); columnsTable.setMultiSelect(false); /** * Create custom sorter */ columns.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (columnOrder.get(o1).intValue() == columnOrder.get(o2).intValue()) { return 0; } else { if (columnOrder.get(o1).intValue() > columnOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button columnsAddButton = new Button("Add"); columnsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), new ColumnDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, columnOrder.size()); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); columnsAddButton.setEnabled(true); columnsAddButton.setStyleName("small"); columnsAddButton.setDescription("Add column"); columnsAddButton.setEnabled(true); final Button columnsEditButton = new Button("Edit"); columnsEditButton.setEnabled(true); columnsEditButton.setStyleName("small"); columnsEditButton.setDescription("Edit column"); columnsEditButton.setEnabled(false); columnsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, columnsTable.getItemIds(), (ColumnDef) columnsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { ColumnDef columnToBeReplaced = (ColumnDef) columnsTable.getValue(); int index = columnOrder.get(columnToBeReplaced); columns.removeItem(columnToBeReplaced); columnOrder.remove(columnToBeReplaced); columns.addItem((ColumnDef) def); columnOrder.put((ColumnDef) def, index); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); } })); } }); final Button columnsRemoveButton = new Button("Remove"); columnsRemoveButton.setEnabled(true); columnsRemoveButton.setStyleName("small"); columnsRemoveButton.setDescription("Remove column"); columnsRemoveButton.setEnabled(false); columnsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { columnsTable.unselect(columnDef); columns.removeItem(columnDef); } columnsTable.refreshRowCache(); } }); final Button columnUpButton = new Button(); columnUpButton.setStyleName("small"); columnUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); columnUpButton.setDescription("Move this a column entry one position up"); columnUpButton.setEnabled(false); columnUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex - 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex - 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); final Button columnDownButton = new Button(); columnDownButton.setStyleName("small"); columnDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); columnDownButton.setDescription("Move this a column entry one position down"); columnDownButton.setEnabled(false); columnDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ColumnDef columnDef = (ColumnDef) columnsTable.getValue(); if (columnDef != null) { int columnDefIndex = columnOrder.get(columnDef); ColumnDef columnDefToSwap = null; for (Map.Entry<ColumnDef, Integer> entry : columnOrder.entrySet()) { if (entry.getValue().intValue() == columnDefIndex + 1) { columnDefToSwap = entry.getKey(); break; } } if (columnDefToSwap != null) { columnsTable.unselect(columnDef); columnOrder.remove(columnDef); columnOrder.remove(columnDefToSwap); columnOrder.put(columnDef, columnDefIndex + 1); columnOrder.put(columnDefToSwap, columnDefIndex); columns.sort(new Object[] { "label" }, new boolean[] { true }); columnsTable.refreshRowCache(); columnsTable.select(columnDef); } } } }); columnsTable.setSizeFull(); columnUpButton.setSizeFull(); columnDownButton.setSizeFull(); columnsAddButton.setSizeFull(); columnsEditButton.setSizeFull(); columnsRemoveButton.setSizeFull(); columnsTable.setImmediate(true); /** * ...and a listener */ columnsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (columnsTable.getValue() != null); columnsRemoveButton.setEnabled(somethingSelected); columnsEditButton.setEnabled(somethingSelected); columnsAddButton.setEnabled(true); columnUpButton .setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() > 0); columnDownButton.setEnabled(somethingSelected && columnOrder.get(columnsTable.getValue()).intValue() < columnOrder.size() - 1); } }); /** * Rows table */ final Table rowsTable = new Table(); rowsTable.setSortEnabled(false); rowsTable.setWidth(25, Unit.PERCENTAGE); final BeanItemContainer<RowDef> rows = new BeanItemContainer<RowDef>(RowDef.class, view.getRows()); final Map<RowDef, Integer> rowOrder = new HashMap<>(); int r = 0; for (RowDef rowDef : view.getRows()) { rowOrder.put(rowDef, r++); } rowsTable.setContainerDataSource(rows); rowsTable.setVisibleColumns("label"); rowsTable.setColumnHeader("label", "Rows"); rowsTable.setColumnExpandRatio("label", 1.0f); rowsTable.setSelectable(true); rowsTable.setMultiSelect(false); /** * Create custom sorter */ rows.setItemSorter(new DefaultItemSorter() { @Override public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } else { return -1; } } if (o2 == null) { return 1; } if (rowOrder.get(o1).intValue() == rowOrder.get(o2).intValue()) { return 0; } else { if (rowOrder.get(o1).intValue() > rowOrder.get(o2).intValue()) { return 1; } else { return -1; } } } }); /** * Adding the buttons... */ final Button rowsAddButton = new Button("Add"); rowsAddButton.setEnabled(true); rowsAddButton.setStyleName("small"); rowsAddButton.setDescription("Add row"); rowsAddButton.setEnabled(true); rowsAddButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), new RowDef(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { rows.addItem((RowDef) def); rowOrder.put((RowDef) def, rowOrder.size()); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsEditButton = new Button("Edit"); rowsEditButton.setEnabled(true); rowsEditButton.setStyleName("small"); rowsEditButton.setDescription("Edit row"); rowsEditButton.setEnabled(false); rowsEditButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { getUI().addWindow(new SurveillanceViewConfigurationCategoryWindow(surveillanceViewService, rowsTable.getItemIds(), (RowDef) rowsTable.getValue(), new SurveillanceViewConfigurationCategoryWindow.SaveActionListener() { @Override public void save(Def def) { RowDef rowToBeReplaced = (RowDef) rowsTable.getValue(); int index = rowOrder.get(rowToBeReplaced); rows.removeItem(rowToBeReplaced); rowOrder.remove(rowToBeReplaced); rows.addItem((RowDef) def); rowOrder.put((RowDef) def, index); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); } })); } }); final Button rowsRemoveButton = new Button("Remove"); rowsRemoveButton.setEnabled(true); rowsRemoveButton.setStyleName("small"); rowsRemoveButton.setDescription("Remove row"); rowsRemoveButton.setEnabled(false); rowsRemoveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { rowsTable.unselect(rowDef); rows.removeItem(rowDef); } rowsTable.refreshRowCache(); } }); final Button rowUpButton = new Button(); rowUpButton.setStyleName("small"); rowUpButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png")); rowUpButton.setDescription("Move this a row entry one position up"); rowUpButton.setEnabled(false); rowUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex - 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex - 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); final Button rowDownButton = new Button(); rowDownButton.setStyleName("small"); rowDownButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png")); rowDownButton.setDescription("Move this a row entry one position down"); rowDownButton.setEnabled(false); rowDownButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { RowDef rowDef = (RowDef) rowsTable.getValue(); if (rowDef != null) { int rowDefIndex = rowOrder.get(rowDef); RowDef rowDefToSwap = null; for (Map.Entry<RowDef, Integer> entry : rowOrder.entrySet()) { if (entry.getValue().intValue() == rowDefIndex + 1) { rowDefToSwap = entry.getKey(); break; } } if (rowDefToSwap != null) { rowsTable.unselect(rowDef); rowOrder.remove(rowDef); rowOrder.remove(rowDefToSwap); rowOrder.put(rowDef, rowDefIndex + 1); rowOrder.put(rowDefToSwap, rowDefIndex); rows.sort(new Object[] { "label" }, new boolean[] { true }); rowsTable.refreshRowCache(); rowsTable.select(rowDef); } } } }); rowsTable.setSizeFull(); rowUpButton.setSizeFull(); rowDownButton.setSizeFull(); rowsAddButton.setSizeFull(); rowsEditButton.setSizeFull(); rowsRemoveButton.setSizeFull(); rowsTable.setImmediate(true); /** * ...and a listener */ rowsTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean somethingSelected = (rowsTable.getValue() != null); rowsRemoveButton.setEnabled(somethingSelected); rowsEditButton.setEnabled(somethingSelected); rowsAddButton.setEnabled(true); rowUpButton.setEnabled(somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() > 0); rowDownButton.setEnabled( somethingSelected && rowOrder.get(rowsTable.getValue()).intValue() < rowOrder.size() - 1); } }); /** * Create form layouts... */ FormLayout baseFormLayout = new FormLayout(); baseFormLayout.addComponent(titleField); baseFormLayout.addComponent(refreshSecondsField); FormLayout columnTableFormLayout = new FormLayout(); columnTableFormLayout.addComponent(columnsAddButton); columnTableFormLayout.addComponent(columnsEditButton); columnTableFormLayout.addComponent(columnsRemoveButton); columnTableFormLayout.addComponent(columnUpButton); columnTableFormLayout.addComponent(columnDownButton); FormLayout rowTableFormLayout = new FormLayout(); rowTableFormLayout.addComponent(rowsAddButton); rowTableFormLayout.addComponent(rowsEditButton); rowTableFormLayout.addComponent(rowsRemoveButton); rowTableFormLayout.addComponent(rowUpButton); rowTableFormLayout.addComponent(rowDownButton); /** * Adding the different {@link com.vaadin.ui.FormLayout} instances to a {@link com.vaadin.ui.GridLayout} */ baseFormLayout.setMargin(true); columnTableFormLayout.setMargin(true); rowTableFormLayout.setMargin(true); GridLayout gridLayout = new GridLayout(); gridLayout.setSizeFull(); gridLayout.setColumns(4); gridLayout.setRows(1); gridLayout.setMargin(true); gridLayout.addComponent(rowsTable); gridLayout.addComponent(rowTableFormLayout); gridLayout.addComponent(columnsTable); gridLayout.addComponent(columnTableFormLayout); gridLayout.setColumnExpandRatio(1, 0.5f); gridLayout.setColumnExpandRatio(2, 1.0f); gridLayout.setColumnExpandRatio(3, 0.5f); gridLayout.setColumnExpandRatio(4, 1.0f); /** * Creating the vertical layout... */ VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(baseFormLayout); verticalLayout.addComponent(gridLayout); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setMargin(true); horizontalLayout.setSpacing(true); horizontalLayout.setWidth(100, Unit.PERCENTAGE); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing properties"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); horizontalLayout.addComponent(cancel); horizontalLayout.setExpandRatio(cancel, 1); horizontalLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!titleField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please use an unique title", Notification.Type.ERROR_MESSAGE); return; } if (!refreshSecondsField.isValid()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "Please enter a valid number in the \"Refresh seconds\" field", Notification.Type.ERROR_MESSAGE); return; } if (columns.getItemIds().isEmpty() || rows.getItemIds().isEmpty()) { ((SurveillanceViewsConfigUI) getUI()).notifyMessage("Error", "You must define at least one row category and one column category", Notification.Type.ERROR_MESSAGE); return; } View finalView = new View(); for (ColumnDef columnDef : columns.getItemIds()) { finalView.getColumns().add(columnDef); } for (RowDef rowDef : rows.getItemIds()) { finalView.getRows().add(rowDef); } finalView.setName(titleField.getValue()); finalView.setRefreshSeconds(Integer.parseInt(refreshSecondsField.getValue())); saveActionListener.save(finalView); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); horizontalLayout.addComponent(ok); verticalLayout.addComponent(horizontalLayout); setContent(verticalLayout); }