Populate extension point's element attribute during runtime - eclipse

Here is my use case. I have an Editor that different plugins can use to display their data. These plugins can create (with intervention from user - wizards) different files that Editor can accept: .p1, .p2, etc. Each plugin contributes file extensions of files that it produces and this data is available via custom extension point. I need a way, if possible to "inject" this data into org.eclipse.ui.editors extension point's extensions attribute.
One way I was thinking about doing this is in a plugin that is called early enough collect file extensions from all plugins that use my extension point and write these values into plugin.properties file's key like supportedFileExtension and extension point org.eclipse.ui.editors will in turn consume this file:
<extension
point="org.eclipse.ui.editors">
<editor
class="MyEditor"
contributorClass="MyActionBarContributor"
default="false"
extensions="%supportedFileExtensions"
id="my.com.editor"
name="My Editor">
</editor>
I also saw class ExtensionParameterValues which is something I can possibly use, but for developer who might want to reuse this little mechanism, it might not be obvious enough what's going, especially when extensions attribute would be empty when using ExtensionParameterValues class. Of course I can put this in documentation, but who reads that, right? :)
Perhaps I am overlooking something simple and there is an easier way to do what I am trying to accomplish?

Rather than using extensions directly you can Eclipse Content Types to do this. First define a base content type:
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
id="contenttype.base"
name="Base content type"/>
Then your different plugins can define a content type for their file extensions using a a content type derived from the base type:
<content-type
base-type="contenttype.base"
file-extensions="p1"
id="contenttype.p1"
name="P1 content type"/>
<content-type
base-type="contenttype.base"
file-extensions="p2"
id="contenttype.p2"
name="P2 content type"/>
For your editor don't specify any extensions, instead use the contentTypeBinding for the base type:
<extension
point="org.eclipse.ui.editors">
<editor
class="MyEditor"
contributorClass="MyActionBarContributor"
default="false"
id="my.com.editor"
name="My Editor">
<contentTypeBinding
contentTypeId="contenttype.base"/>
</editor>
The editor will now be used for all content types based on the base content type.

Related

Tableau not loading custom color palette

I have edited Preferences.tps file from my tableau repository to add following code -
<?xml version='1.0'?>
<workbook>
<preferences>
<color-palette name="My Custom Palette" type="regular">
<color>#75787B</color>
<color>#A7A8AA</color>
<color>#BBBCBC</color>
<color>#B7C9D3</color>
<color>#C6BCD0</color>
<color>#E4D77E</color>
<color>#D9C89E</color>
</color-palette>
</preferences>
</workbook>
Upon restarting the Tableau, I still can't see my color pallet in there. I tried searching online for possible solutions and have even replaced the code with custom codes available online. No luck though!
For continuous/ordered data, the type of the color palette would need to be "ordered-sequential" or "ordered-diverging".
See the link below for more info about creating a custom palette and with examples of various types.
https://onlinehelp.tableau.com/current/pro/desktop/en-us/formatting_create_custom_colors.html
For example:
<?xml version='1.0'?>
<workbook>
<preferences>
<color-palette name="My Custom Palette" type="ordered-diverging">
<color>#75787B</color>
<color>#A7A8AA</color>
<color>#BBBCBC</color>
<color>#B7C9D3</color>
<color>#C6BCD0</color>
<color>#E4D77E</color>
<color>#D9C89E</color>
</color-palette>
</preferences>
</workbook>
Ordered-diverging above produces:
If there are multiple versions of Tableau installed, try testing the custom colors on default one. it works.

How to override apply and restore defaults

I want to configure some appearance settings for a type of file. So I created a new entry in the General->Appearance->Colors and Fonts.
My plugin.xml looks like this:
<extension point="org.eclipse.ui.themes">
<themeElementCategory
id="com.example.themeElementCategory"
label="My specific settings">
<description>
Control the appearance of .example files
</description>
</themeElementCategory>
<colorDefinition
categoryId="com.example.themeElementCategory"
id="com.example.colorDefinition"
label="Some Color"
value="COLOR_DARK_BLUE">
<description>
Your description goes here
</description>
</colorDefinition>
<fontDefinition
categoryId="com.example.themeElementCategory"
id="com.example.fontDefinition"
label="Some Font"
value="Lucida Sans-italic-18">
<description>
Description for this font
</description>
</fontDefinition>
</extension>
Now in the Colors and Fonts I have a new entry were I can set the color and the font.
How can I extend the preferences window so I can override the Restore defaults, Apply and Apply and Close buttons?
In my <themeElementCategory> I will have to add a class=MyHandlingClasswhich would override the performApply(), but what should that class extend/implement?
Same as 1, but add a PropertyChangeEvent, still don't know what should extend/implement
Less likely, create a new preference page which extends the PreferencePage and implements IWorkbenchPreferencePage
How can I achieve one of the first two options?
UPDATE FOR CLARIFICATION
Currently the color and the font for a specific file extension are hardcoded in a class( I KNOW).
When the file is opened in the editor, the informations are read from that static class and visible in the editor.
What I wanted to do:
In a static{} block, read the settings configured in the preferences and update the static fields from my class.
If the user changes those settings from the preferences, on apply I wanted to update the static fields from the class and "repaint" the editor.
If you just want to know when theme items change value use the addPropertyChangeListener method of IThemeManager to add a listener for changes:
IThemeManager manager = PlatformUI.getWorkbench().getThemeManager();
manager.addPropertyChangeListener(listener);
The PropertyChangeEvent passed to the propertyChanged method of IPropertyChangeListener contains the id, old and new value of the changed theme item.

