Example usage for com.vaadin.ui HorizontalLayout addComponent

List of usage examples for com.vaadin.ui HorizontalLayout addComponent

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:annis.gui.HelpUsWindow.java

License:Apache License

public HelpUsWindow() {
    setSizeFull();//from  w  w  w .  ja v a 2 s.  c om
    layout = new VerticalLayout();
    setContent(layout);

    layout.setSizeFull();
    layout.setMargin(new MarginInfo(false, false, true, false));

    HorizontalLayout hLayout = new HorizontalLayout();
    hLayout.setSizeFull();
    hLayout.setMargin(false);

    VerticalLayout labelLayout = new VerticalLayout();
    labelLayout.setMargin(true);
    labelLayout.setSizeFull();

    Label lblOpenSource = new Label();

    lblOpenSource.setValue("<h1>ANNIS is <a href=\"http://opensource.org/osd\">Open Source</a> "
            + "software.</h1>" + "<p>This means you are free to download the source code and add new "
            + "features or make other adjustments to ANNIS on your own.<p/>"
            + "Here are some examples how you can help ANNIS:" + "<ul>"
            + "<li>Fix or report problems (bugs) you encounter when using the ANNIS software.</li>"
            + "<li>Add new features.</li>" + "<li>Enhance the documentation</li>" + "</ul>"
            + "<p>Feel free to visit our GitHub page for more information: <a href=\"https://github.com/korpling/ANNIS\" target=\"_blank\">https://github.com/korpling/ANNIS</a></p>");
    lblOpenSource.setContentMode(ContentMode.HTML);
    lblOpenSource.setStyleName("opensource");
    lblOpenSource.setWidth("100%");
    lblOpenSource.setHeight("-1px");
    labelLayout.addComponent(lblOpenSource);

    Link lnkFork = new Link();
    lnkFork.setResource(new ExternalResource("https://github.com/korpling/ANNIS"));
    lnkFork.setIcon(
            new ExternalResource("https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"));
    lnkFork.setTargetName("_blank");

    hLayout.addComponent(labelLayout);
    hLayout.addComponent(lnkFork);
    hLayout.setComponentAlignment(labelLayout, Alignment.TOP_LEFT);
    hLayout.setComponentAlignment(lnkFork, Alignment.TOP_RIGHT);
    hLayout.setExpandRatio(labelLayout, 1.0f);

    layout.addComponent(hLayout);

    final HelpUsWindow finalThis = this;

    btClose = new Button("Close");
    btClose.addClickListener(new OkClickListener(finalThis));
    layout.addComponent(btClose);

    layout.setComponentAlignment(hLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(btClose, Alignment.MIDDLE_CENTER);
    layout.setExpandRatio(hLayout, 1.0f);
}

From source file:annis.gui.querybuilder.EdgeWindow.java

License:Apache License

public EdgeWindow(final TigerQueryBuilderCanvas parent, NodeWindow source, NodeWindow target) {
    this.parent = parent;
    this.source = source;
    this.target = target;

    setSizeFull();//  w w w .ja va 2  s.  c om

    // HACK: use our own border since the one from chameleon does not really work
    addStyleName(ValoTheme.PANEL_BORDERLESS);
    addStyleName("border-layout");
    addStyleName("white-panel");

    VerticalLayout vLayout = new VerticalLayout();
    setContent(vLayout);
    vLayout.setMargin(false);

    HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.addStyleName("toolbar");
    toolbar.setWidth("100%");
    toolbar.setHeight("-1px");
    vLayout.addComponent(toolbar);

    Label lblTitle = new Label("AQL Operator");
    lblTitle.setWidth("100%");

    toolbar.addComponent(lblTitle);
    toolbar.setComponentAlignment(lblTitle, Alignment.MIDDLE_LEFT);
    toolbar.setExpandRatio(lblTitle, 1.0f);

    btClose = new Button();
    btClose.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    btClose.addStyleName(ValoTheme.BUTTON_SMALL);
    btClose.setIcon(FontAwesome.TIMES_CIRCLE);
    btClose.setWidth("-1px");
    btClose.addListener((Button.ClickListener) this);
    toolbar.addComponent(btClose);

    toolbar.setComponentAlignment(btClose, Alignment.MIDDLE_RIGHT);
    toolbar.setExpandRatio(btClose, 0.0f);

    cbOperator = new ComboBox();
    cbOperator.setNewItemsAllowed(false);
    cbOperator.setTextInputAllowed(false);
    cbOperator.setNullSelectionAllowed(true);
    cbOperator.addItem(CUSTOM);
    cbOperator.setItemCaption(CUSTOM, "custom");
    cbOperator.setNullSelectionItemId(CUSTOM);
    cbOperator.setNewItemHandler(new SimpleNewItemHandler(cbOperator));
    cbOperator.setImmediate(true);
    vLayout.addComponent(cbOperator);
    for (AQLOperator o : AQLOperator.values()) {
        cbOperator.addItem(o);
        cbOperator.setItemCaption(o, o.getDescription() + " (" + o.getOp() + ")");
    }
    cbOperator.setValue(AQLOperator.DIRECT_PRECEDENCE);
    cbOperator.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {

            Object val = event.getProperty().getValue();
            if (val instanceof AQLOperator) {
                txtOperator.setValue(((AQLOperator) val).getOp());
            }
        }
    });

    cbOperator.setWidth("100%");
    cbOperator.setHeight("20px");

    txtOperator = new TextField();
    txtOperator.setValue(".");
    txtOperator.setInputPrompt("select operator definition");
    txtOperator.setSizeFull();
    txtOperator.addValueChangeListener(new OperatorValueChangeListener(parent));
    txtOperator.setImmediate(true);

    vLayout.addComponent(txtOperator);

    vLayout.setExpandRatio(cbOperator, 1.0f);

}

