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() 

Source Link

Document

Constructs an empty TextArea.

Usage

From source file:net.sourceforge.javydreamercsw.validation.manager.web.file.TextDisplay.java

License:Apache License

@Override
public Window getViewer(File f) {
    BufferedReader br = null;//from w w  w. jav a2s  .  c o m
    Window w = new VMWindow(f.getName());
    w.setHeight(80, Sizeable.Unit.PERCENTAGE);
    w.setWidth(80, Sizeable.Unit.PERCENTAGE);
    //Just a plain panel will do
    TextArea text = new TextArea();
    text.setSizeFull();
    w.setContent(text);
    try {
        br = new BufferedReader(new FileReader(f));
        String line;
        StringBuilder sb = new StringBuilder();
        try {
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
            text.setValue(sb.toString());
            text.setReadOnly(true);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        try {
            if (br != null) {
                br.close();
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return w;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java

License:Apache License

private void showVersioningPrompt(Versionable ao, Runnable r) {
    VerticalLayout layout = new VerticalLayout();
    TextArea message = new TextArea();
    message.setValue(TRANSLATOR.translate("missing.reason.message"));
    message.setReadOnly(true);/*w  ww .  j a v  a  2s  . c o  m*/
    message.setSizeFull();
    TextArea desc = new TextArea(TRANSLATOR.translate("general.reason"));
    desc.setSizeFull();
    layout.addComponent(message);
    layout.addComponent(desc);
    //Prompt user with reason for change
    MessageBox prompt = MessageBox.createQuestion();
    prompt.withCaption(TRANSLATOR.translate("missing.reason.title")).withMessage(layout).withYesButton(() -> {
        ao.setReason(desc.getValue());
        if (r != null) {
            r.run();
        }
    }, ButtonOption.focus(), ButtonOption.icon(VaadinIcons.CHECK), ButtonOption.disable())
            .withNoButton(ButtonOption.icon(VaadinIcons.CLOSE));
    prompt.getWindow().setIcon(ValidationManagerUI.SMALL_APP_ICON);
    desc.addTextChangeListener((TextChangeEvent event1) -> {
        //Enable if there is a description change.
        prompt.getButton(ButtonType.YES).setEnabled(!event1.getText().trim().isEmpty());
    });
    prompt.getWindow().setWidth(50, Unit.PERCENTAGE);
    prompt.getWindow().setHeight(50, Unit.PERCENTAGE);
    prompt.open();
}

From source file:nl.kpmg.lcm.ui.view.metadata.MetadataEditWindow.java

License:Apache License

private Layout initRawPanel() {
    textArea = new TextArea();
    textArea.setWidth("100%");
    textArea.setHeight("100%");
    textArea.setRows(MAX_NUMBER_OF_ROWS_FOR_RAW_PANEL);

    ObjectMapper objectMapper = new ObjectMapper();
    try {// w ww. j a v  a 2  s. c o m
        String rawMetadata = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(metadata);
        textArea.setValue(rawMetadata);
    } catch (JsonProcessingException ex) {
        textArea.setEnabled(false);
        LOGGER.warn("Couldn't serialize metadata object", ex);
    }

    saveButton = new Button("Save");
    saveButton.addClickListener(this);

    VerticalLayout panelContent = new VerticalLayout();
    panelContent.setMargin(true);
    panelContent.setSpacing(true);
    panelContent.addComponent(textArea);
    panelContent.addComponent(saveButton);

    return panelContent;
}

From source file:nz.co.senanque.workflowui.FieldGroupWizard.java

License:Apache License

@SuppressWarnings("serial")
public void load(final WorkflowForm form) {

    ProcessDefinition processDefinition = form.getProcessDefinition();
    String task = processDefinition.getTask(form.getProcessInstance().getTaskId()).toString();

    ProcessDefinition ownerProcessDefinition = processDefinition;
    while (processDefinition != null) {
        ownerProcessDefinition = processDefinition;
        processDefinition = processDefinition.getOwnerProcess();
    }//from w  ww. jav  a 2  s  .  com
    setCaption(m_messageSourceAccessor.getMessage("form.wizard.caption",
            new Object[] { new Long(form.getProcessInstance().getId()), ownerProcessDefinition.getName(),
                    form.getProcessInstance().getReference(), ownerProcessDefinition.getDescription() }));
    formPanel.removeAllComponents();
    formPanel.addComponent((VerticalLayout) form);
    ProcessInstance processInstance = form.getProcessInstance();
    if (!form.isReadOnly()) {
        PermissionManager pm = m_maduraSessionManager.getPermissionManager();
        processInstance = getWorkflowClient().lockProcessInstance(form.getProcessInstance(),
                pm.hasPermission(FixedPermissions.TECHSUPPORT), pm.getCurrentUser());
        if (processInstance == null) {
            com.vaadin.ui.Notification.show(m_messageSourceAccessor.getMessage("failed.to.get.lock"),
                    m_messageSourceAccessor.getMessage("message.noop"),
                    com.vaadin.ui.Notification.Type.HUMANIZED_MESSAGE);
            return;
        }
    }
    form.setProcessInstance(processInstance);
    // This is binding the process instance associated with the form to the workflow validation session.
    //        log.debug("Binding {} to Validation engine {}",processInstance.getClass().getSimpleName(),getMaduraSessionManager().getValidationEngine().getIdentifier());
    getMaduraSessionManager().getValidationSession().bind(form.getProcessInstance());
    ((VerticalLayout) form).addListener(new Listener() {

        @Override
        public void componentEvent(Event event) {
            close();
            fireEvent(event);
        }
    });

    formPanel.markAsDirty();

    BeanItem<ProcessInstance> beanItem = new BeanItem<ProcessInstance>(form.getProcessInstance());

    m_maduraFieldGroup = m_maduraSessionManager.createMaduraFieldGroup();
    Button attachments = m_maduraFieldGroup.createButton("attachments", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            m_attachmentsPopup.load(form.getProcessInstance().getId());
        }
    });
    Map<String, Field<?>> fields = m_maduraFieldGroup.buildAndBind(new String[] { "queueName", "bundleName",
            "status", "reference", "lastUpdated", "lockedBy", "comment" }, beanItem);

    TextArea comment = (TextArea) fields.get("comment");
    comment.setRows(2);
    comment.setWordwrap(true);
    comment.setWidth("700px");
    TextArea taskField = new TextArea();
    taskField.setRows(2);
    taskField.setWordwrap(true);
    taskField.setWidth("700px");
    taskField.setValue(task);
    taskField.setReadOnly(true);

    processPanel.removeAllComponents();
    processPanel.setMargin(true);
    processPanel.setSpacing(true);
    HorizontalLayout processPanelHorizontal = new HorizontalLayout();
    processPanelHorizontal.setSpacing(true);
    processPanel.addComponent(processPanelHorizontal);
    VerticalLayout processPanelColumn1 = new VerticalLayout();
    VerticalLayout processPanelColumn2 = new VerticalLayout();
    VerticalLayout processPanelColumn3 = new VerticalLayout();
    processPanelHorizontal.addComponent(processPanelColumn1);
    processPanelHorizontal.addComponent(processPanelColumn2);
    processPanelHorizontal.addComponent(processPanelColumn3);
    processPanelColumn1.addComponent(fields.get("queueName"));
    processPanelColumn1.addComponent(fields.get("bundleName"));
    processPanelColumn2.addComponent(fields.get("reference"));
    processPanelColumn2.addComponent(fields.get("lastUpdated"));
    processPanelColumn3.addComponent(fields.get("lockedBy"));
    processPanelColumn3.addComponent(fields.get("status"));

    processPanel.addComponent(comment);
    processPanel.addComponent(taskField);
    m_maduraSessionManager.updateOtherFields(null);

    m_maduraFieldGroup.setReadOnly(form.isReadOnly());

    processPanel.addComponent(attachments);
    processPanel.markAsDirty();

    auditPanel.removeAllComponents();
    m_audits.setup(form.getProcessInstance());
    auditPanel.addComponent(m_audits);

    if (getParent() == null) {
        UI.getCurrent().addWindow(this);
        this.center();
    }
}

From source file:nz.co.senanque.workflowui.WorkflowUIHints.java

License:Apache License

public AbstractField<?> getTextField(MaduraPropertyWrapper property) {
    AbstractTextField ret = null;//from w  ww .  j  av  a 2  s. co m
    if (property.isSecret()) {
        ret = new PasswordField();
    } else {
        if ("comment".equals(property.getName())) {
            TextArea textArea = new TextArea();
            textArea.setRows(5);
            textArea.setWordwrap(true);
            textArea.setWidth("400px");
            ret = textArea;
        } else {
            ret = new TextField();
        }
    }
    ret.setMaxLength(property.getMaxLength());
    if (property.getValue() == null) {
        property.setValue("");
    }
    return ret;
}

From source file:org.activiti.editor.ui.NewModelPopupWindow.java

License:Apache License

protected void addFields() {
    formLayout = new GridLayout(2, 3);
    formLayout.setSpacing(true);//w w  w.j  av  a 2  s. co  m

    formLayout.addComponent(new Label(i18nManager.getMessage(Messages.TASK_NAME)));
    nameTextField = new TextField();
    nameTextField.setWidth(25, Sizeable.UNITS_EM);
    nameTextField.focus();
    formLayout.addComponent(nameTextField);

    formLayout.addComponent(new Label(i18nManager.getMessage(Messages.TASK_DESCRIPTION)));
    descriptionTextArea = new TextArea();
    descriptionTextArea.setRows(8);
    descriptionTextArea.setWidth(25, Sizeable.UNITS_EM);
    descriptionTextArea.addStyleName(ExplorerLayout.STYLE_TEXTAREA_NO_RESIZE);
    formLayout.addComponent(descriptionTextArea);

    Label editorLabel = new Label(i18nManager.getMessage(Messages.PROCESS_EDITOR_CHOICE));
    formLayout.addComponent(editorLabel);
    formLayout.setComponentAlignment(editorLabel, Alignment.MIDDLE_LEFT);

    selectEditorComponent = new SelectEditorComponent();
    formLayout.addComponent(selectEditorComponent);

    addComponent(formLayout);

    // Some empty space
    Label emptySpace = new Label("&nbsp;", Label.CONTENT_XHTML);
    addComponent(emptySpace);
}

From source file:org.activiti.explorer.ui.task.DescriptionComponent.java

License:Apache License

protected void initLayoutClickListener() {
    addListener(new LayoutClickListener() {
        public void layoutClick(LayoutClickEvent event) {
            if (event.getClickedComponent() != null && event.getClickedComponent().equals(descriptionLabel)) {
                // textarea
                final TextArea descriptionTextArea = new TextArea();
                descriptionTextArea.setWidth(100, UNITS_PERCENTAGE);
                descriptionTextArea.setValue(task.getDescription());
                editLayout.addComponent(descriptionTextArea);

                // ok button
                Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK));
                editLayout.addComponent(okButton);
                editLayout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);

                // replace
                replaceComponent(descriptionLabel, editLayout);

                // When OK is clicked -> update task data + ui
                okButton.addListener(new ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        // Update data
                        task.setDescription(descriptionTextArea.getValue().toString());
                        taskService.saveTask(task);

                        // Update UI
                        descriptionLabel.setValue(task.getDescription());
                        replaceComponent(editLayout, descriptionLabel);
                    }//ww w. j  a va2s . com
                });
            }
        }
    });
}

From source file:org.activiti.explorer.ui.task.TaskDetailPanel.java

License:Apache License

protected void initDescription(HorizontalLayout layout) {
    final CssLayout descriptionLayout = new CssLayout();
    descriptionLayout.setWidth(100, UNITS_PERCENTAGE);
    layout.addComponent(descriptionLayout);
    layout.setExpandRatio(descriptionLayout, 1.0f);
    layout.setComponentAlignment(descriptionLayout, Alignment.MIDDLE_LEFT);

    String descriptionText = null;
    if (task.getDescription() != null && !"".equals(task.getDescription())) {
        descriptionText = task.getDescription();
    } else {/* w  ww .  ja v  a2 s . c o  m*/
        descriptionText = i18nManager.getMessage(Messages.TASK_NO_DESCRIPTION);
    }
    final Label descriptionLabel = new Label(descriptionText);
    descriptionLabel.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
    descriptionLayout.addComponent(descriptionLabel);

    descriptionLayout.addListener(new LayoutClickListener() {
        public void layoutClick(LayoutClickEvent event) {
            if (event.getClickedComponent() != null && event.getClickedComponent().equals(descriptionLabel)) {
                // layout for textarea + ok button
                final VerticalLayout editLayout = new VerticalLayout();
                editLayout.setSpacing(true);

                // textarea
                final TextArea descriptionTextArea = new TextArea();
                descriptionTextArea.setNullRepresentation("");
                descriptionTextArea.setWidth(100, UNITS_PERCENTAGE);
                descriptionTextArea.setValue(task.getDescription());
                editLayout.addComponent(descriptionTextArea);

                // ok button
                Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK));
                editLayout.addComponent(okButton);
                editLayout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);

                // replace
                descriptionLayout.replaceComponent(descriptionLabel, editLayout);

                // When OK is clicked -> update task data + ui
                okButton.addListener(new ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        // Update data
                        task.setDescription(descriptionTextArea.getValue().toString());
                        taskService.saveTask(task);

                        // Update UI
                        descriptionLabel.setValue(task.getDescription());
                        descriptionLayout.replaceComponent(editLayout, descriptionLabel);
                    }
                });
            }
        }
    });
}

From source file:org.apache.openaz.xacml.admin.components.PDPManagement.java

License:Apache License

protected void initializeTree(final boolean isAdmin) {
    ////from  w  w w  .  j a v  a2  s .c  o  m
    // Set the data source
    //
    this.table.setContainerDataSource(this.container);
    //
    // Setup the GUI properties
    //
    this.table.setVisibleColumns("Name", "Description", "Status", "Default", "PDPs", "Policies",
            "PIP Configurations");
    this.table.setColumnHeaders("Name", "Description", "Status", "Default", "PDP's", "Policies",
            "PIP Configurations");
    //
    // The description should be a text area
    //
    this.table.addGeneratedColumn("Description", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            TextArea area = new TextArea();
            area.setValue(((PDPGroup) itemId).getDescription());
            area.setReadOnly(true);
            return area;
        }

    });
    //
    // Generate a GUI element for the PDP's
    //
    this.table.addGeneratedColumn("PDPs", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            final Table table = new Table();
            final PDPContainer container = new PDPContainer((PDPGroup) itemId);
            //
            // Setup the container data
            //
            table.setContainerDataSource(container);
            //
            // Save the group for easy access
            //
            table.setData(itemId);
            //
            // GUI properties
            //
            table.setPageLength(table.getContainerDataSource().size() + 2);
            table.setVisibleColumns("Name", "Status", "Description");
            table.setColumnCollapsingAllowed(true);
            table.setColumnCollapsed("Description", true);
            table.setWidth("100%");
            //
            // If an admin, then it is editable
            //
            if (isAdmin) {
                //
                // Set it as selectable
                //
                table.setSelectable(true);
                //
                // Add actions
                //
                table.addActionHandler(new Handler() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public Action[] getActions(Object target, Object sender) {
                        if (target == null) {
                            return new Action[] { CREATE_PDP };
                        }
                        if (target instanceof PDP) {
                            if (self.container.size() > 1) {
                                return new Action[] { EDIT_PDP, GET_PDP_STATUS, MOVE_PDP, DELETE_PDP };
                            } else {
                                return new Action[] { EDIT_PDP, GET_PDP_STATUS, DELETE_PDP };
                            }
                        }
                        return null;
                    }

                    @Override
                    public void handleAction(Action action, Object sender, Object target) {
                        if (action == CREATE_PDP) {
                            self.editPDP(null, (PDPGroup) table.getData());
                            return;
                        }
                        if (action == EDIT_PDP) {
                            assert target instanceof PDP;
                            self.editPDP((PDP) target, (PDPGroup) table.getData());
                            return;
                        }
                        if (action == MOVE_PDP) {
                            assert target instanceof PDP;
                            self.movePDP((PDP) target, (PDPGroup) table.getData());
                            return;
                        }
                        if (action == DELETE_PDP) {
                            assert target instanceof PDP;
                            self.deletePDP((PDP) target, (PDPGroup) table.getData());
                            return;
                        }
                        if (action == GET_PDP_STATUS) {
                            assert target instanceof PDP;
                            self.getPDPStatus((PDP) target, (PDPGroup) table.getData());
                        }
                    }
                });
                //
                // Respond to events
                //
                table.addItemClickListener(new ItemClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void itemClick(ItemClickEvent event) {
                        if (event.isDoubleClick()) {
                            self.editPDP((PDP) event.getItemId(), (PDPGroup) table.getData());
                        }
                    }
                });
            }
            return table;
        }
    });
    //
    // Generate a GUI element for the policies
    //
    this.table.addGeneratedColumn("Policies", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            Table table = new Table();
            table.setContainerDataSource(new PDPPolicyContainer((PDPGroup) itemId));
            table.setPageLength(table.getContainerDataSource().size() + 2);

            table.setVisibleColumns("Root", "Name", "Version", "Description");
            table.setColumnCollapsingAllowed(true);
            table.setColumnCollapsed("Description", true);

            table.setWidth("100%");

            return table;
        }
    });
    //
    // Generate a GUI element for the PIP configurations
    //
    this.table.addGeneratedColumn("PIP Configurations", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            Table table = new Table();
            if (itemId instanceof PDPGroup) {
                table.setContainerDataSource(new PDPPIPContainer((PDPGroup) itemId));
                table.setPageLength(table.getContainerDataSource().size() + 2);
            }
            if (itemId instanceof PDP) {
                table.setContainerDataSource(new PDPPIPContainer((PDP) itemId));
                table.setVisible(false);
                table.setPageLength(0);
            }
            table.setVisibleColumns("Name", "Description");
            table.setColumnCollapsingAllowed(true);
            table.setColumnCollapsed("Description", true);

            table.setWidth("100%");

            return table;
        }
    });
    //
    // Check the user's authorization level
    //
    if (((XacmlAdminUI) UI.getCurrent()).isAuthorized(XacmlAdminAuthorization.AdminAction.ACTION_ADMIN,
            XacmlAdminAuthorization.AdminResource.RESOURCE_PDP_ADMIN)) {
        this.table.setSelectable(true);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("No admin access to pdp management");
        }
        return;
    }
    //
    // Setup Action Handlers
    //
    this.table.addActionHandler(new Handler() {
        private static final long serialVersionUID = 1L;

        @Override
        public Action[] getActions(Object target, Object sender) {
            if (target == null) {
                //
                // Nothing is selected, they right-clicked empty space.
                // Only one action.
                //
                return new Action[] { CREATE_GROUP };
            }
            if (target instanceof PDPGroup) {
                List<Action> actions = new ArrayList<Action>();
                PDPGroupStatus.Status status = ((PDPGroup) target).getStatus().getStatus();
                if (status == PDPGroupStatus.Status.LOAD_ERRORS) {
                    actions.add(REPAIR_GROUP);
                }
                if (((PDPGroup) target).isDefaultGroup() == false) {
                    actions.add(MAKE_DEFAULT);
                }
                actions.add(EDIT_GROUP);
                if (status == PDPGroupStatus.Status.OUT_OF_SYNCH) {
                    actions.add(SYNCHRONIZE);
                }
                if (((PDPGroup) target).isDefaultGroup() == false) {
                    actions.add(DELETE_GROUP);
                }
                actions.add(CREATE_PDP);
                // Throws a class cast exception
                //               return (Action[]) actions.toArray();
                Action[] actions2 = new Action[actions.size()];
                int index = 0;
                for (Action a : actions) {
                    actions2[index++] = a;
                }
                return actions2;
            }
            return null;
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (action == CREATE_GROUP) {
                self.editPDPGroup(null);
                return;
            }
            if (action == EDIT_GROUP) {
                assert target instanceof PDPGroup;
                self.editPDPGroup((PDPGroup) target);
                return;
            }
            if (action == DELETE_GROUP) {
                self.deleteGroup((PDPGroup) target);
                return;
            }
            if (action == REPAIR_GROUP) {
                if (target instanceof PDPGroup) {
                    ((PDPGroup) target).repair();
                } else {
                    String message = "Action '" + REPAIR_GROUP.getCaption() + "' called on non-group target '"
                            + target + "'";
                    logger.error(message);
                    AdminNotification.error(message);
                }
                return;
            }
            if (action == MAKE_DEFAULT) {
                if (target instanceof PDPGroup) {
                    try {
                        self.container.makeDefault((PDPGroup) target);
                    } catch (Exception e) {
                        AdminNotification.error("Make Default failed. Reason:\n" + e.getMessage());
                    }
                } else {
                    String message = "Action '" + MAKE_DEFAULT.getCaption() + "' called on non-group target '"
                            + target + "'";
                    logger.error(message);
                    AdminNotification.error(message);
                }
                return;
            }
            if (action == SYNCHRONIZE) {
                if (target instanceof PDPGroup) {
                    logger.error("SYNCHRONIZE NOT YET IMPLMENTED");
                    AdminNotification.error("Synchronize not yet implemented");
                } else {
                    String message = "Action '" + SYNCHRONIZE.getCaption() + "' called on non-group target '"
                            + target + "'";
                    logger.error(message);
                    AdminNotification.error(message);
                }
                return;
            }
            if (action == CREATE_PDP) {
                if (target instanceof PDPGroup) {
                    self.editPDP(null, ((PDPGroup) target));
                } else {
                    String message = "Action '" + CREATE_PDP.getCaption() + "' called on non-group target '"
                            + target + "'";
                    logger.error(message);
                    AdminNotification.error(message);
                }
                return;
            }
        }
    });
    //
    // Listen for item change notifications
    //
    this.table.addItemClickListener(new ItemClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void itemClick(ItemClickEvent event) {
            if (event.isDoubleClick()) {
                assert event.getItemId() instanceof PDPGroup;
                self.editPDPGroup((PDPGroup) event.getItemId());
            }
        }
    });
    //
    // Respond to selection events
    //
    this.table.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            Object id = self.table.getValue();
            if (id == null) {
                self.buttonRemove.setEnabled(false);
            } else {
                //
                // Make sure its not the default group
                //
                if (((PDPGroup) id).isDefaultGroup()) {
                    self.buttonRemove.setEnabled(false);
                } else {
                    self.buttonRemove.setEnabled(true);
                }
            }
        }
    });
    //
    // Maximize the table
    //
    this.table.setSizeFull();
}

