首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse Graphiti,如何创建“CustomFeature的创建和获取所有元素”?

Eclipse Graphiti,如何创建“CustomFeature的创建和获取所有元素”?
EN

Stack Overflow用户
提问于 2013-05-02 19:34:03
回答 2查看 687关注 0票数 1

我有两个问题,也许有人能告诉我怎么做

我已经创建了从AbstractCustomFeature扩展的新"testFeature“,并且可以在我的图中调用它。如何获得包含图中所有元素的列表?(我想在开始和以后更新它们的名称和颜色)

我的第二个问题是:我正在尝试将一些元素添加到图中,而不是从调色板中拖放它们。

例如,我在图中保存了一些元素,并且我的“模型说我在图中缺少3个元素”。我想写一个自定义功能,只需单击一次/两次就可以在Graphiti Diagram中绘制/放置缺少的元素,也许我需要在这一部分使用Zest?但在开始时,我只想放几个元素而不从调色板中删除它们,我该怎么做呢?

也许有人能给我指路?

谢谢你的帮忙!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-22 22:33:31

好的!以下是我的解决方案:

代码语言:javascript
复制
class testFeature extends AbstractCustomFeature {
    //...
      public void execute(ICustomContext context) {
          Diagram diagram = getDiagram();                     //get Diagram
          EList<Shape> diagramChildren= diagram.getChildren();//get List with all Children's
          Iterator<Shape> it = diagramChildren.iterator();    //Build iterator for this List


          //go through all objects which are in the Diagram
          while (it.hasNext()) {
              Shape testObjekt = it.next();                                                 
              PictogramElement pe =  testObjekt.getGraphicsAlgorithm().getPictogramElement(); 
              Object bo = getBusinessObjectForPictogramElement(pe);
              //BUILD YOUR EMF & GRAPHITI projects together!!!!
              //otherwise you get always false after editor restart
              if (bo instanceof graphicElement) {
                  graphicElement sElement = (graphicElement)bo;
                  if(pe instanceof ContainerShape){
                      RoundedRectangle testR= (RoundedRectangle) pe.getGraphicsAlgorithm();
                      //testR is my RoundedRectangle like in help tutorial

                      //changes are possible here:
                      //...

                      ContainerShape cs = (ContainerShape) pe;
                      for (Shape shape : cs.getChildren()) {
                        //set Name
                          if (shape.getGraphicsAlgorithm() instanceof Text) {
                              Text text = (Text) shape.getGraphicsAlgorithm();
                                text.setValue("new name!");
                          }
                          //set Line color
                          if (shape.getGraphicsAlgorithm() instanceof Polyline) {
                              Polyline polyline = (Polyline)shape.getGraphicsAlgorithm();
                              polyline.setForeground(manageColor(myColorGreen));
                              polyline.setLineWidth(3);
                          }
                      }
                  }
              }
          }
票数 0
EN

Stack Overflow用户

发布于 2013-05-22 03:31:13

如何获取包含图中所有元素的列表?

Diagram是一个ContainerShape,你可以调用getChildren()来检索所有的形状

将一些元素添加到图中,而无需从调色板中拖放它们。

是否已经在EMF模型中创建了对象,并且您只想让它将其图形副本添加到图中?如果是这样,您需要实例化并执行相应的XXXAddFeature类。

在其他地方(更有可能的是,如果您想要从调色板中模仿一些拖放操作),您必须调用适当的XXXCreateFeature,它会将元素添加到模型(通常,create body将在最后调用addGraphicalRepresentation(),这也会通过在内部调用适当的XXXAddFeature将相应的图形元素添加到图中)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16337025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档