wiki:Entry_MS_Annotation_Migration

Version 3 (modified by sena, 4 years ago) (diff)

--

Migration of static methods

There are two static methods that are being used throughout the plugin to get active viewer and the active viewer for a given Entry. In some cases (mainly from command handlers), these are replaced with the use of injected variables and for some other parts that needs to access these, the static methods are migrated to use eclipse context.

        public static MSAnnotationMultiPageViewer getActiveViewerForEntry(IEclipseContext context, Entry entry ) {
		EPartService partService = context.get(EPartService.class);
		for (MPart part: partService.getParts()) {
			if (part.getObject() instanceof MSAnnotationMultiPageViewer) {
				if (((MSAnnotationMultiPageViewer)part.getObject()).getEntry().equals(entry)) {
					return (MSAnnotationMultiPageViewer)part.getObject();
				}
			}
		}
		return null;
	}
	
	private static MSAnnotationMultiPageViewer getActiveViewer(IEclipseContext context) {
		MPart part = (MPart) context.get(IServiceConstants.ACTIVE_PART);
		if (part != null && part.getObject() instanceof MSAnnotationMultiPageViewer)
			return (MSAnnotationMultiPageViewer) part.getObject();
		return null;
	}

Propagation of checkbox changes

public class MSAnnotationTable extends MassSpecTable {

       ...

       public void finishUpdateHiddenRowsAfterEdit( boolean isDirty ) {
		updateRowVisibilityAfterRead(this.dataLayer, null);
		updateEventListForVisibility();
		reSort();
		if( parentView != null ) {
			IEclipseContext context = parentView.getParentEditor().getContext();
			IEventBroker eventBroker = context.get(IEventBroker.class);
			eventBroker.post (MSAnnotationMultiPageViewer.EVENT_PARENT_ENTRY_VALUE_MODIFIED, parentView.getEntry());
		}

		if( getCurrentRowIndex() != null ) {
			moveRowIntoViewport(getNatIndexFromSourceIndex(getCurrentRowIndex()+1));
		}
		if ( isDirty && ! parentView.isDirty() ) {
			parentView.setDirty(true);
		}		
	}

    ...

}

Before E4 migration, the above code was making a call to a static method in the multi-page viewer to find the parent viewer and make appropriate changes. We now post an event and the related pages (MSAnnotationDetails and MSAnnotationSpectraView in this case) subscribe to that event. An example (from MSAnnotationSpectraView) is shown below:

        @Optional
	@Inject
	void refreshCheckboxes(
			@UIEventTopic(MassSpecMultiPageViewer.EVENT_PARENT_ENTRY_VALUE_MODIFIED) Entry parentEntry) {
		if( getEntry().getParent() != null && 
			getEntry().getParent().equals(parentEntry) ) {
			MSAnnotationSpectraControlPanelView cp = (MSAnnotationSpectraControlPanelView) getControlPanel();
			cp.updateView();
		}
	}