public void onSuccessfulLogin2() { this.context = (WebApplicationContext) getContext(); context .getHttpSession() .setAttribute("session", HibernateUtil.getSessionFactory().openSession()); context.getHttpSession().setAttribute("userName", userCurrent.getName()); controlUserPermissions = new ControlUserPermissions(userCurrent, context); String propName = this.getProperty("pathEntityOrder"); String propPath = this.getContext().getBaseDirectory().getAbsolutePath() + File.separator + propName; HibernateUtil.getEntityOrder(propPath); /** * ******************************************** Cabecera * ****************************************************** */ HorizontalLayout headHorizontalLayout = new HorizontalLayout(); headHorizontalLayout.setWidth("100%"); headHorizontalLayout.setHeight("80"); logoPNG = new Embedded(null, new ThemeResource("images/logo.png")); logoPNG.setWidth("140"); logoPNG.setHeight("60"); headHorizontalLayout.addComponent(logoPNG); headHorizontalLayout.setComponentAlignment(logoPNG, Alignment.MIDDLE_LEFT); headHorizontalLayout.setExpandRatio(logoPNG, 3); UserTab userTab = new UserTab(this); headHorizontalLayout.addComponent(userTab); headHorizontalLayout.setComponentAlignment(userTab, Alignment.MIDDLE_RIGHT); headHorizontalLayout.setExpandRatio(userTab, 1); /** * ********************************************************************* * *************************************** */ /** * ******************************************** Barra Menú * **************************************************** */ toolbar = new YacareToolbar(this); /** * ********************************************************************* * *************************************** */ /** * ******************************************** Cuerpo de página * ********************************************** */ bodyPageVerticalLayout = new VerticalLayout(); bodyPageVerticalLayout.addComponent(headHorizontalLayout); bodyPageVerticalLayout.addComponent(toolbar); YacareFooter footer = new YacareFooter(); bodyPageVerticalLayout.addComponent(footer); bodyPageVerticalLayout.setComponentAlignment(footer, Alignment.BOTTOM_CENTER); /** * ********************************************************************* * *************************************** */ getMainWindow().setContent(bodyPageVerticalLayout); }
private VaadinCollapsiblePhysicalAttributeConfirmActualsFormSectionHeader addFormSection( PhysicalAttributeConfirmActualsFieldSetComponent fieldSet) { GridLayout gridLayout = new GridLayout(3, 1); gridLayout.setWidth("70%"); gridLayout.setSpacing(true); gridLayout.setStyleName("conx-entity-editor-form"); gridLayout.setMargin(true, true, false, true); Embedded placeholder = new Embedded(); placeholder.setHeight("22px"); placeholder.setWidth("1px"); GridLayout captionLayout = new GridLayout(1, 1); captionLayout.setWidth("100%"); captionLayout.setSpacing(true); captionLayout.addComponent(placeholder, 0, 0, 0, 0); GridLayout expectedLayout = new GridLayout(2, 1); expectedLayout.setWidth("100%"); expectedLayout.setSpacing(true); expectedLayout.addComponent(new VaadinConfirmActualsFormSectionHeader("Expected"), 0, 0, 1, 0); GridLayout actualLayout = new GridLayout(2, 1); actualLayout.setWidth("100%"); actualLayout.setSpacing(true); actualLayout.addComponent(new VaadinConfirmActualsFormSectionHeader("Actual"), 0, 0, 1, 0); gridLayout.addComponent(captionLayout, 0, 0, 0, 0); gridLayout.addComponent(expectedLayout, 1, 0, 1, 0); gridLayout.addComponent(actualLayout, 2, 0, 2, 0); gridLayout.setColumnExpandRatio(0, 0.166f); gridLayout.setColumnExpandRatio(1, 0.417f); gridLayout.setColumnExpandRatio(2, 0.417f); VaadinCollapsiblePhysicalAttributeConfirmActualsFormSectionHeader header = new VaadinCollapsiblePhysicalAttributeConfirmActualsFormSectionHeader(fieldSet, gridLayout); innerLayout.addComponent(header); innerLayout.addComponent(header.getLayout()); headers.put(fieldSet, header); return header; }
protected void addProcessImage() { ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(processDefinition.getId()); // Only show when graphical notation is defined if (processDefinitionEntity != null) { boolean didDrawImage = false; if (ExplorerApp.get().isUseJavascriptDiagram()) { try { final InputStream definitionStream = repositoryService.getResourceAsStream( processDefinition.getDeploymentId(), processDefinition.getResourceName()); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); if (bpmnModel.getFlowLocationMap().size() > 0) { int maxX = 0; int maxY = 0; for (String key : bpmnModel.getLocationMap().keySet()) { GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key); double elementX = graphicInfo.getX() + graphicInfo.getWidth(); if (maxX < elementX) { maxX = (int) elementX; } double elementY = graphicInfo.getY() + graphicInfo.getHeight(); if (maxY < elementY) { maxY = (int) elementY; } } Panel imagePanel = new Panel(); // using panel for scrollbars imagePanel.addStyleName(Reindeer.PANEL_LIGHT); imagePanel.setWidth(100, UNITS_PERCENTAGE); imagePanel.setHeight(100, UNITS_PERCENTAGE); URL explorerURL = ExplorerApp.get().getURL(); URL url = new URL( explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId() + "&processInstanceId=" + processInstance.getId()); Embedded browserPanel = new Embedded("", new ExternalResource(url)); browserPanel.setType(Embedded.TYPE_BROWSER); browserPanel.setWidth(maxX + 350 + "px"); browserPanel.setHeight(maxY + 220 + "px"); HorizontalLayout panelLayoutT = new HorizontalLayout(); panelLayoutT.setSizeUndefined(); imagePanel.setContent(panelLayoutT); imagePanel.addComponent(browserPanel); panelLayout.addComponent(imagePanel); didDrawImage = true; } } catch (Exception e) { LOGGER.error("Error loading process diagram component", e); } } if (didDrawImage == false && processDefinitionEntity.isGraphicalNotationDefined()) { StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder() .buildStreamResource(processInstance, repositoryService, runtimeService); if (diagram != null) { Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM)); header.addStyleName(ExplorerLayout.STYLE_H3); header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK); header.addStyleName(ExplorerLayout.STYLE_NO_LINE); panelLayout.addComponent(header); Embedded embedded = new Embedded(null, diagram); embedded.setType(Embedded.TYPE_IMAGE); embedded.setSizeUndefined(); Panel imagePanel = new Panel(); // using panel for scrollbars imagePanel.setScrollable(true); imagePanel.addStyleName(Reindeer.PANEL_LIGHT); imagePanel.setWidth(100, UNITS_PERCENTAGE); imagePanel.setHeight(100, UNITS_PERCENTAGE); HorizontalLayout panelLayoutT = new HorizontalLayout(); panelLayoutT.setSizeUndefined(); imagePanel.setContent(panelLayoutT); imagePanel.addComponent(embedded); panelLayout.addComponent(imagePanel); } } } }
public void onSuccessfulLogin() { userCurrent = ((User) getUser()); this.context = (WebApplicationContext) getContext(); context .getHttpSession() .setAttribute("session", HibernateUtil.getSessionFactory().openSession()); context.getHttpSession().setAttribute("userName", userCurrent.getName()); context.getHttpSession().setAttribute("user", userCurrent); controlUserPermissions = new ControlUserPermissions(userCurrent, context); String propName = this.getProperty("pathEntityOrder"); String propPath = this.getContext().getBaseDirectory().getAbsolutePath() + File.separator + propName; HibernateUtil.getEntityOrder(propPath); // cargar foto PhysicalPerson physicalPerson = userCurrent.getPhysicalPerson(); String fileName = ""; Embedded embedded = null; if (physicalPerson != null && physicalPerson.getDocumentObject() != null && physicalPerson.getDocumentObject().getName() != null) { fileName = physicalPerson.getDocumentObject().getName(); if (checkFile( fileName, FactoryI18nManager.getI18nManager().getPathMessages("url.path.upload.photos") + File.separatorChar)) { FileResource resource = new FileResource( new File( (FactoryI18nManager.getI18nManager().getPathMessages("url.path.upload.photos") + File.separatorChar + fileName)), this); embedded = new Embedded(null, resource); } else { embedded = new Embedded(null, new ThemeResource("images/apps/persona.gif")); } } else { embedded = new Embedded(null, new ThemeResource("images/apps/persona.gif")); } embedded.setWidth("63"); embedded.setHeight("100%"); logoHeaderPNG = new Embedded(null, new ThemeResource("images/apps/yacare.png")); logoHeaderPNG.setWidth("70"); logoHeaderPNG.setHeight("50"); descriptionPNG = new Embedded(null, new ThemeResource("images/apps/yacareDescription.png")); descriptionPNG.setWidth("420"); descriptionPNG.setHeight("20"); HorizontalLayout logosLayout = new HorizontalLayout(); // logosLayout.setSpacing(true); logosLayout.addComponent(logoHeaderPNG); logosLayout.setComponentAlignment(logoHeaderPNG, Alignment.MIDDLE_CENTER); logosLayout.addComponent(descriptionPNG); logosLayout.setComponentAlignment(descriptionPNG, Alignment.MIDDLE_CENTER); logosLayout.setMargin(false, false, false, false); UserTabHeader userTab = new UserTabHeader( userCurrent.getPhysicalPerson().getLastName() + ", " + userCurrent.getPhysicalPerson().getName(), userCurrent.getName(), embedded, getURL().getPath()); /** * ******************************************** Cabecera * ****************************************************** */ HorizontalLayout headHorizontalLayout = new HorizontalLayout(); headHorizontalLayout.setWidth("100%"); headHorizontalLayout.setHeight("50"); headHorizontalLayout.addComponent(logosLayout); headHorizontalLayout.setComponentAlignment(logosLayout, Alignment.MIDDLE_LEFT); headHorizontalLayout.setExpandRatio(logosLayout, 3); headHorizontalLayout.addComponent(userTab); headHorizontalLayout.setComponentAlignment(userTab, Alignment.MIDDLE_RIGHT); headHorizontalLayout.setExpandRatio(userTab, 1); /** * ************************************************************************************************************ */ /** * ******************************************** Barra Menú * **************************************************** */ toolbar = new YacareToolbar(this); /** * ************************************************************************************************************ */ /** * ******************************************** Footer * **************************************************** */ YacareFooter footer = new YacareFooter(); /** * ******************************************** * **************************************************** */ VerticalLayout vl = new VerticalLayout(); vl.setWidth("100%"); vl.setSpacing(false); vl.setMargin(false); vl.addComponent(headHorizontalLayout); vl.addComponent(toolbar); /** * ******************************************** Cuerpo de página * ********************************************** */ verticalLayout = new VerticalLayout(); verticalLayout.setSpacing(false); verticalLayout.setMargin(false); verticalLayout.setSizeFull(); verticalLayout.addComponent(vl); verticalLayout.setComponentAlignment(vl, Alignment.TOP_CENTER); verticalLayout.addComponent(footer); verticalLayout.setComponentAlignment(footer, Alignment.BOTTOM_CENTER); /** * ************************************************************************************************************ */ getMainWindow().setContent(verticalLayout); }
@SuppressWarnings("serial") @Override public void editPhoto(final byte[] imageData) { this.removeAllComponents(); LOG.debug("Receive avatar upload with size: " + imageData.length); try { originalImage = ImageIO.read(new ByteArrayInputStream(imageData)); } catch (IOException e) { throw new UserInvalidInputException("Invalid image type"); } originalImage = ImageUtil.scaleImage(originalImage, 650, 650); MHorizontalLayout previewBox = new MHorizontalLayout() .withSpacing(true) .withMargin(new MarginInfo(false, true, true, false)) .withWidth("100%"); Resource defaultPhoto = UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 100); previewImage = new Embedded(null, defaultPhoto); previewImage.setWidth("100px"); previewBox.with(previewImage).withAlign(previewImage, Alignment.TOP_LEFT); VerticalLayout previewBoxRight = new VerticalLayout(); previewBoxRight.setMargin(new MarginInfo(false, true, false, true)); Label lbPreview = new Label( "<p style='margin: 0px;'><strong>To the left is what your profile photo will look like.</strong></p>" + "<p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. " + "When you are happy with your photo, click the “Accept“ button.</p>", ContentMode.HTML); previewBoxRight.addComponent(lbPreview); MHorizontalLayout controlBtns = new MHorizontalLayout(); controlBtns.setSizeUndefined(); Button cancelBtn = new Button( AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { EventBusFactory.getInstance() .post(new ProfileEvent.GotoProfileView(ProfilePhotoUploadViewImpl.this, null)); } }); cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK); Button acceptBtn = new Button( AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (scaleImageData != null && scaleImageData.length > 0) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData)); UserAvatarService userAvatarService = ApplicationContextUtil.getSpringBean(UserAvatarService.class); userAvatarService.uploadAvatar( image, AppContext.getUsername(), AppContext.getUserAvatarId()); Page.getCurrent().getJavaScript().execute("window.location.reload();"); } catch (IOException e) { throw new MyCollabException("Error when saving user avatar", e); } } } }); acceptBtn.setStyleName(UIConstants.BUTTON_ACTION); acceptBtn.setIcon(FontAwesome.CHECK); controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT); previewBoxRight.addComponent(controlBtns); previewBoxRight.setComponentAlignment(controlBtns, Alignment.TOP_LEFT); previewBox.addComponent(previewBoxRight); previewBox.setExpandRatio(previewBoxRight, 1.0f); this.addComponent(previewBox); CssLayout cropBox = new CssLayout(); cropBox.addStyleName(UIConstants.PHOTO_CROPBOX); cropBox.setWidth("100%"); VerticalLayout currentPhotoBox = new VerticalLayout(); Resource resource = new ByteArrayImageResource(ImageUtil.convertImageToByteArray(originalImage), "image/png"); CropField cropField = new CropField(resource); cropField.setImmediate(true); cropField.setSelectionAspectRatio(1.0f); cropField.addValueChangeListener( new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { VCropSelection newSelection = (VCropSelection) event.getProperty().getValue(); int x1 = newSelection.getXTopLeft(); int y1 = newSelection.getYTopLeft(); int x2 = newSelection.getXBottomRight(); int y2 = newSelection.getYBottomRight(); if (x2 > x1 && y2 > y1) { BufferedImage subImage = originalImage.getSubimage(x1, y1, (x2 - x1), (y2 - y1)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); try { ImageIO.write(subImage, "png", outStream); scaleImageData = outStream.toByteArray(); displayPreviewImage(); } catch (IOException e) { LOG.error("Error while scale image: ", e); } } } }); currentPhotoBox.setWidth("650px"); currentPhotoBox.setHeight("650px"); currentPhotoBox.addComponent(cropField); cropBox.addComponent(currentPhotoBox); this.addComponent(previewBox); this.addComponent(cropBox); this.setExpandRatio(cropBox, 1.0f); }
/** @param el */ public BookImage(Books el, String user) { super(); this.Book = el; this.setStyleName("cells"); this.setHeight("250px"); this.setWidth("200px"); rating.setAnimated(true); rating.setCaption(null); rating.setMaxValue(5); rating.setStyleName("rating"); rating.setReadOnly(true); rating_my.setAnimated(true); rating_my.setCaption(null); rating_my.setMaxValue(5); rating_my.setStyleName("rating_my"); IRaitingService iRaitingService = new IRaitingService(); try { double rate = iRaitingService.getRaiting(el.getId()); rating.setReadOnly(false); rating.setValue(rate); rating.setReadOnly(true); double myrate = iRaitingService.getRaiting(user, el.getId()); rating_my.setValue(myrate); } catch (SQLException e) { e.printStackTrace(); } rating_my.addValueChangeListener( e -> { try { Rating rat = iRaitingService.getUser( getUI().getSession().getAttribute("user").toString(), el.getId()); rat.setRaiting(rating_my.getValue()); iRaitingService.update(rat); double rate = iRaitingService.getRaiting(el.getId()); rating.setReadOnly(false); rating.setValue(rate); rating.setReadOnly(true); new Notification(String.valueOf(rate), Notification.Type.TRAY_NOTIFICATION) .show(Page.getCurrent()); } catch (SQLException e1) { e1.printStackTrace(); } }); rating_layout.addComponent(rating); rating_layout.addComponent(rating_my); rating_layout.setComponentAlignment(rating, Alignment.MIDDLE_LEFT); rating_layout.setComponentAlignment(rating_my, Alignment.MIDDLE_LEFT); rating_layout.setStyleName("ratinglayout"); imageEmbedded.setSource(new FileResource(new File(Book.getImage()))); title.setValue(Book.getTitle()); author.setValue(Book.getAuthor()); if (Book.getFile().isEmpty()) buttonDownload.setEnabled(false); buttonDownload.setWidth("80%"); imageEmbedded.setWidth("100%"); imageEmbedded.setHeight("100%"); title.setWidth(null); author.setWidth(null); VerticalLayout bodyLayout = new VerticalLayout(title, author, imageEmbedded); bodyLayout.setExpandRatio(title, 12); bodyLayout.setExpandRatio(author, 8); bodyLayout.setExpandRatio(imageEmbedded, 80); bodyLayout.setSizeFull(); bodyLayout.setComponentAlignment(title, Alignment.MIDDLE_CENTER); bodyLayout.setComponentAlignment(author, Alignment.MIDDLE_CENTER); bodyLayout.setComponentAlignment(imageEmbedded, Alignment.MIDDLE_CENTER); buttonDownload.setStyleName("super-button"); title.setStyleName("name-label"); author.setStyleName("author-label"); this.addComponent(rating_layout); this.addComponent(bodyLayout); this.addComponent(buttonDownload); this.setComponentAlignment(rating_layout, Alignment.TOP_CENTER); this.setComponentAlignment(bodyLayout, Alignment.TOP_CENTER); this.setComponentAlignment(buttonDownload, Alignment.BOTTOM_CENTER); this.setExpandRatio(rating_layout, 5); this.setExpandRatio(bodyLayout, 85); this.setExpandRatio(buttonDownload, 10); StreamResource sr = getStream(); FileDownloader fileDownloader = new FileDownloader(sr); fileDownloader.extend(buttonDownload); bodyLayout.addLayoutClickListener( e -> { BookWin win = new BookWin(this.Book); UI.getCurrent().addWindow(win); }); }
/** Updates the layout. */ public void update() { removeAllComponents(); if (current == null) return; DBManager.getCommunicator().refresh(current); List<Squad> squads = current.getSquads(); List<Vehicle> vehicles = current.getVehicles(); Application app = getApplication(); for (final Squad squad : squads) { Panel panel = new Panel(); addComponent(panel); HorizontalLayout horContent = new HorizontalLayout(); horContent.setMargin(true); horContent.setSpacing(true); horContent.setWidth("100%"); panel.setContent(horContent); Embedded emb = new Embedded(); emb.setSource(new ClassResource("res/tac/trupp.png", app)); emb.setWidth("50px"); emb.setHeight("30px"); horContent.addComponent(emb); VerticalLayout verContent = new VerticalLayout(); verContent.setSpacing(true); horContent.addComponent(verContent); horContent.setExpandRatio(verContent, 1f); Label lblName = new Label(squad.getName()); lblName.setStyleName(Reindeer.LABEL_H2); verContent.addComponent(lblName); verContent.addComponent(new Label(squad.getType().getName())); List<Helper> helpers = squad.getHelpers(); for (Helper helper : helpers) { verContent.addComponent(new Label("<hr />", Label.CONTENT_XHTML)); verContent.addComponent(new Label(helper.getFirstName() + " " + helper.getLastName())); Label lblTel = new Label(helper.getTelNumber()); lblTel.setStyleName(Reindeer.LABEL_SMALL); verContent.addComponent(lblTel); String quals = ""; List<Qualification> qs = helper.getQualifications(); for (int i = 1; i < qs.size(); i++) quals += qs.get(i - 1) + ", "; Label lblQuals = new Label(quals + qs.get(qs.size() - 1)); lblQuals.setStyleName(Reindeer.LABEL_SMALL); verContent.addComponent(lblQuals); } Slider slider = new Slider(0, 9); slider.setOrientation(Slider.ORIENTATION_VERTICAL); slider.setImmediate(true); slider.addListener( new ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { int state = ((Double) event.getProperty().getValue()).intValue(); squad.setState(state); Long id = squad.getId(); works.getItem(id).getItemProperty("state").setValue(state); boolean visible = units.areUnavailableVisible(); units.setUnavailableVisible(true); units.getItem(id).getItemProperty("state").setValue(state); units.setUnavailableVisible(visible); } }); try { slider.setValue(squad.getState()); } catch (Exception e) { } horContent.addComponent(slider); } for (final Vehicle vehicle : vehicles) { Panel panel = new Panel(); addComponent(panel); HorizontalLayout horContent = new HorizontalLayout(); horContent.setMargin(true); horContent.setSpacing(true); horContent.setWidth("100%"); panel.setContent(horContent); Embedded emb = new Embedded(); File img = vehicle.getImage(); if (img == null) { emb.setSource(new ClassResource("res/tac/fahrzeug.png", app)); } else { emb.setSource(new FileResource(img, app)); } emb.setWidth("50px"); horContent.addComponent(emb); VerticalLayout verContent = new VerticalLayout(); verContent.setSpacing(true); horContent.addComponent(verContent); horContent.setExpandRatio(verContent, 1f); Label lblName = new Label(vehicle.getName()); lblName.setStyleName(Reindeer.LABEL_H2); verContent.addComponent(lblName); verContent.addComponent(new Label(vehicle.getType().getName())); List<Helper> helpers = vehicle.getHelpers(); for (Helper helper : helpers) { verContent.addComponent(new Label("<hr />", Label.CONTENT_XHTML)); verContent.addComponent(new Label(helper.getFirstName() + " " + helper.getLastName())); Label lblTel = new Label(helper.getTelNumber()); lblTel.setStyleName(Reindeer.LABEL_SMALL); verContent.addComponent(lblTel); String quals = ""; List<Qualification> qs = helper.getQualifications(); for (int i = 1; i < qs.size(); i++) quals += qs.get(i - 1) + ", "; Label lblQuals = new Label(quals + qs.get(qs.size() - 1)); lblQuals.setStyleName(Reindeer.LABEL_SMALL); verContent.addComponent(lblQuals); } Slider slider = new Slider(0, 9); slider.setOrientation(Slider.ORIENTATION_VERTICAL); slider.setImmediate(true); slider.addListener( new ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { int state = ((Double) event.getProperty().getValue()).intValue(); vehicle.setState(state); Long id = vehicle.getId(); works.getItem(id).getItemProperty("state").setValue(state); boolean visible = units.areUnavailableVisible(); units.setUnavailableVisible(true); units.getItem(id).getItemProperty("state").setValue(state); units.setUnavailableVisible(visible); } }); try { slider.setValue(vehicle.getState()); } catch (Exception e) { } horContent.addComponent(slider); } }