| 1 | 2 | |
| 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.ExpandBar; |
| 16 | |
import org.eclipse.swt.widgets.ExpandItem; |
| 17 | |
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
| 18 | |
import org.eclipse.swtbot.swt.finder.results.BoolResult; |
| 19 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
| 20 | |
import org.eclipse.swtbot.swt.finder.results.WidgetResult; |
| 21 | |
import org.hamcrest.SelfDescribing; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
public class SWTBotExpandItem extends AbstractSWTBot<ExpandItem> { |
| 30 | |
private ExpandBar expandBar; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public SWTBotExpandItem(ExpandItem w) throws WidgetNotFoundException { |
| 39 | 2 | this(w, null); |
| 40 | 2 | } |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public SWTBotExpandItem(final ExpandItem w, SelfDescribing description) throws WidgetNotFoundException { |
| 50 | 6 | super(w, description); |
| 51 | 6 | this.expandBar = syncExec(new WidgetResult<ExpandBar>() { |
| 52 | |
public ExpandBar run() { |
| 53 | 6 | return w.getParent(); |
| 54 | |
} |
| 55 | |
}); |
| 56 | 6 | } |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public SWTBotExpandItem expand() { |
| 64 | 2 | asyncExec(new VoidResult() { |
| 65 | |
public void run() { |
| 66 | 2 | if (isExpanded()) |
| 67 | 1 | return; |
| 68 | 1 | widget.setExpanded(true); |
| 69 | 1 | expandNotify(); |
| 70 | 1 | } |
| 71 | |
}); |
| 72 | 2 | return this; |
| 73 | |
} |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public SWTBotExpandItem collapse() { |
| 81 | 2 | asyncExec(new VoidResult() { |
| 82 | |
public void run() { |
| 83 | 2 | if (isCollapsed()) |
| 84 | 0 | return; |
| 85 | 2 | widget.setExpanded(false); |
| 86 | 2 | collapseNotify(); |
| 87 | 2 | } |
| 88 | |
}); |
| 89 | 2 | return this; |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
public boolean isExpanded() { |
| 97 | 12 | return syncExec(new BoolResult() { |
| 98 | |
public Boolean run() { |
| 99 | 12 | return widget.getExpanded(); |
| 100 | |
} |
| 101 | |
}); |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public boolean isCollapsed() { |
| 109 | 6 | return !isExpanded(); |
| 110 | |
} |
| 111 | |
|
| 112 | 1 | private void expandNotify() { |
| 113 | 1 | notifyExpandBar(SWT.MouseMove); |
| 114 | 1 | notifyExpandBar(SWT.Activate); |
| 115 | 1 | notifyExpandBar(SWT.FocusIn); |
| 116 | 1 | notifyExpandBar(SWT.MouseDown); |
| 117 | 1 | notifyExpandBar(SWT.Expand); |
| 118 | 1 | notifyExpandBar(SWT.MeasureItem); |
| 119 | 1 | notifyExpandBar(SWT.Deactivate); |
| 120 | 1 | notifyExpandBar(SWT.FocusOut); |
| 121 | 1 | } |
| 122 | |
|
| 123 | 2 | private void collapseNotify() { |
| 124 | 2 | notifyExpandBar(SWT.MouseMove); |
| 125 | 2 | notifyExpandBar(SWT.Activate); |
| 126 | 2 | notifyExpandBar(SWT.FocusIn); |
| 127 | 2 | notifyExpandBar(SWT.MouseDown); |
| 128 | 2 | notifyExpandBar(SWT.Collapse); |
| 129 | 2 | notifyExpandBar(SWT.MeasureItem); |
| 130 | 2 | notifyExpandBar(SWT.Deactivate); |
| 131 | 2 | notifyExpandBar(SWT.FocusOut); |
| 132 | 2 | } |
| 133 | |
|
| 134 | |
private void notifyExpandBar(int eventType) { |
| 135 | 24 | notify(eventType, createEvent(), expandBar); |
| 136 | 24 | } |
| 137 | |
|
| 138 | |
protected Event createEvent() { |
| 139 | 24 | Event e = super.createEvent(); |
| 140 | 24 | e.widget = expandBar; |
| 141 | 24 | e.item = widget; |
| 142 | 24 | return e; |
| 143 | |
} |
| 144 | |
|
| 145 | |
} |