Changing starting view in AvaloniaUI project - avaloniaui

I want to change starting view. It displays MainWindow by default.
I created Start view with cli command and Start view model similarly to MainWindow files.
When I add lines:
<Design.DataContext>
<vm:StartViewModel/>
</Design.DataContext>
to Start.xaml file I get and error:
System.Xaml.XamlException: Exception has been thrown by the target of an invocation.
And when I try to replace MainWindow with Start in App file like this:
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new Start
{
DataContext = new StartViewModel()
};
}
base.OnFrameworkInitializationCompleted();
}
}
I get:
The type or namespace "Start "could not be found.
How can I make this work ?

Related

AvaloniaUI: Setup was already called on one of AppBuilder instances

Whenever I try to restart Avalonia application form base application, I get an exception: "Setup was already called on one of AppBuilder instances." on SetupWithLifetime() call.
Application Startup code is:
public static void Start()
{
lifeTime = new ClassicDesktopStyleApplicationLifetime()
{
ShutdownMode = ShutdownMode.OnLastWindowClose
};
BuildAvaloniaApp().SetupWithLifetime(lifeTime);
lifeTime.Start(new[] { "" });
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
Application shutdown code is:
lifeTime.Shutdown();
lifeTime.Dispose();
Here's a link to functional example code, which produces this error: https://pastebin.com/J1jqppPv
Has anyone encountered such problem? Thank you
SetupWithLifetime calls Setup which can only be called once. A possible solution is to call SetupWithoutStarting on BuildAvaloniaApp, which can only be called once as well, for example:
private static AppBuilder s_builder;
static void Main(string[] args)
{
s_builder = BuildAvaloniaApp();
}
public static void Start()
{
lifeTime = new ClassicDesktopStyleApplicationLifetime()
{
ShutdownMode = ShutdownMode.OnLastWindowClose
};
s_builder.Instance.Lifetime = lifeTime;
s_builder.Instance.OnFrameworkInitializationCompleted();
lifeTime.Start(new[] { "" });
}
private static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
Additional note: Restarting the app probably won't work on macOS.

Adding a DeclarativeComponent in a UIComponent at runtime. Oracle JDeveloper 12c

I've been working in this project for abou a week and haven't find a solution to my problem.
For testing purposes I create a simple new DeclarativeComponent which is a panelGroupLayout that contains 2 OutputText. After that I deploy the jar file and add it to my other Fusion web application libraries.
I want to add this DeclarativeComponent in another UIComponent at runtime by pressing a button which contains the next code in the javabean:
`public void addComponent(ActionEvent actionEvent)
{
// Add event code here...
createOutputComponent();
}
private void createOutputComponent()
{
CuadroDeTextoComponent ui = new CuadroDeTextoComponent(); //This is my Declarative Component
UIComponent parentUIComponent = getPglComponente(); This is the panelGrouopLayout in which i want to add my declarativeComponent
addComponent(parentUIComponent, ui);
}
public void addComponent(UIComponent parentUIComponent, UIXDeclarativeComponent childUIComponent)
{
parentUIComponent.getChildren().add(childUIComponent);
AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
}`
I have tried draging the declarative component and it works, but when I do it dynamically the component doesn't display
For your component to display you may need to add a PPR refresh to it's parent element :
In your case :
public void addComponent(ActionEvent actionEvent)
{
// Add event code here...
createOutputComponent();
}
private void createOutputComponent()
{
CuadroDeTextoComponent ui = new CuadroDeTextoComponent(); //This is my Declarative Component
UIComponent parentUIComponent = getPglComponente(); This is the panelGrouopLayout in which i want to add my declarativeComponent
addComponent(parentUIComponent, ui);
addPPR(parentUIComponent); //Refresh the parent component
}
public void addComponent(UIComponent parentUIComponent, UIXDeclarativeComponent childUIComponent)
{
parentUIComponent.getChildren().add(childUIComponent);
AdfFacesContext.getCurrentInstance().addPartialTarget(parentUIComponent);
}
public static void addPPR(UIComponent component) {
if (component != null) {
AdfFacesContext.getCurrentInstance().addPartialTarget(component.getParent());
}
}

Use Yii CRON command to execute and action in a Controller

I have an action inside a controller MyController:
public function actionMyAction()
{
//To do
}
I also have a console command class /protected/commands/TestMyCommand.php
class TestMyCommand extends CConsoleCommand {
public function actionDoMyCommand($args) {
$class = new MyController;
$result = $class->actionMyAction();
}
}
In my yiiBase.php, I have this line:
else
include($className.'.php');
Which throws an error:
PHP Error[2]: include(MyController.php): failed to open stream: No such file or directory
When I run this commant.
php /var/www/html/path/protected/yiic.php testmycommand domycommand
When I try calling any other php file in my shared folder, the error is not throw.
Is there a way I can execute my action without transferring the function to a file in the shared folder?
I resulted to creating a MyActionUtils.php in the libraries/shared folder and transferred the logic from the controller to the file.
class MyActionUtils
{
public function __construct()
{
}
public function actionMyAction()
{
//To do
}
Then I changed my command to:
class TestMyCommand extends CConsoleCommand {
public function actionDoMyCommand($args) {
$class = new MyActionUtils;
$result = $class->actionMyAction();
}
}
Then I called my cron by navigating to the folder containing yiic.php and running the command: ./yiic testmycommand

Add custom console to Eclipse console list

Based on this tutorial, I'm creating an Eclipse plugin which provides a new console, The console is added to the view and I can print messages there, but for some reason it is not added to the consoles list (the dropdown list in the view's corner, see image below).
This is how I'm creating the console:
public void createConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager consoleManager = plugin.getConsoleManager();
console = new MessageConsole(name, null);
consoleManager.addConsoles(new IConsole[]{console});
}
And then I can print messages using this method:
public void print(String msg) {
MessageConsoleStream out = console.newMessageStream();
out.println(msg);
}
Also I'm using this method to bring the console view to the front:
public void bringToFront() {
try{
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String id = IConsoleConstants.ID_CONSOLE_VIEW;
IConsoleView view = (IConsoleView) page.showView(id);
view.display(console);
} catch(PartInitException e) {
e.printStackTrace();
}
}
Any suggestions?
To add a new type of console to the console view, you need to provide a consoleFactories extension:
<extension
point="org.eclipse.ui.console.consoleFactories">
<consoleFactory
class="com.example.MyConsoleFactory"
icon="icons/etool16/my-console.png"
label="My Console">
</consoleFactory>
</extension>
The factory class needs to provide an implementation for openConsole in which your console is created and shown, just like you did in your existing code:
class ConsoleFactory implements IConsoleFactory {
#Override
public void openConsole() {
IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
MyConsole console = new MyConsole();
consoleManager.addConsoles( new IConsole[] { console } );
consoleManager.showConsoleView( console );
}
}

Show a Dialog() or MessageDialog() from the MainWindow.cs?

I'm trying to display a Dialog() or MessageDialog() from my MainWindow.cs (standard MainWindow.cs file that is created from the C# GTK# 2.0 Project template).
I'm getting a rather nasty error when using the below code:
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build();
}
public void CreateAlert(string message)
{
Console.WriteLine(string.Format("CreateAlert() - message: {0}", message));
Dialog dialog = new Dialog("Error", this, Gtk.DialogFlags.DestroyWithParent);
dialog.Modal = true;
dialog.AddButton ("OK", ResponseType.Close);
dialog.Response += on_dialog_response;
dialog.Run ();
dialog.Destroy ();
}
}
I believe the cause of this error is the second param in the Dialog() constructor - "this". My question is... how does one satisfy the second param of "Window win" when inside the MainWindow.cs?
Thanks in advance.