The save method in the QUBSystem class - called form an actionPerformed
method in the front end class
/**
* Saves this system to a file in serialised form, any exceptions while
* saving this system are notified to the user except for exceptions
when
* closing streams. ".qub" will be appended to the filename if
* it is not already the filename extension.
*
* @param fFile the file to save the system to
*/
public void saveSystem(File fFile)
{
ObjectOutputStream objStream = null; // to write to a file
if(! FileUtils.getExtension(fFile).equals("qub"))
{ // add .qub to the filename if it's not already there
fFile = new File(fFile.getAbsolutePath()+".qub");
}
try
{
objStream = new ObjectOutputStream(new FileOutputStream(fFile));
objStream.writeObject(this); // write to the file
}
catch(Exception ex)
{
try
{
throw new GUIException
("There was a problem saving this system" +
IQUBTraceConstants.NEW_LINE +
"the error message encountered was : " +
IQUBTraceConstants.NEW_LINE + ex.getMessage());
}
catch(GUIException ex1){ /* handled in the ex. class */ }
}
finally
{
try
{
if(null != objStream)
{
objStream.close();
}
}
catch(IOException ignored){} // user won't want to know
}
}
The remove nodes method in the QUBSystem class (the nodes to be removed are
always files)
/**
* Removes files from the JTree associated with this system.
*
* @param vFilesToRemove the paths to the files to be removed
*/
public void removeFiles(TreePath[] vPaths)
{
for(int i=0; i<vPaths.length; i++)
{
OpeningFrame.setStatus("removing "+vPaths[i].toString()+" ...
");
MutableTreeNode oNode
=(MutableTreeNode)(vPaths[i].getLastPathComponent());
oTreeModel_i.removeNodeFromParent(oNode);
}
}
the removeFiles actionPerformed method in the front end
/**
* Handles a remove files action, removes files from a system.
*
* @param e the action event
*/
public void actionPerformed(ActionEvent e)
{
try
{
// get the currently selected components
TreePath[] vSelectedPaths = oSystem_i.getSelections();
// check that all the selected components are parsedFiles
oSystem_i.getNotParsedFiles(vSelectedPaths);
setStatus("removing files ... ");
// got to here so everyting's OK, remove the selected files
oSystem_i.removeFiles(vSelectedPaths);
// check if there are no ParsedFiles left in the system
if(0 >= oSystem_i.getChildCount())
{ // disable appropriate actions as there are no files
left
enableFileActions(false);
}
}
catch(GUIException ex) {/* Handled in the Exception class */}
finally
{
setStatus("idle");
}
}
The exception I get -
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:422)
at
javax.swing.tree.DefaultMutableTreeNode.getChildAt(DefaultMutableTreeNode.ja
va:233)
at
javax.swing.tree.VariableHeightLayoutCache.treeNodesRemoved(VariableHeightLa
youtCache.java:546)
at
javax.swing.plaf.basic.BasicTreeUI$TreeModelHandler.treeNodesRemoved(BasicTr
eeUI.java:2456)
at
javax.swing.tree.DefaultTreeModel.fireTreeNodesRemoved(DefaultTreeModel.java
:533)
at
javax.swing.tree.DefaultTreeModel.nodesWereRemoved(DefaultTreeModel.java:311
)
at
javax.swing.tree.DefaultTreeModel.removeNodeFromParent(DefaultTreeModel.java
:247)
at uk.ac.qub.trace.utils.QUBSystem.removeFiles(QUBSystem.java:403)
at
uk.ac.qub.trace.gui.OpeningFrame$RemoveFilesAction.actionPerformed(OpeningFr
ame.java:784)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1770)
at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButto
n.java:1823)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:4
22)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:260)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener
.java:261)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:230)
at java.awt.Component.processMouseEvent(Component.java:5020)
at java.awt.Component.processEvent(Component.java:4819)
at java.awt.Container.processEvent(Container.java:1383)
at java.awt.Component.dispatchEventImpl(Component.java:3527)
at java.awt.Container.dispatchEventImpl(Container.java:1440)
at java.awt.Component.dispatchEvent(Component.java:3368)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3219)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2930)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2866)
at java.awt.Container.dispatchEventImpl(Container.java:1426)
at java.awt.Window.dispatchEventImpl(Window.java:1568)
at java.awt.Component.dispatchEvent(Component.java:3368)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:193)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:141)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:133)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:101)
"Richard Reynolds" <richier...@ntlworld.com> wrote in message
news:K3Y%7.1998$Hg7.2...@news11-gui.server.ntli.net...