Permalink
Browse files

started integrating the linker and the history service.

  • Loading branch information...
1 parent ed8c5a0 commit 16f3c995a900278e271eb122306db484d396c533 kohsuke committed Mar 14, 2010
@@ -1,6 +1,9 @@
package sorcerer.client;
import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.VisibilityMode;
@@ -9,13 +12,19 @@
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
+import sorcerer.client.LazyDataLoader.Callback;
import sorcerer.client.data.SourceFileLoader;
import sorcerer.client.data.pkg.ClassListLoader;
+import sorcerer.client.data.pkg.Klass;
+import sorcerer.client.data.pkg.Project;
import sorcerer.client.data.pkg.ProjectLoader;
+import sorcerer.client.js.JsArray;
import sorcerer.client.outline.OutlineTreeWidget;
import sorcerer.client.pkg.PackageTreeWidget;
import sorcerer.client.sourceview.SourceViewWidget;
+import static java.lang.Math.max;
+
/**
* Entry point classes define <code>onModuleLoad()</code>.
@@ -28,6 +37,11 @@
public void onModuleLoad() {
INSTANCE = this;
Page.setAppImgDir("resource-files/");
+ History.addValueChangeHandler(new ValueChangeHandler<String>() {
+ public void onValueChange(ValueChangeEvent<String> e) {
+ jumpTo(e.getValue());
+ }
+ });
HLayout h = new HLayout();
h.setWidth100();
@@ -110,6 +124,25 @@ public SourceViewWidget getSourceView() {
public OutlineTreeWidget getOutlineView() {
return outline;
}
+
+ /**
+ * Restores the right state.
+ */
+ public void jumpTo(String historyId) {
+ String pkgName = historyId.substring(0, max(0,historyId.lastIndexOf('.')));
+ final String shortName = historyId.substring(historyId.lastIndexOf('.')+1);
+ for (Project p : ProjectLoader.INSTANCE) {
+ p.getPackage(pkgName).retrieveClassList(new Callback<JsArray<Klass>>() {
+ public void call(JsArray<Klass> value) {
+ for (Klass k : value.iterable()) {
+ if (k.shortName().equals(shortName)) {
+ k.show();
+ }
+ }
+ }
+ });
+ }
+ }
public static Application get() {
return INSTANCE;
@@ -0,0 +1,9 @@
+package sorcerer.client;
+
+/**
+ * Model classes shouldn't update history. That should be done from the widget layer.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public class HistoryManagement {
+}
@@ -1,12 +0,0 @@
-package sorcerer.client;
-
-import sorcerer.client.data.Type;
-
-/**
- * Determines where the definition of a symbol exists.
- *
- * @author Kohsuke Kawaguchi
- */
-public interface Linker {
- String type(Type t);
-}
@@ -1,6 +1,7 @@
package sorcerer.client.data;
import com.google.gwt.core.client.JavaScriptObject;
+import sorcerer.client.linker.Linker;
/**
* @author Kohsuke Kawaguchi
@@ -29,8 +30,7 @@ public Kind kind() {
@Override
public String href() {
- // TODO
- return "TODO";
+ return owner.linker.href(this);
}
@Override
@@ -3,6 +3,7 @@
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
import sorcerer.client.js.JsArray;
+import sorcerer.client.linker.Linker;
/**
* @author Kohsuke Kawaguchi
@@ -56,8 +57,7 @@ public Kind kind() {
@Override
public String href() {
- // TODO
- return "TODO";
+ return owner.linker.href(this);
}
@Override
@@ -1,5 +1,7 @@
package sorcerer.client.data;
+import sorcerer.client.linker.Linker;
+
/**
* @author Kohsuke Kawaguchi
*/
@@ -15,7 +17,7 @@
public final String css;
/**
- * Link to the definition of this method
+ * Hyperlink to the definition.
*/
public abstract String href();
@@ -1,5 +1,8 @@
package sorcerer.client.data;
+import sorcerer.client.linker.Linker;
+import sorcerer.client.linker.SorcererLinker;
+
/**
* Represents a type in AST.
*
@@ -18,6 +21,11 @@
public final String packageName;
+ /**
+ * Linker to use for declarations in this type.
+ * TODO: depending on where we load it, use the right instance.
+ */
+ public final Linker linker = SorcererLinker.INSTANCE;
/**
* Builds a richer in memory information about a type from {@link TypeEntry}
@@ -43,6 +51,9 @@ public String displayText() {
return shortName;
}
+ /**
+ * Fully qualified class name all separated by '.' and not '$'.
+ */
public String fullDisplayName() {
return binaryName.replace('$','.');
}
@@ -58,14 +69,7 @@ public Kind kind() {
@Override
public String href() {
- // TODO: it'd be nice if the source view page can be loaded on its own.
- // the way it's done today requires package view to be loaded.
-// t.linker = window.top.packageView.main.linker.get(t.packageName);
- // YAHOO.log("linker for ["+t.packageName+"] is "+t.linker.name());
-
-// t.href = t.linker.type(t);
- // TODO
- return "TODO";
+ return linker.href(this);
}
@Override
@@ -1,5 +1,7 @@
package sorcerer.client.data;
+import sorcerer.client.linker.Linker;
+
/**
* @author Kohsuke Kawaguchi
*/
@@ -20,7 +22,8 @@ public Kind kind() {
@Override
public String href() {
- return href;
+ // TODO: return linker.href(this);
+ return "TODO";
}
@Override
@@ -5,7 +5,7 @@
import sorcerer.client.data.AST;
/**
- * Represents a type.
+ * Represents a top-level type in the package structure.
*
* @author Kohsuke Kawaguchi
*/
@@ -55,6 +55,11 @@ protected Klass() {}
public Project project() { return pkg().owner(); }
+ public String fullName() {
+ String fn = pkg().fullName();
+ return fn.length()>0 ? fn+'.'+shortName() : shortName();
+ }
+
/**
* Gets the {@link SourceFile} that contains this type.
*/
@@ -0,0 +1,16 @@
+package sorcerer.client.linker;
+
+import sorcerer.client.data.Field;
+import sorcerer.client.data.Method;
+import sorcerer.client.data.Type;
+
+/**
+ * Determines where the definition of a symbol exists.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public interface Linker {
+ String href(Type t);
+ String href(Method m);
+ String href(Field f);
+}
@@ -0,0 +1,26 @@
+package sorcerer.client.linker;
+
+import sorcerer.client.data.Field;
+import sorcerer.client.data.Method;
+import sorcerer.client.data.Type;
+
+/**
+ * {@link Linker} within the same sorcerer, always producing "#..." as href.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public class SorcererLinker implements Linker {
+ public String href(Type t) {
+ return '#'+t.fullDisplayName();
+ }
+
+ public String href(Field f) {
+ return href(f.owner)+'-'+f.name;
+ }
+
+ public String href(Method m) {
+ return href(m.owner)+'-'+m.signature();
+ }
+
+ public static final Linker INSTANCE = new SorcererLinker();
+}
@@ -9,23 +9,29 @@
import sorcerer.client.data.Type;
import sorcerer.client.data.Variable;
import sorcerer.client.js.JsFunction;
+import sorcerer.client.linker.Linker;
/**
* @author Kohsuke Kawaguchi
*/
public class OutlineBuilder extends ASTVisitor {
private final Tree tree;
private OutlineNode node;
+ private final Linker linker;
/**
* If we are visiting inside a {@link Type}, set to that type.
*/
private Type currentType;
- public OutlineBuilder(Tree tree) {
+ public OutlineBuilder(Tree tree, Linker linker) {
this.tree = tree;
+ this.linker = linker;
}
+ /**
+ * As we figure out the access modifier for the current declaration, updates its icon.
+ */
@Override
public void reservedWord(String name) {
if (name.equals("public") || name.equals("protected") || name.equals("private")) {
@@ -40,7 +46,7 @@ public void reservedWord(String name) {
*/
private void decl(TableItem type, boolean isLocal, JsFunction children) {
OutlineNode parent = node;
- node = new OutlineNode(type,isLocal);
+ node = new OutlineNode(type,type.href(),isLocal);
tree.add(node, parent!=null ? parent : tree.getRoot());
children.invoke();
@@ -68,7 +74,7 @@ public void fieldDef(String name, JsFunction children) {
decl(new Field(currentType,name), true,children);
}
- //
+//
// No-ops
//
@Override
@@ -127,5 +133,6 @@ public void identifier(String text) {
@Override
public void variableDef(Variable v, JsFunction children) {
+ children.invoke();
}
}
@@ -18,12 +18,12 @@
* @param decl
* The declaration to be wrapped into a node.
*/
- public OutlineNode(TableItem decl, boolean local) {
+ public OutlineNode(TableItem decl, String href, boolean local) {
super();
this.kind = decl.kind().toLowerCase();
this.isLocal = local;
setAccess("default"); // unless later overridden otherwise
- setTitle("<a href='"+decl.href()+"'>"+decl.outlineTitle()+"</a>");
+ setTitle("<a href='"+href+"'>"+decl.outlineTitle()+"</a>");
}
public void setAccess(String access) {
@@ -5,6 +5,7 @@
import com.smartgwt.client.widgets.tree.TreeNode;
import sorcerer.client.Application;
import sorcerer.client.data.AST;
+import sorcerer.client.linker.SorcererLinker;
/**
* Outline tree view.
@@ -29,7 +30,7 @@ public OutlineTreeWidget() {
public void load(AST ast) {
root.setChildren(new TreeNode[0]);
- ast.accept(new OutlineBuilder(tree));
+ ast.accept(new OutlineBuilder(tree, new SorcererLinker()));
}
public static OutlineTreeWidget get() {
@@ -1,5 +1,6 @@
package sorcerer.client.pkg;
+import com.google.gwt.user.client.History;
import com.smartgwt.client.widgets.tree.TreeNode;
import com.smartgwt.client.widgets.tree.events.LeafClickEvent;
import com.smartgwt.client.widgets.tree.events.LeafClickHandler;
@@ -14,12 +15,12 @@
private final Klass klass;
public KlassNode(Klass k) {
- super(k.shortName());
+ super("<a href='#"+k.fullName()+"'>"+k.shortName()+"</a>");
this.klass = k;
setIcon(k.kind()+'_'+k.access()+".gif");
}
public void onLeafClick(LeafClickEvent event) {
- klass.show();
+ History.newItem(klass.fullName(),true);
}
}

0 comments on commit 16f3c99

Please sign in to comment.