How can I open a JPanel that implements CytoPanelComponent from a context menu task? - cytoscape

I have a context menu task registered as a NodeViewTaskFactory. When I select the context menu item, I want to open the custom JPanel (that implements CytoPanelComponent).
MyPanel myPanel = new MyPanel(...);
registerService(context, myPanel, CytoPanelComponent.class, new Properties());
The panel is available in Cytoscape, but in my task the registrar can't find the service.
public void run(final TaskMonitor taskMonitor) throws Exception {
MyPanel view = registrar.getService(MyPanel.class);
Any tips or suggestions would be appreciated.
Thanks,
Mike
I was hoping to grab the service and open the Panel, but I get an error dialog that states: "Couldn't find service: ....MyPanel"

Related

Vaadin 23: BeforeLeaveEvent vs DialogCloseActionEvent

Context: In a Vaadin 23 application there is a form that is reachable directly via URL. It registers a BeforeLeaveListener with UI.getCurrent().addBeforeLeaveListener(bll);. The implementation of the BeforeLeaveListener is this:
#Override
public void beforeLeave(BeforeLeaveEvent event) {
ContinueNavigationAction action = event.postpone();
askAndProceedIfOk(() -> {action.proceed();});
}
It explicitly postpones the BeforeLeaveEvent and explicitly proceeds the event.
In the application there's a second form that is opened in a modal dialog with the option to close it.
Dialog modalDialog = new Dialog();
modalDialog.setCloseOnEsc(true);
modalDialog.setCloseOnOutsideClick(true);
modalDialog.setModal(true);
The BeforeLeaveListener doesn't work here, but a ComponentEventListener<Dialog.DialogCloseActionEvent> does:
modalDialog.addDialogCloseActionListener(new ComponentEventListener<Dialog.DialogCloseActionEvent>() {
#Override
public void onComponentEvent(Dialog.DialogCloseActionEvent event) {
myForm.askAndProceedIfOk(() -> {modalDialog.close();});
}
});
Surprise: I am surprised that BeforeLeaveEvent and DialogCloseActionEvent work different:
BeforeLeaveEvent offers postpone() and proceed()
DialogCloseActionEvent seems to be implicitly postponed just by showing another modal Dialog that asks the user whether to save unsaved changes. And I do have to close the modal dialog explicitly.
Question: Is it right that both events (with a similar task) work that different or do I miss some details here?

When compiling Specflow project - generation error reported

I am creating a new Specflow project in VS2017. I have added 1 rule in the features file and generated the initial steps code. However, when I attempt to build the project I get the following 2 errors.
(1) CS1029 #error: 'Generation error: Object reference not set to an instance of an object.'
(2) Custom tool error: Generation error: Object reference not set to an instance of an object.
Feature file contains,
Feature: Change_Theme_Change_Scheme
#Change_Theme_Change_Scheme
Scenario: Verfy change of scheme
Given I log into Admin site
And I navigate to Colour Scheme page
And I select the Kumho theme
When I click the Save Theme button
Then Check website main menu background is Red
Steps file contains,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
namespace Tyres_and_Service_Tester.Steps
{
[Binding]
public sealed class Change_Theme_Change_Scheme
{
[Given(#"I log into Admin site")]
public void GivenILogIntoAdminSite()
{
ScenarioContext.Current.Pending();
}
[Given(#"I navigate to Colour Scheme page")]
public void GivenINavigateToColourSchemePage()
{
ScenarioContext.Current.Pending();
}
[Given(#"I select the Kumho theme")]
public void GivenISelectTheKumhoTheme()
{
ScenarioContext.Current.Pending();
}
[When(#"I click the Save Theme button")]
public void WhenIClickTheSaveThemeButton()
{
ScenarioContext.Current.Pending();
}
[Then(#"Check website main menu background is Red")]
public void ThenCheckWebsiteMainMenuBackgroundIsRed()
{
ScenarioContext.Current.Pending();
}
}
}
Image of project references
I've not come across this before when building Specflow projects with earlier versions of VS, and cannot figure out what I've done differently
Many thanks for any help. Tony
Thank you for all your responses. I decided to start from scratch again adding the Specflow packages to VS, and recreating the features, steps etc. As you might of guessed it worked this time - so I'm at a loss what might of been going on. Anyway this question can be closed.

Using DataConnectionDialog

When I am attempting to use the DataConnectionDialog from NuGet (version 1.2), I receive the Advanced Settings dialog for setting up the Database Connection. Is there some Setting I have missed or additional library to retreive?
Code:
using System;
using Microsoft.Data.ConnectionUI;
DataConnectionDialog dcd = new DataConnectionDialog();
DataSource.AddStandardDataSources(dcd);
dcd.SelectedDataSource = DataSource.SqlDataSource;
dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
DataConnectionDialog.Show(dcd);
Output:
What I want (this comes from the datasource wizard in Visual Studio Community 2015):
I happened to stumble on the same issue. From my main form, I called an async method using Task.Factory.StartNew. This method tries to open the Data Connection Dialog but it would show the Advance Settings dialog box instead.
During troubleshooting, I replaced the DataConnectionDialog with a OpenFileDialog and this gave me a ThreadStateException which pointed me towards the solution.
To solve it, I had to put the code in a separate function, e.g. AskConnectionString and call it using Control.Invoke.
e.g.
public void btnConnString_Click(object sender, EventArgs e)
{
_connectionString = (string)this.Invoke(AskConnectionString);
}
public string AskConnectionString()
{
DataConnectionDialog dcd = new DataConnectionDialog();
DataSource.AddStandardDataSources(dcd);
dcd.SelectedDataSource = DataSource.SqlDataSource;
dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
DataConnectionDialog.Show(dcd);
return dcd.ConnectionString;
}

Does detach() method call after attach() method?

I have a simple UI class
public class HelloWorldUI extends UI {
#Override
protected void init(VaadinRequest request) {
System.out.println("Initialized !");
final VerticalLayout layout = new VerticalLayout();
layout.addComponent(new Label("Hello World !"));
setContent(layout);
}
#Override
public void detach() {
System.out.println("Detach !");
super.detach();
}
#Override
public void attach() {
System.out.println("Attach !");
super.attach();
}
}
When first time my UI was loaded , I see outputs at my console as
Attach !
Initialized !
It is OK and this is what I expected. But when I refresh the browser , my console outputs were
Attach !
Initialized !
Detach !
Amazing ! I think Detach ! may be produce first because (as I think) when browser was refreshed , detach() method should be call and attach() , init() should be follow . But actually detach() method will call after attach() method. What's wrong my thinking ?
Browser Refresh = New UI Instance
When you refresh a browser window or tab, a new UI instance is created. So you see an attach message of a new UI instance. The old UI instance will be detached later.
This is default behavior in Vaadin 7. You may change that behavior with an annotation.
#PreserveOnRefresh
Adding #PreserveOnRefresh annotation to the UI changes the behavior: No new UI instance won't be created on refresh.
To quote the doc for this annotation:
Marks a UI that should be retained when the user refreshed the browser window. By default, a new UI instance is created when refreshing, causing any UI state not captured in the URL or the URI fragment to get discarded. By adding this annotation to a UI class, the framework will instead reuse the current UI instance when a reload is detected.

How to make a blackberry application start , by code?

I have a background function listening for push messages. I need to handle though the push. I created the function to take any actions when the push arrives and it works pretty well. For example when a push arrives i increment a number etc etc.
However what would be the code to actually make the application start , when the user presses ok to the push?
I just need to make the application start normally , like the user just pressed on the icon of the app.
I am using OS < 7.X
One typical pattern is to build an application that has two entry points. That is, it can be started in two different ways. One way, would be the normal UiApplication. That's the standard BlackBerry app that can be started with a home screen icon press.
The other way would be to define a background service, that handles push notifications, and is started by the OS as soon as the device boots.
You'll define the background/push entry point by adding an Alternate Entry Point in your app's BlackBerry_App_Descriptor.xml file. Make sure to check Auto-run at Startup and Do not display the application icon .... Your app descriptor xml file should then contain something like this, in addition to the normal entry point for the UiApplication:
<AlternateEntryPoints>
<AlternateEntryPoint Title="PushService" MainMIDletName=""
ArgumentsForMain="-push" HomeScreenPosition="0"
StartupTier="7" IsSystemModule="true"
IsAutostartup="true" hasTitleResource="false"
TitleResourceBundleKey="" TitleResourceBundleName=""
TitleResourceBundleClassName="" TitleResourceBundleRelativePath="">
<Icons/>
<KeywordResources KeywordResourceBundleName="" KeywordResourceBundleRelativePath="" KeywordResourceBundleClassName="" KeywordResourceBundleKey=""/>
</AlternateEntryPoint>
</AlternateEntryPoints>
Then, you'll have a main program like this:
public class MyApp extends UiApplication
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("-push")) {
// this is the push service
PushAgent pa = new PushAgent();
pa.enterEventDispatcher();
} else {
// UiApplication
MyApp app = new MyApp();
app.enterEventDispatcher();
}
}
}
Where PushAgent is a class that extends Application, not UiApplication.
Then, when your push agent receives a notification and you decide you want to show the UI, use something like this:
ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();
// String[] used for command line args, but we don't pass any to the UI app
ApplicationDescriptor ui = new ApplicationDescriptor(ad, new String[] { });
ApplicationManager.getApplicationManager().runApplication(ui);
try this -
When you click the ok button use the following code to run your ui application.
public void dialogClosed(Dialog dialog, int choice) {
switch (choice) {
case Dialog.OK:
try {
ApplicationDescriptor[] appDescriptors =CodeModuleManager.getApplicationDescriptors(CodeModuleManager.getModuleHandle("BlackBerryCity")); //here BlackBerryCity is the COD module Name
ApplicationDescriptor appDescriptor = new ApplicationDescriptor(appDescriptors[0], new String[] {"BlackBerryCity"});
ApplicationManager.getApplicationManager().runApplication(appDescriptor);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case Dialog.CANCEL:
break;
default:
break;
}
}
class EntryPointForApplication extends UiApplication {
private static EntryPointForApplication theApp;
public EntryPointForApplication() {
GUIApplication scr = new GUIApplication();
pushScreen(scr);
}
}
Read this also How to setup alternate entry point in Blackberry application?
For sake of completeness here are all the options that you can use to launch an application:
I am assuming that you already have multiple entry points - one for the background listener and one for the UI Application. Also assuming that you are not passing any Application Arguments for the UI App. (See Nate's answer for full description of how to do this.)
Using runApplication() method:
ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();
// String[] used for command line args, but we don't pass any to the UI app
ApplicationDescriptor ui = new ApplicationDescriptor(ad, new String[] { });
//Launch the application and ask it to come in foreground
ApplicationManager.getApplicationManager().runApplication(ui, true);
Using launch() method:
String modulename = "mymodule";
ApplicationManager.launch(modulename);
Using launchApplication() method:
String modulename = "mymodule";
ApplicationManager.launchApplication(modulename);
One thing to note is that if your UI app is already open, all these methods will simply bring it to foreground in whatever condition it it. If you require the click of button to open a new instance of your app, you will have to pass some random parameter as the application arguments and then ignore it in the main method.

Resources