From bf0288205a7818cb6cdbda27d4ea0b029d70dbb2 Mon Sep 17 00:00:00 2001 From: dsandersoremutah Date: Fri, 8 Sep 2006 15:37:14 +0000 Subject: [PATCH] Renaming XEdit git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@828 0109f412-320b-0410-ab79-c3e0c5ffbbe6 --- xflaim/java/util/xxedit/run.bat | 7 + xflaim/java/util/xxedit/xedit/Attribute.java | 49 + .../util/xxedit/xedit/AttributeSelector.java | 190 + xflaim/java/util/xxedit/xedit/Collection.java | 49 + .../util/xxedit/xedit/CollectionSelector.java | 209 + xflaim/java/util/xxedit/xedit/Document.java | 81 + .../util/xxedit/xedit/DocumentSelector.java | 181 + .../util/xxedit/xedit/EditValueDialog.java | 143 + .../java/util/xxedit/xedit/FileImporter.java | 206 + xflaim/java/util/xxedit/xedit/NodeDialog.java | 819 ++++ xflaim/java/util/xxedit/xedit/NodePanel.java | 642 +++ xflaim/java/util/xxedit/xedit/NodeTag.java | 56 + xflaim/java/util/xxedit/xedit/NodeType.java | 50 + xflaim/java/util/xxedit/xedit/NodeValue.java | 54 + .../xxedit/xedit/OpenDocumentSelector.java | 156 + .../java/util/xxedit/xedit/ProgressBox.java | 258 ++ xflaim/java/util/xxedit/xedit/Status.java | 159 + xflaim/java/util/xxedit/xedit/UITools.java | 51 + xflaim/java/util/xxedit/xedit/XEdit.java | 3435 +++++++++++++++++ .../java/util/xxedit/xedit/XFileFilter.java | 76 + 20 files changed, 6871 insertions(+) create mode 100644 xflaim/java/util/xxedit/run.bat create mode 100644 xflaim/java/util/xxedit/xedit/Attribute.java create mode 100644 xflaim/java/util/xxedit/xedit/AttributeSelector.java create mode 100644 xflaim/java/util/xxedit/xedit/Collection.java create mode 100644 xflaim/java/util/xxedit/xedit/CollectionSelector.java create mode 100644 xflaim/java/util/xxedit/xedit/Document.java create mode 100644 xflaim/java/util/xxedit/xedit/DocumentSelector.java create mode 100644 xflaim/java/util/xxedit/xedit/EditValueDialog.java create mode 100644 xflaim/java/util/xxedit/xedit/FileImporter.java create mode 100644 xflaim/java/util/xxedit/xedit/NodeDialog.java create mode 100644 xflaim/java/util/xxedit/xedit/NodePanel.java create mode 100644 xflaim/java/util/xxedit/xedit/NodeTag.java create mode 100644 xflaim/java/util/xxedit/xedit/NodeType.java create mode 100644 xflaim/java/util/xxedit/xedit/NodeValue.java create mode 100644 xflaim/java/util/xxedit/xedit/OpenDocumentSelector.java create mode 100644 xflaim/java/util/xxedit/xedit/ProgressBox.java create mode 100644 xflaim/java/util/xxedit/xedit/Status.java create mode 100644 xflaim/java/util/xxedit/xedit/UITools.java create mode 100644 xflaim/java/util/xxedit/xedit/XEdit.java create mode 100644 xflaim/java/util/xxedit/xedit/XFileFilter.java diff --git a/xflaim/java/util/xxedit/run.bat b/xflaim/java/util/xxedit/run.bat new file mode 100644 index 0000000..f38438a --- /dev/null +++ b/xflaim/java/util/xxedit/run.bat @@ -0,0 +1,7 @@ +del xedit\*.class +copy c:\work\openflaim\trunk\xflaim\build\win-x86-32\debug\java\xflaimjni.jar +copy c:\work\openflaim\trunk\xflaim\build\win-x86-32\debug\lib\shared\xflaim.dll +"c:\Program Files\Java\jdk1.5.0_06\bin\javac.exe" -g -classpath xflaimjni.jar;. xedit\*.java +"c:\Program Files\Java\jdk1.5.0_06\bin\java.exe" -classpath xflaimjni.jar;. xedit.XEdit + +:done diff --git a/xflaim/java/util/xxedit/xedit/Attribute.java b/xflaim/java/util/xxedit/xedit/Attribute.java new file mode 100644 index 0000000..f96681c --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/Attribute.java @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// Desc: Attributes +// +// Tabs: 3 +// +// Copyright (c) 2004-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: Attribute.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; +import xflaim.*; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class Attribute +{ + Attribute(String sDesc, long lNodeId) + { + m_sDesc = sDesc; + m_lNodeId = lNodeId; + } + + public String toString() + { + return m_sDesc; + } + + String m_sDesc; + long m_lNodeId; + +} diff --git a/xflaim/java/util/xxedit/xedit/AttributeSelector.java b/xflaim/java/util/xxedit/xedit/AttributeSelector.java new file mode 100644 index 0000000..72c0a39 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/AttributeSelector.java @@ -0,0 +1,190 @@ +//------------------------------------------------------------------------------ +// Desc: Attribute Selector +// +// Tabs: 3 +// +// Copyright (c) 2004-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: AttributeSelector.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; + +import xflaim.*; +import java.awt.*; +import java.awt.event.*; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class AttributeSelector extends JDialog implements ActionListener +{ + + private JComboBox m_cbAttribute; + private JButton m_btnOkay; + private JButton m_btnCancel; + private Attribute m_Attribute; + + /** + * @param owner + * @throws java.awt.HeadlessException + */ + public AttributeSelector( + Frame owner, + DOMNode jRefNode, + Attribute attribute) + { + super(owner, "Select Attribute", true); + Container CP; // The content pane for this dialog + GridBagLayout gridbag; + GridBagConstraints constraints = new GridBagConstraints(); + Vector vAttributes; + // Coordinates for location this window in the center of its parent. + Point p; + Dimension d; + int x; + int y; + + setDefaultCloseOperation( DISPOSE_ON_CLOSE); + CP = getContentPane(); + gridbag = new GridBagLayout(); + CP.setLayout( gridbag); + + m_Attribute = attribute; + + // Add the combobox. + vAttributes = new Vector(); + + // Now get all of the attributes from the node + try + { + boolean bFirst = true; + DOMNode jAttr = null; + + for (;;) + { + if (bFirst) + { + bFirst = false; + jAttr = jRefNode.getFirstAttribute(jAttr); + } + else + { + try + { + jAttr = jAttr.getNextSibling(jAttr); + } + catch (XFlaimException ee) + { + if (ee.getRCode() == RCODE.NE_XFLM_DOM_NODE_NOT_FOUND) + { + break; + } + else + { + // Leave it for now. + System.out.println(ee.getMessage()); + } + } + } + + String sDesc = "<" + jAttr.getLocalName() + ">"; + long lNodeId = jAttr.getNodeId(); + vAttributes.add(new Attribute(sDesc, lNodeId)); + + } + } + catch (XFlaimException e) + { + // Leave it for now. + System.out.println(e.getMessage()); + } + + + m_cbAttribute = new JComboBox( vAttributes); + m_cbAttribute.setSelectedIndex(0); + m_cbAttribute.addActionListener(this); + + UITools.buildConstraints(constraints, 0, 0, 2, 1, 0, 0); + + gridbag.setConstraints( m_cbAttribute, constraints); + + CP.add( m_cbAttribute); + + // Add the Okay button + m_btnOkay = new JButton("Okay"); + m_btnOkay.setDefaultCapable(true); + m_btnOkay.addActionListener(this); + + UITools.buildConstraints(constraints, 0, 1, 1, 1, 60, 100); + + gridbag.setConstraints( m_btnOkay, constraints); + + CP.add( m_btnOkay); + + // Add the Cancel button + m_btnCancel = new JButton("Cancel"); + m_btnCancel.addActionListener(this); + + UITools.buildConstraints(constraints, 1, 1, 1, 1, 40, 0); + + gridbag.setConstraints( m_btnCancel, constraints); + + CP.add( m_btnCancel); + + setSize(200, 100); + + p = owner.getLocationOnScreen(); + d = owner.getSize(); + x = (d.width - 200) / 2; + y = (d.height - 100) / 2; + setLocation(Math.max(0, p.x + x), Math.max(0, p.y + y)); + setVisible( true); + } + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Object obj = (Object)e.getSource(); + if (obj == m_cbAttribute || obj == m_btnOkay) + { + Attribute attr = (Attribute)m_cbAttribute.getSelectedItem(); + m_Attribute.m_lNodeId = attr.m_lNodeId; + m_Attribute.m_sDesc = new String(attr.m_sDesc); + if (obj == m_btnOkay) + { + setVisible(false); + dispose(); + } + } + else + { + m_Attribute.m_lNodeId = -1; // Make sure the caller knows we cancelled + setVisible(false); + dispose(); + } + } +} diff --git a/xflaim/java/util/xxedit/xedit/Collection.java b/xflaim/java/util/xxedit/xedit/Collection.java new file mode 100644 index 0000000..75d971d --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/Collection.java @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// Desc: Collections +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: Collection.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; + +/** + * The Collection class defines a simple structure that can be used when selection + * a collection. When instantiated, it is the object that is inserted into + * the vector that is added to the combo Box, ultimatly displaying a drop-down list + * of collections to choose from. + */ +public class Collection +{ + Collection(String sName, int iNumber) + { + m_sName = sName; + m_iNumber = iNumber; + } + + public String toString() + { + return m_sName; + } + + public String m_sName; + public int m_iNumber; +} diff --git a/xflaim/java/util/xxedit/xedit/CollectionSelector.java b/xflaim/java/util/xxedit/xedit/CollectionSelector.java new file mode 100644 index 0000000..36a172a --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/CollectionSelector.java @@ -0,0 +1,209 @@ +//------------------------------------------------------------------------------ +// Desc: Collection Selector +// +// Tabs: 3 +// +// Copyright (c) 2003-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: CollectionSelector.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; + +import xedit.*; +import xflaim.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +/** + * The CollectionSelector is used to popup a dialog window that gives the + * use a choice of collections to choose. The Collection parameter passed + * into the constructor will be initialized to hold the collection the user + * has chosen when this object exits. All of the work is done inthe constructor. + * To use this class/object, simply create a new instance of it and check the + * Collection object that was passed into the constructor. + */ +public class CollectionSelector extends JDialog implements ActionListener +{ + private JComboBox m_cbCollection; + private JButton m_btnOkay; + private JButton m_btnCancel; + private Collection m_Collection; + + public CollectionSelector( + Frame owner, + DbSystem dbSystem, + Db jDb, + Collection collection) + { + super(owner, "Select Collection", true); + + Container CP; // The content pane for this dialog + GridBagLayout gridbag; + GridBagConstraints constraints = new GridBagConstraints(); + Vector vCollections; + DataVector SearchKey = null; + DataVector FoundKey = null; + // Coordinates for location this window in the center of its parent. + Point p; + Dimension d; + int x; + int y; + + setDefaultCloseOperation( DISPOSE_ON_CLOSE); + CP = getContentPane(); + gridbag = new GridBagLayout(); + CP.setLayout( gridbag); + + m_Collection = collection; + + // Add the combobox. + vCollections = new Vector(); + vCollections.add(new Collection("Default Data ", xflaim.Collections.DATA)); + vCollections.add(new Collection("Dictionary ", xflaim.Collections.DICTIONARY)); + + // Now get all of the user defined collections from the database + try + { + boolean bFirst = true; + int iFlags; + + SearchKey = dbSystem.createJDataVector(); + FoundKey = dbSystem.createJDataVector(); + + // Setup the search key. + jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, + SearchKey, + KeyRetrieveFlags.FO_FIRST, + SearchKey); + + SearchKey.setLong(0, ReserveID.ELM_COLLECTION_TAG); + SearchKey.setString(1, "a"); + + for (;;) + { + if (bFirst) + { + bFirst = false; + iFlags = KeyRetrieveFlags.FO_INCL; + jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, SearchKey, iFlags, FoundKey); + + } + else + { + iFlags = KeyRetrieveFlags.FO_EXCL; + jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, FoundKey, iFlags, FoundKey); + + } + + if (FoundKey == null) + { + break; + } + + if (FoundKey.getLong(0) != ReserveID.ELM_COLLECTION_TAG) + { + break; + } + String sName = FoundKey.getString(1); + int iNumber = (int)FoundKey.getLong(3); + vCollections.add(new Collection(sName, iNumber)); + + } + } + catch (XFlaimException e) + { + // Leave it for now. + System.out.println(e.getMessage()); + } + + + + + + + m_cbCollection = new JComboBox( vCollections); + m_cbCollection.setSelectedIndex(0); + m_cbCollection.addActionListener(this); + + UITools.buildConstraints(constraints, 0, 0, 2, 1, 0, 0); + + gridbag.setConstraints( m_cbCollection, constraints); + + CP.add( m_cbCollection); + + // Add the Okay button + m_btnOkay = new JButton("Okay"); + m_btnOkay.setDefaultCapable(true); + m_btnOkay.addActionListener(this); + + UITools.buildConstraints(constraints, 0, 1, 1, 1, 60, 100); + + gridbag.setConstraints( m_btnOkay, constraints); + + CP.add( m_btnOkay); + + // Add the Cancel button + m_btnCancel = new JButton("Cancel"); + m_btnCancel.addActionListener(this); + + UITools.buildConstraints(constraints, 1, 1, 1, 1, 40, 0); + + gridbag.setConstraints( m_btnCancel, constraints); + + CP.add( m_btnCancel); + + setSize(200, 100); + + p = owner.getLocationOnScreen(); + d = owner.getSize(); + x = (d.width - 200) / 2; + y = (d.height - 100) / 2; + setLocation(Math.max(0, p.x + x), Math.max(0, p.y + y)); + setVisible( true); + } + + + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Object obj = (Object)e.getSource(); + if (obj == m_cbCollection || obj == m_btnOkay) + { + Collection coll = (Collection)m_cbCollection.getSelectedItem(); + m_Collection.m_iNumber = coll.m_iNumber; + m_Collection.m_sName = new String(coll.m_sName); + if (obj == m_btnOkay) + { + setVisible(false); + dispose(); + } + } + else + { + setVisible(false); + dispose(); + } + } + +} diff --git a/xflaim/java/util/xxedit/xedit/Document.java b/xflaim/java/util/xxedit/xedit/Document.java new file mode 100644 index 0000000..550a697 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/Document.java @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// Desc: Documents +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: Document.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; + +/** + * The Document class represents a simple structure to hold essential details + * about each document that is opened in XEdit. This class overrides the + * equality testing method used by Vectors to test if one object is + * equivalent to another. Instances of this class are stored in a vector + * during program execution. The Vector.indexOf method is used to + * locate the index of the Document in the vector. + */ +public class Document +{ + public long m_lDocId; + public int m_iCollection; + public String m_sName; + + /** + * + */ + public Document( + String sName, + long lDocId, + int iCollection) + { + m_sName = sName; + m_lDocId = lDocId; + m_iCollection = iCollection; + } + + public String toString() + { + return m_sName; + } + + /** + * Overrides the Object.equals(Object) method to compare + * two Document objects for equivalence. They need not be the + * same object, they just have to be internally identical. + */ + public boolean equals(Object doc) + { + Document d = (Document)doc; + + if (m_lDocId == d.m_lDocId) + { + if (m_iCollection == d.m_iCollection) + { + if (m_sName.equals(d.m_sName)) + { + return true; + } + } + } + return false; + } +} diff --git a/xflaim/java/util/xxedit/xedit/DocumentSelector.java b/xflaim/java/util/xxedit/xedit/DocumentSelector.java new file mode 100644 index 0000000..77f4e22 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/DocumentSelector.java @@ -0,0 +1,181 @@ +//------------------------------------------------------------------------------ +// Desc: Document Selector +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: DocumentSelector.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; + +import xedit.*; +import xflaim.*; +import java.awt.*; +import java.awt.event.*; +import java.util.Vector; +import javax.swing.*; + +/** + * The DocumentSelector class provides a means of presenting a list of + * documents in the database to the user. It will popup a window with a list + * of documents, showing their root element. + */ +public class DocumentSelector extends JDialog implements ActionListener +{ + + private JList m_lstList; + private JButton m_btnOkay; + private JButton m_btnCancel; + private Document m_Document; + + public DocumentSelector( + Frame owner, + Db jDb, + int iCollection, + Document document) + { + super(owner, "Select Document", true); + + Container CP; // The content pane for this dialog + GridBagLayout gridbag; + GridBagConstraints constraints = new GridBagConstraints(); + Vector vDocuments; + int iLength = 0; + + // Coordinates for locating this window in the center of its parent. + Point p; + Dimension d; + int x; + int y; + boolean bFirst = true; + DOMNode jDoc = null; + + setDefaultCloseOperation( DISPOSE_ON_CLOSE); + CP = getContentPane(); + gridbag = new GridBagLayout(); + CP.setLayout( gridbag); + + m_Document = document; + + // Add the combobox. + vDocuments = new Vector(); + // Get the list of documents + for (;;) + { + try + { + if (bFirst) + { + jDoc = jDb.getFirstDocument(iCollection, null); + bFirst = false; + } + else + { + jDoc = jDoc.getNextDocument(jDoc); + } + String sName = new String("<" + jDoc.getLocalName() + ">"); + long lDocId = jDoc.getNodeId(); + vDocuments.add(new Document(sName, lDocId, iCollection)); + if (sName.length() > iLength) + { + iLength = sName.length(); + } + } + catch (XFlaimException e) + { + if (e.getRCode() == RCODE.NE_XFLM_DOM_NODE_NOT_FOUND || + e.getRCode() == RCODE.NE_XFLM_NOT_FOUND) + { + break; + } + } + } + + m_lstList = new JList( vDocuments); + m_lstList.setSelectedIndex(0); + //m_lstList.addActionListener(this); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.getViewport().setView(m_lstList); + + UITools.buildConstraints(constraints, 0, 0, 2, 4, 100, 100); + constraints.anchor = GridBagConstraints.NORTHWEST; + constraints.fill = GridBagConstraints.BOTH; + + gridbag.setConstraints( scrollPane, constraints); + + CP.add( scrollPane); + + // Add the Okay button + m_btnOkay = new JButton("Okay"); + m_btnOkay.setDefaultCapable(true); + m_btnOkay.addActionListener(this); + + UITools.buildConstraints(constraints, 0, 5, 1, 1, 90, 100); + constraints.anchor = GridBagConstraints.EAST; + constraints.fill = GridBagConstraints.NONE; + + gridbag.setConstraints( m_btnOkay, constraints); + + CP.add( m_btnOkay); + + // Add the Cancel button + m_btnCancel = new JButton("Cancel"); + m_btnCancel.addActionListener(this); + + UITools.buildConstraints(constraints, 1, 5, 1, 1, 10, 0); + constraints.anchor = GridBagConstraints.WEST; + + gridbag.setConstraints( m_btnCancel, constraints); + + CP.add( m_btnCancel); + + setSize(Math.max( iLength, 200), 200); + + p = owner.getLocationOnScreen(); + d = owner.getSize(); + x = (d.width - Math.max( iLength, 200)) / 2; + y = (d.height - 200) / 2; + setLocation(Math.max(0, p.x + x), Math.max(0, p.y + y)); + setVisible( true); + } + + + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Object obj = (Object)e.getSource(); + if (obj == m_btnOkay) + { + Document doc = (Document)m_lstList.getSelectedValue(); + m_Document.m_lDocId = doc.m_lDocId; + m_Document.m_sName = new String(doc.m_sName); + setVisible(false); + dispose(); + } + else + { + setVisible(false); + dispose(); + } + } +} diff --git a/xflaim/java/util/xxedit/xedit/EditValueDialog.java b/xflaim/java/util/xxedit/xedit/EditValueDialog.java new file mode 100644 index 0000000..54923b1 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/EditValueDialog.java @@ -0,0 +1,143 @@ +//------------------------------------------------------------------------------ +// Desc: Edit Value Dialog +// +// Tabs: 3 +// +// Copyright (c) 2004-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: EditValueDialog.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; + +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class EditValueDialog extends JDialog implements ActionListener +{ + private JButton m_btnOkay; + private JButton m_btnCancel; + private JTextField m_textField; + private NodeValue m_NodeValue; + + /** + * A class for editing the value of a DOM Node. All values aer treated as strings. + * @param owner + * @param sValue + */ + public EditValueDialog( + String sTitle, + Frame owner, + NodeValue NodeValue) + { + super(owner, sTitle, true); + + m_NodeValue = NodeValue; + + Container CP; // The content pane for this dialog + GridBagLayout gridbag; + GridBagConstraints constraints = new GridBagConstraints(); + // Coordinates for location this window in the center of its parent. + Point p; + Dimension d; + int x; + int y; + + setDefaultCloseOperation( DISPOSE_ON_CLOSE); + CP = getContentPane(); + gridbag = new GridBagLayout(); + CP.setLayout( gridbag); + + m_textField = new JTextField(NodeValue.getValue()); + m_textField.setEditable(true); + JScrollPane sp = new JScrollPane(m_textField); + + UITools.buildConstraints(constraints, 0, 0, 3, 1, 100, 100); + constraints.anchor = GridBagConstraints.NORTHWEST; + constraints.fill = GridBagConstraints.BOTH; + gridbag.setConstraints( sp, constraints); + + CP.add( sp); + + + // Add the Okay button + m_btnOkay = new JButton("Okay"); + m_btnOkay.setDefaultCapable(true); + m_btnOkay.addActionListener(this); + + UITools.buildConstraints(constraints, 1, 1, 1, 1, 60, 100); + constraints.anchor = GridBagConstraints.CENTER; + constraints.fill = GridBagConstraints.NONE; + gridbag.setConstraints( m_btnOkay, constraints); + + CP.add( m_btnOkay); + + // Add the Cancel button + m_btnCancel = new JButton("Cancel"); + m_btnCancel.addActionListener(this); + + UITools.buildConstraints(constraints, 2, 1, 1, 1, 40, 0); + + gridbag.setConstraints( m_btnCancel, constraints); + + CP.add( m_btnCancel); + + setSize(200, 100); + + p = owner.getLocationOnScreen(); + d = owner.getSize(); + x = (d.width - 200) / 2; + y = (d.height - 100) / 2; + setLocation(Math.max(0, p.x + x), Math.max(0, p.y + y)); + setVisible( true); + } + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Object obj = (Object)e.getSource(); + if (obj == m_btnOkay) + { + m_NodeValue.setValue(m_textField.getText()); + setVisible(false); + dispose(); + } + else + { + setVisible(false); + dispose(); + } + } + +} diff --git a/xflaim/java/util/xxedit/xedit/FileImporter.java b/xflaim/java/util/xxedit/xedit/FileImporter.java new file mode 100644 index 0000000..7d9bada --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/FileImporter.java @@ -0,0 +1,206 @@ +//------------------------------------------------------------------------------ +// Desc: File Importer +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: FileImporter.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; + +import xedit.*; +import xflaim.*; +import java.awt.*; +import java.io.*; +import javax.swing.*; + +/** + * The FileImporter runs in a separate thre so that it does not block the main + * XEdit thread while it imports documents into the database. + */ +public class FileImporter extends Thread +{ + + /** + * + */ + public FileImporter( + Frame owner, + DbSystem dbSystem, + String sDbName, + int iCollection, + String sFilename, + String sDirectory, + String [] sList) throws XFlaimException + { + super(); + m_iCollection = iCollection; + m_sFilename = sFilename; + m_sDirectory = sDirectory; + m_sList = sList; + m_dbSystem = dbSystem; + m_owner = owner; + + // Open our own copy of the database. + m_jDb = dbSystem.dbOpen( sDbName, null, null, null, true); + } + + // Need to close the database we when we are done. + public void finalize() + { + m_jDb.close(); + } + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + public void run() + { + countFiles( m_sFilename, + m_sDirectory, + m_sList); + + m_box = new ProgressBox(m_owner, 500, 160, "Preparing to import files", "Filename:", 0, m_iFileCount); + + importFile( m_iCollection, + m_sFilename, + m_sDirectory, + m_sList); + + } + + /*========================================================================= + * Desc: Method to iterate through a possible list of files and import every file in the directory. + *========================================================================*/ + private void importFile( + int iCollection, + String sFilename, + String sDirectory, + String [] sList) + { + boolean bTransBegun = false; + IStream jIStream = null; + + if (m_box.Cancelled()) + { + m_box.terminate(); + return; + } + + // A null sList indicates that we are looking at a file, so we can import it directly. + if (sList == null) + { + m_iCurrentFile++; + m_box.setLabel1("Importing file " + m_iCurrentFile + " of " + m_iFileCount); + m_box.setLabel2("Filename: " + sFilename); + + try + { + jIStream = m_dbSystem.openFileIStream(sFilename); + m_jDb.transBegin(TransactionType.UPDATE_TRANS, 0, 0); + bTransBegun = true; + m_jDb.Import(jIStream, iCollection); + m_jDb.transCommit(); + bTransBegun = false; + } + catch (XFlaimException e) + { + // Abort the transaction, then throw the exception up further. + if (bTransBegun) + { + try + { + m_jDb.transAbort(); + } + catch (XFlaimException ex) + { + JOptionPane.showMessageDialog(null, "Exception occurred in import thread: " + ex.getMessage()); + } + } + JOptionPane.showMessageDialog(null, "Exception occurred in import thread: " + e.getMessage()); + } + m_box.updateProgress(m_iCurrentFile); + } + // Otherwise we need to find the first file. If we come across a directory, we need to search it too. + else + { + for (int iLoop = 0; iLoop < sList.length; iLoop++) + { + File f = new File(sFilename, sList[iLoop]); + if (f.isDirectory()) + { + importFile( iCollection, + new String(f.getPath()), + new String(f.getAbsolutePath()), + f.list()); + } + else + { + importFile( iCollection, + new String(f.getPath()), + sDirectory, + null); + } + } + } + } + + private void countFiles( + String sFilename, + String sDirectory, + String [] sList) + { + if (sList == null) + { + m_iFileCount++; + } + else + { + for (int iLoop = 0; iLoop < sList.length; iLoop++) + { + File f = new File(sFilename, sList[iLoop]); + if (f.isDirectory()) + { + countFiles( new String(f.getPath()), + new String(f.getAbsolutePath()), + f.list()); + } + else + { + countFiles( new String(f.getPath()), + sDirectory, + null); + } + } + + } + } + + /*----------------------------------------- Private members -----------------------------------*/ + private int m_iCollection; + private String m_sFilename; + private String m_sDirectory; + private String [] m_sList; + private DbSystem m_dbSystem; + private Db m_jDb; + private ProgressBox m_box; + private int m_iFileCount = 0; + private int m_iCurrentFile = 0; + private Frame m_owner; +} diff --git a/xflaim/java/util/xxedit/xedit/NodeDialog.java b/xflaim/java/util/xxedit/xedit/NodeDialog.java new file mode 100644 index 0000000..afc35f6 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/NodeDialog.java @@ -0,0 +1,819 @@ +//------------------------------------------------------------------------------ +// Desc: Node Dialog +// +// Tabs: 3 +// +// Copyright (c) 2003-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: NodeDialog.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; + +import xflaim.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.*; +import java.util.Vector; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class NodeDialog extends JDialog implements Runnable, ActionListener, ListSelectionListener, KeyListener +{ + private XEdit m_owner; + private DbSystem m_dbSystem; + private Db m_jDb; + private GridBagConstraints m_gbc; + private GridBagLayout m_gbl; + private long m_lNodeId; + private JList m_NodeTypeList; + private JList m_NodeTagList; + private JRadioButton m_btnNewDocument; + private JRadioButton m_btnNewSibling; + private JRadioButton m_btnNewChild; + private JRadioButton m_btnAnnotation; + private final String m_sNewDocument = "New Document"; + private final String m_sNewSibling = "New Sibling"; + private final String m_sNewChild = "New Child"; + private final String m_sAnnotation = "Annotation"; + private JButton m_btnCancel; + private JButton m_btnAdd; + private JButton m_btnDone; + private JTextField m_textField; + private JLabel m_nodeTagLabel; + private JScrollPane m_scrollPane; + private int m_iCollection; + private boolean m_bTypeSelected = false; + private boolean m_bTagRequired = false; + private boolean m_bTagSelected = false; + private boolean m_bValueRequired = false; + private boolean m_bValueEntered = false; + + + /** + * @param owner + * @throws java.awt.HeadlessException + */ + public NodeDialog( + XEdit owner, + DbSystem dbSystem, + String sDbFileName, + long lNodeId, + int iCollection) throws XFlaimException + { + super(owner, "XFLaim Node Dialog", true); + + m_owner = owner; + m_dbSystem = dbSystem; + m_lNodeId = lNodeId; + m_iCollection = iCollection; + + // Open the database so we can have independant access + m_jDb = m_dbSystem.dbOpen( sDbFileName, null, null, null, true); + + m_gbl = new GridBagLayout(); + m_gbc = new GridBagConstraints(); + m_gbc.insets = new Insets(3, 6, 3, 6); + + setDefaultCloseOperation( DISPOSE_ON_CLOSE); + Container CP = getContentPane(); + CP.setLayout( m_gbl); + + // Select Node Type label + JLabel lbl1 = new JLabel("Select Node Type"); + UITools.buildConstraints(m_gbc, 0, 0, 2, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.NORTHWEST; + m_gbl.addLayoutComponent(lbl1, m_gbc); + CP.add(lbl1); + + // Select Node Tag + m_nodeTagLabel = new JLabel("Select Node Tag"); + m_nodeTagLabel.setVisible(false); + UITools.buildConstraints(m_gbc, 3, 0, 2, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.NORTHWEST; + m_gbl.addLayoutComponent(m_nodeTagLabel, m_gbc); + CP.add(m_nodeTagLabel); + + // Select Node Type list box + Vector vNodeList = new Vector(); + buildNodeTypeList(vNodeList); + m_NodeTypeList = new JList(vNodeList); + m_NodeTypeList.addListSelectionListener(this); + JScrollPane sp = new JScrollPane(m_NodeTypeList); + UITools.buildConstraints(m_gbc, 0, 1, 2, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbl.addLayoutComponent(sp, m_gbc); + CP.add(sp); + + // Select Node Tag list box + m_NodeTagList = new JList(); + m_NodeTagList.setEnabled(false); // Will be enabled later when a valid type is selected. + m_NodeTagList.setVisible(false); + m_NodeTagList.addListSelectionListener(this); + m_scrollPane = new JScrollPane(m_NodeTagList); + UITools.buildConstraints(m_gbc, 3, 1, 2, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbc.fill = GridBagConstraints.BOTH; + m_gbl.addLayoutComponent(m_scrollPane, m_gbc); + m_scrollPane.setVisible(false); + CP.add(m_scrollPane); + + // Radio Button - New Document + m_btnNewDocument = new JRadioButton(m_sNewDocument); + m_btnNewDocument.setActionCommand(m_sNewDocument); + m_btnNewDocument.setSelected(m_lNodeId > 0 ? false : true); + UITools.buildConstraints(m_gbc, 0, 2, 1, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbc.fill = GridBagConstraints.NONE; + m_gbl.addLayoutComponent(m_btnNewDocument, m_gbc); + CP.add(m_btnNewDocument); + + // Radio button - New Sibling + m_btnNewSibling = new JRadioButton(m_sNewSibling); + m_btnNewSibling.setActionCommand(m_sNewSibling); + m_btnNewSibling.setSelected(m_lNodeId > 0 ? true : false); + if (m_lNodeId == 0) + { + m_btnNewSibling.setEnabled(false); + } + UITools.buildConstraints(m_gbc, 0, 3, 1, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbl.addLayoutComponent(m_btnNewSibling, m_gbc); + CP.add(m_btnNewSibling); + + // Radio Button - New Child + m_btnNewChild = new JRadioButton(m_sNewChild); + m_btnNewChild.setActionCommand(m_sNewChild); + m_btnNewChild.setSelected(false); + if (m_lNodeId == 0) + { + m_btnNewChild.setEnabled(false); + } + UITools.buildConstraints(m_gbc, 0, 4, 1, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbl.addLayoutComponent(m_btnNewChild, m_gbc); + CP.add(m_btnNewChild); + + // Radio Button - Annotation + m_btnAnnotation = new JRadioButton(m_sAnnotation); + m_btnAnnotation.setActionCommand(m_sAnnotation); + m_btnAnnotation.setSelected(false); + if (m_lNodeId == 0) + { + m_btnAnnotation.setEnabled(false); + } + UITools.buildConstraints(m_gbc, 0, 5, 1, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbl.addLayoutComponent(m_btnAnnotation, m_gbc); + CP.add(m_btnAnnotation); + + // Group the Radio Buttons + ButtonGroup btnGroup = new ButtonGroup(); + btnGroup.add(m_btnNewDocument); + btnGroup.add(m_btnNewSibling); + btnGroup.add(m_btnNewChild); + btnGroup.add(m_btnAnnotation); + + // Enter new value + JLabel lbl3 = new JLabel("Enter new value"); + UITools.buildConstraints(m_gbc, 0, 6, 2, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbl.addLayoutComponent(lbl3, m_gbc); + CP.add(lbl3); + + // Text box to hold the new value + m_textField = new JTextField(); + m_textField.setEditable(true); + m_textField.addActionListener(this); + m_textField.setActionCommand("Value"); + m_textField.addKeyListener(this); + UITools.buildConstraints(m_gbc, 0, 7, 5, 1, 0, 0); + m_gbc.anchor = GridBagConstraints.WEST; + m_gbc.fill = GridBagConstraints.HORIZONTAL; + m_gbl.addLayoutComponent(m_textField, m_gbc); + CP.add(m_textField); + + + // Cancel button + m_btnCancel = new JButton("Cancel"); + m_btnCancel.setActionCommand("Cancel"); + m_btnCancel.addActionListener(this); + UITools.buildConstraints(m_gbc, 2, 8, 1, 1, 0, 0); + m_gbl.addLayoutComponent(m_btnCancel, m_gbc); + CP.add(m_btnCancel); + + // Add button + m_btnAdd = new JButton("Add"); + m_btnAdd.setActionCommand("Add"); + m_btnAdd.addActionListener(this); + m_btnAdd.setEnabled(false); + UITools.buildConstraints(m_gbc, 3, 8, 1, 1, 0, 0); + m_gbl.addLayoutComponent(m_btnAdd, m_gbc); + CP.add(m_btnAdd); + + // Done button + m_btnDone = new JButton("Done"); + m_btnDone.setActionCommand("Done"); + m_btnDone.addActionListener(this); + m_btnDone.setEnabled(false); + UITools.buildConstraints(m_gbc, 4, 8, 1, 1, 0, 0); + m_gbl.addLayoutComponent(m_btnDone, m_gbc); + CP.add(m_btnDone); + + this.pack(); + this.setResizable(false); + } + + /** + * @param m_NodeTypeList + */ + private void buildNodeTypeList(Vector vNodeList) + { + vNodeList.clear(); + vNodeList.add(new NodeType("Annotation", FlmDomNodeType.ANNOTATION_NODE)); + vNodeList.add(new NodeType("Attribute", FlmDomNodeType.ATTRIBUTE_NODE)); + vNodeList.add(new NodeType("CDATA Section", FlmDomNodeType.CDATA_SECTION_NODE)); + vNodeList.add(new NodeType("Comment", FlmDomNodeType.COMMENT_NODE)); + vNodeList.add(new NodeType("Data", FlmDomNodeType.DATA_NODE)); + vNodeList.add(new NodeType("Document", FlmDomNodeType.DOCUMENT_NODE)); + vNodeList.add(new NodeType("Element", FlmDomNodeType.ELEMENT_NODE)); + vNodeList.add(new NodeType("Processing Instruction", FlmDomNodeType.PROCESSING_INSTRUCTION_NODE)); + } + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + public void run() + { + this.setVisible(true); + } + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + String str = e.getActionCommand(); + + if (str.equals("Cancel")) + { + // Abort everything. + this.dispose(); + } + else if (str.equals("Add")) + { + // Update the database, but don't quit. + if (m_btnNewDocument.isSelected()) + { + try + { + NodeTag ntg = (NodeTag)m_NodeTagList.getSelectedValue(); + int iNumber = 0; + + if (ntg != null) + { + iNumber = ntg.m_iNumber; + } + + m_lNodeId = m_owner.addDocument( + m_iCollection, + iNumber, + m_textField.getText()); + if (m_lNodeId > 0) + { + m_btnNewSibling.setEnabled(true); + m_btnNewChild.setEnabled(true); + m_btnAnnotation.setEnabled(true); + m_btnDone.setEnabled(true); + } + } + catch (XFlaimException ee) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + ee.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + else if (m_btnAnnotation.isSelected()) + { + try + { + m_lNodeId = m_owner.addAnnotation( + m_iCollection, + m_textField.getText(), + m_lNodeId); + if (m_lNodeId > 0) + { + m_btnNewSibling.setEnabled(true); + m_btnNewChild.setEnabled(true); + m_btnAnnotation.setEnabled(true); + m_btnDone.setEnabled(true); + } + } + catch (XFlaimException ex) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + ex.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + else + { + boolean bIsSibling = false; + if (m_btnNewSibling.isSelected()) + { + bIsSibling = true; + } + + try + { + NodeType nt = (NodeType)m_NodeTypeList.getSelectedValue(); + NodeTag ntg = (NodeTag)m_NodeTagList.getSelectedValue(); + int iNumber = 0; + + if (ntg != null) + { + iNumber = ntg.m_iNumber; + } + + m_lNodeId = m_owner.addNode( + m_iCollection, + nt.m_iType, + iNumber, + m_textField.getText(), + bIsSibling, + m_lNodeId); + if (m_lNodeId > 0) + { + m_btnNewSibling.setEnabled(true); + m_btnNewChild.setEnabled(true); + m_btnAnnotation.setEnabled(true); + m_btnDone.setEnabled(true); + } + } + catch (XFlaimException ex) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + ex.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + else if (str.equals("Done")) + { + this.dispose(); + } + else if (str.equals("Value")) + { + m_bValueEntered = true; + enableButtons(); + } + } + + /** + * Finalize method to ensure we close the local copy of the database. + */ + public void finalize() + { + if (m_jDb != null) + { + m_jDb.close(); + } + } + + /* (non-Javadoc) + * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) + */ + public void valueChanged(ListSelectionEvent e) + { + JList list = (JList)e.getSource(); + + Object obj = list.getSelectedValue(); + + if (obj instanceof NodeType) + { + NodeType nt = (NodeType)obj; + + switch(nt.m_iType) + { + case FlmDomNodeType.ATTRIBUTE_NODE: + { + if (buildAttributeTagList()) + { + m_nodeTagLabel.setText("Select Attribute Tag"); + m_nodeTagLabel.setVisible(true); + m_bTypeSelected = true; + m_bTagRequired = true; + m_bTagSelected = false; + m_bValueRequired = true; + } + break; + } + case FlmDomNodeType.ELEMENT_NODE: + { + if (buildElementTagList()) + { + m_nodeTagLabel.setText("Select Element Tag"); + m_nodeTagLabel.setVisible(true); + m_bTagRequired = true; + m_bTagSelected = false; + m_bTypeSelected = true; + } + break; + } + case FlmDomNodeType.DOCUMENT_NODE: // Same as Element Node - Root node. + { + if (buildElementTagList()) + { + m_nodeTagLabel.setText("Select Root Tag"); + m_nodeTagLabel.setVisible(true); + m_bTagRequired = true; + m_bTagSelected = false; + m_bTypeSelected = true; + } + break; + } + case FlmDomNodeType.ANNOTATION_NODE: + { + m_nodeTagLabel.setVisible(false); + m_NodeTagList.setVisible(false); + m_bTypeSelected = true; + m_bTagRequired = false; + m_bTagSelected = false; + m_bValueRequired = true; + m_scrollPane.setVisible(false); + break; + } + case FlmDomNodeType.CDATA_SECTION_NODE: + { + m_nodeTagLabel.setVisible(false); + m_NodeTagList.setVisible(false); + m_bValueRequired = true; + m_bTypeSelected = true; + m_bTagRequired = false; + m_bTagSelected = false; + m_scrollPane.setVisible(false); + break; + } + case FlmDomNodeType.COMMENT_NODE: + { + m_nodeTagLabel.setVisible(false); + m_NodeTagList.setVisible(false); + m_bTypeSelected = true; + m_bTagRequired = false; + m_bTagSelected = false; + m_bValueRequired = true; + m_scrollPane.setVisible(false); + break; + } + case FlmDomNodeType.DATA_NODE: + { + m_nodeTagLabel.setVisible(false); + m_NodeTagList.setVisible(false); + m_bTypeSelected = true; + m_bTagRequired = false; + m_bTagSelected = false; + m_bValueRequired = true; + m_scrollPane.setVisible(false); + break; + } + case FlmDomNodeType.PROCESSING_INSTRUCTION_NODE: + { + m_nodeTagLabel.setVisible(false); + m_NodeTagList.setVisible(false); + m_bTypeSelected = true; + m_bTagRequired = false; + m_bTagSelected = false; + m_bValueRequired = true; + m_scrollPane.setVisible(false); + break; + } + default: + { + JOptionPane.showMessageDialog( + this, + "Invalid DOM Node Type", + "Processing Error", + JOptionPane.WARNING_MESSAGE); + break; + } + } + } + + if (obj instanceof NodeTag) + { + m_bTagSelected = true; + } + enableButtons(); + } + + /** + * + */ + private void enableButtons() + { + if (m_bTypeSelected) + { + if (m_bTagRequired) + { + if (m_bTagSelected) + { + if (m_bValueRequired) + { + if (m_bValueEntered) + { + m_btnAdd.setEnabled(true); +// m_btnDone.setEnabled(true); + } + else + { + m_btnAdd.setEnabled(false); + m_btnDone.setEnabled(false); + } + } + else + { + m_btnAdd.setEnabled(true); +// m_btnDone.setEnabled(true); + } + } + else + { + m_btnAdd.setEnabled(false); + m_btnDone.setEnabled(false); + } + } + else + { + if (m_bValueRequired) + { + if (m_bValueEntered) + { + m_btnAdd.setEnabled(true); +// m_btnDone.setEnabled(true); + } + else + { + m_btnAdd.setEnabled(false); + m_btnDone.setEnabled(false); + } + } + else + { + m_btnAdd.setEnabled(true); +// m_btnDone.setEnabled(true); + } + } + } + } + + /** + * + */ + private boolean buildElementTagList() + { + DataVector SearchKey = null; + DataVector FoundKey = null; + boolean bFirst = true; + int iFlags; + Vector vElements = new Vector(); + + try + { + + SearchKey = m_dbSystem.createJDataVector(); + FoundKey = m_dbSystem.createJDataVector(); + + // Setup the search key. + m_jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, + SearchKey, + KeyRetrieveFlags.FO_FIRST, + SearchKey); + + SearchKey.setLong(0, ReserveID.ELM_ELEMENT_TAG); + SearchKey.setString(1, "a"); + + for (;;) + { + if (bFirst) + { + bFirst = false; + iFlags = KeyRetrieveFlags.FO_INCL; + m_jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, SearchKey, iFlags, FoundKey); + + } + else + { + iFlags = KeyRetrieveFlags.FO_EXCL; + m_jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, FoundKey, iFlags, FoundKey); + + } + + if (FoundKey == null) + { + break; + } + + if (FoundKey.getLong(0) != ReserveID.ELM_ELEMENT_TAG) + { + break; + } + String sName = FoundKey.getString(1); + int iNumber = (int)FoundKey.getLong(3); + vElements.add(new NodeTag("<" + sName + ">", iNumber)); + } + + if (vElements.size() > 0) + { + m_NodeTagList.removeAll(); + m_NodeTagList.setListData(vElements); + m_NodeTagList.setEnabled(true); + m_NodeTagList.setVisible(true); + m_scrollPane.setVisible(true); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occured: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + m_NodeTagList.setEnabled(false); + m_NodeTagList.setVisible(false); + m_scrollPane.setVisible(false); + return false; + } + return true; + } + + /** + * + */ + private boolean buildAttributeTagList() + { + DataVector SearchKey = null; + DataVector FoundKey = null; + boolean bFirst = true; + int iFlags; + Vector vAttributes = new Vector(); + + try + { + + SearchKey = m_dbSystem.createJDataVector(); + FoundKey = m_dbSystem.createJDataVector(); + + // Setup the search key. + m_jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, + SearchKey, + KeyRetrieveFlags.FO_FIRST, + SearchKey); + + SearchKey.setLong(0, ReserveID.ELM_ATTRIBUTE_TAG); + SearchKey.setString(1, "a"); + + for (;;) + { + if (bFirst) + { + bFirst = false; + iFlags = KeyRetrieveFlags.FO_INCL; + m_jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, SearchKey, iFlags, FoundKey); + + } + else + { + iFlags = KeyRetrieveFlags.FO_EXCL; + m_jDb.keyRetrieve(FlmDictIndex.NAME_INDEX, FoundKey, iFlags, FoundKey); + + } + + if (FoundKey == null) + { + break; + } + + if (FoundKey.getLong(0) != ReserveID.ELM_ATTRIBUTE_TAG) + { + break; + } + String sName = FoundKey.getString(1); + int iNumber = (int)FoundKey.getLong(3); + vAttributes.add(new NodeTag("<" + sName + ">", iNumber)); + } + + if (vAttributes.size() > 0) + { + m_NodeTagList.removeAll(); + m_NodeTagList.setListData(vAttributes); + m_NodeTagList.setEnabled(true); + m_NodeTagList.setVisible(true); + m_scrollPane.setVisible(true); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occured: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + m_NodeTagList.setEnabled(false); + m_NodeTagList.setVisible(false); + m_scrollPane.setVisible(false); + return false; + } + return true; + } + + /* (non-Javadoc) + * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) + */ + public void keyPressed(KeyEvent e) + { + // BNot implementing + } + + /* (non-Javadoc) + * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) + */ + public void keyReleased(KeyEvent e) + { + int i = m_textField.getText().length(); + if (i == 0) + { + m_bValueEntered = false; + } + else + { + m_bValueEntered = true; + } + enableButtons(); + + } + + /* (non-Javadoc) + * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) + */ + public void keyTyped(KeyEvent e) + { + // Not implementing + } +/* + public static void main(String[] args) + { + Frame f = new Frame(); + NodeDialog nd = null; +// DbSystem dbSystem; +// try +// { +// dbSystem = new DbSystem(); +// } +// catch (XFlaimException e) +// { +// e.printStackTrace(); +// } +// String sDbFileName = "myxml.db"; +// NodePanel np = new NodePanel(null, 0); + try + { + nd = new NodeDialog(f); + } + catch (XFlaimException e1) + { + e1.printStackTrace(); + System.exit(0); + } + + Thread t = new Thread((Runnable)nd); + + t.start(); + } +*/ +} diff --git a/xflaim/java/util/xxedit/xedit/NodePanel.java b/xflaim/java/util/xxedit/xedit/NodePanel.java new file mode 100644 index 0000000..b87aa19 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/NodePanel.java @@ -0,0 +1,642 @@ +//------------------------------------------------------------------------------ +// Desc: Node Panel +// +// Tabs: 3 +// +// Copyright (c) 2003-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: NodePanel.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; + +import xedit.*; +import xflaim.*; +import java.awt.*; +import javax.swing.*; + +/** + * The Nodepanel class represents the DOM node that is being shown in the XEdit + * main display window. It preseves essential state information. It acts as + * as repository for the XEdit main body to interact with. There is a fixed + * number of NodePanel objects in the XEdit main display that never changes. + * As the user scrolls up or down, causing the nodes to be repositioned, + * the content of each NodePanel is copied to the NodePanel immediately + * adjacent to it. The NodePanels themselves are fixed in their location. + */ +public class NodePanel extends JPanel +{ + private boolean m_bExpanded; + private boolean m_bHasChildren; + private long m_lNodeId; + private long m_lDocId; + private int m_iCollection; + private XEdit m_root; + private JLabel m_label; + private GridBagLayout m_gbLayout; + private GridBagConstraints m_gbConstraints; + private int m_iRow; + private boolean m_bClosing; + + /** + * Constructor + */ + public NodePanel( + XEdit root, + int iRow) + { + m_lNodeId = -1; + m_lDocId = -1; + m_iCollection = -1; + m_root = root; + m_iRow = iRow; + m_bHasChildren = false; + m_bExpanded = false; + m_bClosing = false; + addMouseListener(m_root); + + m_label = new JLabel(); + m_label.setFont(new Font("Courier", Font.PLAIN, 16)); + Dimension d = root.getSizeOfDisplay(); + setSize(d.width, 17); + setMinimumSize(new Dimension(d.width, 17)); + + m_gbLayout = new GridBagLayout(); + m_gbConstraints = new GridBagConstraints(); + setLayout(m_gbLayout); + addToPanel(m_label, 0, 0, 1, 1, 100, 100, false); + + setVisible(true); + } + + /** + * Method reset the node panel. + */ + public void reset() + { + m_lNodeId = -1; + m_iCollection = -1; + m_bHasChildren = false; + m_bExpanded = false; + m_bClosing = false; + m_lDocId = -1; + setLabelText(""); + m_label.setForeground(Color.BLACK); + Dimension d = m_root.getSizeOfDisplay(); + setSize(d.width, 17); + } + + /** + * Method return the row number that this node occupies + */ + public int getRow() + { + return m_iRow; + } + + /** + * Method to get the expanded state of the node + */ + public boolean isExpanded() + { + return m_bExpanded; + } + + /** + * Method return the children status of the node (hasChildren) + */ + public boolean hasChildren() + { + return m_bHasChildren; + } + + /** + * Method return the node Id of the node + */ + public long getNodeId() + { + return m_lNodeId; + } + + /** + * Method return the document Id of the node + */ + public long getDocId() + { + return m_lDocId; + } + + /** + * Method return the closing state of the node, i.e. is this a + * closing node after expansion. + */ + public boolean isClosing() + { + return m_bClosing; + } + + + /** + * Method to set the forground of the label to show that this node is + * selected. + */ + public void selectNode() + { + if (m_lDocId > 0) + { + m_label.setForeground(Color.MAGENTA); + } + } + + /** + * Method to reset the forground of the label to show that this node is + * selected. + */ + public void deselectNode() + { + m_label.setForeground(Color.BLACK); + } + + /** + * Method to retrieve the collection for the current node. + */ + public int getCollection() + { + return m_iCollection; + } + + /** + * Method to copy a NodePanel. The Nodepane np will be copied into + * this node. + */ + public void copyNode( + NodePanel np) + { + m_bClosing = np.m_bClosing; + m_bExpanded = np.m_bExpanded; + m_bHasChildren = np.m_bHasChildren; + m_iCollection = np.m_iCollection; + m_lDocId = np.m_lDocId; + m_lNodeId = np.m_lNodeId; + m_label.setText(new String(np.m_label.getText())); + } + + /** + * Method to set the text that is being displayed by the NodePanel. + * @param sText + */ + private void setLabelText(String sText) + { + m_label.setText(sText); + } + + /** + * Sets up everything needed to present the DOM node as a text string in + * the NodePanel. All internal state variables are set accordingly. + * + * @param jDb + * @param refNode + * @param bExpanded + * @param bClosing + * @throws XFlaimException + */ + public void buildLabel( + DOMNode refNode, + boolean bExpanded, + boolean bClosing, + boolean bList) throws XFlaimException + { + String sText = null; + String sExpand; + String sTag = null; + String sName = null; + String sPrefix = null; + String sValue = null; + String[] saAttrTags = new String[100]; + String[] saAttrValues = new String[100]; + DOMNode attrNode = null; + int iNumAttrs = 0; + int iLevel; + int iNodeType = refNode.getNodeType(); + + m_bHasChildren = refNode.hasChildren(); + m_bExpanded = bExpanded; + m_lNodeId = refNode.getNodeId(); + m_lDocId = refNode.getDocumentId(); + if (m_lDocId == 0) + { + m_lDocId = m_lNodeId; + } + m_bClosing = bClosing; + m_iCollection = refNode.getCollection(); + + iLevel = getLevel(refNode); + + //The first thing on the label is a Plus sign (if the node has children). + if (m_bHasChildren && !bList) + { + if (m_bExpanded) + { + sExpand = "-"; + } + else + { + sExpand = "+"; + } + } + else + { + sExpand = new String(" "); + } + + if ((iNodeType != FlmDomNodeType.DATA_NODE) && + (iNodeType != FlmDomNodeType.COMMENT_NODE)) + { + sPrefix = refNode.getPrefix(); + sName = refNode.getLocalName(); + if (sPrefix != null && !sPrefix.equals("")) + { + sTag = sPrefix + ":" + sName; + } + else + { + sTag = sName; + } + } + + // Check here to see if this document has only one node (ignoring attributes) + // We want to make sure we assign the closing "/" only when the node that is + // marked as closing, truly is closing off other nodes. This is due to + // the way the up/down keys are used. + if (bClosing) + { + if (!m_bHasChildren && m_lDocId == m_lNodeId) + { + m_bClosing = bClosing = false; + } + } + + if (!bClosing) + { + if (refNode.hasAttributes()) + { + boolean bFirst = true; + + for (iNumAttrs = 0;;iNumAttrs++) + { + // We don't know how many attributes this node has, so we will have to rely on catching an exception to + // break out of this loop. + try + { + if (bFirst) + { + attrNode = refNode.getFirstAttribute(null); + bFirst = false; + } + else + { + attrNode = attrNode.getNextSibling(attrNode); + } + } + catch (XFlaimException e) + { + if (e.getRCode() == RCODE.NE_XFLM_DOM_NODE_NOT_FOUND) + { + break; + } + else + { + JOptionPane.showMessageDialog( + this, + "Exception occurred in Database: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return; + } + } // try/catch + + try + { + if (saAttrTags.length < iNumAttrs) + { + JOptionPane.showMessageDialog( + this, + "Too many attributes", + "Internal Error", + JOptionPane.ERROR_MESSAGE); + } + sPrefix = attrNode.getPrefix(); + sName = attrNode.getLocalName(); + if (sPrefix != null && !sPrefix.equals("")) + { + saAttrTags[iNumAttrs] = sPrefix + ":" + sName; + } + else + { + saAttrTags[iNumAttrs] = sName; + } + saAttrValues[iNumAttrs] = getNodeValue(attrNode); + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Exception occurred in Database: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return; + } + + } // for - getting attributes. + } + } + + // Now build the actual label. + sText = sExpand + " "; + if (!bList) + { + for (int i=0; i < iLevel; i++) + { + sText = sText + " "; + } + sText = sText + new Integer(iLevel).toString() + " "; + } + if (iNodeType == FlmDomNodeType.ELEMENT_NODE) + { + sText = sText + "<"; + if (bClosing) + { + sText = sText + "/"; + } + sText = sText + sTag; + + for (int i = 0; i < iNumAttrs; i++) + { + sText = sText + " " + saAttrTags[i] + "=\"" + saAttrValues[i] + "\""; + } + + if (!bClosing) + { + if (m_bHasChildren && !m_bExpanded) + { + sText = sText + "/>"; + } + else + { + sText = sText + ">"; + } + } + else + { + sText = sText + ">"; + } + // Check for annotations. + if (!bClosing && refNode.hasAnnotation()) + { + DOMNode jAnnot = refNode.getAnnotation(null); + sText += jAnnot.getString(); + } + } + else // Comment or Data Node. Don't handle other types right now. + { + if (iNodeType == FlmDomNodeType.COMMENT_NODE) + { + sText = sText + ""; + } + } + if (bList) + { + // Need to make sure we don't let the value get too long on a list. This + // is a temporary measure to help find why the list page when listing + // dictionary documents hooks the key events onto the horizontal scroll + // bar. + if (sText.length() > 65) + { + sText = sText.substring(0, 64); + } + } + m_label.setText(sText); + Dimension d = getSize(); + setSize(m_label.getWidth(), d.height); + } + + /** + * Method to calculate the indentation level of the node. + * + * @param refNode + * @return + * @throws XFlaimException + */ + private int getLevel( + DOMNode refNode) throws XFlaimException + { + DOMNode parent = null; + int iLevel = 0; + boolean bFirst = true; + + for (;;) + { + try + { + if (bFirst) + { + bFirst = false; + parent = refNode.getParentNode(null); + } + else + { + parent = parent.getParentNode(parent); + } + iLevel++; + } + catch (XFlaimException e) + { + if (e.getRCode() == RCODE.NE_XFLM_DOM_NODE_NOT_FOUND) + { + break; + } + else + { + throw e; + } + } + } + + return iLevel; + + } + + /** + * Method to retrieve the node Value as a text string suitable for + * displaying. + * + * @param jNode + * @return + */ + private String getNodeValue( + DOMNode jNode) + { + int iDataType; + String sValue = null; + + try + { + + iDataType = jNode.getDataType(); + + switch (iDataType) + { + case FlmDataType.FLM_TEXT_TYPE: + { + sValue = jNode.getString(); + break; + } + case FlmDataType.FLM_NUMBER_TYPE: + { + long lValue = jNode.getLong(); + sValue = (new Long(lValue)).toString(); + break; + } + case FlmDataType.FLM_BINARY_TYPE: + { + // No supported yet. + } + default: + + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog(this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return null; + } + + + return sValue; + } + + /** + * Adds the internal component (label) to the NodePanel, setting the + * constraints as specified. + * + * @param comp + * @param iColumn + * @param iRow + * @param iColSpan + * @param iRowSpan + * @param iColWeight + * @param iRowWeight + * @param bUpdateDisplay + */ + private void addToPanel( + Component comp, + int iColumn, + int iRow, + int iColSpan, + int iRowSpan, + int iColWeight, + int iRowWeight, + boolean bUpdateDisplay) + { + UITools.buildConstraints(m_gbConstraints, iColumn, iRow, iColSpan, iRowSpan, iColWeight, iRowWeight); + m_gbConstraints.anchor = GridBagConstraints.LINE_START; + m_gbConstraints.fill = GridBagConstraints.NONE; + m_gbLayout.addLayoutComponent(comp, m_gbConstraints); + add(comp); + if (bUpdateDisplay) + { + m_root.updateDisplay(); + } + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) + */ +// public void mouseClicked(MouseEvent e) +// { +// Point p; + + // Select the row. +// m_root.selectRow(this); + +// if (e.getButton() == MouseEvent.BUTTON3) +// { + // popup the document menu. +// m_popup = new JPopupMenu("Document Node Options"); +// m_popup.addFocusListener(this); +// if (m_root.isMainPanel((JPanel)this.getParent())) +// { +// m_closeItem = m_popup.add("Close Document"); +// m_closeItem.addActionListener(this); +// m_popup.addSeparator(); +// } + +// if (m_bHasChildren) +// { +// if (m_bExpanded) +// { +// m_expandCollapseItem = m_popup.add("Collapse Node"); +// } +// else +// { +// m_expandCollapseItem = m_popup.add("Expand Node"); +// } +// m_expandCollapseItem.addActionListener(this); +// m_popup.addSeparator(); +// } + +// m_deleteItem = m_popup.add("Delete Node"); +// m_deleteItem.addActionListener(this); +// m_editItem = m_popup.add("Edit Node"); +// m_editItem.setEnabled(false); +// m_editItem.addActionListener(this); + + // Need to make sure the menu appears close to where our window is located. +// p = e.getPoint(); +// m_popup.show(this, p.x, p.y); +// } + +// if (e.getButton() == MouseEvent.BUTTON1) +// { +// if (e.getClickCount() > 1) +// { + // Expand or Collapse the node. +// if (m_bExpanded) +// { +// collapse(); +// } +// else +// { +// expand(); +// } +// } +// } + +// } + + +} diff --git a/xflaim/java/util/xxedit/xedit/NodeTag.java b/xflaim/java/util/xxedit/xedit/NodeTag.java new file mode 100644 index 0000000..362a9bc --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/NodeTag.java @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// Desc: Node Tag +// +// Tabs: 3 +// +// Copyright (c) 2003-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: NodeTag.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; + +import java.awt.Component; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class NodeTag extends Component +{ + + private String m_sName; + int m_iNumber; + + /** + * + */ + public NodeTag( + String sName, + int iNumber) + { + m_iNumber = iNumber; + m_sName = sName; + + } + + public String toString() + { + return m_sName; + } + +} diff --git a/xflaim/java/util/xxedit/xedit/NodeType.java b/xflaim/java/util/xxedit/xedit/NodeType.java new file mode 100644 index 0000000..120a587 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/NodeType.java @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// Desc: Node Type +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: NodeType.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; + +import java.awt.Component; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class NodeType extends Component +{ + String m_sType; + int m_iType; + + public NodeType( + String sType, + int iType) + { + m_sType = sType; + m_iType = iType; + } + + public String toString() + { + return m_sType; + } +} diff --git a/xflaim/java/util/xxedit/xedit/NodeValue.java b/xflaim/java/util/xxedit/xedit/NodeValue.java new file mode 100644 index 0000000..b4217f6 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/NodeValue.java @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// Desc: Node Value +// +// Tabs: 3 +// +// Copyright (c) 2004-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: NodeValue.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class NodeValue +{ + String m_sValue; + /** + * + */ + public NodeValue( + String sValue) + { + m_sValue = sValue; + } + + public void setValue( + String sValue) + { + m_sValue = sValue; + } + + public String getValue() + { + return m_sValue; + } + +} diff --git a/xflaim/java/util/xxedit/xedit/OpenDocumentSelector.java b/xflaim/java/util/xxedit/xedit/OpenDocumentSelector.java new file mode 100644 index 0000000..1a4b9d4 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/OpenDocumentSelector.java @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// Desc: Open Document Selector +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: OpenDocumentSelector.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ + +package xedit; +import xedit.UITools; + +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JList; +import javax.swing.JDialog; +import javax.swing.JScrollPane; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class OpenDocumentSelector extends JDialog implements ActionListener +{ + + private JList m_lstList; + private JButton m_btnOkay; + private JButton m_btnCancel; + private int m_iItem; + + public OpenDocumentSelector( + Frame owner, + Vector vDocList) + { + super(owner, "Select Open Document", true); + + Container CP; // The content pane for this dialog + GridBagLayout gridbag; + GridBagConstraints constraints = new GridBagConstraints(); + + // Coordinates for locating this window in the center of its parent. + Point p; + Dimension d; + int x; + int y; + + setDefaultCloseOperation( DISPOSE_ON_CLOSE); + CP = getContentPane(); + gridbag = new GridBagLayout(); + CP.setLayout( gridbag); + + m_iItem = -1; + + // Add the list + m_lstList = new JList( vDocList); + m_lstList.setSelectedIndex(0); + + JScrollPane scrollPane = new JScrollPane(); + scrollPane.getViewport().setView(m_lstList); + + UITools.buildConstraints(constraints, 0, 0, 2, 4, 100, 100); + constraints.anchor = GridBagConstraints.NORTHWEST; + constraints.fill = GridBagConstraints.BOTH; + + gridbag.setConstraints( scrollPane, constraints); + + CP.add( scrollPane); + + // Add the Okay button + m_btnOkay = new JButton("Okay"); + m_btnOkay.setDefaultCapable(true); + m_btnOkay.addActionListener(this); + + UITools.buildConstraints(constraints, 0, 5, 1, 1, 90, 100); + constraints.anchor = GridBagConstraints.EAST; + constraints.fill = GridBagConstraints.NONE; + + gridbag.setConstraints( m_btnOkay, constraints); + + CP.add( m_btnOkay); + + // Add the Cancel button + m_btnCancel = new JButton("Cancel"); + m_btnCancel.addActionListener(this); + + UITools.buildConstraints(constraints, 1, 5, 1, 1, 10, 0); + constraints.anchor = GridBagConstraints.WEST; + + gridbag.setConstraints( m_btnCancel, constraints); + + CP.add( m_btnCancel); + + setSize(Math.max( 400, 200), 200); + + p = owner.getLocationOnScreen(); + d = owner.getSize(); + x = (d.width - 400) / 2; + y = (d.height - 300) / 2; + setLocation(Math.max(0, p.x + x), Math.max(0, p.y + y)); + } + + public int showDialog() + { + setVisible( true); + return m_iItem; + } + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Object obj = (Object)e.getSource(); + if (obj == m_btnOkay) + { + m_iItem = m_lstList.getSelectedIndex(); + setVisible(false); + dispose(); + } + else + { + setVisible(false); + dispose(); + } + } +} diff --git a/xflaim/java/util/xxedit/xedit/ProgressBox.java b/xflaim/java/util/xxedit/xedit/ProgressBox.java new file mode 100644 index 0000000..ba8f69e --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/ProgressBox.java @@ -0,0 +1,258 @@ +//------------------------------------------------------------------------------ +// Desc: Progress Box +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: ProgressBox.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import xedit.UITools; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class ProgressBox extends JDialog implements ActionListener +{ + private JLabel m_label1; + private JLabel m_label2; + private JCheckBox m_checkBox; + private JButton m_button; + private JProgressBar m_bar; + private boolean m_bCloseOnExit = false; + private boolean m_bToggled = false; + private boolean m_bCancelPressed = false; + + /** + * @throws java.awt.HeadlessException + */ + public ProgressBox( + Frame owner, + int iWidth, + int iHeight, + String label1, + String label2, + int iMin, + int iMax) + { + super(); + JPanel p1; + JPanel p2; + JPanel p3; + JPanel p4; + Container CP; // The content pane for this dialog + // Coordinates for location this window in the center of its parent. + Point p; + Dimension d; + int x; + int y; + + m_label1 = new JLabel(label1); + m_label2 = new JLabel(label2); + + setDefaultCloseOperation( DISPOSE_ON_CLOSE); + CP = getContentPane(); + CP.setLayout( new GridLayout( 4, 1)); + + p1 = new JPanel(); + p1.add(m_label1); + CP.add(p1); + + p2 = new JPanel(); + p2.add(m_label2); + CP.add(p2); + + m_bar = new JProgressBar(iMin, iMax); + m_bar.setStringPainted(true); + if (iMax == 0) + { + m_bar.setIndeterminate(true); + } + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + UITools.buildConstraints(gbc, 0, 0, 0, 0, 100, 100); + gbc.fill = GridBagConstraints.BOTH; + gbl.setConstraints(m_bar, gbc); + p3 = new JPanel(); + p3.setLayout(gbl); + p3.add(m_bar); + CP.add(p3); + + p4 = new JPanel(); + GridBagLayout grid = new GridBagLayout(); + p4.setLayout(grid); + + m_checkBox = new JCheckBox(); + m_checkBox.setEnabled(true); + m_checkBox.addActionListener(this); + UITools.buildConstraints(gbc, 0, 0, 1, 1, 10, 100); + gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.NONE; + grid.setConstraints(m_checkBox, gbc); + p4.add(m_checkBox); + + JLabel lbl1 = new JLabel("Close when finished"); + UITools.buildConstraints(gbc, 1, 0, 1, 2, 60, 0); + gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.NONE; + grid.setConstraints(lbl1, gbc); + p4.add(lbl1); + + m_button = new JButton("Cancel"); + m_button.addActionListener(this); + UITools.buildConstraints(gbc, 2, 0, 1, 1, 30, 0); + gbc.anchor = GridBagConstraints.EAST; + gbc.fill = GridBagConstraints.NONE; + grid.setConstraints(m_button, gbc); + p4.add(m_button); + + CP.add(p4); + + setSize(iWidth,iHeight); + + if (owner != null) + { + p = owner.getLocationOnScreen(); + d = owner.getSize(); + x = (d.width - iWidth) / 2; + y = (d.height - iHeight) / 2; + setLocation(Math.max(0, p.x + x), Math.max(0, p.y + y)); + } + + setVisible(true); + } + + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Object obj = e.getSource(); + if (obj == m_checkBox) + { + m_bCloseOnExit = !m_bCloseOnExit; + } + else if (obj == m_button) + { + if (m_button.getText().equals("Cancel")) + { + m_bCancelPressed = true; + } + else + { + dispose(); + } + } + } + + public void setLabel1( String newLabel1) + { + m_label1.setText( newLabel1); + } + + public void setLabel2( String newLabel2) + { + m_label2.setText( newLabel2); + } + + public void updateProgress( int iValue) + { + m_bar.setValue( iValue); + if (iValue >= m_bar.getMaximum() && m_bar.getMaximum() > 0) + { + if (m_bCloseOnExit) + { + dispose(); + } + else + { + toggleOkCancelButton(); + } + } + + } + + public void terminate() + { + dispose(); + } + + private void toggleOkCancelButton() + { + if (m_bToggled) + { + m_button.setText("Cancel"); + m_bToggled = false; + } + else + { + m_button.setText("Okay"); + m_bToggled = true; + } + } + + public boolean Cancelled() + { + return m_bCancelPressed; + } + + public void setMax( int iMax) + { + m_bar.setMaximum( iMax); + } + + public static void main(String[] args) + { + ProgressBox b = new ProgressBox(null, 400, 160, "Label 1Label 1Label 1Label 1Label 1Label 1Label 1", + "Label 2Label 2Label 2Label 2Label 2Label 2Label 2", + 0, 999); + + for (int i = 0; i < 1000; i++) + { + if (i % 100 == 0) + { + b.setLabel1( "Importing file " + i + "of 1000"); + } + b.setLabel2("Filename: xxxx" + i + ".xml"); + b.updateProgress(i); + if (b.Cancelled()) + { + b.terminate(); + break; + } + try + { + Thread.sleep(10); + } + catch (Exception e) + { + // Do nothing... + } + } + System.exit(0); + } + +} diff --git a/xflaim/java/util/xxedit/xedit/Status.java b/xflaim/java/util/xxedit/xedit/Status.java new file mode 100644 index 0000000..878b0b8 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/Status.java @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +// Desc: Status +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: Status.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; +import javax.swing.JLabel; + + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class Status +{ + private boolean m_bDatabaseOpen; + private String m_sDatabasePath; + private JLabel m_label; + private long m_lDocId; + private long m_lNodeId; + private boolean m_bTransaction = false; + public int m_iCurrentNode = -2; + public int m_iLastNode = -2; + + + // Constructor + Status() + { + m_bDatabaseOpen = false; + m_sDatabasePath = null; + m_label = null; + m_lDocId = 0; + m_lNodeId = 0; + } + + Status( + JLabel label) + { + m_bDatabaseOpen = false; + m_sDatabasePath = null; + m_lDocId = 0; + m_lNodeId = 0; + m_label = label; + updateLabel(); + } + + public void setDatabaseOpen( + boolean bOpen) + { + m_bDatabaseOpen = bOpen; + updateLabel(); + } + + public boolean getDatabaseOpen() + { + return m_bDatabaseOpen; + } + + public void setDatabasePath( + String sDatabasePath) + { + m_sDatabasePath = sDatabasePath; + updateLabel(); + } + + public String getDatabasePath() + { + return m_sDatabasePath; + } + + public void setDocId( + long lDocId) + { + m_lDocId = lDocId; + updateLabel(); + } + + public long getDocId() + { + return m_lDocId; + } + + public void setNodeId( + long lNodeId) + { + m_lNodeId = lNodeId; + updateLabel(); + } + + public long getNodeId() + { + return m_lNodeId; + } + + public void setLabel( + JLabel label) + { + m_label = label; + updateLabel(); + } + + public void setTransaction( + boolean bTransaction) + { + m_bTransaction = bTransaction; + updateLabel(); + } + + public boolean getTransaction() + { + return m_bTransaction; + } + + public void updateLabel() + { + String sLabelText; + String sDocNode = ""; + String sTransaction = m_bTransaction ? "Update" : ""; + + if (m_label != null) + { + if (m_bDatabaseOpen) + { + sLabelText = "Database: " + m_sDatabasePath; + + if (m_lDocId > 0 && m_lNodeId > 0) + { + sDocNode = new String("\t" + new Long(m_lDocId).toString() + + "/" + new Long(m_lNodeId).toString()); + } + } + else + { + sLabelText = "No Database"; + } +// m_label.setText(sLabelText + " " + sDocNode + " [" + m_iCurrentNode + "/" + m_iLastNode + "]"); + m_label.setText(sLabelText + " " + sDocNode + " " + sTransaction); + } + } +} diff --git a/xflaim/java/util/xxedit/xedit/UITools.java b/xflaim/java/util/xxedit/xedit/UITools.java new file mode 100644 index 0000000..4155cef --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/UITools.java @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// Desc: UI Tools +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: UITools.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; +import java.awt.GridBagConstraints; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class UITools +{ + public static void buildConstraints( + GridBagConstraints gbc, + int gx, + int gy, + int gw, + int gh, + int wx, + int wy) + { + gbc.gridx = gx; + gbc.gridy =gy; + gbc.gridwidth = gw; + gbc.gridheight = gh; + gbc.weightx = wx; + gbc.weighty = wy; + } +} diff --git a/xflaim/java/util/xxedit/xedit/XEdit.java b/xflaim/java/util/xxedit/xedit/XEdit.java new file mode 100644 index 0000000..80324c0 --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/XEdit.java @@ -0,0 +1,3435 @@ +//------------------------------------------------------------------------------ +// Desc: XEdit +// +// Tabs: 3 +// +// Copyright (c) 2003-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: XEdit.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ +package xedit; + +import xflaim.*; +import java.awt.*; +import java.awt.event.*; +import java.io.File; +import java.util.Vector; +import javax.swing.*; + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class XEdit extends JFrame implements Runnable, ActionListener, MouseListener, KeyListener +{ + // Package members + DbSystem m_dbSystem; + Db m_jDb; + + // Private member variables. + private JPanel m_mainDisplay; + private JPanel m_mainPanel; + private Status m_status; + private String m_sDatabaseName; + private String m_sDirectory; + private Vector m_vDocList; + private Vector m_vNodeList; + private int m_iExpandedRow; + private int m_iLastNode; + private final int FIRST_NODE = 0; + private final int LAST_NODE = 31; + private final int NO_NODES = -1; + private NodePanel m_selected; + private boolean m_bDocList = false; + private int m_iCollection; + private Document m_doc; + private XEdit m_parent = null; + private JPopupMenu m_popup = null; + private boolean m_bMustExit = false; + + + /** + * Basic constructor + * @param title + */ + XEdit( + String title) + { + super(title); + init(); + } + + /** + * Collection List constructor + * @param parent + * @param title + * @param jDb + * @param iCollection + * @param doc + */ + XEdit( + XEdit parent, + String title, + Db jDb, + int iCollection, + Document doc) + { + super(title); + m_bDocList = true; + m_parent = parent; + + init(); + + m_iCollection = iCollection; + m_doc = doc; + m_jDb = jDb; + + if (!showDocumentList()) + { + JOptionPane.showMessageDialog( + this, + "Collection contains no documents", + "Empty Collection", + JOptionPane.INFORMATION_MESSAGE); + m_bMustExit = true; + } + } + + /*------------------------------------------------------------------------- + * Desc: Method to execute the common initialization tasks. + *-----------------------------------------------------------------------*/ + private void init() + { + setSize(660, 625); + this.setResizable(false); + this.addKeyListener(this); + + setDefaultCloseOperation(EXIT_ON_CLOSE); + + m_sDatabaseName = null; + m_sDirectory = System.getProperty("user.dir"); + m_selected = null; + + // Create a dbSystem object. + try + { + m_dbSystem = new DbSystem(); + } + catch (XFlaimException e) + { + e.printStackTrace(); + System.exit(0); + } + + // Initialize the jDb to null; + m_jDb = null; + + // Create the main panel that will hold everything else. + m_mainPanel = new JPanel(); + + // Set the layout manager. + m_mainPanel.setLayout(new BorderLayout()); + + // Create the menu and add it to the panel + if (!m_bDocList) + { + JMenuBar menuBar = makeMainMenu(); + m_mainPanel.add("North", menuBar); + } + + // Create the status bar and add it to the panel + JLabel statusBar = new JLabel((m_bDocList + ? "Document List" + : "No Database")); + m_mainPanel.add("South", statusBar); + // New Status object to track our status. + + m_status = new Status(statusBar); + + + // Create the panel to display the documents and the scrollable panel and add them to the + // main panel. + + m_mainDisplay = new JPanel(); + + m_mainDisplay.setLayout(new GridLayout(32, 1)); + JScrollPane scrollPane = new JScrollPane(m_mainDisplay); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); + + m_mainPanel.add("Center", scrollPane); + + m_vDocList = new Vector(); + m_vNodeList = new Vector(); + + // Fill up the display with blank panels. + for (int i = FIRST_NODE; i <= LAST_NODE; i++) + { + NodePanel np = new NodePanel(this, i); + m_mainDisplay.add(np); + m_vNodeList.addElement(np); + } + m_iLastNode = NO_NODES; + + m_status.m_iCurrentNode = NO_NODES; + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + + // Make it all stick together... + setContentPane(m_mainPanel); + } + + /*========================================================================= + * Desc: Method to return the size (Dimension) of the main display panel. + *=======================================================================*/ + public Dimension getSizeOfDisplay() + { + return m_mainDisplay.getSize(); + } + + /*========================================================================= + * Desc: Method to handle the events from the menu. + *=======================================================================*/ + public void actionPerformed(ActionEvent e) + { + JMenuItem source = (JMenuItem) (e.getSource()); + + String label = source.getText(); + + // Are we exiting? + if (label.equals("Exit")) + { + System.exit(0); + } + else if (label.equals("Open")) + { + openDatabase(); + } + else if (label.equals("New")) + { + createDatabase(); + } + else if (label.equals("Close")) + { + closeDatabase(); + } + else if (label.equals("Remove")) + { + removeDatabase(); + } + else if (label.equals("First Document")) + { + getFirstDocument(); + } + else if (label.equals("Open Document")) + { + openDocument(); + } + else if (label.equals("Create Document")) + { + createDocument(m_selected); + } + else if (label.equals("Close Document")) + { + if (m_popup != null) + { + NodePanel np = m_selected; + closeDocument(np); + } + else + { + closeDocument(); + } + } + else if (label.equals("Import Document(s)")) + { + importDocument(); + } + else if (label.equals("Collapse Node")) + { + NodePanel np = m_selected; + if (np.isExpanded()) + { + collapseNode(np); + } + } + else if (label.equals("Expand Node")) + { + NodePanel np = m_selected; + if (!np.isExpanded()) + { + expandNode(np, true); + } + } + else if (label.equals("Delete Node")) + { + deleteNode(m_selected); + } + else if (label.equals("Delete Attribute")) + { + deleteAttribute(m_selected); + } + else if (label.equals("Delete Annotation")) + { + deleteAnnotation(m_selected); + } + else if (label.equals("Edit Value")) + { + editValue(m_selected); + } + else if (label.equals("Edit Attribute")) + { + editAttribute(m_selected); + } + else if (label.equals("Edit Annotation")) + { + editAnnotation(m_selected); + } + else if (label.equals("Add Node")) + { + createNode(m_selected); + } + else if (label.equals("Begin Transaction")) + { + beginTransaction(); + } + else if (label.equals("Commit Transaction")) + { + commitTransaction(); + } + else if (label.equals("Abort Transaction")) + { + abortTransaction(); + } + + // If the popup menu is enabled, let's get rid of it. + if (m_popup != null) + { + m_popup = null; + } + } + + /** + * @param np + */ + private void deleteAnnotation( + NodePanel np) + { + DOMNode jNode = null; + DOMNode jAnnot = null; + boolean bTransBegun = false; + String sMessage; + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), null); + if (!jNode.hasAnnotation()) + { + return; + } + + jAnnot = jNode.getAnnotation(jAnnot); + sMessage = new String("Delete annotation: " + jAnnot.getString()); + + if (JOptionPane.showConfirmDialog( + this, + sMessage) == JOptionPane.OK_OPTION) + { + // Begin a transaction + if (!m_status.getTransaction()) + { + m_jDb.transBegin(TransactionType.UPDATE_TRANS, 0, 0); + bTransBegun = true; + } + + // Delete the node. + jAnnot.deleteNode(); + + // Commit + if (bTransBegun) + { + m_jDb.transCommit(); + bTransBegun = false; + } + + // Refresh the current row + if (np.isExpanded() && np.isClosing()) + { + collapseNode(np); + expandNode(m_selected, true); + } + else + { + np.buildLabel(jNode, np.isExpanded(), np.isClosing(), false); + } + + } + } + catch(XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + finally + { + if (bTransBegun) + { + try + { + m_jDb.transAbort(); + } + catch (XFlaimException ex) + { + // ignore this one. + } + } + } + } + + /** + * @param m_selected + */ + private void deleteAttribute( + NodePanel np) + { + DOMNode jNode = null; + DOMNode jAttr = null; + boolean bTransBegun = false; + String sMessage; + + try + { + Attribute attr = new Attribute("Empty", -1); + + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), jNode); + + AttributeSelector AS = new AttributeSelector(this, jNode, attr); + AS.dispose(); + + if (attr.m_lNodeId == -1) + { + return; // Cancelled + } + + jAttr = m_jDb.getNode(np.getCollection(), attr.m_lNodeId, jAttr); + sMessage = new String("Delete attribute: <" + jAttr.getLocalName() + "> ?"); + + if (JOptionPane.showConfirmDialog( + this, + sMessage) == JOptionPane.OK_OPTION) + { + // See if we need to begin an update transaction + if (!m_status.getTransaction()) + { + m_jDb.transBegin( + TransactionType.UPDATE_TRANS, 0, 0); + bTransBegun = true; + } + + jAttr.deleteNode(); + + if (bTransBegun) + { + m_jDb.transCommit(); + } + + // Update the display. + if (np.isExpanded() && np.isClosing()) + { + collapseNode(np); + expandNode(m_selected, true); + } + else + { + np.buildLabel(jNode, np.isExpanded(), np.isClosing(), false); + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + if (bTransBegun) + { + try + { + m_jDb.transAbort(); + } + catch (XFlaimException ex) + { + // Don't do anything here. + } + } + } + } + + private void editValue( + NodePanel np) + { + DOMNode jNode = null; + boolean bTransBegun = false; + String sValue; + + if (!m_status.getDatabaseOpen()) + { + JOptionPane.showMessageDialog( + this, + "No open database", + "Command Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), jNode); + sValue = jNode.getString(); + NodeValue nv = new NodeValue(sValue); + EditValueDialog valueDialog = new EditValueDialog("Edit Node Value", this, nv); + valueDialog.dispose(); + if (!sValue.equals(nv.getValue())) + { + // See if we need to begin an update transaction + if (!m_status.getTransaction()) + { + m_jDb.transBegin( + TransactionType.UPDATE_TRANS, 0, 0); + bTransBegun = true; + } + + jNode.setString(nv.getValue()); + + if (bTransBegun) + { + m_jDb.transCommit(); + } + + // Update the display. + if (np.isExpanded() && np.isClosing()) + { + collapseNode(np); + expandNode(m_selected, true); + } + else + { + np.buildLabel(jNode, np.isExpanded(), np.isClosing(), false); + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + if (bTransBegun) + { + try + { + m_jDb.transAbort(); + } + catch (XFlaimException ex) + { + // Don't do anything here. + } + } + } + } + + private void editAnnotation( + NodePanel np) + { + DOMNode jNode = null; + DOMNode jAnnot = null; + boolean bTransBegun = false; + String sValue; + + if (!m_status.getDatabaseOpen()) + { + JOptionPane.showMessageDialog( + this, + "No open database", + "Command Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), jNode); + jAnnot = jNode.getAnnotation(jAnnot); + sValue = jAnnot.getString(); + NodeValue nv = new NodeValue(sValue); + EditValueDialog valueDialog = new EditValueDialog("Edit Annotation Value", this, nv); + valueDialog.dispose(); + if (!sValue.equals(nv.getValue())) + { + // See if we need to begin an update transaction + if (!m_status.getTransaction()) + { + m_jDb.transBegin( + TransactionType.UPDATE_TRANS, 0, 0); + bTransBegun = true; + } + + jAnnot.setString(nv.getValue()); + + if (bTransBegun) + { + m_jDb.transCommit(); + } + + // Update the display. + if (np.isExpanded() && np.isClosing()) + { + collapseNode(np); + expandNode(m_selected, true); + } + else + { + np.buildLabel(jNode, np.isExpanded(), np.isClosing(), false); + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + if (bTransBegun) + { + try + { + m_jDb.transAbort(); + } + catch (XFlaimException ex) + { + // Don't do anything here. + } + } + } + } + + private void editAttribute( + NodePanel np) + { + DOMNode jNode = null; + DOMNode jAttr = null; + boolean bTransBegun = false; + String sValue; + + if (!m_status.getDatabaseOpen()) + { + JOptionPane.showMessageDialog( + this, + "No open database", + "Command Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + try + { + Attribute attr = new Attribute("Empty", -1); + + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), jNode); + + AttributeSelector AS = new AttributeSelector(this, jNode, attr); + AS.dispose(); + + if (attr.m_lNodeId == -1) + { + return; // Cancelled + } + + jAttr = m_jDb.getNode(np.getCollection(), attr.m_lNodeId, jAttr); + sValue = jAttr.getString(); + NodeValue nv = new NodeValue(sValue); + EditValueDialog valueDialog = new EditValueDialog("Edit Attribute Value", this, nv); + valueDialog.dispose(); + if (!sValue.equals(nv.getValue())) + { + // See if we need to begin an update transaction + if (!m_status.getTransaction()) + { + m_jDb.transBegin( + TransactionType.UPDATE_TRANS, 0, 0); + bTransBegun = true; + } + + jAttr.setString(nv.getValue()); + + if (bTransBegun) + { + m_jDb.transCommit(); + } + + // Update the display. + if (np.isExpanded() && np.isClosing()) + { + collapseNode(np); + expandNode(m_selected, true); + } + else + { + np.buildLabel(jNode, np.isExpanded(), np.isClosing(), false); + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + if (bTransBegun) + { + try + { + m_jDb.transAbort(); + } + catch (XFlaimException ex) + { + // Don't do anything here. + } + } + } + } + + /** + * @param m_selected + */ + private void createNode( + NodePanel np) + { + if (!m_status.getDatabaseOpen()) + { + JOptionPane.showMessageDialog( + this, + "No open database", + "Command Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + try + { + // Need to get the collection. + long lNodeId = 0; + int iCollection = 0; + + if (np != null) + { + lNodeId = np.getNodeId(); + iCollection = np.getCollection(); + } + + if (iCollection > 0) + { + NodeDialog nd = new NodeDialog( + this, + m_dbSystem, + m_status.getDatabasePath(), + lNodeId, + iCollection); + GraphicsConfiguration gc = nd.getGraphicsConfiguration(); + Rectangle bounds = gc.getBounds(); + int iHeight = nd.getHeight(); + int iWidth = nd.getWidth(); + nd.setLocation(Math.max(0, (bounds.width - iWidth)/2), + Math.max(0, (bounds.height - iHeight)/2)); + Thread t = new Thread((Runnable)nd); + t.start(); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Failed to create dialog: " + e.getMessage(), + "Exception occurred", + JOptionPane.ERROR_MESSAGE); + } + } + + /** + * + */ + private void createDocument( + NodePanel np) + { + if (!m_status.getDatabaseOpen()) + { + JOptionPane.showMessageDialog( + this, + "No open database", + "Command Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + try + { + // Need to get the collection. + int iCollection = selectCollection(); + if (iCollection > 0) + { + long lNodeId = 0; + if (np != null) + { + lNodeId = np.getNodeId(); + } + NodeDialog nd = new NodeDialog( + this, + m_dbSystem, + m_status.getDatabasePath(), + lNodeId, + iCollection); + GraphicsConfiguration gc = nd.getGraphicsConfiguration(); + Rectangle bounds = gc.getBounds(); + int iHeight = nd.getHeight(); + int iWidth = nd.getWidth(); + nd.setLocation(Math.max(0, (bounds.width - iWidth)/2), + Math.max(0, (bounds.height - iHeight)/2)); + Thread t = new Thread((Runnable)nd); + t.start(); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Failed to create dialog: " + e.getMessage(), + "Exception occurred", + JOptionPane.ERROR_MESSAGE); + } + } + + /** + * + */ + private void beginTransaction() + { + if (m_status.getTransaction()) + { + JOptionPane.showMessageDialog( + this, + "Update transaction already in progress", + "Transaction Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + try + { + if (m_status.getDatabaseOpen()) + { + m_jDb.transBegin(TransactionType.UPDATE_TRANS, 0, 0); + m_status.setTransaction(true); + } + else + { + JOptionPane.showMessageDialog( + this, + "Cannot begin transaction - no open database.", + "Incomplete Operation", + JOptionPane.INFORMATION_MESSAGE); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + + } + } + + /** + * + */ + private void commitTransaction() + { + if (!m_status.getTransaction()) + { + JOptionPane.showMessageDialog( + this, + "No update transaction in progress", + "Transaction Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + try + { + if (m_status.getDatabaseOpen()) + { + m_jDb.transCommit(); + m_status.setTransaction(false); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + + } + } + + /** + * + */ + private void abortTransaction() + { + if (!m_status.getTransaction()) + { + JOptionPane.showMessageDialog( + this, + "No update transaction in progress", + "Transaction Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + try + { + if (m_status.getDatabaseOpen()) + { + m_jDb.transAbort(); + m_status.setTransaction(false); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + + } + } + + /*========================================================================= + * Desc: constructs the main menu for the application. + *=======================================================================*/ + private JMenuBar makeMainMenu() + { + JMenuBar menuBar = null; + JMenu fileMenu = null; + JMenu docMenu = null; + JMenu transMenu = null; + + menuBar = new JMenuBar(); + // Create the main menu. + menuBar = new JMenuBar(); + + // Create the File menu + fileMenu = new JMenu("File"); + fileMenu.setMnemonic(KeyEvent.VK_F); + + // Add the file Menu to the menu bar + menuBar.add(fileMenu); + + /*------------------------ File menu ---------------------------------*/ + + // Create a few items to add to the file menu + JMenuItem menuItem = new JMenuItem("Open"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK)); + menuItem.setMnemonic(KeyEvent.VK_O); + menuItem.addActionListener(this); + fileMenu.add(menuItem); + + menuItem = new JMenuItem("Close"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)); + menuItem.setMnemonic(KeyEvent.VK_C); + menuItem.addActionListener(this); + fileMenu.add(menuItem); + + menuItem = new JMenuItem("New"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); + menuItem.setMnemonic(KeyEvent.VK_N); + menuItem.addActionListener(this); + fileMenu.add(menuItem); + + fileMenu.addSeparator(); + + menuItem = new JMenuItem("Remove"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK)); + menuItem.setMnemonic(KeyEvent.VK_R); + menuItem.addActionListener(this); + fileMenu.add(menuItem); + + fileMenu.addSeparator(); + + menuItem = new JMenuItem("Exit"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.ALT_MASK)); + menuItem.setMnemonic(KeyEvent.VK_X); + menuItem.addActionListener(this); + fileMenu.add(menuItem); + + /*------------------------ Document menu ---------------------------------*/ + + // Create the Document menu + docMenu = new JMenu("Document"); + docMenu.setMnemonic(KeyEvent.VK_D); + + // Add the Document Menu to the menu bar + menuBar.add(docMenu); + + // Create a few items to add to the document menu + menuItem = new JMenuItem("First Document"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK)); + menuItem.setMnemonic(KeyEvent.VK_D); + menuItem.addActionListener(this); + docMenu.add(menuItem); + + menuItem = new JMenuItem("Last Document"); + menuItem.addActionListener(this); + menuItem.setEnabled(false); + docMenu.add(menuItem); + + menuItem = new JMenuItem("Next Document"); + menuItem.addActionListener(this); + menuItem.setEnabled(false); + docMenu.add(menuItem); + + menuItem = new JMenuItem("Open Document"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); + menuItem.setMnemonic(KeyEvent.VK_O); + menuItem.addActionListener(this); + docMenu.add(menuItem); + + docMenu.addSeparator(); + + menuItem = new JMenuItem("Create Document"); + menuItem.addActionListener(this); + docMenu.add(menuItem); + + docMenu.addSeparator(); + + menuItem = new JMenuItem("Delete Document"); + menuItem.addActionListener(this); + menuItem.setEnabled(false); + docMenu.add(menuItem); + + docMenu.addSeparator(); + + menuItem = new JMenuItem("Import Document(s)"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK)); + menuItem.setMnemonic(KeyEvent.VK_I); + menuItem.addActionListener(this); + docMenu.add(menuItem); + + docMenu.addSeparator(); + + menuItem = new JMenuItem("Close Document"); + menuItem.addActionListener(this); + docMenu.add(menuItem); + + /*---------------- Transaction Menu ----------------------*/ + // Create the Transaction menu + transMenu = new JMenu("Transaction"); + transMenu.setMnemonic(KeyEvent.VK_T); + + // Add the transaction Menu to the menu bar + menuBar.add(transMenu); + + // Create a few items to add to the transaction menu + menuItem = new JMenuItem("Begin Transaction"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK)); + menuItem.setMnemonic(KeyEvent.VK_B); + menuItem.addActionListener(this); + transMenu.add(menuItem); + + menuItem = new JMenuItem("Commit Transaction"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); + menuItem.setMnemonic(KeyEvent.VK_C); + menuItem.addActionListener(this); + transMenu.add(menuItem); + + menuItem = new JMenuItem("Abort Transaction"); + menuItem.setAccelerator( + KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); + menuItem.setMnemonic(KeyEvent.VK_A); + menuItem.addActionListener(this); + transMenu.add(menuItem); + + + return menuBar; + + } + + /*========================================================================= + * Desc: Method to choose and open a database. + *========================================================================*/ + private void openDatabase() + { + String sDatabaseName = null; + String sDirectory = null; + JFileChooser fileChooser = new JFileChooser(); + XFileFilter dbFilter = new XFileFilter(".db"); + + fileChooser.setFileFilter(dbFilter); + fileChooser.setCurrentDirectory(new File(m_sDirectory)); + fileChooser.setDialogTitle("Open Database"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + + if (fileChooser.showDialog(null, "Open Database") == JFileChooser.APPROVE_OPTION) + { + try + { + sDatabaseName = new String(fileChooser.getSelectedFile().getPath()); + sDirectory = new String(fileChooser.getCurrentDirectory().getPath()); + + if (m_jDb != null) + { + closeDatabase(); + } + + // If this fails, we will throw an exception. + m_jDb = m_dbSystem.dbOpen(sDatabaseName, null, null, null, true); + m_status.setDatabasePath(sDatabaseName); + m_status.setDatabaseOpen(true); + m_sDatabaseName = sDatabaseName; + m_sDirectory = sDirectory; + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + + /*========================================================================= + * Desc: Method to close the current database. + *========================================================================*/ + private void closeDatabase() + { + if (m_jDb == null) + { + return; + } + + // Make sure we clear out the document list. + if (m_mainDisplay.getComponentCount() > 0) + { + closeAllDocuments(); + } + + m_jDb.close(); + m_jDb = null; + m_status.setDatabaseOpen(false); + m_status.setDatabasePath(null); + m_status.setDocId(-1); + m_status.setNodeId(-1); + m_sDatabaseName = null; + if (m_selected != null) + { + m_selected.deselectNode(); + m_selected = null; + } +// m_iCurrentNode = NO_NODES; + m_iLastNode = NO_NODES; + + m_status.m_iCurrentNode = NO_NODES; + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + + updateDisplay(); + + } + + /*========================================================================= + * Desc: Method to close the current database. + *========================================================================*/ + private void createDatabase() + { + String sDatabaseName = null; + String sDirectory = null; + JFileChooser fileChooser = new JFileChooser(); + XFileFilter dbFilter = new XFileFilter(".db"); + + fileChooser.setFileFilter(dbFilter); + fileChooser.setCurrentDirectory(new File(m_sDirectory)); + fileChooser.setDialogTitle("Create Database"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + + if (fileChooser.showDialog(null, "Create Database") == JFileChooser.APPROVE_OPTION) + { + sDatabaseName = new String( fileChooser.getSelectedFile().getPath()); + sDirectory = new String( fileChooser.getCurrentDirectory().getPath()); + + try + { + if (m_jDb != null) + { + closeDatabase(); + } + + // If this fails, we will throw an exception. + m_jDb = m_dbSystem.dbCreate( sDatabaseName, "", "", "", "", null); + + m_status.setDatabasePath(sDatabaseName); + m_status.setDatabaseOpen(true); + m_sDatabaseName = sDatabaseName; + m_sDirectory = sDirectory; + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + + /*========================================================================= + * Desc: Method to delete document node. + *========================================================================*/ + private void deleteNode( + NodePanel np) + { + DOMNode jNode = null; + boolean bTransBegun = false; + Document doc = null; + boolean bIsRoot = false; + String sMessage; + long lDocId; + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), null); + lDocId = np.getDocId(); + + // Check to see if this is a root node. Ultimately we will call delete document + // to handle it. + if (np.getNodeId() == lDocId) + { + bIsRoot = true; + doc = new Document("<" + jNode.getLocalName() + ">", + np.getDocId(), + np.getCollection()); + } + + if (jNode.getNodeType() == FlmDomNodeType.DATA_NODE) + { + sMessage = new String("Delete data node"); + } + else if (bIsRoot) + { + sMessage = new String("Delete document: <" + jNode.getLocalName() + ">"); + } + else + { + sMessage = new String("Delete node: <" + jNode.getLocalName() + ">"); + } + + if (JOptionPane.showConfirmDialog( + this, + sMessage) == JOptionPane.OK_OPTION) + { + boolean bHasNextSibling = false; + + + // Check for a next sibling. + if (jNode.hasNextSibling()) + { + try + { + DOMNode jNext = jNode.getNextSibling(null); + bHasNextSibling = true; + // This is here to silence the warning that jNext is never read. + if (jNext != null) + { + jNext = null; + } + } + catch (XFlaimException e) + { + // Ignore this. + } + } + + // Collapse the current row. + if (np.isExpanded()) + { + collapseNode(np); + } + + // Begin a transaction + if (!m_status.getTransaction()) + { + m_jDb.transBegin(TransactionType.UPDATE_TRANS, 0, 0); + bTransBegun = true; + } + + // Delete the node. + jNode.deleteNode(); + + // Commit + if (bTransBegun) + { + m_jDb.transCommit(); + bTransBegun = false; + } + + // Remove the current node from the display + removeRow(np.getRow()); + + // If the new row is a parent, then we need to collapse it so + // the display looks ok. + if (!bHasNextSibling) + { + if (np.isExpanded() && lDocId == np.getDocId()) + { + collapseNode(np); + } + } + + m_status.setDocId(np.getDocId()); + m_status.setNodeId(np.getNodeId()); + + if (bIsRoot) + { + m_vDocList.remove(doc); + } + } + } + catch(XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + finally + { + if (bTransBegun) + { + try + { + m_jDb.transAbort(); + } + catch (XFlaimException ex) + { + // ignore this one. + } + } + } + } + + /*========================================================================= + * Desc: Method to remove (delete) a database. + *========================================================================*/ + private void removeDatabase() + { + String sDatabaseName = m_sDatabaseName; + + // If there is already an open database close it. + if (sDatabaseName != null) + { + closeDatabase(); + } + else + { + // We need to choose a database to remove. + JFileChooser fileChooser = new JFileChooser(); + XFileFilter dbFilter = new XFileFilter(".db"); + + fileChooser.setFileFilter(dbFilter); + fileChooser.setCurrentDirectory(new File(m_sDirectory)); + fileChooser.setDialogTitle("Remove Database"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + + if (fileChooser.showDialog(null, "Remove Database") == JFileChooser.APPROVE_OPTION) + { + sDatabaseName = new String( fileChooser.getSelectedFile().getPath()); + + if (m_jDb != null) + { + closeDatabase(); + } + } + } + + if (sDatabaseName != null) + { + // If this fails, we will throw an exception. + try + { + m_dbSystem.dbRemove( sDatabaseName, "", "", true); + } + catch (XFlaimException e) + { + JOptionPane.showConfirmDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + + /*========================================================================= + * Desc: Method to choose and import a document or directory into the current database. + *========================================================================*/ + private void importDocument() + { + String sDirectory = null; + JFileChooser fileChooser = new JFileChooser(); + XFileFilter xmlFilter = new XFileFilter(".xml"); + int iCollection; + + // Make sure we have a database open. + if (!m_status.getDatabaseOpen()) + { + JOptionPane.showMessageDialog(this, "There is no open database. Import operation failed."); + return; + } + + fileChooser.setFileFilter(xmlFilter); + fileChooser.setCurrentDirectory(new File(m_sDirectory)); + fileChooser.setDialogTitle("Import XML File or Directory"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + + if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) + { + sDirectory = new String( fileChooser.getCurrentDirectory().getPath()); + iCollection = selectCollection(); + if (iCollection == 0) + { + // Cancelled! + return; + } + + try + { + FileImporter fi = new FileImporter( + this, + m_dbSystem, + m_sDatabaseName, + iCollection, + new String( fileChooser.getSelectedFile().getPath()), + sDirectory, + fileChooser.getSelectedFile().list()); + fi.start(); + + // Save the last selected directory. + m_sDirectory = sDirectory; + } + catch (XFlaimException e) + { + JOptionPane.showConfirmDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + + + /*========================================================================= + * Desc: Method to retrieve the first document from the database. + *========================================================================*/ + private void getFirstDocument() + { + DOMNode jDoc = null; + int iCollection; + + if (m_status.getDatabaseOpen()) + { + // Need to get the collection. + iCollection = selectCollection(); + if (iCollection > 0) + { + try + { + jDoc = m_jDb.getFirstDocument(iCollection, null); + m_vDocList.add(new Document("<" + jDoc.getLocalName() + ">", + jDoc.getNodeId(), + iCollection)); + if (m_iLastNode < LAST_NODE) + { + NodePanel np = (NodePanel)m_vNodeList.get(++m_iLastNode); + np.buildLabel( jDoc, false, false, m_bDocList); + expandNode(np, true); + + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + + if (m_selected == null) + { + selectNode(np); + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + else + { + // Put up a dialog to indicate that there is no database open yet. + JOptionPane.showMessageDialog( + this, + "Cannot retrieve a document - no open database.", + "Incomplete Operation", + JOptionPane.INFORMATION_MESSAGE); + } + } + + /*========================================================================= + * Desc: Method to present a list of documents to open. + *========================================================================*/ + private void openDocument() + { + if (m_status.getDatabaseOpen()) + { + // Need to get the collection. + int iCollection = selectCollection(); + if (iCollection > 0) + { + selectDocument(iCollection); + } + } + else + { + // Put up a dialog to indicate that there is no database open yet. + JOptionPane.showMessageDialog( + this, + "Cannot retrieve a document - no open database.", + "Incomplete Operation", + JOptionPane.INFORMATION_MESSAGE); + } + } + + /*========================================================================= + * Desc: Method to a document of choice from the database. + *========================================================================*/ + private void openDocument( + int iCollection, + long lDocId) + { + DOMNode jDoc = null; + + try + { + if (lDocId > 0) + { + jDoc = m_jDb.getNode(iCollection, lDocId, null); + m_vDocList.add(new Document("<" + jDoc.getLocalName() + ">", + jDoc.getNodeId(), + iCollection)); + if (m_iLastNode < LAST_NODE) + { + NodePanel np = (NodePanel)m_vNodeList.get(++m_iLastNode); + np.buildLabel(jDoc, false, false, m_bDocList); + expandNode(np, true); + + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + + if (m_selected == null) + { + selectNode(np); + } + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred:" + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + + + /*========================================================================= + * Desc: Method to close the document of choice. + *========================================================================*/ + private void closeDocument() + { + int iItem; + boolean bDocFound = false; + + if (m_vDocList.size() > 1) + { + // Need to select the document to close. + iItem = selectDocumentFromList(); + if (iItem >= 0) + { + Document doc = (Document)m_vDocList.get(iItem); + + // Find the root document node and remove it. + for (int i = 0; i <= m_iLastNode; i++) + { + NodePanel np = (NodePanel)m_vNodeList.get(i); + if (np.getDocId() == doc.m_lDocId) + { + closeDocument(np); + bDocFound = true; + break; + } + } + + // The document may not have been visible on the screen, so we must remove it + // from the document list. + if (!bDocFound) + { + m_vDocList.removeElementAt(iItem); + } + } + } + else + { + if (m_vDocList.size() == 1) + { + closeAllDocuments(); + } + } + updateDisplay(); + } + + /*========================================================================= + * Desc: Method to close the document owned by the node panel passed in. + *========================================================================*/ + private void closeDocument( + NodePanel np) + { + int iRow = np.getRow(); + int iItem; + + try + { + DOMNode jNode = m_jDb.getNode( np.getCollection(), np.getNodeId(), null); + Document doc = new Document("<" + jNode.getLocalName() + ">", + np.getDocId(), + np.getCollection()); + + iItem = m_vDocList.indexOf(doc); + if (iItem >= 0) + { + // Now let's clean up the display. + // First, if the document is expanded, we need to collapse it. + if (np.isExpanded()) + { + collapseNode(np); + } + + m_vDocList.removeElementAt(iItem); + + removeRow(iRow); + + if (m_vDocList.size() == 0) + { + m_status.setDocId(0); + m_status.setNodeId(0); + } + + if (m_selected != null) + { + selectNode(m_selected); + } + } + else + { + JOptionPane.showMessageDialog( + this, + "Failed to close current document: Document not found", + "Document Not Closed", + JOptionPane.WARNING_MESSAGE); + } + + + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + + /*========================================================================= + * Desc: Method to close all documents + *========================================================================*/ + private void closeAllDocuments() + { + for (int i= FIRST_NODE; i <= LAST_NODE; i++) + { + NodePanel np = (NodePanel)m_vNodeList.get(i); + np.reset(); + } + m_vDocList.removeAllElements(); +// m_iCurrentNode = NO_NODES; + m_iLastNode = NO_NODES; + m_selected = null; + m_status.m_iCurrentNode = NO_NODES; + m_status.m_iLastNode = m_iLastNode; + m_status.setDocId(0); + m_status.setNodeId(0); + } + + /*========================================================================= + * Desc: Method to select the collection + *========================================================================*/ + private int selectCollection() + { + Collection coll = new Collection("invalid", 0); + CollectionSelector CS = new CollectionSelector(this, m_dbSystem, m_jDb, coll); + CS.dispose(); + + return coll.m_iNumber; + } + + /*========================================================================= + * Desc: Method to select document + *========================================================================*/ + private void selectDocument( + int iCollection + ) + { + Document doc = null; + Thread t = null; + + doc = new Document("invalid", 0, 0); + XEdit DS = new XEdit(this, "Document Selector", m_jDb, iCollection, doc); + GraphicsConfiguration gc = getGraphicsConfiguration(); + Rectangle bounds = gc.getBounds(); + int iHeight = getHeight(); + int iWidth = getWidth(); + DS.setLocation(Math.max(0, (bounds.width - iWidth)/2), + Math.max(0, (bounds.height - iHeight)/2)); + t = new Thread((Runnable)DS); + t.start(); + } + + /*========================================================================= + * Desc: Method to select document from the list of open documents. + *========================================================================*/ + private int selectDocumentFromList() + { + OpenDocumentSelector ods = new OpenDocumentSelector( this, m_vDocList); + return ods.showDialog(); + } + + // Default protection means the package can see this method. + void updateDisplay() + { + setContentPane(m_mainPanel); + } + + // Service method to compare a JPanel object to the main panel + boolean isMainPanel( + JPanel panel) + { + if (panel == m_mainDisplay) + { + return true; + } + else + { + return false; + } + } + + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) + */ + public void mouseClicked(MouseEvent e) + { + NodePanel np = null; + + np = (NodePanel)e.getSource(); + + selectNode(np); + + if (e.getClickCount() == 1 && !m_bDocList) + { + if (e.getButton() == MouseEvent.BUTTON1) + { + if (np.isExpanded()) + { + collapseNode(np); + } + else + { + expandNode(np, false); + } + } + else if (e.getButton() == MouseEvent.BUTTON3) + { + JMenuItem menuItem = null; + DOMNode jNode = null; + + if (m_status.getDatabaseOpen()) + { + try + { + jNode = m_jDb.getNode( + np.getCollection(), + np.getNodeId(), + jNode); + + // popup the document menu. + m_popup = new JPopupMenu("Document Node Options"); + if (np.getDocId() != NO_NODES) + { + if (np.getDocId() == np.getNodeId()) + { + menuItem = m_popup.add("Close Document"); + menuItem.addActionListener(this); + m_popup.addSeparator(); + } + + if (np.hasChildren()) + { + if (np.isExpanded()) + { + menuItem = m_popup.add("Collapse Node"); + } + else + { + menuItem = m_popup.add("Expand Node"); + } + menuItem.addActionListener(this); + m_popup.addSeparator(); + } + + // Make a sub-menu for the delete + JMenu delMenu = new JMenu("Delete"); + + menuItem = delMenu.add("Delete Node"); + menuItem.addActionListener(this); + menuItem = delMenu.add("Delete Attribute"); + menuItem.addActionListener(this); + if (!jNode.hasAttributes()) + { + menuItem.setEnabled(false); + } + menuItem = delMenu.add("Delete Annotation"); + menuItem.addActionListener(this); + if (!jNode.hasAnnotation()) + { + menuItem.setEnabled(false); + } + m_popup.add(delMenu); + + menuItem = m_popup.add("Add Node"); + menuItem.addActionListener(this); + + // Need to make the edit sub-menu. + JMenu editMenu = new JMenu("Edit Node"); + menuItem = editMenu.add("Edit Value"); + // Test for a value + try + { + String sValue = jNode.getString(); + if (sValue.length() == 0) + { + menuItem.setEnabled(false); + } + } + catch (XFlaimException ee) + { + menuItem.setEnabled(false); + } + menuItem.addActionListener(this); + menuItem = editMenu.add("Edit Attribute"); + if (!jNode.hasAttributes()) + { + menuItem.setEnabled(false); + } + menuItem.addActionListener(this); + menuItem = editMenu.add("Edit Annotation"); + if (!jNode.hasAnnotation()) + { + menuItem.setEnabled(false); + } + menuItem.addActionListener(this); + m_popup.add(editMenu); + } + else + { + menuItem = m_popup.add("Add Document"); + menuItem.addActionListener(this); + menuItem.setEnabled(false); + } + } + catch (XFlaimException ex) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + ex.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + + // Need to make sure the menu appears close to where our window is located. + Point p = e.getPoint(); + Point p1 = np.getLocation(); + m_popup.show(this, p1.x + p.x, p1.y + p.y); + } + } + } + + if (e.getClickCount() == 2) + { + if (e.getButton() == MouseEvent.BUTTON1) + { + // Are we selecting a document? + if (m_bDocList) + { + m_doc.m_iCollection = np.getCollection(); + m_doc.m_lDocId = np.getDocId(); + try + { + DOMNode jDoc = m_jDb.getNode(m_doc.m_iCollection, m_doc.m_lDocId, null); + m_doc.m_sName = "<" + jDoc.getLocalName() + ">"; + if (m_parent != null) + { + // Open the document in the parent + m_parent.openDocument(m_doc.m_iCollection, m_doc.m_lDocId); + this.dispose(); + } + } + catch (XFlaimException ex) + { + JOptionPane.showMessageDialog( + this, + "Database Exception ocurred: " + ex.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + } + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) + */ + public void mouseEntered(MouseEvent e) + { + // Do nothing. + + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) + */ + public void mouseExited(MouseEvent e) + { + // Do Nothing + + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) + */ + public void mousePressed(MouseEvent e) + { + // Do Nothing + + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) + */ + public void mouseReleased(MouseEvent e) + { + // Do Nothing + + } + + /* (non-Javadoc) + * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) + */ + public void keyPressed(KeyEvent e) + { + // Do Nothing + + } + + /* (non-Javadoc) + * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) + */ + public void keyReleased(KeyEvent e) + { + int key = e.getKeyCode(); + + if (m_vDocList.isEmpty() && !m_bDocList) + { + return; + } + + switch (key) + { + case KeyEvent.VK_KP_UP: + case KeyEvent.VK_UP: + { + moveUp(); + break; + } + case KeyEvent.VK_KP_DOWN: + case KeyEvent.VK_DOWN: + { + moveDown(); + break; + } + case KeyEvent.VK_PAGE_UP: + { + pageUp(); + break; + } + case KeyEvent.VK_PAGE_DOWN: + { + pageDown(); + break; + } + case KeyEvent.VK_KP_RIGHT: + case KeyEvent.VK_RIGHT: + { + // Expand. + if (!m_selected.isExpanded()) + { + expandNode(m_selected, false); + } + break; + } + case KeyEvent.VK_KP_LEFT: + case KeyEvent.VK_LEFT: + { + // Collapse + if (m_selected.isExpanded()) + { + collapseNode(m_selected); + } + break; + } + case KeyEvent.VK_ENTER: + { + // Are we selecting a document? + if (m_bDocList) + { + m_doc.m_iCollection = m_selected.getCollection(); + m_doc.m_lDocId = m_selected.getDocId(); + try + { + DOMNode jDoc = m_jDb.getNode(m_doc.m_iCollection, m_doc.m_lDocId, null); + m_doc.m_sName = "<" + jDoc.getLocalName() + ">"; + if (m_parent != null) + { + // Open the document in the parent + m_parent.openDocument(m_doc.m_iCollection, m_doc.m_lDocId); + this.dispose(); + } + } + catch (XFlaimException ex) + { + JOptionPane.showMessageDialog( + this, + "Database Exception ocurred: " + ex.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + } + + } + + /** + * + */ + private void moveUp() + { + if (m_selected == null) + { + // First row not set yet. + return; + } + + if (m_selected.getRow() > 0) + { + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow() - 1)); + } + else + { + // We are going to have to move eveyone down one row first. + // Then get the previous row. + if (scrollUp()) + { + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow() - 1)); + } + } + } + + /** + * + */ + private boolean scrollUp() + { + NodePanel npTo; + NodePanel npFrom; + + if (m_selected == null) + { + return false; + } + + if (hasPreviousNode()) + { + for (int i = LAST_NODE; i > 0; --i) + { + npTo = (NodePanel)m_vNodeList.get(i); + npFrom = (NodePanel)m_vNodeList.get(i - 1); + npTo.copyNode(npFrom); + } + + // Move the selected Node down one row too. + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow() + 1)); + + // Now we need to get the previous row. Due to the way this is + // architected, we should be looking at the currently selected row + // to determine the previous row. The currently selected row is supposed to + // be the second row now. If there isn't a previous row, we will get a false + // return value. + if (!m_bDocList) + { + return(getPrevNode()); + } + else + { + return(getPrevDocument()); + } + } + else + { + return false; + } + } + + /** + * @return + */ + private boolean hasPreviousNode() + { + NodePanel np = m_selected; // Should be the first row, i.e. row 0. + DOMNode jNode = null; + Document doc = null; + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getDocId(), null); + + if (!m_bDocList) + { + // With a standard XEdit, we check to see if we have another open + // document. + doc = new Document("<" + jNode.getLocalName() + ">", + np.getDocId(), + np.getCollection()); + + // If we're looking at the root node, then we need to find out if there + // is another document to view previous to this one. + if (np.getDocId() == np.getNodeId() && !np.isClosing()) + { + if (m_vDocList.indexOf(doc) > 0) + { + return true; + } + else + { + return false; + } + } + else + { + return true; + } + } + else + { + // With a DocList, we check to see if there is a previous document. + try + { + jNode = jNode.getPreviousDocument(jNode); + return true; + } + catch (XFlaimException ex) + { + if (ex.getRCode() == RCODE.NE_XFLM_DOM_NODE_NOT_FOUND) + { + return false; + } + else + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + ex.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return false; + } + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return false; + } + + } + + /** + * Fetch the previous node relative to the selected row. Typically, the + * currently selected row is row 0 when this method is invoked. + * + * @return boolean, signals whether the previous node was found or not. + */ + private boolean getPrevNode() + { + NodePanel np = m_selected; + int iSelectedRow = np.getRow(); + DOMNode jNode = null; + Document doc = null; + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), null); + + if (np.isClosing()) + { + // See if we can get a child node + if (jNode.hasChildren()) + { + jNode = jNode.getLastChild(jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow - 1); + np.reset(); + np.buildLabel(jNode, true, false, m_bDocList); + return true; + } + } + + // Check for a previous sibling. + try + { + jNode = jNode.getPreviousSibling(jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow - 1); + np.reset(); + np.buildLabel(jNode, true, jNode.hasChildren() ? true : false, m_bDocList); + return true; + } + catch (XFlaimException e) + { + // Do nothing, we just want to make sure we catch it. + } + + // Check for a parent. + if (np.getNodeId() != np.getDocId()) + { + jNode = jNode.getParentNode(jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow - 1); + np.reset(); + np.buildLabel(jNode, true, false, m_bDocList); + return true; + } + + // Is there a previous document to get? + doc = new Document("<" + jNode.getLocalName() + ">", + np.getDocId(), + np.getCollection()); + int iIndex = m_vDocList.indexOf(doc); + if (iIndex > 0) + { + doc = (Document)m_vDocList.get(iIndex - 1); + jNode = m_jDb.getNode(doc.m_iCollection, doc.m_lDocId, jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow - 1); + np.reset(); + np.buildLabel(jNode, true, true, m_bDocList); + return true; + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return false; + } + + return false; + } + + /** + * + */ + private void pageDown() + { + // Move down one full page worth. The moveDown + // method will stop if we run out of nodes to scroll to. + for (int i = 0; i < LAST_NODE; i++) + { + moveDown(); + } + + } + + /** + * + */ + private void pageUp() + { + // Move up one full page worth. The moveUp method + // will stop if we reach the top. + for (int i = 0; i < LAST_NODE; i++) + { + moveUp(); + } + + } + + /** + * + */ + private void moveDown() + { + if (m_selected == null) + { + return; + } + + if (m_selected.getRow() < m_iLastNode) + { + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow()+ 1)); + } + else + { + // We are going to have to move eveyone up one row first. + // Then get the next row. + if (scrollDown()) + { + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow() + 1)); + } + } + } + + /** + * Scroll the screen down one row. This will pick up the + * next row from off the screen if there is one. + * @return + */ + private boolean scrollDown() + { + NodePanel npTo; + NodePanel npFrom; + + if (m_selected == null) + { + return false; + } + else + { + if (hasNextNode()) + { + for (int i = 0; i < LAST_NODE; i++) + { + npTo = (NodePanel)m_vNodeList.get(i); + npFrom = (NodePanel)m_vNodeList.get(i + 1); + npTo.copyNode(npFrom); + } + + // Backup one row and select it. + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow() - 1)); + + // Now we need to get the next row. Due to the way this is + // architected, we should be looking at the currently selected row + // to determine the next row. The currently selected row is supposed to + // be the next to last row now. If there isn't a next row, we will get a false + // return value. + if (!m_bDocList) + { + return(getNextNode(true)); + } + else + { + return(getNextDocument()); + } + } + else + { + return false; + } + } + + } + + /** + * @return + */ + private boolean hasNextNode() + { + NodePanel np = m_selected; + DOMNode jNode = null; + Document doc = null; + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getDocId(), null); + + if (!m_bDocList) + { + // Standard XEdit - build a Document object to compare with. + doc = new Document("<" + jNode.getLocalName() + ">", + np.getDocId(), + np.getCollection()); + + // If we're looking at the root node, then we need to find out if there + // is another document to view after this one. + if (np.getDocId() == np.getNodeId() && + (np.isClosing() || !np.isExpanded())) + { + int i = m_vDocList.indexOf(doc); + if (i >= 0 && i < m_vDocList.size() - 1) + { + return true; + } + else + { + return false; + } + } + else + { + return true; + } + } + else + { + // This XEdit is a document list, so just see if we can get a next document. + try + { + jNode = jNode.getNextDocument(jNode); + return true; + } + catch (XFlaimException ex) + { + if (ex.getRCode() == RCODE.NE_XFLM_DOM_NODE_NOT_FOUND) + { + return false; + } + else + { + JOptionPane.showMessageDialog( + this, + "Database Exception Occurred" + ex.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return false; + } + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return false; + } + + } + + /** + * Fetch the next node, relative to the currently selected node. This may + * be the first child node, or the next sibling node, the parent node or the + * root node of the next document. If bStartAtChild is false, it will + * skip looking for the first child node. + * + * @param bStartAtChild boolean parameter to signal whether to look for the + * first child or not. + * + * @return boolean - next node found or not found. + */ + private boolean getNextNode( + boolean bStartAtChild) + { + NodePanel np = m_selected; + int iSelectedRow = np.getRow(); + DOMNode jNode = null; + Document doc = null; + + try + { + jNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), jNode); + + if (bStartAtChild && !np.isClosing() && np.isExpanded()) + { + // See if we can get a child node + if (jNode.hasChildren()) + { + jNode = jNode.getFirstChild(jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow + 1); + np.reset(); + np.buildLabel(jNode, true, false, m_bDocList); + return true; + } + } + + // Check for a next sibling. + try + { + jNode = jNode.getNextSibling(jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow + 1); + np.reset(); + np.buildLabel(jNode, true, false, m_bDocList); + return true; + } + catch (XFlaimException e) + { + // Do nothing, we just want to make sure we catch it. + } + + // Check for a parent. + if (np.getNodeId() != np.getDocId()) + { + jNode = jNode.getParentNode(jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow + 1); + np.reset(); + np.buildLabel(jNode, true, true, m_bDocList); + return true; + } + + // Is there a next document to get? + doc = new Document("<" + jNode.getLocalName() + ">", + np.getDocId(), + np.getCollection()); + int iIndex = m_vDocList.indexOf(doc); + if (iIndex < m_vDocList.size() - 1) + { + doc = (Document)m_vDocList.get(iIndex + 1); + jNode = m_jDb.getNode(doc.m_iCollection, doc.m_lDocId, jNode); + np = (NodePanel)m_vNodeList.get(iSelectedRow + 1); + np.reset(); + np.buildLabel(jNode, true, false, m_bDocList); + return true; + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + return false; + } + + return false; + + } + + /* (non-Javadoc) + * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) + */ + public void keyTyped(KeyEvent e) + { + // Do nothing + } + + /*------------------------------------------------------------------------- + * Desc: Method to highlight a row given the NodePanel. + *-----------------------------------------------------------------------*/ + private void selectNode( + NodePanel np) + { + long lDocId; + long lNodeId; + + // Don't select anything if the NodePanel does not have a document + // that is displaying. + if (np.getDocId() == NO_NODES) + { + return; + } + + if (m_selected != null) + { + m_selected.deselectNode(); + } + + m_selected = np; + m_selected.selectNode(); + m_status.m_iCurrentNode = m_selected.getRow(); + lDocId = np.getDocId(); + m_status.setDocId(lDocId); + lNodeId = np.getNodeId(); + m_status.setNodeId(lNodeId); + } + + /*------------------------------------------------------------------------- + * Desc: Method to expand a node one level given the NodePanel. + *-----------------------------------------------------------------------*/ + private void expandNode( + NodePanel np, + boolean bDeep) + { + DOMNode refNode; + DOMNode childNode = null; + boolean bFirst = true; + + m_iExpandedRow = np.getRow(); + + if (!np.hasChildren()) + { + return; + } + + if (np.isClosing()) + { + return; + } + + try + { + refNode = m_jDb.getNode(np.getCollection(), np.getNodeId(), null); + np.buildLabel(refNode, true, false, m_bDocList); + + for (;m_iExpandedRow < LAST_NODE;) + { + if (bFirst) + { + bFirst = false; + childNode = refNode.getFirstChild(null); + } + else + { + try + { + childNode = childNode.getNextSibling(childNode); + } + catch (XFlaimException e) + { + if (e.getRCode() == RCODE.NE_XFLM_DOM_NODE_NOT_FOUND) + { + break; + } + else + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + } + + insertRow(++m_iExpandedRow, childNode, bDeep, false); + if (bDeep) + { + expandNode((NodePanel)m_vNodeList.get(m_iExpandedRow), bDeep); + } + + } + + // See if we have room to put in a closing row. + if (m_iExpandedRow + 1 <= LAST_NODE) + { + insertRow(++m_iExpandedRow, refNode, true, true); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + + /*------------------------------------------------------------------------- + * Desc: Method to collapse a node given the NodePanel. This could result + * in multiple levels being collapsed. + *-----------------------------------------------------------------------*/ + private void collapseNode( + NodePanel np) + { + int iOpeningRow; + int iClosingRow = -1; + long lNodeId; + NodePanel npOpening = np; + NodePanel npClosing = null; + int iCollection; + boolean bHasClosing = false; + + if (!np.isExpanded() || !np.hasChildren()) + { + return; + } + + lNodeId = np.getNodeId(); + iCollection = np.getCollection(); + + try + { + DOMNode refNode = m_jDb.getNode(iCollection, lNodeId, null); + if (np.isClosing()) + { + bHasClosing = true; + npClosing = np; + iClosingRow = np.getRow(); + + // Locate the opening instance of this node, if it is present on + // the screen. If it can't be found on the screen, this node will + // become the opening node and will be displayed as the first row + // on the screen. + iOpeningRow = iClosingRow - 1; + while (iOpeningRow >= 0) + { + npOpening = (NodePanel)m_vNodeList.get(iOpeningRow); + if (npOpening.getNodeId() == lNodeId) + { + break; + } + --iOpeningRow; + } + } + else + { + npOpening = np; + iOpeningRow = np.getRow(); + } + + // Can we short circuit the process by checking for the root node? + //if (lNodeId == np.getDocId()) + //{ + // collapseDocument(npOpening); + // return; + //} + + // Find the closing node. + if (!bHasClosing) + { + for (iClosingRow = iOpeningRow + 1; + iClosingRow <= m_iLastNode; + iClosingRow++) + { + npClosing = (NodePanel)m_vNodeList.get(iClosingRow); + if (npClosing.getNodeId() == lNodeId) + { + bHasClosing = true; + break; + } + } + } + + if (!bHasClosing) + { + clearNodes(npOpening.getRow() + 1, m_iLastNode); + + // When we build this node, we must first set the closing as true + // so we can check for another node. We will rebuild it again + // when we finish. + npOpening.buildLabel(refNode, false, false, m_bDocList); + + selectNode(npOpening); + m_iLastNode = npOpening.getRow(); + m_status.m_iCurrentNode = m_iLastNode; + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + + // If we have just collapsed the last row, there is no need to get another row. + if (m_iLastNode < LAST_NODE) + { + if (getNextNode(false)) + { + m_iLastNode++; + m_status.m_iLastNode = m_iLastNode; + + // Need to expand the new document that just got exposed. + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow() + 1)); // Will get reset on the way out. + m_status.m_iCurrentNode = m_selected.getRow(); + m_status.updateLabel(); + np = m_selected; + // Cannot expand the closing node of a document. + if (np.isClosing()) + { + if (m_iLastNode < LAST_NODE && getNextNode(false)) + { + m_iLastNode++; + selectNode((NodePanel)m_vNodeList.get(m_selected.getRow() + 1)); + m_status.m_iCurrentNode = m_selected.getRow(); + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + + expandNode(m_selected, true); + } + } + else + { + expandNode(m_selected, true); + } + + selectNode(npOpening); + + } + } + } + else // Have a closing node + { + // If we have an opening node, then we need to redraw it first, + // before we collapse the rest. + if (iOpeningRow >= 0) + { + npOpening.buildLabel(refNode, false, false, m_bDocList); + } + + // We need to remove rows one at a time until we get to the closing row. + for (int i = iOpeningRow + 1; (iOpeningRow >= 0) ? i <= iClosingRow : i < iClosingRow; i++) + { + removeRow(iOpeningRow+1); + } + + // If we did not have an opening row, we need to build the row now. + if (iOpeningRow < 0) + { + npOpening.buildLabel(refNode, false, false, m_bDocList); + } + + selectNode(npOpening); + + if (m_iLastNode < npOpening.getRow()) + { + m_iLastNode = npOpening.getRow(); + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + } + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + + } + + /*------------------------------------------------------------------------- + * Desc: Method to collapse a document given the root NodePanel. + *-----------------------------------------------------------------------*/ +/* + private void collapseDocument( + NodePanel npDoc) + { + DOMNode docNode; + + try + { + docNode = m_jDb.getNode(npDoc.getCollection(), npDoc.getDocId(), null); + + clearNodes(npDoc.getRow() + 1, m_iLastNode); + + // When we build this node, we must first set the closing as true + // so we can check for another document. We will rebuid it again + // when we finish. + npDoc.buildLabel(docNode, false, true); + + selectNode(npDoc); + m_iLastNode = m_iCurrentNode; + + if (getNextNode(false)) + { + // Need to expand the new document that just got exposed. + m_iCurrentNode++; // Will get reset on the way out. + expandNode((NodePanel)m_vNodeList.get(m_iCurrentNode), true); + + selectNode(npDoc); // Resets m_iCurrentNode. + + } + npDoc.buildLabel(docNode, false, false); + + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } +*/ + /*------------------------------------------------------------------------- + * Desc: Method to clear the nodes on display within the range specified. + *-----------------------------------------------------------------------*/ + private void clearNodes( + int iFromNode, + int iToNode) + { + if (iFromNode > iToNode) + { + return; + } + + for (int i = iFromNode; i <= iToNode; i++) + { + NodePanel np = (NodePanel)m_vNodeList.get(i); + np.reset(); + } + } + + /*------------------------------------------------------------------------- + * Desc: Method to move a row down one and insert a new row in its place. + *-----------------------------------------------------------------------*/ + private void insertRow( + int iRow, + DOMNode refNode, + boolean bExpanded, + boolean bClosing) + { + NodePanel npCopy = null; + NodePanel npInsert = null; + + // Move them down one row to make room. + for (int i = LAST_NODE; i > iRow; i--) + { + npInsert = (NodePanel)m_vNodeList.get(i); + npCopy = (NodePanel)m_vNodeList.get(i-1); + npInsert.copyNode(npCopy); + } + + // Copy the node that is at the current location into a temporary + // NodePanel. + npInsert = (NodePanel)m_vNodeList.get(iRow); + npCopy = new NodePanel(this, 0); // The row is not copied across NodePanels. + npCopy.copyNode(npInsert); + try + { + npInsert.buildLabel(refNode, bExpanded, bClosing, m_bDocList); + // We cannot hold more than LAST_NODE nodes, so we only increment + // the count till we get there. + if (m_iLastNode < LAST_NODE) + { + m_iLastNode++; + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + } + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + } + + /*------------------------------------------------------------------------- + * Desc: Method to remove a row and move all other rows up one position. + * It will also add a new row to the bottom display if it can. + *-----------------------------------------------------------------------*/ + private void removeRow( + int iRow + ) + { + NodePanel npCopy = null; + NodePanel npInsert = null; + NodePanel np; + NodePanel npSelected = m_selected; + + // Move everybody up one row. + for (int i = iRow; i < LAST_NODE; i++) + { + npInsert = (NodePanel)m_vNodeList.get(i); + npCopy = (NodePanel)m_vNodeList.get(i+1); + npInsert.copyNode(npCopy); + } + + // We have one less node being displayed now. + m_iLastNode--; + m_status.m_iLastNode = m_iLastNode; + + // Clear the last line incase there is nothing left to display. + np = (NodePanel)m_vNodeList.get(m_iLastNode + 1); + np.reset(); + + // Since we have one more row, see if we can expand it. + // Make sure we are looking at a valid row. + if (m_iLastNode >= 0) + { + selectNode((NodePanel)m_vNodeList.get(m_iLastNode)); + } + else + { + m_selected = null; + } + m_status.m_iCurrentNode = m_iLastNode; + m_status.updateLabel(); + + if (m_selected != null) + { + if (getNextNode(true)) + { + m_iLastNode++; + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + } + } + + // If we just removed the first display row and there are no more rows + // to display, then we should clear the currently selected row (node). + if (m_selected != null) + { + selectNode(npSelected); + m_status.m_iCurrentNode = npSelected.getRow(); + m_status.updateLabel(); + } + } + + /*------------------------------------------------------------------------- + * Desc: Method to show the initial document listing. + *-----------------------------------------------------------------------*/ + private boolean showDocumentList() + { + boolean bFirst = true; + DOMNode jDoc = null; + NodePanel np; + int iRow = 0; + + // We will clear the screen first. + clearNodes(0, LAST_NODE); + + try + { + for (iRow = 0; iRow <= LAST_NODE; iRow++) + { + m_status.m_iCurrentNode = iRow; + m_status.updateLabel(); + if (bFirst) + { + bFirst = false; + jDoc = m_jDb.getFirstDocument(m_iCollection, jDoc); + } + else + { + jDoc = jDoc.getNextDocument(jDoc); + } + np = (NodePanel)m_vNodeList.get(iRow); + np.buildLabel(jDoc, false, false, m_bDocList); + + } + m_iLastNode = LAST_NODE; + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + } + catch (XFlaimException e) + { + if (e.getRCode() != RCODE.NE_XFLM_DOM_NODE_NOT_FOUND) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + else + { + if (iRow == 0) + { + return false; + } + else + { + m_iLastNode = iRow - 1; + m_status.m_iLastNode = m_iLastNode; + m_status.updateLabel(); + } + } + } + selectNode((NodePanel)m_vNodeList.get(0)); + m_status.m_iCurrentNode = 0; + m_status.updateLabel(); + + return true; + } + + private boolean getNextDocument() + { + DOMNode jDoc = null; + NodePanel np = m_selected; + int iSelectedRow = np.getRow(); + + try + { + jDoc = m_jDb.getNode(m_iCollection, np.getDocId(), jDoc); + jDoc = jDoc.getNextDocument(jDoc); + insertRow(iSelectedRow + 1, jDoc, false, false); + return true; + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + return false; + } + + private boolean getPrevDocument() + { + DOMNode jDoc = null; + NodePanel np = m_selected; + int iSelectedRow = np.getRow(); + + try + { + jDoc = m_jDb.getNode(m_iCollection, np.getDocId(), jDoc); + jDoc = jDoc.getPreviousDocument(jDoc); + insertRow(iSelectedRow - 1, jDoc, false, false); + return true; + } + catch (XFlaimException e) + { + JOptionPane.showMessageDialog( + this, + "Database Exception occurred: " + e.getMessage(), + "Database Exception", + JOptionPane.ERROR_MESSAGE); + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + public void run() + { + if (m_bMustExit) + { + this.dispose(); + } + else + { + setVisible(true); + } + + } + + /** + * Method to add a new document node to the current database. This method + * assumes that an UPDATE transaction has already been started. If one + * has not been started, an exception will be thrown. + * @param iCollection + * @param iTag + * @param sNodeValue + * @return lDocId The new document root node id. + * @throws XFlaimException + */ + public long addDocument( + int iCollection, + int iTag, + String sNodeValue) throws XFlaimException + { + DOMNode jNode = null; + long lNodeId = 0; + + if (m_status.getTransaction()) + { + + jNode = m_jDb.createRootElement(iCollection, iTag); + + lNodeId = jNode.getNodeId(); + + if (sNodeValue != null && sNodeValue.length() > 0) + { + // Add an annotation note to the document. + jNode.createAnnotation(jNode); + jNode.setString(sNodeValue); + } + } + else + { + JOptionPane.showMessageDialog( + this, + "Illegal State: Action requires Update Transaction", + "Illegal State", + JOptionPane.ERROR_MESSAGE); + } + + return lNodeId; + } + + /** + * Method to add a new node to an existing document, relative to the + * lNodeId parameter. + * @param iCollection + * @param iNodeType + * @param iNodeTag + * @param sNodeValue + * @param bIsSiblingNode + * @param lNodeId + * @return + * @throws XFlaimException + */ + public long addNode( + int iCollection, + int iNodeType, + int iNodeTag, + String sNodeValue, + boolean bIsSiblingNode, + long lNodeId) throws XFlaimException + { + long lAnchorNode = lNodeId; + boolean bIsAttribute = false; + + if (m_status.getTransaction()) + { + DOMNode jNode = m_jDb.getNode( + iCollection, + lNodeId, + null); + + if (iNodeType == FlmDomNodeType.ATTRIBUTE_NODE) + { + jNode = jNode.createAttribute( + iNodeTag, + jNode); + bIsAttribute = true; + } + else + { + if (bIsSiblingNode) + { + // Create the sibling node + jNode = jNode.createNode( + iNodeType, + iNodeTag, + FlmInsertLoc.FLM_NEXT_SIB, + jNode); + } + else + { + jNode = jNode.createNode( + iNodeType, + iNodeTag, + FlmInsertLoc.FLM_LAST_CHILD, + jNode); + } + } + + // Set the value. + if (sNodeValue != null && sNodeValue.length() > 0) + { + jNode.setString(sNodeValue); + } + + if (m_selected != null && + lAnchorNode == m_selected.getNodeId()) + { + // See if we can refresh the selected node/row + NodePanel np = m_selected; + DOMNode jRefNode = m_jDb.getNode( + np.getCollection(), + lAnchorNode, + null); + + if (np.isExpanded() && np.isClosing()) + { + collapseNode(np); + // The original selected node may have changed. We now want to + // expand the currently selected node. + expandNode(m_selected, true); + } + else + { + np.buildLabel(jRefNode, np.isExpanded(), np.isClosing(), false); + } + } + + if (bIsAttribute) + { + return lAnchorNode; + } + else + { + return jNode.getNodeId(); + } + } + else + { + JOptionPane.showMessageDialog( + this, + "Illegal State: Action requires Update Transaction", + "Illegal State", + JOptionPane.ERROR_MESSAGE); + } + + return 0; + + } + + /** + * The main program. + * @param args + */ + public static void main(String[] args) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception e) { + System.err.println( + "Couldn't use the system look and feel: " + e.getMessage()); + e.printStackTrace(); + } + + JFrame ed = new XEdit("XFlaim Editor"); + GraphicsConfiguration gc = ed.getGraphicsConfiguration(); + Rectangle bounds = gc.getBounds(); + int iHeight = ed.getHeight(); + int iWidth = ed.getWidth(); + ed.setLocation(Math.max(0, (bounds.width - iWidth)/2), + Math.max(0, (bounds.height - iHeight)/2)); + Thread t = new Thread((Runnable)ed); + t.start(); + } + + /** + * Method to add an annotation node to an existing node. + * @param iCollection + * @param sAnnotation + * @param lNodeId + * @return + */ + public long addAnnotation( + int iCollection, + String sAnnotation, + long lNodeId) throws XFlaimException + { + + if (m_status.getTransaction()) + { + DOMNode jNode = m_jDb.getNode( + iCollection, + lNodeId, + null); + + jNode = jNode.createAnnotation( jNode); + + // Set the value. + if (sAnnotation != null && sAnnotation.length() > 0) + { + jNode.setString(sAnnotation); + } + + if (m_selected != null && + lNodeId == m_selected.getNodeId()) + { + // See if we can refresh the selected node/row + NodePanel np = m_selected; + DOMNode jRefNode = m_jDb.getNode( + np.getCollection(), + lNodeId, + null); + + if (np.isExpanded() && np.isClosing()) + { + collapseNode(np); + // The original selected node may have changed. We now want to + // expand the currently selected node. + expandNode(m_selected, true); + } + else + { + np.buildLabel(jRefNode, np.isExpanded(), np.isClosing(), false); + } + } + + return lNodeId; + } + else + { + JOptionPane.showMessageDialog( + this, + "Illegal State: Action requires Update Transaction", + "Illegal State", + JOptionPane.ERROR_MESSAGE); + } + + return 0; + } +} diff --git a/xflaim/java/util/xxedit/xedit/XFileFilter.java b/xflaim/java/util/xxedit/xedit/XFileFilter.java new file mode 100644 index 0000000..048a39e --- /dev/null +++ b/xflaim/java/util/xxedit/xedit/XFileFilter.java @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// Desc: File Filter +// +// Tabs: 3 +// +// Copyright (c) 2003,2005-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// 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, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: XFileFilter.java 3120 2006-01-19 13:41:12 -0700 (Thu, 19 Jan 2006) dsanders $ +//------------------------------------------------------------------------------ + +package xedit; +import java.io.File; + +import javax.swing.filechooser.FileFilter; + + +/** + * To change the template for this generated type comment go to + * Window->Preferences->Java->Code Generation->Code and Comments + */ +public class XFileFilter extends FileFilter +{ + + /** + * + */ + public XFileFilter( String filter) + { + super(); + m_sFilter = filter; + } + + /* (non-Javadoc) + * @see javax.swing.filechooser.FileFilter#accept(java.io.File) + */ + public boolean accept(File f) + { + String name = f.getName(); + if (f.isDirectory()) + { + return true; + } + + if ( name.endsWith(m_sFilter)) + { + return true; + } + return false; + } + + /* (non-Javadoc) + * @see javax.swing.filechooser.FileFilter#getDescription() + */ + public String getDescription() + { + return m_sFilter; + } + + String m_sFilter; + +}