Example usage for javax.swing JPopupMenu getSubElements

List of usage examples for javax.swing JPopupMenu getSubElements

Introduction

In this page you can find the example usage for javax.swing JPopupMenu getSubElements.

Prototype

@BeanProperty(bound = false)
public MenuElement[] getSubElements() 

Source Link

Document

Returns an array of MenuElements containing the submenu for this menu component.

Usage

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_layer.java

@Override
public void doPopup(MouseEvent e, int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());// w  ww . j av a  2 s .  com
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!isTableEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                if (networkElementType == NetworkElementType.LAYER
                        && callback.getDesign().getNumberOfLayers() == 1) {

                } else {
                    JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                    removeItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            NetPlan netPlan = callback.getDesign();

                            try {
                                netPlan.removeNetworkLayer(netPlan.getNetworkLayerFromId((long) itemId));

                                final VisualizationState vs = callback.getVisualizationState();
                                Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs
                                        .suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(
                                                new HashSet<>(callback.getDesign().getNetworkLayers()));
                                vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(),
                                        res.getSecond());
                                callback.updateVisualizationAfterChanges(
                                        Sets.newHashSet(NetworkElementType.LAYER));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                            } catch (Throwable ex) {
                                ErrorHandling.addErrorOrException(ex, getClass());
                                ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                            }
                        }
                    });

                    popup.add(removeItem);
                }

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

    popup.show(e.getComponent(), e.getX(), e.getY());
}

From source file:forge.screens.match.CMatchUI.java

@Override
public SpellAbility getAbilityToPlay(List<SpellAbility> abilities, ITriggerEvent triggerEvent) {
    if (triggerEvent == null) {
        if (abilities.isEmpty()) {
            return null;
        }//w w w. ja v a 2 s .  c  o  m
        if (abilities.size() == 1) {
            return abilities.get(0);
        }
        return GuiChoose.oneOrNone("Choose ability to play", abilities);
    }

    if (abilities.isEmpty()) {
        return null;
    }
    if (abilities.size() == 1 && !abilities.get(0).promptIfOnlyPossibleAbility()) {
        if (abilities.get(0).canPlay()) {
            return abilities.get(0); //only return ability if it's playable, otherwise return null
        }
        return null;
    }

    //show menu if mouse was trigger for ability
    final JPopupMenu menu = new JPopupMenu("Abilities");

    boolean enabled;
    boolean hasEnabled = false;
    int shortcut = KeyEvent.VK_1; //use number keys as shortcuts for abilities 1-9
    for (final SpellAbility ab : abilities) {
        enabled = ab.canPlay();
        if (enabled) {
            hasEnabled = true;
        }
        GuiUtils.addMenuItem(menu, FSkin.encodeSymbols(ab.toString(), true),
                shortcut > 0 ? KeyStroke.getKeyStroke(shortcut, 0) : null, new Runnable() {
                    @Override
                    public void run() {
                        CPrompt.SINGLETON_INSTANCE.selectAbility(ab);
                    }
                }, enabled);
        if (shortcut > 0) {
            shortcut++;
            if (shortcut > KeyEvent.VK_9) {
                shortcut = 0; //stop adding shortcuts after 9
            }
        }
    }
    if (hasEnabled) { //only show menu if at least one ability can be played
        SwingUtilities.invokeLater(new Runnable() { //use invoke later to ensure first ability selected by default
            public void run() {
                MenuSelectionManager.defaultManager()
                        .setSelectedPath(new MenuElement[] { menu, menu.getSubElements()[0] });
            }
        });
        MouseEvent mouseEvent = ((MouseTriggerEvent) triggerEvent).getMouseEvent();
        menu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
    }

    return null; //delay ability until choice made
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

@Override
public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();
    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<MulticastDemand> demandRowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<MulticastDemand> selectedDemands = (List<MulticastDemand>) (List<?>) getSelectedElements()
            .getFirst();/*from   ww  w. j  ava  2s  .c o m*/
    if (!selectedDemands.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this demand traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this demand traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!demandRowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                if (networkElementType == NetworkElementType.LAYER
                        && callback.getDesign().getNumberOfLayers() == 1) {

                } else {
                    JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                    removeItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            NetPlan netPlan = callback.getDesign();

                            try {
                                netPlan.getMulticastDemandFromId((long) itemId).remove();
                                callback.getVisualizationState()
                                        .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                                callback.updateVisualizationAfterChanges(
                                        Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                            } catch (Throwable ex) {
                                ErrorHandling.addErrorOrException(ex, getClass());
                                ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                            }
                        }
                    });

                    popup.add(removeItem);
                }

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            if (networkElementType != NetworkElementType.LAYER) {
                JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in table");

                removeItems.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        NetPlan netPlan = callback.getDesign();
                        try {
                            if (rf == null)
                                netPlan.removeAllMulticastDemands();
                            else
                                for (MulticastDemand d : demandRowsInTheTable)
                                    d.remove();
                            callback.getVisualizationState()
                                    .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                            callback.updateVisualizationAfterChanges(
                                    Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ex.printStackTrace();
                            ErrorHandling.showErrorDialog(ex.getMessage(),
                                    "Unable to remove all " + networkElementType + "s");
                        }
                    }
                });
                popup.add(removeItems);
            }

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

    popup.show(e.getComponent(), e.getX(), e.getY());
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_node.java

