Example usage for com.vaadin.ui Alignment TOP_LEFT

List of usage examples for com.vaadin.ui Alignment TOP_LEFT

Introduction

In this page you can find the example usage for com.vaadin.ui Alignment TOP_LEFT.

Prototype

Alignment TOP_LEFT

To view the source code for com.vaadin.ui Alignment TOP_LEFT.

Click Source Link

Usage

From source file:edu.kit.dama.ui.admin.wizard.AccessPointCreation.java

License:Apache License

@Override
public void buildMainLayout() {
    Label information = new Label(
            "In this step you can choose to create a WebDav Access Point. This access point can be used to upload/download data to/from the repository easily. "
                    + "The advantage compared to externally configured access points is the tight integration into the repository system's authentication framework and operating system permissions.<br/>"
                    + "In order to allow access for the system administrator it is recommended to create a WebDav login for the admin user. The login will be the email and the password selected below. "
                    + "You may use the same password as before, but for security reasons it is recommended to use another password for WebDav access.",
            ContentMode.HTML);//  w  w w  .j  a v a 2 s .c om

    addWebDavAccessPoint = new CheckBox("Select to Create a WebDav Access Point");
    addWebDavAccessPoint.setValue(Boolean.TRUE);
    createAdminLogin = new CheckBox("Select to Create an Admin Login for the Access Point");
    createAdminLogin.setValue(Boolean.TRUE);
    addWebDavAccessPoint.addValueChangeListener((event) -> {
        createAdminLogin.setEnabled(addWebDavAccessPoint.getValue());
        accessPointName.setEnabled(addWebDavAccessPoint.getValue());
        baseUrl.setEnabled(addWebDavAccessPoint.getValue());
        basePath.setEnabled(addWebDavAccessPoint.getValue());
        adminPassword.setEnabled(addWebDavAccessPoint.getValue() && createAdminLogin.getValue());
        adminPasswordCheck.setEnabled(addWebDavAccessPoint.getValue() && createAdminLogin.getValue());
    });

    createAdminLogin.addValueChangeListener((event) -> {
        adminPassword.setEnabled(createAdminLogin.getValue());
        adminPasswordCheck.setEnabled(createAdminLogin.getValue());
    });

    accessPointName = UIUtils7.factoryTextField("Access Point Name", "e.g WebDav Access Point", 3, 255);
    accessPointName.setValue("WebDav Access Point");
    accessPointName.setRequired(true);
    accessPointName.setWidth("400px");

    baseUrl = UIUtils7.factoryTextField("Base Url", "e.g http://localhost:8080/webdav", 3, 255);
    baseUrl.setRequired(true);
    baseUrl.setWidth("400px");
    basePath = UIUtils7.factoryTextField("Base Path", "e.g /mnt/data/webdav/", 3, 255);
    basePath.setRequired(true);
    basePath.setWidth("400px");

    adminPassword = new PasswordField("WebDav Password");
    adminPassword.setWidth("400px");
    adminPassword.setRequired(true);
    adminPasswordCheck = new PasswordField("Confirm WebDav Password");
    adminPasswordCheck.setWidth("400px");
    adminPasswordCheck.setRequired(true);

    getMainLayout().addComponent(information);
    getMainLayout().addComponent(addWebDavAccessPoint);
    getMainLayout().addComponent(accessPointName);
    getMainLayout().addComponent(baseUrl);
    getMainLayout().addComponent(basePath);
    getMainLayout().addComponent(createAdminLogin);
    getMainLayout().addComponent(adminPassword);
    getMainLayout().addComponent(adminPasswordCheck);

    getMainLayout().setComponentAlignment(information, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(addWebDavAccessPoint, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(accessPointName, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(baseUrl, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(basePath, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(createAdminLogin, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(adminPassword, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(adminPasswordCheck, Alignment.TOP_LEFT);
}

From source file:edu.kit.dama.ui.admin.wizard.AdministratorAccountCreation.java

License:Apache License

@Override
public void buildMainLayout() {
    Label information = new Label(
            "In order to be able to perform administrative tasks and for basic configuration, a privileged user must be created. This user is allowed to "
                    + "modify settings and internal workflows of the repository system. Therefor, the administrator should have at least valid contact information assigned and must be "
                    + "able to log in into the web interface.<br/>Optionally, OAuth creadentials can be added directly to allow RESTful access to the administrator. However, this can "
                    + "also be done later inside the web user interface.",
            ContentMode.HTML);/*from  www.  j a v  a  2s . c om*/

    adminFirstName = UIUtils7.factoryTextField("First Name", "The first name of the admin user.", 3, 255);
    adminFirstName.setRequired(true);
    adminFirstName.setWidth("400px");
    adminLastName = UIUtils7.factoryTextField("Last Name", "The last name of the admin user.", 3, 255);
    adminLastName.setRequired(true);
    adminLastName.setWidth("400px");
    adminEMail = UIUtils7.factoryTextField("Contact EMail", "The admin contact email.", 6, 255);
    adminEMail.setRequired(true);
    adminEMail.setWidth("400px");
    adminPassword = new PasswordField("Password");
    adminPassword.setWidth("400px");
    adminPassword.setRequired(true);
    adminPasswordCheck = new PasswordField("Confirm Password");
    adminPasswordCheck.setWidth("400px");
    adminPasswordCheck.setRequired(true);
    addOAuthCredentials = new CheckBox("Create OAuth Credentials for Administrator (optional)");
    addOAuthCredentials.setDescription(
            "Create (random) OAuth credentials for the admin user. These credentials can be used to access the RESTful endpoints of the repository. "
                    + "You can also create/modify OAuth credentials later inside the user interface.");
    addOAuthCredentials.setWidth("400px");
    getMainLayout().addComponent(information);
    getMainLayout().addComponent(adminFirstName);
    getMainLayout().addComponent(adminLastName);
    getMainLayout().addComponent(adminEMail);
    getMainLayout().addComponent(adminPassword);
    getMainLayout().addComponent(adminPasswordCheck);
    getMainLayout().addComponent(addOAuthCredentials);
    getMainLayout().setComponentAlignment(information, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(adminFirstName, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(adminLastName, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(adminEMail, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(adminPassword, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(adminPasswordCheck, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(addOAuthCredentials, Alignment.TOP_LEFT);
    addOAuthCredentials.addValueChangeListener((Property.ValueChangeEvent event) -> {
        if (addOAuthCredentials.getValue()) {
            oAuthSecret = RandomStringUtils.randomAlphabetic(16);
        } else {
            oAuthSecret = null;
        }
    });
}

From source file:edu.kit.dama.ui.admin.wizard.BaseMetadataExtractionAndIndexingCreation.java

License:Apache License

public void buildMainLayout() {
    extractorProperties = new HashMap<>();
    Label information = new Label(
            "In order to query for digital objects by metadata, relevant metadata must be extracted, processed and indexed at ingest time. "
                    + "Typically, this process highly depends on the community ingesting data as metadata might be located next to the data, within the data or externally. "
                    + "In order to be able to query at least for base metadata available for all digital objects, basic METS metadata extraction marked below should remain enabled. "
                    + "It is highly recommended to keep the default settings and to modify them later according to special needs.<br/>"
                    + "If you already have a custom metadata extractor in place, feel free to disable the checkbox.",
            ContentMode.HTML);//from www  .j  a v  a  2  s .c o m

    createMetsExtractor = new CheckBox("Select to Enable basic METS metadata extraction for each ingest.");
    createMetsExtractor.setValue(true);

    createMetsExtractor.addValueChangeListener((event) -> {
        Set<Entry<String, TextField>> entries = extractorProperties.entrySet();
        entries.forEach((entry) -> {
            entry.getValue().setEnabled(createMetsExtractor.getValue());
        });
    });

    getMainLayout().addComponent(information);
    getMainLayout().addComponent(createMetsExtractor);
    getMainLayout().setComponentAlignment(information, Alignment.TOP_LEFT);
    getMainLayout().setComponentAlignment(createMetsExtractor, Alignment.TOP_LEFT);

    BasicMetsExtractor ext = new BasicMetsExtractor("");
    String[] internalKeys = ext.getInternalPropertyKeys();

    for (String internalKey : internalKeys) {
        TextField field = UIUtils7.factoryTextField(internalKey, null);
        field.setRequired(true);
        field.setDescription(ext.getInternalPropertyDescription(internalKey));
        if (MetsMetadataExtractor.COMMUNITY_DMD_SECTION_ID.equals(internalKey)) {
            field.setValue("cmd0");
        } else if (MetsMetadataExtractor.COMMUNITY_MD_TYPE_ID.equals(internalKey)) {
            field.setValue("DC");
        } else if (MetsMetadataExtractor.COMMUNITY_METADATA_SCHEMA_ID.equals(internalKey)) {
            field.setValue("oai_dc");
        } else {
            field.setValue("TRUE");
        }
        extractorProperties.put(internalKey, field);
        getMainLayout().addComponent(field);
        getMainLayout().setComponentAlignment(field, Alignment.TOP_LEFT);
    }
}

From source file:edu.kit.dama.ui.admin.wizard.FirstStartWizard.java

License:Apache License

private void buildMainLayout() {
    stepLayout = new VerticalLayout();

    back.setEnabled(false);//  w w  w  .j a v a 2  s  . c o m
    stepLayout.addComponent(stepList[currentStep]);
    stepLayout.setComponentAlignment(stepList[currentStep], Alignment.TOP_RIGHT);
    stepLayout.setSpacing(false);
    stepLayout.setMargin(false);
    stepLayout.setWidth("100%");
    stepLayout.setHeight("500px");

    final VerticalLayout stepLabels = new VerticalLayout();
    for (WizardStep step : stepList) {
        Label stepLabel = new Label(step.getStepName());
        stepLabel.setWidth("250px");
        stepLabels.addComponent(stepLabel);
        stepLabels.setComponentAlignment(stepLabel, Alignment.TOP_LEFT);
    }

    //make introduction label bold
    stepLabels.getComponent(0).addStyleName("myboldcaption");

    Label spacer = new Label();
    stepLabels.addComponent(spacer);
    stepLabels.setExpandRatio(spacer, 1.0f);
    stepLabels.setWidth("275px");
    stepLabels.setHeight("550px");
    stepLabels.setSpacing(true);

    UIUtils7.GridLayoutBuilder builder = new UIUtils7.GridLayoutBuilder(2, 2);

    HorizontalLayout buttonLayout = new HorizontalLayout(back, next);
    buttonLayout.setSizeFull();
    buttonLayout.setComponentAlignment(back, Alignment.BOTTOM_RIGHT);
    buttonLayout.setComponentAlignment(next, Alignment.BOTTOM_RIGHT);
    buttonLayout.setExpandRatio(back, 1.0f);

    next.addClickListener((event) -> {
        if ("Go To Login".equals(next.getCaption())) {
            Page.getCurrent().reload();
        } else if ("Finish".equals(next.getCaption())) {
            //do finish
            WizardPersistHelper helper = new WizardPersistHelper();
            if (helper.persist(properties)) {
                UIUtils7.showInformation("Success",
                        "All information have been successfully stored into the database. For details, please refer to the log output above.\n"
                                + "You may now dismiss this message and click 'Go To Login' in order to access the login page.\n"
                                + "From there you can to login using your administrator account or create a personalized user account.",
                        3000);
                back.setVisible(false);
                next.setCaption("Go To Login");
            } else {
                UIUtils7.showError("Failed to store collected information in database.\n"
                        + "Please refer to the log output above.");
            }
            ((WizardSummary) stepList[currentStep]).setSummary(helper.getMessages());
        } else {
            if (currentStep + 1 <= stepList.length - 1) {
                if (stepList[currentStep].validate()) {
                    stepList[currentStep].collectProperties(properties);
                    currentStep++;
                    stepLayout.replaceComponent(stepList[currentStep - 1], stepList[currentStep]);
                    Label currentLabel = (Label) stepLabels.getComponent(currentStep);
                    Label prevLabel = (Label) stepLabels.getComponent(currentStep - 1);
                    currentLabel.addStyleName("myboldcaption");
                    prevLabel.removeStyleName("myboldcaption");

                    if (stepList[currentStep] instanceof WizardSummary) {
                        StringBuilder summary = new StringBuilder();
                        for (WizardStep step : stepList) {
                            summary.append(step.getSummary()).append("\n");
                        }
                        ((WizardSummary) stepList[currentStep]).setSummary(summary.toString());
                    }
                }
            }

            if (currentStep == stepList.length - 1) {
                //finish
                next.setCaption("Finish");
            } else {
                next.setCaption("Next");
            }

            back.setEnabled(true);
        }
    });

    back.addClickListener((event) -> {
        if (currentStep - 1 >= 0) {
            stepList[currentStep].collectProperties(properties);
            currentStep--;
            stepLayout.replaceComponent(stepList[currentStep + 1], stepList[currentStep]);
            Label currentLabel = (Label) stepLabels.getComponent(currentStep);
            Label prevLabel = (Label) stepLabels.getComponent(currentStep + 1);
            currentLabel.addStyleName("myboldcaption");
            prevLabel.removeStyleName("myboldcaption");
        }
        next.setEnabled(true);
        back.setEnabled(currentStep > 0);
        next.setCaption("Next");
    });

    builder.addComponent(stepLabels, Alignment.TOP_LEFT, 0, 0, 1, 2);
    builder.addComponent(stepLayout, Alignment.TOP_LEFT, 1, 0, 1, 1);
    builder.addComponent(buttonLayout, Alignment.BOTTOM_LEFT, 1, 1, 1, 1);

    mainLayout = builder.getLayout();
    mainLayout.setMargin(true);
    mainLayout.setSizeFull();

    // mainLayout.setColumnExpandRatio(0, .3f);
    mainLayout.setColumnExpandRatio(1, 1f);
    mainLayout.setRowExpandRatio(0, .95f);
    mainLayout.setRowExpandRatio(1, .05f);
}

From source file:edu.kit.dama.ui.admin.workflow.DataWorkflowBasePropertiesLayout.java

License:Apache License

public DataWorkflowBasePropertiesLayout() {
    LOGGER.debug("Building " + DEBUG_ID_PREFIX + " ...");

    setId(DEBUG_ID_PREFIX.substring(0, DEBUG_ID_PREFIX.length() - 1));
    setSizeFull();//ww  w  .  ja v  a2 s . com
    setMargin(true);
    setSpacing(true);
    setCaption("TASK CONFIGURATION");

    setColumns(4);
    setRows(6);
    //first row
    addComponent(getNameField(), 0, 0);
    addComponent(getVersionField(), 1, 0);
    addComponent(getContactBox(), 2, 0);
    addComponent(getGroupBox(), 3, 0);
    //second row
    addComponent(getApplicationPackageUrlField(), 0, 1, 1, 1);
    addComponent(getApplicationArgumentsField(), 2, 1);
    //addComponent(getCheckBoxesLayout(), 3, 1, 3, 2);
    //add placeholder only
    addComponent(new VerticalLayout(), 3, 1, 3, 2);
    Label l = new Label("* Changing fields with a red border will update the version of the associated task.");
    l.addStyleName("red-text");
    addComponent(l, 0, 2, 2, 2);
    l.setHeight("12px");
    setComponentAlignment(l, Alignment.TOP_CENTER);

    //
    addComponent(getKeywordsField(), 0, 3, 2, 3);
    //
    addComponent(getDescriptionArea(), 0, 4, 2, 5);

    Button addPropertyButton = new Button();
    addPropertyButton.setIcon(new ThemeResource(IconContainer.ADD));
    addPropertyButton.addClickListener((Button.ClickEvent event) -> {
        addPropertyComponent.reset();
        addPropertyComponent.showWindow();
    });

    HorizontalLayout layout = new HorizontalLayout(getEnvironmentPropertiesSelect(), addPropertyButton);
    layout.setComponentAlignment(getEnvironmentPropertiesSelect(), Alignment.TOP_LEFT);
    layout.setComponentAlignment(addPropertyButton, Alignment.BOTTOM_RIGHT);
    layout.setSizeFull();
    layout.setExpandRatio(getEnvironmentPropertiesSelect(), .95f);
    layout.setExpandRatio(addPropertyButton, .05f);
    addComponent(layout, 3, 3, 3, 5);

    //add popup to layout
    addPropertyComponent = new AddEnvironmentPropertyComponent(this);

    //set dummy row height to 0
    setColumnExpandRatio(0, 0.2f);
    setColumnExpandRatio(1, 0.15f);
    setColumnExpandRatio(2, 0.2f);
    setColumnExpandRatio(3, 0.25f);
    setRowExpandRatio(5, 1f);

}

From source file:edu.kit.dama.ui.admin.workflow.ExecutionEnvironmentBasePropertiesLayout.java

License:Apache License

/**
 * Default constructor./*w  ww .  j  a va 2 s.  com*/
 */
public ExecutionEnvironmentBasePropertiesLayout() {
    super();

    LOGGER.debug("Building " + DEBUG_ID_PREFIX + " ...");

    setId(DEBUG_ID_PREFIX.substring(0, DEBUG_ID_PREFIX.length() - 1));
    setSizeFull();
    setMargin(true);
    setSpacing(true);

    setColumns(4);
    setRows(6);

    addComponent(getNameField(), 0, 0, 2, 0);
    addComponent(getGroupBox(), 3, 0);
    //
    addComponent(getAccessPointBox(), 0, 1, 2, 1);
    addComponent(getCheckBoxesLayout(), 3, 1);
    //

    addComponent(getAccessPointBasePathField(), 0, 2, 2, 2);
    addComponent(getPathSelectorButton(), 3, 2);
    //
    addComponent(getMaxTasksField(), 0, 3, 2, 3);
    //
    addComponent(getDescriptionArea(), 0, 4, 2, 5);

    //add property selection
    Button addPropertyButton = new Button();
    addPropertyButton.setIcon(new ThemeResource(IconContainer.ADD));
    addPropertyButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            addPropertyComponent.reset();
            addPropertyComponent.showWindow();
        }
    });

    HorizontalLayout layout = new HorizontalLayout(getEnvironmentPropertiesSelect(), addPropertyButton);
    layout.setComponentAlignment(getEnvironmentPropertiesSelect(), Alignment.TOP_LEFT);
    layout.setComponentAlignment(addPropertyButton, Alignment.BOTTOM_RIGHT);
    layout.setSizeFull();
    layout.setExpandRatio(getEnvironmentPropertiesSelect(), .95f);
    layout.setExpandRatio(addPropertyButton, .05f);
    addComponent(layout, 3, 4, 3, 5);

    //add popup to layout
    addPropertyComponent = new AddEnvironmentPropertyComponent(this);

    setComponentAlignment(getPathSelectorButton(), Alignment.BOTTOM_LEFT);
    setColumnExpandRatio(0, 0.2f);
    setColumnExpandRatio(1, 0.2f);
    setColumnExpandRatio(2, 0.2f);
    setColumnExpandRatio(3, 0.2f);
    setRowExpandRatio(5, 1f);
}

From source file:edu.kit.dama.ui.commons.util.PaginationLayout.java

License:Apache License

/**
 * Fill the pagination listing based on a specific query to obtain valid
 * objects./*www. j a v a  2  s.  c  om*/
 */
private void renderPage() {
    //obtain the objects of this page (5 entries per page are shown)
    int start = currentPage * entriesPerPage;
    //initialize page panel and layout
    page = new Panel();
    page.setCaption(caption);
    page.setImmediate(true);
    page.setIcon(icon);
    VerticalLayout pageLayout = new VerticalLayout();
    pageLayout.setMargin(true);
    pageLayout.setImmediate(true);
    pageLayout.setSizeUndefined();
    page.setSizeFull();
    List<C> entries;

    if (overallEntries > 0) {
        AbstractComponent header = callback.renderHeader();
        if (header != null) {
            pageLayout.addComponent(header);
            pageLayout.setComponentAlignment(header, Alignment.TOP_LEFT);
        }
        entries = callback.getEntries(this, start);
        //add all objects of this page
        int objectIdx = 1;
        for (C entry : entries) {
            AbstractComponent renderedEntry = callback.renderEntry(entry, start + objectIdx);

            pageLayout.addComponent(renderedEntry);
            pageLayout.setComponentAlignment(renderedEntry, Alignment.TOP_CENTER);
            Label spacer = new Label("<hr/>", Label.CONTENT_XHTML);
            spacer.setHeight("3px");
            spacer.setWidth("100%");
            pageLayout.addComponent(spacer);
            pageLayout.setComponentAlignment(spacer, Alignment.TOP_CENTER);
            objectIdx++;
        }

        //if there are less than 'entriesPerPage' entries, add a 'filler' to keep the actual items on top of the layout
        if (objectIdx < entriesPerPage) {
            Label filler = new Label();
            pageLayout.addComponent(filler);
            pageLayout.setExpandRatio(filler, 1.0f);
        }
    } else {
        //nothing visible
        Label filler = new Label("No entries available");
        pageLayout.addComponent(filler);
        pageLayout.setExpandRatio(filler, 1.0f);
    }

    page.setContent(pageLayout);
}

From source file:edu.kit.dama.ui.components.ConfirmationWindow7.java

License:Apache License

/**
 * Builds a customized subwindow <b>ConfirmationWindow</b> that allows the
 * user to confirm his previously requested action.
 *
 * @param pTitle The title of the window.
 * @param pMessage The message shown in the window.
 * @param pOptionType The type of the window (OK or YES_NO) which defines the
 * visible buttons./*from   ww w .  ja v  a  2  s  .  co m*/
 * @param pMessageType The message type (INFORMATION, WARNING, ERROR) which
 * determines the icon. If pMessageType is null, no icon will be shown.
 * @param pListener The listener which receives the result if a button was
 * pressed or the window was closed.
 *
 */
ConfirmationWindow7(String pTitle, String pMessage, OPTION_TYPE pOptionType, MESSAGE_TYPE pMessageType,
        IConfirmationWindowListener7 pListener) {
    this.listener = pListener;
    //basic setup

    //set caption depending on type
    String caption = pTitle;
    if (caption == null) {
        if (pMessageType != null) {
            switch (pMessageType) {
            case QUESTION:
                caption = DEFAULT_TITLE;
                break;
            case INFORMATION:
                caption = "Information";
                break;
            case WARNING:
                caption = "Warning";
                break;
            case ERROR:
                caption = "Error";
                break;
            }
        } else {
            //no type provided...use default title
            caption = DEFAULT_TITLE;
        }
    }

    setCaption(caption);
    setModal(true);
    center();

    // Build line of buttons depending on pOptionType
    HorizontalLayout buttonLine = new HorizontalLayout();
    buttonLine.setSpacing(true);
    buttonLine.setWidth("100%");
    //add spacer
    Label spacer = new Label();
    buttonLine.addComponent(spacer);
    //add buttons
    if (OPTION_TYPE.YES_NO_OPTION.equals(pOptionType)) {
        buttonLine.addComponent(buildYesButton("Yes"));
        buttonLine.addComponent(buildNoButton());
        buttonLine.setComponentAlignment(yesButton, Alignment.MIDDLE_RIGHT);
        buttonLine.setComponentAlignment(noButton, Alignment.MIDDLE_RIGHT);
        //Assign ENTER to the YES button
        yesButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
        //Assign ESC to the NO button
        noButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    } else {
        buttonLine.addComponent(buildYesButton("OK"));
        buttonLine.setComponentAlignment(yesButton, Alignment.MIDDLE_RIGHT);
        //Assign ENTER to the OK button
        yesButton.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
        //Assign ESC to close the dialog
        setCloseShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    }

    buttonLine.setExpandRatio(spacer, 1.0f);

    //determine the icon depending on pMessageType
    ThemeResource icon = null;

    if (pMessageType != null) {
        switch (pMessageType) {
        case QUESTION:
            icon = new ThemeResource("img/24x24/question.png");
            break;
        case INFORMATION:
            icon = new ThemeResource("img/24x24/information.png");
            break;
        case WARNING:
            icon = new ThemeResource("img/24x24/warning.png");
            break;
        case ERROR:
            icon = new ThemeResource("img/24x24/forbidden.png");
            break;
        }
    }
    Component iconComponent = new Label();
    if (icon != null) {
        //icon was set, overwrite icon component
        iconComponent = new Image(null, icon);
    }

    //build the message label
    Label message = new Label(pMessage, ContentMode.HTML);
    message.setSizeUndefined();
    //build the main layout
    GridLayout mainLayout = new UIUtils7.GridLayoutBuilder(2, 2)
            .addComponent(iconComponent, Alignment.TOP_LEFT, 0, 0, 1, 1).addComponent(message, 1, 0, 1, 1)
            .addComponent(buttonLine, 0, 1, 2, 1).getLayout();
    mainLayout.setMargin(true);
    mainLayout.setSpacing(true);
    mainLayout.setColumnExpandRatio(0, .05f);
    mainLayout.setColumnExpandRatio(1, 1f);
    mainLayout.setRowExpandRatio(0, 1f);
    mainLayout.setRowExpandRatio(1, .05f);
    setContent(mainLayout);

    //add the close listener
    addCloseListener(new CloseListener() {
        @Override
        public void windowClose(CloseEvent e) {
            fireCloseEvents(RESULT.CANCEL);
        }
    });
}

From source file:edu.kit.dama.ui.repo.components.EntryRenderPanel.java

License:Apache License

/**
 * Build the main layout of the representation of one digital object.
 *
 * @param pContext The authorization context used to decide whether special
 * administrative features are available or not.
 *///www.j  av  a  2  s  .co  m
private void buildMainLayout(IAuthorizationContext pContext) {
    //check if the object could be obtained or not, e.g. due to missing permissions. If not, show an error message.
    if (ERROR_PLACEHOLDER.equals(object.getLabel())) {
        Label warnLabel = new Label("<h3>Failed to obtain entry with identifier '"
                + object.getDigitalObjectIdentifier() + "' from database.</h3>", ContentMode.HTML);
        final Button cleanup = new Button("Cleanup");
        cleanup.setDescription("Click to remove object from search index.");
        cleanup.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                cleanup.setEnabled(false);
                new Notification("Information", "Cleanup not implemented, yet.",
                        Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent());
            }
        });
        if (pContext.getRoleRestriction().atLeast(Role.ADMINISTRATOR)) {
            //show cleanup button
            mainLayout = new HorizontalLayout(warnLabel, cleanup);
        } else {
            //no cleanup available
            mainLayout = new HorizontalLayout(warnLabel);
        }
        mainLayout.setSizeFull();
        return;
    }

    //initialize image field
    typeImage = new Image();
    typeImage.setSizeFull();
    setImage(object);

    //initialize title label/field
    titleField = UIUtils7.factoryTextField(null, "dc:title");
    titleField.addStyleName("basic_title");
    titleLabel = new Label("dc:title");
    titleLabel.setWidth("100%");
    titleLabel.addStyleName("basic_title");

    //initialize creator label
    if (object.getUploader() != null) {
        creatorLabel = new Label(StringUtils.abbreviate(object.getUploader().getFullname(), 100));
        creatorLabel.setEnabled(true);
    } else {
        creatorLabel = new Label("dc:creator");
        creatorLabel.setEnabled(false);
    }
    creatorLabel.setWidth("100%");
    creatorLabel.addStyleName("basic_left");

    //initialize creation label
    if (object.getStartDate() != null) {
        creationLabel = new Label(new SimpleDateFormat().format(object.getStartDate()));
        creationLabel.setEnabled(true);
    } else {
        creationLabel = new Label("dc:date");
        creationLabel.setEnabled(false);
    }

    creationLabel.setWidth("100%");

    //initialize identifier label
    objectIdLabel = new Label(StringUtils.abbreviate(object.getDigitalObjectIdentifier(), 100));
    objectIdLabel.setWidth("100%");
    //initialize description label/area
    descriptionLabel = new Label("dc:description");
    descriptionArea = UIUtils7.factoryTextArea(null, "dc:description");
    descriptionArea.setHeight("50px");
    descriptionLabel.setHeight("50px");
    descriptionLabel.setWidth("100%");

    //action buttons
    downloadButton = new NativeButton("Download");
    downloadButton.setIcon(new ThemeResource("img/32x32/download.png"));
    downloadButton.setStyleName(BaseTheme.BUTTON_LINK);
    downloadButton.setDescription("Download the data of this digital object.");
    downloadButton.setWidth("100%");

    shareButton = new NativeButton("Share");
    shareButton.setIcon(new ThemeResource("img/16x16/share.png"));
    shareButton.setStyleName(BaseTheme.BUTTON_LINK);
    shareButton.setDescription("Share this digital object.");
    Role eligibleRole = Role.GUEST;
    if (parent.getParentUI().isUserLoggedIn()) {
        //obtain role only if a user is logged in and we are not in ingest mode.
        //Otherwise, the dummy context of MyVaadinUI would be used and will cause unwanted access.
        try {
            //Determine eligible role of currently logged in user
            eligibleRole = ResourceServiceLocal.getSingleton().getGrantRole(object.getSecurableResourceId(),
                    parent.getParentUI().getAuthorizationContext().getUserId(),
                    AuthorizationContext.factorySystemContext());
        } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) {
            LOGGER.warn("Failed to determine eligable role for context "
                    + parent.getParentUI().getAuthorizationContext() + ". Continue with GUEST permissions.",
                    ex);
        }
    }

    //Update share button depending on role. Only possessing the role MANAGER (being the owner) entitles to share an object. 
    if (eligibleRole.atLeast(Role.MANAGER)) {
        shareButton.setEnabled(true);
        shareButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                if (parent != null) {
                    parent.showSharingPopup(object);
                }
            }
        });
    } else {
        shareButton.setEnabled(false);
        shareButton.setDescription("Only the object owner is allowed to change sharing information.");
    }

    editButton = new NativeButton("Edit Metadata");
    editButton.setIcon(new ThemeResource("img/16x16/edit.png"));
    editButton.setStyleName(BaseTheme.BUTTON_LINK);
    editButton.setDescription("Edit this digital object's metadata.");

    //Update edit button depending on role. If the object is shared with or owned by the logged in user, editing will be allowed.
    if (eligibleRole.atLeast(Role.MEMBER)) {
        editButton.setEnabled(true);
        editButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                switchEditMode();
            }
        });
    } else {
        editButton.setEnabled(false);
        editButton.setDescription(
                "Only the object owner and users the object is shared with are allowed to change metadata information.");
    }

    starButton = new NativeButton("Favorite");
    starButton.setImmediate(true);
    starButton.setIcon(new ThemeResource("img/16x16/unstarred.png"));
    starButton.setStyleName(BaseTheme.BUTTON_LINK);
    starButton.setDescription("Add/remove digital object to/from favorites.");

    //Update star button depending on role. If the object is shared with or owned by the logged in user, "star'ing" will be allowed.
    if (eligibleRole.atLeast(Role.MEMBER)) {
        starButton.setEnabled(true);
        starButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager();
                mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext());

                try {
                    DigitalObjectType favoriteType = mdm
                            .findSingleResult("SELECT t FROM DigitalObjectType t WHERE t.identifier='"
                                    + MyVaadinUI.FAVORITE_TYPE_IDENTIFIER + "' AND t.typeDomain='"
                                    + MyVaadinUI.FAVORITE_TYPE_DOMAIN + "'", DigitalObjectType.class);
                    if (DigitalObjectTypeHelper.isTypeAssignedToObject(object, favoriteType,
                            AuthorizationContext.factorySystemContext())) {
                        //remove favorite status
                        DigitalObjectTypeHelper.removeTypeFromObject(object, favoriteType,
                                AuthorizationContext.factorySystemContext());
                        starButton.setIcon(new ThemeResource("img/16x16/unstarred.png"));
                        new Notification("Information",
                                "Successfully removed favorite tag from object "
                                        + object.getDigitalObjectIdentifier() + ".",
                                Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent());
                    } else {
                        //assign favorite status
                        DigitalObjectTypeHelper.assignTypeToObject(object, favoriteType,
                                AuthorizationContext.factorySystemContext());
                        starButton.setIcon(new ThemeResource("img/16x16/starred.png"));
                        new Notification("Information",
                                "Successfully added favorite tag to object "
                                        + object.getDigitalObjectIdentifier() + ".",
                                Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent());
                    }
                } catch (Exception e) {
                    LOGGER.error("Failed to change 'favorite' status of digital object.", e);
                    new Notification("Warning", "Failed to update favorite status.",
                            Notification.Type.WARNING_MESSAGE).show(Page.getCurrent());
                }
            }
        });
    } else {
        starButton.setEnabled(false);
        starButton.setDescription(
                "Only the object owner and users the object is shared with are allowed to change the favorite state.");
    }

    dcLayout = new UIUtils7.GridLayoutBuilder(3, 5).addComponent(titleLabel, 0, 0, 2, 1)
            .addComponent(creationLabel, 2, 0, 1, 1).addComponent(creatorLabel, 0, 1, 3, 1)
            .addComponent(objectIdLabel, 0, 2, 3, 1).fill(descriptionLabel, 0, 3).getLayout();
    dcLayout.setSizeFull();

    Button.ClickListener saveCancelButtonListener = new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (saveEditButton.equals(event.getButton())) {
                //do save
                IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager();
                mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext());
                try {
                    String title = titleField.getValue();
                    String description = descriptionArea.getValue();
                    Investigation investigation = object.getInvestigation();
                    boolean wasError = false;
                    if (description != null && description.length() <= 1024 && investigation != null) {
                        if (!description.equals(investigation.getDescription())) {
                            investigation.setDescription(description);
                            //store investigation
                            mdm.save(investigation);
                        }
                    } else {
                        LOGGER.warn(
                                "Failed to commit updated description '{}'. Either length is exceeded or investigation '{}' is null.",
                                description, investigation);
                        wasError = true;
                    }
                    //store object
                    if (title != null && title.length() >= 3 && title.length() <= 255) {
                        if (!title.equals(object.getLabel())) {
                            //store object
                            object.setLabel(title);
                            object = mdm.save(object);
                        }
                    } else {
                        LOGGER.warn("Failed to commit updated title '{}'. Length is invalid (3<=l<=255).",
                                title);
                        wasError = true;
                    }
                    if (wasError) {
                        new Notification("Warning",
                                "Failed to update title and/or description. See logfile for details.",
                                Notification.Type.WARNING_MESSAGE).show(Page.getCurrent());
                    }

                    //As there is not automatic sync between database and search index the entry has to be reindexed at this point in order
                    //to keep both systems consistent. However, changes taking place in between are lost.
                    LOGGER.debug("Object committed to database. Updating index.");
                    ElasticsearchHelper.indexEntry(object);
                } catch (UnauthorizedAccessAttemptException ex) {
                    LOGGER.error("Failed to commit changes.", ex);
                    new Notification("Warning", "Failed to commit changes. See logfile for details.",
                            Notification.Type.WARNING_MESSAGE).show(Page.getCurrent());

                } finally {
                    mdm.close();
                }
            }
            //do cancel/reload and switch back to read-mode
            reset();
            switchEditMode();
        }
    };

    //save/cancel buttons
    saveEditButton = new NativeButton("Commit Update");
    saveEditButton.setIcon(new ThemeResource("img/16x16/save.png"));
    saveEditButton.setStyleName(BaseTheme.BUTTON_LINK);
    saveEditButton.setDescription("Save changes to this digital object's metadata.");
    saveEditButton.addClickListener(saveCancelButtonListener);
    cancelEditButton = new NativeButton("Cancel Update");
    cancelEditButton.setIcon(new ThemeResource("img/16x16/cancel.png"));
    cancelEditButton.setStyleName(BaseTheme.BUTTON_LINK);
    cancelEditButton.setDescription("Withdraw all changes to this digital object's metadata.");
    cancelEditButton.addClickListener(saveCancelButtonListener);

    //default action layout
    Label spacerMiscActionLayout = new Label();
    miscActionLayout = new HorizontalLayout(editButton, shareButton, starButton, spacerMiscActionLayout);
    miscActionLayout.setWidth("100%");
    miscActionLayout.setHeight("18px");
    miscActionLayout.setSpacing(false);
    miscActionLayout.setMargin(false);
    miscActionLayout.setExpandRatio(spacerMiscActionLayout, .9f);

    //edit action layout
    Label spacerEditActionLayout = new Label();
    editActionLayout = new HorizontalLayout(saveEditButton, cancelEditButton, spacerEditActionLayout);
    editActionLayout.setWidth("100%");
    editActionLayout.setHeight("18px");
    editActionLayout.setSpacing(false);
    editActionLayout.setMargin(false);
    editActionLayout.setExpandRatio(spacerEditActionLayout, .9f);

    //divider generation
    Label dividerTop = new Label();
    dividerTop.setHeight("5px");
    dividerTop.addStyleName("horizontal-line");
    dividerTop.setWidth("90%");
    Label dividerBottom = new Label();
    dividerBottom.setHeight("5px");
    dividerBottom.addStyleName("horizontal-line");
    dividerBottom.setWidth("90%");
    Label dividerLeft = new Label();
    dividerLeft.addStyleName("vertical-line");
    dividerLeft.setWidth("5px");
    dividerLeft.setHeight("90%");
    Label dividerRight = new Label();
    dividerRight.addStyleName("vertical-line");
    dividerRight.setWidth("5px");
    dividerRight.setHeight("90%");

    //build content layout
    HorizontalLayout contentLayout = new HorizontalLayout(typeImage, dividerLeft, dcLayout, dividerRight,
            downloadButton);
    contentLayout.setSizeFull();
    contentLayout.setSpacing(true);
    contentLayout.setComponentAlignment(typeImage, Alignment.TOP_RIGHT);
    contentLayout.setComponentAlignment(dividerLeft, Alignment.MIDDLE_CENTER);
    contentLayout.setComponentAlignment(dcLayout, Alignment.MIDDLE_CENTER);
    contentLayout.setComponentAlignment(dividerRight, Alignment.MIDDLE_CENTER);
    contentLayout.setComponentAlignment(downloadButton, Alignment.BOTTOM_CENTER);
    contentLayout.setExpandRatio(typeImage, .1f);
    contentLayout.setExpandRatio(dcLayout, .8f);
    contentLayout.setExpandRatio(downloadButton, .1f);

    //build main layout
    mainLayout = new VerticalLayout(dividerTop, contentLayout, dividerBottom, miscActionLayout);
    mainLayout.setExpandRatio(dividerTop, .05f);
    mainLayout.setComponentAlignment(dividerTop, Alignment.TOP_LEFT);
    mainLayout.setExpandRatio(contentLayout, .80f);
    mainLayout.setExpandRatio(dividerBottom, .05f);
    mainLayout.setComponentAlignment(dividerBottom, Alignment.BOTTOM_RIGHT);
    mainLayout.setExpandRatio(miscActionLayout, .1f);
    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainLayout.addStyleName("basic");
    mainLayout.setWidth("100%");
    mainLayout.setHeight("185px");
    //do reset to load title and description
    reset();
    LOGGER.debug("Layout successfully build up.");
}

