-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix for issue 4629 #5150
Fix for issue 4629 #5150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution, @ffffatgoose. I would just like to comment a point.
* especially for the track execute when the action run the same function but from different source. | ||
* @param source is a string contains the source, for example "button" | ||
*/ | ||
public JabRefAction(Action action, Command command, KeyBindingRepository keyBindingRepository, String source) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid duplicating code, I suggest modifying the previous method (the old one), for example:
public JabRefAction(Action action, Command command, KeyBindingRepository keyBindingRepository) {
this(action, command, keyBindingRepository, null);
}
This way, you should check in your JabRefAction()
method if source
is null
for tracking an execution:
setEventHandler(event -> {
command.execute();
if (source == null) {
trackExecute(getActionName(action, command));
} else {
trackExecute(String.format("%sFrom%s", getActionName(action, command), source));
}
});
You also can use Strings.isNullOrEmpty(source)
, from the com.google.common.base.Strings
package. Or even an Optional<String>
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have our own StringIsNullorEmpty methd in org.jabref.model.StringUtil
just change the JabRefAction as your suggestion :) |
@@ -3,7 +3,7 @@ | |||
/** | |||
* Global String constants for GUI actions | |||
*/ | |||
@Deprecated | |||
//@Deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a special reason for reusing the deprecated Actions-enum? StandardActions is the future... ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please leave the deprecated statement (and try to avoid using this enum).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your first contribution to JabRef! The code looks quite good already and I've only a few minor suggestions for improvement before we can merge.
@@ -74,7 +74,7 @@ private static Label getAssociatedNode(MenuItem menuItem) { | |||
} | |||
|
|||
public MenuItem configureMenuItem(Action action, Command command, MenuItem menuItem) { | |||
ActionUtils.configureMenuItem(new JabRefAction(action, command, keyBindingRepository), menuItem); | |||
ActionUtils.configureMenuItem(new JabRefAction(action, command, keyBindingRepository, "Menu"), menuItem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please create a new enum for the Menu
and Button
constants (I don't like magic strings).
@@ -3,7 +3,7 @@ | |||
/** | |||
* Global String constants for GUI actions | |||
*/ | |||
@Deprecated | |||
//@Deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please leave the deprecated statement (and try to avoid using this enum).
if (StringUtil.isNullOrEmpty(source)) { | ||
trackExecute(getActionName(action, command)); | ||
} else { | ||
trackExecute(getActionName(action, command) + "From" + source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ApplicationInsights library that we use supports a special way to submit additional details (which I completely forgot until 5 mins ago): https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#properties
Could you please send the source
as a property please.
jabref/src/main/java/org/jabref/gui/JabRefFrame.java
Lines 1016 to 1022 in 7561724
private void trackOpenNewDatabase(BasePanel basePanel) { | |
Map<String, String> properties = new HashMap<>(); | |
Map<String, Double> measurements = new HashMap<>(); | |
measurements.put("NumberOfEntries", (double) basePanel.getBibDatabaseContext().getDatabase().getEntryCount()); | |
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements)); | |
} |
return command.toString(); | ||
} else { | ||
return command.getClass().getSimpleName(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been testing this method and there is a small bug in some EditAction
cases (it shows org.jabref.gui.entryeditor.SourceTab$EditAction@56048e40FromMenu
). Due to there are still many classes that use Actions
and OldDatabaseCommandWrapper
, it is a bit complicated to deal with all of them, but I think that something like this should work...
} else {
String commandName = command.getClass().getSimpleName();
if (command instanceof OldDatabaseCommandWrapper || commandName.equals("EditAction")) {
return action.toString();
} else {
return commandName;
}
}
Just a proposal, please adapt it in your own way :"D
Hey @ffffatgoose, it would be awesome if you could have a look at the comments and find some time to incorporate them in the PR or discuss them in the comments in case you disagree. |
I feel very sorry to delay for so long. I have some question for the class jabref/src/main/java/org/jabref/gui/JabRefFrame.java Lines 529 to 541 in 9daa645
The input parameter is in the form of Actions , so I reuse the class to return the exact actionname of user action. Waiting for suggestions :D
|
0761dd1
to
2c71b13
Compare
@ffffatgoose This is not related to your changes, it's a problem in the master branch. #5182 |
Hi @ffffatgoose . JabRef is in the middle of converting the gui from the old swing-controls to javafx (see PR #4894 ) and also refactoring the codebase to the MVVM-pattern. This is why Actions, OldCommandWrapper etc. are deprecated, but are still used, since not everything is already refactored. This will take time. About your checkstyle-issue: I was able to reproduce it with the vanilla-sources. I think it has something to do with the gradle-build-script and some recent updates of the junit-library. Would be probably the best to create a new issue in the issuetracker on github. Edit: Whoopsie, while writing my comment @Siedlerchr was quicker. |
@ffffatgoose @calixtus The checkstyle problem on the master should be gone now |
get it~ I only used the class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my point of view this looks good now.
@davidemdot Could you take a second look if this is ready? |
@tobiasdiez Do you think this is fine to merge? |
Yes, looks good to me! Thanks again for your contribution! |
* upstream/master: (27 commits) remove wrong dependencies add missing dependencies Fix exception when adding field formatter in 'Cleanup entries' dialog Disables the preview cycling Removed unused method (#5219) Switch from tika-parsers to tika-core (#5217) Fix for issue 4629 (#5150) fix l10n, again fix l10n Fix checkstyle Removed old entrypreview and corresponding actions Prototype Add minor improvements and remove unused code Update CHANGELOG.md Update to current entry types and reformat code Convert Integer type to primitive Fix localization keys fix checkstyle again fix checkstyle erros Bibtexextractor ...
Fix #4629