Lines 56-61
Link Here
|
56 |
import javax.swing.JFileChooser; |
56 |
import javax.swing.JFileChooser; |
57 |
import javax.swing.JMenuItem; |
57 |
import javax.swing.JMenuItem; |
58 |
import javax.swing.SwingUtilities; |
58 |
import javax.swing.SwingUtilities; |
|
|
59 |
import org.netbeans.modules.favorites.api.Favorites; |
59 |
import org.openide.DialogDisplayer; |
60 |
import org.openide.DialogDisplayer; |
60 |
import org.openide.NotifyDescriptor; |
61 |
import org.openide.NotifyDescriptor; |
61 |
import org.openide.filesystems.FileObject; |
62 |
import org.openide.filesystems.FileObject; |
Lines 147-160
Link Here
|
147 |
Tab proj = Tab.findDefault(); |
148 |
Tab proj = Tab.findDefault(); |
148 |
proj.open(); |
149 |
proj.open(); |
149 |
proj.requestActive(); |
150 |
proj.requestActive(); |
150 |
proj.doSelectNode((DataObject)activatedNodes[0].getCookie(DataObject.class)); |
151 |
proj.doSelectNode(activatedNodes[0].getCookie(DataObject.class)); |
151 |
} |
152 |
} |
152 |
|
153 |
|
153 |
protected boolean enable(Node[] activatedNodes) { |
154 |
protected boolean enable(Node[] activatedNodes) { |
154 |
if (activatedNodes.length != 1) { |
155 |
if (activatedNodes.length != 1) { |
155 |
return false; |
156 |
return false; |
156 |
} |
157 |
} |
157 |
DataObject dobj = (DataObject)activatedNodes[0].getCookie(DataObject.class); |
158 |
DataObject dobj = activatedNodes[0].getCookie(DataObject.class); |
158 |
if (dobj == null) { |
159 |
if (dobj == null) { |
159 |
return false; |
160 |
return false; |
160 |
} |
161 |
} |
Lines 167-178
Link Here
|
167 |
} |
168 |
} |
168 |
|
169 |
|
169 |
/** Overriden to have different title in popup menu, works but ugly a bit */ |
170 |
/** Overriden to have different title in popup menu, works but ugly a bit */ |
|
|
171 |
@Override |
170 |
public JMenuItem getPopupPresenter() { |
172 |
public JMenuItem getPopupPresenter() { |
171 |
JMenuItem mi = super.getPopupPresenter(); |
173 |
JMenuItem mi = super.getPopupPresenter(); |
172 |
mi.setText(NbBundle.getMessage(Select.class, "ACT_Select")); // NOI18N |
174 |
mi.setText(NbBundle.getMessage(Select.class, "ACT_Select")); // NOI18N |
173 |
return mi; |
175 |
return mi; |
174 |
} |
176 |
} |
175 |
|
177 |
|
|
|
178 |
@Override |
176 |
protected String iconResource() { |
179 |
protected String iconResource() { |
177 |
return "org/netbeans/modules/favorites/resources/actionSelect.png"; // NOI18N |
180 |
return "org/netbeans/modules/favorites/resources/actionSelect.png"; // NOI18N |
178 |
} |
181 |
} |
Lines 181-186
Link Here
|
181 |
return null; |
184 |
return null; |
182 |
} |
185 |
} |
183 |
|
186 |
|
|
|
187 |
@Override |
184 |
protected boolean asynchronous() { |
188 |
protected boolean asynchronous() { |
185 |
return false; |
189 |
return false; |
186 |
} |
190 |
} |
Lines 207-215
Link Here
|
207 |
if ((arr == null) || (arr.length == 0)) return false; |
211 |
if ((arr == null) || (arr.length == 0)) return false; |
208 |
|
212 |
|
209 |
for (int i = 0; i < arr.length; i++) { |
213 |
for (int i = 0; i < arr.length; i++) { |
210 |
DataObject shad = (DataObject) arr[i].getCookie (DataObject.class); |
214 |
DataObject shad = arr[i].getCookie(DataObject.class); |
211 |
//Disable when node is not shadow in Favorites folder. |
215 |
//Disable when node is not shadow in Favorites folder. |
212 |
if (shad == null || shad.getFolder() != Favorites.getFolder()) { |
216 |
if (shad == null || shad.getFolder() != FavoritesNode.getFolder()) { |
213 |
return false; |
217 |
return false; |
214 |
} |
218 |
} |
215 |
} |
219 |
} |
Lines 239-247
Link Here
|
239 |
*/ |
243 |
*/ |
240 |
protected void performAction (Node[] arr) { |
244 |
protected void performAction (Node[] arr) { |
241 |
for (int i = 0; i < arr.length; i++) { |
245 |
for (int i = 0; i < arr.length; i++) { |
242 |
DataObject shad = (DataObject) arr[i].getCookie(DataObject.class); |
246 |
DataObject shad = arr[i].getCookie(DataObject.class); |
243 |
|
247 |
|
244 |
if (shad != null && shad.getFolder() == Favorites.getFolder()) { |
248 |
if (shad != null && shad.getFolder() == FavoritesNode.getFolder()) { |
245 |
try { |
249 |
try { |
246 |
shad.delete(); |
250 |
shad.delete(); |
247 |
} catch (IOException ex) { |
251 |
} catch (IOException ex) { |
Lines 251-256
Link Here
|
251 |
} |
255 |
} |
252 |
} |
256 |
} |
253 |
|
257 |
|
|
|
258 |
@Override |
254 |
protected boolean asynchronous() { |
259 |
protected boolean asynchronous() { |
255 |
return false; |
260 |
return false; |
256 |
} |
261 |
} |
Lines 280-291
Link Here
|
280 |
*/ |
285 |
*/ |
281 |
public boolean enable (Node[] arr) { |
286 |
public boolean enable (Node[] arr) { |
282 |
if ((arr == null) || (arr.length == 0)) return false; |
287 |
if ((arr == null) || (arr.length == 0)) return false; |
283 |
if (arr.length == 1 && arr[0] instanceof Favorites) return true; |
288 |
if (arr.length == 1 && arr[0] instanceof FavoritesNode) return true; |
284 |
|
289 |
|
285 |
|
290 |
|
286 |
|
291 |
|
287 |
for (int i = 0; i < arr.length; i++) { |
292 |
for (int i = 0; i < arr.length; i++) { |
288 |
DataObject dataObject = (DataObject) arr[i].getCookie (DataObject.class); |
293 |
DataObject dataObject = arr[i].getCookie(DataObject.class); |
289 |
//Action is disabled for root folder eg:"/" on Linux or "C:" on Win |
294 |
//Action is disabled for root folder eg:"/" on Linux or "C:" on Win |
290 |
if (dataObject == null) { |
295 |
if (dataObject == null) { |
291 |
return false; |
296 |
return false; |
Lines 297-303
Link Here
|
297 |
return false; |
302 |
return false; |
298 |
} |
303 |
} |
299 |
//Allow to link only once |
304 |
//Allow to link only once |
300 |
if (isInFavorites(fo)) { |
305 |
if (Favorites.getDefault().isInFavorites(fo)) { |
301 |
return false; |
306 |
return false; |
302 |
} |
307 |
} |
303 |
//Check if it is root. |
308 |
//Check if it is root. |
Lines 322-344
Link Here
|
322 |
return true; |
327 |
return true; |
323 |
} |
328 |
} |
324 |
|
329 |
|
325 |
/** Check if given fileobject is already linked in favorites |
|
|
326 |
* @return true if given fileobject is already linked |
327 |
*/ |
328 |
private boolean isInFavorites (FileObject fo) { |
329 |
DataFolder f = Favorites.getFolder(); |
330 |
|
331 |
DataObject [] arr = f.getChildren(); |
332 |
for (int i = 0; i < arr.length; i++) { |
333 |
if (arr[i] instanceof DataShadow) { |
334 |
if (fo.equals(((DataShadow) arr[i]).getOriginal().getPrimaryFile())) { |
335 |
return true; |
336 |
} |
337 |
} |
338 |
} |
339 |
return false; |
340 |
} |
341 |
|
342 |
/** Human presentable name of the action. This should be |
330 |
/** Human presentable name of the action. This should be |
343 |
* presented as an item in a menu. |
331 |
* presented as an item in a menu. |
344 |
* @return the name of the action |
332 |
* @return the name of the action |
Lines 361-367
Link Here
|
361 |
* @param activatedNodes gives array of actually activated nodes. |
349 |
* @param activatedNodes gives array of actually activated nodes. |
362 |
*/ |
350 |
*/ |
363 |
protected void performAction (final Node[] activatedNodes) { |
351 |
protected void performAction (final Node[] activatedNodes) { |
364 |
final DataFolder f = Favorites.getFolder(); |
352 |
final DataFolder f = FavoritesNode.getFolder(); |
365 |
final DataObject [] arr = f.getChildren(); |
353 |
final DataObject [] arr = f.getChildren(); |
366 |
final List<DataObject> listAdd = new ArrayList<DataObject>(); |
354 |
final List<DataObject> listAdd = new ArrayList<DataObject>(); |
367 |
|
355 |
|
Lines 369-375
Link Here
|
369 |
Node[] toShadows = activatedNodes; |
357 |
Node[] toShadows = activatedNodes; |
370 |
|
358 |
|
371 |
try { |
359 |
try { |
372 |
if (activatedNodes.length == 1 && activatedNodes[0] instanceof Favorites) { |
360 |
if (activatedNodes.length == 1 && activatedNodes[0] instanceof FavoritesNode) { |
373 |
// show JFileChooser |
361 |
// show JFileChooser |
374 |
FileObject fo = chooseFileObject(); |
362 |
FileObject fo = chooseFileObject(); |
375 |
if (fo == null) return; |
363 |
if (fo == null) return; |
Lines 430-442
Link Here
|
430 |
return retVal; |
418 |
return retVal; |
431 |
} |
419 |
} |
432 |
|
420 |
|
433 |
static void selectAfterAddition(final DataObject createdDO) { |
421 |
public static void selectAfterAddition(final DataObject createdDO) { |
434 |
final Tab projectsTab = Tab.findDefault(); |
422 |
final Tab projectsTab = Tab.findDefault(); |
435 |
projectsTab.open(); |
423 |
projectsTab.open(); |
436 |
projectsTab.requestActive(); |
424 |
projectsTab.requestActive(); |
437 |
//Try to locate newly added node and select it |
425 |
//Try to locate newly added node and select it |
438 |
if (createdDO != null) { |
426 |
if (createdDO != null) { |
439 |
Node n = Favorites.getNode(); |
427 |
Node n = FavoritesNode.getNode(); |
440 |
Node [] nodes = projectsTab.getExplorerManager().getRootContext().getChildren().getNodes(true); |
428 |
Node [] nodes = projectsTab.getExplorerManager().getRootContext().getChildren().getNodes(true); |
441 |
final Node [] toSelect = new Node[1]; |
429 |
final Node [] toSelect = new Node[1]; |
442 |
boolean setSelected = false; |
430 |
boolean setSelected = false; |
Lines 464-470
Link Here
|
464 |
static DataObject createShadows(final DataFolder favourities, final Node[] activatedNodes, final List<DataObject> listAdd) { |
452 |
static DataObject createShadows(final DataFolder favourities, final Node[] activatedNodes, final List<DataObject> listAdd) { |
465 |
DataObject createdDO = null; |
453 |
DataObject createdDO = null; |
466 |
for (int i = 0; i < activatedNodes.length; i++) { |
454 |
for (int i = 0; i < activatedNodes.length; i++) { |
467 |
DataObject obj = (DataObject) activatedNodes[i].getCookie(DataObject.class); |
455 |
DataObject obj = activatedNodes[i].getCookie(DataObject.class); |
468 |
|
456 |
|
469 |
if (obj != null) { |
457 |
if (obj != null) { |
470 |
try { |
458 |
try { |
Lines 483-489
Link Here
|
483 |
return createdDO; |
471 |
return createdDO; |
484 |
} |
472 |
} |
485 |
|
473 |
|
486 |
static void reorderAfterAddition(final DataFolder favourities, final DataObject[] children, final List<DataObject> listAdd) { |
474 |
public static void reorderAfterAddition(final DataFolder favourities, final DataObject[] children, final List<DataObject> listAdd) { |
487 |
List<DataObject> listDest = new ArrayList<DataObject>(); |
475 |
List<DataObject> listDest = new ArrayList<DataObject>(); |
488 |
if (listAdd.size() > 0) { |
476 |
if (listAdd.size() > 0) { |
489 |
//Insert new nodes just before last (root) node |
477 |
//Insert new nodes just before last (root) node |
Lines 520-525
Link Here
|
520 |
} |
508 |
} |
521 |
} |
509 |
} |
522 |
|
510 |
|
|
|
511 |
@Override |
523 |
protected boolean asynchronous() { |
512 |
protected boolean asynchronous() { |
524 |
return false; |
513 |
return false; |
525 |
} |
514 |
} |
Lines 543-548
Link Here
|
543 |
* presented as an item in a menu. |
532 |
* presented as an item in a menu. |
544 |
* @return the name of the action |
533 |
* @return the name of the action |
545 |
*/ |
534 |
*/ |
|
|
535 |
@Override |
546 |
public String getName() { |
536 |
public String getName() { |
547 |
return NbBundle.getMessage ( |
537 |
return NbBundle.getMessage ( |
548 |
Actions.class, "ACT_AddOnFavoritesNode"); // NOI18N |
538 |
Actions.class, "ACT_AddOnFavoritesNode"); // NOI18N |