PDA

View Full Version : tree listener to open windows



ampahboyz
20 Dec 2012, 7:29 AM
40913
i have window like this, i want clik tree item file upload will open window file upload,,when clik item tree download file open window download file.

package com.mycompany.project.client.view; import java.io.Serializable;import java.util.List; import com.mycompany.resources.client.Resources; import com.mycompany.resources.client.TestData;
import com.extjs.gxt.ui.client.data.BaseTreeModel;import com.extjs.gxt.ui.client.data.ModelData; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.MenuEvent; import com.extjs.gxt.ui.client.event.SelectionChangedEvent;import com.extjs.gxt.ui.client.event.SelectionChangedListener;import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.store.TreeStore; import com.extjs.gxt.ui.client.widget.ContentPanel;import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.button.Button; import com.extjs.gxt.ui.client.widget.button.ButtonBar;import com.extjs.gxt.ui.client.widget.layout.FitLayout;import com.extjs.gxt.ui.client.widget.layout.FlowData; import com.extjs.gxt.ui.client.widget.layout.FlowLayout; import com.extjs.gxt.ui.client.widget.menu.Menu; import com.extjs.gxt.ui.client.widget.menu.MenuItem; import com.extjs.gxt.ui.client.widget.treepanel.TreePanel; import com.google.gwt.core.client.GWT;import com.google.gwt.user.client.Element;import com.google.gwt.user.client.Window;import com.extjs.gxt.ui.client.widget.layout.RowLayout;import com.extjs.gxt.ui.client.Style.Orientation;import com.extjs.gxt.ui.client.widget.layout.RowData;import com.extjs.gxt.ui.client.Style;import com.extjs.gxt.ui.client.util.Margins;import com.extjs.gxt.ui.client.widget.layout.FillLayout;import com.extjs.gxt.ui.client.widget.layout.AbsoluteLayout;import com.extjs.gxt.ui.client.widget.layout.AbsoluteData;import com.extjs.gxt.ui.client.Style.HorizontalAlignment; public class WestPanel2 extends ContentPanel { public WestPanel2() { setButtonAlign(HorizontalAlignment.LEFT); setCollapsible(true); } private int count = 1; @Override protected void onRender(Element parent, int pos) { super.onRender(parent, pos); final Folder model = getTreeModel(); setHeading("Menu AP2T"); final TreeStore<ModelData> store = new TreeStore<ModelData>(); final TreePanel<ModelData> tree = new TreePanel<ModelData>(store); store.add(model.getChildren(), true); setLayout(new AbsoluteLayout()); ButtonBar buttonBar = new ButtonBar(); add(buttonBar, new AbsoluteData(0, 0)); buttonBar.setSize("372px", "26px"); buttonBar.add(new Button("Expand All", new SelectionListener<ButtonEvent>() { public void componentSelected(ButtonEvent ce) { tree.expandAll(); } })); buttonBar.add(new Button("Collapse All", new SelectionListener<ButtonEvent>() { public void componentSelected(ButtonEvent ce) { tree.collapseAll(); } })); AbsoluteData ad_tree = new AbsoluteData(0, 26); ad_tree.setAnchorSpec("0 -60"); add(tree, ad_tree);
tree.setBorders(true); tree.setSize(400, 400); tree.setDisplayProperty("name"); tree.getStyle().setLeafIcon(Resources.ICONS.form()); tree.setWidth(260); tree.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>() { public void selectionChanged(SelectionChangedEvent<ModelData> se) { EditorNew editor = new EditorNew(); editor.show();
}
}); } public static Folder getTreeModel() { Folder[] folders = new Folder[] { new Folder("Managemen Buku", new Folder[] {
new Folder("Bab1", new Music[] { new Music("Six String Quartets", "Beethoven", "Quartets"), new Music("Grosse Fugue for String Quartets", "Beethoven", "Quartets"),}), new Folder("Bab 2", new Music[] { new Music("Sonata in A Minor", "Beethoven", "Sonatas"), new Music("Sonata in F Major", "Beethoven", "Sonatas"),}),
new Folder("Bab 3", new Music[] { new Music("No. 1 - C", "Beethoven", "Concertos"), new Music("No. 5 - E-Flat Major", "Beethoven", "Concertos"),}),
new Folder("Bab 4", new Music[] { new Music("No. 1 - C Major", "Beethoven", "Symphonies"), new Music("No. 2 - D Minor", "Beethoven", "Symphonies"),}),}), new Folder("Arsip", new Music[] { new Music("Upload File", "Brahms", "Symphonies"), new Music("Download File", "Brahms", "Symphonies"),}), new Folder("FAQ", new Folder[] { new Folder("Concertos", new Music[] { new Music("Violin Concerto", "Brahms", "Concertos"), new Music("Piano Concerto No. 2 - B-Flat Major", "Brahms", "Concertos"),}), new Folder("Quartets", new Music[] { new Music("Piano Quartet No. 1 - G Minor", "Brahms", "Quartets"), new Music("String Quartet No. 3 - B-Flat Minor", "Brahms", "Quartets"),}), new Folder("Sonatas", new Music[] { new Music("Two Sonatas for Clarinet - F Minor", "Brahms", "Sonatas"), new Music("Two Sonatas for Clarinet - E-Flat Major", "Brahms", "Sonatas"),}), new Folder("Symphonies", new Music[] { new Music("No. 1 - C Minor", "Brahms", "Symphonies"),
new Music("No. 4 - E Minor", "Brahms", "Symphonies"),}),}), new Folder("Managemen User", new Music[] { new Music("Edit User", "Mozart", "Concertos"), new Music("Violin Concerto No. 4", "Mozart", "Concertos"),}),};
Folder root = new Folder("root"); for (int i = 0; i < folders.length; i++) { root.add((Folder) folders[i]); }
return root; } } class Music extends BaseTreeModel {
public Music() {
}
public Music(String name) { set("name", name); }
public Music(String name, String author, String genre) { set("name", name); set("author", author); set("genre", genre); }
public String getName() { return (String) get("name"); }
public String getAuthor() { return (String) get("author"); }
public String getGenre() { return (String) get("genre"); }
public String toString() { return getName(); } }
class Folder extends BaseTreeModel implements Serializable {
private static int ID = 0; public Folder() { set("id", ID++); }
public Folder(String name) { set("id", ID++); set("name", name); }
public Folder(String name, BaseTreeModel[] children) { this(name); for (int i = 0; i < children.length; i++) { add(children[i]); } }
public Integer getId() { return (Integer) get("id"); }
public String getName() { return (String) get("name"); }
public String toString() { return getName(); } }