-
Notifications
You must be signed in to change notification settings - Fork 6
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
Control clicking exercise opens submit window #447
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import javax.swing.SwingUtilities; | ||
|
@@ -34,7 +34,7 @@ public class TreeView extends com.intellij.ui.treeStructure.Tree { | |
} | ||
}; | ||
|
||
private final transient Set<ActionListener> nodeAppliedListeners = ConcurrentHashMap.newKeySet(); | ||
private final transient HashMap<String, ActionListener> nodeAppliedListeners = new HashMap<>(); | ||
|
||
@NotNull | ||
public static SelectableNodeViewModel<?> getViewModel(Object node) { | ||
|
@@ -98,12 +98,12 @@ private void update() { | |
restoreExpandedState(expandedState); | ||
} | ||
|
||
public void addNodeAppliedListener(ActionListener listener) { | ||
nodeAppliedListeners.add(listener); | ||
public void addNodeAppliedListener(String key, ActionListener listener) { | ||
nodeAppliedListeners.put(key, listener); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my previous comments, I overlooked one issue. As implemented here, this allows only one listener per key. It's possible that we never need more than one but at least in that case the name of this method should reflect that. Anyways, I would probably just instead of key-listener map have to separate set of listeners, one per an event type. And add and remove methods for both. |
||
} | ||
|
||
public void removeNodeAppliedListener(ActionListener listener) { | ||
nodeAppliedListeners.remove(listener); | ||
public void removeNodeAppliedListener(String key) { | ||
nodeAppliedListeners.remove(key); | ||
} | ||
|
||
@NotNull | ||
|
@@ -151,9 +151,12 @@ protected class TreeMouseListener extends MouseAdapter { | |
|
||
@Override | ||
public void mouseClicked(@NotNull MouseEvent e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think the logic inside the method can be tested fully or maybe at least to the extent of the conditional statements? |
||
if (e.getClickCount() == 2 && selectedItem != null) { | ||
if (e.getClickCount() == 1 && e.isControlDown() && selectedItem != null) { | ||
ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); | ||
nodeAppliedListeners.forEach(listener -> listener.actionPerformed(actionEvent)); | ||
nodeAppliedListeners.get("submitExercise").actionPerformed(actionEvent); | ||
} else if (e.getClickCount() == 2 && selectedItem != null) { | ||
ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); | ||
nodeAppliedListeners.get("openSubmission").actionPerformed(actionEvent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TreeView should be a domain-ignorant class; it shouldn't deal with concepts such as "submission". It's a general purpose tree widget. So if anything, the keys should be something like "doubleClick" and "ctrlClick", or maybe more preferably something abstract like "nodePrimaryAction", "nodeSecondaryAction". I wouldn't, however, introduce any magic strings into the public interface of this class (they can be used internally, if you like). Instead, I would make a separate add*Listener and remove*Listener methods for different kind of events. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think separate add*Listener and remove*Listener methods for different kind of events sounds good, I'll do that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me too, but in that case I would prefer two sets for primary and secondary listeners respectively, instead of a map (even if only used internally). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, Olli already suggested this in his later comment, but yes, I agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The javadocs for |
||
} | ||
} | ||
} | ||
|
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.
Should probably be ConcurrentHashMap