Eclipse Plugin Development - Modify the outline of JavaScript editor - java

I'm writing an eclipse plugin for JOII but got stuck on modifying the outline in a JavaScript editor.
I have a ContentAssistant that provides me with a list of ICompletionProposal and got the IJavaCompletionProposalComputer functioning perfectly, giving me nice code completions as I type. There is, however, no outline for it (besides the default javascript stuff).
So the question is: How do I hook the ContentAssistant into something that alters/updates the outline view?
Example code I'm parsing with the plugin:
var SomeClass = Class({
foo: function() {},
bar: function() {}
});
In the outline, "SomeClass" is shown as: SomeClass : Any, but I'd like it to display itself as an actual class with the members.
I've been searching all day (litterally) for an example on this, but no luck..
Thanks in advance!!

Related

An icon exists in all pages, how to code this without using repetitive code?

I have a small chat icon shown in all web pages. How to write in Cypress?
The small chat icon has class of Widget and it should be found in all pages.
I could write something like this below, but I wonder if there is any other way to get rid of repetitive should('have','Widget') although, at this point I'm not even sure if using should('have','Widget') is a correct practice but it works.
cy.get('.pageA').should('have.value', 'Widget')
cy.get('.pageB').should('have.value', 'Widget')
cy.get('.pageC').should('have.value', 'Widget')
cy.get('.pageD').should('have.value', 'Widget')
I am using Cypress with Cucumber Preprocessor.
If the assertions line up within a single test, you can take a data-driven approach
['.pageA', '.pageB', '.pageC', '.pageD'].forEach(page => {
cy.get(page).should('have.value', 'Widget')
})
or if you want individual tests
['.pageA', '.pageB', '.pageC', '.pageD'].forEach(page => {
it(`Page ${page} has the icon`, () => {
cy.get(page).should('have.value', 'Widget')
})
});
A more concrete example from a Cypress tutorial,
it.only('Handles filter links', () => {
const filters = [
{link: 'Active', expectedLength: 3},
{link: 'Completed', expectedLength: 1},
{link: 'All', expectedLength: 4}
]
cy.wrap(filters)
.each(filter => {
cy.contains(filter.link)
.click()
cy.get('.todo-list li')
.should('have.length', filter.expectedLength)
})
})
You can make use of custom commands to avoid writing reusable code.
You can go to cypress/support/commands.js and write:
Cypress.Commands.add('checkChatIcon', (page) => {
cy.get(page).should('have.class', 'Widget')
})
In your tests you can just write:
cy.checkChatIcon('.pageA')
cy.checkChatIcon('.pageB')
You should think about the mechanism that puts the icon on all pages and just test that.
If you have to do something for each page you write to ensure the icon is present then you will need to test every page.
If you have done something so that every page you write automatically has the icon then you only need to test the thing you have done. In this case it might be easier to write a unit test to test this something, as its probably something higher up your platforms code hierarchy than the rendering a single page.
Other approaches you could consider is alternatives to testing every page are
randomizing the page choice so each run tests a random page
creating a #slow test that tests every page that you run infrequently
you could get a list of pages for this using a spider, or by other methods
you could combine tests for other global things using this mechanism
In general testing every page for a piece of common content is very poor practice. It creates a large run-time overhead that scales terribly and provides very little benefit.

Eclipse Advanced code template

I have been researching about how to create my own Eclipse's editor template or customize code template to fit my need but to no avail.
Here is my requirement:
I need to have to this kind of script.
${class} ${classname:newName(class)} = new ${class}();
${classname}.toString();
So when I try to use use this. I can automatically generate the code below just by typing "MyClass" to the ${class} part of the code
MyClass myClass = new MyClass();
myClass.toString();
But just by using that script. "myClass" cannot be automatically generated when I input the class name "MyClass"
So for example, I will have
MyClass classname = new MyClass();
classname.toString();
I have found these resources, but it didn't help me. Can anyone point me to the right direction as I can't seem to find a solution for this problem.
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcodestyle%2Fref-preferences-code-templates.htm
Can you define your own template variables in Eclipse
Is there a Eclipse template variable for short version of enclosing type name
OR, is there a way to create my own Eclipse's "Generate Getters and Setters..",
which can be achieved my right clicking on any eclipse source file -> Source -> "Generate Getters and Setters"
This is the best I've found so far: https://marketplace.eclipse.org/content/fast-code-eclipse-plugin
It does exactly what I want, but it lacks polish and documentation. I've also had it crash on me to the point where I needed to reinstall it.
But it's still the best I've found so far.

Integrate jquery.validate with bootstrap popover

