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 |
|
?
1 |
|
?
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 |
|
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
?
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 |
|
1.1.3 getComponent().doSaveXML();
?
1 2 3 |
|
?
1 2 3 4 5 6 7 8 9 10 11 |
|
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;
}