Example usage for com.vaadin.ui TextArea TextArea

List of usage examples for com.vaadin.ui TextArea TextArea

Introduction

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

Prototype

public TextArea(ValueChangeListener<String> valueChangeListener) 

Source Link

Document

Constructs a new TextArea with a value change listener.

Usage

From source file:org.escidoc.browser.ui.listeners.OnContextAdminDescriptor.java

License:Open Source License

/**
 * Editing since it has a parameter// w  ww. j  a  v a 2 s . c om
 * 
 * @param adminDescriptor
 */
public void adminDescriptorForm(AdminDescriptor adminDescriptor) {

    // Editing
    final Window subwindow = new Window("A modal subwindow");
    subwindow.setModal(true);
    subwindow.setWidth("650px");

    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);

    final TextField txtName = new TextField("Name");
    txtName.setValue(adminDescriptor.getName());
    txtName.setImmediate(true);
    txtName.setValidationVisible(true);
    final TextArea txtContent = new TextArea("Content");
    txtContent.setColumns(30);
    txtContent.setRows(40);
    try {
        txtContent.setValue(adminDescriptor.getContentAsString());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    txtContent.setColumns(30);

    Button addAdmDescButton = new Button("Add Description");
    addAdmDescButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {

            if (txtName.getValue().toString() == null) {
                router.getMainWindow().showNotification(ViewConstants.PLEASE_ENTER_A_NAME,
                        Notification.TYPE_ERROR_MESSAGE);

            } else if (!XmlUtil.isWellFormed(txtContent.getValue().toString())) {
                router.getMainWindow().showNotification(ViewConstants.XML_IS_NOT_WELL_FORMED,
                        Notification.TYPE_ERROR_MESSAGE);
            } else {
                controller.addAdminDescriptor(txtName.getValue().toString(), txtContent.getValue().toString());
                (subwindow.getParent()).removeWindow(subwindow);
                router.getMainWindow().showNotification("Addedd Successfully",
                        Notification.TYPE_HUMANIZED_MESSAGE);
            }
        }
    });

    subwindow.addComponent(txtName);
    subwindow.addComponent(txtContent);
    subwindow.addComponent(addAdmDescButton);

    Button close = new Button(ViewConstants.CLOSE, new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    layout.addComponent(close);
    layout.setComponentAlignment(close, Alignment.TOP_RIGHT);

    router.getMainWindow().addWindow(subwindow);

}

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/*from ww w.  j  a  va2 s . co 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, ""));
                            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()//from ww  w .  j av a 2  s . c o  m
 * 
 * @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 www  . j  a va 2 s. 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, ""));
                            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.view.helpers.ItemPropertiesVH.java

License:Open Source License

private void handleLayoutListeners() {
    if (controller.canUpdateItem()) {
        vlPropertiesLeft.addListener(new LayoutClickListener() {

            @Override// w w w. jav  a2 s.  co 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().equals("com.vaadin.ui.Label")) {
                        final Label child = (Label) event.getChildComponent();
                        if ((child.getDescription() == ViewConstants.DESC_STATUS2)
                                && (!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 {
                    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 {
                            updateItem("");
                        }
                    }
                    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(Integer.valueOf(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")) {
                    lblStatus.setValue("withdrawn");
                } else {
                    cmbStatus.addItem(PublicStatus.valueOf(pubStatus));
                }
                cmbStatus.select(Integer.valueOf(1));

                return cmbStatus;
            }

            private boolean hasAccessDelResource() {
                try {
                    return repositories.pdp().forCurrentUser().isAction(ActionIdConstants.DELETE_CONTAINER)
                            .forResource(resourceProxy.getId()).permitted();
                } catch (final UnsupportedOperationException e) {
                    mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                } catch (final EscidocClientException e) {
                    mainWindow.showNotification(e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                } catch (final 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
                final 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.");

                final HorizontalLayout hl = new HorizontalLayout();

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

                    private static final long serialVersionUID = 1424933077274899865L;

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

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        (subwindow.getParent()).removeWindow(subwindow);
                    }
                });

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

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

            private void updatePublicStatus(final Item item, final String comment) {
                Preconditions.checkNotNull(item, "Item is null");
                Preconditions.checkNotNull(comment, "Comment is null");
                // 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(item, repositories.item(), mainWindow);
                    }
                    try {
                        repositories.item().changePublicStatus(item,
                                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(final Item item, final String comment) {
                if (!resourceProxy.getLockStatus()
                        .equals(lblLockstatus.getValue().toString().replace(lockStatus, ""))) {
                    String lockStatusTxt = lblLockstatus.getValue().toString().replace(lockStatus, "")
                            .toUpperCase();
                    try {
                        if (lockStatusTxt.contains("LOCKED")) {
                            repositories.item().lockResource(item, comment);
                            mainWindow.showNotification(new Window.Notification(ViewConstants.LOCKED,
                                    Notification.TYPE_TRAY_NOTIFICATION));
                        } else {
                            repositories.item().unlockResource(item, 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 updateItem(final String comment) {
                Item item;
                try {
                    item = repositories.item().findItemById(resourceProxy.getId());
                    if (resourceProxy.getLockStatus().equals("unlocked")) {
                        updatePublicStatus(item, comment);
                        // retrive the container to get the last
                        // modifiaction date.
                        item = repositories.item().findItemById(resourceProxy.getId());
                        updateLockStatus(item, comment);
                    } else {
                        updateLockStatus(item, comment);
                        updatePublicStatus(item, comment);
                    }
                } catch (final EscidocClientException e) {
                    LOG.debug("Infrastructure Exception " + e.getLocalizedMessage());
                }
            }

        });
    }

}

From source file:org.esn.esobase.view.tab.QuestTranslateTab.java

public QuestTranslateTab(DBService service_) {
    this.setSizeFull();
    this.setSpacing(false);
    this.setMargin(false);
    this.service = service_;
    QuestChangeListener questChangeListener = new QuestChangeListener();
    FilterChangeListener filterChangeListener = new FilterChangeListener();
    questListlayout = new HorizontalLayout();
    questListlayout.setWidth(100f, Unit.PERCENTAGE);
    questListlayout.setSpacing(false);//from  w ww. j a  v  a 2s.  c  o m
    questListlayout.setMargin(false);
    locationTable = new ComboBox("?");
    locationTable.setPageLength(30);
    locationTable.setScrollToSelectedItem(true);
    locationTable.setWidth(100f, Unit.PERCENTAGE);
    locationTable.addValueChangeListener(filterChangeListener);
    locationTable.setDataProvider(new ListDataProvider<>(locations));
    questTable = new ComboBox("?");
    questTable.setWidth(100f, Unit.PERCENTAGE);
    questTable.setPageLength(15);
    questTable.setScrollToSelectedItem(true);

    questTable.setWidth(100f, Unit.PERCENTAGE);
    questTable.addValueChangeListener(questChangeListener);
    questTable.setDataProvider(new ListDataProvider<>(questList));
    questListlayout.addComponent(questTable);
    FormLayout locationAndQuestLayout = new FormLayout(locationTable, questTable);
    locationAndQuestLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    locationAndQuestLayout.setSizeFull();
    questListlayout.addComponent(locationAndQuestLayout);
    translateStatus = new ComboBoxMultiselect("? ",
            Arrays.asList(TRANSLATE_STATUS.values()));
    translateStatus.setClearButtonCaption("?");
    translateStatus.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            LoadFilters();
            LoadContent();
        }
    });
    noTranslations = new CheckBox("?  ?");
    noTranslations.setValue(Boolean.FALSE);
    noTranslations.addValueChangeListener(filterChangeListener);
    emptyTranslations = new CheckBox("?  ");
    emptyTranslations.setValue(Boolean.FALSE);
    emptyTranslations.addValueChangeListener(filterChangeListener);
    HorizontalLayout checkBoxlayout = new HorizontalLayout(noTranslations, emptyTranslations);
    checkBoxlayout.setSpacing(false);
    checkBoxlayout.setMargin(false);
    translatorBox = new ComboBox("");
    translatorBox.setPageLength(15);
    translatorBox.setScrollToSelectedItem(true);
    translatorBox.setDataProvider(new ListDataProvider<SysAccount>(service.getSysAccounts()));
    translatorBox.addValueChangeListener(filterChangeListener);
    refreshButton = new Button("");
    refreshButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            LoadFilters();
            LoadContent();
        }
    });
    countLabel = new Label();
    searchField = new TextField("?? ?");
    searchField.setSizeFull();
    searchField.addValueChangeListener(filterChangeListener);

    FormLayout filtersLayout = new FormLayout(translateStatus, translatorBox, checkBoxlayout, searchField);
    filtersLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    filtersLayout.setSizeFull();
    questListlayout.addComponent(filtersLayout);
    questListlayout.addComponent(refreshButton);
    questListlayout.addComponent(countLabel);
    questListlayout.setExpandRatio(locationAndQuestLayout, 0.4f);
    questListlayout.setExpandRatio(filtersLayout, 0.4f);
    questListlayout.setExpandRatio(refreshButton, 0.1f);
    questListlayout.setExpandRatio(countLabel, 0.1f);
    questListlayout.setHeight(105f, Unit.PIXELS);
    this.addComponent(questListlayout);
    infoLayout = new VerticalLayout();
    infoLayout.setSizeFull();
    infoLayout.setSpacing(false);
    infoLayout.setMargin(false);
    tabSheet = new TabSheet();
    tabSheet.setSizeFull();
    nameLayout = new VerticalLayout();
    nameLayout.setSizeFull();
    nameHLayout = new HorizontalLayout();
    nameHLayout.setSizeFull();
    nameHLayout.setSpacing(false);
    nameHLayout.setMargin(false);
    nameLayout = new VerticalLayout();
    nameLayout.setSizeFull();
    nameLayout.setSpacing(false);
    nameLayout.setMargin(false);
    questNameEnArea = new TextArea("?");
    questNameEnArea.setSizeFull();
    questNameEnArea.setRows(1);
    questNameEnArea.setReadOnly(true);
    questNameRuArea = new TextArea("? Ru");
    questNameRuArea.setSizeFull();
    questNameRuArea.setRows(1);
    questNameRuArea.setReadOnly(true);
    questNameRawEnArea = new TextArea("?  ");
    questNameRawEnArea.setSizeFull();
    questNameRawEnArea.setRows(1);
    questNameRawEnArea.setReadOnly(true);
    questNameRawRuArea = new TextArea("?   Ru");
    questNameRawRuArea.setSizeFull();
    questNameRawRuArea.setRows(1);
    questNameRawRuArea.setReadOnly(true);
    nameLayout.addComponents(questNameEnArea, questNameRuArea, questNameRawEnArea, questNameRawRuArea);
    nameHLayout.addComponent(nameLayout);
    nameTranslateLayout = new VerticalLayout();
    nameTranslateLayout.setSizeFull();
    nameTranslateLayout.setSpacing(false);
    nameTranslateLayout.setMargin(false);
    nameHLayout.addComponent(nameTranslateLayout);
    infoLayout.addComponent(nameHLayout);
    descriptionLayout = new VerticalLayout();
    descriptionLayout.setSizeFull();
    descriptionHLayout = new HorizontalLayout();
    descriptionHLayout.setSizeFull();
    descriptionHLayout.setSpacing(false);
    descriptionHLayout.setMargin(false);
    descriptionLayout = new VerticalLayout();
    descriptionLayout.setSizeFull();
    descriptionLayout.setSpacing(false);
    descriptionLayout.setMargin(false);
    questDescriptionEnArea = new TextArea("?");
    questDescriptionEnArea.setSizeFull();
    questDescriptionEnArea.setRows(4);
    questDescriptionEnArea.setReadOnly(true);
    questDescriptionRuArea = new TextArea("? Ru");
    questDescriptionRuArea.setSizeFull();
    questDescriptionRuArea.setRows(4);
    questDescriptionRuArea.setReadOnly(true);
    questDescriptionRawEnArea = new TextArea("?  ");
    questDescriptionRawEnArea.setSizeFull();
    questDescriptionRawEnArea.setRows(4);
    questDescriptionRawEnArea.setReadOnly(true);
    questDescriptionRawRuArea = new TextArea("?   Ru");
    questDescriptionRawRuArea.setSizeFull();
    questDescriptionRawRuArea.setRows(4);
    questDescriptionRawRuArea.setReadOnly(true);
    descriptionLayout.addComponents(questDescriptionEnArea, questDescriptionRuArea, questDescriptionRawEnArea,
            questDescriptionRawRuArea);
    descriptionHLayout.addComponent(descriptionLayout);
    descriptionTranslateLayout = new VerticalLayout();
    descriptionTranslateLayout.setSizeFull();
    descriptionTranslateLayout.setSpacing(false);
    descriptionTranslateLayout.setMargin(false);
    descriptionHLayout.addComponent(descriptionTranslateLayout);
    infoLayout.addComponent(descriptionHLayout);
    tabSheet.addTab(infoLayout, "?");
    stepsLayout = new VerticalLayout();
    stepsLayout.setSizeFull();
    stepsLayout.setSpacing(false);
    stepsLayout.setMargin(false);
    stepsData = new TreeData();
    stepsGrid = new TreeGrid(new TreeDataProvider(stepsData));
    stepsGrid.setSelectionMode(Grid.SelectionMode.NONE);
    stepsGrid.setRowHeight(250);
    stepsGrid.setHeaderVisible(false);
    stepsGrid.setSizeFull();
    stepsGrid.setItemCollapseAllowedProvider(new ItemCollapseAllowedProvider() {
        @Override
        public boolean test(Object item) {
            return false;
        }
    });
    stepsGrid.addColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            if (source instanceof QuestStep) {
                return "?";
            }
            if (source instanceof QuestDirection) {
                return " - " + ((QuestDirection) source).getDirectionType().name();
            }
            return null;
        }
    }).setId("rowType").setCaption("").setWidth(132).setStyleGenerator(rowStyleGenerator);
    stepsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestStep) {

                QuestStep step = (QuestStep) source;
                if (step.getTextEn() != null && !step.getTextEn().isEmpty()) {
                    TextArea textEnArea = new TextArea("?  ");
                    textEnArea.setValue(step.getTextEn());
                    textEnArea.setReadOnly(true);
                    textEnArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnArea);
                }
                if (step.getTextRu() != null && !step.getTextRu().isEmpty()) {
                    TextArea textRuArea = new TextArea("  ");
                    textRuArea.setValue(step.getTextRu());
                    textRuArea.setReadOnly(true);
                    textRuArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textRuArea);
                }
            } else if (source instanceof QuestDirection) {
                QuestDirection d = (QuestDirection) source;
                if (d.getTextEn() != null && !d.getTextEn().isEmpty()) {
                    TextArea textEnArea = new TextArea("?  ");
                    textEnArea.setValue(d.getTextEn());
                    textEnArea.setRows(2);
                    textEnArea.setReadOnly(true);
                    textEnArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnArea);
                }
                if (d.getTextRu() != null && !d.getTextRu().isEmpty()) {
                    TextArea textRuArea = new TextArea("  ");
                    textRuArea.setValue(d.getTextRu());
                    textRuArea.setRows(2);
                    textRuArea.setReadOnly(true);
                    textRuArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textRuArea);
                }

            }
            return result;
        }
    }).setId("ingameText").setStyleGenerator(rowStyleGenerator);
    stepsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestStep) {

                QuestStep step = (QuestStep) source;
                if (step.getSheetsJournalEntry() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(step.getSheetsJournalEntry().getTextEn());
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (step.getSheetsJournalEntry().getTextRu() != null && !step.getSheetsJournalEntry()
                            .getTextRu().equals(step.getSheetsJournalEntry().getTextEn())) {
                        TextArea textRuRawArea = new TextArea("    "
                                + step.getSheetsJournalEntry().getTranslator());
                        textRuRawArea.setValue(step.getSheetsJournalEntry().getTextRu());
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);//, "  " 
                    }
                }

            } else if (source instanceof QuestDirection) {
                QuestDirection d = (QuestDirection) source;
                if (d.getSheetsQuestDirection() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(d.getSheetsQuestDirection().getTextEn());
                    textEnRawArea.setRows(2);
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (d.getSheetsQuestDirection().getTextRu() != null && !d.getSheetsQuestDirection()
                            .getTextRu().equals(d.getSheetsQuestDirection().getTextEn())) {
                        TextArea textRuRawArea = new TextArea("    "
                                + d.getSheetsQuestDirection().getTranslator());
                        textRuRawArea.setValue(d.getSheetsQuestDirection().getTextRu());
                        textRuRawArea.setRows(2);
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);
                    }
                }
            }
            return result;
        }
    }).setId("rawText").setStyleGenerator(rowStyleGenerator);
    stepsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            Panel panel = new Panel();
            panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
            panel.setWidth(100f, Unit.PERCENTAGE);
            panel.setHeight(245f, Unit.PIXELS);
            final VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestStep) {

                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestStep step = (QuestStep) source;
                list.addAll(step.getSheetsJournalEntry().getTranslatedTexts());

                if (list != null) {
                    for (TranslatedText t : list) {
                        result.addComponent(new TranslationCell(t));
                        accounts.add(t.getAuthor());
                    }
                }
                if (!accounts.contains(SpringSecurityHelper.getSysAccount())
                        && step.getSheetsJournalEntry() != null
                        && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                    final TranslatedText translatedText = new TranslatedText();
                    translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                    translatedText.setSpreadSheetsJournalEntry(step.getSheetsJournalEntry());
                    Button addTranslation = new Button(" ",
                            FontAwesome.PLUS_SQUARE);
                    addTranslation.addClickListener(new Button.ClickListener() {

                        @Override
                        public void buttonClick(Button.ClickEvent event) {

                            if (translatedText.getSpreadSheetsJournalEntry() != null) {
                                translatedText.getSpreadSheetsJournalEntry().getTranslatedTexts()
                                        .add(translatedText);
                            }
                            result.addComponent(new TranslationCell(translatedText));
                            event.getButton().setVisible(false);
                        }
                    });
                    result.addComponent(addTranslation);
                }
            } else if (source instanceof QuestDirection) {
                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestDirection d = (QuestDirection) source;
                list.addAll(d.getSheetsQuestDirection().getTranslatedTexts());

                if (list != null) {
                    for (TranslatedText t : list) {
                        result.addComponent(new TranslationCell(t));
                        accounts.add(t.getAuthor());
                    }
                }
                if (!accounts.contains(SpringSecurityHelper.getSysAccount())
                        && d.getSheetsQuestDirection() != null
                        && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                    final TranslatedText translatedText = new TranslatedText();
                    translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                    translatedText.setSpreadSheetsQuestDirection(d.getSheetsQuestDirection());
                    Button addTranslation = new Button(" ");
                    addTranslation.addClickListener(new Button.ClickListener() {

                        @Override
                        public void buttonClick(Button.ClickEvent event) {

                            if (translatedText.getSpreadSheetsQuestDirection() != null) {
                                translatedText.getSpreadSheetsQuestDirection().getTranslatedTexts()
                                        .add(translatedText);
                            }
                            result.addComponent(new TranslationCell(translatedText));
                            event.getButton().setVisible(false);
                        }
                    });
                    result.addComponent(addTranslation);
                }
            }
            panel.setContent(result);
            return panel;
        }
    }).setId("translation").setStyleGenerator(rowStyleGenerator);
    stepsGrid.setColumns("rowType", "ingameText", "rawText", "translation");
    stepsLayout.addComponent(stepsGrid);
    tabSheet.addTab(stepsLayout, "");
    itemsGrid = new Grid(new ListDataProvider(itemList));
    itemsGrid.setSelectionMode(Grid.SelectionMode.NONE);
    itemsGrid.setRowHeight(250);
    itemsGrid.setHeaderVisible(false);
    itemsGrid.setSizeFull();
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                QuestItem item = (QuestItem) source;
                if (item.getName() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(item.getName().getTextEn());
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (item.getName().getTextRu() != null
                            && !item.getName().getTextRu().equals(item.getName().getTextEn())) {
                        TextArea textRuRawArea = new TextArea(
                                " ?    "
                                        + item.getName().getTranslator());
                        textRuRawArea.setValue(item.getName().getTextRu());
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);//, "  " 
                    }
                }

            }
            return result;
        }
    }).setId("rawName");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                QuestItem item = (QuestItem) source;
                if (item.getDescription() != null) {
                    TextArea textEnRawArea = new TextArea("?  ");
                    textEnRawArea.setValue(item.getDescription().getTextEn());
                    textEnRawArea.setReadOnly(true);
                    textEnRawArea.setWidth(100f, Unit.PERCENTAGE);
                    result.addComponent(textEnRawArea);
                    if (item.getDescription().getTextRu() != null
                            && !item.getDescription().getTextRu().equals(item.getDescription().getTextEn())) {
                        TextArea textRuRawArea = new TextArea(
                                " ??    "
                                        + item.getDescription().getTranslator());
                        textRuRawArea.setValue(item.getDescription().getTextRu());
                        textRuRawArea.setReadOnly(true);
                        textRuRawArea.setWidth(100f, Unit.PERCENTAGE);
                        result.addComponent(textRuRawArea);//, "  " 
                    }
                }

            }
            return result;
        }
    }).setId("rawDescription");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            Panel panel = new Panel();
            panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
            panel.setWidth(100f, Unit.PERCENTAGE);
            panel.setHeight(245f, Unit.PIXELS);
            final VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestItem item = (QuestItem) source;
                if (item.getName() != null) {
                    String text = item.getName().getTextEn();
                    list.addAll(item.getName().getTranslatedTexts());

                    if (list != null) {
                        for (TranslatedText t : list) {
                            result.addComponent(new TranslationCell(t));
                            accounts.add(t.getAuthor());
                        }
                    }
                    if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && text != null
                            && !text.isEmpty() && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                        final TranslatedText translatedText = new TranslatedText();
                        translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                        translatedText.setSpreadSheetsItemName(item.getName());
                        Button addTranslation = new Button(" ",
                                FontAwesome.PLUS_SQUARE);
                        addTranslation.addClickListener(new Button.ClickListener() {

                            @Override
                            public void buttonClick(Button.ClickEvent event) {

                                if (translatedText.getSpreadSheetsItemName() != null) {
                                    translatedText.getSpreadSheetsItemName().getTranslatedTexts()
                                            .add(translatedText);
                                }
                                result.addComponent(new TranslationCell(translatedText));
                                event.getButton().setVisible(false);
                            }
                        });
                        result.addComponent(addTranslation);
                    }
                }
            }
            panel.setContent(result);
            return panel;
        }
    }).setId("nameTranslation");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            Panel panel = new Panel();
            panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
            panel.setWidth(100f, Unit.PERCENTAGE);
            panel.setHeight(245f, Unit.PIXELS);
            final VerticalLayout result = new VerticalLayout();
            result.setSpacing(false);
            result.setMargin(false);
            if (source instanceof QuestItem) {

                Set<TranslatedText> list = new HashSet<>();
                List<SysAccount> accounts = new ArrayList<>();

                QuestItem item = (QuestItem) source;
                if (item.getDescription() != null) {
                    String text = item.getDescription().getTextEn();
                    list.addAll(item.getDescription().getTranslatedTexts());

                    if (list != null) {
                        for (TranslatedText t : list) {
                            result.addComponent(new TranslationCell(t));
                            accounts.add(t.getAuthor());
                        }
                    }
                    if (!accounts.contains(SpringSecurityHelper.getSysAccount()) && text != null
                            && !text.isEmpty() && SpringSecurityHelper.hasRole("ROLE_TRANSLATE")) {
                        final TranslatedText translatedText = new TranslatedText();
                        translatedText.setAuthor(SpringSecurityHelper.getSysAccount());
                        translatedText.setSpreadSheetsItemDescription(item.getDescription());
                        Button addTranslation = new Button(" ",
                                FontAwesome.PLUS_SQUARE);
                        addTranslation.addClickListener(new Button.ClickListener() {

                            @Override
                            public void buttonClick(Button.ClickEvent event) {

                                if (translatedText.getSpreadSheetsItemDescription() != null) {
                                    translatedText.getSpreadSheetsItemDescription().getTranslatedTexts()
                                            .add(translatedText);
                                }
                                result.addComponent(new TranslationCell(translatedText));
                                event.getButton().setVisible(false);
                            }
                        });
                        result.addComponent(addTranslation);
                    }
                }
            }
            panel.setContent(result);
            return panel;
        }
    }).setId("descriptionTranslation");
    itemsGrid.addComponentColumn(new ValueProvider() {
        @Override
        public Object apply(Object source) {
            VerticalLayout result = new VerticalLayout();
            result.setMargin(new MarginInfo(true, false, false, false));
            result.setSpacing(false);
            if (source instanceof QuestItem) {
                GSpreadSheetsItemName name = ((QuestItem) source).getName();
                if (name.getIcon() != null) {
                    Image image = new Image(null, new ExternalResource(
                            "https://elderscrolls.net" + name.getIcon().replaceAll(".dds", ".png")));
                    result.addComponent(image);
                    return result;
                }
            }
            return result;
        }
    }).setId("icon").setWidth(95);
    itemsGrid.setColumns("icon", "rawName", "nameTranslation", "rawDescription", "descriptionTranslation");
    tabSheet.addTab(itemsGrid, "");
    this.addComponent(tabSheet);
    this.setExpandRatio(tabSheet, 1f);
    GridScrollExtension stepsScrollExtension = new GridScrollExtension(stepsGrid);
    GridScrollExtension itemsScrollExtension = new GridScrollExtension(itemsGrid);
    new NoAutcompleteComboBoxExtension(locationTable);
    new NoAutcompleteComboBoxExtension(questTable);
    new NoAutcompleteComboBoxExtension(translatorBox);
    LoadFilters();
}

From source file:org.fossa.rolp.ui.einschaetzung.EinschaetzungAnlegenFormFields.java

License:Open Source License

@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
    Field field = super.createField(item, propertyId, uiContext);

    if (propertyId.equals(EinschaetzungPojo.EINSCHAETZUNGSTEXT_COLUMN)) {
        TextArea text = new TextArea("");
        text.setStyleName("einschaetzungText");
        text.setWidth("100%");
        text.setRows(25);//w  w  w  .  ja  v a  2s . c o m
        text.setRequired(true);
        return text;
    }
    return field;
}

From source file:org.ikasan.dashboard.ui.dashboard.panel.DashboardPanel.java

License:BSD License

@Subscribe
public void receiveAlertEvent(final AlertEvent event) {
    UI.getCurrent().access(new Runnable() {
        @Override//from w w w  . j ava2 s  . c  om
        public void run() {
            VaadinSession.getCurrent().getLockInstance().lock();
            try {
                Item item = container.addItemAt(0, event.getAlert() + this);

                Property<String> alertProperty = item.getItemProperty("Alert");

                alertProperty.setValue(event.getAlert());

                final Property<String> moduleProperty = item.getItemProperty("Module");

                moduleProperty.setValue(event.getModule());

                TextArea notesField = new TextArea("Notes");
                notesField.setWidth("500px");
                notesField.setRequired(false);
                notesField.setHeight("150px");
                notesField.setImmediate(true);
                notesField.setStyleName("coursedetailtext");
                // popup notes view
                final PopupView notesPopupView = new PopupView("Details", notesField);
                notesPopupView.setCaption("Details");
                notesPopupView.setHideOnMouseOut(false);
                notesPopupView.setData(event.getAlert() + this);

                final Property<PopupView> detailsProperty = item.getItemProperty("Details");

                detailsProperty.setValue(notesPopupView);

                System.out.println("container = " + container);
                System.out.println("Item = " + item);
            } finally {
                VaadinSession.getCurrent().getLockInstance().unlock();
            }

            //               UI.getCurrent().push();   
        }
    });
}

From source file:org.jumpmind.vaadin.ui.sqlexplorer.DbExportDialog.java

License:Open Source License

protected void createOptionLayout() {
    optionLayout = new VerticalLayout();
    optionLayout.addStyleName("v-scrollable");
    optionLayout.setMargin(true);//from  ww w.ja  va 2  s. c o m
    optionLayout.setSpacing(true);
    optionLayout.setSizeFull();
    optionLayout.addComponent(new Label("Please choose from the following options"));

    FormLayout formLayout = new FormLayout();
    formLayout.setSizeFull();
    optionLayout.addComponent(formLayout);
    optionLayout.setExpandRatio(formLayout, 1);

    formatSelect = new ComboBox("Format");
    formatSelect.setImmediate(true);
    for (DbExportFormat format : DbExportFormat.values()) {
        formatSelect.addItem(format);
    }
    formatSelect.setNullSelectionAllowed(false);
    formatSelect.setValue(DbExportFormat.SQL);
    formatSelect.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            DbExportFormat format = (DbExportFormat) formatSelect.getValue();

            switch (format) {
            case SQL:
                compatibilitySelect.setEnabled(true);
                compatibilitySelect.setNullSelectionAllowed(false);
                setDefaultCompatibility();
                data.setEnabled(true);
                foreignKeys.setEnabled(true);
                indices.setEnabled(true);
                quotedIdentifiers.setEnabled(true);
                break;
            case XML:
                compatibilitySelect.setEnabled(false);
                compatibilitySelect.setNullSelectionAllowed(true);
                compatibilitySelect.setValue(null);
                data.setEnabled(true);
                foreignKeys.setEnabled(true);
                indices.setEnabled(true);
                quotedIdentifiers.setEnabled(true);
                break;
            case CSV:
                compatibilitySelect.setEnabled(false);
                compatibilitySelect.setNullSelectionAllowed(true);
                compatibilitySelect.setValue(null);
                data.setEnabled(false);
                foreignKeys.setEnabled(false);
                indices.setEnabled(false);
                quotedIdentifiers.setEnabled(false);
                break;
            case SYM_XML:
                compatibilitySelect.setEnabled(false);
                compatibilitySelect.setNullSelectionAllowed(true);
                compatibilitySelect.setValue(null);
                data.setEnabled(false);
                foreignKeys.setEnabled(false);
                indices.setEnabled(false);
                quotedIdentifiers.setEnabled(false);
                break;
            }
        }
    });
    formatSelect.select(DbExportFormat.SQL);
    formLayout.addComponent(formatSelect);

    compatibilitySelect = new ComboBox("Compatibility");
    for (Compatible compatability : Compatible.values()) {
        compatibilitySelect.addItem(compatability);
    }

    compatibilitySelect.setNullSelectionAllowed(false);
    setDefaultCompatibility();
    formLayout.addComponent(compatibilitySelect);

    createInfo = new CheckBox("Create Tables");
    formLayout.addComponent(createInfo);

    dropTables = new CheckBox("Drop Tables");
    formLayout.addComponent(dropTables);

    data = new CheckBox("Insert Data");
    data.setValue(true);
    formLayout.addComponent(data);

    foreignKeys = new CheckBox("Create Foreign Keys");
    formLayout.addComponent(foreignKeys);

    indices = new CheckBox("Create Indices");
    formLayout.addComponent(indices);

    quotedIdentifiers = new CheckBox("Qualify with Quoted Identifiers");
    formLayout.addComponent(quotedIdentifiers);

    whereClauseField = new TextArea("Where Clause");
    whereClauseField.setWidth(100, Unit.PERCENTAGE);
    whereClauseField.setRows(2);
    formLayout.addComponent(whereClauseField);

    exportFormatOptionGroup = new OptionGroup("Export Format");
    exportFormatOptionGroup.setImmediate(true);
    exportFormatOptionGroup.addItem(EXPORT_AS_A_FILE);
    if (queryPanel != null) {
        exportFormatOptionGroup.addItem(EXPORT_TO_THE_SQL_EDITOR);
    }
    exportFormatOptionGroup.setValue(EXPORT_AS_A_FILE);
    exportFormatOptionGroup.addValueChangeListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            setExportButtonsEnabled();
        }
    });
    formLayout.addComponent(exportFormatOptionGroup);

}

From source file:org.milleni.dunning.ui.prcstart.BulkDunningProcessFinishPanel.java

License:Apache License

protected void initSettingsProperties() {
    panelLayout = new VerticalLayout();
    panelLayout.setSpacing(true);//from  w  w  w  .j a va  2 s  . c  o  m
    detailLayout.setMargin(true, true, true, false);
    detailLayout.addComponent(panelLayout);

    // Database type
    Label reason = new Label("Dunning Surecini Bitirmek Icin Aciklama Giriniz.");
    panelLayout.addComponent(reason);

    textAreaReason = new TextArea("");
    textAreaReason.setRequired(true);
    textAreaReason.setEnabled(true);
    textAreaReason.setRows(2);
    textAreaReason.setColumns(50);
    textAreaReason.setMaxLength(150);
    panelLayout.addComponent(textAreaReason);

    textArea = new TextArea("");
    textArea.setRequired(true);
    textArea.setEnabled(true);
    textArea.setRows(10);
    textArea.setColumns(50);
    panelLayout.addComponent(textArea);

    Button claimButton = new Button("Dunning Sureci Sonlandr");
    claimButton.setIcon(Images.EXECUTE);
    claimButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            String customerIds = (String) textArea.getValue();
            String reason = loggedInUser.getFullName() + " " + (String) textAreaReason.getValue();
            String[] customerIdArray = customerIds.split("\n");
            List<Long> customerIdList = new ArrayList<Long>();

            DunningProcessMasterRepository dpmRepository = DaoHelper.getInstance()
                    .getDunningProcessMasterRepository();
            DunningProcessService dpmService = DaoHelper.getInstance().getDunningProcessService();

            for (String strCustomerId : customerIdArray) {
                strCustomerId = strCustomerId.trim();
                if (StringUtils.hasText(strCustomerId)) {
                    try {
                        customerIdList.add(Long.parseLong(strCustomerId));
                    } catch (Exception ex) {
                        throw new RuntimeException(
                                strCustomerId + " musteri no yanlis formatta " + ex.getMessage());
                    }
                }
            }

            for (Long customerId : customerIdList) {
                List<DunningProcessMaster> dpmList = dpmRepository.findDunningProcessMastersByStatus(customerId,
                        Constants.RUNNING);
                if (dpmList != null && dpmList.size() > 0) {

                    if (dpmList.size() > 1)
                        throw new RuntimeException(
                                customerId + " musterinin birden fazla dunning sureci var. Kontrol ediniz.");

                    DunningProcessMaster dpm = dpmList.get(0);
                    String processInctanceId = dpm.getBpmProcessId();
                    try {
                        runtimeService.deleteProcessInstance(processInctanceId, null);
                        dpm.setStatus(dpmRepository.getProcessStatus(Constants.MANUAL_FINISHED));
                        dpm.setStatusDesc(reason);
                        dpmService.saveDunningProcessMaster(dpm);
                        List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery()
                                .processDefinitionKey(Constants.FL95_SuspendToActive)
                                .variableValueEquals("customerId", customerId).list();
                        if (processInstances != null && processInstances.size() > 0) {
                            for (ProcessInstance processInstance : processInstances) {
                                runtimeService.deleteProcessInstance(processInstance.getId(), null);
                            }
                        }
                    } catch (Exception ex) {
                        throw new RuntimeException(
                                customerId + " musterinin processi silinirken hata olustu." + ex.getMessage());
                    }
                }
            }

            textArea.setValue("");
        }
    });

    panelLayout.addComponent(claimButton);
}