how to hide property page from some resource type - eclipse-plugin

my application project contains a different type of resources. for some IFolder not all folders in the project I need to set property page on right click properties.
my problem is that this page is shown for all folders even the property tester returns false.
plugin.xml
<extension
point="org.eclipse.ui.propertyPages">
<page
class="com.my.ui.properties.PropertiesPage"
id="com.my.ui.properties.Properties"
name="page">
<enabledWhen>
<adapt
type="org.eclipse.core.resources.IFolder">
<test
property="com.my.ui.propertyTester.supperFolder">
</test>
</adapt></enabledWhen>
</page>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="com.my.ui.properties.FolderTester"
id="com.my.ui.propertyTester"
namespace="com.my.ui.propertyTester"
properties="supperFolder"
type="org.eclipse.core.resources.IResource">
</propertyTester>
public class FolderTester extends PropertyTester {
#Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if ("supperFolder".equals(property) && receiver instanceof IFolder) {
IFolder folder = (IFolder) receiver;
if (IWResourceManager.getInstance().isIWResource(folder)) {
..
..
return true;
}
}
}
return false;
}
So what am I missing?

after hours of debugging, i finally found the mistake, I fill like I need to share it, in case someone has the same problem...
so..
in property tester extension point, tester "id" and "namespace" had the same value and that's was creating some sort of conflict.

Related

Binding keys using org.eclipse.ui.binding

I am trying to introduce a shortcut key(Ctrl+Shift+f) to our customized editor to format the content.
I've implememented the following changes.
Added changes to plugin xml by adding key extension with definition Id/schema/context.
Implemented Action by extending TextEditorAction class as below.
#Override
public void run() {
this.doOperation(ISourceViewer.FORMAT);
}
Implemented one Formatter class by implementing IContentFormatter.
Passed the above Formatter class to our cutsomized sourceVIewConfiguration (extends SourceViewerConfiguration) class by overriding getContentFormatter.
overrided createActions() API inside our customized editor class which extends TextEditor.
For some reason my shortcut key is not working. I put a debug point inside my action class and noticed the controller is not going there when i press on the shortcut key.
I also noticed that the newly created key is not displayed under preferences -> keys list.
Can somebody provide pointers or example to resolve the issue.
plugin.xml entries:
<key
commandId="com.language.javascripteditor.XJSFormatAction"
schemeId="myScheme"
sequence="M1+M2+z"/>
<scheme
id="myScheme"
name="myScheme">
</scheme>
Formatter class:
public class JavaScriptEditorFormatter implements IContentFormatter {
#Override
public void format(IDocument document, IRegion region) {
try {
String content =document.get(region.getOffset(), region.getLength());
String formatted = new JSBeautifier().js_beautify(content,null);
document.replace(region.getOffset(), region.getLength(), formatted);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
#Override
public IFormattingStrategy getFormattingStrategy(String contentType) {
throw new UnsupportedOperationException();
}
}
Added a new property file for customized schema with the name plugin_customization.ini and with the content as below
org.eclipse.ui/KEY_CONFIGURATION_ID=myScheme
Command section inside plugin.xml
<command
defaultHandler="com.cisco.nm.workflowbuilder.language.javascripteditor.XJSFormatAction"
id="com.language.javascripteditor.XJSFormatAction"
name="%action.label.format.xjs">
</command>
Instead of a handler I have written an Action class. Please let me know if this approach does not work
1.Added contributor class to extension of the existing editor.
2.Created command with an id for format.eg: com.javascript.text.format
3.written Action class with format method
#Override
public void run() {
this.doOperation(ISourceViewer.FORMAT);
}
4. plugin xml entry
<key
commandId="com.javascript.text.format"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+M2+F"/>
5. Overriden the createActions() .Inside this method instantiated the Action class and setActionDefinitionId.

Xamarin.Forms. Custom Property Binding issue

I created custom controls in Xamarin. One of it is ValidatedEntryCell:
public class ValidatedEntryCell: EntryCell
{
public static readonly BindableProperty ShowBorderProperty = BindableProperty.Create(nameof(ShowBorder), typeof(bool), typeof(ValidatedEntryCell), false);
public bool ShowBorder
{
get { return (bool)GetValue(ShowBorderProperty); }
set
{
SetValue(ShowBorderProperty, value);
OnPropertyChanged();
}
}
}
I want to change that ShowBorder property in case if Text is empty. I tried several cases how to invoke that property:
Invoking that property straight forward in xaml. Smth like: renderers:ValidatedPicker x:Name="Gender" Title="Gender" ShowBorder="True"
That case works fine.
<renderers:ValidatedEntryCell ShowBorder="{Binding FirstNameIsNotValid}" x:Name="FirstName"... (I setup FirstNameIsNotValid = true in codebehind)
I used converters <renderers:ValidatedEntryCell x:Name="LastName" ShowBorder="{Binding Source={x:Reference LastName}, Converter={StaticResource EmptyTextToBoolConverter}, Path=Text.Length}" that always return true
Tried to use style triggers for property.
Unfortunately anything helps here. Will be glad for any advice
Edit: partially helps that link. For now I can setup property in constructor in codebehind and changes made will be visible.

Custom Intellij language built on the top of XML

First of all, what is my intention. I have a set of XML files in my project. Some of those are hierarchical. The top XML looks like this (very simple example)
<RootElement>
<Element id=1>
<Element id=2>
<Element id=3>
<RootElement>
The element itself contains some other elements and attributes, but it is not relevant in this case.
Than there are many files with this structure:
<RootElement>
<Element id=1 superId=3>
<Element id=2 superId=3>
<Element id=3 superId=2>
<RootElement>
Where the superID is index to root XML file. What I want to implement is a plugin which I would use for simple navigation between those two files.
My idea was to create a new language which will extend XML and add some extra functionality. Only files with specific names (2 or 3) will be part of this language.
I have created the new language:
public class MyLanguage extends XMLLanguage {
public static final MyLanguage INSTANCE = new MyLanguage();
protected MyLanguage() {
super(XMLLanguage.INSTANCE,"MyLanguage", new String[]{"text/xml"});
}
}
New file type:
public class MyLanguageFileType extends XmlLikeFileType {
public static final MyLanguageFileType INSTANCE = new MyLanguageFileType();
protected MyLanguageFileType() {
super(MyLanguage.INSTANCE);
}
#Override
public Icon getIcon() {
return Icons.FILE;
}
And new factory:
public class MyLanguageFileFactory extends XmlFileTypeFactory {
#Override
public void createFileTypes(FileTypeConsumer fileTypeConsumer) {
fileTypeConsumer.consume(MyLanguageFileType.INSTANCE,
new FileNameMatcherFactoryImpl().createMatcher("nameOfXML1.xml"),
new FileNameMatcherFactoryImpl().createMatcher("nameOfXML2.xml")
);
}
What is the first problem? I see files with the right icon, but when I create Anotator and register it to MyLanguage, it doesn't work. When I register the same Annotator to the XML file, annotations works well.
So the first question is, what have I done wrong?
Thanks all.
P.S.: Minimally FileTypeFactory works well because I can see files with specific names with icons I have set to it.
You don't need to implement your own language to support the navigation. All you need to do is to implement a PsiReferenceContributor that will inject references into the attributes of your XML files.
Another solution if you just need code completion and static analysis is to use an <xml.schemaProvider implementation="..."> tag in your plugin.xml file with a custom XmlSchemaProvider that returns a local *.xsd file packaged with your plugin. See JavaFxSchemaProvider for an example of how to do this.

How to develop this Eclipse plug-in: add a menu in the page "properties for XXXProject"

I'm going on developing an Eclipse plugin: collect a config for a project. I want to write a GUI for every project properties so that user can input every config item.
How can I implement it. I have researched for some days, just find a way to add a menu in Eclipse Preferences.
But I want to add menu to project properties. Like: User right-click the project in Eclipse, then click Properties, config menu is in left of the properties dialog.
What should I do?
You add to the properties tree by using the org.eclipse.ui.propertyPages extension point in your plugin.
An example property page declaration:
<extension
point="org.eclipse.ui.propertyPages">
<page
class="org.eclipse.ui.internal.ide.dialogs.ResourceInfoPage"
id="org.eclipse.ui.propertypages.info.file"
name="Resource"
>
<enabledWhen>
<adapt type="org.eclipse.core.resources.IResource"/>
</enabledWhen>
</page>
The above is the declaration of the Resource property page taken from Eclipse. It declares that the property page is provided by the ResourceInfoPage class and that it is only shown (enabled) when the selected object is an IResource (a project, folder or file).
The property page class that you write should extend the org.eclipse.ui.dialogs.PropertyPage class. so a skeleton class would be:
public class MyPropertyPage extends PropertyPage
{
#Override
protected Control createContents(Composite parent)
{
IAdaptable selectedObject = getElement();
Composite composite = new Composite(parent, SWT.NONE);
// TODO add your controls here
return composite;
}
#Override
public boolean performDefaults()
{
// TODO deal with Defaults button
}
#Override
public boolean performOk()
{
// TODO deal with OK button
}
}

How to access the map returned by IParameterValues::getParameterValues()?

I declared a command and a commandParameter for this command. I specified the "values" of this commandParameter as a class implemented by myself. The implementation of this class is below,
public class ParameterValues implements IParameterValues {
#Override
public Map<String, Double> getParameterValues() {
// TODO Auto-generated method stub
Map<String, Double> values = new HashMap<String, Double>(2);
values.put("testParam", 1.1239);
values.put("AnotherTest", 4.1239);
return values;
}
}
The implementation of the handler of this command is blow,
public class testHandler extends AbstractHandler implements IHandler {
private static String PARAMETER_ID = "my.parameter1";
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String value = event.getParameter(PARAMETER_ID);
MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
"Test", "Parameter ID: " + PARAMETER_ID + "\nValue: " + value);
return null;
}
}
Now, I contribute the command to a menu,
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="my.edit"
label="Edit">
<command
commandId="myCommand.test"
label="Test1">
<parameter
name="my.parameter1"
value="testParam">
</parameter>
</command>
Since I specified a "values" class for the commandParater, I expect when the menu is clicked, this code line "String value = event.getParameter(PARAMETER_ID);" in the handler class returns 1.1239 instead of "testParam".
But, I still see that code line returns "testParam".
What's the problem? How could I access the map returned by getParameterValues()?
By the way, following menu declaration still works even I don't define "ppp" in the map.
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="my.edit"
label="Edit">
<command
commandId="myCommand.test"
label="Test1">
<parameter
name="my.parameter1"
value="ppp">
</parameter>
</command>
Thanks!
From the javadoc, org.eclipse.core.commands.IParameterValues.getParameterValues() "Returns a map keyed by externalized names for parameter values. These names should be human-readable, and are generally for display to the user in a user interface of some sort. The values should be actual values that will be interpreted by the handler for the command."
This interface is used to provide translatable names for command parameters. So that "Show View (Package Explorer)" can be displayed in the Keys preference page instead of "Show View (org.eclipse.jdt.ui.PackageExplorer)"
But org.eclipse.ui.menus definitions must contain the parameter value as opposed to a translatable name.
You can define the parameter type and AbstractParameterValueConverter in the command definition if you want to process the string parameters and turn them into various objects.