Example usage for com.vaadin.ui VerticalLayout setComponentAlignment

List of usage examples for com.vaadin.ui VerticalLayout setComponentAlignment

Introduction

In this page you can find the example usage for com.vaadin.ui VerticalLayout setComponentAlignment.

Prototype

@Override
    public void setComponentAlignment(Component childComponent, Alignment alignment) 

Source Link

Usage

From source file:org.opencms.ui.CmsVaadinUtils.java

License:Open Source License

/**
 * Shows an alert box to the user with the given information, which will perform the given action after the user clicks on OK.<p>
 *
 * @param title the title//from  w w  w. j  ava2  s.c  om
 * @param message the message
 *
 * @param callback the callback to execute after clicking OK
 */
public static void showAlert(String title, String message, final Runnable callback) {

    final Window window = new Window();
    window.setModal(true);
    Panel panel = new Panel();
    panel.setCaption(title);
    panel.setWidth("500px");
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    panel.setContent(layout);
    layout.addComponent(new Label(message));
    Button okButton = new Button();
    okButton.addClickListener(new ClickListener() {

        /** The serial version id. */
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            window.close();
            if (callback != null) {
                callback.run();
            }
        }
    });
    layout.addComponent(okButton);
    layout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);
    okButton.setCaption(org.opencms.workplace.Messages.get().getBundle(A_CmsUI.get().getLocale())
            .key(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_OK_0));
    window.setContent(panel);
    window.setClosable(false);
    window.setResizable(false);
    A_CmsUI.get().addWindow(window);

}

From source file:org.opencms.ui.dialogs.history.diff.CmsShowVersionButtons.java

License:Open Source License

/**
 * @see org.opencms.ui.dialogs.history.diff.I_CmsDiffProvider#diff(org.opencms.file.CmsObject, org.opencms.gwt.shared.CmsHistoryResourceBean, org.opencms.gwt.shared.CmsHistoryResourceBean)
 *//*from w w  w.j a v  a  2s. c  om*/
public Optional<Component> diff(CmsObject cms, CmsHistoryResourceBean v1, CmsHistoryResourceBean v2) {

    Panel panel = new Panel("");
    panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    HorizontalLayout hl = new HorizontalLayout();
    panel.setContent(hl);
    hl.addComponent(createButton(cms, v1));
    hl.addComponent(createButton(cms, v2));
    VerticalLayout outerContainer = new VerticalLayout();
    outerContainer.addComponent(hl);
    outerContainer.setComponentAlignment(hl, Alignment.MIDDLE_RIGHT);
    outerContainer.setMargin(true);
    hl.setSpacing(true);
    return Optional.fromNullable((Component) outerContainer);
}

From source file:org.opencms.ui.dialogs.history.diff.CmsValueDiff.java

License:Open Source License

/**
 * @see org.opencms.ui.dialogs.history.diff.I_CmsDiffProvider#diff(org.opencms.file.CmsObject, org.opencms.gwt.shared.CmsHistoryResourceBean, org.opencms.gwt.shared.CmsHistoryResourceBean)
 *//*from ww w .  ja  v a2s .c  o m*/
public Optional<Component> diff(final CmsObject cms, CmsHistoryResourceBean v1, CmsHistoryResourceBean v2)
        throws CmsException {

    CmsResource resource1 = A_CmsAttributeDiff.readResource(cms, v1);
    I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource1);
    CmsMacroResolver resolver = new CmsVersionMacroResolver(v1, v2);
    if ((type instanceof CmsResourceTypeXmlContent) || (type instanceof CmsResourceTypeXmlPage)) {
        CmsResource resource2 = A_CmsAttributeDiff.readResource(cms, v2);
        final Panel panel = new Panel(
                CmsVaadinUtils.getMessageText(Messages.GUI_HISTORY_DIALOG_CONTENT_VALUE_TABLE_CAPTION_0));

        final CmsFile file1 = cms.readFile(resource1);

        final CmsFile file2 = cms.readFile(resource2);
        VerticalLayout vl = new VerticalLayout();
        vl.setMargin(true);
        vl.setSpacing(true);
        Table table = buildValueComparisonTable(cms, panel, file1, file2, resolver);
        if (table.getContainerDataSource().size() == 0) {
            return Optional.absent();
        }
        Button fileTextCompareButton = new Button(
                CmsVaadinUtils.getMessageText(Messages.GUI_HISTORY_DIALOG_COMPARE_WHOLE_FILE_0));
        vl.addComponent(fileTextCompareButton);
        vl.setComponentAlignment(fileTextCompareButton, Alignment.MIDDLE_RIGHT);
        fileTextCompareButton.addClickListener(new ClickListener() {

            private static final long serialVersionUID = 1L;

            @SuppressWarnings("synthetic-access")
            public void buttonClick(ClickEvent event) {

                Component diffView = buildWholeFileDiffView(cms, file1, file2);
                CmsHistoryDialog.openChildDialog(panel, diffView,
                        CmsVaadinUtils.getMessageText(Messages.GUI_HISTORY_DIALOG_COMPARE_WHOLE_FILE_0));
            }
        });
        vl.addComponent(table);
        panel.setContent(vl);
        Component result = panel;
        return Optional.fromNullable(result);
    } else {
        return Optional.absent();
    }
}

From source file:org.opencms.ui.login.CmsLoginUI.java

License:Open Source License

/**
 * Initializes the login view.<p>//w w w.  j av  a  2s  .  co  m
 *
 * @param preselectedOu a potential preselected OU
 */
public void showLoginView(String preselectedOu) {

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();

    m_targetOpener = new CmsLoginTargetOpener(A_CmsUI.get());
    //content.setExpandRatio(m_targetOpener, 0f);
    content.addComponent(m_loginForm);
    content.setComponentAlignment(m_loginForm, Alignment.MIDDLE_CENTER);
    content.setExpandRatio(m_loginForm, 1);

    setContent(content);
    if (preselectedOu == null) {
        preselectedOu = "/";
    }
    m_loginForm.selectOrgUnit(preselectedOu);

}

From source file:org.openeos.services.ui.vaadin.internal.notifications.VaadinNotificationManager.java

License:Apache License

private void refreshLayout(final IUnoVaadinApplication application, HorizontalLayout layout) {
    layout.removeAllComponents();//from  w w  w  .  j a v a2 s. c om
    for (final Notification notification : resolveAndSortNotifications(application)) {
        VerticalLayout vLayout = new VerticalLayout();
        vLayout.setMargin(false);
        vLayout.setSpacing(false);
        Button button = new Button();
        button.addListener(new Button.ClickListener() {

            private static final long serialVersionUID = 3202745949615598633L;

            @Override
            public void buttonClick(ClickEvent event) {
                notification.onClick(applicationFactory.createApplication(application));
                ;
            }
        });
        button.setStyleName(Reindeer.BUTTON_LINK);
        button.setIcon(createIconResource(application, notification));
        button.setDescription(notification.getText());
        //createOverlay(application, notification, button, layout);
        vLayout.addComponent(button);
        if (notification.getNumber() != null) {
            Label label = new Label(notification.getNumber().toString());
            label.setSizeUndefined();
            vLayout.addComponent(label);
            vLayout.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
        }
        layout.addComponent(vLayout);
    }
}

From source file:org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog.java

License:Open Source License

public IconSelectionDialog(String selectedIconId) {
    setCaption("Change Icon");
    setModal(true);/*  www  . j  av  a2s.c  om*/
    setResizable(false);
    setClosable(false);
    setWidth(700, Unit.PIXELS);
    setHeight(600, Sizeable.Unit.PIXELS);
    addCloseListener(this);

    okButton = new Button("Ok", this);
    okButton.setId("iconSelectionDialog.button.ok");
    cancelButton = new Button("Cancel", this);
    cancelButton.setId("iconSelectionDialog.button.cancel");

    iconSelectionComponent = new IconSelectionComponent(getElementsToShow(), selectedIconId);
    VerticalLayout iconLayout = new VerticalLayout();
    iconLayout.addStyleName("icon-selection-component");
    iconLayout.setSpacing(true);
    iconLayout.setSizeFull();
    iconLayout.addComponent(iconSelectionComponent);

    final HorizontalLayout buttonLayout = new HorizontalLayout(okButton, cancelButton);
    buttonLayout.setSpacing(true);

    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainLayout.setSizeFull();
    mainLayout.addComponent(iconLayout);
    mainLayout.addComponent(buttonLayout);
    mainLayout.setExpandRatio(iconLayout, 1);
    mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);

    setContent(mainLayout);
    center();
}

From source file:org.opennms.features.topology.ssh.internal.AuthWindow.java

License:Open Source License

