Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[e4-dev] Difficulties determining the part providing selection

Hello everybody.  I've had some difficulty creating a view that reacts to selection changes in other parts except from selections within its own part.  Unfortunately this wasn't as straight-forward as I had hoped.

I added a setInput() that requests the selection and active part:

   @Inject
   public void setInput(
         @Optional @Named(IServiceConstants.SELECTION)
            Object input,
         @Optional @Named(IServiceConstants.ACTIVE_PART)
            MPart activePart,
         IEclipseContext context) {
      if(activePart != null 
            && activePart instanceof MContribution
            && ((MContribution)activePart).getObject() == this) {
         return; 
      }
      // ... do our processing ...
   }

However the provided activePart provided is always *this* part, rather than the selection part.  This doesn't seem right to me — I expected that the other part should be considered as the active part since *this* part is only reacting to a selection in the other part.

As a workaround, the selection part is available as the active part in the parent context:

   IEclipseContext parent =
      (IEclipseContext)context.get(IContextConstants.PARENT);
   MPart selectionPart = (MPart)parent.get(IServiceConstants.ACTIVE_PART);
   if(selectionPart instanceof MContribution
         && ((MContribution)selectionPart).getObject() == this) {
      return;
   }

[If the active part doesn't seem wrong, could I then request additional constants such as IServiceConstants.SELECTION_PART and IServiceConstants.SELECTION_PART_ID?]

And as an aside, these casts makes code much less clear than in E3.x, IMHO.  I wonder if we mightn't be better for the IEclipseContext to provide for the use of adapters to provide typesafe interfaces.  For example:

   IEclipseSelectionContext sc =
      context.getAdapter(IEclipseSelectionContext.class);
   if(sc.getSelectionPart() == this) { return; } 

Brian.

--
On bike helmets: "If you think your hair is more important than your brain, you're probably right."  (B. J. Wawrykow)

Attachment: smime.p7s
Description: S/MIME cryptographic signature


Back to the top