Class DetailViewManager

  • All Implemented Interfaces:
    DetailViewCache

    public class DetailViewManager
    extends java.lang.Object
    implements DetailViewCache
    A manager for the SWT renderings of detail views, with caching.
    Since:
    1.22
    • Constructor Summary

      Constructors 
      Constructor Description
      DetailViewManager​(org.eclipse.swt.widgets.Composite parent)
      Initializes me.
      DetailViewManager​(org.eclipse.swt.widgets.Composite parent, java.util.function.Function<? super org.eclipse.emf.ecore.EObject,​? extends VView> detailView)
      Initializes me with explicit detail views.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ECPSWTView activate​(org.eclipse.emf.ecore.EObject eObject)
      Present the previously cached view for an object.
      void cacheCurrentDetail()
      Cache the currently presented detail view, if any, and remove it from the UI.
      boolean cacheView​(ECPSWTView ecpView)
      Caches the provided ECPSWTView to allow it to be reused later, if there is room for it the cache.
      void clear()
      Dispose all cached views, emptying the cache.
      void dispose()
      Dispose of me and my UI resources.
      ECPSWTView getCachedView​(org.eclipse.emf.ecore.EObject selection)
      Returns the previously cached view for the provided selection.
      ECPSWTView getCurrentDetail()
      Obtain the currently presented detail view.
      org.eclipse.swt.widgets.Control getDetailContainer()
      Obtain the control that contains the rendered details.
      VViewModelProperties getDetailProperties()
      Obtain the view-model properties used for loading the detail view model.
      VView getDetailView​(org.eclipse.emf.ecore.EObject object)
      Obtain the detail view for an object selected in the master view.
      protected VView getDetailView​(org.eclipse.emf.ecore.EObject object, VViewModelProperties properties)
      Get the view provided by the framework for details of the given object.
      VView getDetailView​(ViewModelContext masterContext, org.eclipse.emf.ecore.EObject object)
      Obtain the detail view in the context of the given master view-model context for a selected object in the master view.
      VView getDetailView​(ViewModelContext masterContext, org.eclipse.emf.ecore.EObject object, java.util.function.Consumer<? super VViewModelProperties> propertiesManipulator)
      Obtain the detail view in the context of the given master view-model context for a selected object in the master view.
      protected ECPSWTView getNoDetailsControl()
      Obtain the renderer control showing a hint that there is no selection or no details for the current selection.
      protected VView getNoDetailView()
      Obtain a view to use as placeholder when the framework provides no view for the detail of the selection or when there is no selection.
      boolean isCached​(org.eclipse.emf.ecore.EObject selection)
      Checks whether there is already a cached view available.
      boolean isDisposed()
      Queries whether I have been disposed.
      org.eclipse.swt.widgets.Composite layoutDetailParent​(org.eclipse.swt.widgets.Composite composite)
      Apply a reasonable default layout for the parent composite of a detail container where the only thing contained in that parent is the detail container.
      ECPSWTView render​(ViewModelContext masterContext, VElement masterView, org.eclipse.emf.ecore.EObject object)
      Render the detail view for a given object in the specified master context.
      ECPSWTView render​(ViewModelContext context, DetailRenderingFunction renderer)
      Render the detail view for a given context in the specified parent composite.
      void setCache​(DetailViewCache cache)
      Set the detail-view cache to use.
      void setDetailReadOnly​(boolean readOnly)
      Set the current detail view read-only or not, unless it is intrinsically read-only, in which case it will remain so (this method will have no effect).
      void setFocus()
      Set focus to the currently presented detail view.
      void setNoDetailMessage​(java.lang.String noDetailMessage)
      Set a message to display to the user when there is no detail to show, either because there is no selection in the master or because it has no details.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DETAIL_PROPERTY

        public static final java.lang.String DETAIL_PROPERTY
        Name of a boolean-valued view model property indicating that the view model is being rendered as a detail in a master-detail presentation. It is useful to distinguish this case in enablement/visibility rules, templates, etc. from the general case of a view rendering.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DetailViewManager

        public DetailViewManager​(org.eclipse.swt.widgets.Composite parent)
        Initializes me.
        Parameters:
        parent - the composite in which to create the detail container
      • DetailViewManager

        public DetailViewManager​(org.eclipse.swt.widgets.Composite parent,
                                 java.util.function.Function<? super org.eclipse.emf.ecore.EObject,​? extends VView> detailView)
        Initializes me with explicit detail views. When the detail function can provide a detail view, then the framework's pluggable view providers are not consulted for it.
        Parameters:
        parent - the composite in which to create the detail container
        detailView - the detail-view provider function
    • Method Detail

      • dispose

        public void dispose()
        Dispose of me and my UI resources.
      • isDisposed

        public boolean isDisposed()
        Queries whether I have been disposed.
        Returns:
        whether I am disposed
      • getDetailContainer

        public org.eclipse.swt.widgets.Control getDetailContainer()
        Obtain the control that contains the rendered details. This is useful, for example, to set layout parameters on it in the context of its parent composite.
        Returns:
        the container of the rendered details
      • setCache

        public void setCache​(DetailViewCache cache)
        Set the detail-view cache to use. If some other cache was being used, any rendered controls that it maintained will be disposed.
        Parameters:
        cache - the DetailViewCache to use, or null to use no cache
      • activate

        public ECPSWTView activate​(org.eclipse.emf.ecore.EObject eObject)
        Present the previously cached view for an object.
        Parameters:
        eObject - the object to present
        Returns:
        the re-rendered view
        Throws:
        java.lang.IllegalStateException - if there is no view cached for the object
        See Also:
        isCached(EObject)
      • render

        public ECPSWTView render​(ViewModelContext context,
                                 DetailRenderingFunction renderer)
        Render the detail view for a given context in the specified parent composite. If a cached rendering is available for the domain model, then it is re-used and the context is disposed. Otherwise, the supplied rendering function is used to render the detail view.
        Parameters:
        context - the context to present in the detail view
        renderer - if needed to render a new detail view control
        Returns:
        the rendered view
      • render

        public ECPSWTView render​(ViewModelContext masterContext,
                                 VElement masterView,
                                 org.eclipse.emf.ecore.EObject object)
        Render the detail view for a given object in the specified master context.
        Parameters:
        masterContext - the master context in which the object is selected
        masterView - the master view in which context to render the detail view
        object - the selected object for which to present the detail
        Returns:
        the rendered view
      • getCurrentDetail

        public final ECPSWTView getCurrentDetail()
        Obtain the currently presented detail view.
        Returns:
        the current rendered detail view, or null if none
      • cacheCurrentDetail

        public void cacheCurrentDetail()
        Cache the currently presented detail view, if any, and remove it from the UI.
      • setFocus

        public void setFocus()
        Set focus to the currently presented detail view.
      • getDetailProperties

        public VViewModelProperties getDetailProperties()
        Obtain the view-model properties used for loading the detail view model. Clients may update these properties but must not change the detail property.
        Returns:
        the view-model properties for the detail view
      • getDetailView

        public VView getDetailView​(ViewModelContext masterContext,
                                   org.eclipse.emf.ecore.EObject object)
        Obtain the detail view in the context of the given master view-model context for a selected object in the master view.
        Parameters:
        masterContext - the master view-model context
        object - the selection in the master view for which to get a detail view
        Returns:
        the detail view
      • getDetailView

        public VView getDetailView​(ViewModelContext masterContext,
                                   org.eclipse.emf.ecore.EObject object,
                                   java.util.function.Consumer<? super VViewModelProperties> propertiesManipulator)
        Obtain the detail view in the context of the given master view-model context for a selected object in the master view.
        Parameters:
        masterContext - the master view-model context
        object - the selection in the master view for which to get a detail view
        propertiesManipulator - an optional hook with which to inject properties to assist/filter the detail view model resolution
        Returns:
        the detail view
      • getDetailView

        public VView getDetailView​(org.eclipse.emf.ecore.EObject object)
        Obtain the detail view for an object selected in the master view. This method is useful for master-detail presentations in which the master is not managed by a Form in a ViewModelContext but explicitly by some custom UI control.
        Parameters:
        object - the master view selection
        Returns:
        the detail view for the object
      • setDetailReadOnly

        public void setDetailReadOnly​(boolean readOnly)
        Set the current detail view read-only or not, unless it is intrinsically read-only, in which case it will remain so (this method will have no effect).
        Parameters:
        readOnly - true to set the detail view read-only; false to let its intrinsic read-only state prevail
      • getDetailView

        protected VView getDetailView​(org.eclipse.emf.ecore.EObject object,
                                      VViewModelProperties properties)
        Get the view provided by the framework for details of the given object.
        Parameters:
        object - the object for which to get the detail view
        properties - the properties to use for loading the view
        Returns:
        the detail view (never null, even if the framework provides nothing)
      • getNoDetailView

        protected VView getNoDetailView()
        Obtain a view to use as placeholder when the framework provides no view for the detail of the selection or when there is no selection.
        Returns:
        the no-details placeholder view
      • getNoDetailsControl

        protected ECPSWTView getNoDetailsControl()
        Obtain the renderer control showing a hint that there is no selection or no details for the current selection.
        Returns:
        the no-details control
      • layoutDetailParent

        public org.eclipse.swt.widgets.Composite layoutDetailParent​(org.eclipse.swt.widgets.Composite composite)
        Apply a reasonable default layout for the parent composite of a detail container where the only thing contained in that parent is the detail container.
        Parameters:
        composite - the detail parent composite
        Returns:
        the composite, for convenience of call chaining
      • setNoDetailMessage

        public void setNoDetailMessage​(java.lang.String noDetailMessage)
        Set a message to display to the user when there is no detail to show, either because there is no selection in the master or because it has no details.
        Parameters:
        noDetailMessage - the "no details" message to set, or null for the default localized string ("No selection or no details available for selection.")
      • isCached

        public boolean isCached​(org.eclipse.emf.ecore.EObject selection)
        Description copied from interface: DetailViewCache
        Checks whether there is already a cached view available.
        Specified by:
        isCached in interface DetailViewCache
        Parameters:
        selection - The new master object selection
        Returns:
        true if there is a cached view for the provided selection; false otherwise
      • cacheView

        public boolean cacheView​(ECPSWTView ecpView)
        Description copied from interface: DetailViewCache

        Caches the provided ECPSWTView to allow it to be reused later, if there is room for it the cache.

        Note that a view is cached when it is no longer required, usually because another detail view is taking its place in the editor. Consequently, if the cache is size-limited and cannot actually cache the view, it must dispose that view.

        Specified by:
        cacheView in interface DetailViewCache
        Parameters:
        ecpView - the ECPSWTView to cache
        Returns:
        true if the view was added to the cache; false otherwise (in which case it would be disposed)
      • clear

        public void clear()
        Description copied from interface: DetailViewCache
        Dispose all cached views, emptying the cache. The cache must still be in a state to be used (this is not a "dispose" operation).
        Specified by:
        clear in interface DetailViewCache