Example usage for org.apache.wicket.util.string Strings isEmpty

List of usage examples for org.apache.wicket.util.string Strings isEmpty

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings isEmpty.

Prototype

public static boolean isEmpty(final CharSequence string) 

Source Link

Document

Checks whether the string is considered empty.

Usage

From source file:org.onexus.website.api.widgets.tableviewer.columns.ColumnConfig.java

License:Apache License

@Override
public void addColumns(List<IColumn<IEntityTable, String>> columns, ORI parentURI, boolean sortable) {

    ORI collectionURI = collection.toAbsolute(parentURI);
    Collection collection = getResourceManager().load(Collection.class, collectionURI);

    if (collection != null) {
        List<Field> fields = getFields(collection, parentURI);

        if (Strings.isEmpty(template)) {
            for (Field field : fields) {

                if (length != null) {
                    if (field.getProperty("MAX_LENGTH") != null) {
                        for (Property property : field.getProperties()) {
                            if (property.getKey().equalsIgnoreCase("MAX_LENGTH")) {
                                property.setValue(length.toString());
                                break;
                            }// w w  w .j  a  v  a  2 s .c o m
                        }
                    } else {
                        if (field.getProperties() == null) {
                            field.setProperties(new ArrayList<Property>());
                        }

                        field.getProperties().add(new Property("MAX_LENGTH", length.toString()));
                    }
                }

                IDecorator decoratorImpl = getDecoratorManager().getDecorator(decorator, collection, field);
                List<IDecorator> actionsImpl = createActions(collection, field);

                columns.add(new CollectionColumn(
                        collectionURI, new FieldHeader(label, title, collection, field,
                                new CollectionHeader(collection), filter, sortable),
                        decoratorImpl, actionsImpl));
            }
        } else {
            Field field = fields.get(0);

            IDecorator decoratorImpl = getDecoratorManager().getDecorator(decorator, collection, field);
            List<IDecorator> actionsImpl = createActions(collection, field);
            decoratorImpl.setTemplate(template);

            columns.add(new CollectionColumn(collectionURI, new FieldHeader(label, title, collection, field,
                    new CollectionHeader(collection), filter, sortable), decoratorImpl, actionsImpl));
        }
    }
}

From source file:org.onexus.website.api.widgets.tableviewer.decorators.box.BoxDecorator.java

License:Apache License

private static List<String> getFieldIds(String fields) {

    if (Strings.isEmpty(fields)) {
        return new ArrayList<String>();
    }/* w  ww . j a  v  a  2  s  . co m*/

    String[] fieldsSplit = fields.split(",");
    List<String> fieldIds = new ArrayList<String>(fieldsSplit.length);

    for (String id : fieldsSplit) {
        fieldIds.add(id.trim());
    }

    return fieldIds;
}

From source file:org.onexus.website.api.widgets.tableviewer.decorators.filter.FilterDecorator.java

License:Apache License

@Override
public void populateCell(WebMarkupContainer cellContainer, String componentId, IModel<IEntity> data) {

    Object value = getValue(data.getObject());

    if (value == null) {
        if (Strings.isEmpty(emptyValue)) {
            cellContainer.add(new EmptyPanel(componentId));
        } else {//  ww w . j  a va  2 s . co  m
            cellContainer.add(new Label(componentId, emptyValue));
        }

        return;
    }

    String label = "<i class=\"icon-hand-up\"></i>";
    String tooltip = "Filter results by " + getField().getLabel() + " = " + value;
    LinkPanel linkPanel = new LinkPanel(componentId, label, getLink(collectionId, data, tooltip));
    cellContainer.add(linkPanel);
}

From source file:org.onexus.website.api.widgets.tableviewer.decorators.utils.FieldDecorator.java

License:Apache License

public String getFormatValue(final IEntity entity) {

    if (Strings.isEmpty(template)) {
        return getFormatValue(entity, field.getId());
    }/*from  w  w w . ja  v a  2 s. c o m*/

    if (getValue(entity) == null) {
        return "";
    }

    return replaceParameters(entity, template);

}

From source file:org.onexus.website.api.widgets.tableviewer.decorators.utils.FieldDecorator.java

License:Apache License

protected String fixLinkUrl(String url) {

    if (Strings.isEmpty(url) || url.contains("://")) {
        return url;
    }/*from w w w.  jav  a2  s.  c o m*/

    List<String> segments = RequestCycle.get().getRequest().getUrl().getSegments();
    String lastSegment = segments.get(segments.size() - 1);

    if (segments.size() == 2) {
        url = lastSegment + '/' + url;
    }

    return url;
}

From source file:org.onexus.website.api.widgets.tableviewer.headers.FieldHeader.java

License:Apache License

public boolean isFilterable() {
    return !Strings.isEmpty(filter);
}

From source file:org.onexus.website.api.widgets.tableviewer.TableViewer.java

License:Apache License

