Is there some easy way to reopen closed tabs in Netbeans RCP application?
I have a module application with several modules that each has some topComponents (explorers, editors etc.) but when I close some tab (using the "x" symbol), it stays closed even during next startup and I cant seem to find any way how to restore it.
All the components contains #TopComponent.Registration(mode = "explorer", openAtStartup = true)
The components also contains this:
#TopComponent.Description(
preferredID = "ProductionExplorer",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
What am I missing here?
The persitence type of the top component is set to "always", that means the state of the component will allways be stored when you close the application. Whether it is closed or opened. If you change to PERSISTENCE_NEVER, it won't be saved.
To reset the windows you have to use the menu item "Reset Windows" under "Windows".
Related
In my current project, there is a situation where we have one file let's say "File1.cfg" in project explorer. There is a default editor "Editor 1" registered using "*.editors" extension.
Requirement Function:
When a user double click on the File1.cfg, it should be opened with an "Editor 1" by default and all the time.
There is one more option provided in Toolbar which will be used to open "Editor 2". And this editor should use the resource "File1.cfg" and display the contents as per the UI.
How can this be achieved in the Eclipse?
A plug-in can specify the editor id to be used when opening an editor. See IWorkbenchPage.openEditor and IDE.openEditor.
Normally these APIs check for an editor (of any id) already being open on the file. If you want to force the editor with the given id to open regardless you need to use the IWorkbenchPage method:
IEditorPart openEditor(IEditorInput input, String editorId, boolean activate,
int matchFlags)
with the matchFlags value set to:
IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT
to only match an existing editor with the same id and input.
Here is my specific scenario:
I have my application running in the background and I want to open a new window from my applications toolbar icon right click menu. For simplicity I am using a MessageDialog, and using the method open() on the dialog, the window should display and make itself the active window.
For some reason I've run into the problem that if I had some other application open and I try to open this new dialog, it opens, but behind the active application. The new dialog will open in front of the other windows of the same application, but not the other(active) application.
Is there a simple way to do this that I'm missing?
I was able to find a solution. Essentially you need to find your active workbench shell(the application shell) and use the following methods on that shell, followed by pushing the actual desired window to the front.
You could easily modify this to make your window appear maximized as well by adding the method shell.setMaximized(true) before the redraw.
private static void bringupDialog(WindowState state) {
final Shell workbenchShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
//bring up the application to front
workbenchShell.setVisible( true );
workbenchShell.setMinimized( false );
workbenchShell.redraw();
//focus on dialog
workbenchShell.setActive();
workbenchShell.forceActive();
workbenchShell.setFocus();
workbenchShell.forceFocus();
workbenchShell.moveAbove( null );
workbenchShell.redraw();
Shell shell = instance.getShell(); // desired window shell
shell.setActive();
shell.forceActive();
shell.setFocus();
shell.forceFocus();
shell.moveAbove( null );
shell.redraw();
}
In a RCP application, I change the locale by programatically setting it in the .ini file and restarting the application.
The problem is that view titles, which are defined in OSGI-INF/l10n files referred from the plugin.xml file, aren't updated until I focus them.
For example after having switched from EN to FR, I have this :
It's only after I click on the second tab that I get this :
I can't reset the perspectives as they may have been changed by the user (view resized, removed or added). I've set configurer.setSaveAndRestore(true); in my WorkbenchAdvisor.initialize method to ensure the views layout is restored at launch.
Is there a way to programatically force an update of the views titles without losing the perspective configuration ?
I precise that I can't use the new Eclipse 4 (Juno) API.
As you are restoring perspective from previous session, it might be remembering part titles.
By default ViewPart doesnt do anything in saveMemento() method.
Override below methods are to debug the issue
public void init(IViewSite site, IMemento memento) throws PartInitException
String getPartName()
I have created an IFolder with a placeholder for my views in RCP on eclipse Helios on XP with Java 1.6 like so;
IFolderLayout mainFolder = layout.createFolder("mainfolder,
IPageLayout.LEFT, (float) 100.0, layout.getEditorArea());
mainFolder.addPlaceholder("myview:*");
And this works as expected with a greyed out area, which is populated by the myview when it is created and with subsequent views. However if the last view is ever closed, the whole IFolder area disappears and future views are instantiated in the wrong area/folder of the workbench.
I see a few people mentioning this problem back in 06, but I can't find any solutions and I don't want to keep force resetting the perspective just when the last folder has gone.
http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg15873.html
http://www.eclipsezone.com/eclipse/forums/t53312.html#91951958
I am thinking that I might have to hook the close view method to check to see if it is the last view and re-create the IFolder.
there seems to be a method to prevent the layout from closing;
layout.getViewLayout("myview").setCloseable (false);
layout.getViewLayout("myview:*").setCloseable (false);
but I can't seem to get that to effect the folder from collapsing...
Try this:
Overwrite the method isDurableFolder(...) in your WorkbenchWindowAdvisor so that it looks like this:
#Override
public boolean isDurableFolder(String perspectiveId, String folderId) {
if( "my.perspective".equals(perspectiveId) && "my.mainfolder".equals(folderId) ) {
return true;
}
return super.isDurableFolder(perspectiveId, folderId);
}
Replace my.perspective and my.mainfolder with the ID of your Perspective and Folder. This will create a durable ViewStack for your Folder.
FYI: By default the WorkbenchWindowAdvisor#isDurableFolder(...) returns false. This causes PageLayout#createFolder(...) to create the ViewStack as not durable. The Method PageLayout#createPlaceholderFolder(...) is not able to set the ViewStack durable!
I am working on a multi page editor that loads opens multiple files (e.g. java, html) in separate tabs of a multi page editor. The files get opened with the default editors associated with the file type and these default editors are embedded in the multi page editor as tabs.
Here is how I am determining which editor to load (for a file type):
void createPage() throws PartInitException
{
// get editor registry
IEditorRegistry editorRegistry = Activator.getDefault().getWorkbench().getEditorRegistry();
// loop through mappings until the extension matches.
IEditorDescriptor editorDescriptor = editorRegistry.getDefaultEditor(((IFileEditorInput)getEditorInput()).getFile().getName());
// if no editor was found that is associated to the file extension
if (editorDescriptor == null)
{
IEditorRegistry registry = Activator.getDefault().getWorkbench().getEditorRegistry();
editorDescriptor = registry.findEditor(EditorsUI.DEFAULT_TEXT_EDITOR_ID);
}
IConfigurationElement configuration = ((EditorDescriptor) editorDescriptor).getConfigurationElement();
String className = configuration.getAttribute("class");
IEditorPart editor;
try
{
editor = (IEditorPart) WorkbenchPlugin.createExtension(configuration, "class");
} catch (CoreException e) {
throw new RuntimeException(e);
}
final int index = addPage(editor, getEditorInput());
setPageText(index, "TAB_NAME");
}
The multi tab editor gets created without any problems and the correct editors are loaded within the tabs.
But the ‘Mark Occurrences’ functionality is not working in the Java Editor when loaded in a tab.
I validated that mark occurrences is turned on. When I select a variable in the java editor in my multi page editor tab it does not highlight the other occurrences of the variable.
But if I open the file in my multi tab editor and in a separate java editor at the same time and select a variable in the separate java editor it will highlight the other occurrences in the separate java editor as well as the java editor that is embedded in my multi page editor.
So the functionality seems to be enabled and loaded, it just does not execute the mark occurrences functionality when the selecting happens in the embedded editor.
What needs to be changed so that I can use the mark occurrences functionality from within the java editor that is embedded in my multi tab editor?
My understanding is that Mark Occurences is a central service so I assume I am missing the part that updates this service when something gets selected in my editor. Any idea on what needs to be done so the service gets updated?
Note: This problem only happens if the java editor is embedded in a multi page editor.
This functionality is build into org.eclipse.jdt.internal.ui.javaeditor.JavaEditor of org.eclipse.jdt.ui
As you see it's an internal class. However you can ignore that and subclass it. The org.eclipse.jdt.internal.ui.javaeditor.ToggleMarkOccurrencesAction will work for all open JavaEditors (try opening the same class twice with the standard CompilationUnitEditor and you will see two "mark occurences" markings).This is because a central property PreferenceConstants.EDITOR_MARK_OCCURRENCES is set in the PreferenceStore of the JavaPlugin.
In order to show the ToggleMarkOccurrencesAction Button you will need to provide a IEditorActionBarContributor (Take a look at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditorActionContributor)