Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Parsley » Master-Detail Form Editor using Parsley
Master-Detail Form Editor using Parsley [message #1270882] Thu, 13 March 2014 18:30 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 526
Registered: November 2009
Senior Member
Hello,

I am trying to write a Master-Detail FormEditor and using Parsley as the base for communicating with my model. For this I took EmfAbstractEditor and made it extend FormEditor while adding necessary classes as described in Eclipse Forms: Rich UI for the Rich Client (Master/Details block).

The TreeViewer loads into section of the form. However, I am facing an issue that I am not sure what the cause of is. When I chose context menu from root node to add child, child is added successfully, but if I want to add another child nothing happens. I need to close the editor, open it again and only then I am able to add child. Another issue is where my model has constraint on an element of 1, if I add that element and open context menu to add children, that element is not disabled. Now, if I open my file with EmfTreeEditor everything works fine. I am not sure what's going on here so I was hoping to get some help here as someone might have faced the same issue.

Here are what I think the most relevant classes:

ScrolledPropertiesBlock
AbstractChannelComponentEditor
InletEditor (AbstractChannelComponentEditor extender)

Thanks,
Alex

[Updated on: Thu, 13 March 2014 18:31]

Report message to a moderator

Re: Master-Detail Form Editor using Parsley [message #1271167 is a reply to message #1270882] Fri, 14 March 2014 12:14 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1750
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 13/03/2014 19:30, Alex Kravets wrote:
> Hello,
>
> I am trying to write a Master-Detail FormEditor and using Parsley as the
> base for communicating with my model. For this I took EmfAbstractEditor
> and made it extend FormEditor while adding necessary classes as
> described in https://www.eclipse.org/articles/Article-Forms/article.html
> (Master/Details block).
>
> The TreeViewer loads into section of the form. However, I am facing an
> issue that I am not sure what the cause of is. When I chose context menu
> from root node to add child, child is added successfully, but if I want
> to add another child nothing happens. I need to close the editor, open
> it again and only then I am able to add child. Another issue is where my
> model cast constraint on an element of 1, if I add that element and open
> context menu to add children, that element is not disabled. Now, if I
> open my file with EmfTreeEditor everything works fine. I am not sure
> what's going on here so I was hoping to get some help here as someone
> might have faced the same issue.

Hi Alex

if it works fine with the EmfTreeEditor (thus you can add several
children, but the option is disabled with the constraint of 1), then
probably something is wrong with the injection and the added form editor
part.

We provide a form factory that already takes care of initializing the
form fields and setup databinding.

We still have to implement an editor with the treeviewer and the form;
however, we have a view with the treeviewer and the form (and the view
is saveable, thus it can act as an editor); would you mind try that view
and see if it all works fine?

In the meantime, I'll try to come up with a reusable implementation of
an editor with tree and form.

cheers
Lorenzo


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
Re: Master-Detail Form Editor using Parsley [message #1271224 is a reply to message #1271167] Fri, 14 March 2014 15:01 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 526
Registered: November 2009
Senior Member
Hi Lorenzo,

Yes, all the views Parsley provides work fine. Incidentally, with current attempt at Master-Detail editor I am experiencing the same issue when I was using Master-Detail editor page in generated EMF Editor. The only way TreeViewer works only if generated EMF viewer was already loaded, without it my TreeViewer would not work. I thought there was an issue with my implementation, but as I said same thing happens when I use Parsley emf editor as base. I've tried to debug the code, but so far didn't find anything.

Thanks,
Alex
Re: Master-Detail Form Editor using Parsley [message #1384541 is a reply to message #1271224] Thu, 29 May 2014 09:06 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1750
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 14/03/2014 16:01, Alex Kravets wrote:
> Hi Lorenzo,
>
> Yes, all the views Parsley provides work fine. Incidentally, with
> current attempt at Master-Detail editor I am experiencing the same issue
> when I was using Master-Detail editor page in generated EMF Editor. The
> only way TreeViewer works only if generated EMF viewer was already
> loaded, without it my TreeViewer would not work. I thought there was an
> issue with my implementation, but as I said same thing happens when I
> use Parsley emf editor as base. I've tried to debug the code, but so far
> didn't find anything.
>
> Thanks,
> Alex

Alex, if I remember correctly you posted in another forum that you
solved the issue, right?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
Re: Master-Detail Form Editor using Parsley [message #1604356 is a reply to message #1384541] Fri, 06 February 2015 20:26 Go to previous message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 526
Registered: November 2009
Senior Member
Hi Lorenzo,

Sorry didn't answer sooner as I didn't get notification that you replied and forgot to check this thread.

Here is my code for ScrolledPropertiesBlock:

 // Create a page for the selection tree view.
		 if (editor.getEditorInput() instanceof InMemoryChannelEditorInput) {
			 emfTreeViewer = new TreeViewer(tree);

			 DocumentRootImpl root = (DocumentRootImpl) ChannelFactory.eINSTANCE.createDocumentRoot();
			 root.setRInlineChannel(((InMemoryChannelEditorInput)editor.getEditorInput()).getChannel());

			 editor.getViewiInitializer().initialize(emfTreeViewer, root);
		 } else {
			 URI resourceURI = EditUIUtil.getURI(editor.getEditorInput());

			 LoadResourceResponse response = editor.getResourceLoader().getResource(editor.getEditingDomain(), resourceURI);

			 editor.handleProblems(response);

			 emfTreeViewer = editor.getTreeViewerFactory().createTreeViewer(tree, resourceURI);
			 editor.getViewiInitializer().initialize(emfTreeViewer, response.getResource());
			 enableCellEditing();
		 }

		 emfTreeViewer.setContentProvider(new AdapterFactoryContentProvider(editor.getAdapterFactory()));
		 ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator();
		 ChannelValidator channelValidator = ((ChannelEditor)editor).getChannelValidator();
		 ChannelTreeViewerDecorator labelDecorator = (ChannelTreeViewerDecorator) PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(ChannelTreeViewerDecorator.ID);
		 labelDecorator.setChannelValidator(channelValidator);
		 emfTreeViewer.setLabelProvider(new DecoratingStyledCellLabelProvider(new ChannelAdapterFactoryLabelProvider(editor.getAdapterFactory(), tree.getFont(), ((ChannelEditor)editor).getDescriptorUtils()), labelDecorator, null));

		 editor.setSelectionOnRoot(emfTreeViewer);

		 new AdapterFactoryTreeEditor(emfTreeViewer.getTree(), editor.getAdapterFactory());

		 editor.createContextMenuFor(emfTreeViewer);

		 emfTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			 public void selectionChanged(SelectionChangedEvent event) {
				 Object selectedObject = ((StructuredSelection)event.getSelection()).getFirstElement();
				if (previousSelection != null && previousSelection.equals(selectedObject)) {
					 return;
				 }
				 previousSelection = selectedObject;
				 managedForm.fireSelectionChanged(spart, event.getSelection());
				 buttonsStateProvider(event.getSelection());
			 }

			 private void buttonsStateProvider(ISelection iSelection) {
				 EObject object = (EObject) ((StructuredSelection) iSelection).getFirstElement();
//				 if( object instanceof Inlet
//						 || object instanceof Route
//						 || object instanceof Outlet
//						 || object instanceof Transformer){
//
//					 List<String> extList = ChannelActivator.instance.getSupportedFileExtensions();
//					 if(extList.size() > 1){
//						 importComponentButton.setEnabled(true);
//					 }
//				 }

				 updateUpDownBtnEnablement(object);
				 btnRemove.setEnabled(true);
			 }
		 });

		 emfTreeViewer.addSelectionChangedListener(editor.createSelectionChangedListener());

		 emfTreeViewer.expandAll();

		 emfTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

			 @Override
			 public void doubleClick(DoubleClickEvent event) {
				 Object selection = ((StructuredSelection)event.getSelection()).getFirstElement();
				 if(selection instanceof Reference && ((Reference)selection).getRefId() != null) {
					 try {
						 String guid = ((Reference)selection).getRefId();
						 DependencyType dependencybyGUID = IWResourceManager.getInstance().getDependencybyGUID(((FileEditorInput) editor.getEditorInput()).getFile(), guid);
						 if (dependencybyGUID != null) {
							 IResource resource = WorkspaceUtil.getResource(new Path(dependencybyGUID.getPath()));
							 if (resource != null && resource instanceof IFile) {
								 WorkspaceUtil.openFileInEditor((IFile) resource);
							 }
						 }
					 } catch (CoreException e) {
						 return;
					 }
				 }
			 }
		 });

		 // set selection on element that was last added to the model
		 editor.getEditingDomain().getCommandStack().addCommandStackListener(new CommandStackListener() {
			 @Override
			 public void commandStackChanged(EventObject event) {
				 Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand();

				 if (mostRecentCommand != null) {
					 if(mostRecentCommand instanceof CreateChildCommand){
						 CreateChildCommand command = (CreateChildCommand)mostRecentCommand;
						 Collection<?> result = command.getResult();
						 Object next = result.iterator().next();

						 TreeItem item = new TreeItem(tree.getTopItem(), SWT.NONE);
						 item.setData(next);
						 emfTreeViewer.setSelection(new StructuredSelection(next), true);
						 emfTreeViewer.refresh();
					 }

				 }
			 }
		 });


Th most relevant code is last EditingDomain listener:

editor.getEditingDomain().getCommandStack().addCommandStackListener(new CommandStackListener() {
Previous Topic:Xtext 2.6.0 and Luna
Next Topic:Executing RecordingCommand using InjectableAdapterFactoryEditingDomain
Goto Forum:
  


Current Time: Sat May 26 23:22:07 GMT 2018

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

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

Back to the top