Select editor programmatically

I have written an Eclpse plugin that contains several editor types. For each editor a content type is associated. In some situations I have two possible editors for the same contenttype. I know that I can select the editor via "Open with". But I would like to decide automatically which editor should be opened.
Here is an example
In one plugins I have got the following extension point definitions:
<extension
point="org.eclipse.ui.editors">
<editor
class="de.dstg.adsplus.editors.program.MacroEditor"
contributorClass="de.dstg.adsplus.editors.core.ADSTextEditorActionContributor"
default="true"
icon="icons/macro.png"
id="de.dstg.adsplus.editors.editors.macroEditor"
name="ADS Macro Editor">
<contentTypeBinding
contentTypeId="de.dstg.adsplus.macro">
</contentTypeBinding>
</editor>
</extension
In another plugin I have this definiton:
<extension
point="org.eclipse.ui.editors">
<editor
class="de.dstg.adsplus.focusededitor.FocusedEditor"
contributorClass="de.dstg.adsplus.focusededitor.FocusedEditorContributor"
icon="icons/dveditor.png"
id="de.dstg.adsplus.focusededitor"
name="ADS Focused Editor">
<contentTypeBinding
contentTypeId="de.dstg.adsplus.macro">
</contentTypeBinding>
When I double click on a file with this content type I would like to decide programmatically which editor to open depending on the content of the file or the location where it is stored.
I have tried to find a method that I could implement but without success.
You could use two different content types both using the same file extensions and use a 'content type describer' to distinguish the files.
The content type describer is defined in the content type extension point:
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type id="ABC"
base-type="org.eclipse.core.runtime.xml"
file-extensions="a,b,c">
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber2">
</describer>
</content-type>
The content describer class implements IContentDescriber or ITextContentDescriber. Eclipse calls the describe method to find out if the file is valid for the content type (and to get information about other attributes of the file).

Creating a working copy for Plone 4 custom content types

I have created a custom Plone content type in my package i.e. my.product.
I am in need of integrating a working copy support: so that a "published" document (in my case, a published content type) stays online while it is being edited. Basically, I want to take advantage of 'Working Copy Support (Iterate)' provided by plone.app.iterate to achieve what is explained here. This will provide me with ability to check-in/check-out my changes.
Is this possible in Plone 4 with custom content types using Archetypes? How would one go about it if yes?
I added the following two files inside my.product/my/product/profiles/default folder and it appears to work:
diff_tool.xml
<?xml version="1.0"?>
<object>
<difftypes>
<type portal_type="MyCustomType">
<field name="any" difftype="Compound Diff for AT types"/>
</type>
</difftypes>
</object>
repositorytool.xml
<?xml version="1.0"?>
<repositorytool>
<policymap>
<type name="MyCustomType">
<policy name="at_edit_autoversion"/>
<policy name="version_on_revert"/>
</type>
</policymap>
</repositorytool>
I have never used plone.app.iterate, but this is the generic approach how to solve the problem.
Actions are installed by plone.app.iterate GenericSetup profile. You can see actions here:
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/profiles/default/actions.xml
Pay note to the line *available_expr* which tells when to show the action or not. It points to helper view with the conditition.
The view is defined here
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/browser/configure.zcml#L7
The checks that are performed for the content item if it's archiveable
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/browser/control.py#L47
Most likely the failure comes from if not interfaces.IIterateAware.providedBy condition. Your custom contennt must declare this interface. However, you can confirm this putting a pdb breakpoint in checkin_allowed(self) and step it though line-by-line and see what happens with your content type.

mark file as active - eclipse plugin

i wrote a plugin for a eclipse that let user creating my own type of project , the template of the project have some configuration files and I want to give the user the option to chose which one will be active, it's mean which one i will use when i will compile the project, i add an action of this files that let the user set it as active, my question is if there is any way to mark it in the package explorer(maybe bold ar with some border) as active so when user look at this he can know which one is the active now
Thanks
You can use the decorator extension point org.eclipse.ui.decorators. Add this to your plugin.xml:
<extension
point="org.eclipse.ui.decorators">
<decorator
adaptable="true"
class="MyDecoratorClass"
id="some.id.for.decorator"
label="Active Build Configuration Decorator"
lightweight="true"
location="BOTTOM_RIGHT"
state="false">
<enablement>
<and>
<objectClass
name="org.eclipse.core.resources.IResource">
</objectClass>
<or>
<objectClass
name="org.eclipse.core.resources.IProject">
</objectClass>
<objectClass
name="org.eclipse.core.resources.IFile">
</objectClass>
</or>
</and>
</enablement>
</decorator>
</extension>
Provide implementation in your MyDecoratorClass (or whatever name you choose) to check your project's active config and either adding text, or images. Perhaps have something like this: []
Whenever a user makes a modification that requires you to update the decorators so that the latest changes can be decorated you can use this:
// the resource whose properties changed and needs to be re-decorated
IResource resource = ...;
IDecoratorManager manager = PlatformUI.getWorkbench().getDecoratorManager();
IBaseLabelProvider decorator = manager.getBaseLabelProvider("id.of.my.decorator");
if (decorator != null)
((ILabelProviderListener) manager).labelProviderChanged(new LabelProviderChangedEvent(decorator, resource));