From source file:edu.kit.dama.ui.repo.MyVaadinUI.java

License:Apache License

/**
 * Build the search view and execute the provided query immediately.
 *
 * @param pQuery The query to execute or null if an empty view should be
 * shown.//ww  w.  ja  va 2 s  .  c o  m
 */
private void buildSearchView(String pQuery) {
    loginButton.setWidth("70px");
    loginButton.setStyleName(BaseTheme.BUTTON_LINK);
    logoutButton.setWidth("70px");
    logoutButton.setStyleName(BaseTheme.BUTTON_LINK);
    adminButton.setWidth("70px");
    adminButton.setStyleName(BaseTheme.BUTTON_LINK);

    logoutButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            loggedInUser = UserData.NO_USER;
            refreshMainLayout();
        }
    });

    adminButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Page.getCurrent()
                    .open(DataManagerSettings.getSingleton().getStringProperty(
                            DataManagerSettings.GENERAL_BASE_URL_ID, "http://localhost:8889/BaReDemo")
                            + "/admin", "_blank");
        }
    });

    searchField = UIUtils7.factoryTextField(null, "Search for...");
    searchField.setWidth("920px");
    searchField.setHeight("60px");
    searchField.addStyleName("searchField");

    paginationPanel = new PaginationPanel(this);
    paginationPanel.setSizeFull();
    paginationPanel.setAllEntries(new LinkedList<DigitalObjectId>());

    searchProvider = new FulltextElasticSearchProvider(
            DataManagerSettings.getSingleton()
                    .getStringProperty(DataManagerSettings.ELASTIC_SEARCH_DEFAULT_CLUSTER_ID, "KITDataManager"),
            DataManagerSettings.getSingleton()
                    .getStringProperty(DataManagerSettings.ELASTIC_SEARCH_DEFAULT_HOST_ID, "localhost"),
            DataManagerSettings.getSingleton().getStringProperty(
                    DataManagerSettings.ELASTIC_SEARCH_DEFAULT_INDEX_ID,
                    ElasticsearchHelper.ELASTICSEARCH_TYPE),
            ElasticsearchHelper.ELASTICSEARCH_TYPE);
    NativeButton goButton = new NativeButton();
    goButton.setIcon(new ThemeResource("img/24x24/search.png"));
    goButton.setWidth("60px");
    goButton.setHeight("60px");
    goButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            doSearch();
        }
    });
    goButton.setClickShortcut(KeyCode.ENTER);

    setupLoginForm();
    loginForm.setWidth("320px");
    loginForm.setHeight("150px");
    final PopupView loginPopup = new PopupView(null, loginForm);
    loginPopup.setHideOnMouseOut(false);
    loginButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            //mainLayout.replaceComponent(searchLayout, loginForm);
            loginPopup.setPopupVisible(true);
        }
    });

    Label filler = new Label();
    memberLayout = new HorizontalLayout(filler, adminButton, loginButton, loginPopup);
    memberLayout.setComponentAlignment(loginButton, Alignment.TOP_RIGHT);
    memberLayout.setComponentAlignment(adminButton, Alignment.TOP_RIGHT);
    memberLayout.setComponentAlignment(loginPopup, Alignment.TOP_RIGHT);

    memberLayout.setExpandRatio(filler, 1.0f);
    memberLayout.setMargin(false);
    memberLayout.setSpacing(false);
    memberLayout.setWidth("100%");
    memberLayout.setHeight("30px");

    Label spacer = new Label("<hr/>", ContentMode.HTML);
    spacer.setHeight("20px");

    searchLayout = new UIUtils7.GridLayoutBuilder(3, 4)
            .addComponent(searchField, Alignment.TOP_LEFT, 0, 0, 2, 1)
            .addComponent(goButton, Alignment.TOP_RIGHT, 2, 0, 1, 1).fillRow(spacer, 0, 1, 1)
            .addComponent(paginationPanel, Alignment.MIDDLE_CENTER, 0, 2, 3, 2).getLayout();
    searchLayout.addStyleName("paper");
    searchLayout.setSpacing(true);
    searchLayout.setMargin(true);
    paginationPanel.setWidth("980px");
    //wrapper
    Label icon8Link = new Label("<a href=\"http://icons8.com\">Icons by icon8.com</a>", ContentMode.HTML);
    mainLayout = new VerticalLayout(memberLayout, searchLayout, icon8Link);
    mainLayout.setComponentAlignment(memberLayout, Alignment.TOP_CENTER);
    mainLayout.setComponentAlignment(searchLayout, Alignment.TOP_CENTER);
    mainLayout.setComponentAlignment(icon8Link, Alignment.BOTTOM_RIGHT);
    mainLayout.setExpandRatio(memberLayout, .05f);
    mainLayout.setExpandRatio(searchLayout, .93f);
    mainLayout.setExpandRatio(icon8Link, .02f);

    VerticalLayout fullscreen = new VerticalLayout(mainLayout);
    fullscreen.setComponentAlignment(mainLayout, Alignment.TOP_CENTER);
    fullscreen.setSizeFull();
    setContent(fullscreen);

    mainLayout.setWidth("1024px");
    mainLayout.setHeight("768px");

    if (pQuery != null) {
        searchField.setValue(pQuery);
        doSearch();
    }
}