use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem 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.ui.model.application.ui.menu.MHandledItem in project ACS by ACS-Community.
the class SubscribeNCHandler method canExecute.
@CanExecute
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object obj, MHandledItem handledItem) {
boolean canExecute = false;
if (subscriptionChangeJobMap.isEmpty()) {
// disable while previous subscription change actions are still running
List<ChannelData> ncList = getSelectedNCs(obj);
if (!ncList.isEmpty()) {
canExecute = true;
// if multiple NCs are selected, they must all be in the same subscription state,
// otherwise we don't allow the subscription change
Boolean sharedIsSubscribed = null;
for (ChannelData nc : ncList) {
// all selected NCs must be subscribable
if (!nc.isSubscribable()) {
canExecute = false;
break;
}
if (sharedIsSubscribed == null) {
// the first NC we are checking
sharedIsSubscribed = new Boolean(eventModel.isSubscribed(nc));
} else {
if (eventModel.isSubscribed(nc) != sharedIsSubscribed.booleanValue()) {
canExecute = false;
break;
}
}
}
// We dynamically update the menu item state to display the correct toggle symbol.
if (canExecute) {
handledItem.setSelected(sharedIsSubscribed);
}
}
}
return canExecute;
}
use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem 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.ui.model.application.ui.menu.MHandledItem in project eclipse.platform.ui by eclipse-platform.
the class CustomizePerspectiveDialog method getToolTipText.
private String getToolTipText(MItem item) {
String text = item.getLocalizedTooltip();
if (item instanceof MHandledItem) {
MHandledItem handledItem = (MHandledItem) item;
EBindingService bs = context.get(EBindingService.class);
ParameterizedCommand cmd = handledItem.getWbCommand();
if (cmd == null) {
cmd = generateParameterizedCommand(handledItem, context);
}
TriggerSequence sequence = bs.getBestSequenceFor(handledItem.getWbCommand());
if (sequence != null) {
if (text == null) {
try {
text = cmd.getName();
} catch (NotDefinedException e) {
return null;
}
}
// $NON-NLS-1$
text = text + " (" + sequence.format() + ')';
}
return text;
} else if (OpaqueElementUtil.isOpaqueMenuItem(item)) {
Object opaque = OpaqueElementUtil.getOpaqueItem(item);
if (opaque instanceof ActionContributionItem) {
return ((ActionContributionItem) opaque).getAction().getText();
}
} else if (OpaqueElementUtil.isOpaqueToolItem(item)) {
Object opaque = OpaqueElementUtil.getOpaqueItem(item);
if (opaque instanceof ActionContributionItem) {
return ((ActionContributionItem) opaque).getAction().getToolTipText();
}
}
return text;
}
use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem in project eclipse.platform.ui by eclipse-platform.
the class MenuPopulationTest method assertIcon.
private void assertIcon(HandledContributionItem item, String targetIcon) {
final MHandledItem model = item.getModel();
String iconString = model.getIconURI();
assertEquals(targetIcon, iconString.substring(iconString.lastIndexOf('/')));
}
Aggregations