My RCP app has the coolbar visible by setting configurer.setShowCoolBar(true) in WorkbenchWindowAdvisor#preWindowOpen. But when I contribute a toolbar to the main toolbar, it never shows up. Here's my contribution code:
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="toolbar.perspectivesDynamic">
<dynamic
class="my.package.PerspectiveSwitcherToolbar"
id="perspectiveSwitcherToolbar">
</dynamic>
</toolbar>
</menuContribution>
</extension>
And the ContributionItem class:
public class PerspectiveSwitcherToolbar extends ContributionItem {
...
#Override
public void fill(final ToolBar parent, int index) {
//Does not get called
}
#Override
public void fill(CoolBar parent, int index) {
//Does not get called
}
...
}
I'm using this code for adding a custom perspective switcher. It's rather old, but I see examples everywhere on the Internet adding a toolbar like this to the main toolbar, so I'm missing something elsewher, I assume
I think that is bug 392457: <toolbar><dynamic></toolbar> doesn't work at the moment. You can work around it by using a <control> and managing the contents yourself.
Related
The Open Perspective View shows a list of perspectives to which a user can switch. My custom perspective is there, too. Can I have it not listed or greyed out, if a certain condition bis not met?
The second best alternative that comes to my mind is to have it listed, but the actual switch is not carried out, if b == false.
The best way for me was to use the extension point org.eclipse.ui.activities, as greg-449 suggested, and add a propertyTester. In order to hide perspective related UI elements and not every UI element from the same plugin, one can use isEqualityPattern="true".
<extension point="org.eclipse.ui.activities">
<activity
description="Remove some UI Elements"
id="com.my.plugin.ui.hideUI"
name="HideUI">
<enabledWhen>
<test
forcePluginActivation="false"
property="com.my.plugin.ui.PlanningPropertyTester">
</test>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="com.btc.edm.hidePlanning"
isEqualityPattern="true"
pattern="com.my.plugin.ui/id.of.the.perspective.to.hide">
</activityPatternBinding>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="com.my.plugin.ui.MyPropertyTester"
id="com.my.plugin.ui.propertyTester"
namespace="com.my.plugin.ui"
properties="MyPropertyTester"
type="java.lang.Object">
</propertyTester>
</extension>
It is important to have a fully qualified name for type.
The MyPropertyTester class extends org.eclipse.core.expressions.PropertyTester and overrides the test method.
public class MyPropertyTester extends PropertyTester {
#Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (goodWeather()) {
return true;
return false;
}
}
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..?
I create a file creation page by extending class WizardNewFileCreationPage. What I am trying to do is to hide the help button on the left bottom corner. Any suggestions on how to do this?
Thank you.
Call this method: Wizard#setHelpAvailable(false)
Refer API here
I called this method but not working. See the following:
public class NewTDLDiagram extends Wizard implements INewWizard {
private NewDiagramFilePage page;
public NewTDLDiagram() {
// TODO Auto-generated constructor stub
setHelpAvailable(false);
}
...
}
This class is registered as an extension point of org.eclipse.ui.newWizards:
<extension
point="org.eclipse.ui.newWizards">
<wizard
class="com.abc.graphicview.ui.NewDiagram"
icon="icons/NewSmdWizard.gif"
id="com.abc.graphicview.ui.diagrawizard"
name="Diagram"
project="false">
<selection
class="org.eclipse.core.resources.IResource">
</selection>
</wizard>
</extension>
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>
I want to add a combo box to the toolbar (coolbar) of eclipse using Eclipse Plug-in development API (not an RCP application). This combo box items should be dynamically added/removed.
I know that in RCP applications it is possible by following the link : http://www.thedeveloperspoint.com/?p=140
but I am looking at Eclipse plugin API.
Any help would be greatly appreciated.
Thanks Syam
This can be done by using 2 steps.
STEP 1: By using extension point mechanism create/add toolbar to the global toolbar (using locationURI as "toolbar:org.eclipse.ui.main.toolbar")
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="com.company.module.toolbar"
label="Sample">
<control
class="com.company.module.ui.ComboToolbarContribution"
id="ratata">
</control>
</toolbar>
</menuContribution>
</extension>
STEP 2: Implement the ComboToolbarContribution as follows.
package com.company.module.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
public class ComboToolbarContribution extends
WorkbenchWindowControlContribution {
private Combo mReader;
public ComboToolbarContribution() {
}
#Override
protected Control createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
GridLayout glContainer = new GridLayout(1, false);
glContainer.marginTop = -1;
glContainer.marginHeight = 0;
glContainer.marginWidth = 0;
container.setLayout(glContainer);
GridData glReader = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
glReader.widthHint = 280;
mReader = new Combo(container, SWT.BORDER | SWT.READ_ONLY
| SWT.DROP_DOWN);
mReader.setLayoutData(glReader);
return container;
}
#Override
protected int computeWidth(Control control) {
return 300;
} }
With the above 2 steps a combo box will be added to the global toolbar and user need to provide the global access to the combo box.
To avoid headaches.. if anybody is facing the issue that eclipse only draws 7px height of the control I want to point to a workaround:
https://www.eclipse.org/forums/index.php/t/1076367/
Add another contribution with an icon to the same toolbar (i.e. com.company.module.toolbar) to reserve enough space.
As #Jonny mentioned above it may be necessary to reserve some space.
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="new">
<control
class="org.xy.composite.NewComposite"
id="org.xy.composite.newcomposite.id">
</control>
<command
commandId="newcomposite"
icon="resources/nothing.png"
label="nix"/>
</toolbar>
</menuContribution>
And with the command this is possible