-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add convenient static factory methods to create JFace Actions #851
base: master
Are you sure you want to change the base?
Conversation
9cefcaa
to
74a3cbd
Compare
74a3cbd
to
e524395
Compare
e524395
to
eb89e98
Compare
I like it. Makes consumer code much more readable. |
I think for actions a builderpattern would be much more suitable e.g.
|
Sounds good. I was looking for that as well. The only change I think we have to do, is to provide the runnable/event-consumer as mandatory argument of the create method. An action without a runnable does not make sense so it should be enforced by the type-system. I can add those builder methods in a second commit of this PR. |
This is ensured by the terminal operation that transform the builder into an action. |
Ok. With your proposal initially I was actually thinking about fluent setters, so that the create method already has build the actions and the fluent setters just call the setter that have return type void:
This would have the advantage that the terminal step is not necessary. Furthermore an Action does not necessarily need a text. Therfore the initial method should not require a text. So in that case |
I don't think fluent setters add anything above the current way of calling a setter. |
What's the state of this PR? |
It is currently stalled. I plan to continue on this further discussing Christoph's suggestions, but I don't expect to find time for that to be in time for the September release.
The question I ask myself here, if in usual use-cases so many aspects are shared for different actions. And at the same time I would like to make this simple in simple use-cases where one only wants an action with a runnable, without more setup. |
Creating JFace actions is often cumbersome, especially for simple implementations of the
run
method, because one has to sub-class the Action class and implement at least the run method. Very often this is done using a anonymous class whoserun()
method just calls the desired method.Similar like
org.eclipse.core.runtime.jobs.Job.create()
jface' Action could provide a static factory method that accepts the runnable to execute (and optionally a text and image). And does the anonymous implementation for the caller.I also added overloads that uses a Consumer and overwrites
runWithEvent()
.Additionally an overload to accepts a text and the style could be added to reflect all Action constructor overloads.
Instead of providing the methods in the
Action
class, they could also be added to theIAction
interface.There would be many use-cases in the SDK. I already used it for a few in the second commit, but that could be extended.