From source file:annis.gui.ReportBugWindow.java

License:Apache License

public ReportBugWindow(final String bugEMailAddress, final byte[] screenImage, final String imageMimeType,
        Throwable cause) {/*ww  w  .  jav  a  2  s. c  om*/
    this.cause = cause;

    setSizeUndefined();
    setCaption("Report Problem");

    ReportFormLayout layout = new ReportFormLayout();
    setContent(layout);

    layout.setWidth("100%");
    layout.setHeight("-1px");

    setHeight("420px");
    setWidth("750px");

    form = new FieldGroup(new BeanItem<>(new BugReport()));
    form.bindMemberFields(layout);
    form.setBuffered(true);

    final ReportBugWindow finalThis = this;
    btSubmit = new Button("Submit problem report", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                form.commit();

                if (sendBugReport(bugEMailAddress, screenImage, imageMimeType)) {
                    Notification.show("Problem report was sent",
                            "We will answer your problem report as soon as possible",
                            Notification.Type.HUMANIZED_MESSAGE);
                }

                UI.getCurrent().removeWindow(finalThis);

            } catch (FieldGroup.CommitException ex) {
                List<String> errorFields = new LinkedList<>();
                for (Field f : form.getFields()) {
                    if (f instanceof AbstractComponent) {
                        AbstractComponent c = (AbstractComponent) f;
                        if (f.isValid()) {
                            c.setComponentError(null);
                        } else {
                            errorFields.add(f.getCaption());
                            c.setComponentError(new UserError("Validation failed: "));
                        }
                    }
                } // for each field
                String message = "Please check the error messages "
                        + "(place mouse over red triangle) for the following fields:<br />";
                message = message + StringUtils.join(errorFields, ",<br/>");
                Notification notify = new Notification("Validation failed", message,
                        Notification.Type.WARNING_MESSAGE, true);
                notify.show(UI.getCurrent().getPage());
            } catch (Exception ex) {
                log.error("Could not send bug report", ex);
                Notification.show("Could not send bug report", ex.getMessage(),
                        Notification.Type.WARNING_MESSAGE);
            }
        }
    });

    btCancel = new Button("Cancel", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            form.discard();
            UI.getCurrent().removeWindow(finalThis);
        }
    });

    addScreenshotPreview(layout, screenImage, imageMimeType);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.addComponent(btSubmit);
    buttons.addComponent(btCancel);

    layout.addComponent(buttons);

}

