package com.dbxml.db.admin.components;

/*
 * 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: GridEditor.java,v 1.2 2004/02/12 00:17:54 bradford Exp $
 */

import com.dbxml.db.admin.Admin;
import com.dbxml.db.admin.DocWrapper;
import com.dbxml.db.admin.TabbedNodeEditor;
import com.dbxml.db.admin.xmleditor.XMLEditor;
import java.awt.Color;
import java.awt.Cursor;

/**
 * GridEditor
 */

public class GridEditor extends XMLEditor implements TabbedNodeEditor {
   private DocWrapper doc;
   private boolean reset;

   public GridEditor() {
      try {
         jbInit();
      }
      catch ( Exception e ) {
         Admin.getInstance().addMessage(e.toString());
      }
   }

   private void jbInit() throws Exception {
      this.setAttribLabelSize(100);
      this.setShowAttribs(true);
      this.setIndentSize(35);
      this.setExpanded(true);
      //this.setCollapseText(false);
      this.setCommentColor(new Color(224, 224, 224));
      this.setFont(new java.awt.Font("Dialog", 0, 12));
      this.setTextColor(Color.yellow);
      this.setAttribColor(new Color(255, 255, 219));
      this.setElementColor(Color.white);
      this.setOpaque(true);
      this.setDoubleBuffered(false);
      this.getViewport().setBackground(Color.white);
      this.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_ALWAYS);
      this.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
   }

   public void reset() {
      reset = true;
   }

   public void setDocWrapper(DocWrapper doc) {
      reset = this.doc != doc;
      this.doc = doc;
   }

   public boolean isCutEnabled() {
      return false;
   }

   public void cut() {
      /** @todo This */
   }

   public boolean isCopyEnabled() {
      return false;
   }

   public void copy() {
      /** @todo This */
   }

   public boolean isPasteEnabled() {
      return false;
   }

   public void paste() {
      /** @todo This */
   }

   public boolean isUndoEnabled() {
      return false;
   }

   public void undo() {
      /** @todo This */
   }

   public void find() {
      /** @todo This */
   }

   public void findNext() {
      /** @todo This */
   }

   public boolean isBeautifyEnabled() {
      return false;
   }

   public void beautify() {
      /** @todo This */
   }

   public DocWrapper getDocWrapper() {
      return doc;
   }

   public void activate(boolean readOnly) {
      if ( readOnly != isReadOnly() || reset ) {
         Admin admin = Admin.getInstance();
         admin.setCursor(Cursor.WAIT_CURSOR);
         setReadOnly(readOnly);
         super.setNode(doc.getNode());
         setModified(false);
         admin.setCursor(Cursor.DEFAULT_CURSOR);
      }
   }

   public boolean deactivate() {
      if ( isModified() )
         doc.setNode(super.getNode());
      return true;
   }
}
