List of usage examples for org.apache.wicket.util.string Strings isEmpty
public static boolean isEmpty(final CharSequence string)
string
is considered empty. From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.BaseQuestionPanel.java
License:Open Source License
private static boolean isEmptyString(IModel<String> str) { return str == null || Strings.isEmpty(str.getObject()); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultOpenAnswerDefinitionPanel.java
License:Open Source License
private DataField createAutoCompleteDataField(ValueMap arguments) { final OpenAnswerDefinitionSuggestion suggestion = new OpenAnswerDefinitionSuggestion( getOpenAnswerDefinition());//from w ww .jav a 2s . com final AbstractAutoCompleteDataProvider provider = suggestion .getSuggestionSource() == OpenAnswerDefinitionSuggestion.Source.ITEMS_LIST ? new ItemListDataProvider() : new VariableDataProvider(); final IAutoCompleteDataConverter converter = new IAutoCompleteDataConverter() { private static final long serialVersionUID = 1L; @Override public Data getModelObject(String key) { return DataBuilder.buildText(key); } @Override public String getKey(Data data) { return data.getValueAsString(); } @Override public String getDisplayValue(Data data, String partial) { String key = getKey(data); String label = provider.localizeChoice(key); String display = Strings.escapeMarkup(key, true).toString(); if (Strings.isEmpty(label) == false) { display = display + " : " + Strings.escapeMarkup(label); } return highlightMatches(partial, display); } private String highlightMatches(String partial, String mayContain) { if (mayContain == null) return null; if (Strings.isEmpty(partial)) return mayContain; // The pattern we want is "(tylenol|extra|strength)" StringBuilder pattern = new StringBuilder("("); Joiner.on("|").appendTo(pattern, Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings().split(partial)); pattern.append(")"); Matcher matcher = Pattern.compile(pattern.toString(), Pattern.CASE_INSENSITIVE).matcher(mayContain); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, "<span class='match'>" + Strings.escapeMarkup(matcher.group(0), true) + "</span>"); } matcher.appendTail(sb); return sb.toString(); } }; DataField f = new DataField("open", new PropertyModel<Data>(this, "data"), DataType.TEXT, provider, converter, new AutoCompleteSettings().setAdjustInputWidth(false)); if (suggestion.getNewValueAllowed() == false) { f.add(new AbstractValidator<Data>() { private static final long serialVersionUID = 1L; @Override protected void onValidate(IValidatable<Data> validatable) { Data value = validatable.getValue(); if (value != null && value.getValue() != null && Iterables.contains(provider.getChoices(value.getValueAsString()), value) == false) { error(validatable, "NotASuggestedValue"); } } }); } return f; }
From source file:org.odlabs.wiquery.core.behavior.WiQueryAbstractAjaxBehavior.java
License:Open Source License
/** * <p>/* w w w . ja v a2s .com*/ * Since wicket 6.0 {@link #statement()} is no longer needed, nearly all of WiQuery * core's inner workings have been ported to Wicket 6.0. Use * {@link #renderHead(Component, IHeaderResponse)} to render your statement. * </p> * <p> * For backward compatibility we render the output of this function in an * {@link OnDomReadyHeaderItem} if it is not empty. For your convenience this abstract * class returns null so that nothing is rendered. * <p> */ @Override public void renderHead(Component component, IHeaderResponse response) { super.renderHead(component, response); JsStatement statement = statement(); if (statement != null) { String statementString = statement.render().toString(); if (!Strings.isEmpty(statementString)) { response.render(OnDomReadyHeaderItem.forScript(statementString)); } } }
From source file:org.odlabs.wiquery.core.jqueryplugins.JQueryCookieOption.java
License:Open Source License
/** * Constructeur//from w w w . jav a 2 s . co m * @param name Name of the cookie */ public JQueryCookieOption(String name) { super(); if (Strings.isEmpty(name)) { throw new WicketRuntimeException("name cannot be null or empty"); } options = new Options(); setName(name); }
From source file:org.odlabs.wiquery.ui.autocomplete.AbstractAutocompleteComponent.java
License:Open Source License
@Override public final void convertInput() { String valueId = autocompleteHidden.getConvertedInput(); String input = autocompleteField.getConvertedInput(); final T object = this.getModelObject(); final IChoiceRenderer<? super T> renderer = getChoiceRenderer(); if (NOT_ENTERED.equals(valueId)) valueId = null;// w w w.j av a 2 s .co m if (valueId == null && Strings.isEmpty(input)) { setConvertedInput(null); } else if (valueId == null) { setConvertedInput(getValueOnSearchFail(input)); } else if (object == null || input.compareTo((String) renderer.getDisplayValue(object)) != 0) { final List<? extends T> choices = getChoices(); boolean found = false; for (int index = 0; index < choices.size(); index++) { // Get next choice final T choice = choices.get(index); final String idValue = renderer.getIdValue(choice, index + 1); if (idValue.equals(valueId)) { setConvertedInput(choice); found = true; break; } } if (!found) { // if it is still not entered, then it means this field was not touched // so keep the original value if (valueId.equals(NOT_ENTERED)) { setConvertedInput(getModelObject()); } else { setConvertedInput(getValueOnSearchFail(input)); } } } else { setConvertedInput(object); } }
From source file:org.onexus.ui.api.OnexusWebSession.java
License:Apache License
private boolean authenticatePersona(String username) { if (!Strings.isEmpty(username)) { LoginContext ctx = new LoginContext(username); for (String role : PersonaRoles.getPersonaRoles(username)) { ctx.addRole(role);//from w w w . j a v a 2 s.c o m } LoginContext.set(ctx, getId()); return true; } LoginContext.set(LoginContext.ANONYMOUS_CONTEXT, null); return false; }
From source file:org.onexus.website.api.pages.browser.BrowserPage.java
License:Apache License
@Override protected void onBeforeRender() { VisibleTabs visibleTabs = new VisibleTabs(); // Tabs can change when we fix/unfix entities addOrReplace(new ListView<TabGroup>("tabs", visibleTabs) { @Override//from w w w. j av a 2 s .c o m protected void populateItem(ListItem<TabGroup> item) { TabGroup tabGroup = item.getModelObject(); if (tabGroup.hasSubMenu()) { WebMarkupContainer link = new WebMarkupContainer("link"); link.add(new AttributeModifier("class", "dropdown-toggle")); link.add(new AttributeModifier("data-toggle", "dropdown")); link.add(new AttributeModifier("href", "#")); if (tabGroup.containsTab(getStatus().getCurrentTabId())) { item.add(new AttributeModifier("class", "dropdown active")); TabConfig currentTab = getConfig().getTab(getStatus().getCurrentTabId()); String tabTitle = StringUtils.abbreviate(currentTab.getTitle(), 14); String currentLabel = "<div style=\"position:relative;\"><div style=\"white-space: nowrap; position:absolute; left:13px; top: 13px; font-size: 9px;\"><em>" + tabTitle + "</em></div></div>"; link.add(new Label("label", currentLabel + "<b class='caret'></b> " + tabGroup.getGroupLabel()) .setEscapeModelStrings(false)); } else { item.add(new AttributeModifier("class", "dropdown")); link.add(new Label("label", "<b class='caret'></b> " + tabGroup.getGroupLabel()) .setEscapeModelStrings(false)); } item.add(link); WebMarkupContainer submenu = new WebMarkupContainer("submenu"); submenu.add(new ListView<TabConfig>("item", tabGroup.getTabConfigs()) { @Override protected void populateItem(ListItem<TabConfig> item) { TabConfig tab = item.getModelObject(); BrowserPageLink<String> link = new BrowserPageLink<String>("link", Model.of(tab.getId())) { @Override public void onClick(AjaxRequestTarget target) { getStatus().setCurrentTabId(getModelObject()); sendEvent(EventTabSelected.EVENT); } }; if (!Strings.isEmpty(tab.getHelp())) { item.add(new AttributeModifier("rel", "tooltip")); item.add(new AttributeModifier("data-placement", "right")); item.add(new AttributeModifier("title", tab.getHelp())); } link.add(new Label("label", tab.getTitle())); item.add(link); if (isCurrentTab(tab.getId())) { item.add(new AttributeModifier("class", new Model<String>("active"))); } } }); item.add(submenu); } else { TabConfig tab = tabGroup.getTabConfigs().get(0); BrowserPageLink<String> link = new BrowserPageLink<String>("link", Model.of(tab.getId())) { @Override public void onClick(AjaxRequestTarget target) { getStatus().setCurrentTabId(getModelObject()); sendEvent(EventTabSelected.EVENT); } }; if (!Strings.isEmpty(tab.getHelp())) { link.add(new AttributeModifier("rel", "tooltip")); link.add(new AttributeModifier("title", tab.getHelp())); } link.add(new Label("label", tab.getTitle())); item.add(link); if (isCurrentTab(tab.getId())) { item.add(new AttributeModifier("class", new Model<String>("active"))); } item.add(new WebMarkupContainer("submenu").setVisible(false)); } } }); // Check if the current selected tab is visible. String currentTabId = getStatus().getCurrentTabId(); // Set a current tab if there is no one. if (currentTabId == null) { List<TabConfig> tabs = getConfig().getTabs(); if (tabs != null && !tabs.isEmpty()) { currentTabId = tabs.get(0).getId(); getStatus().setCurrentTabId(currentTabId); // Init currentPage //TODO This is not a good solution PageParameters pageParameters = getPage().getPageParameters(); pageParameters.set(Website.PARAMETER_CURRENT_PAGE, getConfig().getId()); pageParameters.set("ptab", currentTabId); setResponsePage(Website.class, pageParameters); } } List<TabGroup> tabs = visibleTabs.getObject(); boolean hiddenTab = true; for (TabGroup tab : tabs) { if (tab.containsTab(currentTabId)) { hiddenTab = false; } } if (hiddenTab && !tabs.isEmpty()) { TabConfig firstTab = tabs.get(0).getTabConfigs().get(0); getStatus().setCurrentTabId(firstTab.getId()); } List<String> views = new ArrayList<String>(); if (getCurrentTab().getViews() != null) { for (ViewConfig view : getCurrentTab().getViews()) { views.add(view.getTitle()); } } if (getStatus().getCurrentView() == null && views.size() > 0) { getStatus().setCurrentView(views.get(0)); } // Check that the current view is visible List<ViewConfig> filteredViews = new ArrayList<ViewConfig>(); VisiblePredicate predicate = new VisiblePredicate(getStatus().getORI().getParent(), getStatus().getEntitySelections()); CollectionUtils.select(getCurrentTab().getViews(), predicate, filteredViews); boolean visibleView = false; String currentView = getStatus().getCurrentView(); for (ViewConfig view : filteredViews) { if (view.getTitle().equals(currentView)) { visibleView = true; break; } } if (!visibleView) { getStatus().setCurrentView(filteredViews.get(0).getTitle()); } ViewConfig viewConfig = null; if (getCurrentTab().getViews() != null) { for (ViewConfig view : getCurrentTab().getViews()) { if (view.getTitle().equals(getStatus().getCurrentView())) { viewConfig = view; break; } } } if (viewConfig == null) { addOrReplace(new EmptyPanel("content")); } else { if (viewConfig.getLeft() != null && viewConfig.getTop() != null) { addOrReplace(new TopleftLayout("content", viewConfig, getModel())); } else if (viewConfig.getLeft() != null) { addOrReplace(new LeftMainLayout("content", viewConfig, getModel())); } else if (viewConfig.getTop() != null || viewConfig.getTopRight() != null) { addOrReplace(new TopmainLayout("content", viewConfig, getModel())); } else { addOrReplace(new SingleLayout("content", viewConfig, getModel())); } } boolean visible = !isEmbed(); get("selection").setVisible(visible); get("tabs").setVisible(visible); //TODO viewSelector.setVisible(visible && views.size() > 1); super.onBeforeRender(); }
From source file:org.onexus.website.api.pages.browser.layouts.ButtonWidget.java
License:Apache License
public ButtonWidget(String id, final WidgetConfig widgetConfig, final IModel<BrowserPageStatus> pageModel) { super(id);/* w ww. jav a2 s .c o m*/ onEventFireUpdate(EventQueryUpdate.class); this.widgetConfig = widgetConfig; this.pageModel = pageModel; this.widgetModal = new WebMarkupContainer("widgetModal"); widgetModal.setOutputMarkupId(true); widgetModal.add(new EmptyPanel("widget")); widgetModal.add(new AjaxLink<String>("close") { @Override public void onClick(AjaxRequestTarget target) { Component widget = widgetModal.get("widget"); if (widget instanceof Widget) { ((Widget) widget).onClose(target); } target.appendJavaScript("$('#" + widgetModal.getMarkupId() + "').modal('hide')"); } }); if (!Strings.isEmpty(widgetConfig.getWidth())) { int width = Integer.valueOf(widgetConfig.getWidth()); int marginLeft = width / 2; widgetModal.add( new AttributeModifier("style", "width: " + width + "px; margin-left: -" + marginLeft + "px;")); } add(widgetModal); Label button = new Label("button", new PropertyModel<String>(this, "buttonText")); button.setEscapeModelStrings(false); button.setOutputMarkupId(true); if (widgetConfig.getTitle() != null) { button.add(new AttributeModifier("title", widgetConfig.getTitle())); button.add(new AttributeModifier("rel", "tooltip")); widgetModal.add(new Label("modalHeader", widgetConfig.getTitle())); } else { widgetModal.add(new Label("modalHeader", "")); } button.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget target) { Widget<?, ?> widgetPanel = getWidgetManager().create("widget", new WidgetModel(widgetConfig.getId(), pageModel)); widgetModal.addOrReplace(widgetPanel); target.add(widgetModal); target.appendJavaScript("$('#" + widgetModal.getMarkupId() + "').modal('show')"); } }); add(button); }
From source file:org.onexus.website.api.pages.search.boxes.BoxesPanel.java
License:Apache License
public BoxesPanel(String id, SearchPageStatus status, ORI baseUri, FilterConfig filterConfig) { super(id);//from w ww.ja v a 2 s .c o m setMarkupId("boxes"); setOutputMarkupId(true); add(new AttributeModifier("class", "accordion")); RepeatingView boxes = new RepeatingView("boxes"); SearchType type = status.getType(); if (Strings.isEmpty(status.getSearch())) { // Nothing selected add(new EmptyPanel("disambiguation").setVisible(false)); List<SearchLink> links = type.getFixLinks(); if (links != null && !links.isEmpty()) { boxes.add(new MainLinksBox(boxes.newChildId(), links)); } if (type.getFigures() != null) { for (FigureConfig figure : type.getFigures()) { if (!Strings.isEmpty(figure.getVisible()) && "NONE".equalsIgnoreCase(figure.getVisible())) { boxes.add(new FigureBox(boxes.newChildId(), figure, baseUri, null)); } } } } else { ORI collectionUri = type.getCollection().toAbsolute(baseUri); if (filterConfig == null && status.getSearch().indexOf(',') == -1) { // Single entity selection IEntityTable table = getSingleEntityTable(collectionManager, type, collectionUri, baseUri, status.getSearch(), true); boolean found; if (table.next()) { found = true; } else { // If we don't found an exact match, look for a similar one table.close(); table = getSingleEntityTable(collectionManager, type, collectionUri, baseUri, status.getSearch(), false); found = table.next(); } if (found) { IEntity entity = table.getEntity(collectionUri); boxes.add(new LinksBox(boxes.newChildId(), status, entity)); if (type.getFigures() != null) { for (FigureConfig figure : type.getFigures()) { if (Strings.isEmpty(figure.getVisible()) || "SINGLE".equalsIgnoreCase(figure.getVisible())) { boxes.add(new FigureBox(boxes.newChildId(), figure, baseUri, new SingleEntitySelection(entity))); } } } if (table.next()) { add(new DisambiguationPanel("disambiguation", table, collectionUri) { @Override protected void onSelection(AjaxRequestTarget target, String newSearch) { onDisambiguation(target, newSearch); } }); } else { add(new EmptyPanel("disambiguation").setVisible(false)); } } else { add(new EmptyPanel("disambiguation").setVisible(false)); boxes.add(new Label(boxes.newChildId(), "No results found") .add(new AttributeModifier("class", "alert"))); } table.close(); } else { // Multiple entities selection add(new EmptyPanel("disambiguation").setVisible(false)); quickList = false; if (filterConfig == null) { quickList = true; filterConfig = new FilterConfig(status.getSearch()); filterConfig.setCollection(collectionUri); filterConfig.setDefine("fc='" + collectionUri + "'"); String mainKey = type.getKeysList().get(0); In where = new In("fc", mainKey); String[] values = status.getSearch().split(","); for (String value : values) { where.addValue(value.trim()); } filterConfig.setWhere(where.toString()); } IEntityTable table = getMultipleEntityTable(collectionManager, type, collectionUri, baseUri, filterConfig); boxes.add(new LinksBox(boxes.newChildId(), status, collectionUri, filterConfig, new EntityIterator(table, collectionUri)) { @Override protected void onNotFound(Set<String> valuesNotFound) { if (valuesNotFound.isEmpty() || !quickList) { BoxesPanel.this.addOrReplace(new EmptyPanel("disambiguation").setVisible(false)); } else { BoxesPanel.this.addOrReplace(new DisambiguationPanel("disambiguation", valuesNotFound) { @Override protected void onSelection(AjaxRequestTarget target, String newSearch) { onDisambiguation(target, newSearch); } }); } } }); if (type.getFigures() != null) { for (FigureConfig figure : type.getFigures()) { if (Strings.isEmpty(figure.getVisible()) || "LIST".equalsIgnoreCase(figure.getVisible())) { boxes.add(new FigureBox(boxes.newChildId(), figure, baseUri, new MultipleEntitySelection(filterConfig))); } } } } } add(boxes); }
From source file:org.onexus.website.api.pages.search.figures.bar.BarFigurePanel.java
License:Apache License
private String newJavaScript() { StringBuilder code = new StringBuilder(); Query query = createQuery();//from w w w.j av a2s . c o m CollectionField value = config.getValue(); CollectionField xAxis = config.getxAxis(); CollectionField yAxis = config.getyAxis(); IEntityTable table = collectionManager.load(query); List<String> categories = new ArrayList<String>(); Map<String, Map<String, String>> values = new HashMap<String, Map<String, String>>(); while (table.next()) { String xAxisData = String.valueOf(table.getEntity(xAxis.getCollection()).get(xAxis.getField())); String yAxisData = String.valueOf(table.getEntity(yAxis.getCollection()).get(yAxis.getField())); String valueData = String.valueOf(table.getEntity(value.getCollection()).get(value.getField())); if (!categories.contains(xAxisData)) { categories.add(xAxisData); } if (!values.containsKey(yAxisData)) { values.put(yAxisData, new HashMap<String, String>()); } values.get(yAxisData).put(xAxisData, valueData); } table.close(); code.append("$(function () { $('#"); code.append(chart.getMarkupId()); String initUrl = config.getInit(); String init; if (Strings.isEmpty(initUrl)) { init = " chart: {\n" + " type: 'bar'\n" + " },\n" + "\n" + " title: {\n" + " text: null\n" + " },\n" + "\n" + " xAxis: {\n" + " labels: {\n" + " enabled: " + (categories.size() > 30 ? "false" : "true") + "\n" + " }," + " categories: [ ${categories} ]\n" + " },\n" + " yAxis: {\n" + " min: 0,\n" + " title: {\n" + " text: 'mutated samples'\n" + " }\n" + " },\n" + " tooltip: {\n" + " valueDecimals: 0,\n" + " valueSuffix: ' samples'\n" + " },\n" + " plotOptions: {\n" + " series: {\n" + " stacking: 'normal'\n" + " }\n" + " },\n" + " legend: {\n" + " layout: 'vertical',\n" + " align: 'right',\n" + " verticalAlign: 'top',\n" + " x: 0,\n" + " y: 30,\n" + " floating: false,\n" + " borderWidth: 1,\n" + " backgroundColor: '#FFFFFF',\n" + " shadow: true,\n" + " labelFormatter: function() {\n" + " return this.name.length>20 ? this.name.substr(0,19)+'...' : this.name;\n" + " }" + " },\n" + " credits: {\n" + " enabled: false\n" + " },\n" + " series: [ ${series} ] "; } else { IModel<String> initModel = new HtmlDataResourceModel(parentOri, initUrl); init = initModel.getObject(); } // Build categories StringBuilder categoriesText = new StringBuilder(); Iterator<String> categoriesIterator = categories.iterator(); while (categoriesIterator.hasNext()) { categoriesText.append("'").append(categoriesIterator.next()).append("'"); if (categoriesIterator.hasNext()) { categoriesText.append(", "); } } init = init.replace("${categories}", categoriesText.toString()); // Build series StringBuilder seriesText = new StringBuilder(); Iterator<String> seriesIterator = values.keySet().iterator(); while (seriesIterator.hasNext()) { String serieName = seriesIterator.next(); seriesText.append("{ name: '").append(serieName).append("'\n, data: ["); categoriesIterator = categories.iterator(); while (categoriesIterator.hasNext()) { seriesText.append(values.get(serieName).get(categoriesIterator.next())); if (categoriesIterator.hasNext()) { seriesText.append(", "); } } if (seriesIterator.hasNext()) { seriesText.append("] }, \n"); } else { seriesText.append("] }\n"); } } init = init.replace("${series}", seriesText.toString()); code.append("').highcharts({" + init + "});})"); return code.toString(); }