周洪
新手
新手
  • UID203
  • 粉丝1
  • 关注0
  • 发帖数5
阅读:7652回复:0

网页样式编辑器读取构件xml和生成tab页

楼主#
更多 发布于:2016-10-14 16:56
1.CSSFormEditor.java getInput()方法读取编辑器配置:editorConfig包含xml配置内容
protected void setInput(IEditorInput input) {
superSetInput(input);
if (inputFile == null || !inputFile.exists())
return;
if (editorConfig == null) {
editorConfig = CSSEditorConfigUtils.getEditorConfig(inputFile);
}
}
2.CSSEditorConfigUtils.java getEditorConfig()读取xml文件具体信息
public static CSSEditorModel getEditorConfig(IFile editorFile) {
CSSEditorModel editorConfig = new CSSEditorModel();
if (!editorFile.exists())
return editorConfig;
try {
Element editorEle = new SAXReader().read(editorFile.getContents()).getRootElement();
for (Object childObj : editorEle.elements()) {
Element childEle = (Element) childObj;
if (TAG_EDITORPAGE.equals(childEle.getName())) {
editorConfig.addEditorPage(loadCSSEditorPageConfig(childEle, false, editorConfig));
} else if (TAG_CUSTOM_PAGE.equals(childEle.getName())) {
editorConfig.setCustomContent(childEle.getText());
}
}
editorConfig.setActivePageId(editorEle.attributeValue(RUN_ATTR_ACTIVE_PAGE));
editorConfig.setActiveModelId(editorEle.attributeValue(RUN_ATTR_ACTIVE_MODEL));
editorConfig.setNamespace(editorEle.attributeValue(ATTR_NAMESPACE)); // 读取命名空间
editorConfig.setDescription(editorEle.attributeValue(ATTR_DESCRIPTION));
} catch (DocumentException e) {
XHtmlLog.error(e.getMessage(), e);
} catch (CoreException e) {
XHtmlLog.error(e.getMessage(), e);
}
return editorConfig;
}
3.CSSFormEditor.java通过addPages()方法往网页样式编辑器添加tab
protected void addPages() {
try {
int activePage = 0;
int pageCount = 1;
addPage(new CSSOverviewPage(this));
for (CSSEditorPageModel cepm : editorConfig.getEditorPages()) {
CSSFormPage cssPage = new CSSFormPage(this, cepm);
addPage(cssPage);
cssPages.add(cssPage);
if (cepm.getId().equals(editorConfig.getActivePageId()))
activePage = pageCount;
++pageCount;
}
addPage(new CSSCustomPage(this));
if (activePage == 0 && CSSCustomPage.PAGE_ID.equals(editorConfig.getActivePageId()))
activePage = pageCount;
// 设置活动编辑页
setActivePage(activePage);
} catch (PartInitException e) {
XHtmlLog.error(e.getMessage(), e);
}
}
4.构件xml 具体信息
<editorPage id="btn" name="按钮" index="10">
<group id="btn.default" name="基本按钮">
<classGroup id="button.base.default" name="默认按钮" desc="默认按钮">
<class id="button.base.default:normal" name="正常状态" desc="">
<attribute id="width" name="宽度"/>
<attribute id="height" name="高度"/>
<attribute id="color" name="颜色"/>
<attribute id="padding" name="内边距"/>
<attribute id="margin" name="外边距"/>
<attribute id="background" name="背景"/>
<attribute id="border" name="边框"/>
<attribute id="font" name="字体"/>
<codeClass id=".btn-default">
<attribute ref="background"/>
<attribute ref="padding"/>
<attribute ref="margin"/>
<attribute ref="width"/>
<attribute ref="height"/>
<attribute ref="color"/>
<attribute ref="border"/>
<attribute ref="font"/>
</codeClass>
<modelClass id=".xic-btn-default">
<attribute ref="background"/>
<attribute ref="padding"/>
<attribute ref="margin"/>
<attribute ref="width"/>
<attribute ref="height"/>
<attribute ref="color"/>
<attribute ref="border"/>
<attribute ref="font"/>
</modelClass>
</class>
</classGroup>
</group>
</editorPage>
游客

返回顶部