Ignore:
Timestamp:
Sep 19, 2010, 3:19:40 PM (14 years ago)
Author:
mlg
Message:

"Feature" :
Until now, it was not possible to create a "root" category. It is now possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/CategoriesTree.java

    r6958 r6962  
    189189        tree.setSelectionRow(selRow);
    190190        //end
    191         if (selRow != -1) {
    192             if (e.getButton() == 3) {
    193                 JPopupMenu popup = new JPopupMenu();
    194                 menuAjouter = new JMenuItem(Messages.getMessage("categories_add"));
    195                 menuAjouter.addActionListener(this);
    196                 popup.add(menuAjouter);
    197                 menuActualiser = new JMenuItem(Messages.getMessage("categories_update"));
    198                 menuActualiser.addActionListener(this);
    199                 popup.add(menuActualiser);
    200                 popup.show(tree, e.getX(), e.getY());
     191
     192        if (e.getButton() == 3) {
     193            JPopupMenu popup = new JPopupMenu();
     194            menuAjouter = new JMenuItem(Messages.getMessage("categories_add"));
     195            menuAjouter.addActionListener(this);
     196            popup.add(menuAjouter);
     197            menuActualiser = new JMenuItem(Messages.getMessage("categories_update"));
     198            menuActualiser.addActionListener(this);
     199            popup.add(menuActualiser);
     200            popup.show(tree, e.getX(), e.getY());
     201            if (selRow != -1) {
    201202                DefaultMutableTreeNode node = (DefaultMutableTreeNode) (selPath.getLastPathComponent());
    202203                this.selectedCategory = (Category) node.getUserObject();
     204            } else {
     205                this.selectedCategory = null;
    203206            }
    204207        }
     
    217220            String nomcategorie = JOptionPane.showInputDialog(null, Messages.getMessage("categories_enterName"),
    218221                    Messages.getMessage("categories_add"), JOptionPane.INFORMATION_MESSAGE);
     222            //if the name of the category is not empty
    219223            if (!(nomcategorie == null) && !nomcategorie.equals("")) {
    220                 if (CategoryService.getInstance().creer(nomcategorie, selectedCategory.getIdentifiant())) {
    221                     setUpUi();
     224                //if there is a parent category
     225                if (selectedCategory != null) {
     226                    //try to create a category
     227                    if (CategoryService.getInstance().creer(nomcategorie, selectedCategory.getIdentifiant())) {
     228                        setUpUi();
     229                    } else {
     230                        JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), Messages
     231                                .getMessage("error"), JOptionPane.ERROR_MESSAGE);
     232
     233                    }
    222234                } else {
    223                     JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), Messages
    224                             .getMessage("error"), JOptionPane.ERROR_MESSAGE);
    225 
     235                    if (CategoryService.getInstance().creer(nomcategorie)) {
     236                        setUpUi();
     237                    } else {
     238                        JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), Messages
     239                                .getMessage("error"), JOptionPane.ERROR_MESSAGE);
     240
     241                    }
    226242                }
    227243            }
Note: See TracChangeset for help on using the changeset viewer.