Results 1 to 6 of 6
  1. #1
    i4ba1 is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Cool make search function ike eclipse search in window->preference

    hello, i want to make search like in eclipse.in part Window->preference.the search succes to run.but, if the backspace button pushed the data in tree is not back into last search.How can resolve this problem?.....please answer my question.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    Is this a java programming problem?
    Do you have some code to demonstrate the problem?

  3. #3
    i4ba1 is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Default This my code

    package com.andika.sight.rcp.dialogs;

    import java.util.LinkedList;
    import java.util.List;
    import java.util.HashMap;

    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.events.KeyAdapter;
    import org.eclipse.swt.events.KeyEvent;
    import org.eclipse.jface.dialogs.Dialog;
    import org.eclipse.jface.dialogs.IDialogConstants;
    import org.eclipse.swt.SWT; //import org.eclipse.swt.events.SelectionAdapter;
    //import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.widgets.Tree;
    import org.eclipse.swt.widgets.TreeColumn;
    import org.eclipse.swt.widgets.TreeItem;
    import com.andika.sight.rcp.nel.Node;
    import com.andika.sight.rcp.nel.NodeLibrary;

    /*
    may i chat with you?if i can please put your email.this may email muhamad*nizar@rocketmail*com
    */
    public class NodesDialog extends Dialog {

    private static final int CALCEL_ID = IDialogConstants.CLIENT_ID + 1;
    private static final int OK_ID = IDialogConstants.CLIENT_ID + 2;

    private String title = "Nodes";
    private Tree tree;
    private TreeItem root;
    private TreeItem currentRegion = null;
    private TreeItem currentType = null;
    private LinkedList<Node> list;
    private Composite composite;
    private SelectionNodes nodes;
    private String lastRegion = "";
    private String lastType = "";
    private String region, type, vendor, node;
    private Text input;
    private HashMap<Integer, Tree> treeCollection;

    public NodesDialog(Shell parent, SelectionNodes nodes) {
    super(parent);
    this.nodes = nodes;
    }

    protected Point getInitialSize() {
    return new Point(320, 360);
    }

    protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, CALCEL_ID, "Cancel", false);
    createButton(parent, OK_ID, "OK", true);
    }

    protected Control createDialogArea(final Composite parent) {

    composite = (Composite) super.createDialogArea(parent);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new GridLayout());

    input = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.SEARCH);

    input.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    tree = new Tree(composite, SWT.SINGLE | SWT.CHECK);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    tree.setHeaderVisible(true);

    TreeColumn cnode = new TreeColumn(tree, SWT.NONE);
    cnode.setText("Region/Type/Node");
    TreeColumn vnode = new TreeColumn(tree, SWT.NONE);
    vnode.setText("Vendor");
    root = new TreeItem(tree, SWT.NONE);
    root.setText("All");
    boolean checked2 = false;
    boolean checked3 = false;
    for (int i = 0; i < nodes.getLength(); i++) {
    region = nodes.getRegion(i);
    // System.out.println("region " + region);
    type = nodes.getType(i);
    // System.out.println("type "+type);
    vendor = nodes.getVendor(i);
    // System.out.println("vendor "+vendor);
    node = nodes.getName(i);
    // System.out.println("node " + node);

    if (!region.equals(lastRegion)) {
    currentRegion = new TreeItem(root, SWT.SHADOW_OUT);
    currentRegion.setText(region);
    currentRegion.setChecked(false);
    checked2 = currentRegion.getChecked();
    lastRegion = region;
    }

    if (!type.equals(lastType)) {
    currentType = new TreeItem(currentRegion, SWT.NONE);
    currentType.setText(type);
    currentType.setChecked(false);
    checked3 = currentRegion.getChecked();
    lastType = type;
    }

    TreeItem item = new TreeItem(currentType, SWT.NONE);
    item.setText(new String[] { node, vendor });
    currentRegion.setExpanded(false);
    currentType.setExpanded(false);
    item.setChecked(nodes.getSelected(i));
    boolean checked = item.getChecked();
    checkItems(item, checked);
    checkPath(item.getParentItem(), checked, false);

    TreeItem curReg = root;
    System.out.println("curReg "+curReg.getText());
    TreeItem curType = currentType;
    TreeItem curName = item;

    if (checked3 == true) {
    System.out.println("checked2");
    for (int k = 0; k < curType.getItemCount(); k++) {

    curType.getItem(k).setExpanded(true);
    curType.getItem(k).getParentItem().setExpanded(tru e);
    curType.getItem(k).setExpanded(true);
    // curType.getParentItem().setExpanded(true);

    }
    }

    if (checked3 == true) {
    System.out.println("checked2");
    for (int k = 0; k < curType.getItemCount(); k++) {

    curType.getItem(k).setExpanded(true);
    curType.getItem(k).getParentItem().setExpanded(tru e);
    curType.getItem(k).setExpanded(true);
    // curType.getParentItem().setExpanded(true);

    }
    }

    item.setData(i);

    }

    root.setExpanded(true);

    tree.pack();
    cnode.pack();
    vnode.pack();

    keyResponse(input);
    tree.addListener(SWT.Selection, new Listener() {
    public void handleEvent(Event event) {
    if (event.detail == SWT.CHECK) {
    TreeItem item = (TreeItem) event.item;
    boolean checked = item.getChecked();
    checkItems(item, checked);
    checkPath(item.getParentItem(), checked, false);
    }
    }

    });

    return composite;
    }

    private void keyResponse(final Text input) {
    input.addKeyListener(new KeyAdapter() {
    public void keyReleased(KeyEvent e) {
    // String search = input.getText();
    if (e.character == '\u0008' || e.character == '\u007F') {
    System.out.println(treeCollection.size());
    for (int i = 0; i < treeCollection.size(); i++) {
    System.out.println("AAA");
    tree = treeCollection.get(i);
    }

    }

    searchNode(input.getText());
    }
    });
    }

    private void searchNode(String search) {

    int sign = 0;
    int sign2 = 0;
    int sign3 = 0;
    for (int j = 0; j < nodes.getLength(); j++) {

    TreeItem curReg = root;
    TreeItem curGetType = root.getItem(j);

    for (int i = 0; i < curReg.getItemCount(); i++) {
    // System.out.println("curReg.getItemCount() "
    // + curReg.getItemCount());

    if (curReg.getItem(i).getText().toLowerCase().indexOf (
    search.toLowerCase()) >= 0) {

    curReg.getItem(i).setExpanded(true);
    sign2 = 1;
    treeCollection.put(i, tree);
    System.out.println("treeCollection.put(i, tree) "
    + treeCollection.put(i, tree));

    } else if (sign2 == 1) {
    curReg.getItem(i).dispose();
    // System.out.println("BBB");
    sign2 = 0;
    } else if (sign2 == 0) {
    curReg.getItem(i).dispose();
    } else if (curReg.getItem(i).getText().toLowerCase().indexOf (
    search.toLowerCase()) <= 0) {
    // System.out.println("CCC");
    for (int k = 0; k < curGetType.getItemCount(); k++) {

    if (curGetType.getItem(k).getText().toLowerCase()
    .indexOf(search.toLowerCase()) >= 0) {
    curGetType.getItem(k).setExpanded(true);
    curGetType.getItem(k).getParentItem().setExpanded(
    true);
    sign = 1;

    // for (int curDispose = 0; curDispose <
    // curGetType.getItem(k).getItemCount();
    // curDispose++) {
    // System.out.println("DDD");
    // if(curGetType.getItem(curDispose).getText().toLowe rCase()
    // .indexOf(search.toLowerCase()) >= 0 &&
    // curGetType.getItem(curDispose).getExpanded() ==
    // false){
    // System.out.println("FFF");
    // curGetType.getItem(curDispose).getParentItem().dis pose();
    // }
    // }

    } else if (sign == 1) {

    curGetType.getItem(k).dispose();
    // } else if (curGetType.getItem(k).getExpanded() ==
    // false) {
    // System.out.println("DDD");
    // curGetType.getItem(k).getParentItem().dispose();
    //
    } else {
    System.out.println("EEE");
    curGetType.getItem(k).setExpanded(false);
    TreeItem curName = curGetType.getItem(k);

    for (int x = 0; x < curName.getItemCount(); x++) {
    if (curName.getItem(x).getText().toLowerCase()
    .indexOf(search.toLowerCase()) >= 0) {

    curName.getItem(x).setExpanded(true);
    curName.getItem(x).getParentItem()
    .setExpanded(true);
    // sign3 = 1;
    } else if (curName.getItem(x).getText()
    .toLowerCase().indexOf(
    search.toLowerCase()) <= 0) {
    curName.getItem(x).dispose();
    } else if (curName.getItem(x).getExpanded() == true) {
    curName.getItem(x).getParentItem()
    .dispose();
    }
    }

    }
    }

    }
    }

    }

    }

    private void checkPath(TreeItem item, boolean checked, boolean grayed) {
    if (item == null)
    return;
    if (grayed) {
    checked = true;
    } else {
    int index = 0;
    TreeItem[] items = item.getItems();
    while (index < items.length) {
    TreeItem child = items[index];

    // System.out.println("child " + child.getText() + "- "
    // + child.getGrayed() + "- " + child.getChecked()+checked);

    // if(checked != child.getChecked()){
    // child.setExpanded(true);
    // }

    if (child.getGrayed() || checked != child.getChecked()) {
    checked = grayed = true;
    break;
    }

    index++;
    }
    }
    item.setChecked(checked);
    item.setGrayed(grayed);
    checkPath(item.getParentItem(), checked, grayed);
    }

    private void checkItems(TreeItem item, boolean checked) {
    item.setGrayed(false);
    item.setChecked(checked);

    TreeItem[] items = item.getItems();
    // System.out.println("items " + items.length);
    for (int i = 0; i < items.length; i++) {
    checkItems(items[i], checked);

    }
    }

    protected void configureShell(final Shell shell) {
    super.configureShell(shell);
    if (title != null) {
    shell.setText(title);
    }
    }

    protected void buttonPressed(final int buttonId) {
    try {
    if (buttonId == OK_ID) {
    list = new LinkedList<Node>();
    collectFrom(root);
    setReturnCode(OK);
    } else {
    setReturnCode(CANCEL);
    }
    close();
    super.buttonPressed(buttonId);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    private void collectFrom(TreeItem item) {
    if (item.getItems().length > 0) {
    for (TreeItem child : item.getItems()) {
    collectFrom(child);
    }
    } else {
    if (item.getData() != null) {
    int i = ((Integer) item.getData()).intValue();
    nodes.setSelected(i, item.getChecked());
    if (item.getChecked()) {
    String name = item.getText();
    list.addLast(NodeLibrary.get(name));
    }
    }
    }
    }

    public List<Node> getNodes() {
    return list;
    }
    }

    /*
    thanx my man i'll be wait
    */
    Last edited by i4ba1; 08-26-2008 at 12:23 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    Sorry I don't have the org.eclipse.swt.widgets package.

  5. #5
    i4ba1 is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Red face huhuhu

    So Mr.Norm how the logic to make search function like eclipse(window->preference).Mr.norm what is your eclipse?my eclipse is rcp europe.I think the rcp europe have the full package for eclipse plugin.Oh ya please put your email.
    Last edited by i4ba1; 08-26-2008 at 03:04 PM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    Sorry, I don't use eclipse.
    I have no idea what"search function like eclipse(window->preference)" is.

Similar Threads

  1. Code for adding search function in an application
    By Avdhut in forum Threads and Synchronization
    Replies: 5
    Last Post: 03-03-2009, 10:15 AM
  2. how to search xml by SAX
    By eayx in forum XML
    Replies: 1
    Last Post: 07-05-2008, 11:51 AM
  3. binary search
    By tranceluv in forum New To Java
    Replies: 10
    Last Post: 01-14-2008, 07:13 PM
  4. Search
    By Gilgamesh in forum New To Java
    Replies: 5
    Last Post: 11-26-2007, 03:45 AM
  5. Web Search
    By Marcus in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-02-2007, 06:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •