Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server Page getCurrent.

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

From source file:org.jpos.qi.login.LoginView.java

License:Open Source License

private void loginFailed(String nick, User user) {
    boolean userLocked = false;
    if (user != null) {
        int attempts = helper.addLoginAttempt(user);
        int maxLoginAttempts;
        try {//from w ww. ja  va  2 s . co  m
            maxLoginAttempts = helper.getMaxLoginAttempts();
        } catch (NumberFormatException exc) {
            app.displayError("errorMessage.invalidSysConfig", "errorMessage.invalidSysConfigFormat",
                    LoginConstants.MAX_LOGIN_ATTEMPTS.name());
            maxLoginAttempts = 0;
        }
        if (maxLoginAttempts != 0 && attempts >= maxLoginAttempts) {
            helper.lockUser(user);
            userLocked = true;
        }
    }
    //Display message
    String descKey = userLocked ? "login.fail.maxAttempts" : "login.fail.desc";
    Notification notif = new Notification(app.getMessage("login.fail"), app.getMessage(descKey, nick),
            Notification.Type.ERROR_MESSAGE, true);
    notif.show(Page.getCurrent());
}

From source file:org.jpos.qi.Sidebar.java

License:Open Source License

private Component createToggleButton() {
    Button valoMenuToggleButton = new Button("", (Button.ClickListener) event -> {
        if (Page.getCurrent().getBrowserWindowWidth() > 1100) {
            boolean expand = !menuItems.isVisible();
            menuItems.setVisible(expand ? true : false);
        } else {/*  w  ww . ja va  2 s  .co m*/
            if (getStyleName().contains(STYLE_VISIBLE))
                removeStyleName(STYLE_VISIBLE);
            else
                addStyleName(STYLE_VISIBLE);
        }
    });
    valoMenuToggleButton.setIcon(FontAwesome.LIST);
    valoMenuToggleButton.addStyleName("valo-menu-toggle");
    valoMenuToggleButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    valoMenuToggleButton.addStyleName(ValoTheme.BUTTON_SMALL);
    return valoMenuToggleButton;
}

From source file:org.jumpmind.metl.ui.common.PageNotFoundView.java

License:Open Source License

@Override
public void enter(ViewChangeEvent event) {
    String uriFragment = Page.getCurrent().getUriFragment();
    if (isBlank(uriFragment)) {
        viewManager.navigateToDefault();
    } else {//from   w w w.  ja  v a  2s.c  o  m
        pageNotFoundLabel.addStyleName("failure");
        pageNotFoundLabel.setValue("Could not find page for " + uriFragment);
    }
}

From source file:org.jumpmind.metl.ui.common.TopBar.java

License:Open Source License

protected void logout() {
    URI uri = Page.getCurrent().getLocation();
    VaadinSession.getCurrent().close();
    Page.getCurrent().setLocation(uri.getPath());
}

From source file:org.jumpmind.metl.ui.common.TopBar.java

License:Open Source License

protected void openHelp(ClickEvent event) {
    String docUrl = Page.getCurrent().getLocation().toString();
    docUrl = docUrl.substring(0, docUrl.lastIndexOf("/"));
    Page.getCurrent().open(docUrl + "/doc/html/user-guide.html", "doc");
}

From source file:org.jumpmind.metl.ui.views.admin.ApiPanel.java

License:Open Source License

public ApiPanel(ApplicationContext context, TabbedPanel tabbedPanel) {
    setSizeFull();/*from  w ww  .  j a  v a 2s  .co m*/
    String url = Page.getCurrent().getLocation().getPath();
    BrowserFrame e = new BrowserFrame(null,
            new ExternalResource(url.substring(0, url.lastIndexOf("/")) + "/api.html"));
    e.setSizeFull();
    addComponent(e);
}

From source file:org.jumpmind.metl.ui.views.admin.LoggingPanel.java

License:Open Source License

private StreamResource getLogFileResource() {
    StreamSource ss = new StreamSource() {
        public InputStream getStream() {
            try {
                return new BufferedInputStream(new FileInputStream(logFile));
            } catch (FileNotFoundException e) {
                Notification note = new Notification("File Not Found",
                        "Could not find " + logFile.getName() + " to download");
                note.show(Page.getCurrent());
                return null;
            }/*ww  w .  j  av a  2  s  .  c om*/
        }
    };
    return new StreamResource(ss, logFile.getName());
}

From source file:org.jumpmind.metl.ui.views.deploy.EditAgentPanel.java

License:Open Source License

protected void exportConfiguration() {
    final String export = context.getConfigurationService().export(agent);
    StreamSource ss = new StreamSource() {
        private static final long serialVersionUID = 1L;

        public InputStream getStream() {
            try {
                return new ByteArrayInputStream(export.getBytes());
            } catch (Exception e) {
                log.error("Failed to export configuration", e);
                CommonUiUtils.notify("Failed to export configuration.", Type.ERROR_MESSAGE);
                return null;
            }//from   w  ww .ja v a 2s . co m

        }
    };
    String datetime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    StreamResource resource = new StreamResource(ss,
            String.format("%s-config-%s.sql", agent.getName().toLowerCase().replaceAll(" ", "-"), datetime));
    final String KEY = "export";
    setResource(KEY, resource);
    Page.getCurrent().open(ResourceReference.create(resource, this, KEY).getURL(), null);
}

From source file:org.jumpmind.metl.ui.views.design.ImportXmlTemplateWindow.java

License:Open Source License

protected void importXml(String text) {
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {//from  ww  w  .j a v a  2  s. co  m
        Document document = builder.build(new StringReader(text));
        String rootName = document.getRootElement().getName();
        if (rootName.equals("definitions")) {
            importFromWsdl(text);
        } else if (rootName.equals("schema")) {
            importFromXsd(text);
        } else {
            Notification note = new Notification("Unrecognized Content", "The XML file has a root element of "
                    + rootName + ", but expected \"definitions\" for WSDL or \"schema\" for XSD.");
            note.show(Page.getCurrent());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jumpmind.metl.ui.views.design.ImportXmlTemplateWindow.java

License:Open Source License

protected void importFromWsdl(String text) throws Exception {
    File wsdlFile = File.createTempFile("import", "wsdl");
    FileUtils.write(wsdlFile, text);/*from  ww  w  . java 2 s  . c o m*/
    final Wsdl wsdl = Wsdl.parse(wsdlFile.toURI().toURL());
    List<SoapOperation> allOperations = new ArrayList<>();
    List<QName> bindings = wsdl.getBindings();
    for (QName binding : bindings) {
        SoapBuilder builder = wsdl.getBuilder(binding);
        List<SoapOperation> operations = builder.getOperations();
        allOperations.addAll(operations);
    }

    if (allOperations.size() == 0) {
        Notification note = new Notification("No operations", "No operations found in the WSDL.");
        note.show(Page.getCurrent());
    } else if (allOperations.size() == 1) {
        importFromWsdl(wsdl, allOperations.get(0));
    } else {
        ChooseWsdlServiceOperationWindow dialog = new ChooseWsdlServiceOperationWindow(allOperations,
                new ServiceChosenListener() {
                    public boolean onOk(SoapOperation operation) {
                        importFromWsdl(wsdl, operation);
                        return true;
                    }
                });
        UI.getCurrent().addWindow(dialog);
    }
}