I've a registration form validated with jquery.validate plugin.
Now, if the form its not valid, i want to put the result of validate in a bootstrap popover, but really, i don't have idea how i can do this.
Some help?
Checkout this: https://github.com/mingliangfeng/jquery.validate.bootstrap.popover
it is a plugin integrating jQuery validate and bootstrap popover, you may get some idea there.
The jQuery.validate plugin has a method called errorPlacement.
This takes 2 arguments:
error: the error message created by the validator on that element.
element: the element being validated.
The Validator sends the error/valid message here and you can handle all the placement logic in there. What I tend to do is put all that in .setDefaults before initialising the validator.
Example:
jQuery.validator.setDefaults({
ignore: "",
errorPlacement: function (error, element){
// Insert error messgae placement logic here
}
});
For showing and hiding tooltips for your errors, you'd need to use the errorPlacement and success callback functions.
Since you've shown no code of your own, here is a similar setup using the Tooltipster plugin, just to give you an idea about how to use these callback functions. Adjust as needed for Bootstrap popovers or whatever other tooltip plugin you may use.
$(document).ready(function () {
$('#myform').validate({
// rules and options here,
errorPlacement: function (error, element) {
// construct tooltip with message as per plugin method
$(element).tooltipster('update', $(error).text());
// show tooltip as per plugin method
$(element).tooltipster('show');
},
success: function (label, element) {
// hide tooltip as per plugin method
$(element).tooltipster('hide');
}
});
});
DEMO: http://jsfiddle.net/kyK4G/
Reference: https://stackoverflow.com/a/14741689/594235
Documentation: http://jqueryvalidation.org/validate

How to open pickList of ComboboxItem/SelectItem manually/programatically using SmartGWT?

I'm using SmartGWT 2.5 with Java & Mozilla FF 3.6.x.
I want to open pickList of ComboboxItem or SelectItem manually that means programatically. Is it possible? It's OK if I need to use JavaScript to achieve this. Any hint or solution is appreciated.
I finally got the answer. Posting it here might be useful to others. I've used
comboxItem.showPicker();
to achieve manual opening of picklist of ComboboxItem.
In SmartGWT 2.4 (I didn't check newer versions), the showPicker() method of SelectItem does only show an empty div, not the pick list of the select item. (It does work for the ComboBoxItem, as mentioned by RAS' answer).
Some digging into the underlying SmartClient code showed that on the JavaScript side, there is a showPickList() method which is called when the icon is clicked (or on some other events), but this is not exposed by the Java class.
So I used a piece of JSNI (modified from the source code of SelectItem.showPicker) to call this method:
public static native void showPickList(SelectItem item) /*-{
var jsItem = item.#com.smartgwt.client.core.DataClass::getJsObj()();
if(jsItem.showPickList) {
jsItem.showPickList();
}
}-*/
Calling showPickList(item) for any such pick list now opens the picker.

$wnd.google.visualization is undefined

I'm currently building a SmartGWT-based web application (using the Portlet Layout). So I have several "Portlet", which basically extend GWT Window with different content. Now I want a Portlet to display Dygraphs. So I've created an RPC Service implementation which returns a JSON String (based on a DataTable object).
Since I cannot directly serialize a DataTable object I use
String json = JsonRenderer.renderDataTable(data, true, true).toString();
where "data" is of type DataTable.
Now this String gets correctly passed to the client side where I want to create the Dygraph. In this thread , someone suggested to use
public static native DataTable toDataTable(String json)
/-{ return new $wnd.google.visualization.DataTable(eval("(" + json + ")")); }-/;
If I use this in my GWT client code, i get an error saying
com.google.gwt.core.client.JavaScriptException: (TypeError): $wnd.google.visualization is undefined
Do i miss some "import" of the visualization API? Where do i have to instantiate it?
Or is there another way to get the JSON datastring into the Dygraph? I can't find any examples...
Thank you for any hint!
I assume you have included the visualization.jar and the visualization namespace in your module's XML
<inherits name="com.google.gwt.visualization.Visualization"/>
This will give you the Classes. You probably have done this otherwise you would have gotten a compiler error.
However you also have to include the actual visualization javascript file from the google servers (the visualization.jar is only a wrapper). This can be done in two different ways:
1.) Include it in the host page:
<script type="text/javascript">
google.load("visualization", "1", {'packages' : ["corechart"] });
</script>
or
2.) Load it dynamically where you need it:
VisualizationUtils.loadVisualizationApi(onLoadCallback, MotionChart.PACKAGE);
see http://code.google.com/docreader/#p=gwt-google-apis&s=gwt-google-apis&t=VisualizationGettingStarted
Btw. I have forked the Dygraphs Project and changed the GWT wrapper to more like the other visualization wrappers. You can check it out here: https://github.com/timeu/dygraphs
Edit: I have a new GWT wrapper for dygraphs that uses the GWT 2.8's new JsInterop: https://github.com/timeu/dygraphs-gwt
Note: I changed some behaviour in dygraphs and added some features which weren't available in the upstream code.

Categories

Resources