Search in sources :

Example 1 with Evaluate

use of org.eclipse.e4.core.di.annotations.Evaluate in project whole by wholeplatform.

the class AbstractSelectionConstrainedVisibleWhen method evaluate.

@Override
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
    ESelectionService selectionService = (ESelectionService) context.getVariable(ESelectionService.class.getName());
    Object selection = selectionService.getSelection();
    if (selection instanceof IBindingManager) {
        if (isVisible((IBindingManager) selection))
            return EvaluationResult.TRUE;
    }
    return EvaluationResult.FALSE;
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService)

Example 2 with Evaluate

use of org.eclipse.e4.core.di.annotations.Evaluate in project aero.minova.rcp by minova-afis.

the class PrintDetailHandler method visible.

/**
 * Button nur anzeigen, wenn in xbs definiert ist, dass gedruckt werden kann
 *
 * @param part
 * @return
 */
@Evaluate
public boolean visible(MPerspective mPerspective) {
    String maskName = mPerspective.getPersistedState().get(Constants.FORM_NAME);
    Preferences preferences = (Preferences) mApplication.getTransientData().get(Constants.XBS_FILE_NAME);
    Node maskNode = XBSUtil.getNodeWithName(preferences, maskName);
    return maskNode != null;
}
Also used : Node(aero.minova.rcp.form.setup.xbs.Node) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) Preferences(aero.minova.rcp.form.setup.xbs.Preferences) Evaluate(org.eclipse.e4.core.di.annotations.Evaluate)

Example 3 with Evaluate

use of org.eclipse.e4.core.di.annotations.Evaluate in project eclipse.platform.ui by eclipse-platform.

the class ContributionsAnalyzer method isImperativeExpressionVisible.

private static boolean isImperativeExpressionVisible(MImperativeExpression exp, final ExpressionContext eContext) {
    Object imperativeExpressionObject = exp.getObject();
    if (imperativeExpressionObject == null) {
        IContributionFactory contributionFactory = eContext.eclipseContext.get(IContributionFactory.class);
        Object newImperativeExpression = contributionFactory.create(exp.getContributionURI(), eContext.eclipseContext);
        exp.setObject(newImperativeExpression);
        imperativeExpressionObject = newImperativeExpression;
    }
    if (imperativeExpressionObject == null) {
        return false;
    }
    Object result = null;
    // $NON-NLS-1$
    IEclipseContext staticContext = EclipseContextFactory.create("Evaluation-Static");
    staticContext.set(MImperativeExpression.class, exp);
    try {
        if (exp.isTracking()) {
            result = invoke(imperativeExpressionObject, Evaluate.class, eContext.eclipseContext, staticContext, missingEvaluate);
        } else {
            result = ContextInjectionFactory.invoke(imperativeExpressionObject, Evaluate.class, eContext.eclipseContext, staticContext, missingEvaluate);
        }
    } finally {
        staticContext.dispose();
    }
    if (result == missingEvaluate) {
        // $NON-NLS-1$
        String className = "null";
        if (imperativeExpressionObject != null) {
            className = imperativeExpressionObject.getClass().getName();
        }
        throw new IllegalStateException(// $NON-NLS-1$ //$NON-NLS-2$
        "There is no method annotated with @Evaluate in the " + className + " imperative expression class ");
    }
    return (boolean) result;
}
Also used : Evaluate(org.eclipse.e4.core.di.annotations.Evaluate) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) EObject(org.eclipse.emf.ecore.EObject) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory)

Example 4 with Evaluate

use of org.eclipse.e4.core.di.annotations.Evaluate in project eclipse.platform.ui by eclipse-platform.

the class SaveAllHandler method evaluate.

@Override
protected EvaluationResult evaluate(IEvaluationContext context) {
    IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context);
    // no window? not active
    if (window == null)
        return EvaluationResult.FALSE;
    WorkbenchPage page = (WorkbenchPage) window.getActivePage();
    // no page? not active
    if (page == null)
        return EvaluationResult.FALSE;
    // if at least one dirty part, then we are active
    if (page.getDirtyParts().length > 0)
        return EvaluationResult.TRUE;
    EPartService partService = getPartService(window);
    if (partService != null && (partService.getDirtyParts().size() > 0)) {
        return EvaluationResult.TRUE;
    }
    // Since Save All also saves saveables from non-part sources,
    // look if any such saveables exist and are dirty.
    SaveablesList saveablesList = (SaveablesList) window.getWorkbench().getService(ISaveablesLifecycleListener.class);
    if (saveablesList == null) {
        return EvaluationResult.FALSE;
    }
    for (ISaveablesSource nonPartSource : saveablesList.getNonPartSources()) {
        Saveable[] saveables = nonPartSource.getSaveables();
        for (Saveable saveable : saveables) {
            if (saveable.isDirty()) {
                return EvaluationResult.TRUE;
            }
        }
    }
    // if nothing, then we are not active
    return EvaluationResult.FALSE;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Saveable(org.eclipse.ui.Saveable) ISaveablesSource(org.eclipse.ui.ISaveablesSource) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) WorkbenchPage(org.eclipse.ui.internal.WorkbenchPage) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) SaveablesList(org.eclipse.ui.internal.SaveablesList) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener)

Example 5 with Evaluate

use of org.eclipse.e4.core.di.annotations.Evaluate in project eclipse.platform.ui by eclipse-platform.

the class SaveAsHandler method evaluate.

@Override
protected EvaluationResult evaluate(IEvaluationContext context) {
    IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context);
    // no window? not active
    if (window == null)
        return EvaluationResult.FALSE;
    WorkbenchPage page = (WorkbenchPage) window.getActivePage();
    // no page? not active
    if (page == null)
        return EvaluationResult.FALSE;
    MPart activeMPart = getActivePart(window);
    IWorkbenchPart activePart = InternalHandlerUtil.getActivePart(context);
    ISaveablePart part = SaveableHelper.getSaveable(activePart);
    if (part == null && activeMPart != null && activeMPart.isDirty()) {
        return EvaluationResult.FALSE;
    }
    // get saveable part
    ISaveablePart saveablePart = getSaveablePart(context);
    if (saveablePart == null)
        return EvaluationResult.FALSE;
    // if its available, return whatever it says
    return saveablePart.isSaveAsAllowed() ? EvaluationResult.TRUE : EvaluationResult.FALSE;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) WorkbenchPage(org.eclipse.ui.internal.WorkbenchPage) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISaveablePart(org.eclipse.ui.ISaveablePart)

Aggregations

Evaluate (org.eclipse.e4.core.di.annotations.Evaluate)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 WorkbenchPage (org.eclipse.ui.internal.WorkbenchPage)2 Node (aero.minova.rcp.form.setup.xbs.Node)1 Preferences (aero.minova.rcp.form.setup.xbs.Preferences)1 ApplicationPreferences (aero.minova.rcp.preferences.ApplicationPreferences)1 Command (org.eclipse.core.commands.Command)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 Expression (org.eclipse.core.expressions.Expression)1 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 InvalidRegistryObjectException (org.eclipse.core.runtime.InvalidRegistryObjectException)1 EHandlerService (org.eclipse.e4.core.commands.EHandlerService)1 ExpressionContext (org.eclipse.e4.core.commands.ExpressionContext)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 IContributionFactory (org.eclipse.e4.core.services.contributions.IContributionFactory)1 MCommand (org.eclipse.e4.ui.model.application.commands.MCommand)1 MCoreExpression (org.eclipse.e4.ui.model.application.ui.MCoreExpression)1 MExpression (org.eclipse.e4.ui.model.application.ui.MExpression)1