|
Lines 23-30
Link Here
|
| 23 |
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; |
23 |
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; |
| 24 |
import org.eclipse.e4.ui.model.application.ui.basic.MWindow; |
24 |
import org.eclipse.e4.ui.model.application.ui.basic.MWindow; |
| 25 |
import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl; |
25 |
import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl; |
| 26 |
import org.eclipse.swt.custom.SashForm; |
|
|
| 27 |
import org.eclipse.swt.widgets.Composite; |
| 28 |
import org.eclipse.swt.widgets.Shell; |
26 |
import org.eclipse.swt.widgets.Shell; |
| 29 |
import org.eclipse.swt.widgets.Widget; |
27 |
import org.eclipse.swt.widgets.Widget; |
| 30 |
|
28 |
|
|
Lines 122-171
Link Here
|
| 122 |
assertTrue("Part1 data is not an integer", cdVal1 != -1); |
120 |
assertTrue("Part1 data is not an integer", cdVal1 != -1); |
| 123 |
|
121 |
|
| 124 |
assertTrue("Values should be equal", cdVal0 == cdVal1); |
122 |
assertTrue("Values should be equal", cdVal0 == cdVal1); |
| 125 |
|
|
|
| 126 |
testWeights(sash, 50, 50); |
| 127 |
} |
| 128 |
|
| 129 |
private void testWeights(MPartSashContainer sf, double w1, double w2) { |
| 130 |
double baseRatio = w1 / w2; |
| 131 |
|
| 132 |
MPart part0 = (MPart) sf.getChildren().get(0); |
| 133 |
MPart part1 = (MPart) sf.getChildren().get(1); |
| 134 |
|
| 135 |
int cdVal0 = -1; |
| 136 |
try { |
| 137 |
cdVal0 = Integer.parseInt(part0.getContainerData()); |
| 138 |
} catch (NumberFormatException e) { |
| 139 |
} |
| 140 |
assertTrue("Part0 data is not an integer", cdVal0 != -1); |
| 141 |
|
| 142 |
int cdVal1 = -1; |
| 143 |
try { |
| 144 |
cdVal1 = Integer.parseInt(part1.getContainerData()); |
| 145 |
} catch (NumberFormatException e) { |
| 146 |
} |
| 147 |
assertTrue("Part1 data is not an integer", cdVal1 != -1); |
| 148 |
|
| 149 |
// test the model |
| 150 |
checkRatio("MSashForm", cdVal0, cdVal1, baseRatio); |
| 151 |
|
| 152 |
// test the SashForm |
| 153 |
SashForm sfw = (SashForm) sf.getWidget(); |
| 154 |
int[] sfwWghts = sfw.getWeights(); |
| 155 |
checkRatio("SWT SashForm", sfwWghts[0], sfwWghts[1], baseRatio); |
| 156 |
|
| 157 |
// Test the controls (assume vertical for now) |
| 158 |
Composite c1 = (Composite) sfw.getChildren()[0]; |
| 159 |
Composite c2 = (Composite) sfw.getChildren()[1]; |
| 160 |
checkRatio("Control Bounds", c1.getSize().y, c2.getSize().y, baseRatio); |
| 161 |
} |
| 162 |
|
| 163 |
private void checkRatio(String label, int num, int div, double baseRatio) { |
| 164 |
double ratio = (double) num / (double) div; |
| 165 |
|
| 166 |
double TOLERANCE = 0.1; |
| 167 |
boolean withinTolerance = Math.abs(ratio - baseRatio) < TOLERANCE; |
| 168 |
assertTrue("Ratio mismatch on" + label + "weights", withinTolerance); |
| 169 |
} |
123 |
} |
| 170 |
|
124 |
|
| 171 |
private MWindow createSashWithNViews(int n) { |
125 |
private MWindow createSashWithNViews(int n) { |