List of usage examples for com.vaadin.ui VerticalLayout setComponentAlignment
@Override public void setComponentAlignment(Component childComponent, Alignment alignment)
From source file:com.mycollab.module.user.ui.components.ImagePreviewCropWindow.java
License:Open Source License
public ImagePreviewCropWindow(final ImageSelectionCommand imageSelectionCommand, final byte[] imageData) { super(UserUIContext.getMessage(ShellI18nEnum.OPT_PREVIEW_EDIT_IMAGE)); MVerticalLayout content = new MVerticalLayout(); withModal(true).withResizable(false).withWidth("700px").withCenter().withContent(content); try {/*ww w .j a v a 2s. c o m*/ 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().withMargin(new MarginInfo(false, true, true, false)) .withFullWidth(); previewPhoto = new VerticalLayout(); previewPhoto.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); previewPhoto.setWidth("100px"); previewBox.with(previewPhoto).withAlign(previewPhoto, Alignment.TOP_LEFT); VerticalLayout previewBoxTitle = new VerticalLayout(); previewBoxTitle.setMargin(new MarginInfo(false, true, false, true)); previewBoxTitle .addComponent(ELabel.html(UserUIContext.getMessage(ShellI18nEnum.OPT_IMAGE_EDIT_INSTRUCTION))); MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL), clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION); MButton acceptBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), clickEvent -> { if (scaleImageData != null && scaleImageData.length > 0) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData)); imageSelectionCommand.process(image); close(); } catch (IOException e) { throw new MyCollabException("Error when saving user avatar", e); } } }).withIcon(FontAwesome.CHECK).withStyleName(WebThemes.BUTTON_ACTION); MHorizontalLayout controlBtns = new MHorizontalLayout(acceptBtn, cancelBtn); previewBoxTitle.addComponent(controlBtns); previewBoxTitle.setComponentAlignment(controlBtns, Alignment.TOP_LEFT); previewBox.with(previewBoxTitle).expand(previewBoxTitle); CssLayout cropBox = new CssLayout(); 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(valueChangeEvent -> { VCropSelection newSelection = (VCropSelection) valueChangeEvent.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("520px"); currentPhotoBox.setHeight("470px"); currentPhotoBox.addComponent(cropField); cropBox.addComponent(currentPhotoBox); content.with(previewBox, ELabel.hr(), cropBox); displayPreviewImage(); }
From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java
License:Apache License
/** * Create delete tab in the accordion.// w w w. j av a 2 s .com * * @return the component. */ @SuppressWarnings("serial") private final AbstractComponent createDelete() { /* root layout */ final VerticalLayout layout = new VerticalLayout(); layout.setSizeFull(); layout.setMargin(true); layout.setSpacing(true); final Label label = new Label("Deleting a device can be done, only if it is de-activated."); layout.addComponent(label); label.setWidth(null); layout.setComponentAlignment(label, Alignment.MIDDLE_CENTER); final Button deleteButton = new Button("Delete"); layout.addComponent(deleteButton); layout.setComponentAlignment(deleteButton, Alignment.BOTTOM_CENTER); deleteButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { final DeviceDeleteWindow deleteWindow = new DeviceDeleteWindow(model.getItemUuid()); deleteWindow.add(model); } catch (final Exception e) { LOGGER.error("Can not delete device: ", e); } } }); return layout; }
From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java
License:Apache License
/** * Create the component to take a snapshot. * /*w w w. j a v a 2 s . co m*/ * @return the component */ @SuppressWarnings("serial") private final AbstractComponent createTakeSnap() { final VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true); layout.setMargin(true); final FormLayout takeSnapLayout = new FormLayout(); takeSnapLayout.setMargin(true); takeSnapLayout.setImmediate(true); takeSnapLayout.setWidth(null); layout.addComponent(takeSnapLayout); layout.setComponentAlignment(takeSnapLayout, Alignment.MIDDLE_CENTER); // Enter name final TextField vvrName = new TextField("Name", ""); takeSnapLayout.addComponent(vvrName); // take button final Button take = new Button("Take snapshot"); layout.addComponent(take); layout.setComponentAlignment(take, Alignment.MIDDLE_CENTER); take.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { model.takeDeviceSnapshot(vvrName.getValue()); Notification.show("New snapshot created", Notification.Type.TRAY_NOTIFICATION); } catch (final Exception e) { final ErrorWindow err = new ErrorWindow("Snapshot not taken: " + e.getMessage()); err.add(model); } } }); return layout; }
From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java
License:Apache License
/** * Create the component to activate/deactivate a device. * /*from w w w. j a v a 2s . c o m*/ * @return the component */ @SuppressWarnings("serial") private final AbstractComponent createActivate() { final VerticalLayout rootlayout = new VerticalLayout(); rootlayout.setMargin(true); rootlayout.setSpacing(true); final OptionGroup activate = new OptionGroup("Select an option: "); rootlayout.addComponent(activate); rootlayout.setComponentAlignment(activate, Alignment.MIDDLE_CENTER); activate.setNullSelectionAllowed(false); activate.setHtmlContentAllowed(true); activate.setImmediate(true); activate.addItem(DEACTIVATE); activate.addItem(RWACTIVATE); activate.addItem(ROACTIVATE); final boolean isActivated = model.isDeviceActive(); if (isActivated) { final boolean isReadOnly = model.isDeviceReadOnly(); if (isReadOnly) { activate.select(ROACTIVATE); // rw is not authorized, deactivate first activate.setItemEnabled(RWACTIVATE, false); } else { activate.select(RWACTIVATE); // ro is not authorized, deactivate first activate.setItemEnabled(ROACTIVATE, false); } } else { activate.select(DEACTIVATE); } activate.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(final ValueChangeEvent event) { final String valueString = String.valueOf(event.getProperty().getValue()); if (valueString.equals(DEACTIVATE)) { final String action = DEACTIVATE; // Run activation in background WaitingComponent.executeBackground(model, new Background() { @Override public void processing() { model.deActivateDevice(); } @Override public void postProcessing() { activate.setItemEnabled(RWACTIVATE, true); activate.setItemEnabled(ROACTIVATE, true); updateAttributes(); Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION); } }); } else if (valueString.equals(RWACTIVATE)) { final String action = RWACTIVATE; WaitingComponent.executeBackground(model, new Background() { @Override public void processing() { model.activateDeviceRW(); } @Override public void postProcessing() { // ro is not authorized, deactivate first activate.setItemEnabled(ROACTIVATE, false); updateAttributes(); Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION); } }); } else if (valueString.equals(ROACTIVATE)) { final String action = ROACTIVATE; WaitingComponent.executeBackground(model, new Background() { @Override public void processing() { model.activateDeviceRO(); } @Override public void postProcessing() { // rw is not authorized, deactivate first activate.setItemEnabled(RWACTIVATE, false); updateAttributes(); Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION); } }); } } }); return rootlayout; }
From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java
License:Apache License
/** * Create attributes component./*from w w w . ja v a2s . co m*/ * * @return the component */ private final AbstractComponent createAttributes() { final VerticalLayout layout = new VerticalLayout(); final FormLayout deviceAttributesLayout = new FormLayout(); deviceAttributesLayout.setMargin(true); deviceAttributesLayout.setWidth(null); deviceAttributesLayout.setImmediate(true); layout.addComponent(deviceAttributesLayout); layout.setComponentAlignment(deviceAttributesLayout, Alignment.MIDDLE_CENTER); // Enter NAME WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceName(value); } @Override public String getStringValue() { return model.getDeviceName(); } }, "Name", deviceAttributesLayout, model); // Enter DESCRIPTION WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceDescription(value); } @Override public String getStringValue() { return model.getDeviceDescription(); } }, "Description", deviceAttributesLayout, model); // Enter UUID (not editable) final TextField deviceUUID = new TextField("UUID", model.getItemUuid().toString()); deviceUUID.setReadOnly(true); deviceUUID.setWidth("300px"); deviceAttributesLayout.addComponent(deviceUUID); // Enter active final TextField deviceActive = new TextField("Active"); if (model.isDeviceActive()) { deviceActive.setValue("yes"); } else { deviceActive.setValue("no"); } deviceActive.setReadOnly(true); deviceActive.setSizeFull(); deviceAttributesLayout.addComponent(deviceActive); // Enter read only final TextField deviceReadOnly = new TextField("Read Only"); if (model.isDeviceReadOnly()) { deviceReadOnly.setValue("yes"); } else { deviceReadOnly.setValue("no"); } deviceReadOnly.setReadOnly(true); deviceReadOnly.setSizeFull(); deviceAttributesLayout.addComponent(deviceReadOnly); // Enter size WebUiUtils.createFieldLong(new LongAttributeOperation() { @Override public void setLongValue(final long value) { model.setDeviceSize(value); } @Override public long getLongValue() { return model.getDeviceSize(); } }, "Size", deviceAttributesLayout, model); // Enter IQN WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceIqn(value); } @Override public String getStringValue() { return model.getDeviceIqn(); } }, "IQN", deviceAttributesLayout, model); // Enter Alias WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setDeviceIscsiAlias(value); } @Override public String getStringValue() { return model.getDeviceIscsiAlias(); } }, "iSCSI Alias", deviceAttributesLayout, model); // Enter iscsi block size WebUiUtils.createFieldInteger(new IntegerAttributeOperation() { @Override public void setIntegerValue(final int value) { model.setDeviceIscsiBlockSize(value); } @Override public int getIntegerValue() { return model.getDeviceIscsiBlockSize(); } }, "iSCSI Block Size", deviceAttributesLayout, model, true); return layout; }
From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java
License:Apache License
/** * Create delete tab in the accordion.//from ww w. ja v a 2 s .co m * * @return the component. */ @SuppressWarnings("serial") private final AbstractComponent createDelete() { final VerticalLayout layout = new VerticalLayout(); layout.setSizeFull(); layout.setMargin(true); layout.setSpacing(true); final Label label = new Label("Deleting a snapshot can be done, only if it is not the root snapshot."); label.setWidth(null); layout.addComponent(label); layout.setComponentAlignment(label, Alignment.MIDDLE_CENTER); final Button deleteButton = new Button("Delete"); if (model.getItemUuid().equals(model.getSnapshotParent())) { // Root snapshot can not be deleted deleteButton.setEnabled(false); } layout.addComponent(deleteButton); layout.setComponentAlignment(deleteButton, Alignment.BOTTOM_CENTER); deleteButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { final SnapshotDeleteWindow deleteWindow = new SnapshotDeleteWindow(model.getItemUuid()); deleteWindow.add(model); } catch (final Exception e) { LOGGER.error("Can not delete snapshot:", e); final ErrorWindow err = new ErrorWindow("Snapshot not deleted: " + e.getMessage()); err.add(model); } } }); return layout; }
From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java
License:Apache License
/** * Create the component to create a device. * /*from w ww . java2s . com*/ * @return the component */ @SuppressWarnings("serial") private final AbstractComponent createDevice() { final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true); final FormLayout createDeviceLayout = new FormLayout(); createDeviceLayout.setMargin(true); createDeviceLayout.setWidth(null); createDeviceLayout.setImmediate(true); layout.addComponent(createDeviceLayout); layout.setComponentAlignment(createDeviceLayout, Alignment.MIDDLE_CENTER); // Enter name final TextField deviceName = new TextField("Name", ""); createDeviceLayout.addComponent(deviceName); // Enter size final TextField deviceSize = new TextField("Size", ""); createDeviceLayout.addComponent(deviceSize); // Create button final Button create = new Button("Create device"); layout.addComponent(create); layout.setComponentAlignment(create, Alignment.MIDDLE_CENTER); create.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { model.createDevice(deviceName.getValue(), Long.valueOf(deviceSize.getValue())); Notification.show("New device created", Notification.Type.TRAY_NOTIFICATION); } catch (final NumberFormatException e) { final ErrorWindow err = new ErrorWindow("Size must be a valid number"); err.add(model); } catch (final Exception e) { final ErrorWindow err = new ErrorWindow("Device not created: " + e.getMessage()); err.add(model); } } }); return layout; }
From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java
License:Apache License
/** * Create the component for the snapshot attributes * /*from www .ja v a 2s . c om*/ * @return the component */ private final AbstractComponent createAttributes() { final VerticalLayout layout = new VerticalLayout(); final FormLayout snapshotAttributesLayout = new FormLayout(); snapshotAttributesLayout.setMargin(true); snapshotAttributesLayout.setWidth(null); snapshotAttributesLayout.setImmediate(true); layout.addComponent(snapshotAttributesLayout); layout.setComponentAlignment(snapshotAttributesLayout, Alignment.MIDDLE_CENTER); // Enter NAME WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setSnapshotName(value); } @Override public String getStringValue() { return model.getSnapshotName(); } }, "Name", snapshotAttributesLayout, model); // Enter DESCRIPTION WebUiUtils.createFieldString(new StringAttributeOperation() { @Override public void setStringValue(final String value) { model.setSnapshotDescription(value); } @Override public String getStringValue() { return model.getSnapshotDescription(); } }, "Description", snapshotAttributesLayout, model); // Enter UUID (not editable) final TextField snapUUID = new TextField("UUID", model.getItemUuid().toString()); snapUUID.setReadOnly(true); snapUUID.setWidth("300px"); snapshotAttributesLayout.addComponent(snapUUID); return layout; }
From source file:com.oodrive.nuage.webui.component.window.AbstractConfirmationWindow.java
License:Apache License
@SuppressWarnings("serial") @Override/*from w ww. j av a2s. co m*/ public Window init(final AbstractItemModel model) { // Add new window final Window vvrConfirmationWindow = new Window("Confirmation"); vvrConfirmationWindow.center(); vvrConfirmationWindow.setResizable(false); final VerticalLayout vvrConfirmationLayout = new VerticalLayout(); vvrConfirmationLayout.setMargin(true); vvrConfirmationWindow.setContent(vvrConfirmationLayout); // Message to display before buttons final Label confirmationMessage = new Label(confirmation); vvrConfirmationLayout.addComponent(confirmationMessage); vvrConfirmationLayout.setComponentAlignment(confirmationMessage, Alignment.MIDDLE_CENTER); vvrConfirmationLayout.setSpacing(true); final HorizontalLayout buttonLayout = new HorizontalLayout(); vvrConfirmationLayout.addComponent(buttonLayout); // Button OK final Button okButton = new Button("OK"); buttonLayout.setSizeFull(); buttonLayout.addComponent(okButton); buttonLayout.setComponentAlignment(okButton, Alignment.MIDDLE_CENTER); okButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { try { action.execute(model); vvrConfirmationWindow.close(); } catch (final Exception e) { vvrConfirmationWindow.close(); } } }); // Button cancel final Button cancelButton = new Button("Cancel"); buttonLayout.addComponent(cancelButton); buttonLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER); cancelButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { // Just close the window vvrConfirmationWindow.close(); } }); return vvrConfirmationWindow; }
From source file:com.oodrive.nuage.webui.component.window.ErrorWindow.java
License:Apache License
@SuppressWarnings("serial") @Override//w ww . j a v a2 s. com public final Window init(final AbstractItemModel model) { // Add new window with title "Error" final Window vvrErrorWindow = new Window("Error"); vvrErrorWindow.center(); vvrErrorWindow.setResizable(false); final VerticalLayout vvrErrorLayout = new VerticalLayout(); vvrErrorLayout.setMargin(true); vvrErrorWindow.setContent(vvrErrorLayout); // Display message final Label errorMessage = new Label(message); vvrErrorLayout.addComponent(errorMessage); vvrErrorLayout.setComponentAlignment(errorMessage, Alignment.MIDDLE_CENTER); vvrErrorLayout.setSpacing(true); // Button OK final Button okButton = new Button("OK"); vvrErrorLayout.addComponent(okButton); vvrErrorLayout.setComponentAlignment(okButton, Alignment.BOTTOM_CENTER); okButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { // Just close the window vvrErrorWindow.close(); } }); return vvrErrorWindow; }