use of com.servoy.j2db.dataprocessing.CustomValueList.DisplayString in project servoy-client by Servoy.
the class LookupValueList method fill.
private void fill(Object display, Object real) throws ServoyException, RemoteException {
if (dontQuery || table == null)
return;
Object value = null;
int values = 0;
if (display != null) {
values = showValues;
value = display;
} else {
values = returnValues;
value = real;
}
QuerySelect select = null;
BaseQueryTable qTable = null;
if (valueList.getDatabaseValuesType() == IValueListConstants.TABLE_VALUES) {
select = DBValueList.createValuelistQuery(application, valueList, table);
if (select != null) {
qTable = select.getTable();
}
} else {
Relation[] relations = application.getFlattenedSolution().getRelationSequence(valueList.getRelationName());
Pair<QuerySelect, BaseQueryTable> pair = RelatedValueList.createRelatedValuelistQuery(application, valueList, relations, parentState);
if (pair != null) {
select = pair.getLeft();
qTable = pair.getRight();
}
}
if (select == null) {
return;
}
String[] displayValues = null;
String separator = valueList.getSeparator();
if (// $NON-NLS-1$
values == showValues && value != null && separator != null && !separator.equals("")) {
if (values != 1 && values != 2 && values != 4) {
// its a combination
displayValues = Utils.stringSplit(value.toString(), separator);
}
}
OrCondition where = new OrCondition();
if ((values & 1) != 0) {
String dp1 = valueList.getDataProviderID1();
if (displayValues != null) {
for (String displayValue : displayValues) {
where.addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, DBValueList.getQuerySelectValue(table, qTable, dp1), getAsRightType(dp1, displayValue)));
}
}
// also just add the complete value, for the possibility that it was a value with a separator.
value = getAsRightType(dp1, value);
where.addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, DBValueList.getQuerySelectValue(table, qTable, dp1), value));
}
if ((values & 2) != 0) {
String dp2 = valueList.getDataProviderID2();
if (displayValues != null) {
for (String displayValue : displayValues) {
where.addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, DBValueList.getQuerySelectValue(table, qTable, dp2), getAsRightType(dp2, displayValue)));
}
}
value = getAsRightType(dp2, value);
where.addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, DBValueList.getQuerySelectValue(table, qTable, dp2), value));
}
if ((values & 4) != 0) {
String dp3 = valueList.getDataProviderID3();
if (displayValues != null) {
for (String displayValue : displayValues) {
where.addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, DBValueList.getQuerySelectValue(table, qTable, dp3), getAsRightType(dp3, displayValue)));
}
}
value = getAsRightType(dp3, value);
where.addCondition(new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, DBValueList.getQuerySelectValue(table, qTable, dp3), value));
}
select.setCondition(SQLGenerator.CONDITION_SEARCH, where);
FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), select);
if (// apply name as filter on column valuelist_name
valueList.getUseTableFilter()) {
if (tableFilterParams == null) {
tableFilterParams = new ArrayList<TableFilter>();
}
tableFilterParams.add(new // $NON-NLS-1$
TableFilter(// $NON-NLS-1$
"lookupValueList.nameFilter", // $NON-NLS-1$
table.getServerName(), // $NON-NLS-1$
table.getName(), // $NON-NLS-1$
table.getSQLName(), DBValueList.NAME_COLUMN, IBaseSQLCondition.EQUALS_OPERATOR, valueList.getName()));
}
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), table.getName(), null, null);
trackingInfo.setTrackingData(select.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, select, null, tableFilterParams, !select.isUnique(), 0, maxValuelistRows, IDataServer.VALUELIST_QUERY, trackingInfo);
String[] displayFormats = getDisplayFormat();
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = CustomValueList.processRow(set.getRow(i), showValues, returnValues);
DisplayString obj = CustomValueList.handleDisplayData(valueList, displayFormats, concatShowValues, showValues, row, application);
if (obj != null) {
alDisplay.add(obj);
alReal.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
}
}
}
use of com.servoy.j2db.dataprocessing.CustomValueList.DisplayString in project servoy-client by Servoy.
the class LookupValueList method fill.
public void fill(IRecordInternal ps) {
if (valueList.getDatabaseValuesType() == IValueListConstants.RELATED_VALUES) {
this.parentState = ps;
if (parentState != null) {
IFoundSetInternal relation = parentState.getRelatedFoundSet(getRelationName());
if (relatedFoundset != relation) {
clear();
if (relation != null && relation.getSize() > 0) {
// try to load what is already in memory
int count = relation.getSize();
// don't trigger an extra load.
if (relation.hadMoreRows())
count--;
// max the number of rows.
if (count > maxValuelistRows) {
count = maxValuelistRows;
}
IRecordInternal[] records = relation.getRecords(0, count);
Object[][] data = new Object[records.length][];
for (int i = 0; i < records.length; i++) {
data[i] = new Object[3];
if (valueList.getDataProviderID1() != null)
data[i][0] = records[i].getValue(valueList.getDataProviderID1());
if (valueList.getDataProviderID2() != null)
data[i][1] = records[i].getValue(valueList.getDataProviderID2());
if (valueList.getDataProviderID3() != null)
data[i][2] = records[i].getValue(valueList.getDataProviderID3());
}
String[] displayFormats = getDisplayFormat();
for (Object[] element : data) {
DisplayString obj = CustomValueList.handleDisplayData(valueList, displayFormats, concatShowValues, showValues, element, application);
if (obj != null) {
alDisplay.add(obj);
alReal.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, element, application));
}
}
}
}
relatedFoundset = relation;
} else
clear();
}
if (secondLookup != null)
secondLookup.fill(ps);
}
use of com.servoy.j2db.dataprocessing.CustomValueList.DisplayString in project servoy-client by Servoy.
the class WebDataLookupField method init.
private void init() {
add(new HeaderContributor(new IHeaderContributor() {
private static final long serialVersionUID = 1L;
public void renderHead(IHeaderResponse response) {
// $NON-NLS-1$
response.renderCSSReference(new CompressedResourceReference(WebDataLookupField.class, "servoy_lookupfield.css"));
}
}) {
@Override
public boolean isEnabled(Component component) {
return !getScriptObject().isReadOnly() && getScriptObject().isEnabled();
}
});
setOutputMarkupPlaceholderTag(true);
AutoCompleteSettings behSettings = new AutoCompleteSettings();
behSettings.setMaxHeightInPx(200);
behSettings.setPreselect(true);
behSettings.setShowCompleteListOnFocusGain(true);
behSettings.setAdjustInputWidth(false);
ClientProperties clp = (application.getApplicationType() != IApplication.HEADLESS_CLIENT ? ((WebClientInfo) Session.get().getClientInfo()).getProperties() : // in case of batch processors/jsp, we can't get browser info because UI is not given by web client components
null);
if (clp != null && (!clp.isBrowserInternetExplorer() || clp.getBrowserVersionMajor() >= 8)) {
// smart positioning doesn't work on IE < 8 (probably because of unreliable clientWidth/clientHeight browser element js properties)
behSettings.setUseSmartPositioning(true);
// don't know if the problem this setting is for can still be reproduced (I couldn't reproduce it)... this is true by default and makes fields in IE and Opera appear/dissapear if they would be covered by type-ahead popup
behSettings.setUseHideShowCoveredIEFix(false);
} else {
behSettings.setUseSmartPositioning(false);
behSettings.setUseHideShowCoveredIEFix(true);
}
behSettings.setThrottleDelay(500);
IAutoCompleteRenderer<Object> renderer = new IAutoCompleteRenderer<Object>() {
protected String getTextValue(Object object) {
// $NON-NLS-1$
String str = "";
if (object instanceof DisplayString) {
str = object.toString();
} else if (object != null && !(object instanceof String)) {
IConverter con = getConverter(object.getClass());
if (con != null) {
str = con.convertToString(object, getLocale());
} else {
str = object.toString();
}
} else if (object != null) {
str = object.toString();
}
// $NON-NLS-1$//$NON-NLS-2$
if (str == null || str.trim().equals(""))
return " ";
return WebBaseButton.sanitize(str, getScriptObject().trustDataAsHtml()).toString();
}
protected void renderChoice(Object object, Response response, String criteria) {
if (IValueList.SEPARATOR_DESIGN_VALUE.equals(object))
return;
String renderedObject = getTextValue(object);
// escape the markup if it is not html or not just an empty none breaking space (null or empty string object)
if (!renderedObject.equals(" ") && !HtmlUtils.hasHtmlTag(renderedObject))
renderedObject = // $NON-NLS-1$
HtmlUtils.escapeMarkup(// $NON-NLS-1$
renderedObject, // $NON-NLS-1$
true, false).toString();
response.write(renderedObject);
}
/*
* (non-Javadoc)
*
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#render(java.lang.Object, org.apache.wicket.Response,
* java.lang.String)
*/
public void render(Object object, Response response, String criteria) {
String textValue = getTextValue(object);
if (textValue == null) {
throw new IllegalStateException("A call to textValue(Object) returned an illegal value: null for object: " + object.toString());
}
textValue = textValue.replaceAll("\\\"", """);
response.write("<li textvalue=\"" + textValue + "\"");
response.write(">");
renderChoice(object, response, criteria);
response.write("</li>");
}
/*
* (non-Javadoc)
*
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#renderHeader(org.apache.wicket.Response)
*/
@SuppressWarnings("nls")
public void renderHeader(Response response) {
StringBuffer listStyle = new StringBuffer();
listStyle.append("style=\"");
String fFamily = "Tahoma, Arial, Helvetica, sans-serif";
String bgColor = "#ffffff";
String fgColor = "#000000";
String fSize = TemplateGenerator.DEFAULT_FONT_SIZE + "px";
String padding = "2px";
String margin = "0px";
if (getFont() != null) {
Font f = getFont();
if (f != null) {
if (f.getFamily() != null) {
fFamily = f.getFamily();
if (fFamily.contains(" "))
fFamily = "'" + fFamily + "'";
}
if (f.getName() != null) {
String fName = f.getName();
if (fName.contains(" "))
fName = "'" + fName + "'";
fFamily = fName + "," + fFamily;
}
if (f.isBold())
listStyle.append("font-weight:bold; ");
if (f.isItalic())
listStyle.append("font-style:italic; ");
fSize = Integer.toString(f.getSize()) + "px";
}
}
if (getListColor() != null && getListColor().getAlpha() == 255) {
// background shouldn't be transparent
bgColor = getWebColor(getListColor().getRGB());
}
if (getForeground() != null) {
fgColor = getWebColor(getForeground().getRGB());
}
Insets _padding = getPadding();
if (getPadding() != null)
padding = _padding.top + "px " + _padding.right + "px " + _padding.bottom + "px " + _padding.left + "px";
listStyle.append("font-family:" + fFamily + "; ");
listStyle.append("background-color: " + bgColor + "; ");
listStyle.append("color: " + fgColor + "; ");
listStyle.append("font-size:" + fSize + "; ");
// extract padding and border
listStyle.append("min-width:" + (getSize().width - 6) + "px; ");
listStyle.append("margin: " + margin + "; ");
listStyle.append("padding: " + padding + "; ");
listStyle.append("text-align:" + TemplateGenerator.getHorizontalAlignValue(getHorizontalAlignment()));
listStyle.append("\"");
response.write("<ul " + listStyle + ">");
}
/*
* (non-Javadoc)
*
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#renderFooter(org.apache.wicket.Response)
*/
public void renderFooter(Response response) {
// $NON-NLS-1$
response.write("</ul>");
}
/**
* Returns web color representation of int rgba color by
* removing the alpha value
*
* @param color int representation of rgba color
* @return web color of form #rrggbb
*/
private String getWebColor(int color) {
String webColor = Integer.toHexString(color);
int startIdx = webColor.length() - 6;
if (startIdx < 0)
startIdx = 0;
webColor = webColor.substring(startIdx);
StringBuilder sb = new StringBuilder();
sb.append('#');
int nrMissing0 = 6 - webColor.length();
for (int i = 0; i < nrMissing0; i++) {
sb.append('0');
}
sb.append(webColor);
return sb.toString();
}
};
AutoCompleteBehavior<Object> beh = new AutoCompleteBehavior<Object>(renderer, behSettings) {
private static final long serialVersionUID = 1L;
/**
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteBehavior#getChoices(java.lang.String)
*/
@Override
protected Iterator<Object> getChoices(String input) {
String filteredInput = filterInput(input);
if (changeListener != null)
dlm.getValueList().removeListDataListener(changeListener);
try {
dlm.fill(parentState, getDataProviderID(), filteredInput, false);
return dlm.iterator();
} catch (Exception ex) {
Debug.error(ex);
} finally {
if (changeListener != null)
dlm.getValueList().addListDataListener(changeListener);
}
return Collections.emptyList().iterator();
}
/**
* filters the input in case of masked input (removes the mask)
*/
private String filterInput(String input) {
String displayFormat = WebDataLookupField.this.parsedFormat.getDisplayFormat();
if (displayFormat != null && displayFormat.length() > 0 && input.length() == displayFormat.length()) {
int index = firstBlankSpacePosition(input, displayFormat);
if (index == -1)
return input;
return input.substring(0, index);
}
return input;
}
/**
* Computes the index of the first space char found in the input and is not ' ' nor '*' in the format
* Example:
* input '12 - 3 - '
* format '## - ## - #'
* returns 6
* @param input
* @param displayFormat
* @return The index of the first space char found in the input and is not ' ' nor '*' in the format
*/
private int firstBlankSpacePosition(String input, String displayFormat) {
for (int i = 0; i < input.length(); i++) {
if ((input.charAt(i) == ' ') && (displayFormat.charAt(i) != ' ') && (displayFormat.charAt(i) != '*'))
return i;
}
return 0;
}
/**
* @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getFailureScript()
*/
@Override
protected CharSequence getFailureScript() {
// $NON-NLS-1$
return "onAjaxError();";
}
/**
* @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getPreconditionScript()
*/
@Override
protected CharSequence getPreconditionScript() {
// $NON-NLS-1$
return "onAjaxCall();" + super.getPreconditionScript();
}
// need to set this behavior to true (enterHidesWithNoSelection) because otherwise the onKeyDown events
// or other events for the component with type ahead would be null in Firefox, and would not execute as
// expected on the other browsers...
@Override
public void renderHead(IHeaderResponse response) {
settings.setShowListOnEmptyInput(Boolean.TRUE.equals(UIUtils.getUIProperty(getScriptObject(), application, IApplication.TYPE_AHEAD_SHOW_POPUP_WHEN_EMPTY, Boolean.TRUE)));
settings.setShowListOnFocusGain(Boolean.TRUE.equals(UIUtils.getUIProperty(getScriptObject(), application, IApplication.TYPE_AHEAD_SHOW_POPUP_ON_FOCUS_GAIN, Boolean.TRUE)));
if (!getScriptObject().isReadOnly() && getScriptObject().isEnabled()) {
super.renderHead(response);
// $NON-NLS-1$ //$NON-NLS-2$
response.renderJavascript("Wicket.AutoCompleteSettings.enterHidesWithNoSelection = true;", "AutocompleteSettingsID");
}
}
/**
* @see org.apache.wicket.behavior.AbstractBehavior#isEnabled(org.apache.wicket.Component)
*/
@Override
public boolean isEnabled(Component component) {
IFormUIInternal<?> formui = findParent(IFormUIInternal.class);
if (formui != null && formui.isDesignMode()) {
return false;
}
return super.isEnabled(component) && WebClientSession.get().useAjax();
}
};
add(beh);
}
use of com.servoy.j2db.dataprocessing.CustomValueList.DisplayString in project servoy-client by Servoy.
the class LookupListModel method filter.
public void filter(String filter) {
String txt = filter.toLowerCase();
int prevSize = alReal.size();
List<Object> tmp = alDisplay;
if (tmp.size() == 0)
tmp = alReal;
for (int i = tmp.size(); --i >= 0; ) {
Object obj = tmp.get(i);
if (obj instanceof DisplayString) {
if (!((DisplayString) obj).startsWith(txt)) {
if (alDisplay.size() > 0)
alDisplay.remove(i);
alReal.remove(i);
}
} else if (!obj.toString().toLowerCase().startsWith(txt)) {
if (alDisplay.size() > 0)
alDisplay.remove(i);
alReal.remove(i);
}
}
fireChanges(prevSize);
}
use of com.servoy.j2db.dataprocessing.CustomValueList.DisplayString in project servoy-client by Servoy.
the class LookupListModel method fillDBValueListValues.
/**
* @param txt
* @throws Exception
* @throws RepositoryException
* @throws RemoteException
*/
private void fillDBValueListValues(String filter) throws ServoyException {
ValueList valueList = ((LookupValueList) lookup).getValueList();
QuerySelect sqlParts = AbstractBaseQuery.deepClone(creationSQLParts);
if (!generateWherePart(filter, valueList, sqlParts, sqlParts.getTable())) {
ArrayList<IQuerySort> sorts = getSortColumnsForQuery(sqlParts);
if (sorts != null)
sqlParts.setSorts(sorts);
}
try {
FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), sqlParts);
if (// apply name as filter on column valuelist_name in creationSQLParts
nameFilter != null) {
if (tableFilterParams == null) {
tableFilterParams = new ArrayList<TableFilter>();
}
tableFilterParams.add(nameFilter);
}
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), table.getName(), null, null);
trackingInfo.setTrackingData(sqlParts.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, sqlParts, null, tableFilterParams, !sqlParts.isUnique(), 0, 100, IDataServer.VALUELIST_QUERY, trackingInfo);
String[] displayFormat = (lookup instanceof LookupValueList) ? ((LookupValueList) lookup).getDisplayFormat() : null;
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = processRow(set.getRow(i));
DisplayString display = CustomValueList.handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application);
if (display != null) {
alDisplay.add(display);
alReal.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
}
}
hadMoreRows = set.hadMoreRows();
} catch (RemoteException e) {
throw new RepositoryException(e);
}
}
Aggregations