GEF 오브젝트 검색

Functional Tester는 GEF EditParts 및 팔레트를 인식합니다. 일부 그림은 EditPart와 연관성을 갖고 있지 않습니다. Functional Tester API를 사용하여 아래 예제에 표시된 것과 같은 그림을 찾을 수 있습니다.
예제 1: 다음 예제는 텍스트 "레이블"이 있고 EditPart와 연관되지 않은 그림을 검색하기 위해 getFigure() API를 사용하는 방법을 표시합니다.
//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를 사용하는 방법을 표시합니다.
//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);
				}
			}
		}	
	}
	

피드백