Hello World Widget
This post describes how to create a Workbook HomePage Widget like the one shown above, and deploy it to the Workbook server.
Solution Setup in Visual Studio 2017
Create a new Visual C# (.NET Framework) Class Library project and solution.
Set the default namespace to something according to this template MyCompany.MyProject.MyWidget.
Add references to the following .dll files from the Workbook SDK:
Symyx.Framework.dll Symyx.Notebook.dll Symyx.Notebook.Applications.dll
Create the view class
Add a UserControl and name it HelloWorldWidgetView.
Edit the code, add a using statement for "Symyx.Notebook.HomePage", and change the base class to "UserControlWidgetView".
Code for UserControlWidgetView.cs:
using Symyx.Notebook.HomePage; namespace BIOVIA.Example.HelloWorldWidget { public partial class HelloWorldWidgetView: UserControlWidgetView { public HelloWorldWidgetView() { InitializeComponent(); } } }
Modify the appearance of the control as you like in the designer. Mine just has a label with the text "Hello World":
Create the view builder class
Add a Class and name it HelloWorldWidgetViewBuilder.
Edit the code, add a using statement for "Symyx.Notebook.HomePage", and change the base class to "WidgetViewBuilder".
You need to at least override the "CreateView" method and the "WidgetViewType" property.
Code for HelloWorldWidgetViewBuilder:
using System; using Symyx.Notebook.HomePage; namespace BIOVIA.Example.HelloWorldWidget { public class HelloWorldWidgetViewBuilder: WidgetViewBuilder { public override IWidgetView CreateView() { return new HelloWorldWidgetView(); } public override Type WidgetViewType => typeof(HelloWorldWidgetView); } }
Create the widget class
Add a class and name it HelloWorldWidget.
Edit the code, add a using statement for "Symyx.Notebook.Applications.HomePage", and change the base class to "HomePageWidget".
You need to override the "WidgetViewBuilders" and the "ConfigurationViewBuilders" properties.
Code for HelloWorldWidget:
using System.Collections.Generic; using System.Runtime.Serialization; using Symyx.Notebook.Applications.HomePage; using Symyx.Notebook.HomePage; namespace BIOVIA.Example.HelloWorldWidget { [DataContract] public class HelloWorldWidget: HomePageWidget { public HelloWorldWidget() { Title = "Hello World"; } public override void ResetDefaultValues() { base.ResetDefaultValues(); Title = "Hello World"; } public override IEnumerableWidgetViewBuilders => new List { new HelloWorldWidgetViewBuilder() }; public override IEnumerable ConfigurationViewBuilders => new List { new GenericUserControlConfigurationViewBuilder() }; } }
Create the package for deployment
The widget must be deployed to the Workbook server, so all users can use it. The easiest way to do this is to create a deployable package in a .vozip file.
You may have come across these files when deploying HF releases.
Add a new Console App (.NET Framework) project to the solution and name it PackageCreator.
Add references to the following .dll files from the Workbook SDK:
Symyx.Framework.dll Symyx.Notebook.dll Symyx.Notebook.Applications.dll
You also need to reference the other project (HelloWorldWidget).
Set the default namespace to the same as for the other project.
Set the project as the startup project in the solution.
Edit the Program.cs file to have the following content:
using Symyx.Framework.Vault.Packaging; namespace BIOVIA.Example.PackageCreator { class Program { static void Main(string[] args) { using (var package = VaultObjectPackage.Create("HelloWorldWidget.vozip")) { var widget = new HelloWorldWidget.HelloWorldWidget(); package.Add(widget, package); } } } }
When you run this, it will create a file "HelloWorldWidget.vozip" to the output of the project.
Deploy package
Log in to the Workbook server using the Workbook client.
Navigate to the "Site\Shared\Widgets" folder in "Notebook Explorer".
Click "Publish vozip..." from the context menu.
Select the "HelloWorldWidget.vozip" file you created previously, and click the "Open" button. This will upload the package to the server.
Add widget
You can now open the HomePage tab and add the widget:
Select the "Hello World" widget, and click the "OK" button.