Example usage for com.vaadin.ui VerticalLayout addComponent

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

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:ac.uk.icl.dell.vaadin.navigator7.common.HeaderFooterFluidAppLevelWindow.java

License:Open Source License

@Override
protected ComponentContainer createComponents() {
    VerticalLayout mainContainer = (VerticalLayout) getContent(); //set in FluidAppLevelWindow::attach via createMainLayout
    mainContainer.setSizeFull();/*w  w w  .j a va  2 s .c o  m*/

    header = createHeader();
    header.setWidth("100%");

    mainContainer.addComponent(header);

    footer = createFooter();
    footer.setWidth("100%");

    VerticalLayout pageBand = new VerticalLayout();
    pageBand.setSizeFull();

    mainContainer.addComponent(pageBand);
    mainContainer.setExpandRatio(pageBand, 1);

    mainContainer.addComponent(footer);

    return pageBand;
}

From source file:annis.gui.CitationWindow.java

License:Apache License

public CitationWindow(String query, Set<String> corpora, int contextLeft, int contextRight) {
    super("Citation");

    VerticalLayout wLayout = new VerticalLayout();
    setContent(wLayout);/*from  w  w w.j a  v a2 s. c  o  m*/
    wLayout.setSizeFull();

    String url = Helper.generateCitation(query, corpora, contextLeft, contextRight, null, 0, 10);

    TextArea txtCitation = new TextArea();

    txtCitation.setWidth("100%");
    txtCitation.setHeight("100%");
    txtCitation.addStyleName(ChameleonTheme.TEXTFIELD_BIG);
    txtCitation.addStyleName("citation");
    txtCitation.setValue(url);
    txtCitation.setWordwrap(true);
    txtCitation.setReadOnly(true);

    wLayout.addComponent(txtCitation);

    Button btOk = new Button("OK");
    btOk.addListener((Button.ClickListener) this);
    btOk.setSizeUndefined();

    wLayout.addComponent(btOk);

    wLayout.setExpandRatio(txtCitation, 1.0f);
    wLayout.setComponentAlignment(btOk, Alignment.BOTTOM_CENTER);

    setWidth("400px");
    setHeight("200px");

}

From source file:annis.gui.controlpanel.QueryPanel.java

License:Apache License

