|
Lines 13-244
Link Here
|
| 13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
| 14 |
import java.util.HashMap; |
14 |
import java.util.HashMap; |
| 15 |
import java.util.HashSet; |
15 |
import java.util.HashSet; |
| 16 |
import java.util.List; |
|
|
| 17 |
import java.util.Map; |
| 18 |
import javax.annotation.PostConstruct; |
| 19 |
import javax.annotation.PreDestroy; |
| 20 |
import javax.inject.Inject; |
| 21 |
import org.eclipse.e4.core.contexts.ContextInjectionFactory; |
| 22 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
16 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
| 23 |
import org.eclipse.e4.core.contexts.RunAndTrack; |
17 |
import org.eclipse.e4.core.contexts.RunAndTrack; |
| 24 |
import org.eclipse.e4.core.services.events.IEventBroker; |
|
|
| 25 |
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; |
18 |
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; |
| 26 |
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; |
|
|
| 27 |
import org.eclipse.e4.ui.model.application.MApplication; |
19 |
import org.eclipse.e4.ui.model.application.MApplication; |
| 28 |
import org.eclipse.e4.ui.model.application.ui.MElementContainer; |
20 |
import org.eclipse.e4.ui.model.application.ui.MElementContainer; |
| 29 |
import org.eclipse.e4.ui.model.application.ui.MUIElement; |
21 |
import org.eclipse.e4.ui.model.application.ui.MUIElement; |
| 30 |
import org.eclipse.e4.ui.model.application.ui.SideValue; |
22 |
import org.eclipse.e4.ui.model.application.ui.SideValue; |
| 31 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
|
| 32 |
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; |
23 |
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; |
| 33 |
import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem; |
|
|
| 34 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem; |
| 35 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
| 36 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; |
24 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; |
| 37 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution; |
25 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution; |
| 38 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; |
26 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; |
| 39 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; |
27 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; |
| 40 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; |
28 |
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; |
| 41 |
import org.eclipse.e4.ui.workbench.IPresentationEngine; |
|
|
| 42 |
import org.eclipse.e4.ui.workbench.UIEvents; |
| 43 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
| 44 |
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; |
29 |
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; |
| 45 |
import org.eclipse.emf.ecore.EObject; |
|
|
| 46 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
| 47 |
import org.eclipse.jface.action.AbstractGroupMarker; |
| 48 |
import org.eclipse.jface.action.ContributionItem; |
| 49 |
import org.eclipse.jface.action.GroupMarker; |
| 50 |
import org.eclipse.jface.action.IContributionItem; |
| 51 |
import org.eclipse.jface.action.Separator; |
| 52 |
import org.eclipse.jface.action.ToolBarManager; |
| 53 |
import org.eclipse.jface.layout.RowLayoutFactory; |
30 |
import org.eclipse.jface.layout.RowLayoutFactory; |
| 54 |
import org.eclipse.swt.SWT; |
31 |
import org.eclipse.swt.SWT; |
| 55 |
import org.eclipse.swt.events.DisposeEvent; |
32 |
import org.eclipse.swt.events.DisposeEvent; |
| 56 |
import org.eclipse.swt.events.DisposeListener; |
33 |
import org.eclipse.swt.events.DisposeListener; |
| 57 |
import org.eclipse.swt.events.SelectionEvent; |
|
|
| 58 |
import org.eclipse.swt.events.SelectionListener; |
| 59 |
import org.eclipse.swt.graphics.Color; |
| 60 |
import org.eclipse.swt.graphics.GC; |
| 61 |
import org.eclipse.swt.graphics.Image; |
| 62 |
import org.eclipse.swt.graphics.ImageData; |
| 63 |
import org.eclipse.swt.graphics.Point; |
| 64 |
import org.eclipse.swt.graphics.Rectangle; |
| 65 |
import org.eclipse.swt.layout.RowLayout; |
34 |
import org.eclipse.swt.layout.RowLayout; |
| 66 |
import org.eclipse.swt.widgets.Composite; |
35 |
import org.eclipse.swt.widgets.Composite; |
| 67 |
import org.eclipse.swt.widgets.Control; |
36 |
import org.eclipse.swt.widgets.Control; |
| 68 |
import org.eclipse.swt.widgets.Display; |
|
|
| 69 |
import org.eclipse.swt.widgets.Menu; |
| 70 |
import org.eclipse.swt.widgets.ToolBar; |
37 |
import org.eclipse.swt.widgets.ToolBar; |
| 71 |
import org.eclipse.swt.widgets.ToolItem; |
38 |
import org.eclipse.swt.widgets.ToolItem; |
| 72 |
import org.eclipse.swt.widgets.Widget; |
39 |
import org.eclipse.swt.widgets.Widget; |
| 73 |
import org.osgi.service.event.Event; |
|
|
| 74 |
import org.osgi.service.event.EventHandler; |
| 75 |
|
40 |
|
| 76 |
/** |
41 |
/** |
| 77 |
* Create a contribute part. |
42 |
* Create a contribute part. |
| 78 |
*/ |
43 |
*/ |
| 79 |
public class ToolBarRenderer extends SWTPartRenderer { |
44 |
public class ToolBarRenderer extends SWTPartRenderer { |
| 80 |
|
|
|
| 81 |
private Map<MToolBar, ToolBarManager> modelToManager = new HashMap<MToolBar, ToolBarManager>(); |
| 82 |
private Map<ToolBarManager, MToolBar> managerToModel = new HashMap<ToolBarManager, MToolBar>(); |
| 83 |
|
| 84 |
private Map<MToolBarElement, IContributionItem> modelToContribution = new HashMap<MToolBarElement, IContributionItem>(); |
| 85 |
|
| 86 |
private ArrayList<ContributionRecord> contributionRecords = new ArrayList<ContributionRecord>(); |
| 87 |
|
| 88 |
// @Inject |
| 89 |
// private Logger logger; |
| 90 |
|
| 91 |
@Inject |
| 92 |
IPresentationEngine renderer; |
| 93 |
@Inject |
| 94 |
private MApplication application; |
45 |
private MApplication application; |
| 95 |
@Inject |
|
|
| 96 |
private EModelService modelService; |
| 97 |
|
| 98 |
@Inject |
| 99 |
IEventBroker eventBroker; |
| 100 |
private EventHandler itemUpdater = new EventHandler() { |
| 101 |
public void handleEvent(Event event) { |
| 102 |
// Ensure that this event is for a MMenuItem |
| 103 |
if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) |
| 104 |
return; |
| 105 |
|
| 106 |
MToolBarElement itemModel = (MToolBarElement) event |
| 107 |
.getProperty(UIEvents.EventTags.ELEMENT); |
| 108 |
|
| 109 |
IContributionItem ici = getContribution(itemModel); |
| 110 |
if (ici == null) { |
| 111 |
return; |
| 112 |
} |
| 113 |
|
| 114 |
String attName = (String) event |
| 115 |
.getProperty(UIEvents.EventTags.ATTNAME); |
| 116 |
if (UIEvents.UILabel.LABEL.equals(attName)) { |
| 117 |
ici.update(); |
| 118 |
} else if (UIEvents.UILabel.ICONURI.equals(attName)) { |
| 119 |
ici.update(); |
| 120 |
} else if (UIEvents.UILabel.TOOLTIP.equals(attName)) { |
| 121 |
ici.update(); |
| 122 |
} |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
private EventHandler toBeRenderedUpdater = new EventHandler() { |
| 127 |
public void handleEvent(Event event) { |
| 128 |
// Ensure that this event is for a MMenuItem |
| 129 |
if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) |
| 130 |
return; |
| 131 |
|
| 132 |
MToolBarElement itemModel = (MToolBarElement) event |
| 133 |
.getProperty(UIEvents.EventTags.ELEMENT); |
| 134 |
String attName = (String) event |
| 135 |
.getProperty(UIEvents.EventTags.ATTNAME); |
| 136 |
if (UIEvents.UIElement.TOBERENDERED.equals(attName)) { |
| 137 |
Object obj = itemModel.getParent(); |
| 138 |
if (!(obj instanceof MToolBar)) { |
| 139 |
return; |
| 140 |
} |
| 141 |
ToolBarManager parent = getManager((MToolBar) obj); |
| 142 |
if (itemModel.isToBeRendered()) { |
| 143 |
if (parent != null) { |
| 144 |
modelProcessSwitch(parent, itemModel); |
| 145 |
parent.update(true); |
| 146 |
ToolBar tb = parent.getControl(); |
| 147 |
if (tb != null && !tb.isDisposed()) { |
| 148 |
tb.getShell().layout(new Control[] { tb }, |
| 149 |
SWT.DEFER); |
| 150 |
} |
| 151 |
} |
| 152 |
} else { |
| 153 |
IContributionItem ici = modelToContribution |
| 154 |
.remove(itemModel); |
| 155 |
if (ici != null && parent != null) { |
| 156 |
parent.remove(ici); |
| 157 |
} |
| 158 |
if (ici != null) { |
| 159 |
ici.dispose(); |
| 160 |
} |
| 161 |
} |
| 162 |
} else if (UIEvents.UIElement.VISIBLE.equals(attName)) { |
| 163 |
IContributionItem ici = getContribution(itemModel); |
| 164 |
if (ici == null) { |
| 165 |
return; |
| 166 |
} |
| 167 |
ici.setVisible(itemModel.isVisible()); |
| 168 |
ToolBarManager parent = (ToolBarManager) ((ContributionItem) ici) |
| 169 |
.getParent(); |
| 170 |
if (parent != null) { |
| 171 |
parent.markDirty(); |
| 172 |
ToolBar tb = parent.getControl(); |
| 173 |
if (tb != null && !tb.isDisposed()) { |
| 174 |
tb.getShell().layout(new Control[] { tb }, SWT.DEFER); |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
}; |
| 180 |
|
| 181 |
private EventHandler selectionUpdater = new EventHandler() { |
| 182 |
public void handleEvent(Event event) { |
| 183 |
// Ensure that this event is for a MToolItem |
| 184 |
if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) |
| 185 |
return; |
| 186 |
|
| 187 |
MToolBarElement itemModel = (MToolBarElement) event |
| 188 |
.getProperty(UIEvents.EventTags.ELEMENT); |
| 189 |
IContributionItem ici = getContribution(itemModel); |
| 190 |
if (ici != null) { |
| 191 |
ici.update(); |
| 192 |
} |
| 193 |
} |
| 194 |
}; |
| 195 |
|
| 196 |
private EventHandler enabledUpdater = new EventHandler() { |
| 197 |
public void handleEvent(Event event) { |
| 198 |
// Ensure that this event is for a MMenuItem |
| 199 |
if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) |
| 200 |
return; |
| 201 |
|
| 202 |
MToolBarElement itemModel = (MToolBarElement) event |
| 203 |
.getProperty(UIEvents.EventTags.ELEMENT); |
| 204 |
IContributionItem ici = getContribution(itemModel); |
| 205 |
if (ici != null) { |
| 206 |
ici.update(); |
| 207 |
} |
| 208 |
} |
| 209 |
}; |
| 210 |
private Image viewMenuImage; |
| 211 |
|
| 212 |
@PostConstruct |
| 213 |
public void init() { |
| 214 |
eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC), |
| 215 |
itemUpdater); |
| 216 |
eventBroker.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, |
| 217 |
UIEvents.Item.SELECTED), selectionUpdater); |
| 218 |
eventBroker |
| 219 |
.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, |
| 220 |
UIEvents.Item.ENABLED), enabledUpdater); |
| 221 |
eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC, |
| 222 |
UIEvents.UIElement.TOBERENDERED), toBeRenderedUpdater); |
| 223 |
|
| 224 |
} |
| 225 |
|
46 |
|
| 226 |
@PreDestroy |
47 |
HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup = new HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>>(); |
| 227 |
public void contextDisposed() { |
|
|
| 228 |
eventBroker.unsubscribe(itemUpdater); |
| 229 |
eventBroker.unsubscribe(selectionUpdater); |
| 230 |
eventBroker.unsubscribe(enabledUpdater); |
| 231 |
eventBroker.unsubscribe(toBeRenderedUpdater); |
| 232 |
} |
| 233 |
|
48 |
|
| 234 |
/* |
49 |
/* |
| 235 |
* (non-Javadoc) |
50 |
* (non-Javadoc) |
| 236 |
* |
51 |
* |
| 237 |
* @see |
52 |
* @see |
| 238 |
* org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget |
53 |
* org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#init(org.eclipse |
| 239 |
* (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object) |
54 |
* .e4.core.contexts.IEclipseContext) |
| 240 |
*/ |
55 |
*/ |
| 241 |
@Override |
56 |
@Override |
|
|
57 |
public void init(IEclipseContext context) { |
| 58 |
super.init(context); |
| 59 |
application = context.get(MApplication.class); |
| 60 |
} |
| 61 |
|
| 242 |
public Object createWidget(final MUIElement element, Object parent) { |
62 |
public Object createWidget(final MUIElement element, Object parent) { |
| 243 |
if (!(element instanceof MToolBar) || !(parent instanceof Composite)) |
63 |
if (!(element instanceof MToolBar) || !(parent instanceof Composite)) |
| 244 |
return null; |
64 |
return null; |
|
Lines 246-415
Link Here
|
| 246 |
// HACK!! This should be done using a separate renderer |
66 |
// HACK!! This should be done using a separate renderer |
| 247 |
Composite intermediate = new Composite((Composite) parent, SWT.NONE); |
67 |
Composite intermediate = new Composite((Composite) parent, SWT.NONE); |
| 248 |
createToolbar(element, intermediate); |
68 |
createToolbar(element, intermediate); |
| 249 |
processContribution((MToolBar) element); |
69 |
intermediate.addDisposeListener(new DisposeListener() { |
| 250 |
|
70 |
public void widgetDisposed(DisposeEvent e) { |
| 251 |
return intermediate; |
71 |
cleanUp((MToolBar) element); |
| 252 |
} |
|
|
| 253 |
|
| 254 |
/** |
| 255 |
* @param element |
| 256 |
*/ |
| 257 |
private void processContribution(MToolBar toolbarModel) { |
| 258 |
final ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); |
| 259 |
ContributionsAnalyzer.gatherToolBarContributions(toolbarModel, |
| 260 |
application.getToolBarContributions(), |
| 261 |
toolbarModel.getElementId(), toContribute); |
| 262 |
generateContributions(toolbarModel, toContribute); |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* @param toolbarModel |
| 267 |
* @param toContribute |
| 268 |
*/ |
| 269 |
private void generateContributions(MToolBar toolbarModel, |
| 270 |
ArrayList<MToolBarContribution> toContribute) { |
| 271 |
HashSet<String> existingSeparatorNames = new HashSet<String>(); |
| 272 |
for (MToolBarElement child : toolbarModel.getChildren()) { |
| 273 |
String elementId = child.getElementId(); |
| 274 |
if (child instanceof MToolBarSeparator && elementId != null) { |
| 275 |
existingSeparatorNames.add(elementId); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
ToolBarManager manager = getManager(toolbarModel); |
| 280 |
boolean done = toContribute.size() == 0; |
| 281 |
while (!done) { |
| 282 |
ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>( |
| 283 |
toContribute); |
| 284 |
int retryCount = toContribute.size(); |
| 285 |
toContribute.clear(); |
| 286 |
|
| 287 |
for (final MToolBarContribution contribution : curList) { |
| 288 |
if (!processAddition(toolbarModel, manager, contribution, |
| 289 |
existingSeparatorNames)) { |
| 290 |
toContribute.add(contribution); |
| 291 |
} |
| 292 |
} |
| 293 |
// We're done if the retryList is now empty (everything done) or |
| 294 |
// if the list hasn't changed at all (no hope) |
| 295 |
done = (toContribute.size() == 0) |
| 296 |
|| (toContribute.size() == retryCount); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
static class ContributionRecord { |
| 301 |
public ContributionRecord(MToolBar toolbarModel, |
| 302 |
MToolBarContribution contribution, ToolBarManager manager) { |
| 303 |
this.toolbarModel = toolbarModel; |
| 304 |
this.contribution = contribution; |
| 305 |
this.manager = manager; |
| 306 |
} |
| 307 |
|
| 308 |
MToolBar toolbarModel; |
| 309 |
MToolBarContribution contribution; |
| 310 |
ToolBarManager manager; |
| 311 |
ArrayList<MToolBarElement> generatedElements = new ArrayList<MToolBarElement>(); |
| 312 |
|
| 313 |
public void generate() { |
| 314 |
for (MToolBarElement element : contribution.getChildren()) { |
| 315 |
MToolBarElement copy = (MToolBarElement) EcoreUtil |
| 316 |
.copy((EObject) element); |
| 317 |
generatedElements.add(copy); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
public void updateVisibility(IEclipseContext context) { |
| 322 |
ExpressionContext exprContext = new ExpressionContext(context); |
| 323 |
boolean isVisible = ContributionsAnalyzer.isVisible(contribution, |
| 324 |
exprContext); |
| 325 |
for (MToolBarElement item : generatedElements) { |
| 326 |
item.setVisible(isVisible); |
| 327 |
} |
| 328 |
manager.markDirty(); |
| 329 |
} |
| 330 |
|
| 331 |
public void dispose() { |
| 332 |
for (MToolBarElement copy : generatedElements) { |
| 333 |
toolbarModel.getChildren().remove(copy); |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* @param toolbarModel |
| 340 |
* @param manager |
| 341 |
* @param contribution |
| 342 |
* @param existingSeparatorNames |
| 343 |
* @return <code>true</code> if the contribution was successfuly processed |
| 344 |
*/ |
| 345 |
private boolean processAddition(MToolBar toolbarModel, |
| 346 |
final ToolBarManager manager, MToolBarContribution contribution, |
| 347 |
HashSet<String> existingSeparatorNames) { |
| 348 |
int idx = getIndex(toolbarModel, contribution.getPositionInParent()); |
| 349 |
if (idx == -1) { |
| 350 |
return false; |
| 351 |
} |
| 352 |
final ContributionRecord record = new ContributionRecord(toolbarModel, |
| 353 |
contribution, manager); |
| 354 |
contributionRecords.add(record); |
| 355 |
record.generate(); |
| 356 |
for (MToolBarElement copy : record.generatedElements) { |
| 357 |
if (copy instanceof MToolBarSeparator |
| 358 |
&& existingSeparatorNames.contains(copy.getElementId())) { |
| 359 |
// skip this, it's already there |
| 360 |
continue; |
| 361 |
} |
| 362 |
toolbarModel.getChildren().add(idx++, copy); |
| 363 |
if (copy instanceof MToolBarSeparator |
| 364 |
&& copy.getElementId() != null) { |
| 365 |
existingSeparatorNames.add(copy.getElementId()); |
| 366 |
} |
72 |
} |
| 367 |
} |
73 |
}); |
| 368 |
if (contribution.getVisibleWhen() != null) { |
|
|
| 369 |
final IEclipseContext parentContext = modelService |
| 370 |
.getContainingContext(toolbarModel); |
| 371 |
parentContext.runAndTrack(new RunAndTrack() { |
| 372 |
@Override |
| 373 |
public boolean changed(IEclipseContext context) { |
| 374 |
record.updateVisibility(parentContext.getActiveLeaf()); |
| 375 |
manager.update(false); |
| 376 |
return true; |
| 377 |
} |
| 378 |
}); |
| 379 |
} |
| 380 |
|
| 381 |
return true; |
| 382 |
} |
| 383 |
|
74 |
|
| 384 |
private static int getIndex(MElementContainer<?> menuModel, |
75 |
return intermediate; |
| 385 |
String positionInParent) { |
|
|
| 386 |
String id = null; |
| 387 |
String modifier = null; |
| 388 |
if (positionInParent != null && positionInParent.length() > 0) { |
| 389 |
String[] array = positionInParent.split("="); //$NON-NLS-1$ |
| 390 |
modifier = array[0]; |
| 391 |
id = array[1]; |
| 392 |
} |
| 393 |
if (id == null) { |
| 394 |
return menuModel.getChildren().size(); |
| 395 |
} |
| 396 |
|
| 397 |
int idx = 0; |
| 398 |
int size = menuModel.getChildren().size(); |
| 399 |
while (idx < size) { |
| 400 |
if (id.equals(menuModel.getChildren().get(idx).getElementId())) { |
| 401 |
if ("after".equals(modifier)) { //$NON-NLS-1$ |
| 402 |
idx++; |
| 403 |
} |
| 404 |
return idx; |
| 405 |
} |
| 406 |
idx++; |
| 407 |
} |
| 408 |
return id.equals("additions") ? menuModel.getChildren().size() : -1; //$NON-NLS-1$ |
| 409 |
} |
76 |
} |
| 410 |
|
77 |
|
| 411 |
private ToolBar createToolbar(final MUIElement element, |
78 |
ToolBar createToolbar(final MUIElement element, Composite intermediate) { |
| 412 |
Composite intermediate) { |
|
|
| 413 |
int orientation = getOrientation(element); |
79 |
int orientation = getOrientation(element); |
| 414 |
RowLayout layout = RowLayoutFactory.fillDefaults().wrap(false) |
80 |
RowLayout layout = RowLayoutFactory.fillDefaults().wrap(false) |
| 415 |
.spacing(0).type(orientation).create(); |
81 |
.spacing(0).type(orientation).create(); |
|
Lines 418-462
Link Here
|
| 418 |
intermediate.setLayout(layout); |
84 |
intermediate.setLayout(layout); |
| 419 |
// new Label(intermediate, (orientation == SWT.HORIZONTAL ? SWT.VERTICAL |
85 |
// new Label(intermediate, (orientation == SWT.HORIZONTAL ? SWT.VERTICAL |
| 420 |
// : SWT.HORIZONTAL) | SWT.SEPARATOR); |
86 |
// : SWT.HORIZONTAL) | SWT.SEPARATOR); |
| 421 |
|
|
|
| 422 |
ToolBar separatorToolBar = new ToolBar(intermediate, orientation |
87 |
ToolBar separatorToolBar = new ToolBar(intermediate, orientation |
| 423 |
| SWT.WRAP | SWT.FLAT | SWT.RIGHT); |
88 |
| SWT.WRAP | SWT.FLAT | SWT.RIGHT); |
| 424 |
new ToolItem(separatorToolBar, SWT.SEPARATOR); |
89 |
new ToolItem(separatorToolBar, SWT.SEPARATOR); |
| 425 |
ToolBarManager manager = getManager((MToolBar) element); |
90 |
return new ToolBar(intermediate, orientation | SWT.WRAP | SWT.FLAT |
| 426 |
if (manager == null) { |
91 |
| SWT.RIGHT); |
| 427 |
manager = new ToolBarManager(orientation | SWT.WRAP | SWT.FLAT |
|
|
| 428 |
| SWT.RIGHT); |
| 429 |
linkModelToManager((MToolBar) element, manager); |
| 430 |
} |
| 431 |
ToolBar bar = manager.createControl(intermediate); |
| 432 |
bar.setData(manager); |
| 433 |
bar.getShell().layout(new Control[] { bar }, SWT.DEFER); |
| 434 |
bar.addDisposeListener(new DisposeListener() { |
| 435 |
public void widgetDisposed(DisposeEvent e) { |
| 436 |
cleanUp((MToolBar) element); |
| 437 |
} |
| 438 |
}); |
| 439 |
return bar; |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* @param element |
| 444 |
*/ |
| 445 |
protected void cleanUp(MToolBar toolbarModel) { |
| 446 |
for (ContributionRecord record : contributionRecords |
| 447 |
.toArray(new ContributionRecord[contributionRecords.size()])) { |
| 448 |
if (record.toolbarModel == toolbarModel) { |
| 449 |
record.dispose(); |
| 450 |
contributionRecords.remove(record); |
| 451 |
for (MToolBarElement copy : record.generatedElements) { |
| 452 |
IContributionItem ici = modelToContribution.remove(copy); |
| 453 |
if (ici != null) { |
| 454 |
record.manager.remove(ici); |
| 455 |
} |
| 456 |
} |
| 457 |
record.generatedElements.clear(); |
| 458 |
} |
| 459 |
} |
| 460 |
} |
92 |
} |
| 461 |
|
93 |
|
| 462 |
int getOrientation(final MUIElement element) { |
94 |
int getOrientation(final MUIElement element) { |
|
Lines 471-640
Link Here
|
| 471 |
return SWT.HORIZONTAL; |
103 |
return SWT.HORIZONTAL; |
| 472 |
} |
104 |
} |
| 473 |
|
105 |
|
| 474 |
/* |
106 |
public Object getUIContainer(MUIElement childElement) { |
| 475 |
* (non-Javadoc) |
107 |
Composite intermediate = (Composite) super.getUIContainer(childElement); |
| 476 |
* |
108 |
if (intermediate == null || intermediate.isDisposed()) { |
| 477 |
* @see |
109 |
return null; |
| 478 |
* org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents |
|
|
| 479 |
* (org.eclipse.e4.ui.model.application.ui.MElementContainer) |
| 480 |
*/ |
| 481 |
@Override |
| 482 |
public void processContents(MElementContainer<MUIElement> container) { |
| 483 |
// I can either simply stop processing, or we can walk the model |
| 484 |
// ourselves like the "old" days |
| 485 |
// EMF gives us null lists if empty |
| 486 |
if (container == null) |
| 487 |
return; |
| 488 |
|
| 489 |
Object obj = container; |
| 490 |
ToolBarManager parentManager = getManager((MToolBar) obj); |
| 491 |
if (parentManager == null) { |
| 492 |
return; |
| 493 |
} |
| 494 |
// Process any contents of the newly created ME |
| 495 |
List<MUIElement> parts = container.getChildren(); |
| 496 |
if (parts != null) { |
| 497 |
MUIElement[] plist = parts.toArray(new MUIElement[parts.size()]); |
| 498 |
for (int i = 0; i < plist.length; i++) { |
| 499 |
MUIElement childME = plist[i]; |
| 500 |
modelProcessSwitch(parentManager, (MToolBarElement) childME); |
| 501 |
} |
| 502 |
} |
| 503 |
parentManager.update(false); |
| 504 |
|
| 505 |
ToolBar tb = getToolbarFrom(container.getWidget()); |
| 506 |
if (tb != null && ((EObject) container).eContainer() instanceof MPart) { |
| 507 |
MPart part = (MPart) ((EObject) container).eContainer(); |
| 508 |
MMenu viewMenu = getViewMenu(part); |
| 509 |
|
| 510 |
// View menu (if any) |
| 511 |
if (viewMenu != null) { |
| 512 |
addMenuButton(part, tb, viewMenu); |
| 513 |
} |
| 514 |
tb.getShell().layout(new Control[] { tb }, SWT.DEFER); |
| 515 |
} |
110 |
} |
|
|
111 |
ToolBar toolbar = findToolbar(intermediate); |
| 112 |
if (toolbar == null) { |
| 113 |
toolbar = createToolbar(childElement.getParent(), intermediate); |
| 114 |
} |
| 115 |
return toolbar; |
| 516 |
} |
116 |
} |
| 517 |
|
117 |
|
| 518 |
/** |
118 |
ToolBar findToolbar(Composite intermediate) { |
| 519 |
* @param widget |
119 |
if (!intermediate.isDisposed()) { |
| 520 |
* @return |
120 |
Control[] children = intermediate.getChildren(); |
| 521 |
*/ |
121 |
int length = children.length; |
| 522 |
private ToolBar getToolbarFrom(Object widget) { |
122 |
if (length > 0 && children[length - 1] instanceof ToolBar) { |
| 523 |
if (widget instanceof ToolBar) { |
123 |
return (ToolBar) children[length - 1]; |
| 524 |
return (ToolBar) widget; |
|
|
| 525 |
} |
| 526 |
if (widget instanceof Composite) { |
| 527 |
Composite intermediate = (Composite) widget; |
| 528 |
if (!intermediate.isDisposed()) { |
| 529 |
Control[] children = intermediate.getChildren(); |
| 530 |
int length = children.length; |
| 531 |
if (length > 0 && children[length - 1] instanceof ToolBar) { |
| 532 |
return (ToolBar) children[length - 1]; |
| 533 |
} |
| 534 |
} |
124 |
} |
| 535 |
} |
125 |
} |
| 536 |
return null; |
126 |
return null; |
| 537 |
} |
127 |
} |
| 538 |
|
128 |
|
| 539 |
/** |
129 |
@Override |
| 540 |
* @param tb |
130 |
public void hideChild(MElementContainer<MUIElement> parentElement, |
| 541 |
*/ |
131 |
MUIElement child) { |
| 542 |
private void addMenuButton(MPart part, ToolBar tb, MMenu menu) { |
132 |
super.hideChild(parentElement, child); |
| 543 |
ToolItem ti = new ToolItem(tb, SWT.PUSH); |
|
|
| 544 |
ti.setImage(getViewMenuImage()); |
| 545 |
ti.setHotImage(null); |
| 546 |
ti.setToolTipText("View Menu"); //$NON-NLS-1$ |
| 547 |
ti.setData("theMenu", menu); //$NON-NLS-1$ |
| 548 |
ti.setData("thePart", part); //$NON-NLS-1$ |
| 549 |
|
| 550 |
ti.addSelectionListener(new SelectionListener() { |
| 551 |
public void widgetSelected(SelectionEvent e) { |
| 552 |
showMenu((ToolItem) e.widget); |
| 553 |
} |
| 554 |
|
| 555 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 556 |
showMenu((ToolItem) e.widget); |
| 557 |
} |
| 558 |
}); |
| 559 |
} |
| 560 |
|
133 |
|
| 561 |
/** |
134 |
// Since there's no place to 'store' a child that's not in a menu |
| 562 |
* @param item |
135 |
// we'll blow it away and re-create on an add |
| 563 |
*/ |
136 |
Widget widget = (Widget) child.getWidget(); |
| 564 |
protected void showMenu(ToolItem item) { |
137 |
if (widget != null && !widget.isDisposed()) { |
| 565 |
// Create the UI for the menu |
138 |
widget.dispose(); |
| 566 |
final MMenu menuModel = (MMenu) item.getData("theMenu"); //$NON-NLS-1$ |
|
|
| 567 |
MPart part = (MPart) item.getData("thePart"); //$NON-NLS-1$ |
| 568 |
Control ctrl = (Control) part.getWidget(); |
| 569 |
Menu menu = (Menu) renderer.createGui(menuModel, ctrl.getShell(), |
| 570 |
part.getContext()); |
| 571 |
|
| 572 |
// ...and Show it... |
| 573 |
Rectangle ib = item.getBounds(); |
| 574 |
Point displayAt = item.getParent().toDisplay(ib.x, ib.y + ib.height); |
| 575 |
menu.setLocation(displayAt); |
| 576 |
menu.setVisible(true); |
| 577 |
|
| 578 |
Display display = Display.getCurrent(); |
| 579 |
while (!menu.isDisposed() && menu.isVisible()) { |
| 580 |
if (!display.readAndDispatch()) |
| 581 |
display.sleep(); |
| 582 |
} |
| 583 |
menu.dispose(); |
| 584 |
} |
| 585 |
|
| 586 |
private Image getViewMenuImage() { |
| 587 |
if (viewMenuImage == null) { |
| 588 |
Display d = Display.getCurrent(); |
| 589 |
|
| 590 |
Image viewMenu = new Image(d, 16, 16); |
| 591 |
Image viewMenuMask = new Image(d, 16, 16); |
| 592 |
|
| 593 |
Display display = Display.getCurrent(); |
| 594 |
GC gc = new GC(viewMenu); |
| 595 |
GC maskgc = new GC(viewMenuMask); |
| 596 |
gc.setForeground(display |
| 597 |
.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); |
| 598 |
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); |
| 599 |
|
| 600 |
int[] shapeArray = new int[] { 6, 1, 15, 1, 11, 5, 10, 5 }; |
| 601 |
gc.fillPolygon(shapeArray); |
| 602 |
gc.drawPolygon(shapeArray); |
| 603 |
|
| 604 |
Color black = display.getSystemColor(SWT.COLOR_BLACK); |
| 605 |
Color white = display.getSystemColor(SWT.COLOR_WHITE); |
| 606 |
|
| 607 |
maskgc.setBackground(black); |
| 608 |
maskgc.fillRectangle(0, 0, 16, 16); |
| 609 |
|
| 610 |
maskgc.setBackground(white); |
| 611 |
maskgc.setForeground(white); |
| 612 |
maskgc.fillPolygon(shapeArray); |
| 613 |
maskgc.drawPolygon(shapeArray); |
| 614 |
gc.dispose(); |
| 615 |
maskgc.dispose(); |
| 616 |
|
| 617 |
ImageData data = viewMenu.getImageData(); |
| 618 |
data.transparentPixel = data.getPixel(0, 0); |
| 619 |
|
| 620 |
viewMenuImage = new Image(d, viewMenu.getImageData(), |
| 621 |
viewMenuMask.getImageData()); |
| 622 |
viewMenu.dispose(); |
| 623 |
viewMenuMask.dispose(); |
| 624 |
} |
139 |
} |
| 625 |
return viewMenuImage; |
140 |
ToolBar toolbar = (ToolBar) getUIContainer(child); |
|
|
141 |
if (toolbar != null && !toolbar.isDisposed()) { |
| 142 |
toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); |
| 143 |
} |
| 144 |
disposeToolbarIfNecessary(parentElement); |
| 626 |
} |
145 |
} |
| 627 |
|
146 |
|
| 628 |
private MMenu getViewMenu(MPart part) { |
147 |
private void disposeToolbarIfNecessary(MUIElement element) { |
| 629 |
if (part.getMenus() == null) { |
148 |
Composite composite = (Composite) element.getWidget(); |
| 630 |
return null; |
149 |
ToolBar toolbar = findToolbar(composite); |
| 631 |
} |
150 |
if (toolbar != null && hasOnlySeparators(toolbar)) { |
| 632 |
for (MMenu menu : part.getMenus()) { |
151 |
toolbar.dispose(); |
| 633 |
if (menu.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { |
152 |
if (composite.getChildren().length > 0) { |
| 634 |
return menu; |
153 |
composite.getChildren()[0].dispose(); |
| 635 |
} |
154 |
} |
| 636 |
} |
155 |
} |
| 637 |
return null; |
|
|
| 638 |
} |
156 |
} |
| 639 |
|
157 |
|
| 640 |
boolean hasOnlySeparators(ToolBar toolbar) { |
158 |
boolean hasOnlySeparators(ToolBar toolbar) { |
|
Lines 651-717
Link Here
|
| 651 |
} |
169 |
} |
| 652 |
|
170 |
|
| 653 |
@Override |
171 |
@Override |
| 654 |
public void postProcess(MUIElement element) { |
|
|
| 655 |
super.postProcess(element); |
| 656 |
// disposeToolbarIfNecessary(element); |
| 657 |
ToolBar tb = getToolbarFrom(element.getWidget()); |
| 658 |
if (tb != null && !tb.isDisposed()) { |
| 659 |
tb.getShell().layout(new Control[] { tb }, SWT.DEFER); |
| 660 |
tb.setVisible(true); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
public Object getUIContainer(MUIElement childElement) { |
| 665 |
if (childElement.getWidget() instanceof ToolBar) { |
| 666 |
return childElement.getWidget(); |
| 667 |
} |
| 668 |
|
| 669 |
Object obj = super.getUIContainer(childElement); |
| 670 |
if (obj instanceof ToolBar) { |
| 671 |
return obj; |
| 672 |
} |
| 673 |
|
| 674 |
if (obj instanceof Composite) { |
| 675 |
Composite intermediate = (Composite) obj; |
| 676 |
if (intermediate == null || intermediate.isDisposed()) { |
| 677 |
return null; |
| 678 |
} |
| 679 |
ToolBar toolbar = getToolbarFrom(intermediate); |
| 680 |
if (toolbar == null) { |
| 681 |
toolbar = createToolbar(childElement.getParent(), intermediate); |
| 682 |
} |
| 683 |
return toolbar; |
| 684 |
} |
| 685 |
return null; |
| 686 |
} |
| 687 |
|
| 688 |
@Override |
| 689 |
public void disposeWidget(MUIElement element) { |
| 690 |
ToolBar tb = getToolbarFrom(element.getWidget()); |
| 691 |
tb.setVisible(false); |
| 692 |
unbindWidget(element); |
| 693 |
tb.setData(AbstractPartRenderer.OWNING_ME, element); |
| 694 |
} |
| 695 |
|
| 696 |
@Override |
| 697 |
public void hideChild(MElementContainer<MUIElement> parentElement, |
| 698 |
MUIElement child) { |
| 699 |
super.hideChild(parentElement, child); |
| 700 |
|
| 701 |
// Since there's no place to 'store' a child that's not in a menu |
| 702 |
// we'll blow it away and re-create on an add |
| 703 |
Widget widget = (Widget) child.getWidget(); |
| 704 |
if (widget != null && !widget.isDisposed()) { |
| 705 |
widget.dispose(); |
| 706 |
} |
| 707 |
ToolBar toolbar = (ToolBar) getUIContainer(child); |
| 708 |
if (toolbar != null && !toolbar.isDisposed()) { |
| 709 |
toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); |
| 710 |
} |
| 711 |
// disposeToolbarIfNecessary(parentElement); |
| 712 |
} |
| 713 |
|
| 714 |
@Override |
| 715 |
public void childRendered(MElementContainer<MUIElement> parentElement, |
172 |
public void childRendered(MElementContainer<MUIElement> parentElement, |
| 716 |
MUIElement element) { |
173 |
MUIElement element) { |
| 717 |
super.childRendered(parentElement, element); |
174 |
super.childRendered(parentElement, element); |
|
Lines 721-826
Link Here
|
| 721 |
} |
178 |
} |
| 722 |
} |
179 |
} |
| 723 |
|
180 |
|
| 724 |
/** |
181 |
@Override |
| 725 |
* @param parentManager |
182 |
public void processContents(MElementContainer<MUIElement> container) { |
| 726 |
* @param childME |
183 |
super.processContents(container); |
| 727 |
*/ |
184 |
IEclipseContext ctx = getContext(container); |
| 728 |
private void modelProcessSwitch(ToolBarManager parentManager, |
185 |
ExpressionContext eContext = new ExpressionContext(ctx); |
| 729 |
MToolBarElement childME) { |
186 |
ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); |
| 730 |
if (childME instanceof MHandledToolItem) { |
187 |
MElementContainer<?> toolbarObj = container; |
| 731 |
MHandledToolItem itemModel = (MHandledToolItem) childME; |
188 |
MToolBar toolbarModel = (MToolBar) toolbarObj; |
| 732 |
processHandledItem(parentManager, itemModel); |
189 |
ContributionsAnalyzer.gatherToolBarContributions(toolbarModel, |
| 733 |
} else if (childME instanceof MDirectToolItem) { |
190 |
application.getToolBarContributions(), |
| 734 |
MDirectToolItem itemModel = (MDirectToolItem) childME; |
191 |
toolbarModel.getElementId(), toContribute, eContext); |
| 735 |
processDirectItem(parentManager, itemModel); |
192 |
addToolBarContributions(toolbarModel, toContribute, ctx, eContext, |
| 736 |
} else if (childME instanceof MToolBarSeparator) { |
193 |
pendingCleanup); |
| 737 |
MToolBarSeparator itemModel = (MToolBarSeparator) childME; |
|
|
| 738 |
processSeparator(parentManager, itemModel); |
| 739 |
} else if (childME instanceof MToolControl) { |
| 740 |
MToolControl itemModel = (MToolControl) childME; |
| 741 |
processToolControl(parentManager, itemModel); |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
/** |
| 746 |
* @param parentManager |
| 747 |
* @param itemModel |
| 748 |
*/ |
| 749 |
private void processSeparator(ToolBarManager parentManager, |
| 750 |
MToolBarSeparator itemModel) { |
| 751 |
AbstractGroupMarker marker = null; |
| 752 |
if (itemModel.isVisible()) { |
| 753 |
marker = new Separator(); |
| 754 |
marker.setId(itemModel.getElementId()); |
| 755 |
} else { |
| 756 |
if (itemModel.getElementId() != null) { |
| 757 |
marker = new GroupMarker(itemModel.getElementId()); |
| 758 |
} |
| 759 |
} |
| 760 |
parentManager.add(marker); |
| 761 |
} |
| 762 |
|
| 763 |
/** |
| 764 |
* @param parentManager |
| 765 |
* @param itemModel |
| 766 |
*/ |
| 767 |
private void processToolControl(ToolBarManager parentManager, |
| 768 |
MToolControl itemModel) { |
| 769 |
final IEclipseContext lclContext = getContext(itemModel); |
| 770 |
ToolControlContribution ci = ContextInjectionFactory.make( |
| 771 |
ToolControlContribution.class, lclContext); |
| 772 |
ci.setModel(itemModel); |
| 773 |
parentManager.add(ci); |
| 774 |
modelToContribution.put(itemModel, ci); |
| 775 |
} |
| 776 |
|
| 777 |
/** |
| 778 |
* @param parentManager |
| 779 |
* @param itemModel |
| 780 |
*/ |
| 781 |
private void processDirectItem(ToolBarManager parentManager, |
| 782 |
MDirectToolItem itemModel) { |
| 783 |
final IEclipseContext lclContext = getContext(itemModel); |
| 784 |
DirectContributionItem ci = ContextInjectionFactory.make( |
| 785 |
DirectContributionItem.class, lclContext); |
| 786 |
ci.setModel(itemModel); |
| 787 |
parentManager.add(ci); |
| 788 |
modelToContribution.put(itemModel, ci); |
| 789 |
} |
| 790 |
|
| 791 |
/** |
| 792 |
* @param parentManager |
| 793 |
* @param itemModel |
| 794 |
*/ |
| 795 |
private void processHandledItem(ToolBarManager parentManager, |
| 796 |
MHandledToolItem itemModel) { |
| 797 |
final IEclipseContext lclContext = getContext(itemModel); |
| 798 |
HandledContributionItem ci = ContextInjectionFactory.make( |
| 799 |
HandledContributionItem.class, lclContext); |
| 800 |
ci.setModel(itemModel); |
| 801 |
parentManager.add(ci); |
| 802 |
modelToContribution.put(itemModel, ci); |
| 803 |
} |
194 |
} |
| 804 |
|
195 |
|
| 805 |
public ToolBarManager getManager(MToolBar model) { |
196 |
@Override |
| 806 |
return modelToManager.get(model); |
197 |
public void postProcess(MUIElement element) { |
|
|
198 |
super.postProcess(element); |
| 199 |
disposeToolbarIfNecessary(element); |
| 807 |
} |
200 |
} |
| 808 |
|
201 |
|
| 809 |
public MToolBar getToolBarModel(ToolBarManager manager) { |
202 |
public static void addToolBarContributions( |
| 810 |
return managerToModel.get(manager); |
203 |
final MToolBar toolbarModel, |
| 811 |
} |
204 |
ArrayList<MToolBarContribution> toContribute, |
|
|
205 |
IEclipseContext ctx, |
| 206 |
final ExpressionContext eContext, |
| 207 |
HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup) { |
| 208 |
HashSet<String> existingSeparatorNames = new HashSet<String>(); |
| 209 |
for (MToolBarElement child : toolbarModel.getChildren()) { |
| 210 |
String elementId = child.getElementId(); |
| 211 |
if (child instanceof MToolBarSeparator && elementId != null) { |
| 212 |
existingSeparatorNames.add(elementId); |
| 213 |
} |
| 214 |
} |
| 215 |
boolean done = toContribute.size() == 0; |
| 216 |
while (!done) { |
| 217 |
ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>( |
| 218 |
toContribute); |
| 219 |
int retryCount = toContribute.size(); |
| 220 |
toContribute.clear(); |
| 812 |
|
221 |
|
| 813 |
public void linkModelToManager(MToolBar model, ToolBarManager manager) { |
222 |
for (final MToolBarContribution contribution : curList) { |
| 814 |
modelToManager.put(model, manager); |
223 |
final ArrayList<MToolBarElement> toRemove = new ArrayList<MToolBarElement>(); |
| 815 |
managerToModel.put(manager, model); |
224 |
if (!ContributionsAnalyzer.processAddition(toolbarModel, |
|
|
225 |
contribution, toRemove, existingSeparatorNames)) { |
| 226 |
toContribute.add(contribution); |
| 227 |
} else { |
| 228 |
if (contribution.getVisibleWhen() != null) { |
| 229 |
ctx.runAndTrack(new RunAndTrack() { |
| 230 |
@Override |
| 231 |
public boolean changed(IEclipseContext context) { |
| 232 |
if (!toolbarModel.isToBeRendered() |
| 233 |
|| !toolbarModel.isVisible() |
| 234 |
|| toolbarModel.getWidget() == null) { |
| 235 |
return false; |
| 236 |
} |
| 237 |
boolean rc = ContributionsAnalyzer.isVisible( |
| 238 |
contribution, eContext); |
| 239 |
for (MToolBarElement child : toRemove) { |
| 240 |
child.setToBeRendered(rc); |
| 241 |
} |
| 242 |
return true; |
| 243 |
} |
| 244 |
}); |
| 245 |
} |
| 246 |
ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup |
| 247 |
.get(toolbarModel); |
| 248 |
if (lists == null) { |
| 249 |
lists = new ArrayList<ArrayList<MToolBarElement>>(); |
| 250 |
pendingCleanup.put(toolbarModel, lists); |
| 251 |
} |
| 252 |
lists.add(toRemove); |
| 253 |
} |
| 254 |
} |
| 255 |
// We're done if the retryList is now empty (everything done) or |
| 256 |
// if the list hasn't changed at all (no hope) |
| 257 |
done = (toContribute.size() == 0) |
| 258 |
|| (toContribute.size() == retryCount); |
| 259 |
} |
| 816 |
} |
260 |
} |
| 817 |
|
261 |
|
| 818 |
public void clearModelToManager(MToolBar model, ToolBarManager manager) { |
262 |
protected void cleanUp(MToolBar element) { |
| 819 |
modelToManager.remove(model); |
263 |
ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup |
| 820 |
managerToModel.remove(manager); |
264 |
.remove(element); |
|
|
265 |
if (lists == null) { |
| 266 |
return; |
| 267 |
} |
| 268 |
for (ArrayList<MToolBarElement> list : lists) { |
| 269 |
for (MToolBarElement child : list) { |
| 270 |
element.getChildren().remove(child); |
| 271 |
} |
| 272 |
} |
| 821 |
} |
273 |
} |
| 822 |
|
274 |
|
| 823 |
public IContributionItem getContribution(MToolBarElement element) { |
|
|
| 824 |
return modelToContribution.get(element); |
| 825 |
} |
| 826 |
} |
275 |
} |