public TableViewer(String componentId, IModel<TableViewerStatus> status) {
    super(componentId, status);

    onEventFireUpdate(EventQueryUpdate.class, EventAddFilter.class, EventRemoveFilter.class);

    if (status.getObject() == null) {
        status.setObject(getStatus());/*  w  ww . j a  va 2 s.c  om*/
    }

    Integer sessionRowsPerPage = getSession().getMetaData(DEFAULT_ROWS_PER_PAGE);
    final Integer rowsPerPage = sessionRowsPerPage == null ? 20 : sessionRowsPerPage;

    this.dataProvider = new EntitiesRowProvider(status, rowsPerPage) {

        @Override
        protected Query getQuery() {
            return TableViewer.this.getQuery();
        }

        @Override
        protected void addTaskStatus(Progress progressStatus) {
            //TODO
        }

    };

    // Create the columns from the config
    int ccs = getStatus().getCurrentColumnSet();
    List<IColumnConfig> columnsConfig = getConfig().getColumnSets().get(ccs).getColumns();
    final List<IColumn<IEntityTable, String>> columns = new ArrayList<IColumn<IEntityTable, String>>();

    ORI parentURI = getQuery().getOn();

    List<IColumnConfig> visibleColumnsConfig = new ArrayList<IColumnConfig>(columnsConfig.size());
    BrowserPageStatus pageStatus = findParentStatus(BrowserPageStatus.class);

    Predicate sortablePredicate;
    if (pageStatus != null) {
        sortablePredicate = new VisiblePredicate(getPageBaseOri(), pageStatus.getEntitySelections());
        Predicate filter = new VisiblePredicate(getPageBaseOri(), pageStatus.getEntitySelections());
        CollectionUtils.select(columnsConfig, filter, visibleColumnsConfig);
    } else {
        sortablePredicate = new VisiblePredicate(getPageBaseOri(), Collections.EMPTY_LIST);
        visibleColumnsConfig = columnsConfig;
    }

    boolean tableSort = sortablePredicate.evaluate(getConfig().getSortable());
    for (IColumnConfig columnConfig : visibleColumnsConfig) {
        String columnSortStr = columnConfig.getSortable();
        boolean columnSort = sortablePredicate.evaluate(columnSortStr);
        columnConfig.addColumns(columns, parentURI, Strings.isEmpty(columnSortStr) ? tableSort : columnSort);
    }

    // Disable default status order if the table is not sortable.
    if (!tableSort) {
        getStatus().setOrder(null);
    }

    add(new OnDomReadyPanel("datatable") {
        @Override
        protected Panel onDomReadyPanel(String componentId) {

            Boolean forceCount = getConfig().getForceCount();
            if (forceCount != null && forceCount.booleanValue()) {
                dataProvider.forceCount();
            }

            return new DataTablePanel("datatable", columns, dataProvider, rowsPerPage);
        }
    });

}

From source file:org.opensingular.form.wicket.behavior.ConfigureByMInstanciaAttributesBehavior.java

License:Apache License

protected static String appendAtributeValue(String currentValue, String appendValue, String separator) {
    // Short circuit when one of the values is empty: return the other value.
    if (Strings.isEmpty(currentValue))
        return appendValue != null ? appendValue : null;
    else if (Strings.isEmpty(appendValue))
        return currentValue != null ? currentValue : null;

    StringBuilder sb = new StringBuilder(currentValue);
    sb.append(separator);/*  w ww.  j a  v a2  s . com*/
    sb.append(appendValue);
    return sb.toString();
}

From source file:org.opensingular.lib.wicket.util.application.HttpsOnlyUrlRenderer.java

License:Apache License

@SuppressWarnings("deprecation")
public String renderFullUrl(final Url url) {
    if (url instanceof IUrlRenderer) {
        IUrlRenderer renderer = (IUrlRenderer) url;
        return renderer.renderFullUrl(url, getBaseUrl());
    }/* w  ww  . j  a va  2  s  .  co m*/

    final String protocol = "https";
    final String host = resolveHost(url);

    final String path;
    if (url.isContextAbsolute()) {
        path = url.toString();
    } else {
        Url base = new Url(getBaseUrl());
        base.resolveRelative(url);
        path = base.toString();
    }

    StringBuilder render = new StringBuilder();
    if (!Strings.isEmpty(protocol)) {
        render.append(protocol);
        render.append(':');
    }

    if (!Strings.isEmpty(host)) {
        render.append("//");
        render.append(host);
    }

    if (!url.isContextAbsolute()) {
        render.append(request.getContextPath());
        render.append(request.getFilterPath());
    }
    return Strings.join("/", render.toString(), path);
}

From source file:org.projectforge.web.wicket.autocompletion.PFAutoCompleteBehavior.java

License:Open Source License

/**
 * Render autocomplete init javascript and other head contributions
 * //  w w  w.j av a  2 s  .  co  m
 * @param response
 */
private void renderAutocompleteHead(final IHeaderResponse response) {
    final String id = getComponent().getMarkupId();
    String indicatorId = findIndicatorId();
    if (Strings.isEmpty(indicatorId)) {
        indicatorId = "null";
    } else {
        indicatorId = "'" + indicatorId + "'";
    }
    final StringBuffer buf = new StringBuffer();
    buf.append("var favorite" + id + " = ");
    final List<T> favorites = getFavorites();
    final MyJsonBuilder builder = new MyJsonBuilder();
    if (favorites != null) {
        buf.append(builder.append(favorites, false).getAsString());
    } else {
        buf.append(builder.append(getRecentUserInputs()).getAsString());
    }
    buf.append(";").append("var z = $(\"#").append(id).append("\");\n").append("z.autocomplete(\"")
            .append(getCallbackUrl()).append("\",{");
    boolean first = true;
    for (final String setting : getSettingsJS()) {
        if (first == true)
            first = false;
        else
            buf.append(", ");
        buf.append(setting);
    }
    if (first == true)
        first = false;
    else
        buf.append(", ");
    buf.append("favoriteEntries:favorite" + id);
    buf.append("});");
    if (settings.isHasFocus() == true) {
        buf.append("\nz.focus();");
    }
    final String initJS = buf.toString();
    // String initJS = String.format("new Wicket.AutoComplete('%s','%s',%s,%s);", id, getCallbackUrl(), constructSettingsJS(), indicatorId);
    response.render(OnDomReadyHeaderItem.forScript(initJS));
}