搜索 GEF 对象

Functional Tester 识别 GEF EditPart 和 Palette。一些图可能与 EditPart 无关联。可以使用 Functional Tester API 来查找此类图,如以下示例中所示。
示例 1:以下示例显示如何使用 getFigure() API 来检索具有文本 "label" 且与 EditPart 无关联的图
//Get the figure for an EditPart
		GuiTestObject figureTO = EntityEditPart().getFigure();		
		
//Find for a figure that has the text in it.
		TestObject foundTO[] = figureTO.find(atDescendant("text", "label"));
		if(foundTO != null)
		{
			int numFound = foundTO.length;
			for(int index = 0; index < numFound ; index ++)
			{
				if(foundTO[index] != null && foundTO[index] instanceof GuiTestObject)
				{
					//To check for specific property on the figure
					Object figWidth = foundTO[index].getProperty("width");
					if(figWidth != null)
						((GuiTestObject)foundTO[index]).click();
				}				
			}
		}
示例 2:以下示例显示如何使用 getConnectors() API 来对具有标签 "Association" 的连接器执行单击操作
//List the connectors from the node's parent
		TestObject parent = EntityEditPart().getParent();
		if(parent != null && parent instanceof GefEditPartTestObject)
		{
			TestObject connectors[] = ((GefEditPartTestObject)parent).getConnectors();

			if(connectors != null)
			{
				int numConnector = connectors.length; 
				for(int conIndex = 0; conIndex < numConnector; conIndex ++)
				{
					if(connectors[conIndex] != null && connectors[conIndex] instanceof GefEditPartTestObject)
					{
						GuiTestObject figConnector = ((GefEditPartTestObject)connectors[conIndex]).getFigure();
						//Find for a figure that has some text in it.
						TestObject foundConn[] = figConnector.find(atDescendant("text", "association"));
						if(foundConn != null && foundConn.length > 0)						
						{
							//If there is only one label with the text "Association"
							if(foundConn[0] != null && foundConn[0] instanceof GuiTestObject)
							{
								((GuiTestObject)foundConn[0]).click();
							}
						}

					}

				}
			}
		}

示例 3:以下示例使用 isConnector() API 以所选 EditPart 的后代连接器填充列表

//Assuming you have "RootEditPart" in the ObjectMap.
	ArrayList connList = new ArrayList();
	enumerateAllConnectors(RootEditPart(),connList);
	}
	
  	private static void enumerateAllConnectors(TestObject editPart,ArrayList connList)
	{
		if(editPart != null )
		{
			if(editPart instanceof GefEditPartTestObject)
			{
				boolean isConnector = ((GefEditPartTestObject)editPart).isConnector();
				if(isConnector)
					connList.add(editPart);
			}
			
			TestObject []children = editPart.getChildren();
			if(children != null)
			{
				int numChild = children.length;
				for(int i=0; i < numChild ; i++)
				{
					enumerateAllConnectors(children[i], connList);
				}
			}
		}	
	}
	

反馈