Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » EMF Forms: Format correctly a custom field
EMF Forms: Format correctly a custom field [message #1755478] |
Fri, 03 March 2017 15:40 |
Jim 20100 Messages: 69 Registered: June 2016 |
Member |
|
|
Hi,
Here is my code below.
With such code I cannot control the height, the alignment and size of field etc.
I made several trial without success.
I put the composite in red by purpose, here is the result
Code:
Composite composite=new Composite(parent, SWT.NONE);
GridData gd_composite = new GridData(SWT.LEFT, SWT.TOP, true, false, 0, 0);
//gd_composite.heightHint = 25;
composite.setLayoutData(gd_composite);
composite.setBackground(QuotingPreference.INSTANCE.getMupAlertColor());
composite.setLayout(new GridLayout(3, false));
Label label=new Label(composite, SWT.NONE);
GridData gd_label = new GridData(SWT.LEFT, SWT.TOP, false, false, 0, 0);
gd_label.widthHint = 90;
// gd_label.heightHint = 25;
label.setLayoutData(gd_label);
label.setText("Country");
label.setAlignment(SWT.LEFT);
GridData gd_control = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
// gd_label.heightHint = 25;
Composite control = getControl(SWTControl.class,getResolvedDomainModelReference(QuotingPackage.eINSTANCE.getAddress_Country())).createControl(composite);
control.setLayoutData(gd_control);
Button btnCountryButton = new Button(composite, SWT.NONE);
btnCountryButton.setText("...");
|
|
| | | |
Re: EMF Forms: Format correctly a custom field [message #1755866 is a reply to message #1755833] |
Wed, 08 March 2017 17:20 |
Jim 20100 Messages: 69 Registered: June 2016 |
Member |
|
|
Hi,
emfforms 1.9
Here is the complete class:
package biz.astron.sales.quoting.ui.customcontrol;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Locale;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecp.edit.internal.swt.util.SWTControl;
import org.eclipse.emf.ecp.edit.spi.ECPAbstractControl;
import org.eclipse.emf.ecp.view.spi.core.swt.SimpleControlSWTRenderer;
import org.eclipse.emf.ecp.view.spi.core.swt.renderer.TextControlSWTRenderer;
import org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT;
import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.statushandlers.StatusManager;
import biz.astron.preferences.QuotingPreference;
import biz.astron.sales.quoting.QuotingPackage;
import biz.astron.sales.quoting.business.services.ParameterServiceDelegate;
import biz.astron.sales.quoting.business.services.dao.ICountry;
import biz.astron.sales.quoting.status.IQuotingStatus;
import biz.astron.sales.quoting.ui.Activator;
import biz.astron.status.AstronStatus;
import biz.astron.ui.dialog.TableSelectionDialog;
import biz.astron.ui.dialog.TableSelectionDialog.TableSelectionDialogObject;
import swing2swt.layout.FlowLayout;
public class CountryControl extends
ECPAbstractCustomControlSWT {
@Override
protected void disposeCustomControl() {
// TODO Auto-generated method stub
}
@Override
protected void handleContentValidation() {
// TODO Auto-generated method stub
}
@Override
public SWTGridDescription getGridDescription() {
return GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 1, null);
}
@Override
public Control renderControl(SWTGridCell cell, Composite parent)
throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
Composite composite=new Composite(parent, SWT.NONE);
GridData gd_composite = new GridData(SWT.LEFT, SWT.TOP, true, false, 0, 0);
//gd_composite.heightHint = 25;
composite.setLayoutData(gd_composite);
composite.setBackground(QuotingPreference.INSTANCE.getMupAlertColor());
composite.setLayout(new GridLayout(3, false));
Label label=new Label(composite, SWT.NONE);
GridData gd_label = new GridData(SWT.LEFT, SWT.TOP, false, false, 0, 0);
gd_label.widthHint = 90;
// gd_label.heightHint = 25;
label.setLayoutData(gd_label);
label.setText("Country");
label.setAlignment(SWT.LEFT);
GridData gd_control = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
// gd_label.heightHint = 25;
Composite control = getControl(SWTControl.class,getResolvedDomainModelReference(QuotingPackage.eINSTANCE.getAddress_Country())).createControl(composite);
control.setLayoutData(gd_control);
Button btnCountryButton = new Button(composite, SWT.NONE);
btnCountryButton.setText("...");
btnCountryButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Collection<TableSelectionDialogObject> entries = new ArrayList<TableSelectionDialogObject>();
TableSelectionDialog dialogCountry = new TableSelectionDialog(new Shell(Display.getCurrent()),entries);
try {
ArrayList<ICountry> countries = new ParameterServiceDelegate().getCountryList(Locale.getDefault());
for (ICountry country : countries){
TableSelectionDialogObject countryLine = new TableSelectionDialogObject();
countryLine.setColumnValue("label", country.getLabel() , 0);
countryLine.setColumnValue("value", country.getValue() , 0);
entries.add(countryLine);
}}
catch (Exception ex) {
AstronStatus status = new AstronStatus(IStatus.ERROR,Activator.PLUGIN_ID, IQuotingStatus.GET_COUNTRY_ERROR, IQuotingStatus.GET_COUNTRY_ERROR +": Unable to get countries" ,ex); //$NON-NLS-1$
// Let the StatusManager handle the Status and provide a hint
StatusManager.getManager().handle(status, StatusManager.LOG);
}
String currentValue = (String)getValue(getResolvedDomainModelReference(QuotingPackage.eINSTANCE.getAddress_Country()));
if (currentValue!=null)
dialogCountry.selectEntry("value",currentValue,0);
int result = dialogCountry.open();
if (result == IDialogConstants.OK_ID)
setValue(getResolvedDomainModelReference(QuotingPackage.eINSTANCE.getAddress_Country()), dialogCountry.getSelectedObject().getColumnValue("value", 0));
}
});
return composite;
}
}
|
|
| |
Re: EMF Forms: Format correctly a custom field [message #1755883 is a reply to message #1755877] |
Wed, 08 March 2017 22:04 |
Eugen Neufeld Messages: 174 Registered: May 2015 |
Senior Member |
|
|
Hi Jim,
so without trying the code (as it doesn't compile without the model as ed merks already wrote) I would recommend to check you grid layout configuration.
For the textbox you use:
GridData gd_control = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
I would change this to:
GridData gd_control = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
Furthermore as far as I can see you only want to add an additional button to a text control renderer. Check this tutorial with an example where a button is added in order to send emails:
http://eclipsesource.com/blogs/tutorials/how-to-customize-emf-forms/
You can also test the email example using the makeithappen examples which are part of the modeling package.
I would also recommend to update to emfforms 1.11 or 1.12
Cheers,
Eugen
--
Eugen Neufeld
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
|
|
| | |
Goto Forum:
Current Time: Tue Apr 23 13:43:35 GMT 2024
Powered by FUDForum. Page generated in 0.04270 seconds
|