Bug 517122 - expression to check content-type (FilePropertyTester) to also work on IEditorInput (not only IFile)
Summary: expression to check content-type (FilePropertyTester) to also work on IEditor...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: IDE (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday, helpwanted
Depends on:
Blocks:
 
Reported: 2017-05-23 06:25 EDT by Mickael Istria CLA
Modified: 2018-12-08 05:15 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mickael Istria CLA 2017-05-23 06:25:48 EDT
Currently, if one wants to use the expression mechanism to define enablement according to content-type, the content-type test seems to only work on IFile. However, content-type is a more generic concept and the test could also apply to IEditorInput in general.
Comment 1 Mickael Istria CLA 2017-05-23 06:32:17 EDT
I'm putting myself as assignee to make sure I consider this bug, but if anyone wants to work on it sooner, that would be highly welcome and feel free to change assignee.
Comment 2 Mickael Istria CLA 2017-05-24 05:49:27 EDT
As the FilePropertyTester is in org.eclipse.core.resources, it's not good design to implement it in a way that allows any other IEditorInput. And vice-versa: we cannnot create a property test for a generic IEditorInput which can delegate easily to IFile.

Several possible solutions:

1. Create aproperty test that takes as input IEditorInput and adapts the IEditorInput to IContentType[] in the impletion (and make main IEditorInput implementations able to adapt to IContentType)
That would look like:

  <activeWhen>
    <with variable="activeEditorInput">
      <test property="org.eclipse.core.runtime.content.content-type" value="org.eclipse.linuxtools.tapa.content-type" />
    </with>
  </activeWhen>

2. create a property tester that takes as input some IContentType[], and to let the main IEditorInput implementations adapt to IContentType[].
So, in order to get something enabled on any file of content type X, it would be

  <activeWhen>
    <with variable="activeEditorInput">
      <adapt type="[Lorg.eclipse.core.runtime.content.ContentType;">
        <test property="contains"  value="org.eclipse.linuxtools.tapa.content-type" />
      </adapt>
    </with>
  </activeWhen>


While 1 is simpler for users and matches the use-case better; 2 seems more generic as anything adapting to IContentType can take advantage of it.
Which one should we prefere?
Comment 3 Mickael Istria CLA 2017-05-24 05:50:57 EDT
@Dani: do you have any advice regarding comment #2?
Comment 4 Dani Megert CLA 2017-05-24 10:36:19 EDT
(In reply to Mickael Istria from comment #0)
> Currently, if one wants to use the expression mechanism to define enablement
> according to content-type, the content-type test seems to only work on
> IFile. However, content-type is a more generic concept and the test could
> also apply to IEditorInput in general.

I don't get that point. When the editor has been opened all the checks have already been made.
Comment 5 Mickael Istria CLA 2017-05-24 11:23:34 EDT
The idea is to be able to plug content (context menu and so on) according to IEditorInput only, not to the specific editor.
Comment 6 Dani Megert CLA 2017-05-24 11:41:11 EDT
(In reply to Mickael Istria from comment #5)
> The idea is to be able to plug content (context menu and so on) according to
> IEditorInput only, not to the specific editor.

Not following. The input in the editor depends on the IFile or the content type reader. I have no clue what you are asking here.
Comment 7 Mickael Istria CLA 2017-05-24 11:46:33 EDT
Basically, I'd like to attach a command to *any* editor opening a specific content-type, independently of whether the backend is an IFileEditorInput or a URIEditorInput.
I'd like to do it with regular enableWhen expressions. There are currently no way to properly deal with external files and editor input in general with such expressions, unless I missed something.
Comment 8 Dani Megert CLA 2017-05-24 11:55:12 EDT
(In reply to Mickael Istria from comment #7)
> Basically, I'd like to attach a command to *any* editor opening a specific
> content-type, independently of whether the backend is an IFileEditorInput or
> a URIEditorInput.
> I'd like to do it with regular enableWhen expressions. There are currently
> no way to properly deal with external files and editor input in general with
> such expressions, unless I missed something.

That's wrong. Once the editor has been chosen the set of features should be set.
Comment 9 Mickael Istria CLA 2017-05-24 12:29:28 EDT
(In reply to Dani Megert from comment #8)
> That's wrong. Once the editor has been chosen the set of features should be
> set.

I didn't get what "that" exactly refers to in this answer, Ca you please elaborate?
Comment 10 Dani Megert CLA 2017-05-25 04:13:16 EDT
(In reply to Mickael Istria from comment #9)
> (In reply to Dani Megert from comment #8)
> > That's wrong. Once the editor has been chosen the set of features should be
> > set.
> 
> I didn't get what "that" exactly refers to in this answer, Ca you please
> elaborate?

Sorry, I was somehow chasing down another use case.

I now see what you want to do. Solution 1 (new property testers) is the right one, because you do not want to depend on implementers of IEditorInput/s to add an adapter.
Comment 11 Mickael Istria CLA 2018-05-24 13:20:27 EDT
Taking it in my plans for 4.9.
Comment 12 Mickael Istria CLA 2018-11-14 11:01:32 EST
Alexander recently implemented such a property tester in http://git.eclipse.org/c/pde/eclipse.pde.ui.git/commit/?id=2994fd42fa988a1bbc9799f0a1e93cd6b775ea9f .
@Alexander: would you be interested in copying this property tester in a more common plugin (like org.eclipse.ui.workbench) and make PDE use the common one instead? There is much value in having this property tester in a more reusable place.
Comment 13 Alexander Fedorov CLA 2018-11-14 12:45:45 EST
@Mickael: yes, sure
Comment 14 Eclipse Genie CLA 2018-12-08 05:15:11 EST
New Gerrit change created: https://git.eclipse.org/r/133719