How to open the View from command in eclipse RCP? - eclipse-plugin

I need to open a view using the code with the help of HandlerUtil, how can I do it in Eclipse RCP ?
I've tried with PlatformUI.
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("MyView");
but I need to perform it with HandlerUtil

Use getActiveWorkbenchWindow in HandlerUtil:
public class MyHandler extends AbstractHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPage workbenchPage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
workbenchPage.showView("MyView");
}
}

Related

How do I make the "user operation is waiting" dialog invisible in Eclipse RCP?

I'm creating a web development framework with Eclipse RCP.
The wizard is creating a feature that creates a project when you press Finish.
I want to show Process Monitor at the bottom of the wizard
I wrote the code as below.
public abstract class CreateProjectWizard extends Wizard {
public CreateProjectWizard () {
...
setNeedsProgressMonitor(true);
}
...
#Override
public boolean performFinish() {
IRunnableWithProgress runnable= new IRunnableWithProgress() {
#Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
...
IStatus status = createProject(input, monitor);
...
}
};
try {
getContainer().run(true, true, runnable);
}
...
return true;
}
}
How do I make the "user operation is waiting" dialog invisible?
I will let you know if you need additional information.
It looks like you should be able to call Dialog.setBlockedHandler with something that implements IDialogBlockedHandler to change this dialog (both in org.eclipse.jface.dialogs).
The blocked handler does not have to display a dialog, the default JFace handler is just:
new IDialogBlockedHandler() {
#Override
public void clearBlocked() {
// No default behavior
}
#Override
public void showBlocked(IProgressMonitor blocking,
IStatus blockingStatus, String blockedName) {
// No default behavior
}
#Override
public void showBlocked(Shell parentShell, IProgressMonitor blocking,
IStatus blockingStatus, String blockedName) {
// No default behavior
}
};
Eclipse normally replaces this with org.eclipse.ui.internal.dialogs.WorkbenchDialogBlockedHandler which shows the dialog you see (BlockedJobsDialog).
Note that this will not stop the operation waiting for the blocking jobs to finish it will just stop the dialog appearing.

Creating a custom run configuration using IntelliJ SDK and adding Build task in Before launch section

I'm following the tutorial in Run Configuration section of IntelliJ IDEA SDK.
Following the tutorial, I will get a new configuration panel with an empty "Before launch" section. That section is added by default.
I would like to specify some targets by default, i.e. at least the Build target as done in several plugins (see next picture)
I'm trying to understand how, but I cannot find any example nor documentation on this.
How can I add default build task?
Your run configuration (DemoRunConfiguration in the example) should implement RunProfileWithCompileBeforeLaunchOption. This interface doesn't provide any methods to implement, so this is a kind of mark. build task will be added automatically, no additional steps are required.
How can I add my own task to before launch section?
Your plugin.xml should contain a line with stepsBeforeRunProvider
<stepsBeforeRunProvider implementation="com.MyBeforeRunProvider" id="myBeforeRun"/>
For that you should create "before run provider" with "before run task".
public class BeforeRunProvider extends BeforeRunTaskProvider<MyBeforeRunTask> {
#Override
public Key<MyBeforeRunTask> getId() {
return Key.create("ThisIsId");
}
#Override
public String getName() {
return "Nice name";
}
#Override
public String getDescription(MyBeforeRunTask task) {
return "Description";
}
#Nullable
#Override
public Icon getIcon() {
return AllIcons.Actions.Compile;
}
#Nullable
#Override
public MyBeforeRunTask createTask(#NotNull RunConfiguration runConfiguration) {
return new MyBeforeRunTask(getId());
}
#Override
public boolean executeTask(#NotNull DataContext dataContext, #NotNull RunConfiguration runConfiguration, #NotNull ExecutionEnvironment executionEnvironment, #NotNull MyBeforeRunTask myBeforeRunTask) {
return true;
}
}
And the task:
public class MyBeforeRunTask extends BeforeRunTask<MyBeforeRunTask> {
protected MyBeforeRunTask(#NotNull Key<MyBeforeRunTask> providerId) {
super(providerId);
setEnabled(true);
}
}

Scrollable Layout in Vaadin Flow

