Example usage for com.vaadin.server VaadinService getCurrent

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

Introduction

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

Prototype

public static VaadinService getCurrent() 

Source Link

Document

Gets the currently used Vaadin service.

Usage

From source file:annis.gui.AboutWindow.java

License:Apache License

public AboutWindow() {
    setSizeFull();/*  w  w  w. j  av a  2 s . c o  m*/

    layout = new VerticalLayout();
    setContent(layout);
    layout.setSizeFull();
    layout.setMargin(true);

    HorizontalLayout hLayout = new HorizontalLayout();

    Embedded logoAnnis = new Embedded();
    logoAnnis.setSource(new ThemeResource("images/annis-logo-128.png"));
    logoAnnis.setType(Embedded.TYPE_IMAGE);
    hLayout.addComponent(logoAnnis);

    Embedded logoSfb = new Embedded();
    logoSfb.setSource(new ThemeResource("images/sfb-logo.jpg"));
    logoSfb.setType(Embedded.TYPE_IMAGE);
    hLayout.addComponent(logoSfb);

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

    hLayout.setComponentAlignment(logoAnnis, Alignment.MIDDLE_LEFT);
    hLayout.setComponentAlignment(logoSfb, Alignment.MIDDLE_RIGHT);
    hLayout.setComponentAlignment(lnkFork, Alignment.TOP_RIGHT);

    layout.addComponent(hLayout);

    layout.addComponent(new Label(
            "ANNIS is a project of the " + "<a href=\"http://www.sfb632.uni-potsdam.de/\">SFB632</a>.",
            Label.CONTENT_XHTML));
    layout.addComponent(new Label("Homepage: " + "<a href=\"http://corpus-tools.org/annis/\">"
            + "http://corpus-tools.org/annis/</a>.", Label.CONTENT_XHTML));
    layout.addComponent(new Label("Version: " + VersionInfo.getVersion()));
    layout.addComponent(new Label("Vaadin-Version: " + Version.getFullVersion()));

    TextArea txtThirdParty = new TextArea();
    txtThirdParty.setSizeFull();

    StringBuilder sb = new StringBuilder();

    sb.append("The ANNIS team wants to thank these third party software that "
            + "made the ANNIS GUI possible:\n");

    File thirdPartyFolder = new File(VaadinService.getCurrent().getBaseDirectory(), "THIRD-PARTY");
    if (thirdPartyFolder.isDirectory()) {
        for (File c : thirdPartyFolder.listFiles((FileFilter) new WildcardFileFilter("*.txt"))) {
            if (c.isFile()) {
                try {
                    sb.append(FileUtils.readFileToString(c)).append("\n");
                } catch (IOException ex) {
                    log.error("Could not read file", ex);
                }
            }
        }
    }

    txtThirdParty.setValue(sb.toString());
    txtThirdParty.setReadOnly(true);
    txtThirdParty.addStyleName("shared-text");
    txtThirdParty.setWordwrap(false);

    layout.addComponent(txtThirdParty);

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

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

}

From source file:annis.gui.ReportBugWindow.java

License:Apache License

private boolean sendBugReport(String bugEMailAddress, byte[] screenImage, String imageMimeType) {
    MultiPartEmail mail = new MultiPartEmail();
    try {//from  w  w w . j  a va2  s.  c  om
        // server setup
        mail.setHostName("localhost");

        // content of the mail
        mail.addReplyTo(form.getField("email").getValue().toString(),
                form.getField("name").getValue().toString());
        mail.setFrom(bugEMailAddress);
        mail.addTo(bugEMailAddress);

        mail.setSubject("[ANNIS BUG] " + form.getField("summary").getValue().toString());

        // TODO: add info about version etc.
        StringBuilder sbMsg = new StringBuilder();

        sbMsg.append("Reporter: ").append(form.getField("name").getValue().toString()).append(" (")
                .append(form.getField("email").getValue().toString()).append(")\n");
        sbMsg.append("Version: ").append(VersionInfo.getVersion()).append("\n");
        sbMsg.append("Vaadin Version: ").append(Version.getFullVersion()).append("\n");
        sbMsg.append("Browser: ").append(Page.getCurrent().getWebBrowser().getBrowserApplication())
                .append("\n");
        sbMsg.append("URL: ").append(UI.getCurrent().getPage().getLocation().toASCIIString()).append("\n");

        sbMsg.append("\n");

        sbMsg.append(form.getField("description").getValue().toString());
        mail.setMsg(sbMsg.toString());

        if (screenImage != null) {
            try {
                mail.attach(new ByteArrayDataSource(screenImage, imageMimeType), "screendump.png",
                        "Screenshot of the browser content at time of problem report");
            } catch (IOException ex) {
                log.error(null, ex);
            }
        }

        File logfile = new File(VaadinService.getCurrent().getBaseDirectory(), "/WEB-INF/log/annis-gui.log");
        if (logfile.exists() && logfile.isFile() && logfile.canRead()) {
            mail.attach(new FileDataSource(logfile), "annis-gui.log",
                    "Logfile of the GUI (shared by all users)");
        }

        if (cause != null) {
            try {
                mail.attach(new ByteArrayDataSource(Helper.convertExceptionToMessage(cause), "text/plain"),
                        "exception.txt", "Exception that caused the user to report the problem");
            } catch (IOException ex) {
                log.error(null, ex);
            }
        }

        mail.send();
        return true;

    } catch (EmailException ex) {
        Notification.show("E-Mail not configured on server",
                "If this is no Kickstarter version please ask the administrator (" + bugEMailAddress
                        + ") of this ANNIS-instance for assistance. "
                        + "Problem reports are not available for ANNIS Kickstarter",
                Notification.Type.ERROR_MESSAGE);
        log.error(null, ex);
        return false;
    }
}

From source file:annis.gui.tutorial.TutorialPanel.java

License:Apache License

public TutorialPanel() {
    setSizeFull();/*from   w w  w. j av a2s  .  co m*/

    String localBasePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
    URI appURI = UI.getCurrent().getPage().getLocation();
    URI tutorialURI;

    String relativeFile = "/VAADIN/tutorial/index.html";

    try {
        String oldPath = VaadinService.getCurrentRequest().getContextPath();
        if (oldPath == null) {
            oldPath = "";
        }
        if (oldPath.endsWith("/")) {
            oldPath = oldPath.substring(0, oldPath.length() - 1);
        }
        tutorialURI = new URI(appURI.getScheme(), appURI.getUserInfo(), appURI.getHost(), appURI.getPort(),
                oldPath + relativeFile, null, null);
        embedded = new NavigateableSinglePage(new File(localBasePath + relativeFile), tutorialURI);
        embedded.setSizeFull();
        addComponent(embedded);

    } catch (URISyntaxException ex) {
        log.error("Invalid tutorial URI", ex);
    }

}

From source file:annis.libgui.AnnisBaseUI.java

License:Apache License

/**
 * Given an configuration file name (might include directory) this function
 * returns all locations for this file in the "ANNIS configuration system".
 *
 * The files in the result list do not necessarily exist.
 *
 * These locations are the/*from www .  j av a  2 s . c o m*/
 * - base installation: WEB-INF/conf/ folder of the deployment.
 * - global configuration: $ANNIS_CFG environment variable value or /etc/annis/ if not set
 * - user configuration: ~/.annis/
 * @param configFile The file path of the configuration file relative to the base config folder.
 * @return list of files or directories in the order in which they should be processed (most important is last)
 */
public static List<File> getAllConfigLocations(String configFile) {
    LinkedList<File> locations = new LinkedList<File>();

    // first load everything from the base application
    locations.add(new File(VaadinService.getCurrent().getBaseDirectory(), "/WEB-INF/conf/" + configFile));

    // next everything from the global config
    // When ANNIS_CFG environment variable is set use this value or default to
    // "/etc/annis/
    String globalConfigDir = System.getenv("ANNIS_CFG");
    if (globalConfigDir == null) {
        globalConfigDir = "/etc/annis";
    }
    locations.add(new File(globalConfigDir + "/" + configFile));

    // the final and most specific user configuration is in the users home directory
    locations.add(new File(System.getProperty("user.home") + "/.annis/" + configFile));

    return locations;
}

From source file:annis.libgui.AnnisBaseUI.java

License:Apache License

protected final void initLogging() {
    try {/*from  w w w .ja va 2 s .c om*/

        List<File> logbackFiles = getAllConfigLocations("gui-logback.xml");

        InputStream inStream = null;
        if (!logbackFiles.isEmpty()) {
            try {
                inStream = new FileInputStream(logbackFiles.get(logbackFiles.size() - 1));
            } catch (FileNotFoundException ex) {
                // well no logging no error...
            }
        }
        if (inStream == null) {
            ClassResource res = new ClassResource(AnnisBaseUI.class, "logback.xml");
            inStream = res.getStream().getStream();
        }

        if (inStream != null) {
            LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
            JoranConfigurator jc = new JoranConfigurator();
            jc.setContext(context);
            context.reset();

            context.putProperty("webappHome", VaadinService.getCurrent().getBaseDirectory().getAbsolutePath());

            // load config file
            jc.doConfigure(inStream);
        }
    } catch (JoranException ex) {
        log.error("init logging failed", ex);
    }

}

From source file:annis.libgui.AnnisBaseUI.java

License:Apache License

private void initPlugins() {

    log.info("Adding plugins");
    pluginManager = PluginManagerFactory.createPluginManager();
    addCustomUIPlugins(pluginManager);/*w  w  w  . j  a va 2 s  .c o  m*/

    File baseDir = VaadinService.getCurrent().getBaseDirectory();

    File builtin = new File(baseDir, "WEB-INF/lib/annis-visualizers-" + VersionInfo.getReleaseName() + ".jar");
    if (builtin.canRead()) {
        pluginManager.addPluginsFrom(builtin.toURI());
        log.info("added built-in plugins from  {}", builtin.getPath());
    } else {
        log.warn("could not find built-in plugin file {}", builtin.getPath());
    }
    File basicPlugins = new File(baseDir, "WEB-INF/plugins");
    if (basicPlugins.isDirectory()) {
        pluginManager.addPluginsFrom(basicPlugins.toURI());
        log.info("added plugins from {}", basicPlugins.getPath());
    }

    String globalPlugins = System.getenv("ANNIS_PLUGINS");
    if (globalPlugins != null) {
        pluginManager.addPluginsFrom(new File(globalPlugins).toURI());
        log.info("added plugins from {}", globalPlugins);
    }

    StringBuilder listOfPlugins = new StringBuilder();
    listOfPlugins.append("loaded plugins:\n");
    PluginManagerUtil util = new PluginManagerUtil(pluginManager);
    for (Plugin p : util.getPlugins()) {
        listOfPlugins.append(p.getClass().getName()).append("\n");
    }
    log.info(listOfPlugins.toString());

    Collection<VisualizerPlugin> visualizers = util.getPlugins(VisualizerPlugin.class);
    for (VisualizerPlugin vis : visualizers) {
        visualizerRegistry.put(vis.getShortName(), vis);
        resourceAddedDate.put(vis.getShortName(), new Date());
    }
}

From source file:au.org.scoutmaster.views.ContactView.java