public QueryPanel(final AnnisUI ui) {
    super(4, 5);//from w w  w.j a v a2s  .c om
    this.ui = ui;

    this.lastPublicStatus = "Welcome to ANNIS! " + "A tutorial is available on the right side.";

    this.state = ui.getQueryState();

    setSpacing(true);
    setMargin(false);

    setRowExpandRatio(0, 1.0f);
    setColumnExpandRatio(0, 0.0f);
    setColumnExpandRatio(1, 0.1f);
    setColumnExpandRatio(2, 0.0f);
    setColumnExpandRatio(3, 0.0f);

    txtQuery = new AqlCodeEditor();
    txtQuery.setPropertyDataSource(state.getAql());
    txtQuery.setInputPrompt("Please enter AQL query");
    txtQuery.addStyleName("query");
    if (ui.getInstanceFont() == null) {
        txtQuery.addStyleName("default-query-font");
        txtQuery.setTextareaStyle("default-query-font");
    } else {
        txtQuery.addStyleName(Helper.CORPUS_FONT);
        txtQuery.setTextareaStyle(Helper.CORPUS_FONT);
    }

    txtQuery.addStyleName("keyboardInput");
    txtQuery.setWidth("100%");
    txtQuery.setHeight(15f, Unit.EM);
    txtQuery.setTextChangeTimeout(500);

    final VirtualKeyboardCodeEditor virtualKeyboard;
    if (ui.getInstanceConfig().getKeyboardLayout() == null) {
        virtualKeyboard = null;
    } else {
        virtualKeyboard = new VirtualKeyboardCodeEditor();
        virtualKeyboard.setKeyboardLayout(ui.getInstanceConfig().getKeyboardLayout());
        virtualKeyboard.extend(txtQuery);
    }

    txtStatus = new TextArea();
    txtStatus.setValue(this.lastPublicStatus);
    txtStatus.setWidth("100%");
    txtStatus.setHeight(4.0f, Unit.EM);
    txtStatus.addStyleName("border-layout");
    txtStatus.setReadOnly(true);

    piCount = new ProgressBar();
    piCount.setIndeterminate(true);
    piCount.setEnabled(false);
    piCount.setVisible(false);

    btShowResult = new Button("Search");
    btShowResult.setIcon(FontAwesome.SEARCH);
    btShowResult.setWidth("100%");
    btShowResult.addClickListener(new ShowResultClickListener());
    btShowResult.setDescription("<strong>Show Result</strong><br />Ctrl + Enter");
    btShowResult.setClickShortcut(KeyCode.ENTER, ModifierKey.CTRL);
    btShowResult.setDisableOnClick(true);

    VerticalLayout historyListLayout = new VerticalLayout();
    historyListLayout.setSizeUndefined();

    lstHistory = new ListSelect();
    lstHistory.setWidth("200px");
    lstHistory.setNullSelectionAllowed(false);
    lstHistory.setValue(null);
    lstHistory.addValueChangeListener((ValueChangeListener) this);
    lstHistory.setImmediate(true);
    lstHistory.setContainerDataSource(historyContainer);
    lstHistory.setItemCaptionPropertyId("query");
    lstHistory.addStyleName(Helper.CORPUS_FONT);

    Button btShowMoreHistory = new Button("Show more details", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (historyWindow == null) {
                historyWindow = new Window("History");
                historyWindow.setModal(false);
                historyWindow.setWidth("400px");
                historyWindow.setHeight("250px");
            }
            historyWindow.setContent(new HistoryPanel(state.getHistory(), ui.getQueryController()));

            if (UI.getCurrent().getWindows().contains(historyWindow)) {
                historyWindow.bringToFront();
            } else {
                UI.getCurrent().addWindow(historyWindow);
            }
        }
    });
    btShowMoreHistory.setWidth("100%");

    historyListLayout.addComponent(lstHistory);
    historyListLayout.addComponent(btShowMoreHistory);

    historyListLayout.setExpandRatio(lstHistory, 1.0f);
    historyListLayout.setExpandRatio(btShowMoreHistory, 0.0f);

    btHistory = new PopupButton("History");
    btHistory.setContent(historyListLayout);
    btHistory.setDescription("<strong>Show History</strong><br />"
            + "Either use the short overview (arrow down) or click on the button " + "for the extended view.");

    Button btShowKeyboard = null;
    if (virtualKeyboard != null) {
        btShowKeyboard = new Button();
        btShowKeyboard.setWidth("100%");
        btShowKeyboard.setDescription("Click to show a virtual keyboard");
        btShowKeyboard.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        btShowKeyboard.addStyleName(ValoTheme.BUTTON_SMALL);
        btShowKeyboard.setIcon(new ClassResource(VirtualKeyboardCodeEditor.class, "keyboard.png"));
        btShowKeyboard.addClickListener(new ShowKeyboardClickListener(virtualKeyboard));
    }

    Button btShowQueryBuilder = new Button("Query<br />Builder");
    btShowQueryBuilder.setHtmlContentAllowed(true);
    btShowQueryBuilder.addStyleName(ValoTheme.BUTTON_SMALL);
    btShowQueryBuilder.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
    btShowQueryBuilder.setIcon(new ThemeResource("images/tango-icons/32x32/document-properties.png"));
    btShowQueryBuilder.addClickListener(new ShowQueryBuilderClickListener(ui));

    VerticalLayout moreActionsLayout = new VerticalLayout();
    moreActionsLayout.setWidth("250px");
    btMoreActions = new PopupButton("More");
    btMoreActions.setContent(moreActionsLayout);

    //    btShowResultNewTab = new Button("Search (open in new tab)");
    //    btShowResultNewTab.setWidth("100%");
    //    btShowResultNewTab.addClickListener(new ShowResultInNewTabClickListener());
    //    btShowResultNewTab.setDescription("<strong>Show Result and open result in new tab</strong><br />Ctrl + Shift + Enter");
    //    btShowResultNewTab.setDisableOnClick(true);
    //    btShowResultNewTab.setClickShortcut(KeyCode.ENTER, ModifierKey.CTRL, ModifierKey.SHIFT);
    //    moreActionsLayout.addComponent(btShowResultNewTab);

    Button btShowExport = new Button("Export", new ShowExportClickListener(ui));
    btShowExport.setIcon(FontAwesome.DOWNLOAD);
    btShowExport.setWidth("100%");
    moreActionsLayout.addComponent(btShowExport);

    Button btShowFrequency = new Button("Frequency Analysis", new ShowFrequencyClickListener(ui));
    btShowFrequency.setIcon(FontAwesome.BAR_CHART_O);
    btShowFrequency.setWidth("100%");
    moreActionsLayout.addComponent(btShowFrequency);

    /*
     * We use the grid layout for a better rendering efficiency, but this comes
     * with the cost of some complexity when defining the positions of the
     * elements in the layout.
     * 
     * This grid hopefully helps a little bit in understanding the "magic"
     * numbers better.
     * 
     * Q: Query text field
     * QB: Button to toggle query builder // TODO
     * KEY: Button to show virtual keyboard
     * SEA: "Search" button
     * MOR: "More actions" button 
     * HIST: "History" button
     * STAT: Text field with the real status
     * PROG: indefinite progress bar (spinning circle)
     * 
     *   \  0  |  1  |  2  |  3  
     * --+-----+---+---+---+-----
     * 0 |  Q  |  Q  |  Q  | QB 
     * --+-----+-----+-----+-----
     * 1 |  Q  |  Q  |  Q  | KEY 
     * --+-----+-----+-----+-----
     * 2 | SEA | MOR | HIST|     
     * --+-----+-----+-----+-----
     * 3 | STAT| STAT| STAT| PROG
     */
    addComponent(txtQuery, 0, 0, 2, 1);
    addComponent(txtStatus, 0, 3, 2, 3);
    addComponent(btShowResult, 0, 2);
    addComponent(btMoreActions, 1, 2);
    addComponent(btHistory, 2, 2);
    addComponent(piCount, 3, 3);
    addComponent(btShowQueryBuilder, 3, 0);
    if (btShowKeyboard != null) {
        addComponent(btShowKeyboard, 3, 1);
    }

    // alignment
    setRowExpandRatio(0, 0.0f);
    setRowExpandRatio(1, 1.0f);
    setColumnExpandRatio(0, 1.0f);
    setColumnExpandRatio(1, 0.0f);
    setColumnExpandRatio(2, 0.0f);
    setColumnExpandRatio(3, 0.0f);

    //setComponentAlignment(btShowQueryBuilder, Alignment.BOTTOM_CENTER);
}

