package com.dbxml.db.admin.nodes;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: RootNode.java,v 1.4 2004/07/01 02:05:44 bradford Exp $
 */

import com.dbxml.db.admin.Admin;
import com.dbxml.db.admin.dialogs.ConnectDialog;
import com.dbxml.db.admin.dialogs.FilesystemDialog;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 * RootNode
 */

public final class RootNode extends AdminNode implements HasMenu {
   private static final Icon RootIcon = new ImageIcon(RootNode.class.getResource("servers_mini.gif"));

   public static final int ACTION_CONNECT = 0;
   public static final int ACTION_ADDFS = 1;

   private static final com.dbxml.db.admin.nodes.MenuItem[] Menu = new com.dbxml.db.admin.nodes.MenuItem[]{
      new com.dbxml.db.admin.nodes.MenuItem(ACTION_CONNECT, "Connect to Database"),
      new com.dbxml.db.admin.nodes.MenuItem(ACTION_ADDFS, "Attach Filesystem")
   };

   public RootNode() {
      super(null);
   }

   public String getLabel() {
      return "dbXML Data Sources";
   }

   public Icon getIcon() {
      return RootIcon;
   }

   public String getMenuTitle() {
      return "Sources";
   }

   public com.dbxml.db.admin.nodes.MenuItem[] getMenu() {
      return Menu;
   }

   public boolean isParentMenuInherited() {
      return false;
   }

   public int menuAction(int action) {
      Admin admin = Admin.getInstance();
      switch ( action ) {
         case ACTION_CONNECT:
            ConnectDialog connect = new ConnectDialog(admin);
            connect.show();
            break;

         case ACTION_ADDFS:
            FilesystemDialog attach = new FilesystemDialog(admin);
            attach.show();
            break;
      }
      return REFRESH_NONE;
   }
}