@Override
public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();
    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<Node> rowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<Node> selectedNodes = (List<Node>) (List<?>) getSelectedElements().getFirst();
    if (!selectedNodes.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this node traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this node traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override/*from w  w w  .  j ava 2  s .c  o m*/
            public void actionPerformed(ActionEvent e) {
                if (selectedNodes.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedNodes.get(0),
                        callback.getDesign().getNetworkLayerDefault(), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedNodes.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedNodes.get(0),
                        callback.getDesign().getNetworkLayerDefault(), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!rowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);
                removeItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            callback.getDesign().getNodeFromId((long) itemId).remove();
                            callback.getVisualizationState()
                                    .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ErrorHandling.addErrorOrException(ex, getClass());
                            ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                        }
                    }
                });

                popup.add(removeItem);
                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in the table");

            removeItems.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    NetPlan netPlan = callback.getDesign();

                    try {
                        if (rf == null)
                            netPlan.removeAllNodes();
                        else
                            for (Node n : rowsInTheTable)
                                n.remove();
                        callback.getVisualizationState()
                                .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                        callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                        ErrorHandling.showErrorDialog(ex.getMessage(),
                                "Unable to remove all " + networkElementType + "s");
                    }
                }
            });

            popup.add(removeItems);

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

    popup.show(e.getComponent(), e.getX(), e.getY());
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_demand.java

public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();

    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<Demand> demandRowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<Demand> selectedDemands = (List<Demand>) (List<?>) getSelectedElements().getFirst();
    if (!selectedDemands.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this demand traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this demand traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override/*from w  w w  .  ja  va  2  s  .c  om*/
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!demandRowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                removeItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        NetPlan netPlan = callback.getDesign();

                        try {
                            final Demand demand = netPlan.getDemandFromId((long) itemId);
                            demand.remove();
                            callback.getVisualizationState().resetPickedState();
                            callback.updateVisualizationAfterChanges(
                                    Collections.singleton(NetworkElementType.DEMAND));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ErrorHandling.addErrorOrException(ex, getClass());
                            ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                        }
                    }
                });

                popup.add(removeItem);

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }

            JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in the table");
            removeItems.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    NetPlan netPlan = callback.getDesign();

                    try {
                        if (rf == null)
                            netPlan.removeAllDemands();
                        else
                            for (Demand d : demandRowsInTheTable)
                                d.remove();

                        callback.getVisualizationState().resetPickedState();
                        callback.updateVisualizationAfterChanges(
                                Collections.singleton(NetworkElementType.DEMAND));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                        ErrorHandling.showErrorDialog(ex.getMessage(),
                                "Unable to remove all " + networkElementType + "s");
                    }
                }
            });

            popup.add(removeItems);

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

    popup.show(e.getComponent(), e.getX(), e.getY());
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_link.java

