Results 1 to 3 of 3
  1. #1
    afrey is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Eclipse preference page with SWT.Tree

    I'm working on adding a preference page to my eclipse application (Juno). I would like create something similar to what you see on the following Eclipse preference page: Eclipse (Juno) > Window Menu > Preferences > Java > Compiler > Building. That preference page appears to be created using org.eclipse.swt.widgets, but they are using their internal package org.eclipse.jdt.ui, which I can't use, since it's an internal package. So, what I need is something similar to a org.eclipse.swt.widgets.Tree, with its own org.eclipse.swt.widgets.TreeItems that could take Composites. That is because I need to add StringFieldEditors and IntegerFieldEditors, or some type of fields (TextArea??), with some labels in front of them, that I could validate later on. From what I understand, it's not possible to add a Composite to a TreeItem, so how should I go around this problem? Since I can't use the Eclipse internal packages, is there other way to implement what I described above using the public API? Any suggestion is greatly appreciated. Thanks.

    Here is an idea, but this code places the TreeItems contents under the tree. Thoughts?

    Composite comp = getFieldEditorParent();

    Tree tree = new Tree(comp, SWT.NONE);
    tree.setLayout(new FillLayout());
    tree.setHeaderVisible(true);

    TreeItem item1 = new TreeItem(tree, SWT.NONE);
    item1.setText("Name1");

    TreeItem item11 = new TreeItem(item1, SWT.NONE);
    item11.setText("Name11");
    StringFieldEditor s11 = new StringFieldEditor(
    "name11",
    "label11:",
    comp);
    item11.setData(s11);

    TreeItem item12 = new TreeItem(item1, SWT.NONE);
    item12.setText("Name12");
    StringFieldEditor s12 = new StringFieldEditor(
    "name12",
    "label12:",
    comp);
    item12.setData(s12);


    item1.setExpanded(true);
    item11.setExpanded(true);
    item12.setExpanded(true);


    TreeItem item2 = new TreeItem(tree, SWT.NONE);
    item2.setText("Name2");
    Last edited by afrey; 02-22-2013 at 10:18 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Eclipse preference page with SWT.Tree

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    afrey is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: Eclipse preference page with SWT.Tree

    The problem was solved by using org.eclipse.ui.forms.widgets.ExpandableComposite.
    See the example below. I hope this helps someone :).

    protected final void createFieldEditors()
    {
    // Create the ScrolledComposite to scroll horizontally and vertically
    fScrolledComposite = new ScrolledComposite(
    getFieldEditorParent(),
    SWT.H_SCROLL | SWT.V_SCROLL);
    //Displays the scrollbars when the window gets smaller
    fScrolledComposite.setAlwaysShowScrollBars(false);
    // Sets the minimum size for the composite to work for scrolling
    fScrolledComposite.setMinSize(fCompositeWidth, fCompositeHeight);
    fScrolledComposite.setExpandHorizontal(true);
    fScrolledComposite.setExpandVertical(true);

    Composite composite = new Composite(fScrolledComposite, SWT.NONE);
    composite.setLayout(new GridLayout());
    fScrolledComposite.setContent(composite);
    // Sets up the toolkit.
    Display display = composite.getDisplay();
    toolkit = new FormToolkit(display);

    // Creates a form instance.
    form = toolkit.createForm(composite);
    form.getBody().setLayout(new GridLayout());
    form.setBackground(display.getSystemColor(SWT.COLO R_WIDGET_BACKGROUND));
    form.setText("Model: " + SignalGeneratorDevice.MODEL_ID);// Sets title of the Preference page

    // Add the three main nodes to the preference page
    addNode1();
    }

    /**
    * Adds the first node to the preference page
    */
    private void addNode1()
    {
    ExpandableComposite expandableComposite = createExpandableComposite(
    "Signal Generator Device Host/Port:",
    true);
    Composite childComposite = createChildComposite(expandableComposite);

    //Builds fields here (StringFieldEditor, IntegerFieldEditor, etc.)
    ..................
    }

    /**
    * Creates an ExpandableComposite that will be added to the preference page
    *
    * @param label
    * @param expanded
    * @return
    */
    private ExpandableComposite createExpandableComposite(
    String label,
    boolean expanded)
    {
    ExpandableComposite expandableComposite = null;
    if (expanded) {
    expandableComposite = toolkit.createExpandableComposite(
    form.getBody(),
    ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT
    | ExpandableComposite.EXPANDED);
    } else {
    expandableComposite = toolkit
    .createExpandableComposite(
    form.getBody(),
    ExpandableComposite.TWISTIE
    | ExpandableComposite.CLIENT_INDENT);
    }

    expandableComposite.setText(label);
    expandableComposite.setBackground(form.getBackgrou nd());
    expandableComposite.addExpansionListener(new ExpansionAdapter() {
    @Override
    public void expansionStateChanged(
    ExpansionEvent e)
    {
    form.pack();
    }
    });

    GridData gd = new GridData();
    expandableComposite.setLayoutData(gd);

    return expandableComposite;
    }

    /**
    * Creates a child composite for an ExpandableComposite
    *
    * @param expandableComposite
    * @return
    */
    private Composite createChildComposite(
    ExpandableComposite expandableComposite)
    {
    Composite childComposite = new Composite(expandableComposite, SWT.None);

    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    //gd.horizontalAlignment = GridData.END;
    childComposite.setLayoutData(gd);

    expandableComposite.setClient(childComposite);

    return childComposite;
    }

Similar Threads

  1. Display rich:tree in expandable mode when page loads with tree
    By rajpan in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 08-29-2012, 02:33 PM
  2. Replies: 6
    Last Post: 05-21-2012, 06:33 PM
  3. Replies: 1
    Last Post: 08-24-2009, 11:41 AM
  4. Replies: 5
    Last Post: 08-26-2008, 03:43 PM
  5. My Preference Dialog
    By schuetzejanett in forum Eclipse
    Replies: 3
    Last Post: 08-10-2007, 10:48 AM

Tags for this Thread

Posting Permissions

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