Eclipse RCP Content Assist not working with auto activated characters - eclipse

I define my own editor and have completion proposals like this
public IContentAssistant getContentAssistant(ISourceViewer sv) {
ContentAssistant ca = new ContentAssistant();
IContentAssistProcessor pr = new TagCompletionProcessor();
ca.setContentAssistProcessor(pr, IDocument.DEFAULT_CONTENT_TYPE);
return ca;
}
#Override
public char[] getCompletionProposalAutoActivationCharacters() {
String str = "._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
return str.toCharArray();
}
So when I am pressing ctrl-space enter it will work, but I want it should always trigger computeCompletionProposals when any of the above characters are entered.
<extension
point="org.eclipse.ui.editors">
<editor
id="testingpluginproject.editors.XMLEditor"
name="Sample XML Editor"
icon="icons/sample.png"
extensions="xxml"
class="testingpluginproject.editors.XMLEditor"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor">
</editor>
</extension>
So what I am missing?

You must call the ContentAssistant enableAutoActivation method to enable auto activation:
ca.enableAutoActivation(true);
You might also want to look at implementing IContentAssistProcessorExtension rather than just IContentAssistProcessor as it provides a better isCompletionProposalAutoActivation method.

Related

Eclipse RCP bold font in proposal for custom editor

I have a strange problem. I tried two implemenations of Custom Editor, one is using GenericEditor without own Editor implemenation see 1 and the other is with own editor implementation.
Only for the first solution, I get the bold font. For the second implemenation no bold possible. For both I am using the same Proposal Implemenation.
1. Using GenericEditor
<extension
id="keywordsproposal"
name="Keywords Proposals"
point="org.eclipse.ui.genericeditor.contentAssistProcessors">
<contentAssistProcessor
contentType="com.me.editor"
class="com.me.proposalcomputer.AllKeywordsProposalComputer">
</contentAssistProcessor>
</extension>
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="me"
id="com.me.editor"
name="ME"
priority="high">
</content-type>
</extension>
<extension
point="org.eclipse.ui.editors">
<editorContentTypeBinding
contentTypeId="com.me.editor"
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
</extension>
2. Own Editor class
<extension
point="org.eclipse.ui.editors">
<editor
id="com.me.editor"
name="ME Editor"
extensions="me"
class="com.me.editor"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor">
</editor>
</extension>
public class MeSourceViewerConfigurator extends TextSourceViewerConfiguration{
/*
*/
#Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
final ContentAssistant assistant = new ContentAssistant();
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(1);
final IContentAssistProcessor processor= new AllKeywordsProposalComputer();
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
assistant.addContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
return assistant;
}
Do I miss anything to add in plugin.xml or..?

How to ensure that my key bindings have priority over other definitions

I am developing an RCP app. The app has an execution mode where I want to enable various key bindings to control Start, Stop, Continue, Repeat etc. The bindings will be enabled using an 'ExecutionContext' which is set when any of the relevant views are activated.
The context switching is done in each of the 'Execution' views.
#Override
public final void createPartControl(Composite parent)
{
addPartListener();
...
}
private void addPartListener()
{
this.getViewSite().getPage().addPartListener(new IPartListener2()
{
IContextActivation token = null;
#Override
public void partDeactivated(IWorkbenchPartReference partRef)
{
if (token != null)
{
System.out.println("End exec context");
IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(
IContextService.class);
contextService.deactivateContext(token);
token = null;
}
}
#Override
public void partActivated(IWorkbenchPartReference partRef)
{
System.out.println("Set exec context");
IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(
IContextService.class);
token = contextService.activateContext("AtfExecutionContext");
}
});
}
I can see via Console messages that my context is being set and some of the key bindings are working as expected.
However, if a key binding has already been assigned from another plugin, that binding has priority. E.g. I want to use Ctrl+F8 to stop but when that is pressed I get the 'Next perspective' action which is the workbench default.
The binding definition is
<extension
point="org.eclipse.ui.bindings">
<scheme
id="atfscheme"
name="atfscheme"
parentId="org.eclipse.ui.defaultAcceleratorConfiguration">
</scheme>
<key
commandId="com.xxx.atf.model.ui.commands.ExecKey.Start"
contextId="AtfExecutionContext"
schemeId="atfscheme"
sequence="M1+M2+F5">
<!-- F5 does not work but Ctrl-Shift-F5 does -->
</key>
</extension>
<extension
point="org.eclipse.ui.contexts">
<context
id="AtfExecutionContext"
name="AtfExecutionContext"
parentId="org.eclipse.debug.ui.debugging">
<!-- have tried various parentid values... -->
</context>
</extension>
It seems that only previously undefined accelerators work. What do I have to do to override existing definitions and activate mine when my context has been set?
There is a separate context service for each part, you must use the correct context service.
It isn't necessary to activate / deactivate the context on part activation / deactivation. The separate context services will deal with that automatically.
So activate in createPartControl with:
IContextService contextService = getSite().getService(IContextService.class);
token = contextService.activateContext("AtfExecutionContext");
and deactivate when the part closes.
You are also defining a new key binding scheme - that has to be activated separately and isn't what you want here. Just remove that and just use org.eclipse.ui.defaultAcceleratorConfiguration as the schemeId

Increased line height for Consolas font in Eclipse

Many people are using Consolas for their primary programming font but unfortunately there is no way to change line height in Eclipse so it looks kinda ugly as it is shown below:
I was wondering if there is anyone who solved this by adding some extra space between lines or simply changing the font itself which has longer height now.
It would be nice to share it with us here on Stackoverflow.
There are some topics I've found while searching for this but none of them were what I am looking for:
How can I change line height / line spacing in Eclipse?
https://stackoverflow.com/questions/15153938/improved-line-spacing-for-eclipse?lq=1
and so on...
Some of them designed their own fonts (such as Meslo Font) by modifying the existing ones so it would be nice if you could share your modified Consolas font.
As mentioned in one of the answers you reference the underlying StyledText control does have a setLineSpacing method, but the existing editors do not use it.
The CSS styling code in Eclipse 4.3 does provide a way to access this but it requires writing a plugin to extend the CSS in order to do so.
The plugin.xml for the plugin would look like this:
<plugin>
<extension
point="org.eclipse.e4.ui.css.core.elementProvider">
<provider
class="linespacing.LineSpacingElementProvider">
<widget
class="org.eclipse.swt.custom.StyledText"></widget>
</provider>
</extension>
<extension
point="org.eclipse.e4.ui.css.core.propertyHandler">
<handler
adapter="linespacing.StyledTextElement"
composite="false"
handler="linespacing.LineSpacingPropertyHandler">
<property-name
name="line-spacing">
</property-name>
</handler>
</extension>
</plugin>
which declares a CSS element provider LineSpacingElementProvider which would be:
public class LineSpacingElementProvider implements IElementProvider
{
#Override
public Element getElement(final Object element, final CSSEngine engine)
{
if (element instanceof StyledText)
return new StyledTextElement((StyledText)element, engine);
return null;
}
}
The StyledTextElement this provides is just:
public class StyledTextElement extends ControlElement
{
public StyledTextElement(StyledText control, CSSEngine theEngine)
{
super(control, theEngine);
}
}
The second declaration in the plugin.xml is a CSS property handler for a property called line-spacing
public class LineSpacingPropertyHandler extends AbstractCSSPropertySWTHandler implements ICSSPropertyHandler
{
#Override
protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception
{
if (!(control instanceof StyledText))
return;
StyledText text = (StyledText)control;
if ("line-spacing".equals(property))
{
int pixelValue = (int)((CSSPrimitiveValue)value).getFloatValue(CSSPrimitiveValue.CSS_PX);
text.setLineSpacing(pixelValue);
}
}
#Override
protected String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception
{
return null;
}
}
With a plugin containing this installed you can then modify one of the existing CSS style sheets to contain:
StyledText {
line-spacing: 2px;
}
You better choose different fonts. Don't just stick to things. Try new things and accept them. :D I was also using Consolas. But now I am using Courier New and they are pretty fine. If you have 21" or larger display you can use Courier New at 12 or 14 size. Once you use this you will get used to it as you are with Consolas now :P
You could try Fira Mono. See some screenshots here. Small sizes look good too.

Implementation AbstractPreferenceInitializer won't get called in my Eclipse RCP

I want to use the Eclipse mechanism to set default preferences in my RCP application. Therefore I extended the class AbstractPreferenceInitializer to set my default preferences:
public class PreferenceInitializer extends AbstractPreferenceInitializer {
#Override
public void initializeDefaultPreferences() {
IPreferenceStore preferenceStore = PlatformUI.getPreferenceStore();
preferenceStore.setDefault("xyz", xyz);
preferenceStore.setDefault("abc", false);
}
}
Then I defined the extension point:
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="com.abc.PreferenceInitializer">
</initializer>
</extension>
But unfortunately, the initializer won't get called during startup (whereas Eclipse's WorkbenchPreferenceInitializer will be called).
Can someone give me a hint, what to do, to get this run?
Your preference initializer code won't get called until those default values are needed (rather than on application startup, which I'm guessing was your expectation).
If you have yourself a preference page that contains some FieldEditors using your preference names, your preference initializer will get called when you go to the Preferences dialog and select that preference page.
Something along the lines of:
public class MyPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public void createFieldEditors() {
Composite parent = getFieldEditorParent();
addField(new StringFieldEditor(Constants.PREFERENCES.FILE_COMPARE_TOOL_LOCATION, "File compare tool location", parent));
addField(new StringFieldEditor("xyz", "XYZ Value", parent));
addField(new BooleanFieldEditor("abc", "Enable the ABC widget", parent));
}
}
And of course, an extension point for the page:
<extension point="org.eclipse.ui.preferencePages">
<page
class="whatever.package.MyPreferencePage"
id="whatever.package.MyPreferencePage"
name="MyPrefs">
</page>
</extension>

Removing popUpMenus from CNF (Common Navigator Framework) in Eclipse

I have been partially successful at removing almost all the popUp menus from the Commons Navigator Framework simply by configuring the plugin.xml file.
There are 2 menus that refuse to go:
group.edit and
group.reorganize.
My plugin.xml config looks like this:
<extension
point="org.eclipse.ui.navigator.viewer">
<viewer
viewerId="org.eclipse.ui.example.navigator.view">
<popupMenu allowsPlatformContributions="false">
<insertionPoint
name="group.edit" />
<insertionPoint
name="group.reorganize" />
</popupMenu>
</viewer>
<viewerContentBinding
viewerId="org.eclipse.ui.thermo.navigator.view">
<includes>
<contentExtension
pattern="org.eclipse.ui.navigator.resourceContent"/>
</includes>
</viewerContentBinding>
</extension>
Setting the allowsPlatformContribution to false DOES stop contributions to be added to the context menu except for group.edit and group.reorganize... this is starting to look like a bug to me.
The obvious solution is to remove the insertion points from my <popUpMenu> but without them the application throws an exception:
Throwable: java.lang.IllegalArgumentException: Group not found: group.edit
java.lang.IllegalArgumentException: Group not found: group.edit
at org.eclipse.jface.action.ContributionManager.addToGroup(ContributionManager.java:131)
at org.eclipse.jface.action.ContributionManager.appendToGroup(ContributionManager.java:138)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionGroup.fillContextMenu(EditActionGroup.java:74)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider.fillContextMenu(EditActionProvider.java:50)
at org.eclipse.ui.navigator.NavigatorActionService.addCommonActionProviderMenu(NavigatorActionService.java:205)
at org.eclipse.ui.navigator.NavigatorActionService.fillContextMenu(NavigatorActionService.java:172)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager.fillContextMenu(CommonNavigatorManager.java:258)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager$4.menuAboutToShow(CommonNavigatorManager.java:273)
at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:335)
at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:463)
at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:459)
at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:485)
It throws the same exception for the reorganize group.
I succeeded in removing the "group.edit" actions (Copy/Paste) and I've done it that way, using the Common Navigator extension points :
<extension
point="org.eclipse.ui.navigator.viewer">
<viewerActionBinding
viewerId="org.eclipse.ui.navigator.ProjectExplorer">
<includes>
<actionExtension
pattern="my.app.client.actions.MyAppEditActionExtension">
</actionExtension>
</includes>
</viewerActionBinding>
</extension>
<extension
point="org.eclipse.ui.navigator.navigatorContent">
<actionProvider
class="my.app.client.workshop.MyPasteActionProvider"
id="my.app.client.actions.MyAppEditActionExtension"
overrides="org.eclipse.ui.navigator.resources.actions.EditActions"
priority="highest">
<enablement>
<!-- A hack to allways be enabled -->
<not>
<systemTest
property="MyApp"
value="WONT-EVER-BE-SET">
</systemTest>
</not>
</enablement>
</actionProvider>
</extension>
And, with addition of "org.eclipse.ui.navigator.resources" in my plugin dependencies, I implemented "MyPasteActionProvider" like this :
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider;
/**
* Create the Edit actions (Cut/Copy/Paste)
* and register then globally in the workbench using EditActionProvider.
* <p/>
* Then, removes the Copy/Paste contributions in the pop-up menu.
*/
public class MyPasteActionProvider extends EditActionProvider {
public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu);
// remove Copy/Paste contributions
IContributionItem copyItemRemoved = menu.remove("org.eclipse.ui.CopyAction");
IContributionItem pasteItemRemoved = menu.remove("org.eclipse.ui.PasteAction");
}
}
Well, that's a "discouraged access" but I was getting myself discouraged ;-)
JM.D
Generally you should be using the Command Framework with any recent version of Eclipse (3.3 or higher), this replaces the mechanism for providing popup menus in the Common Navigator.
This thread suggests to remove the things that are causing the menu items to appear in the first place:
They are probably in action sets, so if you can identify the action set that's causing the offensive contribution, you can do something like this in your WorkbenchAdvisor:
ActionSetRegistry reg = WorkbenchPlugin.getDefault()
.getActionSetRegistry();
IActionSetDescriptor[] actionSets = reg.getActionSets();
String[] removeActionSets = new String[] {
"org.eclipse.ui.cheatsheets.actionSet",
"org.eclipse.ui.edit.text.actionSet.annotationNavigation",
"org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
"org.eclipse.ui.WorkingSetActionSet",
"org.eclipse.update.ui.softwareUpdates", };
for (int i = 0; i < actionSets.length; i++)
{
boolean found = false;
for (int j = 0; j < removeActionSets.length; j++)
{
if (removeActionSets[j].equals(actionSets[i].getId()))
found = true;
}
if (!found)
continue;
IExtension ext = actionSets[i].getConfigurationElement()
.getDeclaringExtension();
reg.removeExtension(ext, new Object[] { actionSets[i] });
}
The closest bug I have found is the 145233: Make more obvious way to specify input (for RCP apps), with a similar hack.
Bug 143430 (CommonNavigator requires initialInput to be Adaptable) is a more general one, and would indicate that then CNF has been improved with eclipse3.5 (Galileo).
So do you also have this issue with 3.5 and a custom CNF class?
As mentioned in the article "Eclipse CNF: Navigator Content Extensions", CNF has evolved with eclipse3.5, and this article seems to have some tree with true custom contextual menu entries.