@Override
public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();
    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<Link> linkRowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<Link> selectedLinks = (List<Link>) (List<?>) getSelectedElements().getFirst();
    if (!selectedLinks.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this link traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this link traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override/*ww  w.j  a va2 s . co  m*/
            public void actionPerformed(ActionEvent e) {
                if (selectedLinks.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedLinks.get(0), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedLinks.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedLinks.get(0), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!linkRowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);
                removeItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        NetPlan netPlan = callback.getDesign();

                        try {
                            Link link = netPlan.getLinkFromId((long) itemId);
                            link.remove();
                            callback.getVisualizationState()
                                    .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ErrorHandling.addErrorOrException(ex, getClass());
                            ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                        }
                    }
                });

                popup.add(removeItem);
            }

            addPopupMenuAttributeOptions(e, row, itemId, popup);

            JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in table");

            removeItems.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    NetPlan netPlan = callback.getDesign();

                    try {
                        if (rf == null)
                            netPlan.removeAllLinks();
                        else
                            for (Link ee : linkRowsInTheTable)
                                ee.remove();
                        callback.getVisualizationState()
                                .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                        callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                        ErrorHandling.showErrorDialog(ex.getMessage(),
                                "Unable to remove all " + networkElementType + "s");
                    }
                }
            });

            popup.add(removeItems);

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

    popup.show(e.getComponent(), e.getX(), e.getY());
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java

