Example usage for com.vaadin.ui VerticalLayout setSizeUndefined

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

Introduction

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

Prototype

@Override
    public void setSizeUndefined() 

Source Link

Usage

From source file:org.eclipse.hawkbit.ui.login.AbstractHawkbitLoginUI.java

License:Open Source License

protected Component buildLoginForm() {

    final VerticalLayout loginPanel = new VerticalLayout();
    loginPanel.setSizeUndefined();
    loginPanel.setSpacing(true);/*from  ww w . j ava2s. c  o m*/
    loginPanel.addStyleName("login-panel");
    Responsive.makeResponsive(loginPanel);
    loginPanel.addComponent(buildFields());
    if (isDemo) {
        loginPanel.addComponent(buildDisclaimer());
    }
    loginPanel.addComponent(buildLinks());

    checkBrowserSupport(loginPanel);

    return loginPanel;
}

From source file:org.eclipse.hawkbit.ui.login.LoginView.java

License:Open Source License

private Component buildLoginForm() {

    final VerticalLayout loginPanel = new VerticalLayout();
    loginPanel.setSizeUndefined();
    loginPanel.setSpacing(true);//from   w  w  w. j  a  v  a  2  s .com
    loginPanel.addStyleName("dashboard-view");
    loginPanel.addStyleName("login-panel");
    Responsive.makeResponsive(loginPanel);
    loginPanel.addComponent(buildFields());
    loginPanel.addComponent(buildLinks());

    // Check if IE browser is not supported ( < IE11 )
    if (isUnsupportedBrowser()) {
        // Disable sign-in button and display a message
        signin.setEnabled(Boolean.FALSE);
        loginPanel.addComponent(buildUnsupportedMessage());
    }

    return loginPanel;
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsRigTableHelper.java

License:Open Source License

public VerticalLayout createTableLayoutForRig(final RigBean rigBean, final IRigAction controller) {
    Preconditions.checkNotNull(rigBean, "rigModel is null");
    final int RIG_TABLE_SIZE = 5;
    this.rigBean = rigBean;
    final Label selectedLabel = new Label("No selection");
    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeUndefined();
    this.rigTable = new Table();
    this.rigTable.setSelectable(true);
    this.rigTable.setMultiSelect(true);
    this.rigTable.setMultiSelectMode(MultiSelectMode.DEFAULT);
    this.rigTable.setImmediate(true);
    this.rigTable.setPageLength(RIG_TABLE_SIZE);
    this.rigTable.setWidth("350px");
    this.rigTable.setColumnReorderingAllowed(false);
    this.rigTable.setColumnCollapsingAllowed(false);
    this.rigTable.setRowHeaderMode(Table.ROW_HEADER_MODE_HIDDEN);
    this.rigTable.setContainerDataSource(fillRigTableData(rigBean.getContentList()));
    this.rigTable.setColumnHeaders(new String[] { "Name", "Id" }); // put
                                                                   // these
                                                                   // into
                                                                   // ELabsViewContants
    this.rigTable.addListener(new Table.ValueChangeListener() {
        private static final long serialVersionUID = 2000562132182698589L;

        @Override/*from   www.j  a  va 2 s.  co  m*/
        public void valueChange(final ValueChangeEvent event) {
            int selSize = 0;
            Set<?> values = null;
            try {
                values = (Set<?>) event.getProperty().getValue();
            } catch (ClassCastException e) {
                LOG.warn("Table should be multiselectable!", e.getMessage());
            }
            if (values == null || values.size() == 0) {
                selectedLabel.setValue("No selection");
            } else {
                selSize = values.size();
                selectedLabel.setValue("Selected: " + selSize + " element" + ((selSize > 1) ? "s" : ""));
            }

            if (selSize == 0) {
                rigDeleteButton.setEnabled(false);
            } else if (selSize == 1) {
                rigDeleteButton.setEnabled(true);
                rigDeleteButton.setCaption(DELETE_BUTTON_TEXT);
            } else {
                rigDeleteButton.setEnabled(true);
                rigDeleteButton.setCaption(DELETES_BUTTON_TEXT);
            }
        }
    });
    layout.addComponent(this.rigTable);
    layout.addComponent(selectedLabel);
    addRigButtonToLayout(layout, controller);
    return layout;
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsStudyTableHelper.java

License:Open Source License

public VerticalLayout createTableLayoutForMotPublications() {
    final int RIG_TABLE_SIZE = 4;
    final Label selectedLabel = new Label("No selection");
    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeUndefined();
    motPubTable = new Table();
    motPubTable.setSelectable(true);/*from w  w w .jav  a2  s  .co m*/
    motPubTable.setMultiSelect(true);
    motPubTable.setMultiSelectMode(MultiSelectMode.DEFAULT);
    motPubTable.setImmediate(true);
    motPubTable.setPageLength(RIG_TABLE_SIZE);
    motPubTable.setWidth("450px");
    motPubTable.setColumnReorderingAllowed(false);
    motPubTable.setColumnCollapsingAllowed(false);
    motPubTable.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY);
    motPubTable.setContainerDataSource(fillMotPubTableData());
    motPubTable.setColumnHeaders(new String[] { "Url" });
    motPubTable.addListener(new Table.ValueChangeListener() {
        private static final long serialVersionUID = 2000562132182698589L;

        @Override
        public void valueChange(final ValueChangeEvent event) {
            int selSize = 0;
            Set<?> values = null;
            try {
                values = (Set<?>) event.getProperty().getValue();
            } catch (ClassCastException e) {
                LOG.warn("Table should be multiselectable!", e.getMessage());
            }
            if (values == null || values.size() == 0) {
                selectedLabel.setValue("No selection");
            } else {
                selSize = values.size();
                selectedLabel.setValue("Selected: " + selSize + " document" + ((selSize > 1) ? "s" : ""));
            }

            if (selSize == 0) {
                motPubDeleteButton.setEnabled(false);
            } else if (selSize == 1) {
                motPubDeleteButton.setEnabled(true);
                motPubDeleteButton.setCaption(DELETE_BUTTON_TEXT);
            } else {
                motPubDeleteButton.setEnabled(true);
                motPubDeleteButton.setCaption(DELETES_BUTTON_TEXT);
            }
        }
    });
    layout.addComponent(motPubTable);
    layout.addComponent(selectedLabel);
    addMotPubButtonsToLayout(layout);
    return layout;
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsStudyTableHelper.java

License:Open Source License

public VerticalLayout createTableLayoutForResPublications() {
    final int RIG_TABLE_SIZE = 4;
    final Label selectedLabel = new Label("No selection");
    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeUndefined();
    resPubTable = new Table();
    resPubTable.setSelectable(true);//w  w  w. j  a  v a2  s . com
    resPubTable.setMultiSelect(true);
    resPubTable.setMultiSelectMode(MultiSelectMode.DEFAULT);
    resPubTable.setImmediate(true);
    resPubTable.setPageLength(RIG_TABLE_SIZE);
    resPubTable.setWidth("450px");
    resPubTable.setColumnReorderingAllowed(false);
    resPubTable.setColumnCollapsingAllowed(false);
    resPubTable.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY);
    resPubTable.setContainerDataSource(fillResPubTableData());
    resPubTable.setColumnHeaders(new String[] { "Url" });
    resPubTable.addListener(new Table.ValueChangeListener() {
        private static final long serialVersionUID = 2000562132182698589L;

        @Override
        public void valueChange(final ValueChangeEvent event) {
            int selSize = 0;
            Set<?> values = null;
            try {
                values = (Set<?>) event.getProperty().getValue();
            } catch (ClassCastException e) {
                LOG.warn("Table should be multiselectable!", e.getMessage());
            }
            if (values == null || values.size() == 0) {
                selectedLabel.setValue("No selection");
            } else {
                selSize = values.size();
                selectedLabel.setValue("Selected: " + selSize + " document" + ((selSize > 1) ? "s" : ""));
            }
            if (selSize == 0) {
                resPubDeleteButton.setEnabled(false);
            } else if (selSize == 1) {
                resPubDeleteButton.setEnabled(true);
                resPubDeleteButton.setCaption(DELETE_BUTTON_TEXT);
            } else {
                resPubDeleteButton.setEnabled(true);
                resPubDeleteButton.setCaption(DELETES_BUTTON_TEXT);
            }
        }
    });
    layout.addComponent(resPubTable);
    layout.addComponent(selectedLabel);
    addResPubButtonsToLayout(layout);
    return layout;
}

From source file:org.escidoc.browser.ui.dnd.FilesDropBox.java

License:Open Source License

private void showComponent(final Component component, final String name) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeUndefined();
    layout.setMargin(true);/*from  w  w w  .ja  v a  2 s  . c o m*/
    final Window window = new Window(name, layout);
    window.setSizeUndefined();
    component.setSizeUndefined();
    window.addComponent(component);
    getWindow().addWindow(window);
}

From source file:org.escidoc.browser.ui.maincontent.ContainerView.java

License:Open Source License

private void handleLayoutListeners() {
    if (hasAccess()) {

        vlPropertiesLeft.addListener(new LayoutClickListener() {
            private static final long serialVersionUID = 1L;

            @Override/*  ww w . ja va  2s . c om*/
            public void layoutClick(final LayoutClickEvent event) {
                // Get the child component which was clicked

                if (event.getChildComponent() != null) {
                    // Is Label?
                    if (event.getChildComponent().getClass().getCanonicalName() == "com.vaadin.ui.Label") {
                        final Label child = (Label) event.getChildComponent();
                        if ((child.getDescription() == ViewConstants.DESC_STATUS)
                                && (!lblStatus.getValue().equals(status + "withdrawn"))) {
                            reSwapComponents();
                            oldComponent = event.getClickedComponent();
                            swapComponent = editStatus(child.getValue().toString().replace(status, ""));
                            vlPropertiesLeft.replaceComponent(oldComponent, swapComponent);
                        } else if (child.getDescription() == ViewConstants.DESC_LOCKSTATUS) {
                            reSwapComponents();
                            oldComponent = event.getClickedComponent();
                            swapComponent = editLockStatus(child.getValue().toString().replace(status, ""));
                            vlPropertiesLeft.replaceComponent(oldComponent, swapComponent);
                        }
                    }
                    // else {
                    // // getWindow().showNotification(
                    // // "The click was over a " +
                    // event.getChildComponent().getClass().getCanonicalName()
                    // // + event.getChildComponent().getStyleName());
                    // }
                } else {
                    reSwapComponents();
                }
            }

            /**
             * Switch the component back to the original component (Label) after inline editing
             */
            private void reSwapComponents() {

                if (swapComponent != null) {
                    if (swapComponent instanceof Label) {
                        ((Label) oldComponent).setValue(((TextArea) swapComponent).getValue());
                    } else if ((swapComponent instanceof ComboBox)
                            && ((ComboBox) swapComponent).getValue() != null) {
                        ((Label) oldComponent).setValue(status + ((ComboBox) swapComponent).getValue());
                        // Because there should be no comment-window on
                        // Delete Operation
                        if (!(((ComboBox) swapComponent).getValue().equals("delete"))) {
                            addCommentWindow();
                        } else {
                            updateContainer("");
                        }
                    }
                    vlPropertiesLeft.replaceComponent(swapComponent, oldComponent);
                    swapComponent = null;
                }
            }

            private Component editLockStatus(final String lockStatus) {
                final ComboBox cmbLockStatus = new ComboBox();
                cmbLockStatus.setNullSelectionAllowed(false);
                if (lockStatus.contains("unlocked")) {
                    cmbLockStatus.addItem(LockStatus.LOCKED.toString().toLowerCase());
                } else {
                    cmbLockStatus.addItem(LockStatus.UNLOCKED.toString().toLowerCase());
                }
                cmbLockStatus.select(1);
                return cmbLockStatus;

            }

            private Component editStatus(final String publicStatus) {
                final ComboBox cmbStatus = new ComboBox();
                cmbStatus.setInvalidAllowed(false);
                cmbStatus.setNullSelectionAllowed(false);
                final String pubStatus = publicStatus.toUpperCase();
                if (publicStatus.equals("pending")) {
                    cmbStatus.addItem(PublicStatus.PENDING.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase());
                    cmbStatus.setNullSelectionItemId(PublicStatus.PENDING.toString().toLowerCase());
                    if (hasAccessDelResource()) {
                        cmbStatus.addItem("delete");
                    }

                } else if (publicStatus.equals("submitted")) {
                    cmbStatus.setNullSelectionItemId(PublicStatus.SUBMITTED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase());
                } else if (publicStatus.equals("in_revision")) {
                    cmbStatus.setNullSelectionItemId(PublicStatus.IN_REVISION.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase());
                } else if (publicStatus.equals("released")) {
                    cmbStatus.setNullSelectionItemId(PublicStatus.RELEASED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.WITHDRAWN.toString().toLowerCase());
                } else if (publicStatus.equals("withdrawn")) {
                    // do nothing
                } else {
                    cmbStatus.addItem(PublicStatus.valueOf(pubStatus));
                }
                cmbStatus.select(1);

                return cmbStatus;
            }

            private boolean hasAccessDelResource() {
                try {
                    return repositories.pdp().forCurrentUser().isAction(ActionIdConstants.DELETE_CONTAINER)
                            .forResource(resourceProxy.getId()).permitted();
                } catch (UnsupportedOperationException e) {
                    mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                } catch (EscidocClientException e) {
                    mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                } catch (URISyntaxException e) {
                    mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                }
            }

            public void addCommentWindow() {
                subwindow = new Window(ViewConstants.SUBWINDOW_EDIT);
                subwindow.setModal(true);
                // Configure the windws layout; by default a VerticalLayout
                VerticalLayout layout = (VerticalLayout) subwindow.getContent();
                layout.setMargin(true);
                layout.setSpacing(true);
                layout.setSizeUndefined();

                final TextArea editor = new TextArea("Your Comment");
                editor.setRequired(true);
                editor.setRequiredError("The Field may not be empty.");

                HorizontalLayout hl = new HorizontalLayout();

                Button close = new Button("Update", new Button.ClickListener() {
                    // inline click-listener
                    @Override
                    public void buttonClick(ClickEvent event) {
                        // close the window by removing it from the
                        // parent window
                        updateContainer(editor.getValue().toString());
                        (subwindow.getParent()).removeWindow(subwindow);
                    }
                });
                Button cancel = new Button("Cancel", new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        (subwindow.getParent()).removeWindow(subwindow);
                    }
                });

                hl.addComponent(close);
                hl.addComponent(cancel);

                subwindow.addComponent(editor);
                subwindow.addComponent(hl);
                mainWindow.addWindow(subwindow);
            }

            private void updatePublicStatus(Container container, String comment) {
                // Update PublicStatus if there is a change
                if (!resourceProxy.getVersionStatus()
                        .equals(lblCurrentVersionStatus.getValue().toString().replace(status, ""))) {

                    String publicStatusTxt = lblCurrentVersionStatus.getValue().toString().replace(status, "")
                            .toUpperCase();
                    if (publicStatusTxt.equals("DELETE")) {
                        new ResourceDeleteConfirmation(container, repositories.container(), mainWindow);

                    }
                    try {
                        repositories.container().changePublicStatus(container,
                                lblCurrentVersionStatus.getValue().toString().replace(status, "").toUpperCase(),
                                comment);
                        if (publicStatusTxt.equals("SUBMITTED")) {
                            mainWindow.showNotification(new Window.Notification(ViewConstants.SUBMITTED,
                                    Notification.TYPE_TRAY_NOTIFICATION));
                        } else if (publicStatusTxt.equals("IN_REVISION")) {
                            mainWindow.showNotification(new Window.Notification(ViewConstants.IN_REVISION,
                                    Notification.TYPE_TRAY_NOTIFICATION));
                        } else if (publicStatusTxt.equals("RELEASED")) {
                            mainWindow.showNotification(new Window.Notification(ViewConstants.RELEASED,
                                    Notification.TYPE_TRAY_NOTIFICATION));

                        } else if (publicStatusTxt.equals("WITHDRAWN")) {
                            mainWindow.showNotification(new Window.Notification(ViewConstants.WITHDRAWN,
                                    Notification.TYPE_TRAY_NOTIFICATION));
                        }
                    } catch (EscidocClientException e) {
                        mainWindow.showNotification(new Window.Notification(ViewConstants.ERROR, e.getMessage(),
                                Notification.TYPE_ERROR_MESSAGE));
                    }
                }
            }

            private void updateLockStatus(Container container, String comment) {
                // Update LockStatus if there is a change
                if (!resourceProxy.getLockStatus()
                        .equals(lblLockstatus.getValue().toString().replace(lockStatus, ""))) {
                    String lockStatusTxt = lblLockstatus.getValue().toString().replace(lockStatus, "")
                            .toUpperCase();
                    try {
                        if (lockStatusTxt.contains("LOCKED")) {
                            repositories.container().unlockResource(container, comment);
                            mainWindow.showNotification(new Window.Notification(ViewConstants.LOCKED,
                                    Notification.TYPE_TRAY_NOTIFICATION));
                        } else {
                            repositories.container().lockResource(container, comment);
                            mainWindow.showNotification(new Window.Notification(ViewConstants.UNLOCKED,
                                    Notification.TYPE_TRAY_NOTIFICATION));
                        }

                    } catch (EscidocClientException e) {
                        mainWindow.showNotification(new Window.Notification(ViewConstants.ERROR, e.getMessage(),
                                Notification.TYPE_ERROR_MESSAGE));
                    }
                }
            }

            private void updateContainer(String comment) {
                LOG.debug("Called the updateContainer");
                Container container;
                try {
                    container = repositories.container().findContainerById(resourceProxy.getId());
                    if (resourceProxy.getLockStatus().contains("unlocked")) {
                        updatePublicStatus(container, comment);
                        // retrive the container to get the last
                        // modifiaction date.
                        container = repositories.container().findContainerById(resourceProxy.getId());
                        updateLockStatus(container, comment);
                    } else {
                        updateLockStatus(container, comment);
                        updatePublicStatus(container, comment);
                    }
                } catch (final EscidocClientException e) {
                    LOG.debug("Infrastructure Exception " + e.getLocalizedMessage());
                }
            }

        });
    }

}

From source file:org.escidoc.browser.ui.maincontent.ContextView.java

License:Open Source License

/**
 * Called in the reSwapComponents()/* w w  w. j  av  a2 s  .c om*/
 * 
 * @return String
 */
public void addCommentWindow(final String status) {
    final Window subwindow = new Window(ViewConstants.SUBWINDOW_EDIT);
    subwindow.setModal(true);
    // Configure the windws layout; by default a VerticalLayout
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeUndefined();

    final TextArea editor = new TextArea("Your Comment");
    editor.setRequired(true);
    editor.setRequiredError("The Field may not be empty.");

    HorizontalLayout hl = new HorizontalLayout();

    Button close = new Button("Update", new Button.ClickListener() {

        @Override
        public void buttonClick(@SuppressWarnings("unused") com.vaadin.ui.Button.ClickEvent event) {
            // close the window by removing it from the parent window
            String comment = editor.getValue().toString();
            try {
                contextController.updatePublicStatus(status, resourceProxy.getId(), comment);
                mainWindow.showNotification("Context Status updated successfully",
                        Notification.TYPE_TRAY_NOTIFICATION);
            } catch (EscidocClientException e) {
                mainWindow.showNotification(
                        "Could not update Context Type, an error occurred" + e.getLocalizedMessage(),
                        Notification.TYPE_ERROR_MESSAGE);
            }
            (subwindow.getParent()).removeWindow(subwindow);

        }
    });
    Button cancel = new Button("Cancel", new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") com.vaadin.ui.Button.ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);

        }
    });

    hl.addComponent(close);
    hl.addComponent(cancel);

    subwindow.addComponent(editor);
    subwindow.addComponent(hl);
    mainWindow.addWindow(subwindow);
}

From source file:org.escidoc.browser.ui.maincontent.FolderView.java

License:Open Source License

private void handleLayoutListeners() {
    if (folderController.hasAccess()) {
        vlLeft.addListener(new LayoutClickListener() {
            private static final long serialVersionUID = 1L;

            private Window subwindow;

            @Override/*from ww w  . j av  a2s  .c  o m*/
            public void layoutClick(final LayoutClickEvent event) {
                // Get the child component which was clicked

                if (event.getChildComponent() != null) {
                    // Is Label?
                    if (event.getChildComponent().getClass().getCanonicalName() == "com.vaadin.ui.Label") {
                        final Label child = (Label) event.getChildComponent();
                        if ((child.getDescription() == ViewConstants.DESC_STATUS)
                                && (!lblStatus.getValue().equals(status + "withdrawn"))) {
                            reSwapComponents();
                            oldComponent = event.getClickedComponent();
                            swapComponent = editStatus(child.getValue().toString().replace(status, ""));
                            vlLeft.replaceComponent(oldComponent, swapComponent);
                        } else if (child.getDescription() == ViewConstants.DESC_LOCKSTATUS) {
                            reSwapComponents();
                            oldComponent = event.getClickedComponent();
                            swapComponent = editLockStatus(child.getValue().toString().replace(status, ""));
                            vlLeft.replaceComponent(oldComponent, swapComponent);
                        }
                    }
                    // else {
                    // // getWindow().showNotification(
                    // // "The click was over a " +
                    // event.getChildComponent().getClass().getCanonicalName()
                    // // + event.getChildComponent().getStyleName());
                    // }
                } else {
                    reSwapComponents();
                }
            }

            /**
             * Switch the component back to the original component (Label) after inline editing
             */
            private void reSwapComponents() {

                if (swapComponent != null) {
                    if (swapComponent instanceof Label) {
                        ((Label) oldComponent).setValue(((TextArea) swapComponent).getValue());
                    } else if ((swapComponent instanceof ComboBox)
                            && ((ComboBox) swapComponent).getValue() != null) {
                        ((Label) oldComponent).setValue(status + ((ComboBox) swapComponent).getValue());
                        // Because there should be no comment-window on
                        // Delete Operation
                        if (!(((ComboBox) swapComponent).getValue().equals("delete"))) {
                            addCommentWindow();
                        } else {
                            updateContainer("");
                        }
                    }
                    vlLeft.replaceComponent(swapComponent, oldComponent);
                    swapComponent = null;
                }
            }

            private Component editLockStatus(final String lockStatus) {
                final ComboBox cmbLockStatus = new ComboBox();
                cmbLockStatus.setNullSelectionAllowed(false);
                if (lockStatus.contains("unlocked")) {
                    cmbLockStatus.addItem(LockStatus.LOCKED.toString().toLowerCase());
                } else {
                    cmbLockStatus.addItem(LockStatus.UNLOCKED.toString().toLowerCase());
                }
                cmbLockStatus.select(1);
                return cmbLockStatus;

            }

            private Component editStatus(final String publicStatus) {
                final ComboBox cmbStatus = new ComboBox();
                cmbStatus.setInvalidAllowed(false);
                cmbStatus.setNullSelectionAllowed(false);
                final String pubStatus = publicStatus.toUpperCase();
                if (publicStatus.equals("pending")) {
                    cmbStatus.addItem(PublicStatus.PENDING.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase());
                    cmbStatus.setNullSelectionItemId(PublicStatus.PENDING.toString().toLowerCase());
                    if (hasAccessDelResource()) {
                        cmbStatus.addItem("delete");
                    }

                } else if (publicStatus.equals("submitted")) {
                    cmbStatus.setNullSelectionItemId(PublicStatus.SUBMITTED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase());
                } else if (publicStatus.equals("in_revision")) {
                    cmbStatus.setNullSelectionItemId(PublicStatus.IN_REVISION.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.IN_REVISION.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.SUBMITTED.toString().toLowerCase());
                } else if (publicStatus.equals("released")) {
                    cmbStatus.setNullSelectionItemId(PublicStatus.RELEASED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.RELEASED.toString().toLowerCase());
                    cmbStatus.addItem(PublicStatus.WITHDRAWN.toString().toLowerCase());
                } else if (publicStatus.equals("withdrawn")) {
                    // do nothing
                } else {
                    cmbStatus.addItem(PublicStatus.valueOf(pubStatus));
                }
                cmbStatus.select(1);

                return cmbStatus;
            }

            private boolean hasAccessDelResource() {
                try {
                    return repositories.pdp().forCurrentUser().isAction(ActionIdConstants.DELETE_CONTAINER)
                            .forResource(resourceProxy.getId()).permitted();
                } catch (UnsupportedOperationException e) {
                    router.getMainWindow().showNotification(e.getMessage(),
                            Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                } catch (EscidocClientException e) {
                    router.getMainWindow().showNotification(e.getMessage(),
                            Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                } catch (URISyntaxException e) {
                    router.getMainWindow().showNotification(e.getMessage(),
                            Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                }
            }

            public void addCommentWindow() {
                subwindow = new Window(ViewConstants.SUBWINDOW_EDIT);
                subwindow.setModal(true);
                // Configure the windws layout; by default a VerticalLayout
                VerticalLayout layout = (VerticalLayout) subwindow.getContent();
                layout.setMargin(true);
                layout.setSpacing(true);
                layout.setSizeUndefined();

                final TextArea editor = new TextArea("Your Comment");
                editor.setRequired(true);
                editor.setRequiredError("The Field may not be empty.");

                HorizontalLayout hl = new HorizontalLayout();

                Button close = new Button("Update", new Button.ClickListener() {
                    // inline click-listener
                    @Override
                    public void buttonClick(ClickEvent event) {
                        // close the window by removing it from the
                        // parent window
                        updateContainer(editor.getValue().toString());
                        (subwindow.getParent()).removeWindow(subwindow);
                    }
                });
                Button cancel = new Button("Cancel", new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        (subwindow.getParent()).removeWindow(subwindow);
                    }
                });

                hl.addComponent(close);
                hl.addComponent(cancel);

                subwindow.addComponent(editor);
                subwindow.addComponent(hl);
                router.getMainWindow().addWindow(subwindow);
            }

            private void updatePublicStatus(Container container, String comment) {
                // Update PublicStatus if there is a change
                if (!resourceProxy.getVersionStatus()
                        .equals(lblCurrentVersionStatus.getValue().toString().replace(status, ""))) {

                    String publicStatusTxt = lblCurrentVersionStatus.getValue().toString().replace(status, "")
                            .toUpperCase();
                    if (publicStatusTxt.equals("DELETE")) {
                        new ResourceDeleteConfirmation(container, repositories.container(),
                                router.getMainWindow());

                    }
                    try {
                        repositories.container().changePublicStatus(container,
                                lblCurrentVersionStatus.getValue().toString().replace(status, "").toUpperCase(),
                                comment);
                        if (publicStatusTxt.equals("SUBMITTED")) {
                            router.getMainWindow().showNotification(new Window.Notification(
                                    ViewConstants.SUBMITTED, Notification.TYPE_TRAY_NOTIFICATION));
                        } else if (publicStatusTxt.equals("IN_REVISION")) {
                            router.getMainWindow().showNotification(new Window.Notification(
                                    ViewConstants.IN_REVISION, Notification.TYPE_TRAY_NOTIFICATION));
                        } else if (publicStatusTxt.equals("RELEASED")) {
                            router.getMainWindow().showNotification(new Window.Notification(
                                    ViewConstants.RELEASED, Notification.TYPE_TRAY_NOTIFICATION));

                        } else if (publicStatusTxt.equals("WITHDRAWN")) {
                            router.getMainWindow().showNotification(new Window.Notification(
                                    ViewConstants.WITHDRAWN, Notification.TYPE_TRAY_NOTIFICATION));
                        }
                    } catch (EscidocClientException e) {
                        router.getMainWindow().showNotification(new Window.Notification(ViewConstants.ERROR,
                                e.getMessage(), Notification.TYPE_ERROR_MESSAGE));
                    }
                }
            }

            private void updateContainer(String comment) {
                LOG.debug("Called the updateContainer");
                Container container;
                try {
                    container = repositories.container().findContainerById(resourceProxy.getId());
                    if (resourceProxy.getLockStatus().contains("unlocked")) {
                        container = repositories.container().findContainerById(resourceProxy.getId());
                        updatePublicStatus(container, comment);
                    } else {
                        updatePublicStatus(container, comment);
                    }
                } catch (final EscidocClientException e) {
                    LOG.debug("Infrastructure Exception " + e.getLocalizedMessage());
                }
            }

        });
    }

}

From source file:org.escidoc.browser.ui.OrganizationSelectionView.java

License:Open Source License

public Window modalWindow() {
    final Window modalWindow = new Window("Select an Organization");
    modalWindow.setHeight("600px");
    modalWindow.setWidth("400px");
    VerticalLayout modalWindowLayout = (VerticalLayout) modalWindow.getContent();
    modalWindow.setModal(true);//  ww  w  .ja v  a2 s .  co m

    modalWindow.setContent(modalWindowLayout);

    modalWindowLayout.setMargin(true);
    modalWindowLayout.setSpacing(true);

    // modalWindowLayout.setWidth("400px");
    // modalWindowLayout.setHeight("600px");
    modalWindowLayout.setSizeUndefined();

    orgUnitFilter = new TextField(ViewConstants.ORGANIZATIONAL_UNIT);

    orgUnitFilter.setWidth("300px");
    modalWindowLayout.addComponent(orgUnitFilter);

    orgUnitFilter.addListener(new TextChangeListener() {

        private SimpleStringFilter filter;

        @Override
        public void textChange(TextChangeEvent event) {
            // // TODO refactor this, the list should not return the data
            // source
            Filterable ds = (Filterable) tree.getDataSource();
            ds.removeAllContainerFilters();
            filter = new SimpleStringFilter(PropertyId.NAME, event.getText(), true, false);
            ds.addContainerFilter(filter);
        }
    });

    buildOrganizationTreeView();
    modalWindowLayout.addComponent(tree);

    Button saveButton = new Button(ViewConstants.SAVE, new Button.ClickListener() {

        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            try {
                ResourceModel selected = tree.getSelected();
                List<ResourceModel> list = new ArrayList<ResourceModel>();
                list.add(selected);

                UserGroup updateGroup = repositories.group().updateGroup(resourceProxy.getId(),
                        (String) nameField.getValue(), list);
                mw.showNotification("Group, " + updateGroup.getXLinkTitle() + ", is updated",
                        Window.Notification.TYPE_TRAY_NOTIFICATION);

                dataSource.addBean(selected);
                mw.removeWindow(modalWindow);
            } catch (EscidocClientException e) {
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.append("Can not update a group. Reason: ");
                errorMessage.append(e.getMessage());
                mw.showNotification(ViewConstants.ERROR, errorMessage.toString(),
                        Window.Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
    modalWindowLayout.addComponent(saveButton);
    return modalWindow;
}