Example usage for com.vaadin.ui Button addClickListener

List of usage examples for com.vaadin.ui Button addClickListener

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

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);
            }//from   www.  ja  v  a2  s.co  m
        }
    }

    p.setContent(l);
    return p;
}

From source file:annis.gui.ExampleQueriesPanel.java

License:Apache License

private Component getOpenCorpusPanel(final String corpusName) {
    final Button btn = new Button(corpusName);

    btn.setStyleName(BaseTheme.BUTTON_LINK);
    btn.addClickListener(new Button.ClickListener() {
        @Override/*from  w  ww  .j a va 2  s.c  om*/
        public void buttonClick(Button.ClickEvent event) {
            CorpusListPanel corpusList = ui.getSearchView().getControlPanel().getCorpusList();
            corpusList.initCorpusBrowser(corpusName, btn);
        }
    });

    return btn;
}

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 w  ww.ja  v a2  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();
}

From source file:annis.gui.ShareQueryReferenceWindow.java

License:Apache License

public ShareQueryReferenceWindow(DisplayedResultQuery query, boolean shorten) {
    super("Query reference link");

    VerticalLayout wLayout = new VerticalLayout();
    setContent(wLayout);//w w  w . ja  v a 2  s. c  om
    wLayout.setSizeFull();
    wLayout.setMargin(true);

    Label lblInfo = new Label(
            "<p style=\"font-size: 18px\" >" + "<strong>Share your query:</strong>&nbsp;"
                    + "1.&nbsp;Copy the generated link 2.&nbsp;Share this link with your peers. " + "</p>",
            ContentMode.HTML);
    wLayout.addComponent(lblInfo);
    wLayout.setExpandRatio(lblInfo, 0.0f);

    String shortURL = "ERROR";
    if (query != null) {
        URI url = Helper.generateCitation(query.getQuery(), query.getCorpora(), query.getLeftContext(),
                query.getRightContext(), query.getSegmentation(), query.getBaseText(), query.getOffset(),
                query.getLimit(), query.getOrder(), query.getSelectedMatches());

        if (shorten) {
            shortURL = Helper.shortenURL(url);
        } else {
            shortURL = url.toASCIIString();
        }
    }

    TextArea txtCitation = new TextArea();

    txtCitation.setWidth("100%");
    txtCitation.setHeight("100%");
    txtCitation.addStyleName(ValoTheme.TEXTFIELD_LARGE);
    txtCitation.addStyleName("shared-text");
    txtCitation.setValue(shortURL);
    txtCitation.setWordwrap(true);
    txtCitation.setReadOnly(true);

    wLayout.addComponent(txtCitation);

    Button btClose = new Button("Close");
    btClose.addClickListener((Button.ClickListener) this);
    btClose.setSizeUndefined();

    wLayout.addComponent(btClose);

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

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

}

From source file:annis.gui.ShareSingleMatchGenerator.java

License:Apache License

