Programatically manipulating the Eclipse RCP EditorArea Sashes - eclipse

I have an eclipse RCP application that uses and Editor Area. I have a few things that I would like to do programatically but cannot find any documentation:
1) Do not restore editor sash layout. I.e., I like to use rcp saveAndRestore functionality, but for my perspectives, views, and other momentos. I do not however want to restore the editor area multiple tab groups at all. I choose not to implement the IPersistableEditor interface, and therefore my editor sessions are not restored, but when my application restarts, it still has split windows (swt sashes for multiple tab groups), etc, and i wish it was just 1 editor area tab group like default.
2) I would like to programaticaly split/duplicate an editor into another tab group, for example I would like a button that says "Split Horizontal" and that opens a new editor in a new tab group beside the current one.
Any help is much appreciated! Happy Coding!
/P

1) Funny, seems like a bug in the platform.
You can explicitly close all editors upon workbench window close. One option to do this would be to override the preWindowShellClose method in your WorkbenchWindowAdvisor:
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
#Override
public boolean preWindowShellClose() {
getWindowConfigurer().getWindow().getActivePage().closeAllEditors(true);
return super.preWindowShellClose();
}
}
If you don't have access to the ApplicationWorkbenchWindowAdvisor, you can try to do the same with the IPerspectiveListenerX
2) I think there is no public API for this. The editor area behavior is defined in the presentation factory (see org.eclipse.ui.presentationFactories extension-point). You could clone the RCP standard presentation and implement the desired split-editor-area-on-demand functionality.

Related

Build a Perspective from Fragment with Eclipse e4

Is it possible to define a perspective stack and perspective in the fragment.e4xmi?
The Eclipse 4 model editor doesn't seem to allow it. Why?
I add a new Model Fragment and for Feature Name I click Find ....
When I want to add a Perspective or a Perspective Stack, the dialog greys out the OK-Button.
Also, I have a lack of understanding what this Dialog is showing in general. It lists certain UI Elements and a lot of items below them, like
children
handlers
menus
and so on.
But those are listed multiple times. For example children is listed under CompositePart and under Dialog. But it doesn't make any difference which one I chose.
I know I can define the Perspective in the plugin.xml using the extension point and implementing IPerspectiveFactory. Is there no way to do it with the fragment.e4xmi?
Not sure about that dialog as I don't usually use it.
What you want to add is a Model Fragment with the 'Extended Element-ID' set to the id of the TrimmedWindow you want to put the perspective in. The 'Feature Name' would be children.
The model editor should then let you add a "Perspective Stack" as a child.
You can add the Perspective to the stack.
Note: Using the plugin.xml and IPerspectiveFactory is for Eclipse 3.x compatability mode, not pure e4. If you are using compatability mode I'm not sure how defining a perspective in the model editor fits.

Eclipse 4 RCP Application (standalone!): Add "show view" in menu

In my standalone RCP Application (which I start using a product configuration) I would like to add a menu entry "show view" that lists all views I have defined in my persistent application model (an application.e4xmi file) being closed.
Currently I do not have any Advisor Classes in use.
What I did was to manually add HandledMenuItems for each view and added a CoreExpression as Visible-When Expression.
This expression tests for a special key value pair in the application context. The problem here is that I would need a special expression for each view.
What would be a good pattern to solve this problem?
Or is there a way to parametrize the core expression?
Could I use any predefined eclipse plugins / commands / handlers?
Update: Instead it would also be okay to have the Window > Show View structure in my standalone RCP application - exactly like it exists in the Eclipse workbench. Is there a way to add this menu (entry) by using any predefined / available means?
I'm not sure if this helps you, because it's eclipse 3.7 code, but you can give it a try.
I added a dynamic menu contribution to the View menu like so:
<menu id="x.y.menu.views label="%menu.window.label">
<dynamic class="x.y.menu.ViewListMenuContribution" id="viewlist" />
</menu>
In that class, I used one of the the eclipse menu factories to actually fill the menu:
#Override
public void fill(Menu menu, int index)
{
super.fill(menu, index);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IContributionItem item = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
if (item != null)
item.fill(menu, index);
}
This should show all views that are currently closed.
There is currently no way to do that, except keeping track of the parts yourself and reopening them with the EPartService

Remove "Quick Access" entry in Eclipse Juno

