⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grid.java

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		private final RowRenderer _renderer;		private boolean _rendered, _ctrled;		private Renderer() {			_renderer = getRealRenderer();		}		private void render(Row row) throws Throwable {			if (row.isLoaded())				return; //nothing to do			if (!_rendered && (_renderer instanceof RendererCtrl)) {				((RendererCtrl)_renderer).doTry();				_ctrled = true;			}			final Component cell = row.getFirstChild();			if (!(_renderer instanceof RowRendererExt)			|| (((RowRendererExt)_renderer).getControls() & 				RowRendererExt.DETACH_ON_RENDER) != 0) { //detach (default)				cell.detach();			}			try {				_renderer.render(row, _model.getElementAt(row.getIndex()));			} catch (Throwable ex) {				try {					final Label label = newRenderLabel(Exceptions.getMessage(ex));					label.applyProperties();					label.setParent(row);				} catch (Throwable t) {					log.error(t);				}				row.setLoaded(true);				throw ex;			} finally {				if (row.getChildren().isEmpty())					cell.setParent(row);			}			row.setLoaded(true);			_rendered = true;		}		private void doCatch(Throwable ex) {			if (_ctrled) {				try {					((RendererCtrl)_renderer).doCatch(ex);				} catch (Throwable t) {					throw UiException.Aide.wrap(t);				}			} else {				throw UiException.Aide.wrap(ex);			}		}		private void doFinally() {			if (_ctrled)				((RendererCtrl)_renderer).doFinally();		}	}	/** Renders the specified {@link Row} if not loaded yet,	 * with {@link #getRowRenderer}.	 *	 * <p>It does nothing if {@link #getModel} returns null.	 * In other words, it is meaningful only if live data model is used.	 */	public void renderRow(Row row) {		if (_model == null) return;		final Renderer renderer = new Renderer();		try {			renderer.render(row);		} catch (Throwable ex) {			renderer.doCatch(ex);		} finally {			renderer.doFinally();		}	}	/** Renders all {@link Row} if not loaded yet,	 * with {@link #getRowRenderer}.	 */	public void renderAll() {		if (_model == null) return;		final Renderer renderer = new Renderer();		try {			for (Iterator it = _rows.getChildren().iterator(); it.hasNext();)				renderer.render((Row)it.next());		} catch (Throwable ex) {			renderer.doCatch(ex);		} finally {			renderer.doFinally();		}	}	/** Renders a set of specified rows.	 * It is the same as {@link #renderItems}.	 */	public void renderRows(Set rows) {		renderItems(rows);	}	public void renderItems(Set rows) {		if (_model == null) { //just in case that app dev might change it			if (log.debugable()) log.debug("No model no render");			return;		}		if (rows.isEmpty())			return; //nothing to do		final Renderer renderer = new Renderer();		try {			for (Iterator it = rows.iterator(); it.hasNext();)				renderer.render((Row)it.next());		} catch (Throwable ex) {			renderer.doCatch(ex);		} finally {			renderer.doFinally();		}	}	/** Returns the style class for the odd rows.	 *	 * <p>Default: odd.	 *	 * @since 3.0.0	 */	public String getOddRowSclass() {		return _scOddRow;	}	/** Sets the style class for the odd rows.	 * If the style class doesn't exist, the striping effect disappears.	 * You can provide different effects by providing the proper style	 * classes.	 * @since 3.0.0	 */	public void setOddRowSclass(String scls) {		if (scls != null && scls.length() == 0) scls = null;		if (!Objects.equals(_scOddRow, scls)) {			_scOddRow = scls;			smartUpdate("z.scOddRow", scls);		}	}	//-- super --//	public void setMold(String mold) {		final String old = getMold();		if (!Objects.equals(old, mold)) {			super.setMold(mold);			if ("paging".equals(old)) { //change from paging				if (_paging != null) {					removePagingListener(_paging);					_paging.detach();				} else if (_pgi != null) {					removePagingListener(_pgi);				}			} else if (inPagingMold()) { //change to paging				if (_pgi != null) addPagingListener(_pgi);				else newInternalPaging();			}		}	}	public String getOuterAttrs() {		final StringBuffer sb =			new StringBuffer(80).append(super.getOuterAttrs());		if (_align != null)			HTMLs.appendAttribute(sb, "align", _align);		if (_model != null)			HTMLs.appendAttribute(sb, "z.model", true);		if (_scOddRow != null)			HTMLs.appendAttribute(sb, "z.scOddRow", _scOddRow);		return sb.toString();	}	//-- Component --//	public boolean insertBefore(Component newChild, Component refChild) {		if (newChild instanceof Rows) {			if (_rows != null && _rows != newChild)				throw new UiException("Only one rows child is allowed: "+this+"\nNote: rows is created automatically if live data");			_rows = (Rows)newChild;		} else if (newChild instanceof Columns) {			if (_cols != null && _cols != newChild)				throw new UiException("Only one columns child is allowed: "+this);			_cols = (Columns)newChild;		} else if (newChild instanceof Foot) {			if (_foot != null && _foot != newChild)				throw new UiException("Only one foot child is allowed: "+this);			_foot = (Foot)newChild;		} else if (newChild instanceof Paging) {			if (_pgi != null)				throw new UiException("External paging cannot coexist with child paging");			if (_paging != null && _paging != newChild)				throw new UiException("Only one paging is allowed: "+this);			if (!inPagingMold())				throw new UiException("The child paging is allowed only in the paging mold");			_pgi = _paging = (Paging)newChild;		} else if (!(newChild instanceof Auxhead)) {			throw new UiException("Unsupported child for grid: "+newChild);		} 		if (super.insertBefore(newChild, refChild)) {			//not need to invalidate since auxhead visible only with _cols			if (!(newChild instanceof Auxhead))				invalidate();			return true;		}		return false;	}	public boolean removeChild(Component child) {		if (!super.removeChild(child))			return false;		if (_rows == child) _rows = null;		else if (_cols == child) _cols = null;		else if (_foot == child) _foot = null;		else if (_paging == child) {			_paging = null;			if (_pgi == child) _pgi = null;		}		invalidate();		return true;	}	//Cloneable//	public Object clone() {		final Grid clone = (Grid)super.clone();		clone.init();		int cnt = 0;		if (clone._rows != null) ++cnt;		if (clone._cols != null) ++cnt;		if (clone._foot != null) ++cnt;		if (clone._paging != null) ++cnt;		if (cnt > 0) clone.afterUnmarshal(cnt);		return clone;	}	/** @param cnt # of children that need special handling (used for optimization).	 * -1 means process all of them	 */	private void afterUnmarshal(int cnt) {		for (Iterator it = getChildren().iterator(); it.hasNext();) {			final Object child = it.next();			if (child instanceof Rows) {				_rows = (Rows)child;				if (--cnt == 0) break;			} else if (child instanceof Columns) {				_cols = (Columns)child;				if (--cnt == 0) break;			} else if (child instanceof Foot) {				_foot = (Foot)child;				if (--cnt == 0) break;			} else if (child instanceof Paging) {				_pgi = _paging = (Paging)child;				if (--cnt == 0) break;			}		}	}	//Serializable//	private synchronized void readObject(java.io.ObjectInputStream s)	throws java.io.IOException, ClassNotFoundException {		s.defaultReadObject();		init();		afterUnmarshal(-1);		//TODO: how to marshal _pgi if _pgi != _paging		//TODO: re-register event listener for onPaging		if (_model != null) initDataListener();	}	//-- ComponentCtrl --//	protected Object newExtraCtrl() {		return new ExtraCtrl();	}	/** A utility class to implement {@link #getExtraCtrl}.	 * It is used only by component developers.	 */	protected class ExtraCtrl extends XulElement.ExtraCtrl	implements InnerWidth, RenderOnDemand {		//InnerWidth//		public void setInnerWidthByClient(String width) {			_innerWidth = width == null ? "100%": width;		}		//RenderOnDemand//		public void renderItems(Set items) {			int cnt = items.size();			if (cnt == 0)				return; //nothing to do			cnt = 20 - cnt;			if (cnt > 0 && _preloadsz > 0) { //Feature 1740072: pre-load				if (cnt > _preloadsz) cnt = _preloadsz;				//1. locate the first item found in items				final List toload = new LinkedList();				Iterator it = getRows().getChildren().iterator();				while (it.hasNext()) {					final Row row = (Row)it.next();					if (items.contains(row)) //found						break;					if (!row.isLoaded())						toload.add(0, row); //reverse order				}				//2. add unload items before the found one				if (!toload.isEmpty()) {					int bfcnt = cnt/3;					for (Iterator e = toload.iterator();					bfcnt > 0 && e.hasNext(); --bfcnt, --cnt) {						items.add(e.next());					}				}				//3. add unloaded after the found one				while (cnt > 0 && it.hasNext()) {					final Row row = (Row)it.next();					if (!row.isLoaded() && items.add(row))						--cnt;				}			}			Grid.this.renderItems(items);		}	}	/** An iterator used by _heads.	 */	private class Iter implements Iterator {		private final ListIterator _it = getChildren().listIterator();		public boolean hasNext() {			while (_it.hasNext()) {				Object o = _it.next();				if (o instanceof Columns || o instanceof Auxhead) {					_it.previous();					return true;				}			}			return false;		}		public Object next() {			for (;;) {				Object o = _it.next();				if (o instanceof Columns || o instanceof Auxhead)					return o;			}		}		public void remove() {			throw new UnsupportedOperationException();		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -