Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[ease-dev] Feature request: clipboard support (or instead loading arbitrary classes by name for DIY)

For debugging JavaScript code with Eclipse, I've realized it would be convenient to select a JavaScript variable name, and then run an EASE script to create a console.log(...) statement to be put in the clipboard so I could paste that somewhere. With my previous approach, I can replace the selection, and I wrote a script to do that, but the selected code is not usually where I want the logging statement to go. So being able to put the results of a script in the clipboard to paste where desired afterwards would be useful.

Some related example code in Java for accessing the Eclipse clipboard:
http://www.javadocexamples.com/java_source/org/eclipse/swt/snippets/Snippet122.java.html

Now, I could create an EASE script to do the whole process if I could just figure out a way to do things like "cb = new Clipboard(display);" from JavaScript using EASE. So, as an alternative to adding more methods to the UI module, is there a way to import an arbitrary class into the JavaScript Rhino environment from a name (in this case, "org.eclipse.swt.dnd.Clipboard") so that I can access its fields or use a constructor on a class?

One way to do that in Java is to use "Class.forName(...)".

Although, even if that worked, it seems like the next hurdle I might run into is then creating an object array in EASE to pass into API calls. That is the section of the snippet in the URL above for:
   Object[] data = new Object[]{selection};
   Transfer[] types = new Transfer[] {TextTransfer.getInstance()};

Here is how that is done in Jython as one example:
  http://www.jython.org/archive/21/docs/jarray.html
"Many Java methods require Java array objects as arguments. The way that these arguments are used means that they must correspond to fixed-length, mutable sequences, sometimes of primitive data types. The PyArray class is added to support these Java arrays and instances of this class will be automatically returned from any Java method call that produces an array. In addition, the "jarray" module is provided to allow users of Jython to create these arrays themselves, primarily for the purpose of passing them to a Java method.
  The jarray module exports two functions:
    array(sequence, type)
    zeros(length, type)
array will create a new array of the same length as the input sequence and will populate it with the values in sequence. zeros will create a new array of the given length filled with zeros (or null's if appropriate). type can either be a single character typecode (using the same mappings as Python's array module) or it can be an instance of a JavaClass object. The valid typecodes are shown in the following table: ..."

I'm not saying that part of the Jython API is necessarily the best, as it might make more sense for "type" to be the first argument instead of the last for the "arrays" and "zeros" functions defined there. And I'd rather see it say makeJavaArray or makeJavaZeros or something like that.

Thoughts?

--Paul Fernhout
http://www.pdfernhout.net/
====
The biggest challenge of the 21st century is the irony of technologies of abundance in the hands of those still thinking in terms of scarcity.


Back to the top