Eclipse RCP application Active Title Bar - java

I am working in an RCP application similar to Eclipse where the user can navigate in Project Explorer tree and opens any file in the Editor
i am Setting the RCP application title in a class which extends "WorkbenchWindowAdvisor" as the following:
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setTitle("My RCP Application title");
But what i need to show up in title bar the perspective name and the opened file path like in normal eclipse:
any suggestions
Thanks

This is requires listening to a lot of events in your WorkbenchWindowAdvisor.
In the preWindowOpen method you need to add listeners for:
Page activation and closing using configurer.getWindow().addPageListener(listener) The pageActivated and pageClosed listener methods need to update the title.
Perspective changes using configurer.getWindow().addPerspectiveListener(listener). The perspectiveActivated, perspectiveSavedAs, perspectiveDeactivated methods need to update the title.
Part activations using configurer.getWindow().getPartService().addPartListener(listener). This need to use an IPartListener2. The partActivated, partBroughtToTop, partClosed, partHidden, partVisible methods need to update the title.
You get the open file path from the active editor:
IWorkbenchPage currentPage = configurer.getWindow().getActivePage();
IEditorPart activeEditor = currentPage.getActiveEditor();
if (activeEditor != null) {
path = activeEditor.getTitleToolTip();
}
and the perspective name:
IPerspectiveDescriptor persp = currentPage.getPerspective();
if (persp != null) {
label = persp.getLabel();
}
The full, even more complex, code for this is in org.eclipse.ui.internal.ide.application.IDEWorkbenchWindowAdvisor

Related

Eclipse Plugin: Get editor state information

i have the following problem and am grateful for any help.
I start a batch processing for a file in my plugin and unfortunately I have to make sure that the file is closed in the text editor.
I also have to make sure that other editor references for the same file are closed.
Examples:
"Menu => Window => new Window
"Menu => Editor => Toggle Split Horizontal/Vertical and Clone.
This I have also hopefully managed to do
Here's my code:
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (IWorkbenchWindow window : windows) {
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorReferences = page.getEditorReferences();
for (IEditorReference editorReference : editorReferences) {
String name = editorReference.getName();
IEditorPart editorPart = editorReference.getEditor(false);
if (editorPart instanceof ITextEditor && name != null) {
// Here I note down various attributes, e.g. split
if (name.equals(memberName)) {
MPart mPart = editorPart.getSite().getService(MPart.class);
if (mPart != null) {
List<String> tags = mPart.getTags();
if (tags.contains(IPresentationEngine.SPLIT_HORIZONTAL)) {
openConfiguration.setSplitHorizontal();
} else if (tags.contains(IPresentationEngine.SPLIT_VERTICAL)) {
openConfiguration.setSplitVertical();
}
}
... // another attributes
// close Editor
page.closeEditor(editorPart, false);
}
}
}
}
Now I have the problem that the file is restored in the same state after the batch processing is finished. For example, if the user has done a "horizontal split" or a "clone" on the previously closed file, this should now be displayed exactly as before. When splitting, for example, also with the same ratio as before.
My solution is that I remember the relevant data before (when closing, see code above) and set it again after opening.
Question: Is this the right approach or is there a more elegant way?
Question: How do I determine the ratio for a split?
Question: How do I recognize a clone reference? ("Menu => Editor => Clone")
The plugin must run in an RCA that is still based on Eclipse 4.8 and supports the Eclipse 3.x API.

Eclipse plugin dev - How to show default IResource context menu in non-text custom editor?

I´m writing an Eclipse plugin to show the contents of an own file type in an own custom editor.
This file basically consists of 1..n IFile´s from the Project Explorer which are shown in a SWT TreeView.
The entries in this TreeView are some Beans organized in a flat List, but i provide an adapter to convert them to IFile´s.
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="de.dstg.delta.collections.model.Collection$Member"
class="de.dstg.delta.collections.CollectionMemberAdapterFactory">
<adapter
type="org.eclipse.ui.views.properties.IPropertySource2">
</adapter>
<adapter
type="org.eclipse.core.resources.IFile">
</adapter>
</factory>
</extension>
Eclipse Screenshot
It´s no problem to show a custom SWT menu but i think the right way is using the Eclipse menu structure, especially by providing default behaviour for Resources.
How can i show the default context popup menu, which is used by right-clicking resources in the Project Explorer, in my SWT TableView?
EDIT second question removed
EDIT2
According to the answer from greg-449, the problem remains that the context menu shows no entries i would like to have for this type of selection.
f.e. i need delete or open with or something like that 'file basics' without implementing it on my own.
We have also some other menus from additional plugins that should be visible here when the appropriate file type is selected. This works in Project Explorer but not in my table view.
I think the problem is the type of the selected element.
Plugin spy shows the following in my table view:
type of the selected element: Collection$Member,
interfaces valid for the selected element: IAdaptable
whereas the Project Explorer shows File and IFile, respectively.
My adapter works generally and delivers the related IFile while being triggered from an unknown Eclipse source.
I think i have to explicitely say, that the context menu should use the IFile type to get the correct menu entries but i dont´t know how.
Or did i miss something?
There isn't really a 'default' menu. Some menu items are defined to be added to all popup menus that define a specific place holder.
To use the place holder you must register your context menu with Eclipse, something like:
private void createContextMenu(Viewer viewer) {
Control menuControl = viewer.getControl();
MenuManager menuMgr = new MenuManager("#PopUp");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
#Override
public void menuAboutToShow(IMenuManager mgr) {
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(menuControl);
menuControl.setMenu(menu);
// register the context menu such that other plugins may contribute to it
getSite().registerContextMenu(menuMgr, viewer);
}
private void fillContextMenu(IMenuManager menu) {
// TODO add your actions
// Standard additions
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
You will probably also need to set your viewer as the 'selection provider':
getSite().setSelectionProvider(viewer);
Many menu items will check this to see what the type of the current selection is.
There is nothing that will automatically give you things like Open With or Delete, you have to add these yourself in the 'fillContextMenu' section.
You can use org.eclipse.ui.actions.OpenWithMenu for Open With.
IFile file = ... currently selected file
IMenuManager submenu = new MenuManager("Open With...");
submenu.add(new OpenWithMenu(getSite().getPage(), file);
menu.append(submenu);

How to rename the eclipse plugin menu programmatically

I am developing an eclipse plugin.I have given my menu,sub menu names and plugin id in plugin.xml.
I want to dynamically rename my plugin id as well my menu and sub menu name.I came across this SOF link.I am using the below code.
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
Menu menu = menuManager.getMenu();
String itemId = "plugin_menu_id";
IContributionItem item = menuManager.find(itemId);
System.out.println("item.getId() --> " + item.getId());
//gives the plugin_menu_id
System.out.println( "menu.getItemCount() ==> "+ menu.getItemCount());
//gives no of menus in eclipse
But unfortunately I am unable to find an option to rename the menu from IContributionItem.
So is there any other way to modify things in eclipse plugin?
I found a temporary solution .Instead of using a MenuManager,I created a dynamic menu using Actions Framework instead of Command Framework though the former is deprecated.
So each time , I create a Menu,I am able to change the Menu name,icon etc.
I am searching for an equivalent in the Command Framework and will post as soon as I found that.

Eclipse RCP 4.x - Defining workspace location

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)
Long story short:
I've got simple E4 application, product project, feature and main plugin with simple trim window.
Works, after exporting works too.
Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.
But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???
Of course I've tried with :
Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);
But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add
-data #noDefault in products Launching Arguments ... The same...
I always try to accomplish my tasks by myself but this.... this... ehh... Help ?
You should be able to do this in the #PostContextCreate method of the life cycle class. Don't specify the '-data' argument
#PostContextCreate
public void postContextCreate()
{
Location instanceLoc = Platform.getInstanceLocation();
// Stop if location is set
if (instanceLoc.isSet())
return;
File file = new File("C:\\TEST");
instanceLocation.set(file.toURL(), false);
}
Note: You need '\\' in your file path.
This is adapted from code which I use in my e4 RCP.
If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

Update two editor instance showing same file

I have eclipse rcp application, editor with ctabfolder in certain scenerio i am having editor instance further ctabfolder page those are showing file content. My problem is that if i opened same file in first editor and afer change made at file i opened another editor at application, now it showing the previous opened file not the updated one while i have made avaliable changed file for all process for opening another ediotr.
I am using this for creating editor input, I think this is culprit as it is in a singleton pattern and returning the already invoked instance of ctab page.
IFileStore fileStore = EFS.getLocalFileSystem().getStore("filepath");
if yes then tell me the appropriate replacement for this.
To make an editor be aware that the file it is editing has been changed by another editor you need to make the editor track resource changes using an IResourceChangeListener. Set this up with something like:
IResourceChangeListener resourceChange = new ResourceChange();
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChange, IResourceChangeEvent.POST_CHANGE);
The ResourceChange class would be:
private class ResourceChange implements IResourceChangeListener
{
#Override
public void resourceChanged(final IResourceChangeEvent event)
{
final IResourceDelta eventDelta = event.getDelta();
final IResourceDelta trackDelta = eventDelta.findMember(editFile);
if (trackDelta != null)
{
if ((trackDelta.getKind() & IResourceDelta.CHANGED) != 0 &&
(trackDelta.getFlags() & IResourceDelta.CONTENT) != 0)
{
// TODO handle change
}
}
}
}
editFile is the IFile the editor is working with.
You need to be careful how to handle the change because this will be invoked during the Save operation for the editor.

Categories

Resources