• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eclipse preference page with SWT.Tree

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 (please see the attachment). 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");
SWT-Tree.jpg
[Thumbnail for SWT-Tree.jpg]
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alina Frey, welcome to the Ranch! Please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/swt-jface/69217-eclipse-preference-page-swt-tree.html
http://stackoverflow.com/questions/15027839/eclipse-preference-page
 
Alina Frey
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.COLOR_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.getBackground());
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;
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic