How to limit Visibility of a popup menu only to a certain Project Type? - eclipse-plugin

I am using menuContributions+popup to show a context menu in my plugin.xml. I need to limit it's visibility only to
certain type of Project(e.g. Dynamic Web Project) (Menu should appear on right click of only parent project folder) and
a particular folder(e.g Web Content) and it's sub folders inside the Project Folder structure.
I was able to achieve the 1) condition to some extent by using
<menuContribution locationURI="popup:common.new.menu?after=additions">
<command
label="Web Wiz"
commandId="commandId"
icon="icons/sample.gif">
<visibleWhen>
<with variable="selection">
<iterate ifEmpty="false"
operator="or">
<instanceof
value="org.eclipse.core.resources.IProject"/>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
but it appears for all kinds of projects...I need to limit it to only a Dynamic Web Project, so what should I add to meet this requirement in plugin.xml?

Add a propertyTester that will test your project type.
Use that tester in the visibleWhen
You can read about property-tester at the eclipse help, or at the extension help itself :)
EDIT - Check this one out as well - http://wiki.eclipse.org/Command_Core_Expressions#Property_Testers (especially the ResourcePropertyTester, which can provide you a built-in implementation that you can use)

For the second condition:
<test forcePluginActivation="true"
property="testWizard.propertyTester.checkFolder"
value="org.eclipse.wst.jsdt.core.jsNature"
</test>
is the reference to the property tester , which can be defined as
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="testwizard.wizards.MyPropTester"
id="MyPropTesterFolder"
namespace="testWizard.propertyTester"
properties="checkFolder"
type="org.eclipse.core.resources.IFolder">
</propertyTester>
then the kind of folder and it's subfolders can be tested as below in
package testwizard.wizards;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
public class MyPropTester extends PropertyTester{
#Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
IFolder folder=(IFolder)receiver;
String folderPath=folder.getProjectRelativePath().toString();
String arr[]=folderPath.split("/");
try {
if(folder.getProject().hasNature(expectedValue.toString()))
{
if(arr[0].equals("XYZ"))
{
return true;
}
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
}

<menuContribution locationURI="popup:common.new.menu?after=additions">
<command
label="Web Wiz"
commandId="commandId"
icon="icons/sample.gif">
<visibleWhen>
<with variable="selection">
<iterate operator="and" ifEmpty="false">
<test
property="org.eclipse.core.resources.projectNature"
value="your-project-nature" />
</iterate>
</with>
</visibleWhen>
</command>
<menuContribution>

Related

how do I add a RCP project to eclipse menu?

I have an eclipse RCP application (already built). I need to integrate it with eclipse UI itself. What I mean is -- I want to add a menu option in eclipse User Interface and a command in the menu which when clicked runs the application.
It is similar to find and replace option in the eclipse menu
Any idea how this can be done?
I also want the application to be bundled with eclipse
Write a plugin that you install in to Eclipse (rather than your RCP).
The plugin can use the org.eclipse.ui.menus extension point to add to the File menu. For example:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:file?after=open.ext">
<command
commandId="my.command.id"
id="my.menu.id"
style="push">
</command>
</menuContribution>
Use the org.eclipse.ui.commands extension point to define the command
<extension
point="org.eclipse.ui.commands">
<command
id="my.commnd.id"
description="Description text"
name="Name">
</command>
Use the org.eclipse.ui.handlers extension point to define a handler for the command
<extension
point="org.eclipse.ui.handlers">
<handler
class="package.CommandHandler"
commandId="my.command.id">
</handler>
The handler contains the code to run your RCP:
public class CommandHandler extends AbstractHandler
{
public Object execute(ExecutionEvent event) throws ExecutionException
{
// TODO launch your RCP
return null;
}
}

Optional Resources in Spring.Net

How to include Spring configuration files optionally? I think about something simular to this:
<spring>
<context>
<resource uri="file:///Objects/RequiredObjects.xml" />
<resource uri="file:///Objects/OptionalObjects.xml" required="false" />
</context>
This way I could provide developers the possibility to override some configuration parts (e.g. for a local speed improvement or automatism during app startup) without affecting the app.config and the problem that a developer could checkin his modified file when it is not really his intent to change the config for all.
Not as simple as in AutoFac (because there is already a builtin way) but possible to achieve something similar with a little coding:
using System.IO;
using System.Xml;
using Spring.Core.IO;
public class OptionalFileSystemResource : FileSystemResource
{
public OptionalFileSystemResource(string uri)
: base(uri)
{
}
public override Stream InputStream
{
get
{
if (System.IO.File.Exists(this.Uri.LocalPath))
{
return base.InputStream;
}
return CreateEmptyStream();
}
}
private static Stream CreateEmptyStream()
{
var xml = new XmlDocument();
xml.LoadXml("<objects />");
var stream = new MemoryStream();
xml.Save(stream);
stream.Position = 0;
return stream;
}
}
Register a section handler:
<sectionGroup name="spring">
...
<section name="resourceHandlers" type="Spring.Context.Support.ResourceHandlersSectionHandler, Spring.Core"/>
...
</sectionGroup>
...
<spring>
<resourceHandlers>
<handler protocol="optionalfile" type="MyCoolStuff.OptionalFileSystemResource, MyCoolStuff" />
</resourceHandlers>
...
<context>
<resource uri="file://Config/MyMandatoryFile.xml" />
<resource uri="optionalfile://Config/MyOptionalFile.xml" />
...
You'll find more information about resources and resource handlers in the Spring.Net documentation.

Reading mule config from database

Is it possible to read mule configuration file path (file endpoints), smtp host /user/password (smtp endpoints) from database.We finally want to provide a User Interface , where the user can edit the properties through the screen.The normal properties file approach (key/Value) pairs was used earlier but needs to change to read these properties from the database.Any help on this will be greatly appreciated.
Yes, you can use a custom properties provider.
Its configuration would look like this:
<spring:bean class="org.mule.DatabasePropertiesProvider" id="DatabasePropertiesProvider"/>
<spring:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<spring:property name="properties">
<spring:bean factory-bean="DatabasePropertiesProvider" factory-method="getProperties" />
</spring:property>
</spring:bean>
And the code for DatabasePropertiesProvider is as simple as this:
public class DatabasePropertiesProvider {
public Properties getProperties() throws Exception {
Properties properties = new Properties();
// get properties from the database
return properties;
}
}

Eclipse conflicting handlers

On developing an eclipse plugin i created a command in the Manifest extensions with id crtc_v4.session with a default handler crtc_v4.handlers.StartSession , I added a handler in the manifest for this command this handler enables the command according to the variable crtc_v4.sessionvar.
The problem which appears on the console is :
!MESSAGE Conflicting handlers for crtc_v4.session: {crtc_v4.handlers.StartSession#98bc5c} vs {crtc_v4.handlers.StartSession#1265d09}
But it doesn't block running the plugin. I'm asking about the solution for this problem, and whether it affects the performance of my plugin in general ?
Edit :
The snippet that define the command :
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="crtc_v5.crtctoolbar">
<command
commandId="crtc_v5.session"
icon="icons/neutral.png"
label="Start Session"
style="push">
</command>
</toolbar>
</menuContribution>
The snippet that define the handler :
</extension>
<command
defaultHandler="crtc_v5.handlers.StartSession"
id="crtc_v5.session"
name="session">
</command>
</extension>
And here is the enablement against sessionvar :
<extension
point="org.eclipse.ui.handlers">
<handler
class="crtc_v5.handlers.StartSession"
commandId="crtc_v5.session">
<enabledWhen>
<with
variable="crtc_v5.sessionvar">
<equals
value="LOGGEDIN">
</equals>
</with>
</enabledWhen>
</handler>
You've defined a default handler in the command and another one in the org.eclipse.ui.handlers extension. If you want to use enabledWhen, simply remove the defaultHandler attribute (since both instances provide the same handler, crtc_v5.handlers.StartSession).
When you want to have different handlers provide the behaviour for your command depending on the application state, you would use activeWhen in the org.eclipse.ui.handlers definition, but that doesn't seem to be the case here.

With arquillian incontainer mode ,Why Test method is getting exeduted square of the times of values returned by data provider in testng?

I'm using TestNG as Unit Test Framework and Jboss AS7.1.1 Final as server
The data provider and Test methods works well in Client Mode
The same dataprovider will return 10 rows and my Test method is getting executed nearly 100times in In container mode
Test method
#Test(groups="bean-tests",dataProvider="Presenter-Data-Provider")
public void findByIdPositiveTest(long presenterId,String expectedPresenterName)
{
}
Dataprovider method:
#DataProvider(name = "Presenter-Data-Provider")
public Object[][] presenterTestDataProvider()
{
EntityManagerFactory emf=null;
EntityManager em=null;
Object testcaseData[][]=null;
Session session=null;
try
{
emf=Persistence.createEntityManagerFactory("TestCaseDataSource");
em=emf.createEntityManager();
session=em.unwrap(Session.class);
Criteria query=session.createCriteria(TestPresenter.class).setFirstResult(0).setMaxResults(10);
List<TestPresenter> rowList=query.list();
testcaseData=new Object[rowList.size()][2];
for(int loopCount=0;loopCount<rowList.size();loopCount++)
{
TestPresenter row=rowList.get(loopCount);
testcaseData[loopCount][0]=row.getPresenterId();
testcaseData[loopCount][1]=row.getExpectedPresenterName();
}
}
catch(Exception exception)
{
mLog.error(exception.getMessage());
}
return testcaseData;
}
I'm running as Test Suite using folowing Suite configuration
<test name="Bean testing">
<groups>
<run>
<!-- This has to be added by default while using arquillian Test Runner -->
<include name="arquillian" />
<include name="bean-tests" />
</run>
</groups>
<classes>
<class name="blah.blah.blah.PresenterManagerBeanTest" />
</classes>
</test>
Pls let me know What I did was wrong
Or direct me how to get values from DB to Data provider and tests using In container mode
Thanks in advance
sathiya seelan
It looks like it's related to https://issues.jboss.org/browse/ARQ-1282. Issue is still open.