59
59
import javax .swing .JLabel ;
60
60
import javax .swing .JPanel ;
61
61
import javax .swing .JPopupMenu ;
62
+ import javax .swing .KeyStroke ;
62
63
import javax .swing .SwingConstants ;
63
64
import javax .swing .SwingUtilities ;
64
65
import javax .swing .UIManager ;
82
83
import org .openide .awt .ActionReference ;
83
84
import org .openide .awt .ActionReferences ;
84
85
import org .openide .awt .ActionRegistration ;
86
+ import org .openide .awt .Actions ;
85
87
import org .openide .awt .StatusDisplayer ;
86
88
import org .openide .awt .UndoRedo ;
87
89
import org .openide .explorer .ExplorerManager ;
@@ -133,7 +135,7 @@ public class ProjectTab extends TopComponent
133
135
134
136
private static final Logger LOG = Logger .getLogger (ProjectTab .class .getName ());
135
137
136
- private static Map <String , ProjectTab > tabs = new HashMap <String , ProjectTab >();
138
+ private static Map <String , ProjectTab > tabs = new HashMap <>();
137
139
138
140
private final transient ExplorerManager manager ;
139
141
private transient Node rootNode ;
@@ -214,14 +216,29 @@ public ProjectTab() {
214
216
public void setGroup (Group g ) {
215
217
if (id .equals (ID_LOGICAL )) {
216
218
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
218
221
} 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
220
224
}
221
225
} 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
+ }
223
232
}
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
225
242
}
226
243
227
244
private void initValues () {
@@ -240,7 +257,7 @@ private void initValues() {
240
257
}
241
258
manager .setRootContext ( rootNode );
242
259
}
243
-
260
+
244
261
/** Explorer manager implementation
245
262
*/
246
263
@ Override
@@ -386,7 +403,7 @@ public void writeExternal (ObjectOutput out) throws IOException {
386
403
id = (String )in .readObject ();
387
404
rootNode = ((Node .Handle )in .readObject ()).getNode ();
388
405
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 <>();
390
407
try {
391
408
selPaths .addAll (NbCollections .checkedListByCopy ((List <?>) in .readObject (), String [].class , true ));
392
409
}
@@ -435,7 +452,7 @@ public void run() {
435
452
LOG .log (Level .FINE , "{0}: expanding paths" , id );
436
453
btv .expandNodes (exPaths );
437
454
LOG .log (Level .FINE , "{0}: selecting paths" , id );
438
- final List <Node > selectedNodes = new ArrayList <Node >();
455
+ final List <Node > selectedNodes = new ArrayList <>();
439
456
Node root = manager .getRootContext ();
440
457
for (String [] sp : selPaths ) {
441
458
LOG .log (Level .FINE , "{0}: selecting {1}" , new Object [] {id , Arrays .asList (sp )});
@@ -453,7 +470,7 @@ public void run() {
453
470
EventQueue .invokeLater (new Runnable () {
454
471
@ Override public void run () {
455
472
try {
456
- manager .setSelectedNodes (selectedNodes .toArray (new Node [0 ] ));
473
+ manager .setSelectedNodes (selectedNodes .toArray (Node []:: new ));
457
474
} catch (PropertyVetoException x ) {
458
475
LOG .log (Level .FINE , null , x );
459
476
}
@@ -649,7 +666,7 @@ void expandNode(Node node) {
649
666
}
650
667
651
668
private List <String []> getSelectedPaths () {
652
- List <String []> result = new ArrayList <String [] >();
669
+ List <String []> result = new ArrayList <>();
653
670
Node root = manager .getRootContext ();
654
671
for (Node n : manager .getSelectedNodes ()) {
655
672
String [] path = NodeOp .createPath (n , root );
@@ -728,7 +745,7 @@ public void run() {
728
745
729
746
public List <String []> getExpandedPaths () {
730
747
731
- List <String []> result = new ArrayList <String [] >();
748
+ List <String []> result = new ArrayList <>();
732
749
733
750
TreeNode rtn = Visualizer .findVisualizer ( rootNode );
734
751
TreePath tp = new TreePath ( rtn ); // Get the root
@@ -831,7 +848,7 @@ public void run() {
831
848
// showing popup on right click in projects tab when label <No Project Open> is shown
832
849
private class LabelPopupDisplayer extends MouseAdapter {
833
850
834
- private Component component ;
851
+ private final Component component ;
835
852
836
853
public LabelPopupDisplayer (Component comp ) {
837
854
component = comp ;
0 commit comments