widget.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 653 行 · 第 1/2 页
JAVA
653 行
} /** * If a preference "pref" is not found as a preference * specifically set for this widget, the prefix is prepended * and the connection preferences are checked; the default is "<i>id.</i>", * for example connection.getPreferenceValue("<i>id.</i>pref"). */ public void setPreferencePrefix( String preferencePrefix ) { _preferencePrefix = preferencePrefix; } /** * Return a preference value. */ public String getPreferenceValue( WidgetConnection connection, String key ) { String[] values = getPreferenceValues( connection, key ); if ( values == null ) return null; else if ( values.length == 0 ) return ""; else return values[0]; } /** * Return preference values. */ public String[] getPreferenceValues( WidgetConnection connection, String key ) { WidgetPreference widgetPreference = getWidgetPreference( key ); boolean isReadOnly = widgetPreference != null && !widgetPreference.isReadOnly(); String[] values = null; if ( widgetPreference != null ) values = widgetPreference.getValues(); if ( !isReadOnly ) { key = key + _preferencePrefix; values = connection.getPreferenceValues( key, values ); } return values; } protected WidgetPreference getWidgetPreference( String key ) { if ( _widgetPreferences == null ) return null; else return _widgetPreferences.get( key ); } /** * The default mode to use unless it specified in the State, * default is WidgetMode.VIEW. */ public void setWidgetMode( WidgetMode widgetMode ) { _widgetMode = widgetMode; } WidgetMode getWidgetMode() { return _widgetMode; } /** * Default is to allow all widget modes. */ public void addAllowedWidgetMode( WidgetMode widgetMode ) { if ( _allowedWidgetModesSet == null ) _allowedWidgetModesSet = new HashSet<WidgetMode>(); _allowedWidgetModesSet.add( widgetMode ); } public boolean isWidgetModeAllowed( WidgetMode widgetMode ) { if ( _allowedWidgetModesSet == null ) return true; else return _allowedWidgetModesSet.contains( widgetMode ); } public void init() throws WidgetException { } private void initAll() throws WidgetException { if ( !_lifecycle.toInitializing() ) return; if ( _id == null && _parent != null ) throw new IllegalStateException( L.l( "`{0}' is required", "id" ) ); if ( _preferencePrefix == null ) _preferencePrefix = _id + "."; init(); _lifecycle.toActive(); } public Set<Map.Entry<String,Widget>> entrySet() { return (Set<Map.Entry<String,Widget>>) Collections.EMPTY_SET; } public Widget put( String id, Widget value ) { throw new UnsupportedOperationException(); } /** * Called once for each request to restore the state of the widget * for the request. */ protected S decode( WidgetConnection connection ) throws WidgetException { if ( log.isLoggable( Level.FINER ) ) log.finer( L.l( "decode {0}", getLogId() ) ); S state = createState( connection ); state.setWidget( this ); String parameterName = getParameterName(); if ( parameterName == null && getParent() != null ) throw new IllegalStateException( L.l("`{0}' cannot be null", "parameter-name" ) ); if ( parameterName != null ) { String[] data = connection.getParameterValues( getParameterName() ); if ( log.isLoggable( Level.FINEST ) ) log.finest( L.l( "data from parameter {0} is {1}", getParameterName(), data ) ); state.decode( data ); } decodeChildren( connection, state ); return state; } protected void decodeChildren( WidgetConnection connection, WidgetState state ) throws WidgetException { if ( !isEmpty() ) { for ( Widget child : values() ) { decodeChild( connection, state, child ); } } } protected WidgetState decodeChild( WidgetConnection connection, WidgetState thisState, Widget child ) throws WidgetException { WidgetState childState = child.decode( connection ); childState.setParent( thisState ); thisState.put( child.getId(), childState ); return childState; } abstract protected S createState( WidgetConnection connection ) throws WidgetException; private void encodeTree( WidgetURL url, WidgetState state, Widget target ) throws WidgetException { encodeTree( url, state, target, false, false ); } private void encodeTree( WidgetURL url, WidgetState state, Widget target, boolean isAction, boolean sawTarget ) throws WidgetException { if ( target == this ) { sawTarget = true; isAction = isAction( state ); } encode( url, state, isAction ); if ( !isEmpty() ) { for ( Widget child : values() ) { WidgetState childState = state.get( child.getId() ); if ( childState == null ) { throw new IllegalStateException( L.l( "no state for `{0}', missing decode()?", child.getLogId() ) ); } child.encodeTree( url, childState, target, isAction, sawTarget ); } } } protected void encode( WidgetURL url, WidgetState state, boolean isAction ) throws WidgetException { if ( log.isLoggable( Level.FINEST ) ) log.finest( L.l( "encode {0}", getLogId() ) ); WidgetMode widgetMode = state._widgetMode; if ( widgetMode != null ) { if ( widgetMode == WidgetMode.VIEW || widgetMode.equals( WidgetMode.VIEW ) ) { if ( state.getParent() != null ) url.setParameter( getModeParameterName(), widgetMode.toString() ); } else { url.setParameter( getModeParameterName(), widgetMode.toString() ); } } if ( isAction && isActionParameter( state ) ) { url.setAction( true ); } else { String[] data = state.encode(); if ( data != null ) url.setParameter( getParameterName(), data ); } } /** * Does this widget submit a value directly, s * in some manner other than a parameter to the url? * * This value only has an effect if a url is being made * from a widget that has a true value * for isAction(). * * For example, HTML fields like <input> return true. */ protected boolean isActionParameter( WidgetState state ) { return false; } /** * Does this widget make it so that children with isActionParameter() * can submit values without encoding them? * * For example, an HTML <form> does this. */ protected boolean isAction( WidgetState state ) { return false; } /** * Derived classes use this to create a url. * * The widget tree is followed parent by parent until the top is reached, * and then the connection is used to create a url for that widget. */ protected WidgetURL createURL( WidgetConnection connection ) throws WidgetException { Widget target = this; Widget top = this; while ( top.getParent() != null ) top = top.getParent(); WidgetURL url = connection.createURL(); WidgetState state = connection.prepare( top ); top.encodeTree( url, state, target ); return url; } public void render( WidgetConnection connection, S widgetState ) throws WidgetException, IOException { if ( ! _lifecycle.isActive() ) initAll(); WidgetRenderer<S> widgetRenderer = _rendererCache.getRenderer( connection, this, widgetState ); widgetRenderer.render( connection, widgetState ); } public void destroy() { if ( !_lifecycle.toDestroying() ) return; _lifecycle.toDestroy(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?