Open two editors with the same label - eclipse

I've recently developed a new RCP application with eclipse e4 and now I have run into a problem that whenever I want to open another editor which has the same label, that I cannot open it because I always check if there is already an open editor with the same label and then grant this editor focus in order to bring it on top of the part stack.
I use a part descriptor to dynamically open an editor whenever the user double-clicks on a tree element and then uses the tree elements name as label. Now it can happen that some tree elements have the same label ...
Is there any other way in eclipse e4 I can check if an editor is already open, besides comparing the label of all open editors with the label of the editor I want to open?
Any help or pointers would be appreciated.

The default way is assigning an input uri while creating an editor (InputPart in e4)
MInputPart inputPart = MBasicFactory.INSTANCE.createInputPart();
inputPart.setInputURI("someInputUri");
And then you can call:
Collection<MInputPart> inputParts = partService.getInputParts("someInputUri");
Where partService is an instance of EPartService. You can manage a group of input parts using this approach.

Related

How can I use a non-IFileEditorInput as the default EditorInput in my plugin?

I am in the middle of creating an Eclipse plugin that will open an editor. Everything is mapped out well - my plugin.xml is set up correctly to open the editor for anything with the .xyz extension. The only thing holding me back is the IEditorInput.
I have a subclass of IEditorInput that I created for use with my editor. When I open the editor programmatically, I can create that EditorInput and open the editor correctly. However, when I open the editor using Project Explorer (Right click > Open With > My Editor), it is opened with a FileEditorInput.
How can I change the default behavior of Project Explorer to create the correct IEditorInput? Is there something in plugin.xml that I'm missing?
Thanks!
The editor doesn't get to choose the kind of editor input object it's given. It can use a IDocumentProvider to support different kinds of IEditorInput, but you should never artificially limit your editor to working with one kind of input, even if you do manage to change how the Project Explorer works.

How to split multipages editor in Eclipse

Eclipse allow users to split the Editor Area into more one space, giving ability to display two files at the same time ( or the same file if you duplicate it using Window->New Editor)
Is there anyway to split the editor window itself into multiple areas for editors with multiple pages ?
e.g.
Assume you are opening plugin.xml file, and you want to view "plugin.xml" tab/page next to "Extensions" tab/page.
The hard way is :
_- Open the desired plugin.xml file
_- From top toolbar, select Window->New Editor
_- Split the editor area into two areas
_- Select "plugin.xml" tab/page in one editor, and "Extension" tab/page in the other eidtor.
I would like to drag the tab/page to split just like we do for different editor.
If Eclipse does not provide that, Is it doable in custom editor , if Yes then How?
Thanks
No you can't do this with the multipage editors. These editors use the CTabFolder control to show the pages and this control only supports showing one page at a time.
Not sure what you mean by a custom editor. You could write a separate editor for each page so that you could then open these editors separately, which would allow the split. However this would be a huge amount of work.

Eclipse GEF graphical editor without header

I am developing RCP plug-in with GEF framework.
I've created basic graphical editor (GraphicalEditor and IEditorInput)
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.openEditor(new TEditorInput("T"), TGraphicalEditor.ID,false);
When I run the application I get editor with a header that contains the tab with the name of the editor and control buttons to maximize and minimize the editor.
What I need is to display just the editor, without the header.
Can it be done?
To my knowledge, it is not possible to just hide an editor's tab.
However, you can try two workarounds:
Have your GEF editor be displayed in an Eclipse view instead of an editor and open such a view as a standalone view. An example of how to open a GEF diagram in a view can be found in GEF's Directed Graph Example. An example of how to open a view as standalone can be found in one the Eclipse RCP official tutorials.
Extend the presentation factories extension point to control how workbench parts are displayed (which includes control over the part stack tab).
I suggest you try the first approach, as to me it seems easier to implement.
The idea with editors is that you can instantiate them multiply for different editor inputs. I am not aware of any way to restrict the number of open editors to just one (well, it appears you can in Eclipse 4.2 if that helps you)
For views, what you want can be done by setting the perspective to fixed and set showTitle of the org.eclipse.ui.perspectiveExtensions extension to false on the view. Maybe you can use a view instead of an editor and control the editor input yourself?
(For example, using an editor, the default Open action would instantiate a new editor, while you probably want to replace the contents in your only editor, right?)

Only one editor per file in eclipse?

Eclipse PDE documentation claims:
You can think of the input object as the document or file that is
being edited. Changes made in an editor are not committed until the
user saves them.
Only one editor can be open for any particular editor input in a
workbench page. For example, if the user is editing readme.txt in the
workbench, opening it again in the same perspective will activate the
same editor. (You can open another editor on the same file from a
different workbench window or perspective).
Obviously it is possible to open a file using different editors - for example .java file using default java editor, and then text editor (by 'open with'). Is this part of the documentation wrong? Or is IEditorInput different for these two editors? I'm just wondering.
It was like that originally, and I think their point was double-clicking on an already open file will just bring it to the front, not open a new editor with the same information. Tht's still true, but that's not the whole truth :-)
I believe that section needs to be expanded, as I'm pretty sure the capability you refer to has been there for years as well. There's a "New Editor" entry in the editor tab context menu that allows you to open the same file in the same type of editor too.

How to associate an Eclipse sample Editor with a file in project explorer view

I have an sample editor which opens up by selecting an action from a sample Menu created in the menu bar.
How do i associate this editor with a file in Project explorer view?
I mean if i double click on the file in project explorer view , the editor should spawn up.
Basically i want this editor to work like a regular eclipse editor.
Please let me know your suggestions or any online material which explains the framework on how to achieve this.
Thanks,
Karthik
Have a look at IWorkbenchPage.openEditor(IEditorInput input, String editorId). Here you specify the input object of the editor and the ID for the editor.
In a RCP application, the IEditorInput is usually made up by you - nothing fancy is needed unless you want to persist the editors - and ID is specified via the org.eclipse.ui.editors.