From source file:annis.gui.SearchUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    super.init(request);

    this.instanceConfig = getInstanceConfig(request);

    getPage().setTitle(instanceConfig.getInstanceDisplayName() + " (ANNIS Corpus Search)");

    queryController = new QueryController(this);

    refresh = new Refresher();
    // deactivate refresher by default
    refresh.setRefreshInterval(-1);// w  w w. ja v a 2s .  c  om
    refresh.addListener(queryController);
    addExtension(refresh);

    // always get the resize events directly
    setImmediate(true);

    VerticalLayout mainLayout = new VerticalLayout();
    setContent(mainLayout);

    mainLayout.setSizeFull();
    mainLayout.setMargin(false);

    final ScreenshotMaker screenshot = new ScreenshotMaker(this);
    addExtension(screenshot);

    css = new CSSInject(this);

    HorizontalLayout layoutToolbar = new HorizontalLayout();
    layoutToolbar.setWidth("100%");
    layoutToolbar.setHeight("-1px");

    mainLayout.addComponent(layoutToolbar);
    layoutToolbar.addStyleName("toolbar");
    layoutToolbar.addStyleName("border-layout");

    Button btAboutAnnis = new Button("About ANNIS");
    btAboutAnnis.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btAboutAnnis.setIcon(new ThemeResource("info.gif"));

    btAboutAnnis.addClickListener(new AboutClickListener());

    btBugReport = new Button("Report Bug");
    btBugReport.addStyleName(ChameleonTheme.BUTTON_SMALL);
    btBugReport.setDisableOnClick(true);
    btBugReport.setIcon(new ThemeResource("../runo/icons/16/email.png"));
    btBugReport.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            screenshot.makeScreenshot();
            btBugReport.setCaption("bug report is initialized...");
        }
    });

    String bugmail = (String) VaadinSession.getCurrent().getAttribute("bug-e-mail");
    if (bugmail != null && !bugmail.isEmpty() && !bugmail.startsWith("${")
            && new EmailValidator("").isValid(bugmail)) {
        this.bugEMailAddress = bugmail;
    }
    btBugReport.setVisible(this.bugEMailAddress != null);

    lblUserName = new Label("not logged in");
    lblUserName.setWidth("-1px");
    lblUserName.setHeight("-1px");
    lblUserName.addStyleName("right-aligned-text");

    btLoginLogout = new Button("Login", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (isLoggedIn()) {
                // logout
                Helper.setUser(null);
                Notification.show("Logged out", Notification.Type.TRAY_NOTIFICATION);
                updateUserInformation();
            } else {
                showLoginWindow();
            }
        }
    });
    btLoginLogout.setSizeUndefined();
    btLoginLogout.setStyleName(ChameleonTheme.BUTTON_SMALL);
    btLoginLogout.setIcon(new ThemeResource("../runo/icons/16/user.png"));

    Button btOpenSource = new Button("Help us to make ANNIS better!");
    btOpenSource.setStyleName(BaseTheme.BUTTON_LINK);
    btOpenSource.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Window w = new HelpUsWindow();
            w.setCaption("Help us to make ANNIS better!");
            w.setModal(true);
            w.setResizable(true);
            w.setWidth("600px");
            w.setHeight("500px");
            addWindow(w);
            w.center();
        }
    });

    layoutToolbar.addComponent(btAboutAnnis);
    layoutToolbar.addComponent(btBugReport);
    layoutToolbar.addComponent(btOpenSource);
    layoutToolbar.addComponent(lblUserName);
    layoutToolbar.addComponent(btLoginLogout);

    layoutToolbar.setSpacing(true);
    layoutToolbar.setComponentAlignment(btAboutAnnis, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btBugReport, Alignment.MIDDLE_LEFT);
    layoutToolbar.setComponentAlignment(btOpenSource, Alignment.MIDDLE_CENTER);
    layoutToolbar.setComponentAlignment(lblUserName, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setComponentAlignment(btLoginLogout, Alignment.MIDDLE_RIGHT);
    layoutToolbar.setExpandRatio(btOpenSource, 1.0f);

    //HorizontalLayout hLayout = new HorizontalLayout();
    final HorizontalSplitPanel hSplit = new HorizontalSplitPanel();
    hSplit.setSizeFull();

    mainLayout.addComponent(hSplit);
    mainLayout.setExpandRatio(hSplit, 1.0f);

    AutoGeneratedQueries autoGenQueries = new AutoGeneratedQueries("example queries", this);

    controlPanel = new ControlPanel(queryController, instanceConfig, autoGenQueries);
    controlPanel.setWidth(100f, Layout.Unit.PERCENTAGE);
    controlPanel.setHeight(100f, Layout.Unit.PERCENTAGE);
    hSplit.setFirstComponent(controlPanel);

    tutorial = new TutorialPanel();
    tutorial.setHeight("99%");

    mainTab = new TabSheet();
    mainTab.setSizeFull();
    mainTab.addTab(autoGenQueries, "example queries");
    mainTab.addTab(tutorial, "Tutorial");

    queryBuilder = new QueryBuilderChooser(queryController, this, instanceConfig);
    mainTab.addTab(queryBuilder, "Query Builder");

    hSplit.setSecondComponent(mainTab);
    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
    hSplit.addSplitterClickListener(new AbstractSplitPanel.SplitterClickListener() {
        @Override
        public void splitterClick(AbstractSplitPanel.SplitterClickEvent event) {
            if (event.isDoubleClick()) {
                if (hSplit.getSplitPosition() == CONTROL_PANEL_WIDTH) {
                    // make small
                    hSplit.setSplitPosition(0.0f, Unit.PIXELS);
                } else {
                    // reset to default width
                    hSplit.setSplitPosition(CONTROL_PANEL_WIDTH, Unit.PIXELS);
                }
            }
        }
    });
    // hLayout.setExpandRatio(mainTab, 1.0f);

    addAction(new ShortcutListener("^Query builder") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(queryBuilder);
        }
    });

    addAction(new ShortcutListener("Tutor^eial") {
        @Override
        public void handleAction(Object sender, Object target) {
            mainTab.setSelectedTab(tutorial);
        }
    });

    getPage().addUriFragmentChangedListener(this);

    getSession().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            checkCitation(request);

            if (request.getPathInfo() != null && request.getPathInfo().startsWith("/vis-iframe-res/")) {
                String uuidString = StringUtils.removeStart(request.getPathInfo(), "/vis-iframe-res/");
                UUID uuid = UUID.fromString(uuidString);
                IFrameResourceMap map = VaadinSession.getCurrent().getAttribute(IFrameResourceMap.class);
                if (map == null) {
                    response.setStatus(404);
                } else {
                    IFrameResource res = map.get(uuid);
                    if (res != null) {
                        response.setStatus(200);
                        response.setContentType(res.getMimeType());
                        response.getOutputStream().write(res.getData());
                    }
                }
                return true;
            }

            return false;
        }
    });

    getSession().setAttribute(MediaController.class, new MediaControllerImpl());

    getSession().setAttribute(PDFController.class, new PDFControllerImpl());

    loadInstanceFonts();

    checkCitation(request);
    lastQueriedFragment = "";
    evaluateFragment(getPage().getUriFragment());

    updateUserInformation();
}

From source file:annis.visualizers.component.rst.RSTPanel.java

License:Apache License

RSTPanel(VisualizerInput visInput) {
    String btWidth = "30px";
    HorizontalLayout grid = new HorizontalLayout();
    final int scrollStep = 200;

    // the calculation of the output json is done here.
    final RSTImpl rstView = new RSTImpl(visInput);
    rstView.setId(UUID.randomUUID().toString());

    this.setHeight("-1px");
    this.setWidth("100%");
    grid.setHeight("-1px");
    grid.setWidth("100%");

    final Button buttonLeft = new Button();
    buttonLeft.setWidth(btWidth);/*w w  w .  j  a v a 2  s . c om*/
    buttonLeft.setHeight("100%");
    buttonLeft.addStyleName("left-button");
    buttonLeft.setEnabled(false);

    final Button buttonRight = new Button();
    buttonRight.setWidth(btWidth);
    buttonRight.setHeight("100%");
    buttonRight.addStyleName("right-button");

    buttonLeft.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (rstView.getScrollLeft() < scrollStep) {
                buttonLeft.setEnabled(false);
                rstView.setScrollLeft(0);
            } else {
                //if the right button was deactivated set it back
                rstView.setScrollLeft(rstView.getScrollLeft() - scrollStep);
            }

            buttonRight.setEnabled(true);
        }
    });

    buttonRight.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            renderInfo.calculate("#" + rstView.getId() + " canvas");
        }
    });

    renderInfo = new CssRenderInfo(new CssRenderInfo.Callback() {
        @Override
        public void renderInfoReceived(int width, int height) {
            if (width - rstView.getScrollLeft() > scrollStep) {
                buttonLeft.setEnabled(true);
                rstView.setScrollLeft(rstView.getScrollLeft() + scrollStep);
            } else {
                rstView.setScrollLeft(rstView.getScrollLeft() - (width - rstView.getScrollLeft()));

                buttonLeft.setEnabled(true);
                buttonRight.setEnabled(false);
            }
        }
    });
    rstView.addExtension(renderInfo);

    grid.addComponent(buttonLeft);
    grid.addComponent(rstView);
    grid.addComponent(buttonRight);
    setContent(grid);
    grid.setExpandRatio(rstView, 1.0f);
}

From source file:at.meikel.nentis.Nentis.java

License:Apache License