/**
 * This constructor method spawns a window to authorize the
 * username and password input by the user. If the authroization
 * is sucessful, the user will be connected to the host at the 
 * given port through SSH, and the terminal emulator this window
 * will be replaced by a terminal emulator. 
 * //  www. j a  v a  2s .com
 * @param host - The host name to connect to
 * @param port - The port number to connect to
 */
public AuthWindow(String host, int port) {
    super("Login");
    m_host = host;
    m_port = port;
    if ("".equals(m_host) || m_port == 0) {
        showOptions = true;
    }
    setCaption("Auth Window");
    setModal(true);
    setWidth("260px");
    setHeight("190px");
    if (showOptions)
        setHeight("260px");
    setResizable(false);

    Label hostLabel = new Label("Host: ");
    hostField = new TextField();
    //        hostField.setMaxLength(FIELD_BUFFER);

    Label portLabel = new Label("Port: ");
    portField = new TextField();
    //        portField.setMaxLength(FIELD_BUFFER);

    Label usernameLabel = new Label("Username: ");
    usernameField = new TextField();
    //        usernameField.setMaxLength(FIELD_BUFFER);

    Label passwordLabel = new Label("Password: ");
    passwordField = new PasswordField();
    passwordField.setMaxLength(FIELD_BUFFER);

    final Button loginButton = new Button("Login");
    loginButton.setClickShortcut(KeyCode.ENTER);
    client = SshClient.setUpDefaultClient();
    client.start();
    loginButton.addClickListener(this);
    GridLayout grid = new GridLayout(2, 2);
    if (showOptions) {
        grid = new GridLayout(2, 4);
        grid.addComponent(hostLabel);
        grid.addComponent(hostField);
        grid.addComponent(portLabel);
        grid.addComponent(portField);
    }
    grid.addComponent(usernameLabel);
    grid.addComponent(usernameField);
    grid.addComponent(passwordLabel);
    grid.addComponent(passwordField);
    grid.setSpacing(true);
    grid.setMargin(new MarginInfo(false, false, true, false));
    VerticalLayout layout = new VerticalLayout();
    layout.addComponent(grid);
    layout.addComponent(loginButton);
    layout.setComponentAlignment(loginButton, Alignment.BOTTOM_RIGHT);
    setContent(layout);
}

From source file:org.opennms.features.topology.ssh.internal.SSHWindow.java

License:Open Source License

/**
 * The constructor for the SSH window//w  w w  .j  a  va2 s .  c  o  m
 * 
 * @param session The current SSH session
 * @param width The width of the window
 * @param height The height of the window
 */
public SSHWindow(ClientSession session, int width, int height) {
    super("SSH");
    setImmediate(true);
    setResizeLazy(false);
    setWidth("" + width + "px");
    setHeight("" + height + "px");

    VerticalLayout vPanel = new VerticalLayout();
    vPanel.setWidth("100%");
    vPanel.setHeight("100%");

    if (session != null) {
        terminal = new SSHTerminal(this, session, TERM_WIDTH, TERM_HEIGHT);
        vPanel.addComponent(terminal);
        vPanel.setComponentAlignment(terminal, Alignment.TOP_CENTER);
    } else {
        vPanel.addComponent(errorLabel);
        vPanel.setComponentAlignment(errorLabel, Alignment.MIDDLE_CENTER);
    }
    setContent(vPanel);
}

From source file:org.opennms.features.vaadin.config.EventAdminApplication.java

License:Open Source License

