Reputation: 1003
I am trying to create a custom form editor page. Inside the form page I needs to have a table where I can list key value pairs. The properties list table I want to create as a reusable component.
I have created the form but there is unwanted space coming before the properties table composite(see image below). How can I get rid of this empty space?
Below is my code for the form page
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.editor.FormPage;
public class EnvironmentPage extends FormPage {
public EnvironmentPage(FormEditor editor) {
super(editor, Activator.PLUGIN_ID + ".amf.environment", "Environment");
}
@Override
protected void createFormContent(IManagedForm managedForm) {
FormToolkit toolkit = managedForm.getToolkit();
ScrolledForm form = managedForm.getForm();
form.setText("Environment");
Composite body = form.getBody();
GridLayout gridLayout = new GridLayout(2, true);
body.setLayout(gridLayout);
toolkit.paintBordersFor(body);
Composite leftComposite = toolkit.createComposite(body, SWT.NONE);
leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout leftCompositeLayout = new GridLayout();
leftCompositeLayout.marginWidth = 0;
leftCompositeLayout.marginHeight = 0;
leftComposite.setLayout(leftCompositeLayout);
createPropertiesSection(toolkit, leftComposite);
Composite rightComposite = toolkit.createComposite(body, SWT.NONE);
rightComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout rightCompositeLayout = new GridLayout();
rightCompositeLayout.marginWidth = 0;
rightCompositeLayout.marginHeight = 0;
rightComposite.setLayout(rightCompositeLayout);
// TODO Controls on left composite
super.createFormContent(managedForm);
}
private void createPropertiesSection(FormToolkit toolkit, Composite leftComposite) {
Section section = toolkit.createSection(leftComposite,
ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE);
section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
section.setText("Log4J Properties");
Composite log4jComposite = toolkit.createComposite(section, SWT.BORDER);
toolkit.adapt(log4jComposite);
GridLayout gridLayout = new GridLayout();
gridLayout.marginBottom = 0;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
log4jComposite.setLayout(gridLayout);
log4jComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
section.setClient(log4jComposite);
PropertiesEditor propsEditor = new PropertiesEditor(log4jComposite, SWT.NONE) {
@Override
public void loadData() {
// TODO Auto-generated method stub
}
};
propsEditor.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
toolkit.paintBordersFor(section);
}
}
Below the properties editor class
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.forms.widgets.FormToolkit;
public abstract class PropertiesEditor extends Composite {
protected FormToolkit toolkit;
protected Button btnRemove;
protected Button btnAdd;
protected Table propertiesTable;
public PropertiesEditor(Composite parent, int style) {
super(parent, style);
toolkit = new FormToolkit(parent.getDisplay());
createComposite(parent);
}
private void createComposite(Composite parent) {
Composite propertiesGroup = toolkit.createComposite(parent, SWT.BORDER);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginWidth = 1;
gridLayout.marginHeight = 1;
gridLayout.verticalSpacing = 1;
propertiesGroup.setLayout(gridLayout);
propertiesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
propertiesTable = toolkit.createTable(propertiesGroup, SWT.BORDER | SWT.FULL_SELECTION);
propertiesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
propertiesTable.setHeaderVisible(true);
propertiesTable.setLinesVisible(true);
propertiesTable.setData("name", "properties-table");
toolkit.adapt(propertiesTable, true, true);
TableColumn tableColumnKey = new TableColumn(propertiesTable, SWT.NONE);
tableColumnKey.setText("Key");
TableColumn tableColumValue = new TableColumn(propertiesTable, SWT.NONE);
tableColumValue.setText("Value");
propertiesTable.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
tableColumnKey.setWidth((int) (propertiesTable.getClientArea().width * 0.3));
tableColumValue.setWidth((int) (propertiesTable.getClientArea().width * 0.7));
}
});
Composite buttonsGroup = toolkit.createComposite(propertiesGroup, SWT.NONE);
buttonsGroup.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, true, 1, 1));
GridLayout buttonsLayout = new GridLayout();
buttonsLayout.marginWidth = 10;
buttonsGroup.setLayout(buttonsLayout);
new Label(buttonsGroup, SWT.NONE);
new Label(buttonsGroup, SWT.NONE);
btnAdd = toolkit.createButton(buttonsGroup, "Add", SWT.NONE);
GridData gd_btnAdd = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
gd_btnAdd.widthHint = 60;
btnAdd.setLayoutData(gd_btnAdd);
toolkit.adapt(btnAdd, true, true);
btnRemove = toolkit.createButton(buttonsGroup, "Remove", SWT.NONE);
GridData gd_btnRemove = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
gd_btnRemove.widthHint = 60;
btnRemove.setLayoutData(gd_btnRemove);
toolkit.adapt(btnRemove, true, true);
}
public abstract void loadData();
}
Upvotes: 0
Views: 175
Reputation: 111216
Your PropertiesEditor
extends Composite
but then you are not doing anything with that composite and instead creating another Composite
in the createComposite
method whose parent is the parent passed to the PropertiesEditor
constructor. I think the gap at the top is the PropertiesEditor
composite.
Upvotes: 2