How do I remove the "Quick Access" text entry from Juno's CDT toolbar? I never use it and it consumes valuable space on my laptop screen.
This bug Make "Quick access" optional and hidden by default covers it. It looks like it is not currently possible, I suggest you add your interest to the bug.
I looked for an answer to this question because Quick Access took a full row in the toolbar. Instead of removing it (Which requires too much hacking for my taste), I just removed a few toolbar buttons that I didn't use anyway, and the Quick Access shifted up among the rest of the buttons taking only an acceptable amount of space.
There is really no need for that many buttons for any one perspective. They should fit unless your screen is tiny. Customise this in Window -> Customize Prespective...
Here is a quick hack which doesn't require any plugin installation, instead you just need to add a few lines to your current layout's CSS file. Works perfectly for me in v4.2.2
Navigate to <ECLIPSE_HOME>/plugins/org.eclipse.platform_<VERSION>/css then open up the CSS file of whichever layout you are using, e.g. mine was e4_default.css. Now append the following snippet to the file:
#SearchField {
visibility:hidden;
}
Now just restart Eclipse and the box is gone.
*Edit
It appears that the layout file e4_basestyle.css is used universally, regardless of your current layout. Thus you should be able to add the above snippet to that file and this fix will be persistent, even if you change layouts.
In Luna this has been fixed.
You can just right click on Quick Access toolbar and click hide to hide it. Refer last few comments in https://bugs.eclipse.org/bugs/show_bug.cgi?id=362420
A solution inspired from :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=319991
(With eclipse Juno 4.2) Just add this piece of code to your ApplicationWorkbenchWindowAdvisor class and call the method from preWindowOpen().
private void hideQuickAccess() {
UIJob job = new UIJob("hide quick access") {
#Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
if (window instanceof WorkbenchWindow) {
MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
for (MTrimElement element : topTrim.getChildren()) {
if ("SearchField".equals(element.getElementId())) {
((Control) element.getWidget()).dispose();
break;
}
}
}
return Status.OK_STATUS;
}
};
job.schedule();
It might not work unless changing the accessibility rule of the org.eclipse.e4.ui.model.workbench.source_0.10.1.v20120523-1955.jar.
To change this option, go to the Java build Path menu, find the jar, expand it and the option will appear.
NB: I'm not sure about the entailment of this last change, it could be 'not clean'.
Check out this plugin: https://github.com/atlanto/eclipse-4.x-filler#hide-quick-access-plug-in
Works with Eclipse Kepler release.
This plug-in adds a functionality to hide/show Quick Access textbox in the main toolbar.
Window ☞ Hide Quick Access
Solution for Version: Oxygen Release (4.7.0):
Save the icons you are constantly using by dragging them off the "Toolbar" e.g. left/right/under to the Editor.
Then toggle: Window > Appearance > Hide/Show Toolbar
Done. :)
Type "toggle toolbar" in the quick access window (yes, that very thing that annoys us) and it'll be gone. C.f.

Is there a way to integrate Properties View within the Eclipse Multipage editor?

I am trying to implement an Eclipse editor which consists of a design part, Palette part and the Properties part for the selected palette item. All in the same editor page.
After a long time of googling, I have come to know that there are no proper articles or examples for this issue. Is there some solution that I could get from anyone here?
The SWT Design editor implements this feature in its editor. However, I am unable to access its source.
To access the properties view, you have to have three things:
Your editor must define its SelectionProvider (getSite().setSelectionProvider()). A SelectionProvider is either a JFace Viewer, or can be any class that return a corresponding ISelection interface.
The objects returned by the ISelection must either implement IPropertySource or return an IPropertySource adapter using the getAdapter(IPropertySource.class).
In multi-page editors you have to make sure, that the SelectionProvider also returns what expected.
For details about the first two point, see the following Eclipse Corner article: Take control of your properties, or if you would like to use the Tabbed properties view seen in GMF editors, The Eclipse Tabbed Properties View.

Eclipse RCP application - multi-window design for multiple monitors

Question about Eclipse RCP and whole perspective/view/editor design - what is the best way to create application which will display multiple windows on multiple monitors? Tutorials and book I've seen always pack RCP/SWT design into views inside perspective within single application window.
Should one window rule all others or they all should be equal (closing last one exits application)? How deal with the perspectives and views? Are there any other things we should know?
Environment: Eclipse Ganymede, Windows XP.
A single Eclipse workbench can create multiple windows. Each window is laid out using a perspective, so different windows could be set to different perspectives, or the same perspective, and you can switch perspectives in each window independently of the other windows.
You can also set input for each window. This is useful if each window is working on different data (for example, each window could be connected to a different server or could be showing data from different databases that all have the same schema but different data).
It may be that you are using windows only so that you can see different perspectives of the same data on different monitors. In that case you do not need to programatically create the windows but need only add the action supplied by the workbench. This can be done by modifying your ActionBarAdvisor class:
add to the field declarations:
private IWorkbenchAction newWindowAction;
add to the code where you make the actions (typically a method called makeActions):
newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(window);
register(newWindowAction);
add to the code where you create the menus:
menu.add(newWindowAction);
where menu is typically the Window menu. If you don't have a Window menu already in your application and would like to create one, the following line will work:
MenuManager menu = new MenuManager(
"&Window",
IWorkbenchActionConstants.M_WINDOW);
This will give you a menu item that will create a new window in the same way as the Window->New Window menu item in the Eclipse IDE.
If, on the other hand, you want each window to show different data then you will need to open the new windows programatically. This allows you to set different input for each window. You will need a line of code something like:
IWorkbenchPage newPage = window.openPage(inputObject);
where inputObject contains information that identifies the data shown in the window. If you want to set the initial perspective this can be done by calling setPerspective on the page.
You will want to set the title in each window:
newPage.getWorkbenchWindow().getShell().setText(windowTitle);
where windowTitle is a string describing the input to the window.
You can fetch the input for a window as follows:
window.getActivePage().getInput()
You can then cast this to whatever class you are using as your window input.