From source file:annis.gui.CorpusBrowserPanel.java

License:Apache License

/**
 * Places a label with the text "(No <caption>)" in the centered middle of the accordion
 * tab.//  w  ww.  jav  a2s .  co m
 *
 * @param accordion the target accordion
 * @param caption is set as caption of the accordion tab
 */
private void placeEmptyLabel(Accordion accordion, String caption) {
    VerticalLayout v = new VerticalLayout();
    v.setSizeFull();
    Label l = new Label("(No " + caption + ")");
    v.addComponent(l);
    l.setSizeUndefined();
    v.setComponentAlignment(l, Alignment.MIDDLE_CENTER);
    accordion.addTab(v, caption, null);
    l.setSizeUndefined();
}

From source file:annis.gui.docbrowser.DocBrowserTable.java

License:Apache License

private Panel generateVisualizerLinks(String docName) {
    Panel p = new Panel();
    VerticalLayout l = new VerticalLayout();
    p.addStyleName(ChameleonTheme.PANEL_BORDERLESS);

    if (docVisualizerConfig != null) {
        Visualizer[] visualizers = docVisualizerConfig.getVisualizers();

        if (visualizers != null) {
            for (Visualizer visualizer : visualizers) {
                Button openVis = new Button(visualizer.getDisplayName());
                openVis.setDescription("open visualizer with the full text of " + docName);
                openVis.addClickListener(new OpenVisualizerWindow(docName, visualizer, openVis));
                openVis.setStyleName(BaseTheme.BUTTON_LINK);
                openVis.setDisableOnClick(true);
                l.addComponent(openVis);
            }//www .  jav  a2  s  .  c  o m
        }
    }

    p.setContent(l);
    return p;
}

From source file:annis.gui.ExportPanel.java

License:Apache License

