📄 uisearchfield.java
字号:
/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.ui;
//import com.sourcetap.sfa.ui.UIDisplayObject;
//import com.sourcetap.sfa.ui.UIFieldInfo;
import com.sourcetap.sfa.util.UserInfo;
import org.ofbiz.entity.*;
import org.ofbiz.entity.model.*;
import org.ofbiz.base.util.Debug;
import java.util.*;
/**
* This class is used by the UI builder to display a search field on the screen.
*
* @author <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*/
public class UISearchField {
public static final String module = UISearchField.class.getName();
/**
* Dynamically retrieves values to display as a drop down list when the search field is in list mode.
*
* @author <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param delegator Reference to the OFBIZ delegator being used to connect to the data base
* @param entityName The name of the entity whose instances are to be displayed in the list.
* @param searchField Name of attribute in the listed entity to be compared to the searchValue
* @param searchValue Value entered by the user into the search field. To be used in a LIKE clause to filter the items in the drop down.
* @param userInfo Reference to user info object containing information about the currently logged-in user
*
* @return String containing the HTML text that will draw the current field on the web page
*
* @see com.sourcetap.sfa.ui.UIWebScreenSection
*/
public List getSearchFieldValuesDynamic(GenericDelegator delegator,
String entityName, String searchField, String searchValue,
UserInfo userInfo) {
return new LinkedList();
}
/**
* Produces an HTML string to display the search field in search mode.
*
* @author Chris Maurer
* @author <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param htmlName The name to be used for the current field in the HTML
* @param action Action string defining the current screen mode. See UIScreenSection for possible values.
* @param fieldInfo Reference to field info object containing attributes of the current field
* @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
* @param fieldValue Value stored or to be stored in the data base
* @param tabIndex Tab index (tab order) of the current field on the HTML form
*
* @return String containing the HTML text that will draw the current field on the web page
*
* @see com.sourcetap.sfa.ui.UIWebScreenSection
*/
public static String displaySearchValueBox(String htmlName, String action,
UIFieldInfo fieldInfo, UIDisplayObject uiDisplayObject,
String fieldValue, int tabIndex) {
// Display an input box where the user can type search criteria.
StringBuffer displayHtml = new StringBuffer();
displayHtml.append("<INPUT TYPE=\"TEXT\" ID=\"" + htmlName +
"\" NAME=\"" + htmlName + "\" TABINDEX=\"" +
String.valueOf(tabIndex) + "\" ");
displayHtml.append(UIWebUtility.translateAttribSize(
uiDisplayObject.getAttribSize()));
displayHtml.append(UIWebUtility.translateAttribMaxLength(
uiDisplayObject.getAttribMaxLength(),
String.valueOf(fieldInfo.getMaxLength())));
displayHtml.append(UIWebUtility.translateAttribDisabled(
uiDisplayObject.getAttribDisabled()));
displayHtml.append(UIWebUtility.translateAttribReadOnly(
uiDisplayObject.getAttribReadOnly()));
displayHtml.append(UIWebUtility.translateAttribAlign(
uiDisplayObject.getAttribAlign()));
displayHtml.append(UIWebUtility.translateAttribClass(
uiDisplayObject.getAttribClass(action,
fieldInfo.getIsMandatory())));
displayHtml.append(UIWebUtility.translateAttribFieldName(
uiDisplayObject.getAttribEntitySearchDef()));
displayHtml.append(UIWebUtility.translateAttribEntityName(
uiDisplayObject.getAttribEntity()));
displayHtml.append(UIWebUtility.translateAttribIdName(
uiDisplayObject.getAttribEntityValueDef()));
displayHtml.append(UIWebUtility.translateAttribFindClass(
uiDisplayObject.getAttribEntityFindMethod()));
displayHtml.append(" VALUE='" + fieldValue + "'>");
return displayHtml.toString();
}
/**
* Produces an HTML string to display the search field on a web page being built by the UIWebScreenSection class.
* If the screen is being displayed in read-only mode, this method looks up the specified name value using the
* current value as the primary key, and displays the looked up name instead of a search field.
*
* @author Chris Maurer
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
* @param protect Defines wether to show the current field in protected (read-only)_ mode
* @param htmlName The name to be used for the current field in the HTML
* @param fieldValue Value stored or to be stored in the data base
* @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
* @param fieldInfo Reference to field info object containing attributes of the current field
* @param action Action string defining the current screen mode. See UIScreenSection for possible values.
* @param tabIndex Tab index (tab order) of the current field on the HTML form
* @param protect Boolean value defining whether to show the current field in protected (read-only)_ mode
* @param userInfo Reference to user info object containing information about the currently logged-in user
* @param delegator Reference to the OFBIZ delegator being used to connect to the data base
*
* @return String containing the HTML text that will draw the current field on the web page
*
* @see com.sourcetap.sfa.ui.UIWebScreenSection
*/
public String displayFieldHtml(UIDisplayObject uiDisplayObject,
boolean protect, String htmlName, String fieldValue,
Vector entityDetailsVector, UIFieldInfo fieldInfo, String action,
int tabIndex, UserInfo userInfo, GenericDelegator delegator) {
StringBuffer displayHtml = new StringBuffer();
if (!protect) {
// Not protected. Need to display in edit mode.
// Use a <P> element as a placeholder(?)
displayHtml.append("<P ID=\"" + htmlName + "Holder\" NAME=\"" +
htmlName + "Holder\" >\n");
if ((fieldValue != null) &&
(String.valueOf(fieldValue).trim().length() > 0)) {
// Field has a value already. Build an HTML SELECT that includes 2 entries: The one already
// in the field, and the "search again" value.
HashMap findMap = UIWebUtility.decodeEntityFindDef(uiDisplayObject.getAttribEntityPkFindDef(),
entityDetailsVector,
fieldInfo.getUiAttribute().getAttributeName());
ModelEntity entityEntity = delegator.getModelEntity(uiDisplayObject.getAttribEntity());
GenericPK entityPk = new GenericPK(entityEntity, findMap);
//GenericValue entityGenericValue = delegator.findByPrimaryKeyCache(entityPk);
GenericValue optGV = null;
try {
optGV = delegator.findByPrimaryKeyCache(entityPk);
} catch (GenericEntityException e) {
displayHtml.append(UIWebUtility.displayFieldReadOnly(
uiDisplayObject, htmlName, fieldValue, fieldValue,
entityDetailsVector));
Debug.logError(
"[UISearchField.displayFieldHtml] Error searching for the single value to put in the drop down for the serach field: " +
e.getLocalizedMessage(), module);
return displayHtml.toString();
}
if (uiDisplayObject.getAttribEntity().equals("")) {
displayHtml.append(UIWebUtility.displayFieldReadOnly(
uiDisplayObject, htmlName, fieldValue, fieldValue,
entityDetailsVector));
Debug.logError(
"[UISearchField.displayFieldHtml] Entity name is required for SEARCH_TEXT display type.", module);
return displayHtml.toString();
}
if (optGV != null) {
displayHtml.append("<SELECT ID=\"" + htmlName +
"\" NAME=\"" + htmlName + "\" TABINDEX=\"" +
String.valueOf(tabIndex) + "\" ");
displayHtml.append(UIWebUtility.translateAttribSize(
uiDisplayObject.getAttribSize()));
displayHtml.append(UIWebUtility.translateAttribDisabled(
uiDisplayObject.getAttribDisabled()));
displayHtml.append(UIWebUtility.translateAttribClass(
uiDisplayObject.getAttribClass(action,
fieldInfo.getIsMandatory())));
displayHtml.append(UIWebUtility.translateAttribFieldName(
uiDisplayObject.getAttribEntitySearchDef()));
displayHtml.append(UIWebUtility.translateAttribEntityName(
uiDisplayObject.getAttribEntity()));
displayHtml.append(UIWebUtility.translateAttribIdName(
uiDisplayObject.getAttribEntityValueDef()));
displayHtml.append(UIWebUtility.translateAttribFindClass(
uiDisplayObject.getAttribEntityFindMethod()));
displayHtml.append(">\n");
String optionValue = String.valueOf(optGV.get(
uiDisplayObject.getAttribEntityValueDef()));
Vector optGVVector = new Vector();
optGVVector.add(optGV);
String optionDisplay = UIUtility.decodeEntityDisplayDef(uiDisplayObject.getAttribEntityDisplayDef(),
optGVVector,
UIWebUtility.getAttribFromParamName(htmlName));
displayHtml.append("<OPTION VALUE=\"" + optionValue + "\"");
if (optionValue.equals(fieldValue)) {
displayHtml.append(" SELECTED");
}
displayHtml.append(">" + optionDisplay + "</OPTION>\n");
displayHtml.append(
"<OPTION VALUE=\"search again\">Search again...</OPTION>\n");
displayHtml.append("</SELECT>");
} else {
// Entity was not found in the data base. Display the search box so the user can pick a new one.
displayHtml.append(displaySearchValueBox(htmlName, action,
fieldInfo, uiDisplayObject, fieldValue, tabIndex));
}
} else {
// Field value is still blank. Display an input box where the user can type search criteria.
displayHtml.append(displaySearchValueBox(htmlName, action,
fieldInfo, uiDisplayObject, fieldValue, tabIndex));
}
if (fieldInfo.getIsMandatory() &&
!action.equals(UIScreenSection.ACTION_SHOW_QUERY) &&
!action.equals(UIScreenSection.ACTION_SHOW_QUERY_REPORT) &&
!action.equals(UIScreenSection.ACTION_SHOW_REPORT)) {
displayHtml.append("*\n");
}
displayHtml.append("</p>");
displayHtml.append("<SCRIPT FOR=\"" + htmlName +
"\" EVENT=\"onblur()\" LANGUAGE=\"JavaScript\" >sendData(this, this.form, '" +
action + "');</script>\n");
displayHtml.append("<SCRIPT FOR=\"" + htmlName +
"\" EVENT=\"onchange()\" LANGUAGE=\"JavaScript\" >searchAgain(this, this.form);</script>\n");
return displayHtml.toString();
} else {
// User can't edit right now, so there's no point in showing the list. Just look up the
// the display value and show it.
GenericValue linkGenericValue = UIUtility.getReadOnlyValue(fieldValue,
fieldInfo.getUiAttribute().getAttributeName(),
uiDisplayObject, entityDetailsVector, delegator);
displayHtml.append(UIDropDown.getSelectHtmlReadOnly(fieldValue,
htmlName, fieldInfo.getUiAttribute().getAttributeName(),
uiDisplayObject,
UIDropDown.decodeValue(
uiDisplayObject.getAttribEntityValueDef(),
uiDisplayObject.getAttribEntityDisplayDef(),
UIWebUtility.getAttribFromParamName(htmlName),
linkGenericValue),
UIWebUtility.translateAttribAnchorHrefDef(
uiDisplayObject.getAttribAnchorHrefDef(),
entityDetailsVector,
UIWebUtility.getAttribFromParamName(htmlName)),
UIWebUtility.translateAttribAnchorTarget(
uiDisplayObject.getAttribAnchorTarget()), delegator));
return displayHtml.toString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -