Index: java/main/src/main/java/com/framsticks/gui/Frame.java
===================================================================
--- java/main/src/main/java/com/framsticks/gui/Frame.java	(revision 97)
+++ java/main/src/main/java/com/framsticks/gui/Frame.java	(revision 98)
@@ -11,5 +11,5 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
-import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.Map;
 
@@ -28,10 +28,8 @@
 import javax.swing.ToolTipManager;
 import javax.swing.UIManager;
-import javax.swing.event.TreeModelEvent;
-import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeExpansionListener;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.DefaultTreeSelectionModel;
 import javax.swing.tree.TreePath;
@@ -40,16 +38,16 @@
 import org.apache.log4j.Logger;
 
+import com.framsticks.core.Mode;
 import com.framsticks.core.Path;
 import com.framsticks.core.Tree;
+import com.framsticks.core.TreeOperations;
 import com.framsticks.gui.view.TreeCellRenderer;
-import com.framsticks.util.FramsticksException;
+import com.framsticks.params.AccessInterface;
 import com.framsticks.util.dispatching.Dispatching;
-import com.framsticks.util.dispatching.ExceptionResultHandler;
+import com.framsticks.util.dispatching.FutureHandler;
 import com.framsticks.util.dispatching.Joinable;
 import com.framsticks.util.dispatching.JoinableCollection;
 import com.framsticks.util.dispatching.JoinableParent;
 import com.framsticks.util.dispatching.JoinableState;
-import com.framsticks.util.dispatching.RunAt;
-import com.framsticks.util.lang.ScopeEnd;
 import com.framsticks.util.swing.KeyboardModifier;
 import com.framsticks.util.swing.MenuConstructor;
@@ -72,11 +70,12 @@
 	protected JScrollPane treeScrollPane;
 	protected JTree jtree;
-	protected DefaultTreeModel treeModel;
-	protected javax.swing.tree.MutableTreeNode rootNode;
+	protected TreeModel treeModel;
+
+	protected MetaNode rootNode;
+
 	protected JPanel treePanel;
 	protected JPopupMenu treePopupMenu;
 	protected JMenuItem treePopupMenuHeader;
 
-	TreeNode currentlyPoppedTreeNode;
 	protected JPanel mainPanel;
 	protected JPanel leftPanel;
@@ -91,6 +90,6 @@
 	protected JMenu helpMenu;
 
-	protected final Map<Tree, TreeAtFrame> treeAtFrames = new HashMap<Tree, TreeAtFrame>();
-	protected JoinableCollection<Tree> trees = new JoinableCollection<Tree>();
+	protected final Map<Tree, TreeAtFrame> treeAtFrames = new IdentityHashMap<>();
+	protected JoinableCollection<Tree> trees = new JoinableCollection<>();
 
 	public Frame(Browser browser) {
@@ -106,5 +105,4 @@
 		log.debug("creating " + this);
 
-
 		Container contentPane = getSwing().getContentPane();
 		treePopupMenu = new JPopupMenu("title");
@@ -114,27 +112,7 @@
 		treePanel.setLayout(new BorderLayout());
 
-		treeModel = new DefaultTreeModel(null);
-		treeModel.addTreeModelListener(new TreeModelListener() {
-
-			@Override
-			public void treeNodesChanged(TreeModelEvent arg0) {
-				log.trace("treeNodesChanged: " + arg0);
-			}
-
-			@Override
-			public void treeNodesInserted(TreeModelEvent arg0) {
-				// log.trace("treeNodesInserted: " + arg0);
-			}
-
-			@Override
-			public void treeNodesRemoved(TreeModelEvent arg0) {
-				log.trace("treeNodesRemoved: " + arg0);
-			}
-
-			@Override
-			public void treeStructureChanged(TreeModelEvent arg0) {
-				log.trace("treeStructureChanged: " + arg0);
-			}
-		});
+		rootNode = new MetaNode();
+		rootNode.setName("root");
+		treeModel = new TreeModel(this);
 
 		jtree = new JTree(treeModel);
@@ -152,7 +130,19 @@
 		});
 
+		jtree.addTreeExpansionListener(new TreeExpansionListener() {
+
+			@Override
+			public void treeCollapsed(TreeExpansionEvent e) {
+
+			}
+
+			@Override
+			public void treeExpanded(TreeExpansionEvent e) {
+				loadChildren(treeModel.convertToPath(e.getPath()), false);
+			}
+		});
+
 		jtree.setExpandsSelectedPaths(true);
 		jtree.setEditable(false);
-		jtree.setDoubleBuffered(true);
 		jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
 		jtree.setShowsRootHandles(true);
@@ -173,5 +163,9 @@
 		});
 
-		new KeyboardModifier(jtree, JComponent.WHEN_FOCUSED).join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)).join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)).join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)).join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
+		new KeyboardModifier(jtree, JComponent.WHEN_FOCUSED)
+			.join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0))
+			.join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0))
+			.join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0))
+			.join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
 
 		jtree.setCellRenderer(new TreeCellRenderer());
@@ -182,7 +176,4 @@
 		treePanel.add(treeScrollPane);
 
-		rootNode = new DefaultMutableTreeNode();
-		rootNode.setUserObject("root");
-		treeModel.setRoot(rootNode);
 
 		normalWorkPanel = new JPanel();
@@ -248,4 +239,12 @@
 		});
 
+		new MenuConstructor(fileMenu).add(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK), new AbstractAction("Reload current") {
+			@Override
+			public void actionPerformed(ActionEvent actionEvent) {
+
+				loadPath(treeModel.convertToPath(jtree.getSelectionPath()), true);
+			}
+		});
+
 	}
 
@@ -254,16 +253,30 @@
 	}
 
-	public void addRootPath(Path path) {
+	public void addRootPath(final Path path) {
 		assert isActive();
+
 		Tree tree = path.getTree();
+
+		log.info("trying mount: " + path);
+		if (!tree.getAssignedRoot().isResolved()) {
+			tree.get(path, Mode.FETCH, new FutureHandler<Path>(this) {
+
+				@Override
+				protected void result(Path result) {
+					addRootPath(result);
+				}
+			});
+			return;
+		}
+
 		assert browser.getTrees().contains(tree);
 
 		TreeAtFrame e = new TreeAtFrame(tree, this);
-		tree.addListener(e);
 		treeAtFrames.put(tree, e);
-		TreeNode node = new TreeNode(e, path);
-		e.rootTreeNode = node;
-		treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount());
-		jtree.expandPath(new TreePath(rootNode));
+
+		rootNode.getChildren().add(new TreeNode(tree.getAssignedRoot()));
+		e.rootNode = tree.getAssignedRoot();
+		treeModel.nodeStructureChanged(new TreePath(rootNode));
+		// jtree.expandPath(new TreePath(rootNode));
 	}
 
@@ -275,4 +288,5 @@
 	}
 
+
 	private void showPopup(MouseEvent e) {
 		assert isActive();
@@ -280,10 +294,7 @@
 			return;
 		}
-		currentlyPoppedTreeNode = findTreeNodeByTreePath(jtree.getPathForLocation(e.getX(), e.getY()));
-		if (currentlyPoppedTreeNode == null) {
-			return;
-		}
-
-		Path path = currentlyPoppedTreeNode.getTreePath();
+		TreePath treePath = jtree.getPathForLocation(e.getX(), e.getY());
+
+		Path path = treeModel.convertToPath(treePath);
 		treePopupMenu.removeAll();
 
@@ -291,16 +302,8 @@
 			provider.provide(treePopupMenu, path);
 		}
-		// treePopupMenuHeader.setText(path.getTree().getName() + path.getTextual());
 		treePopupMenu.show(e.getComponent(), e.getX(), e.getY());
-		//currentlyPoppedPanel.getNode().getFramsClass().getName()
-	}
-
-	public TreeNode getCurrentlyPoppedTreeNode() {
-		assert isActive();
-		return currentlyPoppedTreeNode;
 	}
 
 	public void clear() {
-		treeModel.setRoot(null);
 		cardPanel.removeAll();
 		cardPanel.updateUI();
@@ -308,82 +311,76 @@
 	}
 
-	public ScopeEnd startChange(final DefaultMutableTreeNode node) {
-		assert isActive();
-		final TreePath selection = jtree.getSelectionPath();
-		return new ScopeEnd() {
-			@Override
-			public void close() {
-				assert isActive();
-				treeModel.nodeChanged(node);
-				jtree.setSelectionPath(selection);
-			}
-		};
-	}
-
-	public void selectTreeNode(final TreeNode treeNode) {
-		assert isActive();
-		/*		final Panel panel = treeNode.getOrCreatePanel();
-		 if (panel == null) {
-		 return;
-		 }
-		 panel.setCurrentTreeNode(treeNode);
-		 treeNode.updateData();
-		 showPanel(panel);*/
-	}
-
-	public TreeNode findTreeNodeByTreePath(TreePath treePath) {
+	public void loadChildren(Path path, boolean reload) {
+		if (path == null) {
+			return;
+		}
+		AccessInterface access = TreeOperations.bindAccess(path);
+
+		int count = access.getCompositeParamCount();
+		for (int i = 0; i < count; ++i) {
+			Path childPath = path.appendParam(access.getCompositeParam(i)).tryFindResolution();
+			loadPath(childPath, reload);
+		}
+
+	}
+
+	public void loadPath(Path path, boolean reload) {
+		if (path == null) {
+			return;
+		}
+		if (path.isResolved() && !reload) {
+			return;
+		}
+		path.getTree().get(path, Mode.FETCH, new FutureHandler<Path>(this) {
+			@Override
+			protected void result(Path result) {
+				final TreePath treePath = treeModel.convertToTreePath(result);
+
+				treeModel.nodeStructureChanged(treePath);
+				if (treePath.equals(jtree.getSelectionPath())) {
+					treeAtFrames.get(result.getTree()).useOrCreatePanel(treePath);
+				}
+			}
+		});
+	}
+
+	public void chooseTreeNode(final TreePath treePath) {
 		assert isActive();
 		if (treePath == null) {
-			return null;
-		}
-		if (!(treePath.getLastPathComponent() instanceof TreeNode)) {
-			return null;
-		}
-		return (TreeNode) treePath.getLastPathComponent();
-	}
-
-	public void chooseTreeNode(TreePath treePath) {
-		assert isActive();
-		final TreeNode treeNode = findTreeNodeByTreePath(treePath);
-		if (treeNode == null) {
-			return;
-		}
-		treeNode.select();
-	}
-
-	protected final ExceptionResultHandler dialogHandler = new ExceptionResultHandler() {
-
-		@Override
-		public void handle(FramsticksException exception) {
-			//TODO TEH
-			throw exception;
-
-		}
-	};
-
-	public void goTo(Path path) {
-		assert isActive();
-		final TreePath treePath = treeAtFrames.get(path.getTree()).getTreePath(path, false);
-		log.info("go to path: " + path + "(" + treePath + ")");
-
-		this.dispatch(new RunAt<Frame>(dialogHandler) {
-			@Override
-			protected void runAt() {
-				log.info("executed");
-				jtree.setSelectionPath(treePath);
-				jtree.makeVisible(treePath);
-				assert jtree.isVisible(treePath);
-			}
-		});
-
-	}
-
-	public void addNode(TreeNode child, DefaultMutableTreeNode parent) {
-		assert isActive();
-
-		try (ScopeEnd e = startChange(parent)) {
-			treeModel.insertNodeInto(child, parent, parent.getChildCount());
-		}
-	}
+			return;
+		}
+		if (treeModel.isChanging()) {
+			return;
+		}
+
+		Path path = treeModel.convertToPath(treePath);
+		if (path == null) {
+			return;
+		}
+		path = path.assureResolved();
+		final Tree tree = path.getTree();
+
+		treeAtFrames.get(tree).useOrCreatePanel(treePath);
+		loadChildren(path, false);
+
+	}
+
+
+	// public void goTo(Path path) {
+	//	assert isActive();
+	//	final TreePath treePath = treeModel.convertToTreePath(path);
+	//	log.info("go to path: " + path + "(" + treePath + ")");
+
+	//	this.dispatch(new RunAt<Frame>(this) {
+	//		@Override
+	//		protected void runAt() {
+	//			log.info("executed");
+	//			jtree.setSelectionPath(treePath);
+	//			jtree.makeVisible(treePath);
+	//			assert jtree.isVisible(treePath);
+	//		}
+	//	});
+
+	// }
 
 	@Override
@@ -422,3 +419,10 @@
 	}
 
+	/**
+	 * @return the treeModel
+	 */
+	public TreeModel getTreeModel() {
+		return treeModel;
+	}
+
 }
