Results 1 to 3 of 3
- 02-22-2013, 08:44 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
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.
- 02-23-2013, 09:02 AM #2
Re: Eclipse preference page with SWT.Tree
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 02-28-2013, 10:58 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
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
-
Display rich:tree in expandable mode when page loads with tree
By rajpan in forum JavaServer Faces (JSF)Replies: 0Last Post: 08-29-2012, 02:33 PM -
Which is the more popular format for braces and what is your preference?
By EscSequenceAlpha in forum New To JavaReplies: 6Last Post: 05-21-2012, 06:33 PM -
Retrieve Node of tree in next page using jsp, struts tiles
By visiau in forum Advanced JavaReplies: 1Last Post: 08-24-2009, 11:41 AM -
make search function ike eclipse search in window->preference
By i4ba1 in forum Advanced JavaReplies: 5Last Post: 08-26-2008, 03:43 PM -
My Preference Dialog
By schuetzejanett in forum EclipseReplies: 3Last Post: 08-10-2007, 10:48 AM
Bookmarks