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();
}
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!");
}
}
}
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);
}
}
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);
}
}
}
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();
}
}
});
}
Aggregations