Lines 46-84
Link Here
|
46 |
|
46 |
|
47 |
import javax.swing.Action; |
47 |
import javax.swing.Action; |
48 |
import javax.swing.Icon; |
48 |
import javax.swing.Icon; |
49 |
import javax.swing.JMenuItem; |
|
|
50 |
import org.netbeans.api.project.Project; |
51 |
import org.netbeans.modules.project.ui.ProjectTab; |
49 |
import org.netbeans.modules.project.ui.ProjectTab; |
52 |
import org.netbeans.spi.project.ui.support.ProjectActionPerformer; |
|
|
53 |
import org.openide.awt.Mnemonics; |
54 |
import org.openide.filesystems.FileObject; |
50 |
import org.openide.filesystems.FileObject; |
55 |
import org.openide.loaders.DataObject; |
51 |
import org.openide.loaders.DataObject; |
56 |
import org.openide.util.ImageUtilities; |
52 |
import org.openide.util.ImageUtilities; |
57 |
import org.openide.util.Lookup; |
53 |
import org.openide.util.Lookup; |
58 |
import org.openide.util.NbBundle; |
54 |
import org.openide.util.NbBundle; |
59 |
import org.openide.util.actions.Presenter; |
|
|
60 |
|
55 |
|
61 |
/** Action sensitive to current project |
56 |
public class SelectNodeAction extends LookupSensitiveAction { |
62 |
* |
|
|
63 |
* @author Pet Hrebejk |
64 |
*/ |
65 |
public class SelectNodeAction extends LookupSensitiveAction implements Presenter.Menu, Presenter.Popup { |
66 |
|
57 |
|
67 |
// XXX Better icons |
|
|
68 |
private static final Icon SELECT_IN_PROJECTS_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/project/ui/resources/projectTab.png", false); //NOI18N |
58 |
private static final Icon SELECT_IN_PROJECTS_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/project/ui/resources/projectTab.png", false); //NOI18N |
69 |
private static final Icon SELECT_IN_FILES_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/project/ui/resources/filesTab.png", false); //NOI18N |
59 |
private static final Icon SELECT_IN_FILES_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/project/ui/resources/filesTab.png", false); //NOI18N |
70 |
|
60 |
|
71 |
private static final String SELECT_IN_PROJECTS_NAME = NbBundle.getMessage( CloseProject.class, "LBL_SelectInProjectsAction_Name" ); // NOI18N |
61 |
private static final String SELECT_IN_PROJECTS_NAME = NbBundle.getMessage(CloseProject.class, "LBL_SelectInProjectsAction_MainMenuName"); // NOI18N |
72 |
private static final String SELECT_IN_FILES_NAME = NbBundle.getMessage( CloseProject.class, "LBL_SelectInFilesAction_Name" ); // NOI18N |
62 |
private static final String SELECT_IN_FILES_NAME = NbBundle.getMessage(CloseProject.class, "LBL_SelectInFilesAction_MainMenuName"); // NOI18N |
73 |
|
|
|
74 |
private static final String SELECT_IN_PROJECTS_NAME_MENU = NbBundle.getMessage( CloseProject.class, "LBL_SelectInProjectsAction_MenuName" ); // NOI18N |
75 |
private static final String SELECT_IN_FILES_NAME_MENU = NbBundle.getMessage( CloseProject.class, "LBL_SelectInFilesAction_MenuName" ); // NOI18N |
76 |
private static final String SELECT_IN_PROJECTS_NAME_MAIN_MENU = NbBundle.getMessage( CloseProject.class, "LBL_SelectInProjectsAction_MainMenuName" ); // NOI18N |
77 |
private static final String SELECT_IN_FILES_NAME_MAIN_MENU = NbBundle.getMessage( CloseProject.class, "LBL_SelectInFilesAction_MainMenuName" ); // NOI18N |
78 |
|
79 |
private String command; |
80 |
private ProjectActionPerformer performer; |
81 |
private String namePattern; |
82 |
|
63 |
|
83 |
private String findIn; |
64 |
private String findIn; |
84 |
|
65 |
|
Lines 100-110
Link Here
|
100 |
return a; |
81 |
return a; |
101 |
} |
82 |
} |
102 |
|
83 |
|
103 |
/** |
|
|
104 |
* Constructor for global actions. E.g. actions in main menu which |
105 |
* listen to the global context. |
106 |
* |
107 |
*/ |
108 |
public SelectNodeAction( Icon icon, String name ) { |
84 |
public SelectNodeAction( Icon icon, String name ) { |
109 |
this(icon, name, null); |
85 |
this(icon, name, null); |
110 |
} |
86 |
} |
Lines 112-128
Link Here
|
112 |
super( icon, lookup, new Class[] { DataObject.class, FileObject.class } ); |
88 |
super( icon, lookup, new Class[] { DataObject.class, FileObject.class } ); |
113 |
this.setDisplayName( name ); |
89 |
this.setDisplayName( name ); |
114 |
} |
90 |
} |
115 |
|
|
|
116 |
private SelectNodeAction(String command, ProjectActionPerformer performer, String namePattern, Icon icon, Lookup lookup) { |
117 |
super( icon, lookup, new Class[] { Project.class, DataObject.class, FileObject.class } ); |
118 |
this.command = command; |
119 |
this.performer = performer; |
120 |
this.namePattern = namePattern; |
121 |
refresh(getLookup(), true); |
122 |
} |
123 |
|
91 |
|
124 |
protected void actionPerformed( Lookup context ) { |
92 |
protected void actionPerformed( Lookup context ) { |
125 |
|
|
|
126 |
FileObject fo = getFileFromLookup( context ); |
93 |
FileObject fo = getFileFromLookup( context ); |
127 |
if ( fo != null ) { |
94 |
if ( fo != null ) { |
128 |
ProjectTab pt = ProjectTab.findDefault( findIn ); |
95 |
ProjectTab pt = ProjectTab.findDefault( findIn ); |
Lines 135-171
Link Here
|
135 |
setEnabled( fo != null ); |
102 |
setEnabled( fo != null ); |
136 |
} |
103 |
} |
137 |
|
104 |
|
138 |
protected final String getCommand() { |
|
|
139 |
return command; |
140 |
} |
141 |
|
142 |
protected final String getNamePattern() { |
143 |
return namePattern; |
144 |
} |
145 |
|
146 |
// Presenter.Menu implementation ------------------------------------------ |
147 |
|
148 |
public JMenuItem getMenuPresenter () { |
149 |
if (ProjectTab.ID_LOGICAL.equals (this.findIn)) { |
150 |
return buildPresenter(SELECT_IN_PROJECTS_NAME_MAIN_MENU); |
151 |
} else { |
152 |
return buildPresenter(SELECT_IN_FILES_NAME_MAIN_MENU); |
153 |
} |
154 |
} |
155 |
|
156 |
// Presenter.Popup implementation ------------------------------------------ |
157 |
|
158 |
public JMenuItem getPopupPresenter() { |
159 |
if (ProjectTab.ID_LOGICAL.equals (this.findIn)) { |
160 |
return buildPresenter(SELECT_IN_PROJECTS_NAME_MENU); |
161 |
} else { |
162 |
return buildPresenter(SELECT_IN_FILES_NAME_MENU); |
163 |
} |
164 |
} |
165 |
|
166 |
|
167 |
// Private methods --------------------------------------------------------- |
168 |
|
169 |
private FileObject getFileFromLookup( Lookup context ) { |
105 |
private FileObject getFileFromLookup( Lookup context ) { |
170 |
|
106 |
|
171 |
FileObject fo = context.lookup(FileObject.class); |
107 |
FileObject fo = context.lookup(FileObject.class); |
Lines 178-190
Link Here
|
178 |
return dobj == null ? null : dobj.getPrimaryFile(); |
114 |
return dobj == null ? null : dobj.getPrimaryFile(); |
179 |
} |
115 |
} |
180 |
|
116 |
|
181 |
private JMenuItem buildPresenter (String title) { |
|
|
182 |
JMenuItem menuPresenter = new JMenuItem (this); |
183 |
Mnemonics.setLocalizedText(menuPresenter, title); |
184 |
menuPresenter.setIcon(null); |
185 |
|
186 |
return menuPresenter; |
187 |
} |
188 |
|
189 |
|
190 |
} |
117 |
} |