Modifying react-native files - java

i changed a BaseViewManager.java file inside of react-native to make resource-id available thru react-native. the thing is that no matter what i do, nothing takes effect, even if i put typos in the .java files. my colleague told me it's probably because the .java is not being built.
so how to build the react-native .java files??
i tried npm start of course but nothing took any effect.
and this is the code that i want to change
#ReactProp(name = PROP_TEST_ID)
public void setTestId(T view, String testId) {
view.setTag(R.id.react_test_id, testId);
// temporarily set the tag and keyed tags to avoid end to end test regressions
view.setTag(testId);
}
#ReactProp(name = PROP_NATIVE_ID)
public void setNativeId(T view, String nativeId) {
view.setTag(R.id.view_tag_native_id, nativeId);
ReactFindViewUtil.notifyViewRendered(view);
}

You have to build React Native from source. Here is tutorial for that: https://reactnative.dev/contributing/how-to-build-from-source I tried it and it works :)

Related

Plugin development: listener to resource change in plugin

I am developing plugin of graph that use the objects in the current file that open. If I change the file that open, I want the graph will update.
Now, I am using setFocus() method in my class that extends ViewPart, and update the graph in every call to this function.
This is not what I want, I want to update the graph only when the resource change.
I found this link:
link to similar question
This is like my question, but there is no answer
I need to put the following code in the activator.java file of my plugin?:
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResourceChangeListener listener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
System.out.println("Something changed!");
}
};
workspace.addResourceChangeListener(listener);
//... some time later one ...
workspace.removeResourceChangeListener(listener);
If I need to add this code, where to put it? In which method to put it in the activator.java file?
If not, what I need to do?
Set up the listener in the view part createPartControl.
The activator is not a suitable place to set up listeners as it is only run when some other code in the plugin runs.

Eclipse RCP 4.x - Defining workspace location

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)
Long story short:
I've got simple E4 application, product project, feature and main plugin with simple trim window.
Works, after exporting works too.
Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.
But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???
Of course I've tried with :
Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);
But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add
-data #noDefault in products Launching Arguments ... The same...
I always try to accomplish my tasks by myself but this.... this... ehh... Help ?
You should be able to do this in the #PostContextCreate method of the life cycle class. Don't specify the '-data' argument
#PostContextCreate
public void postContextCreate()
{
Location instanceLoc = Platform.getInstanceLocation();
// Stop if location is set
if (instanceLoc.isSet())
return;
File file = new File("C:\\TEST");
instanceLocation.set(file.toURL(), false);
}
Note: You need '\\' in your file path.
This is adapted from code which I use in my e4 RCP.
If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

Why is Play not finding the view?

This is my show() method for UsersController
import views.html.*;
public static Result show(Long id)
{
User user = User.findById(id);
return ok(views.html.users.show.render(user));
}
However, IntelliJ marks show as red and cannot find the symbol.
I already did activator compile and is target folder already has object show.template.scala.
Can anyone help me figure out what the problem is and how to fix it?
Should be something like. Note the return type.
public static Result show(Long id) {
User user = User.findById(id);
return ok(views.html.users.show.render(user));
}
Also make sure you add this to you your routes file and ensure the the show.scala.html file is in a "/views/users" folder.
I used to have the same problem every time that i created a new view in Eclipse. My solution was to refresh eclipse files with "play eclipse". In this case i think you have to find the way to make idea recognize the files (maybe "activator idea"?)

Java equivalent of #ifdef that allows non-compilable code

