/** * @param menuModel * @param manager * @param menuContribution * @return true if the menuContribution was processed */ private boolean processAddition( MMenu menuModel, final MenuManager manager, MMenuContribution menuContribution, final HashSet<String> existingMenuIds, HashSet<String> existingSeparatorNames, boolean menuBar) { final ContributionRecord record = new ContributionRecord(menuModel, menuContribution, this); if (!record.mergeIntoModel()) { return false; } if (menuBar) { final IEclipseContext parentContext = modelService.getContainingContext(menuModel); parentContext.runAndTrack( new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { record.updateVisibility(parentContext.getActiveLeaf()); manager.update(true); return true; } }); } return true; }
public static void initializeApplicationServices(IEclipseContext appContext) { final IEclipseContext theContext = appContext; // we add a special tracker to bring up current selection from // the active window to the application level appContext.runAndTrack( new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { IEclipseContext activeChildContext = context.getActiveChild(); if (activeChildContext != null) { Object selection = activeChildContext.get(IServiceConstants.ACTIVE_SELECTION); theContext.set(IServiceConstants.ACTIVE_SELECTION, selection); } return true; } }); // we create a selection service handle on every node that we are asked // about as handle needs to know its context appContext.set( ESelectionService.class.getName(), new ContextFunction() { @Override public Object compute(IEclipseContext context, String contextKey) { return ContextInjectionFactory.make(SelectionServiceImpl.class, context); } }); }
/** * Tests setting a value in a context that a RAT is listening to. This test mimics what occurs * when handlers change in e4. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=305038 */ public void testSetValueRunAndTrack() { context.set( "somefunction", new ContextFunction() { @Override public Object compute(IEclipseContext context, String contextKey) { // make sure this function has a large number of dependencies for (int i = 0; i < 1000; i++) { context.get("NonExistentValue-" + i); } return context.get("something"); } }); context.runAndTrack( new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { context.get("somefunction"); return true; } }); new PerformanceTestRunner() { int i = 0; @Override protected void test() { context.set("something", "value-" + i++); } }.run(this, 10, 400); }
public static void addToolBarContributions( final MToolBar toolbarModel, ArrayList<MToolBarContribution> toContribute, IEclipseContext ctx, final ExpressionContext eContext, HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup) { HashSet<String> existingSeparatorNames = new HashSet<String>(); for (MToolBarElement child : toolbarModel.getChildren()) { String elementId = child.getElementId(); if (child instanceof MToolBarSeparator && elementId != null) { existingSeparatorNames.add(elementId); } } boolean done = toContribute.size() == 0; while (!done) { ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>(toContribute); int retryCount = toContribute.size(); toContribute.clear(); for (final MToolBarContribution contribution : curList) { final ArrayList<MToolBarElement> toRemove = new ArrayList<MToolBarElement>(); if (!ContributionsAnalyzer.processAddition( toolbarModel, contribution, toRemove, existingSeparatorNames)) { toContribute.add(contribution); } else { if (contribution.getVisibleWhen() != null) { ctx.runAndTrack( new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { if (!toolbarModel.isToBeRendered() || !toolbarModel.isVisible() || toolbarModel.getWidget() == null) { return false; } boolean rc = ContributionsAnalyzer.isVisible(contribution, eContext); for (MToolBarElement child : toRemove) { child.setToBeRendered(rc); } return true; } }); } ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup.get(toolbarModel); if (lists == null) { lists = new ArrayList<ArrayList<MToolBarElement>>(); pendingCleanup.put(toolbarModel, lists); } lists.add(toRemove); } } // We're done if the retryList is now empty (everything done) or // if the list hasn't changed at all (no hope) done = (toContribute.size() == 0) || (toContribute.size() == retryCount); } }
@Override public void get( IObjectDescriptor[] descriptors, Object[] actualArgs, final IRequestor requestor, boolean initial, boolean track, boolean group) { final String[] keys = new String[descriptors.length]; final boolean[] active = new boolean[descriptors.length]; for (int i = 0; i < descriptors.length; i++) { String key = getKey(descriptors[i]); if ((actualArgs[i] == IInjector.NOT_A_VALUE)) keys[i] = key; else if (ECLIPSE_CONTEXT_NAME.equals(key)) // allow provider to override IEclipseContext keys[i] = ECLIPSE_CONTEXT_NAME; else keys[i] = null; if (descriptors[i] == null) active[i] = false; else active[i] = (descriptors[i].hasQualifier(Active.class)); } if (requestor != null && track) { // only track if requested if (initial) { RunAndTrack trackable = new ContextInjectionListener(context, actualArgs, keys, active, requestor, group); context.runAndTrack(trackable); } else { // we do track if this is done inside a computation, but don't create another // runnable fillArgs(actualArgs, keys, active); } } else { if (descriptors.length > 0) { pauseRecording(); try { fillArgs(actualArgs, keys, active); } finally { resumeRecording(); } } } }
/** * @param toolbarModel * @param manager * @param contribution * @param existingSeparatorNames * @return <code>true</code> if the contribution was successfuly processed */ private boolean processAddition( final MToolBar toolbarModel, final ToolBarManager manager, MToolBarContribution contribution) { final ToolBarContributionRecord record = new ToolBarContributionRecord(toolbarModel, contribution, this); if (!record.mergeIntoModel()) { return false; } if (record.anyVisibleWhen()) { final IEclipseContext parentContext = getContext(toolbarModel); parentContext.runAndTrack( new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { if (getManager(toolbarModel) == null) { // tool bar no longer being managed, ignore it return false; } record.updateVisibility(parentContext.getActiveLeaf()); runExternalCode( new Runnable() { public void run() { manager.update(false); } }); // disposeToolbarIfNecessary(toolbarModel); return true; } }); } return true; }