@Override
public void init(VaadinRequest request) {
    if (eventProxy == null)
        throw new RuntimeException("eventProxy cannot be null.");
    if (eventConfDao == null)
        throw new RuntimeException("eventConfDao cannot be null.");

    final VerticalLayout layout = new VerticalLayout();

    final HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setMargin(true);//  www  . ja v  a 2 s.c om

    final Label comboLabel = new Label("Select Events Configuration File");
    toolbar.addComponent(comboLabel);
    toolbar.setComponentAlignment(comboLabel, Alignment.MIDDLE_LEFT);

    final File eventsDir = new File(ConfigFileConstants.getFilePathString(), "events");
    final XmlFileContainer container = new XmlFileContainer(eventsDir, true);
    container.addExcludeFile("default.events.xml"); // This is a protected file, should not be updated.
    final ComboBox eventSource = new ComboBox();
    toolbar.addComponent(eventSource);
    eventSource.setImmediate(true);
    eventSource.setNullSelectionAllowed(false);
    eventSource.setContainerDataSource(container);
    eventSource.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);
    eventSource.addValueChangeListener(new ComboBox.ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            final File file = (File) event.getProperty().getValue();
            if (file == null)
                return;
            try {
                LOG.info("Loading events from {}", file);
                final Events events = JaxbUtils.unmarshal(Events.class, file);
                addEventPanel(layout, file, events);
            } catch (Exception e) {
                LOG.error("an error ocurred while saving the event configuration {}: {}", file, e.getMessage(),
                        e);
                Notification.show("Can't parse file " + file + " because " + e.getMessage());
            }
        }
    });

    final Button add = new Button("Add New Events File");
    toolbar.addComponent(add);
    add.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            PromptWindow w = new PromptWindow("New Events Configuration", "Events File Name") {
                @Override
                public void textFieldChanged(String fieldValue) {
                    final File file = new File(eventsDir, normalizeFilename(fieldValue));
                    LOG.info("Adding new events file {}", file);
                    final Events events = new Events();
                    addEventPanel(layout, file, events);
                }
            };
            addWindow(w);
        }
    });

    final Button remove = new Button("Remove Selected Events File");
    toolbar.addComponent(remove);
    remove.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (eventSource.getValue() == null) {
                Notification.show("Please select an event configuration file.");
                return;
            }
            final File file = (File) eventSource.getValue();
            ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to remove the file "
                    + file.getName()
                    + "?\nThis cannot be undone and OpenNMS won't be able to handle the events configured on this file.",
                    "Yes", "No", new ConfirmDialog.Listener() {
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                LOG.info("deleting file {}", file);
                                if (file.delete()) {
                                    try {
                                        // Updating eventconf.xml
                                        boolean modified = false;
                                        File configFile = ConfigFileConstants
                                                .getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME);
                                        Events config = JaxbUtils.unmarshal(Events.class, configFile);
                                        for (Iterator<String> it = config.getEventFileCollection()
                                                .iterator(); it.hasNext();) {
                                            String fileName = it.next();
                                            if (file.getAbsolutePath().contains(fileName)) {
                                                it.remove();
                                                modified = true;
                                            }
                                        }
                                        if (modified) {
                                            JaxbUtils.marshal(config, new FileWriter(configFile));
                                            EventBuilder eb = new EventBuilder(
                                                    EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "WebUI");
                                            eventProxy.send(eb.getEvent());
                                        }
                                        // Updating UI Components
                                        eventSource.select(null);
                                        if (layout.getComponentCount() > 1)
                                            layout.removeComponent(layout.getComponent(1));
                                    } catch (Exception e) {
                                        LOG.error("an error ocurred while saving the event configuration: {}",
                                                e.getMessage(), e);
                                        Notification.show("Can't save event configuration. " + e.getMessage(),
                                                Notification.Type.ERROR_MESSAGE);
                                    }
                                } else {
                                    Notification.show("Cannot delete file " + file,
                                            Notification.Type.WARNING_MESSAGE);
                                }
                            }
                        }
                    });
        }
    });

    layout.addComponent(toolbar);
    layout.addComponent(new Label(""));
    layout.setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT);

    setContent(layout);
}

From source file:org.opennms.features.vaadin.config.PromptWindow.java

License:Open Source License

/**
 * Instantiates a new Event Generator window.
 *
 * @param caption the caption/*from  ww  w .  ja v a 2  s. c om*/
 * @param fieldLabel the field label
 */
public PromptWindow(String caption, String fieldLabel) {
    setCaption(caption);
    setModal(true);
    setWidth("400px");
    setHeight("150px");
    setResizable(false);
    setClosable(false);
    addStyleName("dialog");

    fileName = new TextField(fieldLabel);
    fileName.setNullSettingAllowed(false);
    fileName.setWidth("100%");
    fileName.setRequired(true);
    fileName.setRequiredError("This field cannot be null.");

    okButton = new Button("Continue");
    okButton.addClickListener(this);

    cancelButton = new Button("Cancel");
    cancelButton.addClickListener(this);

    HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.addComponent(okButton);
    toolbar.addComponent(cancelButton);

    VerticalLayout layout = new VerticalLayout();
    layout.addComponent(fileName);
    layout.addComponent(toolbar);
    layout.setComponentAlignment(toolbar, Alignment.BOTTOM_RIGHT);

    setContent(layout);
}