org.eclipse.e4.core.services.events.IEventBroker Java Examples

The following examples show how to use org.eclipse.e4.core.services.events.IEventBroker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PCalTranslateAutomaticallyHandler.java    From tlaplus with MIT License 6 votes vote down vote up
@Inject
public void initializeAtStartup(final IWorkbench workbench, final ICommandService commandService) {
	/*
	 * Check the UI state of the IHandler/Command which indicates if the user
	 * enabled automatic PlusCal conversion.
	 */
	final Command command = commandService.getCommand("toolbox.command.module.translate.automatially");
	final State state = command.getState(RegistryToggleState.STATE_ID);
	if (!((Boolean) state.getValue()).booleanValue()) {
		return;
	}
	// This IHander is stateful even across Toolbox restarts. In other words, if the
	// user enables automatic PlusCal translation, it will remain enabled even after
	// a Toolbox restart. This means we have to register this EventHandler at the
	// IEventBroker during Toolbox startup.
	// It is vital that we use the Workbench's IEventBroker instance. If e.g. we
	// would use an IEventBroker from higher up the IEclipseContext hierarchy, the
	// broker would be disposed when a new spec gets opened while the IHandler's state
	// remains enabled.
	workbench.getService(IEventBroker.class).unsubscribe(this);
	Assert.isTrue(workbench.getService(IEventBroker.class).subscribe(TLAEditor.PRE_SAVE_EVENT, this));
}
 
Example #2
Source File: AbstractPDFViewerRunnable.java    From tlaplus with MIT License 6 votes vote down vote up
public AbstractPDFViewerRunnable(ProducePDFHandler handler, IWorkbenchPartSite site, IResource aSpecFile) {
	Assert.isNotNull(handler);
	Assert.isNotNull(site);
	Assert.isNotNull(aSpecFile);
	this.handler = handler;
	this.specFile = aSpecFile;
	
	final boolean autoRegenerate = TLA2TeXActivator.getDefault().getPreferenceStore()
			.getBoolean(ITLA2TeXPreferenceConstants.AUTO_REGENERATE);
	if (autoRegenerate) {
		// Subscribe to the event bus with which the TLA Editor save events are
		// distributed. In other words, every time the user saves a spec, we
		// receive an event and provided the spec corresponds to this PDF, we
		// regenerate it.
		// Don't subscribe in EmbeddedPDFViewerRunnable#though, because it is run
		// repeatedly and thus would cause us to subscribe multiple times.
		final IEventBroker eventService = site.getService(IEventBroker.class);
		Assert.isTrue(eventService.subscribe(TLAEditor.SAVE_EVENT, this));
		
		// Register for part close events to deregister the event handler
		// subscribed to the event bus. There is no point in regenerating
		// the PDF if no PDFEditor is open anymore.
		final IPartService partService = site.getService(IPartService.class);
		partService.addPartListener(this);
	}
}
 
Example #3
Source File: PCalTranslateAutomaticallyHandler.java    From tlaplus with MIT License 5 votes vote down vote up
@Execute
public void execute(final ExecutionEvent event, final IWorkbench workbench) throws ExecutionException {
	// Toggle the IHandler's state at the UI level (check mark on/off) and
	// unsubscribe/subscribe the EventHandler.
	final IEventBroker eventBroker = workbench.getService(IEventBroker.class);
	if (HandlerUtil.toggleCommandState(event.getCommand())) {
		eventBroker.unsubscribe(this);
	} else {
		eventBroker.unsubscribe(this);
		Assert.isTrue(eventBroker.subscribe(TLAEditor.PRE_SAVE_EVENT, this));
	}
}
 
Example #4
Source File: PCalTranslateAutomaticallyHandler.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
public void handleEvent(final Event event) {
	try {
		final TLAEditor editor = (TLAEditor) event.getProperty(IEventBroker.DATA);
		translate(editor, editor.getSite().getShell(), false);
	} catch (InvocationTargetException | InterruptedException e) {
		throw new RuntimeException(e);
	}
}
 
Example #5
Source File: AbstractPDFViewerRunnable.java    From tlaplus with MIT License 5 votes vote down vote up
public void handleEvent(final Event event) {
	// Listen for TLAEditor/save to regenerate the PDF and refresh the
	// editor iff the event DATA corresponds to this.specFile. There might
	// be several PDFs open each responsible for a certain spec.
	if (TLAEditor.SAVE_EVENT.equals(event.getTopic())) {
		final Object property = event.getProperty(IEventBroker.DATA);
		if (property instanceof IFile && this.specFile.equals(property)) {
			preUpdate();
			handler.runPDFJob(this, specFile);
		}
	}
}
 
Example #6
Source File: AbstractPDFViewerRunnable.java    From tlaplus with MIT License 5 votes vote down vote up
public void partClosed(IWorkbenchPart aPart) {
	// Listen for PDFEditor close events to de-register this event listener
	// from receiving further TLAEditor/save events. If the user closes the
	// PDFEditor, it implicitly means she's no longer interested in the PDF.
	if (aPart == part) {
		final IEventBroker service = aPart.getSite().getService(IEventBroker.class);
		service.unsubscribe(this);
	}
}
 
Example #7
Source File: TLAEditor.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
  public void createPartControl(final Composite parent)
  {
      super.createPartControl(parent);
      /*
       * Add projection support (i.e. for folding) 
       */
      final ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
      projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
      projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
      projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
      projectionSupport.install();
      
if (viewer.canDoOperation(ProjectionViewer.TOGGLE)) {
	viewer.doOperation(ProjectionViewer.TOGGLE);
}

      // model for adding projections (folds)
      annotationModel = viewer.getProjectionAnnotationModel();

      // this must be instantiated after annotationModel so that it does
      // not call methods that use annotation model when the model is still null
      proofStructureProvider = new TLAProofFoldingStructureProvider(this);
      
      // refresh the editor in case it should be
      // read only
      refresh();

      // tlapmColoring = new TLAPMColoringOutputListener(this);
      
      service = this.getSite().getService(IEventBroker.class);
  }
 
Example #8
Source File: EsbEditorEvent.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public static void CreateBroker(String pluginId) {

		Bundle bundle = Platform.getBundle(pluginId);
		IEclipseContext eclipseContext = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
		eclipseContext.set(org.eclipse.e4.core.services.log.Logger.class, null);
		iEventBroker = eclipseContext.get(IEventBroker.class);
	}
 
Example #9
Source File: ActiveOrganizationProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public void saveActiveOrganization(final String organizationName) {
    getPreferenceNode().put(OrganizationPreferenceConstants.DEFAULT_ORGANIZATION, organizationName);
    try {
        getPreferenceNode().flush();
        PlatformUI.getWorkbench().getService(IEventBroker.class).send(ACTIVE_ORGANIZATION_CHANGED, organizationName);
    } catch (final BackingStoreException e) {
        BonitaStudioLog.error(e);
    }
}
 
Example #10
Source File: QuitHandler.java    From offspring with MIT License 5 votes vote down vote up
@Execute
public void execute(Display display, IEventBroker broker, INxtService nxt,
    IDataProviderPool pool, IWorkbench workbench, UISynchronize sync) {
  if (Shutdown.execute(display.getActiveShell(), broker, sync, nxt, pool)) {
    workbench.close();
  }
}
 
Example #11
Source File: ApplicationConfiguration.java    From warcraft-remake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Execute the injection.
 * 
 * @param eventBroker The event broker service.
 */
@PostConstruct
public void execute(IEventBroker eventBroker)
{
    final MWindow existingWindow = application.getChildren().get(0);
    existingWindow.setLabel(Activator.PLUGIN_NAME);
    eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new AppStartupCompleteEventHandler());
}
 
Example #12
Source File: AssetExchangeImpl.java    From offspring with MIT License 4 votes vote down vote up
@Override
public void initialize(IEventBroker broker) {
  this.broker = broker;
}
 
Example #13
Source File: OpenIntroAddon.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@PostConstruct
public void pc(IEventBroker eventBroker, RepositoryAccessor repositoryAccessor) {
    this.repositoryAccessor = repositoryAccessor;
    eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, this::handleEvent);
}
 
