KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > gui > task > LoadConfigTask


1 package org.sapia.regis.gui.task;
2
3 import java.io.File JavaDoc;
4 import java.io.StringWriter JavaDoc;
5
6 import javax.swing.JTree JavaDoc;
7 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
8 import javax.swing.tree.DefaultTreeModel JavaDoc;
9 import javax.swing.tree.TreePath JavaDoc;
10
11 import org.dom4j.Document;
12 import org.dom4j.io.SAXReader;
13 import org.sapia.regis.Configurable;
14 import org.sapia.regis.Node;
15 import org.sapia.regis.gui.GlobalContext;
16 import org.sapia.regis.gui.GuiConsts;
17
18 public class LoadConfigTask implements Task, GuiConsts{
19
20   public void execute() throws Exception JavaDoc {
21     File JavaDoc configFile = GlobalContext.getInstance().getModelManager().getFileSystemModel().showFileDialog();
22     if(configFile != null){
23       SAXReader reader = new SAXReader();
24       Document doc = reader.read(configFile);
25       StringWriter JavaDoc writer = new StringWriter JavaDoc();
26       doc.write(writer);
27       Configurable registry = (Configurable)GlobalContext.getInstance().getRegistry();
28       Node JavaDoc root = GlobalContext.getInstance().getRegistry().getRoot();
29       registry.load(root.getAbsolutePath(),
30           GlobalContext.getInstance().getUsername(),
31           GlobalContext.getInstance().getPassword(),
32           writer.toString(),null);
33       
34       JTree JavaDoc tree = (JTree JavaDoc)GlobalContext.getInstance().getWidget(TREE);
35       tree.clearSelection();
36       DefaultTreeModel JavaDoc model = (DefaultTreeModel JavaDoc)tree.getModel();
37       DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)model.getRoot();
38       tree.collapsePath(new TreePath JavaDoc(((DefaultMutableTreeNode JavaDoc)model.getRoot()).getPath()));
39       node.removeAllChildren();
40       
41       GlobalContext.getInstance().success("Configuration file loaded successfully");
42     }
43   }
44 }
45
Popular Tags