private void initMain(TabSheet tabSheet) {
    final VerticalLayout mainTab = new VerticalLayout();
    tabSheet.addTab(mainTab);//w  ww  .  j a  va2s  .  c  o  m
    tabSheet.getTab(mainTab).setCaption("Main");

    final HorizontalLayout buttons = new HorizontalLayout();
    mainTab.addComponent(buttons);

    final VerticalLayout state = new VerticalLayout();
    mainTab.addComponent(state);

    final VerticalLayout info = new VerticalLayout();
    mainTab.addComponent(info);

    Button createTicket = new Button("Create a new ticket");
    createTicket.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent clickEvent) {
            state.removeAllComponents();
            Ticket ticket = nentisApi.createTicket("Ticket (" + new Date() + ")");
            state.addComponent(
                    new Label("Ticket #" + ticket.getId() + " [" + ticket.getDescription() + "] created."));
        }
    });
    buttons.addComponent(createTicket);

    Button listAllTickets = new Button("List all existing tickets");
    listAllTickets.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent clickEvent) {
            state.removeAllComponents();
            List<Ticket> allTickets = nentisApi.getAllTickets();
            info.removeAllComponents();
            if (allTickets != null) {
                for (Ticket ticket : allTickets) {
                    info.addComponent(new Label(
                            "Ticket #" + ticket.getId() + " [" + ticket.getDescription() + "] created."));
                }
            }
        }
    });
    buttons.addComponent(listAllTickets);

    final Button openSubWindow = new Button("Open a sub window");
    openSubWindow.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent clickEvent) {
            buttons.removeComponent(openSubWindow);
            Window subWindow = new Window("Sub window");
            mainWindow.addWindow(subWindow);
        }
    });
    buttons.addComponent(openSubWindow);
}

From source file:at.peppol.webgui.app.components.InvoiceLineAllowanceChargeForm.java

License:Mozilla Public License

private void initElements() {

    final GridLayout grid = new GridLayout(4, 4);
    final VerticalLayout outerLayout = new VerticalLayout();
    hiddenContent = new VerticalLayout();
    hiddenContent.setSpacing(true);/* www  . j a va  2s  .c o  m*/
    hiddenContent.setMargin(true);

    table = new InvoiceLineAllowanceChargeTable(lineAllowanceChargeList);
    table.setSelectable(true);
    table.setImmediate(true);
    table.setNullSelectionAllowed(false);
    table.setHeight(150, UNITS_PIXELS);
    table.setFooterVisible(false);
    table.addStyleName("striped strong");

    VerticalLayout tableContainer = new VerticalLayout();
    tableContainer.addComponent(table);
    tableContainer.setMargin(false, true, false, false);

    Button addButton = new Button("Add new");
    Button editButton = new Button("Edit selected");
    Button deleteButton = new Button("Delete selected");

    VerticalLayout buttonsContainer = new VerticalLayout();
    buttonsContainer.setSpacing(true);
    buttonsContainer.addComponent(addButton);
    buttonsContainer.addComponent(editButton);
    buttonsContainer.addComponent(deleteButton);

    InvoiceLineAllowanceChargeTableEditor editor = new InvoiceLineAllowanceChargeTableEditor(editMode, inv);
    Label label = new Label("<h3>Adding allowance/charge line</h3>", Label.CONTENT_XHTML);
    addButton.addListener(editor.addButtonListener(editButton, deleteButton, hiddenContent, table,
            lineAllowanceChargeList, label));
    label = new Label("<h3>Edit allowance/charge line</h3>", Label.CONTENT_XHTML);
    editButton.addListener(editor.editButtonListener(addButton, deleteButton, hiddenContent, table,
            lineAllowanceChargeList, label));
    deleteButton.addListener(editor.deleteButtonListener(table));

    Panel outerPanel = new Panel(prefix + " Allowances/Charges");
    //outerPanel.setStyleName("light");     

    // ---- HIDDEN FORM BEGINS -----
    VerticalLayout formLayout = new VerticalLayout();
    formLayout.addComponent(hiddenContent);
    hiddenContent.setVisible(false);
    // ---- HIDDEN FORM ENDS -----

    grid.setSizeUndefined();
    grid.addComponent(tableContainer, 0, 0);
    grid.addComponent(buttonsContainer, 1, 0);

    outerPanel.addComponent(grid);
    outerPanel.addComponent(formLayout);
    outerLayout.addComponent(outerPanel);
    outerPanel.requestRepaintAll();

    VerticalLayout mainLayout = new VerticalLayout();
    final VerticalLayout showHideContentLayout = new VerticalLayout();
    showHideContentLayout.addComponent(outerPanel);
    HorizontalLayout showHideButtonLayout = new HorizontalLayout();
    Button btn = new Button("Show/Hide Allowances/Charges", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub
            showHideContentLayout.setVisible(!showHideContentLayout.isVisible());
        }
    });
    showHideButtonLayout.setWidth("100%");
    showHideButtonLayout.addComponent(btn);
    showHideButtonLayout.setComponentAlignment(btn, Alignment.MIDDLE_RIGHT);

    //mainLayout.addComponent(showHideButtonLayout);
    mainLayout.addComponent(showHideContentLayout);
    //showHideContentLayout.setVisible(false);    

    addComponent(mainLayout);

}

