java - How to design a checkbox treeviewer using jface -
i have designed checkbox treeviewer using jface when run program doesnot display thing on ui.i not able find issue is.please me whrer problem new jface.
private void createtreemenu(composite parentcomposite){ /*treeitem = new treeitem(tree, swt.multi | swt.check | swt.virtual |swt.border ); treeitem.settext("(1)test session"); treeitem.setimage(new image(null, treeviewer.class.getclassloader().getresourceasstream("icons/folder-main.jpg")));*/ composite treemenu = new composite(parentcomposite, swt.border); treemenu.setlayout(new gridlayout(1, false)); treemenu.setlayoutdata(new griddata(griddata.fill, griddata.fill, true, true)); /*tree = new tree (treemenu, swt.multi | swt.check |swt.virtual ); griddata treegd = new griddata(swt.fill, griddata.fill, true, true); tree.setlayoutdata(treegd);*/ checkboxtreeviewer treeviewer=new checkboxtreeviewer(tree); treeviewer.setcontentprovider(new filetreecontentprovider()); treeviewer.setlabelprovider(new filetreelabelprovider1()); treeviewer.setinput(treeitem); parameters.add("root"); /*treeitem = new treeitem(tree, swt.multi | swt.check | swt.virtual |swt.border ); treeitem.settext("(1)test session"); treeitem.setimage(new image(null, treeviewer.class.getclassloader().getresourceasstream("icons/folder-main.jpg")));*/ tree.addlistener(swt.selection, new listener() { public void handleevent(event e) { if(e.item == null) { return; } treeselection = tree.getselection(); } }); treemenu.addlistener(swt.mousedown, new listener() { @override public void handleevent(event event) { tree.setselection(new treeitem[] {}); treeselection = null; } }); final menu menu = new menu(tree); tree.setmenu(menu); loadmenudetails(menu); } public treeitem getinput() { treeitem = new treeitem(tree, swt.multi | swt.check | swt.virtual |swt.border ); treeitem.settext("(1)test session"); treeitem.setimage(new image(null, treeviewer.class.getclassloader().getresourceasstream("icons/folder-main.jpg"))); return treeitem; } /** * class provides content tree in filetree */ class filetreecontentprovider implements itreecontentprovider { /** * gets children of specified object * * @param arg0 * parent object * @return object[] */ public object[] getchildren(object arg0) { // return files , subdirectories in directory //return ((file) arg0).listfiles(); return null; } /** * gets parent of specified object * * @param arg0 * object * @return object */ public object getparent(object arg0) { // return file's parent file //return ((file) arg0).getparentfile(); return null; } /** * returns whether passed object has children * * @param arg0 * parent object * @return boolean */ public boolean haschildren(object arg0) { // children object[] obj = getchildren(arg0); // return whether parent has children return obj == null ? false : obj.length > 0; } /** * gets root element(s) of tree * * @param arg0 * input data * @return object[] */ /*public object[] getelements(object arg0) { // these root elements of tree // don't care arg0 is, because want // root nodes in file system return file.listroots(); //return "new root"; }*/ public object[] getelements(object inputelement) { //treeitem rootitem = new treeitem((tree) arg0, swt.check); //rootitem.settext("root"); // return new object[] { "session root" }; // root item want display treeitem = new treeitem(tree, swt.multi | swt.check | swt.virtual |swt.border ); treeitem.settext("(1)test session"); treeitem.setimage(new image(null, treeviewer.class.getclassloader().getresourceasstream("icons/folder-main.jpg"))); if (inputelement instanceof treeitem) { system.out.println("getelements"); return ((list<string>)inputelement).toarray(); } return new object[] {parameters.toarray()}; } /** * disposes created resources */ public void dispose() { // nothing dispose } /** * called when input changes * * @param arg0 * viewer * @param arg1 * old input * @param arg2 * new input */ public void inputchanged(viewer arg0, object arg1, object arg2) { // nothing change } } class filetreelabelprovider1 implements ilabelprovider { // listeners private list listeners; // images tree nodes private image file; private image dir; // label provider state: preserve case of file names/directories /** * constructs filetreelabelprovider */ public filetreelabelprovider1() { // create list hold listeners listeners = new arraylist(); // create images try { file = new image(null, new fileinputstream("images/file.gif")); dir = new image(null, new fileinputstream("images/directory.gif")); } catch (filenotfoundexception e) { // swallow it; we'll without images } } /** * gets image display node in tree * * @param arg0 * node * @return image */ public image getimage(object arg0) { // if node represents directory, return directory image. // otherwise, return file image. return ((file) arg0).isdirectory() ? dir : file; } /** * gets text display node in tree * * @param arg0 * node * @return string */ public string gettext(object arg0) { // name of file string text = ((file) arg0).getname(); // if name blank, path if (text.length() == 0) { text = ((file) arg0).getpath(); } // check case settings before returning text return text ; } /** * adds listener label provider * * @param arg0 * listener */ public void addlistener(ilabelproviderlistener arg0) { listeners.add(arg0); } /** * called when labelprovider being disposed */ public void dispose() { // dispose images if (dir != null) dir.dispose(); if (file != null) file.dispose(); } /** * returns whether changes specified property on specified * element affect label element * * @param arg0 * element * @param arg1 * property * @return boolean */ public boolean islabelproperty(object arg0, string arg1) { return false; } /** * removes listener * * @param arg0 * listener remove */ public void removelistener(ilabelproviderlistener arg0) { listeners.remove(arg0); } }
try giving tree object parent composite , flags (swt.border | swt.check) worked me way
tree = new tree(treemenu, swt.border | swt.check);
Comments
Post a Comment