Search in sources :

Example 1 with Execute

use of org.eclipse.e4.core.di.annotations.Execute in project ACS by ACS-Community.

the class CopyDetailsToClipboardHandler method execute.

/**
	 * Receives the selection from the event detail part.
	 * <p>
	 * It may be my lack of understanding of good Eclipse 4 RCP practices that I wish
	 * I could handle the mouse menu action locally in the event detail part,
	 * instead of sending the data via selection service to separate handler.
	 * Perhaps to be refactored once this becomes clearer. 
	 */
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ParsedAnyData[] parsedAnyData) throws ExecutionException {
    if (parsedAnyData == null || parsedAnyData.length == 0) {
        return;
    }
    System.out.println("Will copy event details to the clipboard...");
    // Convert selected table rows into a multi-line String
    StringBuilder sb = new StringBuilder();
    for (ParsedAnyData parsedAny : parsedAnyData) {
        sb.append(parsedAnyDataToString(parsedAny));
    }
    // Write that data to the system clipboard
    Clipboard cb = new Clipboard(Display.getCurrent());
    TextTransfer textTransfer = TextTransfer.getInstance();
    cb.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
    cb.dispose();
}
Also used : ParsedAnyData(alma.acs.eventbrowser.parts.ParsedAnyData) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 2 with Execute

use of org.eclipse.e4.core.di.annotations.Execute 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 3 with Execute

use of org.eclipse.e4.core.di.annotations.Execute in project ACS by ACS-Community.

the class SubscribeNCHandler method execute.

/**
	 * Allows one or many NCs to be selected, which is why we use 'Object' instead of 'ChannelData' as the selection.
	 */
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object obj, MHandledItem handledItem) {
    List<ChannelData> ncList = getSelectedNCs(obj);
    for (ChannelData nc : ncList) {
        // We simply toggle the subscription, ignoring the CHECK menu item state.
        // In fact we have to manually toggle the menu in the end, since the UI-induced toggling got lost 
        // when eclipse called 'canExecute' right before this method.
        boolean previousIsSubscribed = eventModel.isSubscribed(nc);
        SubscriptionChangeJob job = (previousIsSubscribed ? new UnsubscribeJob(nc) : new SubscribeJob(nc));
        subscriptionChangeJobMap.put(nc.getName(), job);
        job.schedule();
        handledItem.setSelected(!previousIsSubscribed);
    }
}
Also used : ChannelData(alma.acs.nsstatistics.ChannelData) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 4 with Execute

use of org.eclipse.e4.core.di.annotations.Execute in project ACS by ACS-Community.

the class SaveHandler method execute.

@Execute
public void execute(Shell shell) {
    System.out.println("Saving...");
    FileDialog fileChooser = new FileDialog(shell, SWT.SAVE);
    String fileName = fileChooser.open();
    if (fileName == null) {
        System.out.println("No file to save");
    } else {
        System.out.println("File to save: " + fileName);
        File fileToSave = new File(fileName);
        try {
            SaveData saveHelper = new SaveData(SaveData.FileContentType.WIKI, fileToSave);
        } catch (Throwable t) {
            System.err.println(t.getMessage());
            t.printStackTrace(System.err);
        }
    }
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) SaveData(alma.acs.alarmsystemprofiler.save.SaveData) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 5 with Execute

use of org.eclipse.e4.core.di.annotations.Execute in project eclipse.themes.darker by jinmingjian.

the class DarkerThemer method onExecute.

@Execute
public void onExecute() {
    eventBroker.subscribe(IThemeEngine.Events.THEME_CHANGED, new EventHandler() {

        public void handleEvent(Event event) {
            ITheme currentTheme = (ITheme) event.getProperty(IThemeEngine.Events.THEME);
            // THEME_DARKER_PREF_THEMEENABLED, false))
            if (currentTheme.getId().equals(THEME_DARKER_ID)) {
                setupPreferences();
                isLastThemeDarker = true;
                DarkerWeavingHook.enableWeaving();
                hookDarkerCore();
            } else if (isLastThemeDarker) {
                DarkerWeavingHook.disableWeaving();
                setToDefaultPreferences();
            }
        }
    });
}
Also used : ITheme(org.eclipse.e4.ui.css.swt.theme.ITheme) EventHandler(org.osgi.service.event.EventHandler) Event(org.osgi.service.event.Event) Execute(org.eclipse.e4.core.di.annotations.Execute)

Aggregations

Execute (org.eclipse.e4.core.di.annotations.Execute)5 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)3 SaveData (alma.acs.alarmsystemprofiler.save.SaveData)1 ParsedAnyData (alma.acs.eventbrowser.parts.ParsedAnyData)1 ChannelData (alma.acs.nsstatistics.ChannelData)1 File (java.io.File)1 ITheme (org.eclipse.e4.ui.css.swt.theme.ITheme)1 MItem (org.eclipse.e4.ui.model.application.ui.menu.MItem)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Event (org.osgi.service.event.Event)1 EventHandler (org.osgi.service.event.EventHandler)1