I created a command:
<command
id="disableOrEnableCommand"
name="Disable or Enable Command">
</command>
Then I added a button to the toolbar:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="disableOrEnable">
<command
commandId="disableOrEnableCommand"
label="Disable Me"
style="push">
</command>
</toolbar>
</menuContribution>
</extension>
The next step was binding the command to a handler:
<extension
point="org.eclipse.ui.handlers">
<handler
class="DisableOrEnableHandler"
commandId="disableOrEnableCommand">
</handler>
</extension>
I configured the handler to implement IHandler and IElementUpdater( because I want to update the button text):
public class DisableOrEnableHandler implements IHandler, IElementUpdater{
public boolean isEnabled = true;
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
isEnabled = !isEnabled;
// Trigger somehow the updateElement() method
return null;
}
#Override
public void updateElement(UIElement element, #SuppressWarnings("rawtypes") Map parameters) {
if ( isEnabled) {
element.setText("Disable me");
} else {
element.setText("Enable me");
}
}
// other overriden methods from IHandler and IElementUpdater
}
I am missing one piece of the puzzle, how can I configure the button to trigger the updateElement when the button is pressed?
You use the ICommandService.refreshElements call to call update elements. In the handler you can use something like:
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
ICommandService commandService = window.getService(ICommandService.class);
commandService.refreshElements(event.getCommand().getId(), null);
(code abstracted from org.eclipse.ui.internal.handlers.PinEditorHandler)
Related
I am very new to Xamarin Forms development and I need a popup dialog. I found exactly what I am looking for in https://github.com/rotorgames/Rg.Plugins.Popup, but I cannot for the life of me figure out how to use it. Could someone point me to a working example or provide some direction on use? The README.md on the site is not helping me much.
I want the the popup dialog to appear when a info button is clicked in the top navigation bar. All the popup needs is 1-2 buttons (and labels) for setting user settings.
This is for Xamarin.Forms: iOS and Android.
In simple steps:
Install the plugin in all the projects
Add the PopUp in your
Xaml
Use the methods they provide on the documentacion for Show/Hide the PopUp:
Task PushAsync(PopupPage page, bool animate = true)
Task PopAllAsync(bool animate = true)
They also provide a demo, check it:
https://github.com/rotorgames/Rg.Plugins.Popup/tree/master/src/Demo
Add a reference to the library, i.e. from nuget, to all projects.
Within your Android project, add this Rg.Plugins.Popup.Popup.Init(this, savedInstanceState); inside the MainActivity.cs OnCreate method, before Xamarin Forms Inits.
And the same for the iOS project, inside AppDelegate.cs FinishedLaunching method()
//Android
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Rg.Plugins.Popup.Popup.Init(this, savedInstanceState); /*Must add before the other Xamarin Inits*/
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Xamarin.Forms.Forms.Init(this, savedInstanceState);
}
//iOS
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Rg.Plugins.Popup.Popup.Init(); /* place at the top*/
....
}
Add a new ContentPage (.xaml) to your Views directory.
<?xml version="1.0" encoding="utf-8" ?>
<pages:PopupPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations; assembly=Rg.Plugins.Popup"
x:Class="MyProjectName.Views.MyContentPageName">
<pages:PopupPage.Animation>
<animations:ScaleAnimation
PositionIn="Center"
PositionOut="Center"
ScaleIn="1.2"
ScaleOut="0.8"
DurationIn="400"
DurationOut="300"
EasingIn="SinOut"
EasingOut="SinIn"
HasBackgroundAnimation="True"/>
</pages:PopupPage.Animation>
<StackLayout HorizontalAlignment="FillAndExpand" VerticalAlignment="FillAndExpand">
<!-- place your layout content here ....fx a close popup button -->
<Button Clicked="CloseBtn_Clicked" Text="Close" />
</StackLayout>
</pages:PopupPage>
In the ContentPage (PopupPage) code behind file, add using Rg.Plugins.Popup.Services; and inherit from the following
using Rg.Plugins.Popup.Services;
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyContentPageName: Rg.Plugins.Popup.Pages.PopupPage
{
public MyContentPageName()
{
InitializeComponent();
}
public void OnAnimationStarted(bool isPopAnimation)
{
// optional code here
}
public void OnAnimationFinished(bool isPopAnimation)
{
// optional code here
}
protected override bool OnBackButtonPressed()
{
// Return true if you don't want to close this popup page when a back button is pressed
return true;
}
// Invoked when background is clicked
protected override bool OnBackgroundClicked()
{
// Return false if you don't want to close this popup page when a background of the popup page is clicked
return false;
}
private async void CloseBtn_Clicked(object sender, EventArgs e)
{
await PopupNavigation.Instance.PopAsync(true);
}
}
From the .xaml.cs page, where you would like to open the popup, add this:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Rg.Plugins.Popup.Contracts;
using Rg.Plugins.Popup.Services;
public partial class MyOtherPage : ContentPage
{
private IPopupNavigation _popup { get; set; }
private MyContentPageName _modalPage;
public MyOtherPage()
{
_popup = PopupNavigation.Instance;
_modalPage = new MyContentPageName();
}
protected override void OnAppearing()
{
base.OnAppearing();
_popup.Popped += Popup_Popped;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
_popup.Popped -= Popup_Popped;
}
private async void Tapped_OpenModal(object sender, EventArgs e)
{
await _popup.PushAsync(_modalPage);
}
/// <summary> Triggered when the MyContentPageName popup is closed "PopAsync()" </summary>
private async void Popup_Popped(object sender, Rg.Plugins.Popup.Events.PopupNavigationEventArgs e)
{
/* add your logic here, if necessary */
}
}
*Note: If your modal simply displays static content, there is no need for a _popped event delegate within the OnAppearing()/OnDisappearing().
I want to create a method in a controller of a fxml file, I want this method acts when the slider is changing.
I have a fxml file like this:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="150.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Slider fx:id="mySlider" blockIncrement="0.1" layoutX="26.0" layoutY="32.0" majorTickUnit="0.5" max="1.0" minorTickCount="1" showTickLabels="true" showTickMarks="true" />
<TextField fx:id="textField" layoutX="100.0" layoutY="99.0" prefHeight="25.0" prefWidth="75.0" />
<Label layoutX="43.0" layoutY="103.0" text="Label" />
</children>
</AnchorPane>
and I want to have a controller like this
package paper.view;
import javafx.fxml.FXML;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
public class RootController
{
#FXML
private Slider mySlider;
#FXML
private TextField textField;
mySlider.valueProperty().addListener((observable, oldValue, newValue) -> {
textFieldOfEp.setText(Double.toString(newValue.doubleValue()) );
});
});
}
I want reflect the changes of slider in the textField.
like this picture:
How can I do this through a controller?
I don't want to do this in a start method of main class.
my start methos is like this:
public void start(Stage primaryStage) throws IOException
{
FXMLLoader loader=new FXMLLoader();
loader.setLocation(mainApp.class.getResource("view/Root.fxml"));
AnchorPane ap=loader.load();
Scene scene=new Scene(ap);
primaryStage.setScene(scene);
primaryStage.show();
}
the proposed answer worked.
You should register the listener in the controller's initialize() method:
package paper.view;
import javafx.fxml.FXML;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
public class RootController
{
#FXML
private Slider mySlider;
#FXML
private TextField textField;
public void initialize() {
mySlider.valueProperty().addListener((observable, oldValue, newValue) -> {
textField.setText(Double.toString(newValue.intValue()));
});
}
}
and make sure you either specify the controller in the FXML file:
<AnchorPane fx:controller="paper.view.RootController" prefHeight="150.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
or set the controller on the FXMLLoader directly in code.
This will automatically update the text field when the intValue() of the slider's value changes:
I just accidentally found that property onValueChange does the trick, needing a ChangeListener<Number> signature for the handler (Double works too):
<Slider onValueChange="#doStuff"/>
#FXML
private void doStuff(ObservableValue<Number> ovn, Number before, Number after) {
System.out.println(before+" "+after);
}
Good day,
I am writing to you because I tried to follow your instructions [here: http://wiki.eclipse.org/CDT/cdt-debug-dsf-gdb-extensibility ] for adding a new command to gdb while using cdt eclipse.
I does not seem to work at all. I put print statements in all of the methods of all the extended classes. Nothing gets printed, which indicates that none of these methods are called. Following is my code. What am I missing?
(i didn't get to the point of actually implementing the new services factory since i there
plugin.xml:
<plugin>
<extension
point="org.eclipse.debug.core.launchDelegates">
<launchDelegate
delegate="tracerdubug.MyTracerLaunchDelegate"
id="TracerDubug.MyTracerLaunchDelegate"
modes="debug, run">
</launchDelegate>
</extension>
</plugin>
TracerRunControl:
public class TracerRunControl extends GDBRunControl_7_0 {
public TracerRunControl(DsfSession session) {
super(session);
System.out.println("TracerRunControl");
}
}
//################################################################
public class MyTracerLaunchDelegate extends GdbLaunchDelegate implements ILaunchConfigurationDelegate2{
public MyTracerLaunchDelegate() {
super();
System.out.println("MyTracerLaunchDelegate::ctr()");
}
#Override
public void launch( ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor ) throws CoreException {
System.out.println("MyTracerLaunchDelegate::launch()");
super.launch(config, mode, launch, monitor);
}
#Override
protected IDsfDebugServicesFactory newServiceFactory(String version) {
System.out.println("MyTracerLaunchDelegate");
return new TracerDebugServicesFactory(version);
}
}
//################################################################
public class TracerDebugServicesFactory extends GdbDebugServicesFactory {
public TracerDebugServicesFactory(String version) {
super(version);
// TODO Auto-generated constructor stub
}
#Override
protected ICommandControl createCommandControl(DsfSession session, ILaunchConfiguration config) {
GDBControl_7_0 g = new GDBControl_7_0(session,config);
System.out.println("TracerDebugServicesFactory::createCommandControl");
return g;
}
#Override
protected IRunControl createRunControlService(DsfSession session) {
System.out.println("TracerDebugServicesFactory::createProcessesService");
return new TracerRunControl(session);
}
#Override
protected IProcesses createProcessesService(DsfSession session) {
System.out.println("TracerDebugServicesFactory::createProcessesService");
return new GDBProcesses_7_0(session);
}
}
Thanks,
Shai
I had the same problem and got the answer from another forum. You must add more info and more extensions:
<extension
point="org.eclipse.debug.core.launchDelegates">
<launchDelegate
delegate="tracerdubug.MyTracerLaunchDelegate"
delegate="Tracerdubug.MyTracerLaunchDelegate"
delegateDescription="Your description"
id="org.eclipse.cdt.dsf.gdb.launch.localCLaunch"
modes="debug"
name="My GDB Launch Delegate"
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer"
type="org.eclipse.cdt.launch.applicationLaunchType">
</launchDelegate>
</extension>
<extension point="org.eclipse.debug.ui.launchConfigurationTypeImages">
<launchConfigurationTypeImage
icon="icons/img.gif"
configTypeID="Tracerdubug.MyTracerLaunchDelegate"
id="Tracerdubug.TabGroups.launcher.Image">
</launchConfigurationTypeImage>
</extension>
<extension point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
type="Tracerdubug.MyTracerLaunchDelegate"
class="Tracerdubug.TabGroups.TabGroupTest"
id="Tracerdubug.TabGroups.TabGroupTest">
</launchConfigurationTabGroup>
</extension>
and you need a new class = Tracerdubug.TabGroups.TabGroupTest:
package Tracerdubug.TabGroups;
import org.eclipse.cdt.dsf.gdb.internal.ui.launching.CDebuggerTab;
import org.eclipse.cdt.dsf.gdb.internal.ui.launching.CMainAttachTab;
import org.eclipse.cdt.dsf.gdb.internal.ui.launching.AttachCDebuggerTab;
import org.eclipse.cdt.launch.ui.CArgumentsTab;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.EnvironmentTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
public class TabGroupTest extends AbstractLaunchConfigurationTabGroup {
// Create an array of tabs to be displayed in the debug dialog
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs =
new ILaunchConfigurationTab[] {,
new CMainAttachTab(),
new CArgumentsTab(),
new EnvironmentTab(),
new SourceLookupTab(),
new CommonTab(),
};
setTabs(tabs);
}
}
You can also create your own tabs, see: http://www.eclipse.org/articles/Article-Launch-Framework/launch.html
My command factory is loaded, I'm now learning how to use an existing service to send the command...
I'm very new with VBA in Outlook.
So I'm trying to manipulate the Save Button for the Task Formulars.
I was wondering how to make a "different" Save Button wich actually does the same but with some extras.
So does anybody knows how you can save a Task that you're actually at with a VBA makro???
Thanks for Help
Bruno
You will need to create a new ribbon item that will be your custom button, this item should have your custom save function defined as its handler. Here is an example of how to customise the ribbon
namespace OutlookAddIn
{
[ComVisible(true)]
public class RibbonHook : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
public RibbonHook()
{
}
public string GetCustomUI(string ribbonID)
{
string xml = string.Empty;
switch (ribbonID)
{
case "Microsoft.Outlook.Task":
xml = GetResourceText("OutlookAddIn.RibbonTask.xml");
break;
}
return xml;
}
#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}
public void buttonTaskCustomSave_Action(Office.IRibbonControl control)
{
Outlook.Taskitem taskItem = (Outlook.taskItem)OutlookAddIn.Globals.OLA.Application.ActiveInspector().CurrentItem;
//do stuff with the task here
}
#endregion
#region Helpers
private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourceNames.Length; ++i)
{
if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
}
}
return null;
}
#endregion
}
}
you will need to add this to your main addin class
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new RibbonHook();
}
and this is the ribbon xml
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabTask">
<group id="TaskCustom"
label="Custom Save">
<button id="buttonTaskCustomSave" label="Custom Save" onAction ="buttonTaskCustomSave_Action"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
is it possible to fire a button Click event in code behind in user control?
In C# events can only be invoked from the class that declares them. In case of the Button there is a method called OnClick which raises the ClickEvent but it is protected. So you need to declare class that inherits from Button and change the visibility of OnClick method (or declare some over method that calls base.OnClick)
public class MyButton : Button
{
public new void OnClick()
{
base.OnClick();
}
}
Example of XAML
<StackPanel Background="White" >
<my:MyButton x:Name="TestButton" Click="HandleClick" Content="Test" />
<TextBlock x:Name="Result" />
</StackPanel>
And code behind:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
new Timer(TimerCall,null,0,1000);
}
private void TimerCall(object state)
{
Dispatcher.BeginInvoke(()=>TestButton.OnClick());
}
private void HandleClick(object sender, RoutedEventArgs e)
{
Result.Text = String.Format("Clicked on {0:HH:mm:ss}",DateTime.Now);
}
}
Though it is always easier to call event handler directly.
HandleClick(this,null)
Then there will be no need for extra plumbing.