From source file:at.peppol.webgui.app.components.InvoiceLineCommodityClassificationForm.java

License:Mozilla Public License

private void initElements() {

    final GridLayout grid = new GridLayout(4, 4);
    final VerticalLayout outerLayout = new VerticalLayout();
    hiddenContent = new VerticalLayout();
    hiddenContent.setSpacing(true);//from   www .  ja v a 2s  .co m
    hiddenContent.setMargin(true);

    table = new InvoiceLineCommodityClassificationTable(lineCommodityList);
    table.setSelectable(true);
    table.setImmediate(true);
    table.setNullSelectionAllowed(false);
    table.setHeight(150, UNITS_PIXELS);
    table.setFooterVisible(false);
    table.addStyleName("striped strong");

    VerticalLayout tableContainer = new VerticalLayout();
    tableContainer.addComponent(table);
    tableContainer.setMargin(false, true, false, false);

    Button addButton = new Button("Add new");
    Button editButton = new Button("Edit selected");
    Button deleteButton = new Button("Delete selected");

    VerticalLayout buttonsContainer = new VerticalLayout();
    buttonsContainer.setSpacing(true);
    buttonsContainer.addComponent(addButton);
    buttonsContainer.addComponent(editButton);
    buttonsContainer.addComponent(deleteButton);

    InvoiceLineCommodityClassificationTableEditor editor = new InvoiceLineCommodityClassificationTableEditor(
            editMode);
    Label label = new Label("<h3>Adding commodity classification line</h3>", Label.CONTENT_XHTML);
    addButton.addListener(
            editor.addButtonListener(editButton, deleteButton, hiddenContent, table, lineCommodityList, label));
    label = new Label("<h3>Edit commodity classification line</h3>", Label.CONTENT_XHTML);
    editButton.addListener(
            editor.editButtonListener(addButton, deleteButton, hiddenContent, table, lineCommodityList, label));
    deleteButton.addListener(editor.deleteButtonListener(table));

    Panel outerPanel = new Panel(prefix + " Commodity Classifications");
    //outerPanel.setStyleName("light");     

    // ---- HIDDEN FORM BEGINS -----
    VerticalLayout formLayout = new VerticalLayout();
    formLayout.addComponent(hiddenContent);
    hiddenContent.setVisible(false);
    // ---- HIDDEN FORM ENDS -----

    grid.setSizeUndefined();
    grid.addComponent(tableContainer, 0, 0);
    grid.addComponent(buttonsContainer, 1, 0);

    outerPanel.addComponent(grid);
    outerPanel.addComponent(formLayout);
    outerLayout.addComponent(outerPanel);
    outerPanel.requestRepaintAll();

    VerticalLayout mainLayout = new VerticalLayout();
    final VerticalLayout showHideContentLayout = new VerticalLayout();
    showHideContentLayout.addComponent(outerPanel);
    HorizontalLayout showHideButtonLayout = new HorizontalLayout();
    Button btn = new Button("Show/Hide Allowances/Charges", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub
            showHideContentLayout.setVisible(!showHideContentLayout.isVisible());
        }
    });
    showHideButtonLayout.setWidth("100%");
    showHideButtonLayout.addComponent(btn);
    showHideButtonLayout.setComponentAlignment(btn, Alignment.MIDDLE_RIGHT);

    //mainLayout.addComponent(showHideButtonLayout);
    mainLayout.addComponent(showHideContentLayout);
    //showHideContentLayout.setVisible(false);    

    addComponent(mainLayout);

}

From source file:at.peppol.webgui.app.components.InvoiceLineOrderForm.java

License:Mozilla Public License

private void initElements() {

    final GridLayout grid = new GridLayout(4, 4);
    final VerticalLayout outerLayout = new VerticalLayout();
    hiddenContent = new VerticalLayout();
    hiddenContent.setSpacing(true);/*from   w  w w .  j  ava 2  s  .com*/
    hiddenContent.setMargin(true);

    table = new InvoiceLineOrderReferenceTable(lineOrderList);
    table.setSelectable(true);
    table.setImmediate(true);
    table.setNullSelectionAllowed(false);
    table.setHeight(150, UNITS_PIXELS);
    table.setFooterVisible(false);
    table.addStyleName("striped strong");

    VerticalLayout tableContainer = new VerticalLayout();
    tableContainer.addComponent(table);
    tableContainer.setMargin(false, true, false, false);

    Button addButton = new Button("Add new");
    Button editButton = new Button("Edit selected");
    Button deleteButton = new Button("Delete selected");

    VerticalLayout buttonsContainer = new VerticalLayout();
    buttonsContainer.setSpacing(true);
    buttonsContainer.addComponent(addButton);
    buttonsContainer.addComponent(editButton);
    buttonsContainer.addComponent(deleteButton);

    InvoiceLineOrderReferenceTableEditor editor = new InvoiceLineOrderReferenceTableEditor(editMode);
    Label label = new Label("<h3>Adding order line</h3>", Label.CONTENT_XHTML);
    addButton.addListener(
            editor.addButtonListener(editButton, deleteButton, hiddenContent, table, lineOrderList, label));
    label = new Label("<h3>Edit order line</h3>", Label.CONTENT_XHTML);
    editButton.addListener(
            editor.editButtonListener(addButton, deleteButton, hiddenContent, table, lineOrderList, label));
    deleteButton.addListener(editor.deleteButtonListener(table));

    Panel outerPanel = new Panel(prefix + " Referencing Orders");
    //outerPanel.setStyleName("light");     

    // ---- HIDDEN FORM BEGINS -----
    VerticalLayout formLayout = new VerticalLayout();
    formLayout.addComponent(hiddenContent);
    hiddenContent.setVisible(false);
    // ---- HIDDEN FORM ENDS -----

    grid.setSizeUndefined();
    grid.addComponent(tableContainer, 0, 0);
    grid.addComponent(buttonsContainer, 1, 0);

    outerPanel.addComponent(grid);
    outerPanel.addComponent(formLayout);
    outerLayout.addComponent(outerPanel);
    outerPanel.requestRepaintAll();

    VerticalLayout mainLayout = new VerticalLayout();
    final VerticalLayout showHideContentLayout = new VerticalLayout();
    showHideContentLayout.addComponent(outerPanel);
    HorizontalLayout showHideButtonLayout = new HorizontalLayout();
    Button btn = new Button("Show/Hide Allowances/Charges", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub
            showHideContentLayout.setVisible(!showHideContentLayout.isVisible());
        }
    });
    showHideButtonLayout.setWidth("100%");
    showHideButtonLayout.addComponent(btn);
    showHideButtonLayout.setComponentAlignment(btn, Alignment.MIDDLE_RIGHT);

    //mainLayout.addComponent(showHideButtonLayout);
    mainLayout.addComponent(showHideContentLayout);
    //showHideContentLayout.setVisible(false);    

    addComponent(mainLayout);

}

From source file:at.peppol.webgui.app.components.InvoiceTabForm.java

License:Mozilla Public License

private void initElements() {
    supplierForm = new PartyDetailForm("Supplier", supplier.getParty());
    supplierForm.setImmediate(true);// w  ww . j  a v  a 2  s. c om
    customerForm = new PartyDetailForm("Customer", customer.getParty());
    customerForm.setImmediate(true);
    //supplierForm.setSizeFull ();
    //customerForm.setSizeFull ();

    final HorizontalLayout footerLayout = new HorizontalLayout();
    footerLayout.setSpacing(true);
    footerLayout.setMargin(true);
    footerLayout.addComponent(new Button("Save Invoice", new Button.ClickListener() {

        @Override
        public void buttonClick(final Button.ClickEvent event) {
            SetCommonCurrency();
            ValidatorHandler vh = new ValidatorHandler(footerLayout);
            AbstractUBLDocumentMarshaller.setGlobalValidationEventHandler(vh);
            vh.clearErrors();
            clearTabErrorStyles();
            boolean invoiceHasErrors = false;

            List<ValidationError> errors = GlobalValidationsRegistry.runAll();
            if (errors.size() > 0) {
                invoiceHasErrors = true;
                Window errorWindow = new Window("Errors");
                //position and size of the window
                errorWindow.setPositionX(200);
                errorWindow.setPositionY(200);
                errorWindow.setWidth("600px");
                errorWindow.setHeight("300px");

                //add the error messages
                String errorMessage = "<ol>";
                for (int i = 0; i < errors.size(); i++) {
                    errorMessage += "<li style=\"margin-top: 4px;\"><b>" + errors.get(i).getRuleID() + "</b>: "
                            + errors.get(i).getErrorInfo() + "</li>";
                    //mark the appropriate Tab as error
                    Tab tab = invTabSheet.getTab(errors.get(i).getMainComponent());
                    if (tab != null)
                        tab.setStyleName("test111");
                }
                errorMessage += "</ol>";
                errorWindow.addComponent(new Label(errorMessage, Label.CONTENT_XHTML));

                //show the error window
                getParent().getWindow().addWindow(errorWindow);
                errors.clear();
            }

            ValidatorsList.validateListenersNotify();
            if (ValidatorsList.validateListeners() == false) {
                invoiceHasErrors = true;
            }

            if (invoiceHasErrors) {
                getWindow().showNotification("Validation error. Could not save invoice",
                        Notification.TYPE_TRAY_NOTIFICATION);
            } else {
                try {
                    if (invoiceFilePath.equals("")) {
                        UBL20DocumentMarshaller.writeInvoice(invoice,
                                new StreamResult(new File(um.getDrafts().getFolder().toString()
                                        + System.getProperty("file.separator") + "invoice"
                                        + System.currentTimeMillis() + ".xml")));
                        invoiceFilePath = um.getDrafts().getFolder().toString()
                                + System.getProperty("file.separator") + "invoice" + System.currentTimeMillis()
                                + ".xml";
                    } else {
                        UBL20DocumentMarshaller.writeInvoice(invoice,
                                new StreamResult(new File(invoiceFilePath)));
                    }
                    getWindow()
                            .showNotification(
                                    "Validation passed. Invoice saved in "
                                            + um.getDrafts().getName().toUpperCase() + " folder",
                                    Notification.TYPE_TRAY_NOTIFICATION);
                } catch (Exception e) {
                    getWindow().showNotification("Disk access error. Could not save invoice",
                            Notification.TYPE_ERROR_MESSAGE);
                }
            }

            /*PEPPOL validation
             * final ValidationPyramid vp = new ValidationPyramid (EValidationDocumentType.INVOICE,
                    ValidationTransaction.createUBLTransaction (ETransaction.T10));
             final List <ValidationPyramidResultLayer> aResults = vp.applyValidation (new FileSystemResource ("invoice.xml"))
                   .getAllValidationResultLayers ();
             if (aResults.isEmpty ())
               System.out.println ("  The document is valid!");
             else
               for (final ValidationPyramidResultLayer aResultLayer : aResults)
                 for (final IResourceError aError : aResultLayer.getValidationErrors ())
                   System.out.println ("  " + aResultLayer.getValidationLevel () + " " + aError.getAsString (Locale.US));
            */
            /*ValidatorsList.validateListenersNotify();
            if (ValidatorsList.validateListeners() == false) {
               getParent().getWindow().showNotification("Validation error... ",Notification.TYPE_TRAY_NOTIFICATION);
            }
            else
               getParent().getWindow().showNotification("Validation passed! ",Notification.TYPE_TRAY_NOTIFICATION);
            */

        }
    }));

    /*    footerLayout.addComponent (new Button ("Save Invoice", new Button.ClickListener () {
            
          @Override
          public void buttonClick (final Button.ClickEvent event) {
            try {
              SetCommonCurrency ();          
              System.out.println (invoice.getDelivery ().get (0).getDeliveryAddress ().getStreetName ().getValue ());
            }
            catch (final Exception ex) {
              LOGGER.error ("Error creating files. ", ex);
            }
          }
        }));
    */
    footerLayout.addComponent(new Button("Read Invoice from disk", new Button.ClickListener() {

        @Override
        public void buttonClick(final Button.ClickEvent event) {
            try {
                SetCommonCurrency();
                InvoiceType inv = UBL20DocumentMarshaller
                        .readInvoice(new StreamSource(new FileInputStream(new File("invoice.xml"))));
            } catch (final Exception ex) {
                LOGGER.error("Error creating files. ", ex);
            }
        }
    }));

    getFooter().addComponent(footerLayout);

}