private IEclipseContext getStaticContext(Event event) { if (infoContext == null) { infoContext = EclipseContextFactory.create(DCI_STATIC_CONTEXT); ContributionsAnalyzer.populateModelInterfaces(getModel(), infoContext, getModel().getClass().getInterfaces()); } if (event == null) { infoContext.remove(Event.class); } else { infoContext.set(Event.class, event); } return infoContext; }
@Override public void dispose() { if (widget != null) { widget.dispose(); widget = null; getModel().setWidget(null); } }
@Override protected void updateMenuItem() { MenuItem item = (MenuItem) widget; String text = getModel().getLocalizedLabel(); if (text != null) { item.setText(text); } else { item.setText(""); //$NON-NLS-1$ } final String tooltip = getModel().getLocalizedTooltip(); item.setToolTipText(tooltip); item.setSelection(getModel().isSelected()); item.setEnabled(getModel().isEnabled()); }
private boolean checkContribution(IEclipseContext lclContext) { if (!(getModel() instanceof MContribution)) { return false; } MContribution contrib = (MContribution) getModel(); if (contrib.getObject() == null) { contrib.setObject(contribFactory.create( contrib.getContributionURI(), lclContext)); } return contrib.getObject() != null; }
@Override protected void updateToolItem() { ToolItem item = (ToolItem) widget; final String text = getModel().getLocalizedLabel(); Image icon = item.getImage(); boolean mode = getModel().getTags().contains(FORCE_TEXT); if ((icon == null || mode) && text != null) { item.setText(text); } else { item.setText(""); //$NON-NLS-1$ } final String tooltip = getModel().getLocalizedTooltip(); item.setToolTipText(tooltip); item.setSelection(getModel().isSelected()); item.setEnabled(getModel().isEnabled()); }
@Override protected boolean canExecuteItem(Event trigger) { final IEclipseContext lclContext = getContext(getModel()); if (!checkContribution(lclContext)) { return false; } MContribution contrib = (MContribution) getModel(); IEclipseContext staticContext = getStaticContext(trigger); Boolean result = ((Boolean) ContextInjectionFactory.invoke( contrib.getObject(), CanExecute.class, getExecutionContext(lclContext), staticContext, Boolean.TRUE)); return result.booleanValue(); }
@Override protected void executeItem(Event trigger) { final IEclipseContext lclContext = getContext(getModel()); if (!checkContribution(lclContext)) { return; } MContribution contrib = (MContribution) getModel(); IEclipseContext staticContext = getStaticContext(trigger); Object result = ContextInjectionFactory.invoke(contrib.getObject(), Execute.class, getExecutionContext(lclContext), staticContext, missingExecute); if (result == missingExecute && logger != null) { logger.error("Contribution is missing @Execute: " + contrib.getContributionURI()); //$NON-NLS-1$ } }
@Override protected void handleWidgetDispose(Event event) { if (event.widget == widget) { if (infoContext != null) { infoContext.dispose(); infoContext = null; } ToolItemUpdater updater = getUpdater(); if (updater != null) { updater.removeItem(this); } widget.removeListener(SWT.Selection, getItemListener()); widget.removeListener(SWT.Dispose, getItemListener()); widget.removeListener(SWT.DefaultSelection, getItemListener()); widget = null; Object obj = getModel().getTransientData().get(DISPOSABLE); if (obj instanceof Runnable) { ((Runnable) obj).run(); } getModel().setWidget(null); disposeOldImages(); } }