Example #14
Source File: EsbEditorEvent.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
public static IEventBroker getiEventBroker() {
	return iEventBroker;
}
 
Example #15
Source File: GenerateBDMOperation.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected IEventBroker eventBroker() {
    return (IEventBroker) PlatformUI.getWorkbench().getService(IEventBroker.class);
}
 
Example #16
Source File: BusinessObjectModelFileStore.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected Optional<IEventBroker> eventBroker() {
    if (PlatformUI.isWorkbenchRunning()) {
        return Optional.of(PlatformUI.getWorkbench().getService(IEventBroker.class));
    }
    return Optional.empty();
}
 
Example #17
Source File: DeleteBDMEventHandler.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@PostConstruct
public void registerHandler(IEventBroker eventBroker) {
    eventBroker.subscribe(BDM_DELETED_TOPIC, this);
}
 
Example #18
Source File: PostBDMEventHandler.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@PostConstruct
public void registerHandler(IEventBroker eventBroker) {
    eventBroker.subscribe(BDM_DEPLOYED_TOPIC, this);
}
 
Example #19
Source File: NXTService.java    From offspring with MIT License 4 votes vote down vote up
@Override
public IEventBroker getEventBroker() {
  return broker;
}
 
Example #20
Source File: NXTService.java    From offspring with MIT License 4 votes vote down vote up
@Override
public void initialize(IEventBroker _broker, final UISynchronize sync) {
  this.broker = _broker;

  logger.info("Initialize START");
  listeners = new NXTListeners(broker, this);

  H2ListenerHelper.getInstance().initialize(broker);
  initializing = true;

  /* Start the initialization process */
  broker.post(INxtService.TOPIC_INITIALIZATION_START, 1);

  /* The first block scanned signals reading of database is complete */
  broker.subscribe(INxtService.TOPIC_BLOCK_SCANNED, new EventHandler() {

    @Override
    public void handleEvent(Event event) {
      broker.unsubscribe(this);
      setScanning(true);
      broker.post(INxtService.TOPIC_BLOCK_SCANNER_START, 1);
    }
  });

  logger.info("NXT init START");

  try {
    /* Read the database file AND iterate over all records in database */
    Nxt.init(Config.properties);
  }
  catch (final Throwable t) {
    sync.syncExec(new Runnable() {

      @Override
      public void run() {
        MessageDialog
            .openError(
                Display.getDefault().getActiveShell(),
                "NXT initialization Error",
                "A fatal error occured initializing NXT.\n"
                    + "If this keeps occuring consider to delete NXT database folder.\n\n"
                    + t.toString());
      }
    });
    System.exit(-1);
    return;
  }

  logger.info("NXT init END");

  broker.post(INxtService.TOPIC_BLOCK_SCANNER_FINISHED, getBlockCount());

  broker.post(INxtService.TOPIC_INITIALIZATION_FINISHED, 1);
  setScanning(false);

  initializing = false;
  logger.info("Initialization COMPLETE");

  /* Nxt initialized and ready turn on forging for all accounts */
  sync.asyncExec(new Runnable() {

    @Override
    public void run() {
      for (IAccount account : unlockedAccounts) {
        account.startForging();
      }
    }
  });
}
 
Example #21
Source File: H2ListenerHelper.java    From offspring with MIT License 4 votes vote down vote up
public IEventBroker getEventBroker() {
  return broker;
}
 
Example #22
Source File: H2ListenerHelper.java    From offspring with MIT License 4 votes vote down vote up
public void initialize(IEventBroker broker) {
  this.broker = broker;
}
 
Example #23
Source File: Shutdown.java    From offspring with MIT License 4 votes vote down vote up
public static boolean execute(Shell shell, IEventBroker broker,
    UISynchronize sync, final INxtService nxt, final IDataProviderPool pool) {

  if (!MessageDialog.openConfirm(shell, "Shutdown Offspring",
      "Are you sure you want to shutdown Offspring?")) {
    return false;
  }

  final StartupDialog dialog = new StartupDialog(shell, sync);
  dialog.setBlockOnOpen(true);
  dialog.showOKButton(false);
  dialog.create();

  Job startupJob = new Job("Startup Job") {

    volatile boolean DONE = false;

    @Override
    protected IStatus run(final IProgressMonitor monitor) {
      Thread cancelThread = new Thread(new Runnable() {

        @Override
        public void run() {
          while (!DONE) {
            try {
              Thread.sleep(500);
              if (monitor.isCanceled()) {
                System.exit(-1);
                return;
              }
            }
            catch (InterruptedException e) {
              return;
            }
          }
        }

      });
      cancelThread.start();

      try {
        monitor.beginTask("Shutting down dataprovider pools",
            IProgressMonitor.UNKNOWN);
        pool.destroy();

        monitor.setTaskName("Shutting down NXT");
        nxt.shutdown();

        monitor.done();
      }
      finally {
        DONE = true;
      }
      return Status.OK_STATUS;
    }
  };
  Job.getJobManager().setProgressProvider(new ProgressProvider() {

    @Override
    public IProgressMonitor createMonitor(Job job) {
      return dialog.getProgressMonitor();
    }
  });
  startupJob.schedule();
  dialog.open();
  //
  //
  // BusyIndicator.showWhile(shell.getDisplay(), new Runnable() {
  //
  // @Override
  // public void run() {
  // nxt.shutdown();
  // pool.destroy();
  // }
  // });

  return true;
}
 
Example #24
Source File: LifeCycleManager.java    From offspring with MIT License 4 votes vote down vote up
@PostContextCreate
void postContextCreate(IApplicationContext context, Display display,
    final IEventBroker broker, final INxtService nxt, IWallet wallet,
    UISynchronize sync, IUserService userService, IDataProviderPool pool) {

  logger.info("LifeCycleManager.postContextCreate");

  String appId = "com.dgex.offspring.application.lifecycle.LifeCycleManager";
  boolean alreadyRunning;
  try {
    JUnique.acquireLock(appId);
    alreadyRunning = false;
  }
  catch (AlreadyLockedException e) {
    alreadyRunning = true;
  }
  if (alreadyRunning) {
    File home = new File(System.getProperty("user.home") + File.separator
        + ".junique");

    MessageDialog
        .openWarning(
            display.getActiveShell(),
            "Offspring Already Running",
            "Offspring is already running.\n\n"
                + "If you keep seeing this dialog close Offspring with your taskmanager.\n\n"
                + "Cannot find Offspring in your taskmanager?\n"
                + "Then delete this folder " + home.getAbsolutePath());
    System.exit(0);
    return;
  }

  context.applicationRunning();

  final LoginDialog loginDialog = new LoginDialog(Display.getCurrent()
      .getActiveShell(), wallet);
  loginDialog.setBlockOnOpen(true);

  if (loginDialog.open() != Window.OK)
    System.exit(0);

  /* Must re-initialize if user selected to use test net (write new config) */
  if (Config.nxtIsTestNet) {
    Config.initialize();
  }
}
 
Example #25
Source File: UserServiceImpl.java    From offspring with MIT License 4 votes vote down vote up
@Override
public void initialize(IEventBroker broker, INxtService nxt) {
  this.nxt = nxt;
  this.broker = broker;
}
 
Example #26
Source File: INxtService.java    From offspring with MIT License 2 votes vote down vote up
/**
 * Returns the IEventBroker
 * 
 * @return
 */
public IEventBroker getEventBroker();
 
Example #27
Source File: INxtService.java    From offspring with MIT License 2 votes vote down vote up
/**
 * The IEventBroker is not available until later, thats why we pass it here as
 * an argument. The initialize method calls Nxt.init()
 * 
 * @param broker
 * @param sync
 */
public void initialize(IEventBroker broker, UISynchronize sync);
 
Example #28
Source File: IAssetExchange.java    From offspring with MIT License votes vote down vote up
public void initialize(IEventBroker broker); 
Example #29
Source File: IUserService.java    From offspring with MIT License votes vote down vote up
public void initialize(IEventBroker eventBroker, INxtService nxt);