How to dynamically a tabs in a perspective

Hi everyone,

I have created a perspective with two CDockables, the rightPanel and the leftPanel, each of them taking half the grid.

In the leftPanel, I can select text files in a tree view. When double-clicking a text file, I want it to appear in a text editor on the rightPanel (by default, there is already a “tab” in the right panel, I want to add one more for each opened text file).

How can I do that?

I tried directly adding a CDockable wrapping the text editor in the existing perspective like this:

private final void editSelectedFile() {
    final TextEditor textEditor = new TextEditor(selectedFile);

    CPerspective perspective = perspectivesMap.get(perspectiveName);
    final String uniqueId = String.valueOf(counter.incrementAndGet());
    final DefaultSingleCDockable dockable = new DefaultSingleCDockable(uniqueId, selectedFile.getName(), textEditor);
    control.addDockable(dockable);

    final CGridPerspective center = perspective.getContentArea().getCenter();
    center.gridAdd(50, 0, 50, 100, new SingleCDockablePerspective(uniqueId));
    perspectives.setPerspective(perspectiveName, perspective);
    control.load(perspectiveName);
}

My problem is that if I close the text editor for file1.txt and open a new editor for file2.txt, the editor of file1.txt appears again. This is normal, it is registered in the perspective… But this is not the behaviour the user expects…

What I want is to insert the new CDockables in the current view, at the correct place, and not to add them in the perspective itself.

The documentation on perspectives is rather limited and I could’nt find how to do it. Can anyone help?

Kind regards

Perspectives are not that well suited for this kind of task. Perspectives are meant to be used if you don’t want to create Dockable-objects, but if you already have them using perspectives just adds a lot work without much benefit.

Personally I would insert a CWorkingArea at the right side, and then add the text-editor-dockables to that area. This would produce a behavior that is very similar to Eclipse. When opening a new text-editor-dockable you would select an existing one (if there is one), access its location with “getBaseLocation”, use “CLocation.aside” to create a new location, and then call “setLocation” on the new dockable with the new location. The new dockable then appears on “the next tab”, as near as possible to the dockable that was already visible.

If you wish an example, please let me know.