private DateField overviewTab() {
    // Overview tab

    final SMMultiColumnFormLayout<Contact> overviewForm = new SMMultiColumnFormLayout<Contact>(3,
            this.fieldGroup);
    overviewForm.setColumnFieldWidth(0, 100);
    overviewForm.setColumnLabelWidth(1, 0);
    overviewForm.setColumnFieldWidth(1, 140);
    overviewForm.setColumnLabelWidth(2, 40);
    overviewForm.setColumnFieldWidth(2, 80);
    overviewForm.setMargin(true);/*from   ww  w. j ava 2  s .c  o m*/

    // overviewForm.setColumnLabelWidth(0, 100);
    // overviewForm.setColumnLabelWidth(1, 0);
    // overviewForm.setColumnLabelWidth(2, 60);
    // overviewForm.setColumnFieldWidth(0, 100);
    // overviewForm.setColumnFieldWidth(1, 100);
    // overviewForm.setColumnFieldWidth(2, 20);

    // overviewForm.setSizeFull();

    final FormHelper<Contact> formHelper = overviewForm.getFormHelper();

    // overviewForm.setMargin(true);
    this.tabs.addTab(overviewForm, "Overview");
    overviewForm.bindBooleanField("Active", Contact_.active);
    overviewForm.newLine();
    overviewForm.colspan(3);
    this.groupRoleField = formHelper.new EntityFieldBuilder<GroupRole>().setLabel("Role")
            .setField(Contact_.groupRole).setListFieldName(GroupRole_.name).build();
    this.groupRoleField.addValueChangeListener(this.changeListener);

    overviewForm.newLine();
    overviewForm.colspan(3);
    overviewForm.bindTextField("Firstname", Contact_.firstname);
    overviewForm.newLine();
    overviewForm.colspan(3);
    overviewForm.bindTextField("Middle name", Contact_.middlename);
    overviewForm.newLine();

    overviewForm.colspan(3);
    overviewForm.bindTextField("Lastname", Contact_.lastname);

    overviewForm.newLine();
    this.birthDate = overviewForm.bindDateField("Birth Date", Contact_.birthDate, "yyyy-MM-dd", Resolution.DAY);
    // fieldOverviewSectionEligibity = overviewForm.addTextField(null);
    // fieldOverviewSectionEligibity.setReadOnly(true);
    this.ageField = overviewForm.bindLabel("Age");
    // overviewForm.setComponentAlignment(this.ageField,
    // Alignment.MIDDLE_LEFT);
    overviewForm.newLine();
    overviewForm.bindEnumField("Gender", Contact_.gender, Gender.class);
    overviewForm.newLine();

    overviewForm.colspan(3);
    overviewForm.bindBooleanField("Do Not Send Bulk Communications", Contact_.doNotSendBulkCommunications);
    overviewForm.newLine();

    overviewForm.colspan(3);
    overviewForm.bindEnumField("Preferred Communications", Contact_.preferredCommunications,
            PreferredCommunications.class);
    overviewForm.newLine();

    overviewForm.colspan(3);
    final TextField homeEmail = overviewForm.bindTextField("Home Email", Contact_.homeEmail);
    final String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();

    final FileResource resource = new FileResource(new File(basepath + "/WEB-INF/images/email.png"));

    this.homeEmailImage = new Image(null, resource);
    this.homeEmailImage.setDescription("Click to send an email");
    this.homeEmailImage.addClickListener(new MouseEventLogged.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(final com.vaadin.event.MouseEvents.ClickEvent event) {
            showMailForm(homeEmail);

        }
    });
    overviewForm.addComponent(this.homeEmailImage);
    this.homeEmailImage.setVisible(false);
    overviewForm.newLine();
    overviewForm.colspan(3);
    final TextField workEmail = overviewForm.bindTextField("Work Email", Contact_.workEmail);
    this.workEmailImage = new Image(null, resource);
    this.workEmailImage.setDescription("Click to send an email");
    overviewForm.addComponent(this.workEmailImage);
    this.workEmailImage.addClickListener(new MouseEventLogged.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(final com.vaadin.event.MouseEvents.ClickEvent event) {
            showMailForm(workEmail);

        }
    });

    this.workEmailImage.setVisible(false);

    overviewForm.newLine();

    overviewForm.bindTextField("Phone 1", "phone1.phoneNo");
    overviewForm.bindEnumField(null, "phone1.phoneType", PhoneType.class);
    this.primaryPhone1 = overviewForm.bindBooleanField("Primary",
            Contact_.phone1.getName() + "." + Phone_.primaryPhone.getName());
    this.primaryPhone1.addValueChangeListener(new PhoneChangeListener());

    overviewForm.newLine();
    overviewForm.bindTextField("Phone 2", "phone2.phoneNo");
    overviewForm.bindEnumField(null, "phone2.phoneType", PhoneType.class);
    this.primaryPhone2 = overviewForm.bindBooleanField("Primary", "phone2.primaryPhone");
    this.primaryPhone2.addValueChangeListener(new PhoneChangeListener());

    overviewForm.newLine();
    overviewForm.bindTextField("Phone 3", "phone3.phoneNo");
    overviewForm.bindEnumField(null, "phone3.phoneType", PhoneType.class);
    this.primaryPhone3 = overviewForm.bindBooleanField("Primary", "phone3.primaryPhone");
    this.primaryPhone3.addValueChangeListener(new PhoneChangeListener());

    overviewForm.newLine();
    overviewForm.colspan(3);
    overviewForm.bindTextField("Street", "address.street");
    overviewForm.newLine();
    overviewForm.colspan(3);
    overviewForm.bindTextField("City", "address.city");

    overviewForm.newLine();
    overviewForm.bindTextField("State", "address.state");
    overviewForm.bindTextField("Postcode", "address.postcode");
    overviewForm.newLine();

    overviewForm.colspan(3);
    this.tagField = overviewForm.bindTagField(this, "Tags", Contact_.tags);

    // tabs.addTab(overviewForm, "Contact");

    return this.birthDate;

}

From source file:ch.bfh.ti.soed.hs16.srs.view.views.helpers.Header.java

License:Open Source License

public Header() {

    /* init objects */
    this.layout = new VerticalLayout();

    // find application in directory
    String basePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
    // image as file resource
    // TODO Yep, logo appears. However, file should be retrieved from
    // location within JAR file. Consult Vaadin documentation on how to do
    // this.// w  ww. j a  va  2 s.  c om
    FileResource fileResource = new FileResource(new File(basePath + File.separator + "VAADIN" + File.separator
            + "themes" + File.separator + "mytheme" + File.separator + "srsLogo.jpg"));
    Image pic = new Image("", fileResource);

    /* add components to layout */
    this.layout.addComponents(pic);
}

From source file:ch.bfh.ti.soed.hs16.srs.white.helpers.ResourcesHelper.java

License:Open Source License

private ResourcesHelper() {
    final String PROJECT_NAME = "white";

    if (VaadinService.getCurrent() != null)
        path = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
    else {//from   ww w  . j  a  v a  2 s .co  m
        path = getClass().getClassLoader().getResource(".").getPath();
        String[] pathSplit = path.split("/");
        StringBuilder pathBuilder = new StringBuilder("/");

        for (String s : pathSplit) {
            if (s.equals(PROJECT_NAME)) {
                pathBuilder.append(s).append("/src/main/webapp");
                break;
            }

            if (!s.isEmpty())
                pathBuilder.append(s).append("/");
        }

        path = pathBuilder.toString();
    }
}

From source file:com.cerebro.cable.xforce.view.GestioneRazze.java

public GestioneRazze() {

    setMargin(true);/*from w  w  w . java  2s  .c  o m*/

    TableQuery racesTQ = new TableQuery("races", connPool);
    SQLContainer racesContainer = null;
    try {
        racesContainer = new SQLContainer(racesTQ);
    } catch (Exception ex) {
        logger.error("Errore nella tabella delle razze: " + ex.getMessage());
    }
    Grid racesTable = new Grid(racesContainer);
    racesTable.removeAllColumns();
    for (int i = 0; i < racesTabCols.length; i++) {
        racesTable.addColumn(racesTabCols[i][0]);
        Grid.Column col = racesTable.getColumn(racesTabCols[i][0]);
        col.setHeaderCaption(racesTabCols[i][1]);
    }
    racesTable.getColumn("image").setRenderer(new ImageRenderer(), new Converter<Resource, String>() {
        @Override
        public String convertToModel(Resource value, Class<? extends String> targetType, Locale locale)
                throws Converter.ConversionException {
            return "not needed";
        }

        @Override
        public Resource convertToPresentation(String value, Class<? extends Resource> targetType, Locale locale)
                throws Converter.ConversionException {
            return new FileResource(
                    new File(VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + value));
        }

        @Override
        public Class<String> getModelType() {
            return String.class;
        }

        @Override
        public Class<Resource> getPresentationType() {
            return Resource.class;
        }

    });

    FormLayout raceEditor = new FormLayout();

    addComponents(racesTable);
}