📄 palette.java
字号:
super.onComponentTag(tag); tag.getAttributes().put("onclick", Palette.this.getDownOnClickJS()); } }.add(new Image("image", DOWN_IMAGE)); } /** * factory method for the move up component * * @return move up component */ protected Component newUpComponent() { return new PaletteButton("moveUpButton") { private static final long serialVersionUID = 1L; protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.getAttributes().put("onclick", Palette.this.getUpOnClickJS()); } }.add(new Image("image", UP_IMAGE)); } /** * factory method for the remove component * * @return remove component */ protected Component newRemoveComponent() { return new PaletteButton("removeButton") { private static final long serialVersionUID = 1L; protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.getAttributes().put("onclick", Palette.this.getRemoveOnClickJS()); } }.add(new Image("image", REMOVE_IMAGE)); } /** * factory method for the addcomponent * * @return add component */ protected Component newAddComponent() { return new PaletteButton("addButton") { private static final long serialVersionUID = 1L; protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.getAttributes().put("onclick", Palette.this.getAddOnClickJS()); } }.add(new Image("image", ADD_IMAGE)); } /** * factory method for the selected items component * * @return selected items component */ protected Component newSelectionComponent() { return new Selection("selection", this) { private static final long serialVersionUID = 1L; protected Map getAdditionalAttributes(Object choice) { return Palette.this.getAdditionalAttributesForSelection(choice); } }; } /** * @see org.apache.wicket.extensions.markup.html.form.palette.component#getAdditionalAttributes() */ protected Map getAdditionalAttributesForSelection(Object choice) { return null; } /** * factory method for the available items component * * @return available items component */ protected Component newChoicesComponent() { return new Choices("choices", this) { private static final long serialVersionUID = 1L; protected Map getAdditionalAttributes(Object choice) { return Palette.this.getAdditionalAttributesForChoices(choice); } }; } /** * @see org.apache.wicket.extensions.markup.html.form.palette.component#getAdditionalAttributes() */ protected Map getAdditionalAttributesForChoices(Object choice) { return null; } private Component getChoicesComponent() { return choicesComponent; } private Component getSelectionComponent() { return selectionComponent; } /** * Returns recorder component. Recorder component is a form component used to track the * selection of the palette. It receives <code>onchange</code> javascript event whenever a * change in selection occurs. * * @return recorder component */ public final Recorder getRecorderComponent() { return recorderComponent; } /** * @return collection representing all available items */ public Collection getChoices() { return (Collection)choicesModel.getObject(); } /** * @return collection representing selected items */ public Collection getModelCollection() { return (Collection)getModelObject(); } /** * @return choice renderer */ public IChoiceRenderer getChoiceRenderer() { return choiceRenderer; } /** * @return items visible without scrolling */ public int getRows() { return rows; } /** * The model object is assumed to be a Collection, and it is modified in-place. Then * {@link Model#setObject(Object)} is called with the same instance: it allows the Model to be * notified of changes even when {@link Model#getObject()} returns a different * {@link Collection} at every invocation. * * @see FormComponent#updateModel() */ protected final void updateModel() { // prepare model Collection model = (Collection)getModelObject(); model.clear(); // update model Iterator it = getRecorderComponent().getSelectedChoices(); while (it.hasNext()) { final Object selectedChoice = it.next(); model.add(selectedChoice); } getModel().setObject(model); } /** * builds javascript handler call * * @param funcName * name of javascript function to call * @return string representing the call tho the function with palette params */ protected String buildJSCall(String funcName) { return new StringBuffer(funcName).append("('") .append(getChoicesComponent().getMarkupId()) .append("','") .append(getSelectionComponent().getMarkupId()) .append("','") .append(getRecorderComponent().getMarkupId()) .append("');") .toString(); } /** * @return choices component on focus javascript handler */ public String getChoicesOnFocusJS() { return buildJSCall("Wicket.Palette.choicesOnFocus"); } /** * @return selection component on focus javascript handler */ public String getSelectionOnFocusJS() { return buildJSCall("Wicket.Palette.selectionOnFocus"); } /** * @return add action javascript handler */ public String getAddOnClickJS() { return buildJSCall("Wicket.Palette.add"); } /** * @return remove action javascript handler */ public String getRemoveOnClickJS() { return buildJSCall("Wicket.Palette.remove"); } /** * @return move up action javascript handler */ public String getUpOnClickJS() { return buildJSCall("Wicket.Palette.moveUp"); } /** * @return move down action javascript handler */ public String getDownOnClickJS() { return buildJSCall("Wicket.Palette.moveDown"); } protected void onDetach() { // we need to manually detach the choices model since it is not attached // to a component // an alternative might be to attach it to one of the subcomponents choicesModel.detach(); super.onDetach(); } private class PaletteButton extends WebMarkupContainer { private static final long serialVersionUID = 1L; /** * Constructor * * @param id */ public PaletteButton(String id) { super(id); } protected void onComponentTag(ComponentTag tag) { if (!isPaletteEnabled()) { tag.getAttributes().put("disabled", "disabled"); } } } /** * Renders header contributions * * @param response */ public void renderHead(IHeaderResponse response) { response.renderJavascriptReference(JAVASCRIPT); ResourceReference css = getCSS(); if (css != null) { response.renderCSSReference(css); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -