For my eclipse rcp application, I tried to change the "Number of opened editors before closing" programatically by modifying the extension point org.eclipse.ui.editors :
IPreferenceStore prefs = getPreferenceStore();
prefs.setValue("org.eclipse.editorss.maxEditorTabs",15) ;
((IPersistentPreferenceStore) prefs).save() ;
https://i.stack.imgur.com/G5rS0.png
but it doesn't work, so I tried to use IWorkbenchPreferenceConstants.MAX_EDITORS_FROM_MODEL but I guess it's not available in the latest version of Eclipse anymore.
so my question is can i change this value or not ?
The "Number of opened editors before closing" preference id is the REUSE_EDITORS constant in org.eclipse.ui.internal.IPreferenceConstants.
The preference must be set in the WorkbenchPlugin.getDefault().getPreferenceStore() preference store.
Note that both IPreferenceConstants and WorkbenchPlugin are internal so really should not be used.
See org.eclipse.ui.internal.ide.dialogs.IDEEditorsPreferencePage for more details.
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.
In my project the user sees the red cross icon on the file containing an error and the folders above. When the (modelling nature of the sirius) plugin is added to the project the red cross dissapears on the file (not on the folders).
How can i keep the error icon on the file?
I can get information about the content extension which probably causes the problem
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); ProjectExplorer expl = (ProjectExplorer) page.findView(IPageLayout.ID_PROJECT_EXPLORER);
INavigatorContentService content = expl.getNavigatorContentService();
INavigatorContentExtension siriusext = content.getContentExtensionById("org.eclipse.sirius.ui.resource.content.session");
siriusext.getDescriptor().getAppearsBeforeId();
The problem is probably the sirius INavigatorContentService because it is set to appear before id "org.eclipse.jdt.java.ui.javaContent"
(siriusext.getDescriptor().getAppearsBeforeId())
How can i (have the modelling nature and) keep the error icon on the file?
Any help is appreciated!
I answered your question on the Sirius forum [1].
The problem seems to come from the getImage() implementation in the label provider used by the INavigatorExtension provided by Sirius.
A workaround could be to try to provide your own navigator content with an Override element targeting the Sirius Content Management (org.eclipse.sirius.ui.resource.content.session) as suppressed extension and provide your own label provider (which could extend the Sirius one and specifically handle the file case in getImage, but you might loose the M decorator on files handled by Sirius).
Could you open a bugzilla [2] to track the issue ? Then the team will have the possibility to analyze the issue and try to find a proper solution.
Regards,
Maxime
[1] https://www.eclipse.org/forums/index.php?t=msg&th=877968&goto=1498330&#msg_1498330
[2] https://bugs.eclipse.org/bugs/enter_bug.cgi?product=sirius
I'd like to save user preferences from a sketch running either on a PC or an Android phone, using the same code in as standard "Java-way" as possible.
Ideal candidate for my purposes seems to be the java.util.prefs.Preferences class. So, I wrote a little test script to see if it's working in processing:
String prId = "counter";
Preferences prefs = Preferences.userNodeForPackage(this.getClass());
int counter = prefs.getInt(prId, 0);
println(counter);
prefs.putInt(prId, 1+counter);
This program outputs an increasing number each time it is executed - on a PC. On Android, the default value (0) is always shown.
Are there any additional steps required to get this working on Android? Permissions to be requested?
Are there any alternatives for saving name - value pairs on both platforms?
Obs.: "WRITE_EXTERNAL_STORAGE" permission is already enabled
This is a known Android bug unfortunately: https://code.google.com/p/android/issues/detail?id=22232
Basically the app does not have write permissions for the generated path, which should be a system-specific location where the user has write permissions instead.
Simplest (cross platform) workaround could be to use java.util.Properties, where you have control over the storage location.
Another workaround (if you are tied to the Preferences API for some reason) might be to provide your own implementation of AbstractPreferences (perhaps backed by Android SharedPreferences?), see this SO post: Is there a way to use java.util.Preferences under Windows without it using the Registry as the backend?
P.S.: Another workaround option might be to explicitly export / import the data using Preferences.exportSubtree(OutputStream os) and
Preferences.importPreferences(InputStream is)
In Android, the preferred way to store preferences is to make use of SharedPreferences. The equivalent code would be like this:
String prId = "counter";
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
int counter = prefs.getInt(prId,0); // Get int, default is 0
SharedPreferences.Editor prefsEditor = prefs.edit();
prefsEditor.putInt(prId, counter++); // Put counter back
prefsEditor.commit(); //Don't forget to commit the changes
I don't know exactly why java.util.prefs.Preferences would fail in Android. I suspect the reason is data would be deleted after the current Activity or the application is destroyed.
Because directory structure is different on each platform, it's hard to get preferences by just using one single same method. For example, data is stored in /.java/.userPrefs/**yourpacakgename**/prefs.xml on Android while it's in Registry on Windows and in ~/Library/Preferences/**yourpacakgename**/prefs.xml on Mac OS X. Also, you can't use Preferences.userRoot() in Android because an application cannot get root access.
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 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)