How to find LRLocator of a figure?

39 views
Skip to first unread message
unread,
Mar 28, 2014, 4:36:18 AM3/28/14
      IWidgetLocator iw[] = ui.findAll(new LRLocator(0, new FigureLocator()));
      FigureReference ifR = (FigureReference) iw[0];
      List list1 = ifR.getFigure().getChildren();

      IFigure ifigure = (IFigure) list1.get(0);

      List list2 = ifigure.getChildren();
      org.eclipse.draw2d.Label label = (org.eclipse.draw2d.Label) list2.get(0);

I would like to find the LRLocator of the variable "label" but I am not sure how that could be done. Any help will be really appreciated.

Fred G

unread,
Mar 28, 2014, 9:21:39 AM3/28/14
Hi,

If I understand you correctly, you want to find a Label (org.eclipse.draw2d.Label) with the help of a LRLocator.
You could try the following:
LRLocator labelLocator = new LRLocator(0, new FigureClassLocator("org.eclipse.draw2d.label"));

Please note, that I have not tested this. I just looked through the JavaDoc reference:
https://developers.google.com/java-dev-tools/wintester/html/reference/javadoc/com/windowtester/runtime/gef/locator/LRLocator

You can also take a look at the code examples here:
http://windowtester.googlecode.com/svn/trunk/com.windowtester.gef_test/sample-src/com/windowtester/samples/gef/tests/SampleGEFLogicTest.java
http://windowtester.googlecode.com/svn/trunk/com.windowtester.gef_test/src/com/windowtester/test/gef/tests/smoke/scenarios/FlowDrivingSmokeTest1.java

Regards,

Fred
unread,
Apr 1, 2014, 5:03:51 AM4/1/14
Hi,
Thanks. I will try it out and let you know.
Regards
Muhammad
unread,
Apr 1, 2014, 11:23:42 AM4/1/14
Hi Fred,

The code that uploaded earlier that gives me all the label name. I wanted to find the their LRLocator by name.
Or find all the label's LRLocator of a figure.


LRLocator labelLocator = new LRLocator(0, new FigureClassLocator("org.eclipse.draw2d.label"));
Using this bit of code you still need to provide the index. I am just wondering is it possible to go from finding all the label then for each label finding their location.


On Friday, 28 March 2014 14:21:39 UTC, Fred G wrote:

Fred G

unread,
Apr 3, 2014, 1:38:02 PM4/3/14
Hi,

You can define the following two inner classes:

    public class LabelNameLocator extends FigureLocator {
        public LabelNameLocator(String name) {
            super(new LabelNameMatcher(name));
        }
    }
   
    public class LabelNameMatcher implements IFigureMatcher {
        private final String name;
        public LabelNameMatcher(String name) {
            this.name = name;
        }
        public boolean matches(IFigureReference figure) {
            if(figure.getFigure() instanceof Label){
                String text = TextHelper.getText(figure.getFigure());
                if(text != null){
                    return name.equals(text);
                }
            }
            return false;
        }
    };


Then you can use the following line to get the locator for a label with the text "label 1":

LabelNameLocator labelNameLocator = new LabelNameLocator("label 1");

Or if there is more than one label with the same text:

IWidgetLocator[] labelNameLocators = findAll(new LabelNameLocator("label 1"));

Hope that helps,

Fred
Reply all
Reply to author
Forward
0 new messages