public ExportPanel(QueryPanel queryPanel, QueryController controller, QueryUIState state) {
    super(2, 3);/*from ww w.  ja  va 2 s.  c om*/
    this.queryPanel = queryPanel;
    this.controller = controller;
    this.state = state;

    this.eventBus = new EventBus();
    this.eventBus.register(ExportPanel.this);

    this.formLayout = new FormLayout();
    formLayout.setWidth("-1px");

    setWidth("99%");
    setHeight("-1px");

    initHelpMessages();

    setColumnExpandRatio(0, 0.0f);
    setColumnExpandRatio(1, 1.0f);

    cbExporter = new ComboBox("Exporter");
    cbExporter.setNewItemsAllowed(false);
    cbExporter.setNullSelectionAllowed(false);
    cbExporter.setImmediate(true);

    for (Exporter e : SearchView.EXPORTER) {
        cbExporter.addItem(e.getClass().getSimpleName());
    }

    cbExporter.setValue(SearchView.EXPORTER[0].getClass().getSimpleName());
    cbExporter.addValueChangeListener(new ExporterSelectionHelpListener());

    formLayout.addComponent(cbExporter);
    addComponent(formLayout, 0, 0);

    lblHelp = new Label(help4Exporter.get((String) cbExporter.getValue()));
    lblHelp.setContentMode(ContentMode.HTML);
    addComponent(lblHelp, 1, 0);

    cbLeftContext = new ComboBox("Left Context");
    cbRightContext = new ComboBox("Right Context");

    cbLeftContext.setNullSelectionAllowed(false);
    cbRightContext.setNullSelectionAllowed(false);

    cbLeftContext.setNewItemsAllowed(true);
    cbRightContext.setNewItemsAllowed(true);

    cbLeftContext
            .addValidator(new IntegerRangeValidator("must be a number", Integer.MIN_VALUE, Integer.MAX_VALUE));
    cbRightContext
            .addValidator(new IntegerRangeValidator("must be a number", Integer.MIN_VALUE, Integer.MAX_VALUE));

    for (Integer i : SearchOptionsPanel.PREDEFINED_CONTEXTS) {
        cbLeftContext.addItem(i);
        cbRightContext.addItem(i);
    }

    cbLeftContext.setValue(5);
    cbRightContext.setValue(5);

    formLayout.addComponent(cbLeftContext);
    formLayout.addComponent(cbRightContext);

    txtAnnotationKeys = new TextField("Annotation Keys");
    txtAnnotationKeys.setDescription("Some exporters will use this comma "
            + "seperated list of annotation keys to limit the exported data to these " + "annotations.");
    formLayout.addComponent(new HelpButton(txtAnnotationKeys));

    txtParameters = new TextField("Parameters");
    txtParameters.setDescription(
            "You can input special parameters " + "for certain exporters. See the description of each exporter "
                    + "(? button above) for specific parameter settings.");
    formLayout.addComponent(new HelpButton(txtParameters));

    btExport = new Button("Perform Export");
    btExport.setIcon(FontAwesome.PLAY);
    btExport.setDisableOnClick(true);
    btExport.addClickListener(new ExportButtonListener());

    btCancel = new Button("Cancel Export");
    btCancel.setIcon(FontAwesome.TIMES_CIRCLE);
    btCancel.setEnabled(false);
    btCancel.addClickListener(new CancelButtonListener());
    btCancel.setVisible(SearchView.EXPORTER[0].isCancelable());

    btDownload = new Button("Download");
    btDownload.setDescription("Click here to start the actual download.");
    btDownload.setIcon(FontAwesome.DOWNLOAD);
    btDownload.setDisableOnClick(true);
    btDownload.setEnabled(false);

    HorizontalLayout layoutExportButtons = new HorizontalLayout(btExport, btCancel, btDownload);
    addComponent(layoutExportButtons, 0, 1, 1, 1);

    VerticalLayout vLayout = new VerticalLayout();
    addComponent(vLayout, 0, 2, 1, 2);

    progressBar = new ProgressBar();
    progressBar.setVisible(false);
    progressBar.setIndeterminate(true);
    vLayout.addComponent(progressBar);

    progressLabel = new Label();
    vLayout.addComponent(progressLabel);

    if (state != null) {
        cbLeftContext.setPropertyDataSource(state.getLeftContext());
        cbRightContext.setPropertyDataSource(state.getRightContext());
        cbExporter.setPropertyDataSource(state.getExporterName());

        state.getExporterName().setValue(SearchView.EXPORTER[0].getClass().getSimpleName());

        txtAnnotationKeys.setConverter(new CommaSeperatedStringConverterList());
        txtAnnotationKeys.setPropertyDataSource(state.getExportAnnotationKeys());

        txtParameters.setPropertyDataSource(state.getExportParameters());

    }

}

From source file:annis.gui.HelpUsWindow.java

License:Apache License

public HelpUsWindow() {
    setSizeFull();// w ww  .j  a v a  2 s .c  o  m
    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.HistoryPanel.java

License:Apache License

public HistoryPanel(final BeanItemContainer<Query> containerHistory, QueryController controller) {
    this.controller = controller;

    VerticalLayout layout = new VerticalLayout();
    setContent(layout);/*  w w  w .  java 2 s  .c o m*/

    setSizeFull();
    layout.setSizeFull();

    tblHistory = new Table();

    layout.addComponent(tblHistory);
    tblHistory.setSizeFull();
    tblHistory.setSelectable(true);
    tblHistory.setMultiSelect(false);
    tblHistory.setContainerDataSource(containerHistory);

    tblHistory.addGeneratedColumn("gennumber", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            int idx = containerHistory.indexOfId(itemId);
            return new Label("" + (idx + 1));
        }
    });
    citationGenerator = new CitationLinkGenerator();
    tblHistory.addGeneratedColumn("genlink", citationGenerator);

    tblHistory.addStyleName(Helper.CORPUS_FONT);
    tblHistory.setVisibleColumns("gennumber", "query", "genlink");
    tblHistory.setColumnHeader("gennumber", "#");
    tblHistory.setColumnHeader("query", "Query");
    tblHistory.setColumnHeader("genlink", "URL");
    tblHistory.setColumnExpandRatio("query", 1.0f);
    tblHistory.setImmediate(true);
    tblHistory.addValueChangeListener((ValueChangeListener) this);
    tblHistory.addItemClickListener((ItemClickListener) this);

}

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  .j  av  a 2 s.  c  o m*/

    // 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.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);/*from   ww w . j  a v  a 2  s  .  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();
}