Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Jim 20100 is currently offline Jim 20100Friend
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
index.php/fa/28653/0/

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 #1755604 is a reply to message #1755478] Mon, 06 March 2017 09:58 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 174
Registered: May 2015
Senior Member
Hi Jim,
what do you want to achieve?
Where should the controls be placed?
Could you provide a simple example to reproduce the issue?

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: EMF Forms: Format correctly a custom field [message #1755826 is a reply to message #1755604] Wed, 08 March 2017 13:38 Go to previous messageGo to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
Eugen,

As you can see, my custom field is not displayed correctly: the label is not aligned, the width of the field is not spread as the other fields, the height of the composite is too high (the red area).
You have he SWT code and the screenshot so I thought it was clear?

Regards
Jim
Re: EMF Forms: Format correctly a custom field [message #1755833 is a reply to message #1755826] Wed, 08 March 2017 14:02 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 174
Registered: May 2015
Senior Member
Hi Jim,

which method did you overwrite?
From which class did you subclass?
What is the emfforms version you used?

A lot of variables there, this is why a minimal running example helps to identify the problem easier.

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: EMF Forms: Format correctly a custom field [message #1755866 is a reply to message #1755833] Wed, 08 March 2017 17:20 Go to previous messageGo to next message
Jim 20100 is currently offline Jim 20100Friend
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 #1755877 is a reply to message #1755866] Wed, 08 March 2017 20:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Of course without your model, no one can compile this code to execute it and to test it...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Forms: Format correctly a custom field [message #1755883 is a reply to message #1755877] Wed, 08 March 2017 22:04 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
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/
Re: EMF Forms: Format correctly a custom field [message #1755899 is a reply to message #1755883] Thu, 09 March 2017 08:08 Go to previous messageGo to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
Hi,

Exactly what I did. I reproduce the email example. but I have another technical problem that I described in another post.
But anyway I wanted to know how to make a correct layout in this case.

Jim
Re: EMF Forms: Format correctly a custom field [message #1756070 is a reply to message #1755899] Fri, 10 March 2017 15:14 Go to previous message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 174
Registered: May 2015
Senior Member
Hi Jim,

did you try my suggestions?
Further more as far as I can see in your code you are not doing what is done in the email example. So instead of extending eg the text-control renderer you extended the ECPAbstractCustomControlSWT. I would not recommend this. It is much better to extend eg the SimpleControlSWTControlSWTRenderer.

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:EMF Forms: Customize derived field - Modification is ignored
Next Topic:[EMF Forms] : EEnum ComboCellEditor in TableControl?
Goto Forum:
  


Current Time: Tue Apr 16 08:03:20 GMT 2024

Powered by FUDForum. Page generated in 0.18991 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top