![](/img/trans.png)
[英]How do I disable/remove the Palette of an Eclipse Graphiti editor?
[英]Eclipse Graphiti, How to create “CustomFeature's create & get all Elements”?
我有2個問題,也許有人可以告訴我我該怎么做
我已經創建了從AbstractCustomFeature擴展的新“ testFeature”,並且可以在我的圖表中調用它。 我如何獲得包含圖中所有元素的列表?(我想在開始和以后更新它們的名稱和顏色)
我的第二個問題是:我正在嘗試向圖中添加一些元素,而無需從面板中拖放它們。
例如,我在圖中保存了一些元素,而我的“模型說我在圖中錯過了3個元素”。 我想編寫一個自定義功能,只需單擊一次/兩次,即可繪制/放置Graphiti圖中缺少的元素,也許我需要在這一部分使用Zest? 但是在開始時,我只想放置一些元素而不將其從面板中刪除,我該怎么做?
也許有人可以給我指示?
謝謝你的幫助!
如何獲取包含圖中所有元素的列表?
圖是一個ContainerShape ,您可以調用getChildren()
來檢索所有形狀
向圖中添加一些元素,而無需從面板中拖放它們。
是否已經在EMF模型內部創建了對象,並且只希望將其圖形對應對象添加到圖中? 如果是這樣,則需要實例化並自己執行相應的XXXAddFeature
類。
在其他地方(更可能是,如果您想模仿調色板中的某些拖放操作),則必須調用適當的XXXCreateFeature
,它將在模型中添加(“以XXXCreateFeature
說法” create)元素(通常是create主體最后將調用addGraphicalRepresentation()
,該方法還將通過內部調用適當的XXXAddFeature
將相應的圖形元素添加到圖中。
好! 這是我的解決方案:
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);
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.