标签:des c style class blog code
1.DiagramModel
注意:是继承自AbstractModel(功能:监听)
public class DiagramModel extends AbstractModel {
public DiagramModel() { super(); name=""; initModel(); 见下面: }
public void initModel(){ setName("Diagram"); setDiagramDoc(DocumentHelper.createDocument()); 创建document setRootElement(getDiagramDoc().addElement(ModelType.ELE_ROOT)); setDiagramElement(getRootElement().addElement(ModelType.ELE_DIAGRAM)); setDiagramExElement(getRootElement().addElement(ModelType.ELE_DIAGRAMEX)); }
添加根元素root,并且添加root的子元素diagram和diagramex。??
1.1 doSaveXML()
public void doSaveXML() { // TODO Auto-generated method stub this.addDiagramAttribute(ModelType.ATR_NAME, name); 先添加属性NAME和属性值name。 getDiagramHead().doSaveXML(); getComponent().doSaveXML(); for(int i=0;i<getPorts().size();i++){ ((ElementModel)getPorts().get(i)).doSaveXML(); } for(int i=0;i<getTexts().size();i++){ ((ElementModel)getTexts().get(i)).doSaveXML(); } }
1.1.1 addDiagramAttribute(ModelType.ATR_NAME, name);
protected void addDiagramAttribute(String name,String value){ if(getDiagramElement()==null){ return; } getDiagramElement().addAttribute(name, value); } protected void removeDiagramAttribute(String name){ if(getDiagramElement()==null){ return; } Attribute atr = getDiagramElement().attribute(name); if(atr != null){ getDiagramElement().remove(atr); } }
1.1.2 getDiagramHead().doSaveXML();
1
2
3 |
public <span style= "color: rgb(255, 0, 0);" > DiagramHeadingModel</span> getDiagramHead() { return
diagramHead; } |
1 |
public class DiagramHeadingModel extends
ElementModel { |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 |
先定义一些属性,并且定义一个结构体 private
String definition,myCtype,myReturn,mySystem,diagramType; private
boolean isRetShow,isSysShow,isRunsOnShow; public
static final String SELECT_DEF = "select_def" ; public
static final String SELECT_CTYPE = "select_ctype" ; public
static final String SELECT_RETURN = "select_return" ; public
static final String SELECT_SYSTEM = "select_system" ; public
static final String SELECT_DIAGRAM = "select_diagram" ; private
IPropertyDescriptor[] descriptor; private
List<IPropertyDescriptor> descriptorList = new
ArrayList<IPropertyDescriptor>(); private
static final TextPropertyDescriptor definitionDescriptor = new
TextPropertyDescriptor(SELECT_DEF, "Definition" ); private
static final TextPropertyDescriptor ctypeDescriptor = new
TextPropertyDescriptor(SELECT_CTYPE, "runs On" ); private
static final TextPropertyDescriptor returnDescriptor = new
TextPropertyDescriptor(SELECT_RETURN, "return" ); private
static final TextPropertyDescriptor systemDescriptor = new
TextPropertyDescriptor(SELECT_SYSTEM, "system" ); private
static final PropertyDescriptor diagramDescriptor = new
PropertyDescriptor(SELECT_DIAGRAM, "Diagram Type" ); public
DiagramHeadingModel() { super (ConstantResourceFactory.LABEL_DIAGRAMHEAD_MODEL, ConstantResourceFactory.ID_DIAGRAMHEAD_MODEL, ConstantResourceFactory.SIZE_DIAGRAMHEAD); // TODO Auto-generated constructor stub definition= "" ; myCtype= "" ; myReturn= "" ; mySystem= "" ; diagramType= "" ; isRetShow= false ; isSysShow= false ; isRunsOnShow= false ; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 |
public IPropertyDescriptor[] getPropertyDescriptors() { // TODO Auto-generated method stub if (descriptor == null ){ descriptorList.add(definitionDescriptor); descriptorList.add(diagramDescriptor); if (isRunsOnShow()){ descriptorList.add(ctypeDescriptor); } if (isRetShow()){ descriptorList.add(returnDescriptor); } if (isSysShow()){ descriptorList.add(systemDescriptor); } descriptor = (IPropertyDescriptor[]) descriptorList .toArray( new
IPropertyDescriptor[ 1 ]); } return
descriptor; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
<span style= "color: rgb(255, 0, 0);" >然后保存,过程就是两步:首先继承elementModel的dosaveXML,然后添加自己的属性。</span> public void doSaveXML() { // TODO Auto-generated method stub super .doSaveXML(); this .addXMLElementAttribute(ModelType.ATR_DIAGRAM,diagramType); this .addXMLElementAttribute(ModelType.ATR_DEFINITION,definition); if (isRunsOnShow()){ this .addXMLElementAttribute(ModelType.ATR_RUNSON,myCtype); } else { this .removeXMLElementAttribute(ModelType.ATR_RUNSON); } if (isRetShow()){ this .addXMLElementAttribute(ModelType.ATR_RETURN,myReturn); } else { this .removeXMLElementAttribute(ModelType.ATR_RETURN); } if (isSysShow()){ this .addXMLElementAttribute(ModelType.ATR_SYSTEM,mySystem); } else { this .removeXMLElementAttribute(ModelType.ATR_SYSTEM); } } |
1.1.3 getComponent().doSaveXML();
1
2
3 |
public <span style= "color: rgb(255, 0, 0);" >ComponentInstanceModel</span> getComponent() { return
component; } |
1
2
3
4
5
6
7
8
9
10
11 |
public void doSaveXML() { // TODO Auto-generated method stub super .doSaveXML(); for ( int
i= 0 ;i<children.size();i++){ <span style= "background-color: rgb(0, 255, 0);" >((ElementModel)children.get(i)).doSaveXML();</span> } if (tail!= null ) tail.doSaveXML(); } |
1.1.4 ((ElementModel)getPorts().get(i)).doSaveXML();
到了最重要的portelementmodel了。
public abstract class PortElementModel extends ElementModel {
定义一些属性:
private static final IPropertyDescriptor[] descriptorPort = new IPropertyDescriptor[]{ new PropertyDescriptor(SELECT_LABEL,"Model Label"), new TextPropertyDescriptor(SELECT_NAME,"Port Name"), new TextPropertyDescriptor(SELECT_TYPE,"Port Type"), };
初始化:
public PortElementModel(String label, String modelID, Dimension size) { super(label, modelID, size); // TODO Auto-generated constructor stub name=""; type=""; }
保存:
public void doSaveXML() { // TODO Auto-generated method stub super.doSaveXML(); this.addXMLElementAttribute(ModelType.ELE_NAME, name); this.addXMLElementAttribute(ModelType.ELE_TYPE, type); }
1.1.5 ((ElementModel)getTexts().get(i)).doSaveXML();
public abstract class LiteralElementModel extends ElementModel { public void doSaveXML() { // TODO Auto-generated method stub super.doSaveXML(); } }
1.2 DiagramModel中定义的变量
private List<Object> children = new ArrayList<Object>(); private List<Object> ports = new ArrayList<Object>(); doSaveXML() private List<Object> texts = new ArrayList<Object>(); doSaveXML() private List<Object> containers = new ArrayList<Object>(); private List<Object> portOps = new ArrayList<Object>(); private List<Object> refers = new ArrayList<Object>(); private ComponentInstanceModel component; doSaveXML()
public ComponentInstanceModel getComponent() { return component; } public void setComponent(ComponentInstanceModel component) { this.component = component; }
private DiagramHeadingModel diagramHead; doSaveXML()
public void setDiagramHead(DiagramHeadingModel diagramHead) { this.diagramHead = diagramHead; } public DiagramHeadingModel getDiagramHead() { return diagramHead; }
private String name;
public String getName() { return name; } public void setName(String name) { this.name = name; }
private Document diagramDoc;
public void setDiagramDoc(Document diagramDoc) { this.diagramDoc = diagramDoc; } public Document getDiagramDoc() { return diagramDoc; }
private Element rootElement,diagramElement,diagramExElement;
public void setDiagramElement(Element diagramElement) { this.diagramElement = diagramElement; } public Element getDiagramElement() { return diagramElement; }
public void setDiagramExElement(Element diagramExElement) { this.diagramExElement = diagramExElement; } public Element getDiagramExElement() { return diagramExElement; }
public void setRootElement(Element rootElement) { this.rootElement = rootElement; } public Element getRootElement() { return rootElement; }
标签:des c style class blog code
原文地址:http://www.cnblogs.com/liyuhui20093357/p/3768944.html