Example usage for com.vaadin.ui Link setVisible

List of usage examples for com.vaadin.ui Link setVisible

Introduction

In this page you can find the example usage for com.vaadin.ui Link setVisible.

Prototype

@Override
    public void setVisible(boolean visible) 

Source Link

Usage

From source file:annis.gui.EmbeddedVisUI.java

License:Apache License

private void generateVisFromRemoteURL(final String visName, final String rawUri, Map<String, String[]> args) {
    try {// w  ww  .j  av  a  2  s .co m
        // find the matching visualizer
        final VisualizerPlugin visPlugin = this.getVisualizer(visName);
        if (visPlugin == null) {
            displayMessage("Unknown visualizer \"" + visName + "\"",
                    "This ANNIS instance does not know the given visualizer.");
            return;
        }

        URI uri = new URI(rawUri);
        // fetch content of the URI
        Client client = null;
        AnnisUser user = Helper.getUser();
        if (user != null) {
            client = user.getClient();
        }
        if (client == null) {
            client = Helper.createRESTClient();
        }
        final WebResource saltRes = client.resource(uri);

        displayLoadingIndicator();

        // copy the arguments for using them later in the callback
        final Map<String, String[]> argsCopy = new LinkedHashMap<>(args);

        Background.runWithCallback(new Callable<SaltProject>() {
            @Override
            public SaltProject call() throws Exception {
                return saltRes.get(SaltProject.class);
            }
        }, new FutureCallback<SaltProject>() {
            @Override
            public void onFailure(Throwable t) {
                displayMessage("Could not query the result.", t.getMessage());
            }

            @Override
            public void onSuccess(SaltProject p) {
                // TODO: allow to display several visualizers when there is more than one document
                SCorpusGraph firstCorpusGraph = null;
                SDocument doc = null;
                if (p.getCorpusGraphs() != null && !p.getCorpusGraphs().isEmpty()) {
                    firstCorpusGraph = p.getCorpusGraphs().get(0);
                    if (firstCorpusGraph.getDocuments() != null && !firstCorpusGraph.getDocuments().isEmpty()) {
                        doc = firstCorpusGraph.getDocuments().get(0);
                    }
                }
                if (doc == null) {
                    displayMessage("No documents found in provided URL.", "");
                    return;
                }

                if (argsCopy.containsKey(KEY_INSTANCE)) {
                    Map<String, InstanceConfig> allConfigs = loadInstanceConfig();
                    InstanceConfig newConfig = allConfigs.get(argsCopy.get(KEY_INSTANCE)[0]);
                    if (newConfig != null) {
                        setInstanceConfig(newConfig);
                    }
                }
                // now it is time to load the actual defined instance fonts
                loadInstanceFonts();

                // generate the visualizer
                VisualizerInput visInput = new VisualizerInput();
                visInput.setDocument(doc);
                if (getInstanceConfig() != null && getInstanceConfig().getFont() != null) {
                    visInput.setFont(getInstanceFont());
                }
                Properties mappings = new Properties();
                for (Map.Entry<String, String[]> e : argsCopy.entrySet()) {
                    if (!KEY_SALT.equals(e.getKey()) && e.getValue().length > 0) {
                        mappings.put(e.getKey(), e.getValue()[0]);
                    }
                }
                visInput.setMappings(mappings);
                String[] namespace = argsCopy.get(KEY_NAMESPACE);
                if (namespace != null && namespace.length > 0) {
                    visInput.setNamespace(namespace[0]);
                } else {
                    visInput.setNamespace(null);
                }

                String baseText = null;
                if (argsCopy.containsKey(KEY_BASE_TEXT)) {
                    String[] value = argsCopy.get(KEY_BASE_TEXT);
                    if (value.length > 0) {
                        baseText = value[0];
                    }
                }

                List<SNode> segNodes = CommonHelper.getSortedSegmentationNodes(baseText,
                        doc.getDocumentGraph());

                if (argsCopy.containsKey(KEY_MATCH)) {
                    String[] rawMatch = argsCopy.get(KEY_MATCH);
                    if (rawMatch.length > 0) {
                        // enhance the graph with match information from the arguments
                        Match match = Match.parseFromString(rawMatch[0]);
                        addMatchToDocumentGraph(match, doc);
                    }
                }

                Map<String, String> markedColorMap = new HashMap<>();
                Map<String, String> exactMarkedMap = Helper.calculateColorsForMarkedExact(doc);
                Map<String, Long> markedAndCovered = Helper.calculateMarkedAndCoveredIDs(doc, segNodes,
                        baseText);
                Helper.calulcateColorsForMarkedAndCovered(doc, markedAndCovered, markedColorMap);
                visInput.setMarkedAndCovered(markedAndCovered);
                visInput.setMarkableMap(markedColorMap);
                visInput.setMarkableExactMap(exactMarkedMap);
                visInput.setContextPath(Helper.getContext());
                String template = Helper.getContext() + "/Resource/" + visName + "/%s";
                visInput.setResourcePathTemplate(template);
                visInput.setSegmentationName(baseText);
                // TODO: which other thing do we have to provide?

                Component c = visPlugin.createComponent(visInput, null);
                // add the styles
                c.addStyleName("corpus-font");
                c.addStyleName("vis-content");

                Link link = new Link();
                link.setCaption("Show in ANNIS search interface");
                link.setIcon(ANNISFontIcon.LOGO);
                link.setVisible(false);
                link.addStyleName("dontprint");
                link.setTargetName("_blank");
                if (argsCopy.containsKey(KEY_SEARCH_INTERFACE)) {
                    String[] interfaceLink = argsCopy.get(KEY_SEARCH_INTERFACE);
                    if (interfaceLink.length > 0) {
                        link.setResource(new ExternalResource(interfaceLink[0]));
                        link.setVisible(true);
                    }
                }
                VerticalLayout layout = new VerticalLayout(link, c);
                layout.setComponentAlignment(link, Alignment.TOP_LEFT);
                layout.setSpacing(true);
                layout.setMargin(true);

                setContent(layout);

                IDGenerator.assignID(link);
            }

        });

    } catch (URISyntaxException ex) {
        displayMessage("Invalid URL", "The provided URL is malformed:<br />" + ex.getMessage());
    } catch (LoginDataLostException ex) {
        displayMessage("LoginData Lost",
                "No login data available any longer in the session:<br /> " + ex.getMessage());
    } catch (UniformInterfaceException ex) {
        if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()) {
            displayMessage("Corpus access forbidden",
                    "You are not allowed to access this corpus. "
                            + "Please login at the <a target=\"_blank\" href=\"" + Helper.getContext()
                            + "\">main application</a> first and then reload this page.");
        } else {
            displayMessage("Service error", ex.getMessage());
        }
    } catch (ClientHandlerException ex) {
        displayMessage("Could not generate the visualization because the ANNIS service reported an error.",
                ex.getMessage());
    } catch (Throwable ex) {
        displayMessage("Could not generate the visualization.",
                ex.getMessage() == null
                        ? ("An unknown error of type " + ex.getClass().getSimpleName()) + " occured."
                        : ex.getMessage());
    }
}

From source file:de.catma.ui.CatmaApplication.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    backgroundService = new UIBackgroundService(true);

    storeParameters(request.getParameterMap());

    Page.getCurrent().setTitle("CATMA 5.0 " + MINORVERSION);

    mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();/*  w w  w.  jav  a2  s.  co  m*/

    menuPanel = new Panel();
    menuPanel.addStyleName("menuPanel");
    mainLayout.addComponent(menuPanel);

    contentPanel = new Panel();
    contentPanel.setHeight("100%");
    contentPanel.addStyleName("contentPanel");

    defaultContentPanelLabel = new Label("Please log in to get started");
    defaultContentPanelLabel.addStyleName("defaultContentPanelLabel");
    contentPanel.setContent(defaultContentPanelLabel);

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

    menuLayout = new HorizontalLayout();
    menuLayout.setMargin(true);
    menuLayout.setSpacing(true);

    logoResource = new ThemeResource("catma-logo.png");
    Link logoImage = new Link(null, new ExternalResource("http://www.catma.de"));
    logoImage.setIcon(logoResource);
    logoImage.setTargetName("_blank");
    menuLayout.addComponent(logoImage);

    MenuFactory menuFactory = new MenuFactory();
    try {

        initTempDirectory();
        tagManager = new TagManager();

        repositoryManagerView = new RepositoryManagerView(
                new RepositoryManager(this, tagManager, RepositoryProperties.INSTANCE.getProperties()));

        tagManagerView = new TagManagerView(tagManager);

        taggerManagerView = new TaggerManagerView();

        analyzerManagerView = new AnalyzerManagerView();

        visualizationManagerView = new VisualizationManagerView();

        menu = menuFactory.createMenu(menuLayout, contentPanel,
                new MenuFactory.MenuEntryDefinition("Repository Manager", repositoryManagerView),
                new MenuFactory.MenuEntryDefinition("Tag Type Manager", tagManagerView),
                new MenuFactory.MenuEntryDefinition("Tagger", taggerManagerView),
                new MenuFactory.MenuEntryDefinition("Analyzer", analyzerManagerView),
                new MenuFactory.MenuEntryDefinition("Visualizer", visualizationManagerView));
        addPropertyChangeListener(CatmaApplicationEvent.userChange, menu.userChangeListener);

        Link latestFeaturesLink = new Link("Latest Features",
                new ExternalResource("http://www.catma.de/latestfeatures"));
        latestFeaturesLink.setTargetName("_blank");
        menuLayout.addComponent(latestFeaturesLink);
        menuLayout.setComponentAlignment(latestFeaturesLink, Alignment.TOP_RIGHT);
        menuLayout.setExpandRatio(latestFeaturesLink, 1.0f);

        Link aboutLink = new Link("About", new ExternalResource("http://www.catma.de"));
        aboutLink.setTargetName("_blank");
        menuLayout.addComponent(aboutLink);
        menuLayout.setComponentAlignment(aboutLink, Alignment.TOP_RIGHT);

        Link termsOfUseLink = new Link("Terms of Use", new ExternalResource("http://www.catma.de/termsofuse"));
        termsOfUseLink.setTargetName("_blank");
        menuLayout.addComponent(termsOfUseLink);
        menuLayout.setComponentAlignment(termsOfUseLink, Alignment.TOP_RIGHT);

        Link manualLink = new Link("Manual", new ExternalResource(request.getContextPath() + "/manual/"));
        manualLink.setTargetName("_blank");
        menuLayout.addComponent(manualLink);
        menuLayout.setComponentAlignment(manualLink, Alignment.TOP_RIGHT);

        Link helpLink = new Link("Helpdesk", new ExternalResource("http://www.catma.de/helpdesk/"));
        helpLink.setTargetName("_blank");
        menuLayout.addComponent(helpLink);
        menuLayout.setComponentAlignment(helpLink, Alignment.TOP_RIGHT);
        helpLink.setVisible(false);

        btHelp = new Button(FontAwesome.QUESTION_CIRCLE);
        btHelp.addStyleName("help-button");
        btHelp.addStyleName("application-help-button");

        menuLayout.addComponent(btHelp);

        btHelp.addClickListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {

                if (uiHelpWindow.getParent() == null) {
                    UI.getCurrent().addWindow(uiHelpWindow);
                } else {
                    UI.getCurrent().removeWindow(uiHelpWindow);
                }

            }
        });

        LoginLogoutCommand loginLogoutCommand = new LoginLogoutCommand(menu, repositoryManagerView);
        Button btloginLogout = new Button("Sign in", event -> loginLogoutCommand.menuSelected(null));
        btloginLogout.setStyleName(BaseTheme.BUTTON_LINK);
        btloginLogout.addStyleName("application-loginlink");

        loginLogoutCommand.setLoginLogoutButton(btloginLogout);

        menuLayout.addComponent(btloginLogout);
        menuLayout.setComponentAlignment(btloginLogout, Alignment.TOP_RIGHT);
        menuLayout.setWidth("100%");

        menuPanel.setContent(menuLayout);

        setContent(mainLayout);

        if (getParameter(Parameter.USER_IDENTIFIER) != null) {
            btloginLogout.click();
        }

        setPollInterval(10000);

        if ((getParameter(Parameter.AUTOLOGIN) != null) && (getUser() == null)) {
            getPage().setLocation(repositoryManagerView.createAuthenticationDialog().createLogInClick(this,
                    RepositoryPropertyKey.CATMA_oauthAuthorizationCodeRequestURL.getValue(),
                    RepositoryPropertyKey.CATMA_oauthAccessTokenRequestURL.getValue(),
                    RepositoryPropertyKey.CATMA_oauthClientId.getValue(),
                    RepositoryPropertyKey.CATMA_oauthClientSecret.getValue(), URLEncoder.encode("/", "UTF-8")));
        }

    } catch (Exception e) {
        showAndLogError("The system could not be initialized!", e);
    }

}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultRowEditingFormView.java

