Dengues Studio: Google Group:http://groups.google.com/group/dengues; QQ Group:24885404.
在GEF实现表格的收缩,如下图:
伸展的图:

按减号收起:

功能代码:
org.dengues.designer.ui.database.figures.DBTableCustomFigure
的部分实现代码:
 1 Image image = dbTable.isHidden() ? EXPAND_IMAGE : COLLAPSE_IMAGE;
 2         final Button button = new Button(image);
 3         button.setRolloverEnabled(true);
 4         button.addChangeListener(new ChangeListener() {
 5 
 6             /*
 7              * (non-Javadoc)
 8              * 
 9              * @see org.eclipse.draw2d.ChangeListener#handleStateChanged(org.eclipse.draw2d.ChangeEvent)
10              */
11             public void handleStateChanged(ChangeEvent event) {
12                 if (event.getPropertyName().equals(ButtonModel.PRESSED_PROPERTY)) {
13                     List children2 = button.getChildren();
14                     i++;
15                     for (Object object2 : children2) {
16                         if (object2 instanceof Label) {
17                             Label label = (Label) object2;
18                             if (i % 2 == 0) {
19                                 if (EXPAND_IMAGE.equals(label.getIcon())) {
20                                     label.setIcon(COLLAPSE_IMAGE);
21                                     for (DBColumn column : getColumns()) {
22                                         column.setHidden(false);
23                                     }
24                                 } else {
25                                     label.setIcon(EXPAND_IMAGE);
26                                     for (DBColumn column : getColumns()) {
27                                         column.setHidden(true);
28                                     }
29                                 }
30                                 i = 0;
31                             }
32                         }
33                     }
34                 }
35             }
36         });
37         titleFigure.add(button);
org.dengues.designer.ui.database.parts.DBColumnEditPart

 1 public void notifyChanged(Notification notification) {
 2         int type = notification.getEventType();
 3         int id = notification.getFeatureID(DatabasePackage.class);
 4         switch (type) {
 5         case Notification.SET:
 6             switch (id) {
 7             case DatabasePackage.DB_COLUMN__X:
 8             case DatabasePackage.DB_COLUMN__Y:
 9             case DatabasePackage.DB_COLUMN__HEIGHT:
10             case DatabasePackage.DB_COLUMN__WIDTH:
11             case DatabasePackage.DB_COLUMN__NAME:
12             case DatabasePackage.DB_COLUMN__FOREIGN_KEY:
13             case DatabasePackage.DIAGRAM_CHILD__SELECTED:
14                 refreshVisuals();
15                 break;
16             case DatabasePackage.DB_COLUMN__HIDDEN:
17                 getCastModel().getTable().setHidden(notification.getNewBooleanValue());
18                 break;
19             }

 1 org.dengues.designer.ui.database.parts.DBTableEditPart
 2 //实现代码
 3 public void notifyChanged(Notification notification) {
 4         int type = notification.getEventType();
 5         int id = notification.getFeatureID(DatabasePackage.class);
 6         switch (type) {
 7         case Notification.SET:
 8             switch (id) {
 9             case DatabasePackage.DB_TABLE__X:
10             case DatabasePackage.DB_TABLE__Y:
11             case DatabasePackage.DB_TABLE__HEIGHT:
12             case DatabasePackage.DB_TABLE__WIDTH:
13             case DatabasePackage.DB_TABLE__NAME:
14             case DatabasePackage.DB_TABLE__HIDDEN:
15                 refreshVisuals();
16                 break;
 1 protected void refreshVisuals() {
 2         EList columns = getCastModel().getColumns();
 3         int colNum = 0;
 4         for (Object object : columns) {
 5             if (object instanceof DBColumn) {
 6                 if (!((DBColumn) object).isHidden()) {
 7                     colNum++;
 8                 }
 9             }
10         }
11         int i = colNum * COLUMN_HEIGHT + TABLE_HEADER;
12 
13         Rectangle bounds = new Rectangle(getCastModel().getX(), getCastModel().getY(), getCastModel().getWidth(), i);
14         customTableFigure.getTableName().setText(getCastModel().getName());
15         ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), bounds);
16     }
17 






Dengues论坛(http://groups.google.com/group/dengues/),一个很好的Eclipse开发者乐园.

Feedback

# re: [Dengues]在GEF中实现,表格图像的收缩.像Tree一样。  回复  更多评论   

2009-03-19 16:02 by defrag_sly
我作了一个gef tree。跟普通的tree基本没区别。喜欢交流的话。请跟我联系。
http://defrag-sly.javaeye.com/admin/blogs/343016

# re: [Dengues]在GEF中实现,表格图像的收缩.像Tree一样。  回复  更多评论   

2009-06-20 15:38 by Hsieh
当Table被折叠的时候,连线时怎么处理的 ?

只有注册用户登录后才能发表评论。


网站导航:
 
Dengues Studio: Google Group:http://groups.google.com/group/dengues; QQ Group:24885404.