标签:
2015.5.3
1.model
1 import java.io.*; 2 import java.util.List; 3 import java.io.BufferedReader; 4 import java.io.File; 5 import java.io.FileReader; 6 import java.io.FileWriter; 7 import java.io.IOException; 8 9 import org.dom4j.Element; 10 import org.eclipse.draw2d.geometry.Dimension; 11 import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor; 12 import org.eclipse.ui.views.properties.IPropertyDescriptor; 13 import org.eclipse.ui.views.properties.PropertyDescriptor; 14 import org.eclipse.ui.views.properties.TextPropertyDescriptor; 15 16 import com.example.helper.ConstantResourceFactory; 17 import com.example.helper.ModelStringConstant; 18 import com.example.helper.CustomErrorInfo; 19 import com.example.model.ModelType; 20 import com.example.model.NonContainerModel; 21 import com.example.propertyDiscriptor.EditDialogPropertyDescriptor; 22 import com.example.propertyDiscriptor.FileDialogPropertyDescriptor; 23 24 public class SampleModel extends NonContainerModel { 25 public String edit; 26 public static final String SELECT_LABEL = "label"; 27 public static final String SELECT_NAME = "name"; 28 public static final String SELECT_EDIT = "edit"; 29 //******************************************结构体部分******************************** 30 public SampleModel() { 31 super(ConstantResourceFactory.LABEL_SAMPLE_MODEL, 32 ConstantResourceFactory.ID_SAMPLE_MODEL, 33 ConstantResourceFactory.SIZE_SAMPLE_ELEMENT); 34 setName("样条曲线"); 35 setEdit("编辑属性"); 36 //setModel("空");这里的setModel是setModelString,string里放的是文件的内容 37 } 38 //******************************************结构体部分******************************** 39 40 41 42 //******************************************属性编辑部分******************************** 43 public IPropertyDescriptor[] descriptors = new IPropertyDescriptor[] { 44 new PropertyDescriptor(SELECT_LABEL, "模型名字"), 45 new TextPropertyDescriptor(SELECT_NAME, "名字"), 46 new EditDialogPropertyDescriptor(SELECT_EDIT,"编辑"), 47 }; 48 49 public IPropertyDescriptor[] getPropertyDescriptors() { 50 return descriptors; 51 } 52 53 public Object getPropertyValue(Object id) { 54 super.getPropertyValue(id); 55 if (id.equals(SELECT_LABEL)){ 56 return getModelName(); 57 } 58 else if (id.equals(SELECT_NAME)){ 59 return getName(); 60 } 61 else if (id.equals(SELECT_EDIT)){ 62 return getEdit(); 63 } 64 return null; 65 } 66 67 public boolean isPropertySet(Object id) { 68 return true; 69 } 70 71 public void resetPropertyValue(Object id) { 72 } 73 74 public void setPropertyValue(Object id, Object value) { 75 super.setPropertyValue(id, value); 76 if(id.equals(SELECT_NAME)){ 77 setName((String)value); 78 } 79 80 else if(id.equals(SELECT_EDIT)){ 81 setEdit((String)value); 82 } 83 } 84 //******************************************属性编辑部分******************************** 85 86 87 88 //******************************************XML部分******************************** 89 public void doSaveXML(){ 90 super.doSaveXML(); 91 // this.addXMLElementAttribute(ModelType.ATR_MODELSTRING, (String) getModel()); 92 //文件内容读取并保存部分 93 // this.doSaveModel(); 94 95 } 96 97 98 @Override 99 public void rebuildFromXml(Element e,List<Object> err) { 100 // TODO Auto-generated method stub 101 super.rebuildFromXml(e,err); 102 } 103 //******************************************XML部分******************************** 104 105 106 107 108 109 /* 110 //******************************************复制部分******************************** 111 @Override 112 public Object copy() { 113 // TODO Auto-generated method stub 114 LinearMotionModel model=new LinearMotionModel(); 115 initCopyModel(model); 116 return model; 117 } 118 119 protected void initCopyModel(LinearMotionModel model) { 120 // TODO Auto-generated method stub 121 super.initCopyModel(model); 122 model.setCoorType(coorType); 123 model.setDisplacement(displacement); 124 model.setVelocity(velocity); 125 } 126 //******************************************复制部分******************************** 127 */ 128 129 130 //******************************************get/set部分******************************** 131 public String getEdit() { 132 return edit; 133 } 134 135 public void setEdit(String edit) { 136 this.edit = edit; 137 firePropertyChange(ConstantResourceFactory.P_EDIT,null,edit); 138 } 139 //******************************************get/set部分******************************** 140 }
2.editPart,直接复制的callPart,里面没什么代码,父类都实现了。
3.partFactory
4.figure,复制的callFigure,没动。
1 import org.eclipse.draw2d.ColorConstants; 2 import org.eclipse.draw2d.Ellipse; 3 import org.eclipse.draw2d.Graphics; 4 import org.eclipse.draw2d.geometry.Dimension; 5 import org.eclipse.draw2d.geometry.Point; 6 import org.eclipse.draw2d.geometry.Rectangle; 7 import org.eclipse.swt.graphics.Color; 8 9 10 11 public class SampleFigure extends PortElementFigure { 12 13 public SampleFigure(){ 14 super(); 15 } 16 17 public Dimension getPreferredSize(int wHint, int hHint) { 18 return FigureDimensionConstant.SIZE_PORT_ELEMENT; 19 } 20 21 protected void paintFigure(Graphics g) { 22 super.paintFigure(g); 23 24 int x = getMainRect().x; 25 int y = getMainRect().y; 26 int w = getMainRect().width; 27 int h = getMainRect().height; 28 29 g.drawLine(x+w/6,y+5*h/6,x+w/3, y+h/3); 30 g.drawLine(x+3*w/6,y+2*h/3,x+w/3, y+h/3); 31 g.drawLine(x+5*w/6,y+h/6,x+3*w/6,y+2*h/3); 32 33 if(isShow()){ 34 drawLabelFrame(g,getNameFigure().getBounds(),true); 35 //drawLabelFrame(g,getTypeFigure().getBounds(),true); 36 } 37 38 } 39 40 }
5.figureFactory
6.paletteFactory
7.customModelFactory
8.ModelType
9.plugin.xml
运行没有问题。
还需要解决的问题:
(1)如何获取数据一开始就导入到属性栏中?(2)保存数据部分的程序还没有写。
标签:
原文地址:http://www.cnblogs.com/liyuhui21310122/p/4474545.html