Implementation AbstractPreferenceInitializer won't get called in my Eclipse RCP - 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>

Related

Eclipse RCP Content Assist not working with auto activated characters

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.

How to create a file with different extension using org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard

Is there a way to create a file with specific extension. Currently im creating a html kind file. Is there a way to give specific extension to the file while creating? Maybe .css or .js etc?
<extension
point="org.eclipse.ui.newWizards">
<category id="com.ui.category" name="XXX Project">
</category>
<wizard
category="com.ui.category"
id="ui.wizard.NewFileWizard"
name="Create a new File"
icon="icons/new_project.png"
class="org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard"
project="true"
>
</wizard>
</extension>
You will have to create your own wizard to do this, extending BasicNewFileResourceWizard
The minimum code would be something like this:
public class FileExtNewFileWizard extends BasicNewFileResourceWizard
{
public FileExtNewFileWizard()
{
super();
}
#Override
public void addPages()
{
super.addPages();
// Get the page created by `super.addPages` and set the default file extension
WizardNewFileCreationPage page = (WizardNewFileCreationPage)getPage("newFilePage1");
page.setFileExtension("css");
}
}

Eclipse RCP Can't Contribute to Main Toolbar

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.

Is it possible to hide help button from wizard page org.eclipse.ui.dialogs.WizardNewFileCreationPage in Eclipse?

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>

Handling drag and drop of files inside Eclipse Package Explorer

I'm trying to create an Eclipse plugin to support a proprietary project file format. My goal is to be able to drag and drop a file in the Project Explorer (any type of file) onto a file of the type I support, and have the name of the file being dragged appended to the end of the proprietary file.
Right now, I have a custom editor that can parse out some data from an existing file in a manageable way. This means that I have an editor associated with the file type, such that my special icon shows up next to it. I don't know if that's relevant.
I'm attempting to use the extension point "org.eclipse.ui.dropActions" but I'm not sure how to register my DropActionDelegate (implements org.eclipse.ui.part.IDropActionDelegate) such that it will be called when a file is dropped onto one of my type within the Project Explorer.
Anybody have any ideas? Am I even on the right track with the DropActionDelegate?
You are on the right track implementing an IDropActionDelegate:
class DropActionDelegate implements IDropActionDelegate {
#Override
public boolean run(Object source, Object target) {
String transferredData (String) target; // whatever type is needed
return true; // if drop successful
}
}
The purpose of the extension point org.eclipse.ui.dropActions is to provide drop behaviour to views which you don't have defined yourself (like the Project Explorer).
You register the drop action extension like this:
<extension point="org.eclipse.ui.dropActions">
<action
id="my_drop_action"
class="com.xyz.DropActionDelegate">
</action>
</extension>
Don't forget to attach an adequate listener to your editor in your plugin code:
class DragListener implements DragSourceListener {
#Override
public void dragStart(DragSourceEvent event) {
}
#Override
public void dragSetData(DragSourceEvent event) {
PluginTransferData p;
p = new PluginTransferData(
"my_drop_action", // must be id of registered drop action
"some_data" // may be of arbitrary type
);
event.data = p;
}
#Override
public void dragFinished(DragSourceEvent event) {
}
}