Activate and deactivate key bindings defined as BindingContext in the application model. The content referred to in this service is the BindingContext and not the IEclipseContext.
Logger
org.eclipse.e4.core.services插件中的Logger提供了日志功能
Adapter
An adapter can adapt an object to the specified type, allowing clients to request domain-specific behavior for an object. It integrates IAdaptable and IAdapterManager
// Showing and hiding parts detailsTodoPart = partService.findPart("com.example.todo.rcp.parts.tododetails"); partService.hidePart(detailsTodoPart); …… detailsTodoPart.setVisible(true); partService.showPart(detailsTodoPart, PartState.VISIBLE);
//Switching perspectives @Execute public void execute(MApplication app, EPartService partService, EModelService modelService) { MPerspective element = (MPerspective) modelService.find("secondperspective", app); // now switch perspective partService.switchPerspective(element); }
// creating parts dynamically @Execute public void execute(EPartService partService) {
// create a new Part based on a PartDescriptor // in the application model // assume the ID is used for the PartDescriptor MPart part = partService .createPart("com.example.e4.rcp.todo.partdescriptor.fileeditor"); part.setLabel("New Dynamic Part");
// If multiple parts of this type are now allowed // in the application model, // then the provided part will be shown // and returned partService.showPart(part, PartState.ACTIVATE); }
//switch perspective @Execute public void execute(MApplication app, EPartService partService, EModelService modelService) { MPerspective element = (MPerspective) modelService.find("secondperspective", app); partService.switchPerspective(element); }
@PostConstruct public void createControls(Composite parent) { Button button = new Button(parent, SWT.PUSH); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { dirty.setDirty(true); } }); }
@Persist public void save(MDirtyable dirty, ITodoService todoService) { // save changes via ITodoService for example todoService.saveTodo(todo); // save was successful dirty.setDirty(false); } }
//or use code: Logger log = (Logger) context.get(Logger.class.getName());
# 实现自己的服务
Usually services have two parts: the interface definition and the implementation. How these two are linked is defined by a context function , an OSGi service or plain context value setting (IEclipseContext). Please note that there can be more than one service implementation for an interface.