| 1 | 608 | |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package org.eclipse.swtbot.swt.finder.widgets; |
| 12 | |
|
| 13 | |
import org.eclipse.swt.SWT; |
| 14 | |
import org.eclipse.swt.widgets.Event; |
| 15 | |
import org.eclipse.swt.widgets.TabFolder; |
| 16 | |
import org.eclipse.swt.widgets.TabItem; |
| 17 | |
import org.eclipse.swtbot.swt.finder.ReferenceBy; |
| 18 | |
import org.eclipse.swtbot.swt.finder.SWTBot; |
| 19 | |
import org.eclipse.swtbot.swt.finder.SWTBotWidget; |
| 20 | |
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
| 21 | |
import org.eclipse.swtbot.swt.finder.results.BoolResult; |
| 22 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
| 23 | |
import org.eclipse.swtbot.swt.finder.results.WidgetResult; |
| 24 | |
import org.eclipse.swtbot.swt.finder.utils.MessageFormat; |
| 25 | |
import org.eclipse.swtbot.swt.finder.utils.SWTUtils; |
| 26 | |
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; |
| 27 | |
import org.hamcrest.SelfDescribing; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
@SWTBotWidget(clasz = TabItem.class, preferredName = "tabItem", referenceBy = { ReferenceBy.MNEMONIC }) |
| 35 | |
public class SWTBotTabItem extends AbstractSWTBot<TabItem> { |
| 36 | |
|
| 37 | 608 | private TabFolder parent; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public SWTBotTabItem(TabItem w) throws WidgetNotFoundException { |
| 46 | 1 | this(w, null); |
| 47 | 1 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public SWTBotTabItem(TabItem w, SelfDescribing description) throws WidgetNotFoundException { |
| 57 | 306 | super(w, description); |
| 58 | 306 | this.parent = syncExec(new WidgetResult<TabFolder>() { |
| 59 | |
public TabFolder run() { |
| 60 | 306 | return widget.getParent(); |
| 61 | |
} |
| 62 | |
}); |
| 63 | 306 | } |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
public SWTBotTabItem activate() throws TimeoutException { |
| 72 | 304 | log.trace(MessageFormat.format("Activating {0}", this)); |
| 73 | 304 | waitForEnabled(); |
| 74 | |
|
| 75 | 304 | asyncExec(new VoidResult() { |
| 76 | |
public void run() { |
| 77 | 304 | widget.getParent().setSelection(widget); |
| 78 | 304 | log.debug(MessageFormat.format("Activated {0}", this)); |
| 79 | 304 | } |
| 80 | |
}); |
| 81 | |
|
| 82 | 304 | notify(SWT.Selection, createEvent(), parent); |
| 83 | |
|
| 84 | 304 | new SWTBot().waitUntil(new DefaultCondition() { |
| 85 | |
public boolean test() throws Exception { |
| 86 | 304 | return isActive(); |
| 87 | |
} |
| 88 | |
|
| 89 | |
public String getFailureMessage() { |
| 90 | 0 | return "Timed out waiting for " + SWTUtils.toString(widget) + " to activate"; |
| 91 | |
} |
| 92 | |
}); |
| 93 | 304 | return this; |
| 94 | |
} |
| 95 | |
|
| 96 | |
protected Event createEvent() { |
| 97 | 304 | Event event = super.createEvent(); |
| 98 | 304 | event.widget = parent; |
| 99 | 304 | event.item = widget; |
| 100 | 304 | return event; |
| 101 | |
} |
| 102 | |
|
| 103 | |
public boolean isActive() { |
| 104 | 304 | return syncExec(new BoolResult() { |
| 105 | |
public Boolean run() { |
| 106 | 304 | return parent.getSelection()[0] == widget; |
| 107 | |
} |
| 108 | |
}); |
| 109 | |
} |
| 110 | |
|
| 111 | |
public boolean isEnabled() { |
| 112 | 304 | return syncExec(new BoolResult() { |
| 113 | |
public Boolean run() { |
| 114 | 304 | return parent.isEnabled(); |
| 115 | |
} |
| 116 | |
}); |
| 117 | |
} |
| 118 | |
|
| 119 | |
} |