In Vaadin Flow, there exists no Component that is essentially a Scrollable Layout.
In Vaadin 8, this was done by the Panel.
Is there a way to achieve a scrollable Component in Vaadin Flow?
Edit: I have now published an add-on here that provides the class VerticalScrollLayout, and also the class HorizontalScrollLayout. If there are suggestions for improvements, feel free to contact me or comment here.
Yes it is possible, although there is no existing Component that does it automatically.
The way to go is placing a VerticalLayout (for a vertical scroll bar) inside another component, and setting the display property of that VerticalLayout from flex to block. (credits to Diego Sanz Villafruela in the vaadin forum)
I have made my own VerticalScrollLayout class that does it all for you, so that using it in a view is as easy as using a simple VerticalLayout
public class VerticalScrollLayout extends VerticalLayout {
private VerticalLayout content;
public VerticalScrollLayout(){
preparePanel();
}
public VerticalScrollLayout(Component... children){
preparePanel();
this.add(children);
}
private void preparePanel() {
setWidth("100%");
setHeight("100%");
getStyle().set("overflow", "auto");
content = new VerticalLayout();
content.getStyle().set("display", "block");
content.setWidth("100%");
content.setPadding(false);
super.add(content);
}
public VerticalLayout getContent(){
return content;
}
#Override
public void add(Component... components){
content.add(components);
}
#Override
public void remove(Component... components){
content.remove(components);
}
#Override
public void removeAll(){
content.removeAll();
}
#Override
public void addComponentAsFirst(Component component) {
content.addComponentAtIndex(0, component);
}
}
There is now an official component for scrolling:
https://vaadin.com/docs/latest/components/scroller

TestNG, is there a class level listener like IClassListener like ITestListener

I want to perform same action for every class (just like #BeforeClass). I guess listeners can do things where you don't have to write code individually, but I did not find in each method/class but can be executed via a listener. Is there a way to execute my method before every class or just once before method of that class?
Check the beforeConfiguration() method in TestListenerAdapter.
#Override
public void beforeConfiguration(ITestResult tr) {
if(tr.getMethod().getMethodName().equals("methodNameForBeforeClass")) {
//...
}
}
Try configuration related methods in TestListenerAdapter:
class TestNGListener extends TestListenerAdapter {
#Override
public void beforeConfiguration(ITestResult tr) {
super.beforeConfiguration(tr);
logger.info("=========== Configuration method '{}' started ===========", tr.getMethod().getMethodName());
}
#Override
public void onConfigurationSuccess(ITestResult tr) {
super.onConfigurationSuccess(tr);
logger.info("=========== Configuration method '{}' finished ===========", tr.getMethod().getMethodName());
}
#Override
public void onConfigurationFailure(ITestResult tr) {
super.onConfigurationFailure(tr);
logger.error("!!!!!!!!!!! Configuration method '{}' failed !!!!!!!!!!!", tr.getMethod().getMethodName());
}
}
Extend TestListenerAdapter and override onTestStart(ITestResult result) method. This will help you to run something everytime a test starts

Google Guice, Interceptors and PrivateModules

New poster here, hope I don't brake any rules :)
I am using PrivateModule in google-guice in order to have multiple DataSource's for the same environment. But I am having a hard time getting MethodInterceptor's to work inside the private modules.
Below is a simple test case that explains the "problem".
A simple service class would be:
interface Service {
String go();
}
class ServiceImpl implements Service {
#Override #Transactional
public String go() {
return "Test Case...";
}
}
The MyModule class would be:
class MyModule extends AbstractModule {
#Override
protected void configure() {
install(new PrivateModule() {
#Override
protected void configure() {
bind(Service.class).to(ServiceImpl.class);
bindInterceptor(
Matchers.any(),
Matchers.annotatedWith(Transactional.class),
new MethodInterceptor() {
#Override
public Object invoke(MethodInvocation i)
throws Throwable {
System.out.println("Intercepting: "
+ i.getMethod().getName());
return i.proceed();
}
});
expose(Service.class);
}
});
}
}
And the final test case:
public class TestCase {
#Inject Service service;
public TestCase() {
Guice.createInjector(new MyModule()).injectMembers(this);
}
public String go() {
return service.go();
}
public static void main(String[] args) {
TestCase t = new TestCase();
System.out.println(t.go());
}
}
You would expect the output to be:
Intercepting: go
Test Case...
But it doesn't happen, the interceptor is not used, ant only Test Case... is output.
If I bind/expose the ServiceImpl instead of the interface then it works.
Thanks in advance,
Regards,
LL
Well... I figured it out shortly after I posted the question :)
The problem is that you also need to expose() the ServiceImpl class.
So the bind/expose would be.
bind(ServiceImpl.class); // ServiceImpl annotated with #Singleton
bind(Service.class).to(ServiceImpl.class);
expose(ServiceImpl.class);
expose(Service.class);
Regards,
LL
You need to explicitly bind ServiceImpl in the private module. The problem with your existing code is that it inherits the binding for ServiceImpl from the parent module. From the PrivateModule docs,
Private modules are implemented using parent injectors. When it can satisfy their dependencies, just-in-time bindings will be created in the root environment. Such bindings are shared among all environments in the tree.
Adding this line should fix the problem:
bind(ServiceImpl.class);