Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Modifying EMF createPages()(How to add my own controls to createPages()?)
Modifying EMF createPages() [message #1247932] Sun, 16 February 2014 20:00 Go to next message
Greg Dart is currently offline Greg DartFriend
Messages: 17
Registered: September 2013
Junior Member
Hi,

Having generated an EMF model & editor code, I want to create my own page/view and add some controls to it (combo boxes, groups, etc). How should I go about this please? My attempt is shown below, but clearly doesn't work - best I can manage is the display of one combo filling the entire view.

Do I need to create something like a view part (which I've done and laid out all my controls nicely - it's just not connected with my EMF code at all)? If it is a view part how do I link it to the EMF code (if not in createPages())?

All clues, hints, help appreciated.

Thanks,
Greg

	/**
	 * This is the method used by the framework to install your own controls.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void createPages() {
		// Creates the model from the editor input
		//
		createModel();

		// Only creates the other pages if there is something that can be edited
		//
		if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
			// Create a page .
			//
			
			Group grpSubject = new Group(getContainer(), SWT.NONE);
			grpSubject.setLocation(0, 43);
			grpSubject.setSize(219, 83);
			grpSubject.setText("Subject");
			// grpSubject.setLayout(new BoxLayout(BoxLayout.X_AXIS));
			
			final Combo cmbSubject = new Combo(getContainer(), SWT.READ_ONLY);
			final String osScopeItems[] = { "Product", "Customer", "Service", "Billing", "Resource", "F-P-T", "Network I/F", "Operations  H/O", "B2B", "Custom"  };
			cmbSubject.setItems(osScopeItems);
			
			cmbSubjectViewer = new ComboViewer(cmbSubject);
			setCurrentViewer(cmbSubjectViewer);
			
			cmbSubjectViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
			cmbSubjectViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
			cmbSubjectViewer.setInput(editingDomain.getResourceSet());
			cmbSubjectViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);

			int pageIndex = addPage(grpSubject);
			setPageText(pageIndex, getString("_UI_SelectionPage_label"));
			int x = getActivePage();
			setControl(x, cmbSubject);
			
		    DataBindingContext bindingContext = new DataBindingContext();
		    bindingContext.bindValue(ViewersObservables.observeSingleSelection(cmbSubjectViewer),
		    		EMFEditObservables.observeValue(editingDomain, ContractSpecEditorPackage.eINSTANCE.getSubject(), 
		    				(EStructuralFeature) ContractSpecEditorPackage.Literals.SUBJECT));
			

			getSite().getShell().getDisplay().asyncExec
				(new Runnable() {
					 public void run() {
						 setActivePage(0);
					 }
				 });
		}

		// Ensures that this editor will only display the page's tab
		// area if there are more than one page
		//
		getContainer().addControlListener
			(new ControlAdapter() {
				boolean guard = false;
				@Override
				public void controlResized(ControlEvent event) {
					if (!guard) {
						guard = true;
						hideTabs();
						guard = false;
					}
				}
			 });

		getSite().getShell().getDisplay().asyncExec
			(new Runnable() {
				 public void run() {
					 updateProblemIndication();
				 }
			 });
	}
Re: Modifying EMF createPages() [message #1248313 is a reply to message #1247932] Mon, 17 February 2014 05:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Greg,


On 16/02/2014 9:00 PM, Greg Dart wrote:
> Hi,
>
> Having generated an EMF model & editor code, I want to create my own
> page/view and add some controls to it (combo boxes, groups, etc). How
> should I go about this please? My attempt is shown below, but clearly
> doesn't work - best I can manage is the display of one combo filling
> the entire view.
This is more a question of how to create views using JFace, not an
EMF-specific question. To have a view with multiple things on it, you'd
need a Composite and using layouts https://wiki.eclipse.org/JFaceSnippets
>
> Do I need to create something like a view part (which I've done and
> laid out all my controls nicely - it's just not connected with my EMF
> code at all)? If it is a view part how do I link it to the EMF code
> (if not in createPages())?
You'll want to use data binding to bind something more specific than the
whole editing domain.
>
> All clues, hints, help appreciated.
>
> Thanks,
> Greg
>
>
> /**
> * This is the method used by the framework to install your own
> controls.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> @Override
> public void createPages() {
> // Creates the model from the editor input
> //
> createModel();
>
> // Only creates the other pages if there is something that can
> be edited
> //
> if
> (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
> // Create a page .
> //
>
> Group grpSubject = new Group(getContainer(), SWT.NONE);
> grpSubject.setLocation(0, 43);
> grpSubject.setSize(219, 83);
> grpSubject.setText("Subject");
> // grpSubject.setLayout(new BoxLayout(BoxLayout.X_AXIS));
>
> final Combo cmbSubject = new Combo(getContainer(),
> SWT.READ_ONLY);
> final String osScopeItems[] = { "Product", "Customer",
> "Service", "Billing", "Resource", "F-P-T", "Network I/F", "Operations
> H/O", "B2B", "Custom" };
> cmbSubject.setItems(osScopeItems);
>
> cmbSubjectViewer = new ComboViewer(cmbSubject);
> setCurrentViewer(cmbSubjectViewer);
>
> cmbSubjectViewer.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory));
> cmbSubjectViewer.setLabelProvider(new
> AdapterFactoryLabelProvider(adapterFactory));
> cmbSubjectViewer.setInput(editingDomain.getResourceSet());
> cmbSubjectViewer.setSelection(new
> StructuredSelection(editingDomain.getResourceSet().getResources().get(0)),
> true);
>
> int pageIndex = addPage(grpSubject);
> setPageText(pageIndex, getString("_UI_SelectionPage_label"));
> int x = getActivePage();
> setControl(x, cmbSubject);
>
> DataBindingContext bindingContext = new DataBindingContext();
> bindingContext.bindValue(ViewersObservables.observeSingleSelection(cmbSubjectViewer),
> EMFEditObservables.observeValue(editingDomain,
> ContractSpecEditorPackage.eINSTANCE.getSubject(),
> (EStructuralFeature)
> ContractSpecEditorPackage.Literals.SUBJECT));
I imagine this must thrown an exception given EClass (the third
argument) isn't an EStructuralFeature. You'll want to obverse some
value you get from the resource in the resource set, and you'll want to
specify a feature that value actually has.

http://www.vogella.com/tutorials/EclipseDataBindingEMF/article.html
>
>
> getSite().getShell().getDisplay().asyncExec
> (new Runnable() {
> public void run() {
> setActivePage(0);
> }
> });
> }
>
> // Ensures that this editor will only display the page's tab
> // area if there are more than one page
> //
> getContainer().addControlListener
> (new ControlAdapter() {
> boolean guard = false;
> @Override
> public void controlResized(ControlEvent event) {
> if (!guard) {
> guard = true;
> hideTabs();
> guard = false;
> }
> }
> });
>
> getSite().getShell().getDisplay().asyncExec
> (new Runnable() {
> public void run() {
> updateProblemIndication();
> }
> });
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Modifying EMF createPages() [message #1248365 is a reply to message #1248313] Mon, 17 February 2014 07:15 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

On 17/02/2014 05:56, Ed Merks wrote:
>
>>
>> Having generated an EMF model & editor code, I want to create my own
>> page/view and add some controls to it (combo boxes, groups, etc). How
>> should I go about this please? My attempt is shown below, but clearly
>> doesn't work - best I can manage is the display of one combo filling
>> the entire view.
> This is more a question of how to create views using JFace, not an
> EMF-specific question. To have a view with multiple things on it,
> you'd need a Composite and using layouts
> https://wiki.eclipse.org/JFaceSnippets
Have a look at WindowBuilder.

Regards

Ed Willink
Previous Topic:howto: "The chosen operation is not currently available"
Next Topic:etypes.ecore Model in CDO Source
Goto Forum:
  


Current Time: Thu Apr 25 12:52:24 GMT 2024

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

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

Back to the top