Search in sources :

Example 1 with IEventBroker

use of org.eclipse.e4.core.services.events.IEventBroker in project ACS by ACS-Community.

the class PeriodicRefreshHandler method execute.

/**
	 * Starts a {@link NotifyServiceUpdateJob} with 10 seconds refresh period,
	 * which will notify the interested parts via the IEventBroker.
	 * <p>
	 * An alternative implementation could get parameter <code>@Active MPart part</code> injected
	 * and notify the part directly, without IEventBroker.
	 */
@Execute
public void execute(MHandledItem handledItem) {
    // sync menu item state
    sharedIsSelected = handledItem.isSelected();
    for (MItem menuItem : menuItemsToSync.values()) {
        menuItem.setSelected(sharedIsSelected);
    }
    // start or stop the periodic refresh job
    if (sharedIsSelected) {
        if (job == null) {
            // start periodic refreshes
            job = new NotifyServiceUpdateJob(eventModel, sync, statusLineWriter, eventBroker, refreshDelaySeconds * 1000);
            job.schedule();
            System.out.println("Scheduled refresh job.");
        } else {
            System.out.println("Error: refresh job is already running!");
        }
    } else {
        if (job != null) {
            job.cancel();
            job = null;
            System.out.println("Cancelled refresh job.");
        } else {
            System.out.println("Error: refresh job is already cancelled!");
        }
    }
}
Also used : MItem(org.eclipse.e4.ui.model.application.ui.menu.MItem) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 2 with IEventBroker

use of org.eclipse.e4.core.services.events.IEventBroker in project whole by wholeplatform.

the class E4Utils method suspendOperation.

public static void suspendOperation(SuspensionKind kind, Throwable throwable, IEntity sourceEntity, final IBindingManager bindings, Set<String> includeNames) {
    if (bindings.wIsSet("debug#reportModeEnabled") && !bindings.wBooleanValue("debug#reportModeEnabled"))
        return;
    if (bindings.wIsSet("debug#debugModeEnabled") && !bindings.wBooleanValue("debug#debugModeEnabled")) {
        if (kind.isError())
            E4Utils.reportError((IEclipseContext) bindings.wGetValue("eclipse#eclipseContext"), "Domain behavior error", "Error while executing domain behavior", throwable);
        return;
    }
    if (kind.isBreak() && bindings.wIsSet("debug#breakpointsEnabled") && !bindings.wBooleanValue("debug#breakpointsEnabled"))
        return;
    if (bindings.wIsSet("viewer") && ((IEntityPartViewer) bindings.wGetValue("viewer")).getControl().getDisplay().getThread() == Thread.currentThread()) {
        E4Utils.reportError((IEclipseContext) bindings.wGetValue("eclipse#eclipseContext"), "Domain behavior error", "Attempted suspension in UI thread", throwable);
        return;
    }
    final IEclipseContext context = (IEclipseContext) bindings.wGetValue("eclipse#eclipseContext");
    context.get(UISynchronize.class).syncExec(new Runnable() {

        public void run() {
            try {
                ClassLoader cl = ReflectionFactory.getPlatformClassLoader();
                Class<?> uiPluginClass = Class.forName("org.whole.lang.e4.ui.E4CompatibilityPlugin", true, cl);
                Method method = uiPluginClass.getMethod("revealPerspective", String.class);
                method.invoke(null, "org.whole.lang.ui.perspectives.LanguageWorkbenchDebugPerspectiveFactory");
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
            E4Utils.revealPart(context, IE4UIConstants.DEBUG_PART_ID);
            E4Utils.revealPart(context, IE4UIConstants.VARIABLES_PART_ID);
            if (bindings.wIsSet("self") && bindings.wIsSet("viewer")) {
                IEntity selfEntity = bindings.wGet("self");
                ((IEntityPartViewer) bindings.wGetValue("viewer")).selectAndReveal(selfEntity);
            }
            if (throwable instanceof IWholeFrameworkException) {
                IEntity messageModel = ((IWholeFrameworkException) throwable).getMessageModel();
                E4Utils.revealPart(context, IE4UIConstants.RESULTS_PART_ID);
                IEventBroker eventBroker = context.get(IEventBroker.class);
                eventBroker.post(IE4UIConstants.TOPIC_UPDATE_RESULTS, messageModel);
            }
        }
    });
    IEventBroker eventBroker = context.get(IEventBroker.class);
    ExecutionState execution = new ExecutionState(kind, throwable, sourceEntity, bindings, includeNames);
    eventBroker.post(IE4UIConstants.TOPIC_UPDATE_DEBUG, execution);
    execution.pause();
}
Also used : ExecutionState(org.whole.lang.e4.ui.jobs.ExecutionState) IEntity(org.whole.lang.model.IEntity) Method(java.lang.reflect.Method) WholeRuntimeException(org.whole.lang.exceptions.WholeRuntimeException) IWholeFrameworkException(org.whole.lang.exceptions.IWholeFrameworkException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IWholeFrameworkException(org.whole.lang.exceptions.IWholeFrameworkException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) UISynchronize(org.eclipse.e4.ui.di.UISynchronize) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker)

Example 3 with IEventBroker

use of org.eclipse.e4.core.services.events.IEventBroker in project whole by wholeplatform.

the class E4DebugGraphicalPart method updateUI.

protected void updateUI() {
    updateActions();
    IEventBroker eventBroker = context.get(IEventBroker.class);
    ExecutionState execution = executions.peek();
    if (execution != null) {
        final IEntity sourceEntity = execution.getSourceEntity();
        IEntity contents = EntityUtils.getCompoundRoot(sourceEntity);
        getViewer().setContents(contents);
        getViewer().setInteractive(contents, false, true, false);
        context.get(UISynchronize.class).asyncExec(new Runnable() {

            @Override
            public void run() {
                IEntity adaptee = sourceEntity.wGetAdaptee(false);
                IEntityPart sourceEntityPart = getViewer().getEditPartRegistry().get(adaptee);
                sourceEntityPart.installEditPolicy(SuspensionFeedbackEditPolicy.SUSPENSION_FEEDBACK_ROLE, new SuspensionFeedbackEditPolicy(getSuspensionKind(), execution.getThrowable()));
                getViewer().reveal(sourceEntity);
            }
        });
        eventBroker.post(IE4UIConstants.TOPIC_UPDATE_VARIABLES, execution.getVariablesModel());
    } else {
        getViewer().setEntityContents(createDefaultContents());
        eventBroker.post(IE4UIConstants.TOPIC_UPDATE_VARIABLES, null);
    }
}
Also used : ExecutionState(org.whole.lang.e4.ui.jobs.ExecutionState) IEntity(org.whole.lang.model.IEntity) SuspensionFeedbackEditPolicy(org.whole.lang.ui.editpolicies.SuspensionFeedbackEditPolicy) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker) UISynchronize(org.eclipse.e4.ui.di.UISynchronize) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 4 with IEventBroker

use of org.eclipse.e4.core.services.events.IEventBroker in project whole by wholeplatform.

the class ActionCallRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException {
    IEntity model = bm.wGet("self");
    boolean analyzing = bm.wBooleanValue("analyzing");
    if (analyzing) {
        // clone model if is analyzing
        model = EntityUtils.clone(model);
        CommonsEntityFactory.instance.createRootFragment(model.wGetAdapter(CommonsEntityDescriptorEnum.Any));
        ReflectionFactory.getHistoryManager(model).setHistoryEnabled(true);
        // map selected entities if analyzing
        IEntity tuple = bm.wGet("selectedEntities");
        int size = tuple.wSize();
        for (int i = 0; i < size; i++) tuple.wSet(i, EntityUtils.mapEntity(tuple.wGet(i), model));
        bm.wSet("primarySelectedEntity", EntityUtils.mapEntity(bm.wGet("primarySelectedEntity"), model));
        bm.wSet("focusEntity", EntityUtils.mapEntity(bm.wGet("focusEntity"), model));
    }
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    final CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    final ModelTransactionCommand mtc = new ModelTransactionCommand(model, label);
    pm.beginTask("executing action", 90, IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.actionCall(bm);
        mtc.commit();
        if (analyzing) {
            E4Utils.revealPart(context, RESULTS_PART_ID);
            IEventBroker eventBroker = context.get(IEventBroker.class);
            eventBroker.post(IE4UIConstants.TOPIC_UPDATE_RESULTS, bm.getResult());
        } else if (mtc.canUndo()) {
            context.get(UISynchronize.class).syncExec(new Runnable() {

                public void run() {
                    commandStack.execute(mtc);
                }
            });
        }
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        pm.endTask();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker)

Aggregations

IEventBroker (org.eclipse.e4.core.services.events.IEventBroker)3 IEntity (org.whole.lang.model.IEntity)3 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)2 ExecutionState (org.whole.lang.e4.ui.jobs.ExecutionState)2 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)2 Method (java.lang.reflect.Method)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 MItem (org.eclipse.e4.ui.model.application.ui.menu.MItem)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 IWholeFrameworkException (org.whole.lang.exceptions.IWholeFrameworkException)1 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)1 WholeRuntimeException (org.whole.lang.exceptions.WholeRuntimeException)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)1 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)1 SuspensionFeedbackEditPolicy (org.whole.lang.ui.editpolicies.SuspensionFeedbackEditPolicy)1