import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
-import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
if (!mouseEvent.isPopupTrigger()) {
return;
}
- Point eventLocation = mouseEvent.getPoint();
- TreePath[] selectedPaths = fileTree.getSelectionPaths();
- if ((selectedPaths == null) || (selectedPaths.length == 0)) {
- /* try to find item under click. */
- TreePath clickedPath = fileTree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
- if (clickedPath != null) {
- fileTree.setSelectionPath(clickedPath);
- selectedPaths = new TreePath[] { clickedPath };
- } else {
- logger.log(Level.FINER, "nothing selected for context menu");
- return;
- }
+ List<ProjectFileWrapper> selectedProjectFileWrappers = getSelectedProjectFileWrappers(false);
+ TreePath clickedPath = fileTree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
+ ProjectFileWrapper clickedProjectFileWrapper = (ProjectFileWrapper) clickedPath.getLastPathComponent();
+ if (!selectedProjectFileWrappers.contains(clickedProjectFileWrapper)) {
+ fileTree.setSelectionPath(clickedPath);
}
- if (selectedPaths.length == 1) {
- ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPaths[0].getLastPathComponent();
+ if (selectedProjectFileWrappers.size() == 1) {
+ ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0);
ProjectFile projectFile = projectFileWrapper.getProjectFile();
setDefaultFileAction.setEnabled(!isHidden(projectFileWrapper) && projectFile.isFile() && !projectFile.getCompletePath().equals(project.getDefaultFile()));
} else {
setDefaultFileAction.setEnabled(false);
}
- treeContextMenu.show(fileTree, eventLocation.x, eventLocation.y);
+ treeContextMenu.show(fileTree, mouseEvent.getX(), mouseEvent.getY());
}
/**