【仅供内部供应商使用,不提供对外解答和培训】

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeEclipse
firstline1
titleToolBarButton.java
linenumberstrue
collapsetrue
package com.fr.form.ui;

import com.fr.data.core.DataCoreXmlUtils;
import com.fr.form.event.Listener;
import com.fr.general.data.Condition;
import com.fr.js.JavaScript;
import com.fr.js.JavaScriptImpl;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.script.Calculator;
import com.fr.stable.core.NodeVisitor;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;

/*
 * TODO ToolBar上面的所有Widget是有共同的默认方法(afterload)的, 任何类型的Widget也是默认的实现方法的
 * 故,希望多重继承,看了Think in java,觉得也许可以把ToolBar变成一个外部类,Email, Next那些作为ToolBar的内部类,也许可行
 */
public abstract class ToolBarButton extends Button {
    // richer:权限控制,仅使用PrivilegeCondition
    protected Condition condition;

    public ToolBarButton(String text) {
        super(text);
        this.setEnabled(true);
    }

    public ToolBarButton(String text, String iconName) {
        super(text, iconName);
        // alex:工具栏按钮默认为disabled
        this.setEnabled(true);
    }

    public String widgetName() {
        return getClass().getSimpleName();
    }

    public Condition getCondition() {
        return this.condition;
    }

    public void setCondition(Condition condition) {
        this.condition = condition;
    }

    public Listener[] createListeners(Repository repo) {
        return new Listener[]{
                new Listener(AFTERINIT, initAction(repo)),
                new Listener(EVENT_CLICK, clickScript(repo)),
                new Listener(
                        WebContentUtils.getContentPanel(repo), WebContentUtils.EVENT_STARTLOAD, new JavaScriptImpl(
                        getDisableAction()
                )
                ), new Listener(
                WebContentUtils.getContentPanel(repo), WebContentUtils.EVENT_AFTERLOAD, new JavaScriptImpl(
                onContentPanelAfterLoad(repo)
        )
        )
        };
    }

    /**
     * 返回按钮点击事件脚本
     * @param repo Repository 请求资料对象
     * @return 点击事件脚本
     * 这个函数不推荐再使用,推荐直接使用clickScript方法
     */
    @Deprecated
    protected abstract JavaScriptImpl clickAction(Repository repo);

    protected JavaScript clickScript(Repository repo){
        return clickAction(repo);
    }

    protected JavaScript initAction(Repository repo) {
        return new JavaScriptImpl("this.disable();");
    }

    /*
     * 对应于ContentPanel.afterload事件
     */
    protected String onContentPanelAfterLoad(Repository repo) {
        return getEnableAction();
    }

    @Override
    public JSONObject createJSONConfig(Repository repo, Calculator c, NodeVisitor nodeVisitor) throws JSONException {
        JSONObject jo = super.createJSONConfig(repo, c, nodeVisitor);
        jo.put("widgetName", widgetName());
        return jo;
    }

    public void readXML(XMLableReader reader) {
        super.readXML(reader);
        if (reader.isChildNode()) {
            if (Condition.XML_TAG.equals(reader.getTagName())) {
                ToolBarButton.this.condition = DataCoreXmlUtils.readCondition(reader);
            }
        }
    }

    public void writeXML(XMLPrintWriter writer) {
        super.writeXML(writer);
        if (condition != null) {
            DataCoreXmlUtils.writeXMLCondition(writer, condition);
        }
    }

    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof ToolBarButton)) {
            return false;
        }
        return super.equals(obj);
    }
}

四、支持版本

产品线

版本

支持情况

备注

FR8.0支持
FR9.0支持
FR10.0支持
BI3.6支持不支持仪表板
BI4.0支持不支持仪表板
BI5.1支持不支持仪表板
BI5.1.2支持不支持仪表板
BI5.1.3支持不支持仪表板

五、插件注册

Code Block
languagexml
themeEclipse
firstline1
titleplugin.xml
linenumberstrue
<extra-designer>
        <ToolbarItemProvider class="your class name"/>
</extra-designer>

...

demo地址:demo-toolbar-item-provider

Image Added

Image Added

九、开源案例

免责声明:所有文档中的开源示例,均为开发者自行开发并提供。仅用于参考和学习使用,开发者和官方均无义务对开源案例所涉及的所有成果进行教学和指导。若作为商用一切后果责任由使用者自行承担。

...