XML Editor´s SelectionProvider

<oXygen/> general issues.
SSC
Posts: 206
Joined: Thu Dec 01, 2011 4:22 pm
Location: Hamburg, Germany

XML Editor´s SelectionProvider

Post by SSC » Wed Jan 18, 2012 6:17 pm

Hello,

Currently I am trying to use the SelectionService of Eclipse to view meta data of our business objects in the Eclipse Property View like it is described in the http://www.eclipse.org/articles/article ... index.html tutorial.

Using the org.eclipse.core.runtime.adapters extension to build

Code: Select all

IAdapterFactory
s works quite well with our Objects and a suitable IPropertySource of those objects.

Now I would to know which kind of objects does the

Code: Select all

ISelectionProvider
of your XML Editor provide?

I want to achieve something similar like this :

Code: Select all

public class AuthorNodeAdapterFactory implements IAdapterFactory {

@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == IPropertySource.class) {
return new AuthorNodePropertySource((AuthorNode) adaptableObject);
}
return null;
}

@Override
public Class[] getAdapterList() {
return new Class[] { IPropertySource.class };
}

}
Unfortunately it seems that an AuthorNode is never provided by the SelectionService of Eclipse. But something similar must be provided I think because otherwise the outline view wouldn´t react either.
Hopefully this makes clear what I am aiming at, otherwise ask and I´ll try to describe my intent in more detail.
Simon Scholz
vogella GmbH
http://www.vogella.com

Radu
Posts: 6683
Joined: Fri Jul 09, 2004 5:18 pm

Re: XML Editor´s SelectionProvider

Post by Radu » Thu Jan 19, 2012 1:56 pm

Hi Simon,

I think I understand.

We have not been interested until now such extensions because we did not see benefits in implementing them.
For example our Author Outline implements an ISelectionProvider but does not manage listeners for firing selection events, so it's basically not functional.
Are you also interested in our Author page to implement such a selection provider? The Author page is 100% drawn on a Canvas so it lacks default support which would be available in a text viewer.

Are you interested in seeing in the Eclipse Properties view properties of a certain AuthorNode? If so, what properties would be useful to present for such an XML element? Or are you interested in calling the selection service from Eclipse and obtain the AuthorNode which is currently selected?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

SSC
Posts: 206
Joined: Thu Dec 01, 2011 4:22 pm
Location: Hamburg, Germany

Re: XML Editor´s SelectionProvider

Post by SSC » Thu Jan 19, 2012 3:34 pm

Hello Radu,
Or are you interested in calling the selection service from Eclipse and obtain the AuthorNode which is currently selected?
This is what I wanted to achieve.
Now I´ve done it like that :

Code: Select all


public class OxygenEditorSelectionProvider {

private WSEditorPage currentEditorPage = null;

private AuthorCaretListener caretListener = new AuthorCaretListener() {

@Override
public void caretMoved(AuthorCaretEvent caretEvent) {

IEditorPart activeEditor = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (activeEditor != null) {
ISelectionProvider selectionProvider = activeEditor.getSite()
.getSelectionProvider();
if (selectionProvider instanceof MultiPageSelectionProvider) {
StructuredSelection structuredSelection = new StructuredSelection(
caretEvent.getNode());
SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(
selectionProvider, structuredSelection);
((MultiPageSelectionProvider) selectionProvider)
.firePostSelectionChanged(selectionChangedEvent);
}
}
}
};

public OxygenEditorSelectionProvider() {
super();
init();
}

private void init() {
IPartListener partListener = new IPartListener() {

@Override
public void partOpened(IWorkbenchPart workbenchPart) {
if (workbenchPart instanceof WSEditor) {
final WSEditor ed = (WSEditor) workbenchPart;
partWSEditorChanged(ed);
ed.addPageChangedListener(new WSEditorPageChangedListener() {
@Override
public void editorPageChanged() {
OxygenEditorSelectionProvider.this
.partWSEditorChanged(ed);
}
});
}
}

@Override
public void partDeactivated(IWorkbenchPart arg0) {
// TODO Auto-generated method stub

}

@Override
public void partClosed(IWorkbenchPart arg0) {
// TODO Auto-generated method stub

}

@Override
public void partBroughtToTop(IWorkbenchPart arg0) {
// TODO Auto-generated method stub

}

@Override
public void partActivated(IWorkbenchPart arg0) {
// TODO Auto-generated method stub

}
};

IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
IPartService partService = activeWorkbenchWindow.getPartService();
partService.addPartListener(partListener);

IEditorPart activeEditor = activeWorkbenchWindow.getActivePage()
.getActiveEditor();
if (activeEditor instanceof WSEditor) {
final WSEditor ed = (WSEditor) activeEditor;
partWSEditorChanged(ed);
ed.addPageChangedListener(new WSEditorPageChangedListener() {
@Override
public void editorPageChanged() {
OxygenEditorSelectionProvider.this.partWSEditorChanged(ed);
}
});
}
}

private void partWSEditorChanged(WSEditor editor) {
WSEditorPage currentPage = editor.getCurrentPage();
if (currentPage instanceof WSAuthorEditorPage) {
if (!(currentPage.equals(this.currentEditorPage))) {
if (this.currentEditorPage instanceof WSAuthorEditorPage) {
((WSAuthorEditorPage) this.currentEditorPage)
.removeAuthorCaretListener(caretListener);
}
((WSAuthorEditorPage) currentPage)
.addAuthorCaretListener(caretListener);
this.currentEditorPage = currentPage;
}
}
}
}
I started thinking about the Adapter Framework, when I faced the problem of having different business objects(oxygens and ours).
In order to have those objects loosely coupled, also for objects which may come in the future , I decided to realize the communication of those objects between the viewparts with those adapters.
Are you interested in seeing in the Eclipse Properties view properties of a certain AuthorNode? If so, what properties would be useful to present for such an XML element?
As I mentioned in one of my former threads, we have one generic viewpart for showing meta information of a currently selected object in the RCP client. So this viewpart does nearly the same job as the standard property view, but in a more generic way. We want to avoid having several views for showing meta information about certain objects.

Regards,

Simon
Simon Scholz
vogella GmbH
http://www.vogella.com

SSC
Posts: 206
Joined: Thu Dec 01, 2011 4:22 pm
Location: Hamburg, Germany

Re: XML Editor´s SelectionProvider

Post by SSC » Thu Jan 19, 2012 4:32 pm

I forgot to response on that question:
If so, what properties would be useful to present for such an XML element?
We want to display the textcontent, the attributes and custom PIs over an AuthorNode.

I know you have the Attributes View which is great, but it would be another view so that it would break our wish to only have one view, which shows all the meta data of all objects.
Simon Scholz
vogella GmbH
http://www.vogella.com

Radu
Posts: 6683
Joined: Fri Jul 09, 2004 5:18 pm

Re: XML Editor´s SelectionProvider

Post by Radu » Thu Jan 19, 2012 6:32 pm

Hi Simon,

I understand, we will consider providing a better implementation for the selection providers both in the Author and Outline view.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply