Skip to content

Commit 3860d48

Browse files
authored
Merge pull request #8786 from mbien/project-tab-tooltips
Add tooltips to Projects, Files and Favorites tabs
2 parents 3e700fe + 12d17eb commit 3860d48

File tree

6 files changed

+52
-19
lines changed

6 files changed

+52
-19
lines changed

ide/projectui/src/org/netbeans/modules/project/ui/Bundle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ ACSN_BrowseFolders_Select_Option=Select Folder
3232
ACSD_BrowseFolders_Select_Option=N/A
3333
LBL_BrowseFolders_jLabel1=&Folders\:
3434
LBL_BrowseFolders_Dialog=Browse Folders
35+
3536
# ProjectTab
3637
LBL_projectTab_tc=Files
3738
LBL_projectTabLogical_tc=Projects
39+
TT_projectTab_tc=Open Projects - Physical View\n({0}) to select editor file in view
40+
TT_projectTabLogical_tc=Open Projects - Logical View\n({0}) to select editor file in view
41+
3842
# {0} - display name of currently selected group
3943
LBL_projectTabLogical_tc_with_group=Projects - {0}
44+
TT_projectTab_tc_with_group=Open Projects [{1}] - Physical View\n({0}) to select editor file in view
45+
TT_projectTabLogical_tc_with_group=Open Projects [{1}] - Logical View\n({0}) to select editor file in view
4046

4147
LBL_ProjectMode=Projects
4248

ide/projectui/src/org/netbeans/modules/project/ui/ProjectTab.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import javax.swing.JLabel;
6060
import javax.swing.JPanel;
6161
import javax.swing.JPopupMenu;
62+
import javax.swing.KeyStroke;
6263
import javax.swing.SwingConstants;
6364
import javax.swing.SwingUtilities;
6465
import javax.swing.UIManager;
@@ -82,6 +83,7 @@
8283
import org.openide.awt.ActionReference;
8384
import org.openide.awt.ActionReferences;
8485
import org.openide.awt.ActionRegistration;
86+
import org.openide.awt.Actions;
8587
import org.openide.awt.StatusDisplayer;
8688
import org.openide.awt.UndoRedo;
8789
import org.openide.explorer.ExplorerManager;
@@ -133,7 +135,7 @@ public class ProjectTab extends TopComponent
133135

134136
private static final Logger LOG = Logger.getLogger(ProjectTab.class.getName());
135137

136-
private static Map<String, ProjectTab> tabs = new HashMap<String, ProjectTab>();
138+
private static Map<String, ProjectTab> tabs = new HashMap<>();
137139

138140
private final transient ExplorerManager manager;
139141
private transient Node rootNode;
@@ -214,14 +216,29 @@ public ProjectTab() {
214216
public void setGroup(Group g) {
215217
if (id.equals(ID_LOGICAL)) {
216218
if (g != null) {
217-
setName(NbBundle.getMessage(ProjectTab.class, "LBL_projectTabLogical_tc_with_group", g.getName()));
219+
setName(NbBundle.getMessage(ProjectTab.class, "LBL_projectTabLogical_tc_with_group", g.getName())); // NOI18N
220+
setToolTipText(NbBundle.getMessage(ProjectTab.class, "TT_projectTabLogical_tc_with_group", g.getName(), getKeyStrokeString())); // NOI18N
218221
} else {
219-
setName(NbBundle.getMessage(ProjectTab.class, "LBL_projectTabLogical_tc"));
222+
setName(NbBundle.getMessage(ProjectTab.class, "LBL_projectTabLogical_tc")); // NOI18N
223+
setToolTipText(NbBundle.getMessage(ProjectTab.class, "TT_projectTabLogical_tc", getKeyStrokeString())); // NOI18N
220224
}
221225
} else {
222-
setName(NbBundle.getMessage(ProjectTab.class, "LBL_projectTab_tc"));
226+
setName(NbBundle.getMessage(ProjectTab.class, "LBL_projectTab_tc")); // NOI18N
227+
if (g != null) {
228+
setToolTipText(NbBundle.getMessage(ProjectTab.class, "TT_projectTab_tc_with_group", g.getName(), getKeyStrokeString())); // NOI18N
229+
} else {
230+
setToolTipText(NbBundle.getMessage(ProjectTab.class, "TT_projectTab_tc", getKeyStrokeString())); // NOI18N
231+
}
223232
}
224-
// Seems to be useless: setToolTipText(getName());
233+
}
234+
235+
private String getKeyStrokeString() {
236+
Action action = id.equals(ID_LOGICAL)
237+
? Actions.forID("Window/SelectDocumentNode", "org.netbeans.modules.project.ui.SelectInProjects") // NOI18N
238+
: Actions.forID("Window/SelectDocumentNode", "org.netbeans.modules.project.ui.SelectInFiles"); // NOI18N
239+
return action != null && action.getValue(Action.ACCELERATOR_KEY) instanceof KeyStroke ks
240+
? Actions.keyStrokeToString(ks)
241+
: ""; // NOI18N
225242
}
226243

227244
private void initValues() {
@@ -240,7 +257,7 @@ private void initValues() {
240257
}
241258
manager.setRootContext( rootNode );
242259
}
243-
260+
244261
/** Explorer manager implementation
245262
*/
246263
@Override
@@ -386,7 +403,7 @@ public void writeExternal (ObjectOutput out) throws IOException {
386403
id = (String)in.readObject();
387404
rootNode = ((Node.Handle)in.readObject()).getNode();
388405
final List<String[]> exPaths = NbCollections.checkedListByCopy((List<?>) in.readObject(), String[].class, true);
389-
final List<String[]> selPaths = new ArrayList<String[]>();
406+
final List<String[]> selPaths = new ArrayList<>();
390407
try {
391408
selPaths.addAll(NbCollections.checkedListByCopy((List<?>) in.readObject(), String[].class, true));
392409
}
@@ -435,7 +452,7 @@ public void run() {
435452
LOG.log(Level.FINE, "{0}: expanding paths", id);
436453
btv.expandNodes(exPaths);
437454
LOG.log(Level.FINE, "{0}: selecting paths", id);
438-
final List<Node> selectedNodes = new ArrayList<Node>();
455+
final List<Node> selectedNodes = new ArrayList<>();
439456
Node root = manager.getRootContext();
440457
for (String[] sp : selPaths) {
441458
LOG.log(Level.FINE, "{0}: selecting {1}", new Object[] {id, Arrays.asList(sp)});
@@ -453,7 +470,7 @@ public void run() {
453470
EventQueue.invokeLater(new Runnable() {
454471
@Override public void run() {
455472
try {
456-
manager.setSelectedNodes(selectedNodes.toArray(new Node[0]));
473+
manager.setSelectedNodes(selectedNodes.toArray(Node[]::new));
457474
} catch (PropertyVetoException x) {
458475
LOG.log(Level.FINE, null, x);
459476
}
@@ -649,7 +666,7 @@ void expandNode(Node node) {
649666
}
650667

651668
private List<String[]> getSelectedPaths() {
652-
List<String[]> result = new ArrayList<String[]>();
669+
List<String[]> result = new ArrayList<>();
653670
Node root = manager.getRootContext();
654671
for (Node n : manager.getSelectedNodes()) {
655672
String[] path = NodeOp.createPath(n, root);
@@ -728,7 +745,7 @@ public void run() {
728745

729746
public List<String[]> getExpandedPaths() {
730747

731-
List<String[]> result = new ArrayList<String[]>();
748+
List<String[]> result = new ArrayList<>();
732749

733750
TreeNode rtn = Visualizer.findVisualizer( rootNode );
734751
TreePath tp = new TreePath( rtn ); // Get the root
@@ -831,7 +848,7 @@ public void run() {
831848
// showing popup on right click in projects tab when label <No Project Open> is shown
832849
private class LabelPopupDisplayer extends MouseAdapter {
833850

834-
private Component component;
851+
private final Component component;
835852

836853
public LabelPopupDisplayer(Component comp) {
837854
component = comp;

ide/projectui/src/org/netbeans/modules/project/ui/groups/Group.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ public void setName(String n) {
450450
EventQueue.invokeLater(new Runnable() {
451451
@Override public void run() {
452452
ProjectTab.findDefault(ProjectTab.ID_LOGICAL).setGroup(Group.this);
453+
ProjectTab.findDefault(ProjectTab.ID_PHYSICAL).setGroup(Group.this);
453454
}
454455
});
455456
}
@@ -549,6 +550,7 @@ static void open(final Group g, String oldGroupName, boolean isNewGroup, Prefere
549550
EventQueue.invokeLater(new Runnable() {
550551
@Override public void run() {
551552
ProjectTab.findDefault(ProjectTab.ID_LOGICAL).setGroup(g);
553+
ProjectTab.findDefault(ProjectTab.ID_PHYSICAL).setGroup(g);
552554
}
553555
});
554556
String handleLabel;

platform/favorites/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
javac.compilerargs=-Xlint:all -Xlint:-serial -Xlint:-options -Werror
18-
javac.source=1.8
18+
javac.release=17

platform/favorites/src/org/netbeans/modules/favorites/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ACT_View=Fa&vorites
2222
ACT_Select_Main_Menu=Select in F&avorites
2323

2424
Favorites=Favorites
25+
TT_Favorites=Favorite Files and Locations \n({0}) to select editor file in view
2526

2627
#name [display name]
2728
CTL_DisplayNameTemplate ={0} [{1}]

platform/favorites/src/org/netbeans/modules/favorites/Tab.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import java.util.Stack;
3232
import java.util.logging.Level;
3333
import java.util.logging.Logger;
34+
import javax.swing.Action;
3435
import javax.swing.ActionMap;
3536
import javax.swing.JFileChooser;
37+
import javax.swing.KeyStroke;
3638
import javax.swing.text.DefaultEditorKit;
3739
import javax.swing.tree.DefaultTreeModel;
3840
import javax.swing.tree.TreeModel;
@@ -112,7 +114,7 @@ private Tab() {
112114
public HelpCtx getHelpCtx () {
113115
return new HelpCtx(Tab.HELP_ID);
114116
}
115-
117+
116118
@Override
117119
public ExplorerManager getExplorerManager() {
118120
return manager;
@@ -232,7 +234,12 @@ private NodeListener rcListener () {
232234
* obtained from specified root context node */
233235
private void initializeWithRootContext (Node rc) {
234236
// update TC's attributes
235-
setToolTipText(rc.getDisplayName());
237+
String hotkey = ""; // NOI18N
238+
Action action = org.openide.awt.Actions.forID("Window/SelectDocumentNode", "org.netbeans.modules.favorites.Select"); // NOI18N
239+
if (action != null && action.getValue(Action.ACCELERATOR_KEY) instanceof KeyStroke ks) {
240+
hotkey = org.openide.awt.Actions.keyStrokeToString(ks);
241+
}
242+
setToolTipText(NbBundle.getMessage(Tab.class, "TT_Favorites", hotkey)); //NOI18N
236243
setName(rc.getDisplayName());
237244
updateTitle();
238245
// attach listener
@@ -521,8 +528,8 @@ private static FileObject chooseFileObject(FileObject file) {
521528
File chooserSelection = null;
522529
JFileChooser chooser = new JFileChooser ();
523530
chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES );
524-
chooser.setDialogTitle(NbBundle.getBundle(Actions.class).getString ("CTL_DialogTitle"));
525-
chooser.setApproveButtonText(NbBundle.getBundle(Actions.class).getString ("CTL_ApproveButtonText"));
531+
chooser.setDialogTitle(NbBundle.getMessage(Actions.class, "CTL_DialogTitle"));
532+
chooser.setApproveButtonText(NbBundle.getMessage(Actions.class, "CTL_ApproveButtonText"));
526533
chooser.setSelectedFile(FileUtil.toFile(file));
527534
int option = chooser.showOpenDialog( WindowManager.getDefault().getMainWindow() ); // Show the chooser
528535
if ( option == JFileChooser.APPROVE_OPTION ) {
@@ -562,8 +569,8 @@ private void scrollToSelection() {
562569
final Node[] selection = getExplorerManager().getSelectedNodes();
563570
if( null == selection || selection.length < 1 )
564571
return;
565-
if( view instanceof MyBeanTreeView ) {
566-
((MyBeanTreeView)view).scrollNodeToVisible(selection[0]);
572+
if( view instanceof MyBeanTreeView myBeanTreeView ) {
573+
myBeanTreeView.scrollNodeToVisible(selection[0]);
567574
}
568575
}
569576

0 commit comments

Comments
 (0)