I have a menu item XYZ. I have a preference page MyPref which has a check box and a couple of text fields. When the check box in MyPref is check, I want menu XYZ to be enabled else it should be disabled. Is there a way to achieve this.
Yes, the way certainly exist.
1). Create an entry in your IPreferenceStore - just get the class which extends AbstractUIPlugin and do the following:
IPreferenceStore store = IExtendAbstractUIPlugin.getDefault()
.getPreferenceStore();
then store some value which will reflect your checkbox state:
preferenceStore.setValue("XYZMenuPreference", false); // if disabled
or
preferenceStore.setValue("XYZMenuPreference", true); // if enabled
2). Create a Property Tester extention to your plugin.xml:
<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.xyz.PropertyTester"
id="org.xyz.PropertyTester"
type="java.lang.Object"
namespace="org.xyz"
properties="XYZmenu">
</propertyTester>
</extension>
3). When declaring your menu handler in plugin.xml you should add the following:
<handler
class="your-menu-handler-class"
commandId="your-command-id">
<enabledWhen>
<with variable="selection">
<test property="org.xyz.XYZmenu" value="true" forcePluginActivation="true"/>
</with>
</enabledWhen>
</handler>
4). Now you need a class "org.xyz.PropertyTester" (as defined in plugin.xml) which will extend the org.eclipse.core.expressions.PropertyTester and override method test(<some args>) where he must check the property value:
if (property.equals("XYZmenu"){
IPreferenceStore store = IExtendAbstractUIPlugin.getDefault()
.getPreferenceStore();
return store.getBoolean("XYZMenuPreference");
}
5). After that add a change listener to your checkbox and use it to re-evaluate a visibility of your menu item:
IEvaluationService service = (IEvaluationService) PlatformUI
.getWorkbench().getService(IEvaluationService.class);
service.requestEvaluation("org.xyz.XYZmenu");
it will force the method test() from your org.xyz.PropertyTester class to be called and will enable your menu item if preference
"XYZMenuPreference" is set to true.
upd.
namespace - a unique id determining the name space the properties are added to
properties - a comma separated list of properties provided by this property tester
this is from official eclipse tutorial so you can feel free to define any namespace and property name, but the you should use it like in point 5.
Related
So I am designing an app that dynamically themes itself based upon an API response. I have been able to programmatically set the colors in the resource dictionary for the rest of my app but I am trying to find out how to set get the button and AppBarButton hover and click colors to fit in my color scheme. I have previously changed this by hardcoding the RequestedTheme property in the required elements.
Is there a way to bind the RequestedTheme property to a static resource set in a resource dictionary that I am able to set programmatically? I am open to accomplishing the theming of the buttons differently if need be but would like to avoid having to bind to a local variable on each page if possible.
Thanks so much!
You could define a custom theme resource class like the following:
public enum MyTheme
{
//
// Summary:
// Use the Application.RequestedTheme value for the element. This is the default.
Default = 0,
//
// Summary:
// Use the **Light** default theme.
Light = 1,
//
// Summary:
// Use the **Dark** default theme.
Dark = 2
}
Then, in resource dictionary, you could define your different theme resource:
<Application.Resources>
<local:MyTheme x:Key="MyTheme">Light</local:MyTheme>
</Application.Resources>
In XAML page, you could reference to it:
<Button Content="test" RequestedTheme="{StaticResource MyTheme}"></Button>
You can then change the value in code with:
App.Current.Resources["MyTheme"] = isThemeDark ? "Dark" : "Light";
I have a costum editor for my own languages and I want to change from the property menu between them and recolor the syntax accordingly. I don't know if I have to use a reconciler or something else. The only way that the syntax is recolored, is by closing and opening the current file.
In your editor you need to listen for property change events from your preference store.
In your initializeEditor method call setPreferenceStore(preferenceStore)
Override the handlePreferenceStoreChanged method:
#Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event)
{
// TODO update settings affected by the event
// TODO If required invalidate the current presentation to update the colors
getSourceViewer().invalidateTextPresentation();
super.handlePreferenceStoreChanged(event);
}
You need to add code to look at the property change event to see if it is one that you need to handle. If the event changes something (such as changing the colors) that needs to text to be redrawn call getSourceViewer().invalidateTextPresentation().
To support all the normal text editor preferences you need to use a chained preference store in the setPreferenceStore call:
IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
IPreferenceStore yourPreferenceStore = get your preference store
IPreferenceStore combinedPreferenceStore = new ChainedPreferenceStore(new IPreferenceStore[] {yourPreferenceStore, generalTextStore});
setPreferenceStore(combinedPreferenceStore);
In JavaFX property can be bound to some observable value.
Label l = new Label();
l.visibleProperty().bind(l.textProperty().length().isEqualTo(3));
l.setText("123"); // show label
l.setText("1234"); // hide label
Recently I have discovered that binding can be done not only in code but in FXML markup document.
<!-- Label is visible only if input is visible. -->
<Label l="Please input some value:" visible="${value.visible}" />
<TextField fx:id="value" />
Is there similar feature in another languages and markup tools or that is kind of oracle innovation? :-)
update: I added XAML tag because I guess it has something similar.
I have found out that QML has the same feature.
I want to display a array of objects in PropertyView/PropertySheet,just like this:
How to do it?
thx.
You can follow this eclipse tips: creating a custom property view, based on PageBookView (which is the kind of view which displays the properties of the selected element in the active part. Whenever the selection changes or the active part changes, it tracks them and displays the properties, unless you used the 'Pin to selection' feature available from 3.5).
<view
class="com.eclipse_tips.views.CustomPropertiesView"
icon="icons/sample.gif"
id="com.eclipse-tips.views.customePropertiesView"
name="My Properties View">
</view>
Followed by:
public class CustomPropertiesView extends PropertySheet {
#Override
protected boolean isImportant(IWorkbenchPart part) {
if (part.getSite().getId().equals(IPageLayout.ID_PROJECT_EXPLORER))
return true;
return false;
}
}
Now this would react to properties from the project explorer (and not your own set of properties).
So you need to get back to the PageBookView article and see how to implement your own display.
I'm extending Eclipse using the Eclipse plugin infrastructure, and I've come into a problem:
I created a text editor and I would like to add actions to the Eclipse toolbar when my editor is open and has focus. For example:
textViewer.getTextWidget().addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
/* add actions */
}
public void focusLost(FocusEvent e) {
/* remove actions */
}
});
The following example of extensionPoint: ActionSet, add the action button to the toolbar permanently:
<action
class="MyActionClass"
id="MyActionID"
label="MyActionLabel"
menubarPath="MyActionMenuBarPath"
toolbarPath="MyActionToolBarPath" <-- this property
...
</action>
how to make this dynamically?
Thank you for your response, I found a simple way to do this, simply add the following extension point if the buttons are ActionSet:
<extension
point="org.eclipse.ui.actionSetPartAssociations">
<actionSetPartAssociation
targetID="myActionSetId">
<part
id="myEditorId">
</part>
</actionSetPartAssociation>
You could look at the Eclipse implementation of similar dynamic toolbar updates.
For example, the Breadcrumb bare can only be activated for Java Editor, and the toolbar "Toggle Breadcrumb" button will not be visible for any other type of editors.
alt text http://img109.imageshack.us/img109/359/eclipsetoolbarupdate.png
That is a ToggleBreadcrumbAction, declared in plugin.xml as
<actionSet
label="%javaEditorPresentationActionSet.label"
visible="false"
id="org.eclipse.jdt.ui.text.java.actionSet.presentation">
<action
allowLabelUpdate="true"
style="toggle"
toolbarPath="org.eclipse.ui.edit.text.actionSet.presentation/Presentation"
id="org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences"
definitionId="org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences"
disabledIcon="$nl$/icons/full/dtool16/mark_occurrences.gif"
icon="$nl$/icons/full/etool16/mark_occurrences.gif"
helpContextId="toggle_mark_occurrences_action_context"
label="%toggleMarkOccurrences.label"
retarget="true"
tooltip="%toggleMarkOccurrences.tooltip">
</action>
<action
allowLabelUpdate="true"
style="toggle"
toolbarPath="org.eclipse.ui.edit.text.actionSet.presentation/Presentation"
id="org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"
definitionId="org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"
disabledIcon="$nl$/icons/full/dtool16/toggle_breadcrumb.gif"
icon="$nl$/icons/full/etool16/toggle_breadcrumb.gif"
helpContextId="toggle_mini_browser_action_context"
label="%toggleBreadcrumb.label"
retarget="true"
tooltip="%toggleBreadcrumb.tooltip">
</action>
</actionSet>
You can try the same kind of definition.