GEF オブジェクトの検索

Functional Tester は GEF EditParts および Palettes を認識します。一部の Figure には、EditPart との関連付けがない場合があります。Functional Tester API を使用して、以下の例に示すような Figure を検索することができます。
例 1: 以下の例は、getFigure() API を使用して、EditPart に関連付けられていないテキスト "label" が含まれる Figure を取得する方法を示しています。
//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);
				}
			}
		}	
	}
	

フィードバック