📄 tablecontrol.java
字号:
package com.esri.solutions.jitk.web.faces.component;
import java.net.URL;
import javax.faces.component.UICommand;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.faces.component.MapControl;
import com.esri.solutions.jitk.web.data.results.TableModel;
import com.esri.solutions.jitk.web.faces.event.TableEvent;
/**
* The {@link TableControl} provides the functionality to display results in a
* in form of a table.
*
*/
public class TableControl extends UICommand {
/**
* The standard component family for this component.
*/
public static final String COMPONENT_FAMILY = "com.esri.jitk.web.Table";
/**
* The standard component type for this component.
*/
public static final String COMPONENT_TYPE = "com.esri.jitk.web.Table";
/**
* The name of the XSL file used to render this control by default.
*/
public static final String DEFAULT_XSL_FILE_NAME = "jitk-results-tabular.xsl";
private boolean init = false;
private boolean visible = true;
private URL xslUrl;
private String mapId;
private int pageSize;
public TableControl() {
this.setRendererType(COMPONENT_TYPE);
this.addActionListener(new TableControlActionListener());
}
/**
* Set whether this control is to be initialized.
* .
* @param init if true, the control
*/
public void setInit(boolean init) {
this.init = init;
}
/**
* Return an indicator whether this control is initialized.
*
* @return true, if the control is initialized
*/
public boolean isInit() {
return this.init;
}
/**
* Set the visibility of this control.
*
* @param visible if true, this control will be visible
*/
public void setVisible(boolean visible) {
this.visible = visible;
}
/**
* Return whether this controls is visible.
*
* @return true if this control is visible
*/
public boolean isVisible() {
return this.visible;
}
/**
* Sets the URL of the XSL file used to render the control.
* @param xslUrl the URL of the XSL file
*/
public void setXslUrl(URL xslUrl) {
this.xslUrl = xslUrl;
}
/**
* Return the URL of the XSL file used to render the control.
*
* @return {@link URL} the URL object
*/
public URL getXslUrl() {
if (xslUrl != null)
return xslUrl;
ValueBinding vb = getValueBinding("xslUrl");
if (vb != null)
return (URL) vb.getValue(getFacesContext());
else
return (xslUrl);
}
/**
* Returns the map control id associated with the control.
* @return {@link String} - the map control id
*/
public String getMapId() {
return this.mapId;
}
/**
* Sets the control ID. The map control id.
* @param mapId the map control id
*/
public void setMapId(String mapId) {
this.mapId = mapId;
}
/**
* Returns the page size associated with the control.
* @return {@link int} - the number of records in each page
*/
public int getPageSize() {
return this.pageSize;
}
/**
* Sets the page size. The number of records in each page.
* @param pageSize the page size
*/
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
getTableModel().setPageSize(pageSize);
}
/**
* Return the {@link TableModel} object associated with this control.
*
* <p/>
* This is a convenience method for <code>(TableModel)getValue()</code>.
*
* @return the {@link TableModel}
*/
public TableModel getTableModel() {
return (TableModel)getValue();
}
/**
* Set the {@link TableModel} object associated with this control.
*
* <p/>
* This is a convenience method for <code>setValue(Object)</code>.
*
* param tableModel the {@link TableModel}
*/
public void setWebTable(TableModel tableModel) {
setValue(tableModel);
}
/**
* Set the value property of the {@link UICommand}. The value must be a
* {@link TableModel}.
*
* @param value the new value
*
* @throws java.lang.ClassCastException if the specified value is not a
* {@link TableModel}.
*/
@Override
public void setValue(Object value) {
if (value != null && !(value instanceof TableModel)) {
throw new ClassCastException(value.getClass().getName());
}
super.setValue(value);
}
/**
* Returns the family of this control.
* @return {@link String}- the {@link #COMPONENT_FAMILY}
*/
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
/**
* Restore the state of the control.
*
* @param facesContext the associated FacesContext
* @param state the object to restore the state of the control from
*/
@Override
public void restoreState(FacesContext facesContext, Object state) {
Object[] values = (Object[]) state;
super.restoreState(facesContext, values[0]);
init = ((Boolean) values[1]).booleanValue();
visible = ((Boolean) values[2]).booleanValue();
xslUrl = (URL) values[3];
mapId = (String) values[4];
}
/**
* Save the state of this control.
*
* @param facesContext the associated FacesContext
* @return {@link Object} the object to be saved
*/
@Override
public Object saveState(FacesContext facesContext) {
Object[] values = new Object[5];
values[0] = super.saveState(facesContext);
values[1] = init ? Boolean.TRUE : Boolean.FALSE;
values[2] = (visible ? Boolean.TRUE : Boolean.FALSE);
values[3] = xslUrl;
values[4] = mapId;
return values;
}
public TableEvent queueTableEvent(FacesContext facesContext, String key, String action) {
MapControl mapControl = (mapId != null) ? (MapControl) findComponent(mapId) : null;
WebContext webContext = (mapControl != null) ? mapControl.getWebMap().getWebContext() : null;
Object data = null;
if (key != null && action != null) {
if(action.equalsIgnoreCase("sort")) {
data = key.substring(getId().length() + 1);
} else {
data = getTableModel().getRowData(Integer.parseInt(key.substring(getId().length() + 1)));
}
}
TableEvent event = new TableEvent(this, facesContext, webContext, data, action);
queueEvent(event);
return event;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -