aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Eclipse preference page with SWT.Tree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Eclipse preference page with SWT.Tree" Watch "Eclipse preference page with SWT.Tree" New topic
Author

Eclipse preference page with SWT.Tree

Alina Frey
Greenhorn

Joined: Feb 22, 2013
Posts: 4
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");


[Thumbnail for SWT-Tree.jpg]

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4527
    
    5

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


luck, db
There are no new questions, but there may be new answers.
Alina Frey
Greenhorn

Joined: Feb 22, 2013
Posts: 4
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;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Eclipse preference page with SWT.Tree