Is it possible in Java to do a sort of #ifdef thing, like in C/C++?
Example:
class Test
{
public static final boolean ANDROID = false;
public Test()
{
if (ANDROID)
{
// do stuff that won't compile if not on android
}
else
{
// do stuff that should be only done on desktop
}
}
}
Note that even if ANDROID is false, as in the example, it will still try to compile the code inside of the if, even though it won't (and shouldn't) compile.
I'm looking for a way to do conditional compilation -- the compiler shouldn't even look at the if if ANDROID is false.
The context of my question is that I have a Processing application in Eclipse. I'm using both normal Processing and Processing for Android in two separate projects, but I want to be able to move the source code of the projects between one another without having compiler errors. For example, I want to be able to have source code files that I can move from the Android project to the desktop project and only have to change a couple of things -- for example, changing ANDROID = true to ANDROID = false.
I really need it to be conditional compilation because when I copy the source code from the Android project to the desktop project, the desktop libraries obviously won't include Android libraries, and then the source code won't even compile.
EDIT: So now that I know that there is no preprocessor in Java, my question is: is there any other way to have this functionality in my projects (being able to copy source code from one to the other with only very minor changes) without having to manually [un]comment specific pieces of code and having to remember where those are?
EDIT 2: This is not a duplicate of the other question because my question includes code that may have compiler errors in it, whereas the question that this was closed as a duplicate of does not. (That other question concerns only code that would compile fine even without #ifdefs.) To explain, the most highly rated (and accepted) answer for the other question talks about code that is compiled, but is simply not emitted in the bytecode. However, my question concerns code that would not even compile originally.
As others have said, the answer to your actual question is no.
However, you might approach your problem by isolating the Android or desktop code. You could do this by having three separate projects in eclipse:
Core: This is the "shared" code that exists between both versions.
Android: This contains only the code that runs on Android.
Desktop: This contains only the code that runs on desktop.
Both your Android and Desktop projects would contain the Core project on their classpaths. In eclipse, you'd do this by going to your Java Build Path, then clicking the Projects tab, then adding the Core project to the "Required projects" list.
Then you'd set your code up so your Android and Desktop projects are what you actually deploy, and your Core project contains the code shared between them. Here's a simple example. Let's say we have an example class that looks like this:
public class Adder{
public void addAndPrint(int x, int y){
//code that will work on both Android and desktop
int sum = x+y;
if (ANDROID){
//code that will only work on Android
Log.v("example", "Sum:" + sum);
}
else{
//code that will only work on desktop
System.out.println("Sum: " + sum)
}
}
}
You could get around this by refactoring your code to isolate the "core" code that will work on both desktop and Android. Something like this:
//example core class
public class CoreAdder{
Printer printer;
public CoreAdder(Printer printer){
this.printer = printer;
}
public void addAndPrint(int x, int y){
int sum = x+y;
printer.print("Sum: " + sum);
}
}
//example core interface. We might print differently on
//Android and Desktop, so implement this interface in each.
public interface Printer{
public void print(String printMe);
}
Then, you'd isolate the code that will only work on Desktop:
//on desktop, use System.out.println()
public class DesktopPrinter implements Printer{
public void print(String printMe){
System.out.println(printMe);
}
}
//on desktop, entry point is main()
public class DesktopMain{
public static void main(String... args){
DesktopPrinter printer = new DesktopPrinter();
CoreAdder adder = new CoreAdder(printer);
adder.addAndPrint(1, 2);
}
}
And the code that will only work on Android:
//on Android, use a logger
public class AndroidPrinter implements Printer{
public void print(String printMe){
Log.v("example", "index=" + i);
}
}
//on Android, entry point is Activity
public class AndroidActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
AndroidPrinter printer = new AndroidPrinter ();
CoreAdder adder = new CoreAdder(printer);
adder.addAndPrint(1, 2);
}
}
Note that this is just an example, and I know that both System.out.println() and Log.v() could work on either platform. But the idea is the same: split your project up into multiple projects, and use interfaces to abstract away the behavior that changes between platforms.
As Java does not natively include a preprocessor, it would be incumbent upon you to manually execute one before compiling. The c preprocessor is m4, which you can run yourself.
There are no-preprocessors in java like C,C++ etc. All you can do is comment out the code.
Use #ifdef and friends as in C and run the Java sources through the C pre-processor before compiling them.
For gcc the pre-processor is called cpp, for VC it's cl.exe using the option /P.
No, there is no such thing as a preprocessor in Java that can hide chunks of code to the JVM.
EDIT:
While you could of course run any program against your code base to preprocess it, think about if you really want this. The Android code will diverge more from the other Java code in time and your code will be littered with those #ifdef-like statements. Your IDE will also still see them and give you errors in both areas of code. In this case it's much easier to just make two projects out of it or, and that's my advice, create a platform independent library which you include in both projects and includes the functionality you need.
By defining productFlavors in build you can use folders that will be compiled when specific flavor is chosen thus you can make code in same codebase available conditionally at compile time.

Trying to use the Netbeans ProgressBar to show long running tasks, having problems with dependancies and libraries

I have an application built on top of NetBeans. We have some long running jobs that I'd like to keep running in the background, but allow the user to see progress on the bar on the lower right.
E.G:
I can't seem to access it from my code.
Initially I didn't have this library
org.netbeans.api.progress.ProgressHandle;
org.netbeans.api.progress.ProgressHandleFactory;
I had to go out and hunt down the JAR file. That doesn't make whole lot of sense to me, I figure it should be available.
This creates an error when I try to call the ProgressHandle into effect, I get this error
java.lang.ClassNotFoundException: org.openide.awt.StatusLineElementProvider …
Followed by a stack trace. Obviously I don't have all the packages necessary to operate this.
What the big question is then, what am I missing as far as accessing these NetBeans libraries correctly?
Thanks,
Here's the code when I'm trying to call the progressbar into action
`
ProgressHandle progr;
if (thread == null) {
thread = new Thread() {
#Override
public void run() {
progr.start();
progr.progress("Sending backup to remote server.");
… //Some code that sends a backup
progr.finish();
`
I'll be rewriting this question a few times, until I think it's clear, I'm open to input
Add a module dependency on Progress API. Right click on your module > properties.Select Libraries from the left panel. Click Add to open up the module dependency dialog. Select Progress API and click OK. Now you have the dependency on Progress API and you can use it as
ProgressHandle ph = ProgressHandleFactory.createSystemHandle("My Task");
ph.start(100);
Edit:
Also u dont have to add any jar files.. The Progress API module dependency will take care of that

Categories

Resources