License:Apache License

@Override
public void addBlobField(ContainerRow row, TableColumn tableColumn, final ContainerBlob containerBlob,
        boolean readonly) {

    HorizontalLayout blobField = new HorizontalLayout();
    if (tableColumn.getTitle() != null) {
        blobField.setCaption(tableColumn.getTitle());
    } else {/*from   ww w . j a va  2 s  . co  m*/
        blobField.setCaption(tableColumn.getName());
    }

    blobField.setSpacing(true);

    final FileMetadata metadata = tableColumn.getFileMetadata();
    Assert.notNull(metadata, "Missing file metadata for field '" + tableColumn.getName() + "'");

    Link downloadLink = new Link();
    downloadLink.setVisible(false);
    blobField.addComponent(downloadLink);
    blobField.setComponentAlignment(downloadLink, Alignment.MIDDLE_LEFT);

    updateDownloadLink(row, containerBlob, metadata, downloadLink);

    if (!readonly) {
        Upload upload = buildUpload(row, containerBlob, metadata, downloadLink);
        blobField.addComponent(upload);
    }
    fieldLayout.addComponent(blobField);
}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultRowEditingFormView.java

License:Apache License

private void updateDownloadLink(ContainerRow row, final ContainerBlob containerBlob,
        final FileMetadata metadata, Link link) {

    if (!containerBlob.isEmpty()) {
        StreamSource streamSource = containerBlob.getStreamSource();
        String displayName = metadata.getCurrentDisplayname(row);
        String fileName = metadata.getCurrentFilename(row);
        String mimeType = metadata.getCurrentMimetype(row);
        StreamResource resource = new StreamResource(streamSource, fileName);
        resource.setMIMEType(mimeType);//from  w  w  w .j ava  2s .  co m

        link.setVisible(true);
        link.setTargetName("_blank");
        link.setCaption(displayName);
        link.setResource(resource);
    }
}