@Test
//Temporarily adding ignore as this testcase has some defect and fails
// all the time. This has to be fixed in the next release.
@Ignore/*  w  w  w.  j  av a  2s  .  co  m*/
public final void testHeapsOfStuff() {
    /**
     * Test a lot of the entity creation / deletion Tests hot keys also
     */
    depositPresenter.refreshFileList();
    DepositTreeModel fileSystemModel = (DepositTreeModel) theFrame.treeFileSystem.getModel();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    assertTrue(rootNode.getChildCount() > 0);
    DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    assertTrue(childNode.getChildCount() == 1); // Should be a placeholder
    DefaultMutableTreeNode grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(0);
    assertTrue(grandChildNode.getUserObject() instanceof FileSystemObject);
    FileSystemObject fso = (FileSystemObject) grandChildNode.getUserObject();
    assertTrue(fso.getIsPlaceholder());
    TreePath currentTreePath = new TreePath(childNode.getPath());
    depositPresenter.expandFileSystemTree(currentTreePath);
    if (childNode.getChildCount() > 0) {
        grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(0);
        assertTrue(grandChildNode.getUserObject() instanceof FileSystemObject);
        fso = (FileSystemObject) grandChildNode.getUserObject();
        assertFalse(fso.getIsPlaceholder());
    }
    try {
        setUp();
    } catch (Exception ex) {
        fail();
    }
    // After setup the model will have changed - but it shouldn't change
    // again after this
    fileSystemModel = (DepositTreeModel) theFrame.treeFileSystem.getModel();
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();

    TreePath[] selectionPaths = loadEntity(RESOURCES_INPUT_PATH_NAMED);
    // Entity root not set yet - should be able to get a menu
    JPopupMenu menu = depositPresenter.processFileTreeKeyPress('m', selectionPaths);
    assertTrue(menu != null);
    // Set the root
    menu = depositPresenter.processFileTreeKeyPress('s', selectionPaths);
    DepositTreeModel entityModel = (DepositTreeModel) theFrame.treeEntities.getModel();
    DepositTreeModel structMapModel = (DepositTreeModel) theFrame.treeStructMap.getModel();
    assertTrue(menu == null);
    // The digital original should already have been added automatically
    // Only one allowed, so this should fail.
    assertFalse(depositPresenter.canAddRepresentationType('d'));
    // Only one allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('p'));
    // multiple allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('a'));
    // multiple allowed, two added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('m'));

    // While we've got the named stuff loaded, might as well check the move
    // up/down
    DefaultMutableTreeNode ieRootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    // Right - we should have one DO & 2 AC
    assertTrue(ieRootNode.getChildCount() == 3);
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) ieRootNode.getChildAt(0);
    assertTrue(node.getUserObject() instanceof FileGroup);
    FileGroup group = (FileGroup) node.getUserObject();
    assertTrue(group.getEntityType().equals(RepresentationTypes.DigitalOriginal));
    int childNo = 0;
    childNode = (DefaultMutableTreeNode) node.getChildAt(childNo);
    assertTrue(childNode.getUserObject() instanceof FileSystemObject);
    fso = (FileSystemObject) childNode.getUserObject();
    // while (fso.getFileName().equalsIgnoreCase(".svn")) {
    // childNo++;
    // childNode = (DefaultMutableTreeNode)node.getChildAt(childNo);
    // assertTrue(childNode.getUserObject() instanceof FileSystemObject);
    // fso = (FileSystemObject)childNode.getUserObject();
    // }
    // childNo = 0;
    fso.setSortBy(SortBy.UserArranged);
    while (!fso.getFileName().equalsIgnoreCase("Chapter1")) {
        childNo++;
        childNode = (DefaultMutableTreeNode) node.getChildAt(childNo);
        assertTrue(childNode.getUserObject() instanceof FileSystemObject);
        fso = (FileSystemObject) childNode.getUserObject();
    }
    doIEMoveTest(childNo, node.getChildCount(), fso, group);

    childNo = 0;
    DefaultMutableTreeNode subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
    assertTrue(subChildNode.getUserObject() instanceof FileSystemObject);
    FileSystemObject fsoChild = (FileSystemObject) subChildNode.getUserObject();
    fsoChild.setSortBy(SortBy.UserArranged);
    while (!fsoChild.getFileName().equalsIgnoreCase("test_87_archive_1_P_1.jpg")) {
        childNo++;
        subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
        assertTrue(subChildNode.getUserObject() instanceof FileSystemObject);
        fsoChild = (FileSystemObject) subChildNode.getUserObject();
    }
    fso.setSortBy(SortBy.UserArranged);
    fsoChild.setSortBy(SortBy.UserArranged);
    // doIEMoveTest(childNo, childNode.getChildCount(), fsoChild, fso);

    node = (DefaultMutableTreeNode) ieRootNode.getChildAt(1);
    assertTrue(node.getUserObject() instanceof FileGroup);
    group = (FileGroup) node.getUserObject();
    assertTrue(group.getEntityType().equals(RepresentationTypes.AccessCopy));
    node = (DefaultMutableTreeNode) ieRootNode.getChildAt(2);
    assertTrue(node.getUserObject() instanceof FileGroup);
    group = (FileGroup) node.getUserObject();
    assertTrue(group.getEntityType().equals(RepresentationTypes.AccessCopy));

    DefaultMutableTreeNode structRootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    childNo = 0;
    childNode = (DefaultMutableTreeNode) structRootNode.getChildAt(childNo);
    assertTrue(childNode.getUserObject() instanceof StructMap);
    StructMap map = (StructMap) childNode.getUserObject();
    while (!map.getStructureName().equalsIgnoreCase("Chapter1")) {
        childNo++;
        childNode = (DefaultMutableTreeNode) structRootNode.getChildAt(childNo);
        assertTrue(childNode.getUserObject() instanceof StructMap);
        map = (StructMap) childNode.getUserObject();
    }
    doStructMoveTest(childNo, structRootNode.getChildCount(), map, structRootNode.getUserObject());
    childNo = 0;
    subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
    assertTrue(subChildNode.getUserObject() instanceof StructMap);
    map = (StructMap) subChildNode.getUserObject();
    while (!map.getStructureName().equalsIgnoreCase("Page 1")) {
        childNo++;
        subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
        assertTrue(subChildNode.getUserObject() instanceof StructMap);
        map = (StructMap) subChildNode.getUserObject();
    }
    doStructMoveTest(childNo, structRootNode.getChildCount(), map, childNode.getUserObject());
    childNo = 0;
    DefaultMutableTreeNode subSubChildNode = (DefaultMutableTreeNode) subChildNode.getChildAt(childNo);
    assertTrue(subSubChildNode.getUserObject() instanceof FileSystemObject);
    fso = (FileSystemObject) subSubChildNode.getUserObject();
    while (!fso.getFileName().equalsIgnoreCase("test_87_view_1_P_1.jpg")) {
        childNo++;
        subSubChildNode = (DefaultMutableTreeNode) subChildNode.getChildAt(childNo);
        assertTrue(subSubChildNode.getUserObject() instanceof FileSystemObject);
        fso = (FileSystemObject) subSubChildNode.getUserObject();
    }
    doStructMoveTest(childNo, subChildNode.getChildCount(), fso, subChildNode.getUserObject());

    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    FSOCollection coll = FSOCollection.create();
    coll.add((FileSystemObject) rootNode.getUserObject());
    FileSystemObject child = coll.getFSOByFullFileName("test_87_view_1_P_1.jpg", true);
    depositPresenter.selectNode(child, ETreeType.EntityTree);
    assertTrue(depositPresenter.canCreateAutoStructItem());

    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    depositPresenter.selectNode(rootNode.getUserObject(), ETreeType.EntityTree);
    assertFalse(depositPresenter.canCreateAutoStructItem());
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    depositPresenter.selectNode(node.getUserObject(), ETreeType.EntityTree);
    assertFalse(depositPresenter.canCreateAutoStructItem());

    // Delete all the struct map & entity nodes so we can re-add them using
    // hot keys
    rootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    int nodeNo = 0;
    node = (DefaultMutableTreeNode) rootNode.getChildAt(nodeNo);
    map = (StructMap) node.getUserObject();
    while (!map.getStructureName().equals("Chapter1")) {
        nodeNo++;
        node = (DefaultMutableTreeNode) rootNode.getChildAt(nodeNo);
        map = (StructMap) node.getUserObject();
    }
    nodeNo = 0;
    childNode = (DefaultMutableTreeNode) node.getChildAt(nodeNo);
    map = (StructMap) childNode.getUserObject();
    while (!map.getStructureName().equals("Page 1")) {
        nodeNo++;
        childNode = (DefaultMutableTreeNode) node.getChildAt(nodeNo);
        map = (StructMap) childNode.getUserObject();
    }
    assertTrue(childNode.getChildCount() == 3);
    grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(0);
    TreePath path = new TreePath(grandChildNode.getPath());
    theFrame.treeStructMap.setSelectionPath(path);
    Object nodeObject = grandChildNode.getUserObject();
    // _presenter.selectNode(nodeObject, ETreeType.StructMapTree);
    assertTrue(depositPresenter.canDeleteStructItem());
    depositPresenter.deleteStructMapItem();
    assertTrue(childNode.getChildCount() == 2);
    int noOfNodes = node.getChildCount();
    path = new TreePath(childNode.getPath());
    theFrame.treeStructMap.setSelectionPath(path);
    nodeObject = childNode.getUserObject();
    // _presenter.selectNode(nodeObject, ETreeType.StructMapTree);
    assertTrue(depositPresenter.canDeleteStructItem());
    depositPresenter.deleteStructMapItem();
    assertTrue(node.getChildCount() == noOfNodes - 1);

    noOfNodes = rootNode.getChildCount();
    for (int i = 0; i < noOfNodes; i++) {
        node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
        path = new TreePath(node.getPath());
        theFrame.treeStructMap.setSelectionPath(path);
        nodeObject = node.getUserObject();
        // _presenter.selectNode(nodeObject, ETreeType.StructMapTree);
        assertTrue(depositPresenter.canDeleteStructItem());
        depositPresenter.deleteStructMapItem();
        assertTrue(rootNode.getChildCount() == noOfNodes - i - 1);
        if (rootNode.getChildCount() > 0) {
            node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
            assertFalse(node.getUserObject().equals(nodeObject));
        }
    }
    assertTrue(rootNode.getChildCount() == 0);

    // Struct map should be clear now - clear IE
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    nodeNo = 0;
    childNode = (DefaultMutableTreeNode) node.getChildAt(nodeNo);
    fso = (FileSystemObject) childNode.getUserObject();
    while (!fso.getDescription().equals("Chapter1")) {
        nodeNo++;
        childNode = (DefaultMutableTreeNode) rootNode.getChildAt(nodeNo);
        fso = (FileSystemObject) childNode.getUserObject();
    }
    nodeNo = 0;
    grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(nodeNo);
    fso = (FileSystemObject) grandChildNode.getUserObject();
    while (!fso.getFileName().equals("test_87_archive_1_P_1.jpg")) {
        nodeNo++;
        grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(nodeNo);
        fso = (FileSystemObject) grandChildNode.getUserObject();
    }
    noOfNodes = childNode.getChildCount();
    path = new TreePath(grandChildNode.getPath());
    JPopupMenu pop = depositPresenter.getEntityMenu(grandChildNode);
    assertTrue(pop.getSubElements().length == 3);
    pop = depositPresenter.getEntityMenu(childNode);
    assertTrue(pop.getSubElements().length == 2);
    pop = depositPresenter.getEntityMenu(node);
    assertTrue(pop.getSubElements().length == 1);
    pop = depositPresenter.getEntityMenu(rootNode);
    assertTrue(pop.getSubElements().length == 3);

    theFrame.treeEntities.setSelectionPath(path);
    // _presenter.selectNode(nodeObject, ETreeType.EntityTree);
    assertTrue(depositPresenter.canDeleteEntityItem());
    depositPresenter.deleteEntity();
    assertTrue(childNode.getChildCount() == noOfNodes - 1);
    noOfNodes = node.getChildCount();
    path = new TreePath(childNode.getPath());
    theFrame.treeEntities.setSelectionPath(path);
    // _presenter.selectNode(nodeObject, ETreeType.EntityTree);
    assertTrue(depositPresenter.canDeleteEntityItem());
    depositPresenter.deleteEntity();
    assertTrue(node.getChildCount() == noOfNodes - 1);

    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    noOfNodes = rootNode.getChildCount();
    for (int i = 0; i < noOfNodes; i++) {
        node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
        path = new TreePath(node.getPath());
        theFrame.treeEntities.setSelectionPath(path);
        nodeObject = node.getUserObject();
        // _presenter.selectNode(nodeObject, ETreeType.EntityTree);
        assertTrue(depositPresenter.canDeleteEntityItem());
        depositPresenter.deleteEntity();
        assertTrue(rootNode.getChildCount() == noOfNodes - i - 1);
        if (rootNode.getChildCount() > 0) {
            node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
            assertFalse(node.getUserObject().equals(nodeObject));
        }
        rootNode = (DefaultMutableTreeNode) entityModel.getRoot(); // Make
        // sure
        // we
        // have
        // the
        // right
        // root
        // node
        // - it
        // changes
    }
    assertTrue(rootNode.getChildCount() == 0);
    depositPresenter.resetScreen();

    // Adding an auto structure item from a single file
    // should result in all three representation types being there
    selectionPaths = loadEntity(RESOURCES_INPUT_MANUAL);
    // Entity root not set yet - should be able to get a menu
    menu = depositPresenter.processFileTreeKeyPress('m', selectionPaths);
    assertTrue(menu != null);
    // Set the root
    menu = depositPresenter.processFileTreeKeyPress('s', selectionPaths);
    assertTrue(menu == null);
    // Only one allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('d'));
    // Only one allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('p'));
    // multiple allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('a'));
    // multiple allowed, two added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('m'));

    // Create DO
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    String[] fileNames = { "File1.jpg", "File1.tif", "File1.tn" };
    addFilesToEntityAndCheckResults(fileSystemModel, entityModel, fileNames,
            RepresentationTypes.DigitalOriginal);

    // Create AC 1
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    fileNames = new String[] { "File2.jpg", "File2.tif", "File2.tn" };
    addFilesToEntityAndCheckResults(fileSystemModel, entityModel, fileNames, RepresentationTypes.AccessCopy);

    // Create AC 2
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    fileNames = new String[] { "File3.jpg", "File3.tif", "File3.tn" };
    addFilesToEntityAndCheckResults(fileSystemModel, entityModel, fileNames, RepresentationTypes.AccessCopy);

    // Should now have a completely populated IE - test Struct map
    // Adding an auto structure item from a single file
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    coll = FSOCollection.create();
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    group = (FileGroup) node.getUserObject();
    coll = group.getChildren();
    child = coll.getFSOByFullFileName("File1.jpg", true);
    depositPresenter.selectNode(child, ETreeType.EntityTree);
    assertTrue(depositPresenter.canCreateAutoStructItem());
    theFrame.setInputResult("First Test");
    depositPresenter.createAutoStructItem(true);
    rootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    assertTrue(rootNode.getChildCount() == 1);
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    assertTrue(node.getChildCount() == 3);
    assertTrue(node.getUserObject() instanceof StructMap);
    map = (StructMap) node.getUserObject();
    assertTrue(map.getStructureName().equalsIgnoreCase("First Test"));
    node = (DefaultMutableTreeNode) node.getChildAt(0);
    ;
    assertTrue(node.getUserObject().equals(child));

    // Adding an auto structure item NOT from a single file
    // should result in only one representation type being there - the one
    // selected
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    coll = FSOCollection.create();
    node = (DefaultMutableTreeNode) rootNode.getChildAt(1);
    group = (FileGroup) node.getUserObject();
    coll = group.getChildren();
    child = coll.getFSOByFullFileName("File2.jpg", true);
    depositPresenter.selectNode(child, ETreeType.EntityTree);
    assertTrue(depositPresenter.canCreateAutoStructItem());
    theFrame.setInputResult("Second Test");
    depositPresenter.createAutoStructItem(false);
    rootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    assertTrue(rootNode.getChildCount() == 2);
    node = (DefaultMutableTreeNode) rootNode.getChildAt(1);
    assertTrue(node.getChildCount() == 1);
    assertTrue(node.getUserObject() instanceof StructMap);
    map = (StructMap) node.getUserObject();
    assertTrue(map.getStructureName().equalsIgnoreCase("Second Test"));
    node = (DefaultMutableTreeNode) node.getChildAt(0);
    ;
    assertTrue(node.getUserObject().equals(child));

    depositPresenter.resetScreen();
    selectionPaths = loadEntity(RESOURCES_INPUT_MULTIPLE);
    // Entity root should now be unset - should be able to get a menu
    menu = depositPresenter.processFileTreeKeyPress('m', selectionPaths);
    assertTrue(menu != null);
    // Set the multiple root
    menu = depositPresenter.processFileTreeKeyPress('e', selectionPaths);
    assertTrue(menu == null);
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    LOG.debug("ChildCount: " + rootNode.getChildCount());
    assertTrue(rootNode.getChildCount() >= 3); // 3 on local PC, 4 on
    // server. Gah!
    for (int i = 0; i < 3; i++) {
        node = (DefaultMutableTreeNode) rootNode.getChildAt(i);
        assertTrue(node.getUserObject() instanceof FileGroupCollection);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java

@Test
public final void testFavourites() {
    LOG.debug("*************************************************************************");
    LOG.debug("testFavourites");
    LOG.debug("*************************************************************************");
    // Set it up/*  w ww.j a va 2 s .  c  om*/
    FileUtils.deleteFileOrDirectoryRecursive(FAVOURITES_PATH);
    try {
        setUp();
    } catch (Exception ex) {
        fail();
    }
    DepositTreeModel fileSystemModel = (DepositTreeModel) theFrame.treeFileSystem.getModel();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    FSOCollection coll = FSOCollection.create();
    FileSystemObject fso = (FileSystemObject) rootNode.getUserObject();
    coll.add(fso);
    if (fso.getFile() == null) {
        LOG.debug("Root Object (file null): " + fso.getDescription());
    } else {
        try {
            LOG.debug("Root Object (file not null): " + fso.getFile().getCanonicalPath());
        } catch (Exception ex) {
        }
    }
    for (int i = 0; i < rootNode.getChildCount(); i++) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) rootNode.getChildAt(i);
        fso = (FileSystemObject) node.getUserObject();
        if (fso.getFile() == null) {
            LOG.debug("Child " + i + " (file null): " + fso.getDescription());
        } else {
            try {
                LOG.debug("Child " + i + " (file not null): " + fso.getFile().getCanonicalPath());
            } catch (Exception ex) {
            }
        }
    }
    File settingsPathFile = new File(RESOURCES_SETTINGS_PATH);
    File favouritesPathFile = new File(FAVOURITES_PATH);
    assertTrue(favouritesPathFile.exists());
    FileSystemObject child = null;
    // Make sure the tree includes the path
    String fullPath = "";
    try {
        fullPath = settingsPathFile.getCanonicalPath();
    } catch (Exception ex) {
        fail();
    }
    String[] paths;
    String fileSeparator = System.getProperty("file.separator");
    if (fileSeparator.equals("\\")) {
        fullPath = fullPath.replaceAll("/", fileSeparator);
        paths = fullPath.split("[\\\\]");
    } else {
        fullPath = fullPath.replaceAll("[\\\\]", fileSeparator);
        paths = fullPath.split(fileSeparator);
    }
    String currentPath = "";
    String rootPath = paths[0] + fileSeparator;
    LOG.debug("Full Path: " + fullPath);
    LOG.debug("Root Path: " + rootPath);
    for (int i = 0; i < paths.length; i++) {
        LOG.debug("Path " + i + ": " + paths[i]);
    }
    for (int i = 0; i < paths.length; i++) {
        currentPath += paths[i] + fileSeparator;
        LOG.debug("Current Path: " + currentPath);
        child = coll.getFSOByFullPath(currentPath, true);
        if (child == null) {
            LOG.debug("Child is null (not found)");
        } else {
            if (child.getFile() == null) {
                LOG.debug("Child found, file is null");
            } else {
                LOG.debug("Child found, path " + child.getFullPath());
            }
        }
        depositPresenter.selectNode(child, ETreeType.FileSystemTree);
        TreePath currentTreePath = theFrame.treeFileSystem.getSelectionPath();
        LOG.debug("currentTreePath: " + currentTreePath.toString());
        depositPresenter.expandFileSystemTree(currentTreePath);
    }

    // Test the favourites
    // No favourites loaded - check that the menu is empty
    TreePath[] treePaths = null;
    depositPresenter.clearFavourites();
    assertFalse(depositPresenter.canStoreFavourites(treePaths));
    treePaths = theFrame.treeFileSystem.getSelectionPaths();
    assertTrue(depositPresenter.canStoreFavourites(treePaths));
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) theFrame.treeFileSystem
            .getLastSelectedPathComponent();
    fso = (FileSystemObject) node.getUserObject();
    JPopupMenu menu = (JPopupMenu) theFrame.mnuFileFavourites.getSubElements()[0];
    assertTrue(menu.getSubElements().length == 1);
    JMenuItem item = (JMenuItem) menu.getSubElements()[0];
    String noFavouritesText = item.getText();
    assertFalse(noFavouritesText.equals(fso.getFullPath()));

    // Store a favourite & check that it is included in the menu
    depositPresenter.storeAsFavourite(node);
    assertTrue(menu.getSubElements().length == 2);
    item = (JMenuItem) menu.getSubElements()[0];
    assertTrue(item.getText().equals(fso.getFullPath()));
    // Reset the screen & then check that the favourite is included in the
    // menu
    try {
        setUp();
    } catch (Exception ex) {
        fail();
    }
    menu = (JPopupMenu) theFrame.mnuFileFavourites.getSubElements()[0];
    assertTrue(menu.getSubElements().length == 2);
    item = (JMenuItem) menu.getSubElements()[0];
    assertTrue(item.getText().equals(fso.getFullPath()));
    // Delete the storage file & make sure that there are no menu items
    FileUtils.deleteFileOrDirectoryRecursive(FAVOURITES_PATH);
    try {
        setUp();
    } catch (Exception ex) {
        fail();
    }
    menu = (JPopupMenu) theFrame.mnuFileFavourites.getSubElements()[0];
    assertTrue(menu.getSubElements().length == 1);
    item = (JMenuItem) menu.getSubElements()[0];
    assertTrue(item.getText().equals(noFavouritesText));

    // Check clearing
    depositPresenter.storeAsFavourite(node);
    assertTrue(menu.getSubElements().length == 2);
    item = (JMenuItem) menu.getSubElements()[0];
    assertTrue(item.getText().equals(fso.getFullPath()));
    depositPresenter.clearFavourites();
    assertTrue(theFrame.mnuFileFavourites.getSubElements().length == 1);
    item = (JMenuItem) menu.getSubElements()[0];
    assertTrue(item.getText().equals(noFavouritesText));

    // Check loading a directory
    fileSystemModel = (DepositTreeModel) theFrame.treeFileSystem.getModel();
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    coll = FSOCollection.create();
    coll.add((FileSystemObject) rootNode.getUserObject());
    currentPath = rootPath;
    depositPresenter.loadPath(currentPath);
    DefaultMutableTreeNode newNode = (DefaultMutableTreeNode) theFrame.treeFileSystem
            .getLastSelectedPathComponent();
    FileSystemObject fsoNew = (FileSystemObject) newNode.getUserObject();
    assertTrue(fsoNew.getFullPath().equals(currentPath));
    currentPath = fso.getFullPath();
    depositPresenter.loadPath(currentPath);
    newNode = (DefaultMutableTreeNode) theFrame.treeFileSystem.getLastSelectedPathComponent();
    fsoNew = (FileSystemObject) newNode.getUserObject();
    assertTrue(fsoNew.getFullPath().equals(fso.getFullPath()));
    FileUtils.deleteFileOrDirectoryRecursive(FAVOURITES_PATH);
}