From source file:org.apache.openaz.xacml.admin.components.PIPManagement.java

License:Apache License

protected void initializeTree(boolean isReadOnly) {
    ///*from w  ww.j av  a  2  s .  com*/
    // Initialize GUI properties
    //
    this.tablePIP.setImmediate(true);
    this.tablePIP.setContainerDataSource(this.container);
    this.tablePIP.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    this.tablePIP.setItemCaptionPropertyId("name");
    this.tablePIP.setVisibleColumns(visibleColumns);
    this.tablePIP.setColumnHeaders(columnHeaders);
    this.tablePIP.setSizeFull();
    //
    // Access?
    //
    if (isReadOnly) {
        if (logger.isDebugEnabled()) {
            logger.debug("read only pip access");
        }
        return;
    }
    this.tablePIP.setSelectable(true);
    //
    // Setup click handler
    //
    this.tablePIP.addItemClickListener(new ItemClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void itemClick(ItemClickEvent event) {
            if (event.isDoubleClick()) {
                PIPManagement.editConfiguration(self.container.getItem(event.getItemId()));
            }
        }
    });
    //
    // Setup action handler
    //
    this.tablePIP.addActionHandler(new Handler() {
        private static final long serialVersionUID = 1L;

        @Override
        public Action[] getActions(Object target, Object sender) {
            if (target == null) {
                return new Action[] { ADD_CONFIGURATION };
            }
            //
            // Target is an Object ID
            //
            EntityItem<PIPConfiguration> config = self.container.getItem(target);
            if (config != null && config.getEntity().isReadOnly() == false) {
                if (config.getEntity().requiresResolvers()) {
                    return new Action[] { EDIT_CONFIGURATION, CLONE_CONFIGURATION, REMOVE_CONFIGURATION,
                            PUBLISH_CONFIGURATION, ADD_RESOLVER };
                } else {
                    return new Action[] { EDIT_CONFIGURATION, CLONE_CONFIGURATION, REMOVE_CONFIGURATION,
                            PUBLISH_CONFIGURATION };
                }
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find item: " + target);
            }
            return null;
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            EntityItem<PIPConfiguration> config = self.container.getItem(target);
            if (config == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not find item: " + target);
                }
                return;
            }
            if (action == ADD_CONFIGURATION) {
                PIPManagement.editConfiguration(self.container.createEntityItem(new PIPConfiguration()));
                return;
            }
            if (action == EDIT_CONFIGURATION) {
                PIPManagement.editConfiguration(config);
                return;
            }
            if (action == CLONE_CONFIGURATION) {
                self.cloneConfiguration(config);
                return;
            }
            if (action == REMOVE_CONFIGURATION) {
                self.removeConfiguration(config);
                return;
            }
            if (action == ADD_RESOLVER) {
                PIPResolverComponent.addResolver(config.getEntity(), null);
                return;
            }
            if (action == PUBLISH_CONFIGURATION) {
                PIPResolverComponent.publishConfiguration(config);
                return;
            }
        }
    });
    //
    // When a selection changes listener
    //
    this.tablePIP.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            self.setupButtons();
        }
    });
    this.tablePIP.addGeneratedColumn("description", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EntityItem<PIPConfiguration> entity = self.container.getItem(itemId);
            if (entity != null && entity.getEntity() != null) {
                TextArea area = new TextArea();
                area.setValue(entity.getEntity().getDescription());
                area.setNullRepresentation("");
                area.setSizeFull();
                area.setReadOnly(true);
                return area;
            }
            return null;
        }
    });
    this.tablePIP.addGeneratedColumn("piptype", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EntityItem<PIPConfiguration> entity = self.container.getItem(itemId);
            if (entity != null && entity.getEntity() != null) {
                return entity.getEntity().getPiptype().getType();
            }
            return null;
        }
    });
    //
    // Customize the resolver column
    //
    this.tablePIP.addGeneratedColumn("Resolvers", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EntityItem<PIPConfiguration> entity = self.container.getItem(itemId);
            if (entity != null && entity.getEntity() != null && entity.getEntity().requiresResolvers()) {
                PIPResolverComponent component = new PIPResolverComponent(entity.getEntity());
                return component;
            }
            return null;
        }
    });
}