📄 component.java
字号:
package com.cownew.uidesigner.model;import java.util.List;import org.eclipse.draw2d.geometry.Rectangle;import org.eclipse.jface.viewers.ICellEditorValidator;import org.eclipse.ui.views.properties.IPropertyDescriptor;import org.eclipse.ui.views.properties.IPropertySource;import org.eclipse.ui.views.properties.TextPropertyDescriptor;import com.cownew.uidesigner.common.ComponentIdManager;abstract public class Component extends Element implements IPropertySource{ static final long serialVersionUID = 4; public static final String BOUNDS = "BOUNDS"; public static final String ID = "ID"; private Rectangle bounds; private String id = "component"; private Form form; public Form getForm() { return form; } public void setForm(Form form) { this.form = form; } public Rectangle getBounds() { return bounds; } public void setBounds(Rectangle bounds) { this.bounds = bounds; firePropertyChange(BOUNDS, null, bounds); } public void setId(String id) { if (this.id.equals(id)) { return; } this.id = id; firePropertyChange(ID, null, id); } public String getId() { return id; } public Object getEditableValue() { return this; } public IPropertyDescriptor[] getPropertyDescriptors() { TextPropertyDescriptor idDesc = new TextPropertyDescriptor(ID, "Id"); idDesc.setValidator(new ICellEditorValidator() { public String isValid(Object value) { String id = (String) value; ComponentIdManager idMgr = new ComponentIdManager(getForm()); // 防止id重名 if (idMgr.isIdConflicted(id, Component.this)) { return "控件Id:" + id + "已经存在"; } return null; } }); IPropertyDescriptor[] descriptors = new IPropertyDescriptor[] { idDesc }; return descriptors; } public Object getPropertyValue(Object id) { if (id.equals(ID)) { return getId(); } return null; } public boolean isPropertySet(Object id) { return true; } public void resetPropertyValue(Object id) { } public void setPropertyValue(Object id, Object value) { if (id == ID) { setId((String) value); } } /** * 生成代码片段(生成代码的逻辑本不应该和模型混在一起,不过由于代码生成逻辑 目前不是很复杂,所以暂时这么做 * * @param parentId * 父控件的id * @return 代码段,List中每一个元素是一个类型为String的代码行 */ public abstract List<String> generateCode(String parentId);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -