Search in sources :

Example 21 with Link

use of com.vaadin.ui.Link in project ANNIS by korpling.

the class EmbeddedVisUI method generateVisFromRemoteURL.

private void generateVisFromRemoteURL(final String visName, final String rawUri, Map<String, String[]> args) {
    try {
        // 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]);
                        Helper.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());
    }
}
Also used : VisualizerPlugin(annis.libgui.visualizers.VisualizerPlugin) WebResource(com.sun.jersey.api.client.WebResource) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) Match(annis.service.objects.Match) InstanceConfig(annis.libgui.InstanceConfig) VerticalLayout(com.vaadin.ui.VerticalLayout) List(java.util.List) LinkedList(java.util.LinkedList) Client(com.sun.jersey.api.client.Client) Component(com.vaadin.ui.Component) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) SDocument(org.corpus_tools.salt.common.SDocument) SaltProject(org.corpus_tools.salt.common.SaltProject) ExternalResource(com.vaadin.server.ExternalResource) AnnisUser(annis.libgui.AnnisUser) URISyntaxException(java.net.URISyntaxException) LoginDataLostException(annis.libgui.LoginDataLostException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) VisualizerInput(annis.libgui.visualizers.VisualizerInput) LoginDataLostException(annis.libgui.LoginDataLostException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Link(com.vaadin.ui.Link)

Example 22 with Link

use of com.vaadin.ui.Link in project VaadinUtils by rlsutton1.

the class ContainerCSVExport method writeRow.

private void writeRow(CSVWriter writer, Table table, Object id, Set<Object> properties) {
    Item item = table.getItem(id);
    String[] values = new String[properties.size() + extraColumnHeadersAndPropertyIds.size()];
    int i = 0;
    for (Object propertyId : properties) {
        @SuppressWarnings("rawtypes") final Property itemProperty = item.getItemProperty(propertyId);
        if (itemProperty != null && itemProperty.getValue() != null) {
            ColumnGenerator generator = table.getColumnGenerator(propertyId);
            if (generator != null && itemProperty.getType() != Boolean.class) {
                Object value = generator.generateCell(table, id, propertyId);
                if (value instanceof Label) {
                    value = new HtmlToPlainText().getPlainText(Jsoup.parse(((Label) value).getValue()));
                }
                if (value instanceof AbstractLayout) {
                    value = new HtmlToPlainText().getPlainText(Jsoup.parse(itemProperty.getValue().toString()));
                }
                if (value instanceof Link) {
                    value = new HtmlToPlainText().getPlainText(Jsoup.parse(itemProperty.getValue().toString()));
                }
                if (value != null) {
                    values[i++] = value.toString();
                }
            } else {
                values[i++] = itemProperty.getValue().toString();
            }
        } else {
            ColumnGenerator generator = table.getColumnGenerator(propertyId);
            if (generator != null) {
                Object value = generator.generateCell(table, id, propertyId);
                if (value != null) {
                    if (value instanceof ClickableLabel) {
                        value = new HtmlToPlainText().getPlainText(Jsoup.parse(((ClickableLabel) value).getValue()));
                    }
                    if (value instanceof Label) {
                        value = new HtmlToPlainText().getPlainText(Jsoup.parse(((Label) value).getValue()));
                    // value = ((Label) value).getValue();
                    }
                    if (value instanceof AbstractLayout) {
                        // set a string using setData() on the layout.
                        if (((AbstractLayout) value).getData() instanceof ContainerCSVExportData) {
                            value = ((AbstractLayout) value).getData().toString();
                        } else {
                            value = "";
                        }
                    }
                    if (value instanceof Link) {
                        value = new HtmlToPlainText().getPlainText(Jsoup.parse(((Link) value).getCaption()));
                    }
                }
                if (value == null) {
                    value = "";
                }
                values[i++] = value.toString();
            } else {
                values[i++] = "";
            }
        }
    }
    for (Object columnId : extraColumnHeadersAndPropertyIds.values()) {
        String value = getValueForExtraColumn(item, columnId);
        if (value == null) {
            value = "";
        }
        values[i++] = value;
    }
    writer.writeNext(values);
}
Also used : HtmlToPlainText(org.jsoup.examples.HtmlToPlainText) ClickableLabel(au.com.vaadinutils.fields.ClickableLabel) Label(com.vaadin.ui.Label) Item(com.vaadin.data.Item) ColumnGenerator(com.vaadin.ui.Table.ColumnGenerator) ClickableLabel(au.com.vaadinutils.fields.ClickableLabel) AbstractLayout(com.vaadin.ui.AbstractLayout) Property(com.vaadin.data.Property) Link(com.vaadin.ui.Link)

Example 23 with Link

use of com.vaadin.ui.Link in project cia by Hack23.

the class AbstractView method createTopHeaderActionsForUserContext.

/**
 * Creates the top header actions for user context.
 */
private void createTopHeaderActionsForUserContext() {
    if (UserContextUtil.allowRoleInSecurityContext(ROLE_ADMIN) || UserContextUtil.allowRoleInSecurityContext(ROLE_USER)) {
        final Link userHomePageLink = pageLinkFactory.createUserHomeViewPageLink();
        topHeaderRightPanel.addComponent(userHomePageLink);
        topHeaderRightPanel.setComponentAlignment(userHomePageLink, Alignment.MIDDLE_RIGHT);
        final Button logoutButton = new Button(LOGOUT, VaadinIcons.SIGN_OUT);
        final LogoutRequest logoutRequest = new LogoutRequest();
        logoutRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
        logoutButton.addClickListener(new LogoutClickListener(logoutRequest));
        topHeaderRightPanel.addComponent(logoutButton);
        topHeaderRightPanel.setComponentAlignment(logoutButton, Alignment.MIDDLE_RIGHT);
    } else {
        final Link createRegisterPageLink = pageLinkFactory.createRegisterPageLink();
        topHeaderRightPanel.addComponent(createRegisterPageLink);
        topHeaderRightPanel.setComponentAlignment(createRegisterPageLink, Alignment.MIDDLE_RIGHT);
        final Link createLoginPageLink = pageLinkFactory.createLoginPageLink();
        topHeaderRightPanel.addComponent(createLoginPageLink);
        topHeaderRightPanel.setComponentAlignment(createLoginPageLink, Alignment.MIDDLE_RIGHT);
    }
}
Also used : LogoutClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.LogoutClickListener) Button(com.vaadin.ui.Button) LogoutRequest(com.hack23.cia.service.api.action.application.LogoutRequest) Link(com.vaadin.ui.Link)

Example 24 with Link

use of com.vaadin.ui.Link in project cia by Hack23.

the class PageLinkFactoryImpl method addPartyPageLink.

@Override
public Link addPartyPageLink(final ViewRiksdagenParty data) {
    final Link pageLink = new Link(PARTY + data.getPartyName(), new ExternalResource(PAGE_PREFIX + UserViews.PARTY_VIEW_NAME + PAGE_SEPARATOR + data.getPartyId()));
    pageLink.setId(ViewAction.VISIT_PARTY_VIEW.name() + PAGE_SEPARATOR + data.getPartyId());
    pageLink.setIcon(VaadinIcons.GROUP);
    return pageLink;
}
Also used : ExternalResource(com.vaadin.server.ExternalResource) Link(com.vaadin.ui.Link)

Example 25 with Link

use of com.vaadin.ui.Link in project cia by Hack23.

the class PageLinkFactoryImpl method createAdminPagingLink.

@Override
public Link createAdminPagingLink(final String label, final String page, final String pageId, final String pageNr) {
    final Link pageLink = new Link(label, new ExternalResource(PAGE_PREFIX + page + PAGE_SEPARATOR + "[" + pageNr + "]"));
    pageLink.setId(page + "ShowPage" + PAGE_SEPARATOR + pageNr);
    pageLink.setIcon(VaadinIcons.SERVER);
    return pageLink;
}
Also used : ExternalResource(com.vaadin.server.ExternalResource) Link(com.vaadin.ui.Link)

Aggregations

Link (com.vaadin.ui.Link)36 ExternalResource (com.vaadin.server.ExternalResource)24 VerticalLayout (com.vaadin.ui.VerticalLayout)21 Label (com.vaadin.ui.Label)18 HorizontalLayout (com.vaadin.ui.HorizontalLayout)8 PostConstruct (javax.annotation.PostConstruct)7 ExternalResource (com.vaadin.terminal.ExternalResource)5 Button (com.vaadin.ui.Button)4 StreamResource (com.vaadin.terminal.StreamResource)3 TextField (com.vaadin.ui.TextField)3 ComboBox (com.vaadin.ui.ComboBox)2 Embedded (com.vaadin.ui.Embedded)2 GridLayout (com.vaadin.ui.GridLayout)2 HashMap (java.util.HashMap)2 Secured (org.springframework.security.access.annotation.Secured)2 AnnisUser (annis.libgui.AnnisUser)1 InstanceConfig (annis.libgui.InstanceConfig)1 LoginDataLostException (annis.libgui.LoginDataLostException)1 VisualizerInput (annis.libgui.visualizers.VisualizerInput)1 VisualizerPlugin (annis.libgui.visualizers.VisualizerPlugin)1