public ShareSingleMatchGenerator(List<ResolverEntry> visualizers, Match match, PagedResultQuery query,
        String segmentation, PluginSystem ps) {
    this.match = match;
    this.query = query;
    this.segmentation = segmentation;
    this.ps = ps;

    setResizeLazy(true);/*from  w w w .  j a va  2 s.c  o m*/

    directURL = new ObjectProperty<>("");
    iframeCode = new ObjectProperty<>("");

    visContainer = new BeanItemContainer<>(ResolverEntry.class);
    visContainer.addAll(visualizers);

    txtDirectURL = new TextArea(directURL);
    txtDirectURL.setCaption("Link for publications");
    txtDirectURL.setWidth("100%");
    txtDirectURL.setHeight("-1px");
    txtDirectURL.addStyleName(ValoTheme.TEXTFIELD_LARGE);
    txtDirectURL.addStyleName("shared-text");
    txtDirectURL.setWordwrap(true);
    txtDirectURL.setReadOnly(true);

    txtIFrameCode = new TextArea(iframeCode);
    txtIFrameCode.setCaption("Code for embedding visualization into web page");
    txtIFrameCode.setWidth("100%");
    txtIFrameCode.setHeight("-1px");
    txtIFrameCode.addStyleName(ValoTheme.TEXTFIELD_LARGE);
    txtIFrameCode.addStyleName("shared-text");
    txtIFrameCode.setWordwrap(true);
    txtIFrameCode.setReadOnly(true);

    preview = new BrowserFrame();
    preview.setCaption("Preview");
    preview.addStyleName("shared-text");
    preview.setSizeFull();

    generatedLinks = new VerticalLayout(txtDirectURL, txtIFrameCode, preview);
    generatedLinks.setComponentAlignment(txtDirectURL, Alignment.TOP_LEFT);
    generatedLinks.setComponentAlignment(txtIFrameCode, Alignment.TOP_LEFT);
    generatedLinks.setExpandRatio(preview, 1.0f);

    visSelector = new Grid(visContainer);
    visSelector.setCaption("Select visualization");
    visSelector.setHeight("100%");
    visSelector.setColumns("displayName");
    visSelector.setSelectionMode(Grid.SelectionMode.SINGLE);
    visSelector.addSelectionListener(ShareSingleMatchGenerator.this);
    visSelector.select(visContainer.getIdByIndex(0));
    visSelector.setWidth("300px");
    visSelector.getColumn("displayName").setSortable(false);

    generatedLinks.setSizeFull();

    Label infoText = new Label(
            "<p style=\"font-size: 18px\" >" + "<strong>Share your match:</strong>&nbsp;"
                    + "1.&nbsp;Choose the visualization to share. 2.&nbsp;Copy the generated link or code. "
                    + "3.&nbsp;Share this link with your peers or include the code in your website. " + "</p>",
            ContentMode.HTML);

    HorizontalLayout hLayout = new HorizontalLayout(visSelector, generatedLinks);
    hLayout.setSizeFull();
    hLayout.setSpacing(true);
    hLayout.setExpandRatio(generatedLinks, 1.0f);

    Button btClose = new Button("Close");
    btClose.setSizeUndefined();
    btClose.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            getUI().removeWindow(ShareSingleMatchGenerator.this);
        }
    });

    layout = new VerticalLayout(infoText, hLayout, btClose);
    layout.setSizeFull();
    layout.setExpandRatio(hLayout, 1.0f);
    layout.setComponentAlignment(btClose, Alignment.MIDDLE_CENTER);

    setContent(layout);
}

From source file:at.jku.ce.adaptivetesting.vaadin.ui.MainUI.java

License:LGPL

public MainUI() {
    // Make the web-app large
    setSizeFull();//from   ww w. j av  a2 s.  c o m
    // Set the layout for the bottom
    // Create a 3rd party licence button with a click listener
    final Button licences = new Button("Lizenzen");
    licences.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 32642854872179636L;

        @Override
        public void buttonClick(ClickEvent event) {
            LogHelper.logInfo("Opened LicenceWindow");
            LicenceWindow licenceWindow = new LicenceWindow();
            licenceWindow.addCloseListener(new CloseListener() {

                private static final long serialVersionUID = 7874342882437355680L;

                @Override
                public void windowClose(CloseEvent e) {
                    event.getButton().setEnabled(true);
                }
            });
            getUI().addWindow(licenceWindow);
            // Disable sender
            event.getButton().setEnabled(false);
        }

    });
    Label copyright = new HtmlLabel(
            "<i> Reisisoft & JKU 2014 - " + new GregorianCalendar().get(Calendar.YEAR) + "</i>");
    /* Button openLog = new Button("Open Log", (ClickListener) event -> {
       Navigator navigator = getUI().getNavigator();
       assert navigator != null;
       navigator.navigateTo(Views.Log.toString());
            
    });*/
    // Add the flowLayout at position 1 (second element) -> centered
    // Add everthing to flowlayout
    GridLayout southLayout = new GridLayout(3, 1);
    southLayout.setWidth("100%");
    southLayout.addComponent(licences, 0, 0);
    // southLayout.addComponent(openLog, 1, 0);
    southLayout.addComponent(copyright, 2, 0);
    // Add southlayout to the main Layout
    addComponent(southLayout);
    setComponentAlignment(southLayout, Alignment.BOTTOM_CENTER);
}

From source file:at.jku.ce.adaptivetesting.vaadin.ui.MockQuestion.java

License:LGPL

public MockQuestion(Question question) {
    this.question = question;

    TextArea textArea = new TextArea("Question text");
    textArea.setSizeFull();/*  ww w .ja  va  2s  .  c om*/

    // Download the result
    Button button = new Button("Display current user's solution");

    button.setSizeFull();
    button.addClickListener(e -> {
        Window window = new Window("Current user solution");
        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        window.setContent(layout);
        // Update questionText
        textArea.addTextChangeListener(ev -> questionText = ev.getText());
        textArea.setTextChangeEventMode(TextChangeEventMode.EAGER);
        Label label;
        try {
            label = new Label(toXML());
        } catch (Exception e1) {
            label = new Label(
                    "<h1>Error parsing XML</h1><p>" + e1.getMessage() + Arrays.toString(e1.getStackTrace()),
                    ContentMode.HTML);
            LogHelper.logThrowable(e1);
        }
        layout.addComponent(label);
        window.center();
        getUI().addWindow(window);
    });
    // Add components to the UI
    addComponent(textArea);
    addComponent(question);
    addComponent(button);
}

From source file:at.jku.ce.adaptivetesting.vaadin.ui.topic.accounting.AccountingQuestionManager.java

License:LGPL

public AccountingQuestionManager(String quizName) {
    super(quizName);
    Button openKontenplan = new Button("Kontenplan ffnen");
    openKontenplan.addClickListener(e -> {
        openKontenplan.setEnabled(false);
        // Create Window with layout
        Window window = new Window("Kontenplan");
        GridLayout layout = new GridLayout(1, 1);
        layout.addComponent(AccountingDataProvider.getInstance().toHtmlTable());
        layout.setSizeFull();//from  w  w  w . ja  v  a 2  s .  c  o  m
        window.setContent(layout);
        window.center();
        window.setWidth("60%");
        window.setHeight("80%");
        window.setResizable(false);
        window.addCloseListener(e1 -> openKontenplan.setEnabled(true));
        getUI().addWindow(window);

    });
    addHelpButton(openKontenplan);
}

From source file:at.reisisoft.jku.ce.adaptivelearning.vaadin.ui.MainUI.java

License:LGPL

public MainUI() {
    // Make the web-app large
    setSizeFull();/*  www .  j  a  va 2  s  .  c o m*/
    // Set the layout for the bottom
    // Create a 3rd party licence button with a click listener
    final Button licences = new Button("Show 3rd party licences");
    licences.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 32642854872179636L;

        @Override
        public void buttonClick(ClickEvent event) {
            LogHelper.logInfo("Opened LicenceWindow");
            LicenceWindow licenceWindow = new LicenceWindow();
            licenceWindow.addCloseListener(new CloseListener() {

                private static final long serialVersionUID = 7874342882437355680L;

                @Override
                public void windowClose(CloseEvent e) {
                    event.getButton().setEnabled(true);
                }
            });
            getUI().addWindow(licenceWindow);
            // Disable sender
            event.getButton().setEnabled(false);
        }

    });
    Label copyright = new HtmlLabel(
            "<i> Reisisoft 2014 - " + new GregorianCalendar().get(Calendar.YEAR) + "</i>");
    Button openLog = new Button("Open Log", (ClickListener) event -> {
        Navigator navigator = getUI().getNavigator();
        assert navigator != null;
        navigator.navigateTo(Views.Log.toString());

    });
    // Add the flowLayout at position 1 (second element) -> centered
    // Add everthing to flowlayout
    GridLayout southLayout = new GridLayout(3, 1);
    southLayout.setWidth("100%");
    southLayout.addComponent(licences, 0, 0);
    southLayout.addComponent(openLog, 1, 0);
    southLayout.addComponent(copyright, 2, 0);
    // Add southlayout to the main Layout
    addComponent(southLayout);
    setComponentAlignment(southLayout, Alignment.BOTTOM_CENTER);
}

From source file:at.reisisoft.jku.ce.adaptivelearning.vaadin.ui.topic.accounting.AccountingQuestionManager.java

License:LGPL

public AccountingQuestionManager(String quizName) {
    super(quizName);
    Button openKontenplan = new Button("Open Kontenplan");
    openKontenplan.addClickListener(e -> {
        openKontenplan.setEnabled(false);
        // Create Window with layout
        Window window = new Window("Kontenplan");
        GridLayout layout = new GridLayout(1, 1);
        layout.addComponent(AccountingDataProvider.getInstance().toHtmlTable());
        layout.setSizeFull();//from w ww . j  a va  2 s . com
        window.setContent(layout);
        window.center();
        window.setWidth("60%");
        window.setHeight("80%");
        window.setResizable(false);
        window.addCloseListener(e1 -> openKontenplan.setEnabled(true));
        getUI().addWindow(window);

    });
    addHelpButton(openKontenplan);
}